Source Code Cross Referenced for AbstractApplicationEventDialog.java in  » Net » Terracotta » org » terracotta » dso » dialogs » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » org.terracotta.dso.dialogs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package org.terracotta.dso.dialogs;
006:
007:        import org.eclipse.core.resources.IProject;
008:        import org.eclipse.core.resources.IWorkspaceRoot;
009:        import org.eclipse.core.resources.ResourcesPlugin;
010:        import org.eclipse.jdt.core.IJavaProject;
011:        import org.eclipse.jdt.core.IMethod;
012:        import org.eclipse.jdt.core.IType;
013:        import org.eclipse.jdt.core.JavaCore;
014:        import org.eclipse.jdt.core.JavaModelException;
015:        import org.eclipse.jdt.internal.ui.JavaPluginImages;
016:        import org.eclipse.jface.dialogs.IDialogSettings;
017:        import org.eclipse.jface.dialogs.MessageDialog;
018:        import org.eclipse.jface.resource.ImageDescriptor;
019:        import org.eclipse.jface.viewers.CheckStateChangedEvent;
020:        import org.eclipse.jface.viewers.CheckboxTreeViewer;
021:        import org.eclipse.jface.viewers.ICheckStateListener;
022:        import org.eclipse.jface.viewers.ILabelProvider;
023:        import org.eclipse.jface.viewers.ILabelProviderListener;
024:        import org.eclipse.jface.viewers.ISelectionChangedListener;
025:        import org.eclipse.jface.viewers.IStructuredSelection;
026:        import org.eclipse.jface.viewers.ITreeContentProvider;
027:        import org.eclipse.jface.viewers.SelectionChangedEvent;
028:        import org.eclipse.jface.viewers.StructuredSelection;
029:        import org.eclipse.jface.viewers.Viewer;
030:        import org.eclipse.swt.SWT;
031:        import org.eclipse.swt.custom.CLabel;
032:        import org.eclipse.swt.custom.SashForm;
033:        import org.eclipse.swt.custom.StackLayout;
034:        import org.eclipse.swt.events.FocusAdapter;
035:        import org.eclipse.swt.events.FocusEvent;
036:        import org.eclipse.swt.events.ModifyEvent;
037:        import org.eclipse.swt.events.ModifyListener;
038:        import org.eclipse.swt.events.SelectionAdapter;
039:        import org.eclipse.swt.events.SelectionEvent;
040:        import org.eclipse.swt.events.SelectionListener;
041:        import org.eclipse.swt.graphics.Image;
042:        import org.eclipse.swt.graphics.ImageData;
043:        import org.eclipse.swt.graphics.PaletteData;
044:        import org.eclipse.swt.graphics.RGB;
045:        import org.eclipse.swt.layout.GridData;
046:        import org.eclipse.swt.layout.GridLayout;
047:        import org.eclipse.swt.widgets.Button;
048:        import org.eclipse.swt.widgets.Combo;
049:        import org.eclipse.swt.widgets.Composite;
050:        import org.eclipse.swt.widgets.Control;
051:        import org.eclipse.swt.widgets.Group;
052:        import org.eclipse.swt.widgets.Label;
053:        import org.eclipse.swt.widgets.Shell;
054:        import org.eclipse.swt.widgets.Table;
055:        import org.eclipse.swt.widgets.TableItem;
056:        import org.eclipse.swt.widgets.Text;
057:        import org.eclipse.swt.widgets.Tree;
058:        import org.eclipse.swt.widgets.TreeItem;
059:        import org.eclipse.ui.forms.HyperlinkSettings;
060:        import org.eclipse.ui.forms.widgets.FormToolkit;
061:        import org.terracotta.dso.ConfigurationHelper;
062:        import org.terracotta.dso.MultiChangeSignaller;
063:        import org.terracotta.dso.TcPlugin;
064:        import org.terracotta.dso.editors.ConfigurationEditor;
065:        import org.terracotta.ui.util.EmptyIterator;
066:        import org.terracotta.ui.util.SWTUtil;
067:
068:        import com.tc.admin.common.AbstractResolutionAction;
069:        import com.tc.admin.common.AbstractWorkState;
070:        import com.tc.admin.common.NonPortableMessages;
071:        import com.tc.admin.common.NonPortableWorkState;
072:        import com.tc.object.appevent.AbstractApplicationEvent;
073:        import com.tc.object.appevent.NonPortableObjectState;
074:        import com.terracottatech.config.Include;
075:        import com.terracottatech.config.OnLoad;
076:        import com.terracottatech.config.TcConfigDocument;
077:        import com.terracottatech.config.TcConfigDocument.TcConfig;
078:
079:        import java.io.IOException;
080:        import java.util.ArrayList;
081:        import java.util.Iterator;
082:
083:        import javax.swing.tree.DefaultMutableTreeNode;
084:        import javax.swing.tree.DefaultTreeModel;
085:
086:        public abstract class AbstractApplicationEventDialog extends
087:                MessageDialog {
088:            protected IJavaProject fJavaProject;
089:            private AbstractApplicationEvent fEvent;
090:            private FormToolkit fFormToolkit;
091:            private SashForm fTopSashForm;
092:            private SashForm fBottomSashForm;
093:            protected Table fIssueTable;
094:            protected Tree fObjectTree;
095:            protected CLabel fSummaryLabel;
096:            private Group fDetailsPanel;
097:            private Group fResolutionsPanel;
098:            protected CheckboxTreeViewer fActionTreeViewer;
099:            protected Composite fActionPanel;
100:            protected StackLayout fActionStackLayout;
101:            protected IncludeRulePanel fIncludeRuleView;
102:            private Label fNoActionView;
103:            protected TcConfig fNewConfig;
104:            protected ConfigurationHelper fConfigHelper;
105:
106:            private static final int[] DEFAULT_TOP_SASH_WEIGHTS = new int[] {
107:                    100, 100 };
108:            private static final int[] DEFAULT_BOTTOM_SASH_WEIGHTS = new int[] {
109:                    100, 100 };
110:
111:            private static final String DIALOG_TOP_SASH_WEIGHTS_1 = TcPlugin.PLUGIN_ID
112:                    + ".DIALOG_TOP_SASH_WEIGHTS_1"; //$NON-NLS-1$
113:            private static final String DIALOG_TOP_SASH_WEIGHTS_2 = TcPlugin.PLUGIN_ID
114:                    + ".DIALOG_TOP_SASH_WEIGHTS_2"; //$NON-NLS-1$
115:
116:            private static final String DIALOG_BOTTOM_SASH_WEIGHTS_1 = TcPlugin.PLUGIN_ID
117:                    + ".DIALOG_BOTTOM_SASH_WEIGHTS_1"; //$NON-NLS-1$
118:            private static final String DIALOG_BOTTOM_SASH_WEIGHTS_2 = TcPlugin.PLUGIN_ID
119:                    + ".DIALOG_BOTTOM_SASH_WEIGHTS_2"; //$NON-NLS-1$
120:
121:            protected static final Image NOT_PORTABLE_ICON = JavaPluginImages
122:                    .get(JavaPluginImages.IMG_FIELD_PRIVATE);
123:            protected static final Image NEVER_PORTABLE_ICON = JavaPluginImages
124:                    .get(JavaPluginImages.IMG_FIELD_PRIVATE);
125:            protected static final Image TRANSIENT_ICON = JavaPluginImages
126:                    .get(JavaPluginImages.IMG_FIELD_PUBLIC);
127:            protected static final Image PORTABLE_ICON = JavaPluginImages
128:                    .get(JavaPluginImages.IMG_FIELD_DEFAULT);
129:            protected static final Image PRE_INSTRUMENTED_ICON = JavaPluginImages
130:                    .get(JavaPluginImages.IMG_FIELD_PROTECTED);
131:            protected static final Image OBJ_CYCLE_ICON = TcPlugin
132:                    .createImage("/images/eclipse/obj_cycle.gif"); //$NON-NLS-1$
133:            protected static final Image RESOLVED_ICON = TcPlugin
134:                    .createImage("/images/eclipse/nature.gif"); //$NON-NLS-1$
135:            protected static final Image HELP_ICON = TcPlugin
136:                    .createImage("/images/eclipse/help.gif"); //$NON-NLS-1$
137:
138:            protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
139:
140:            protected static final Iterator EMPTY_ITERATOR = new EmptyIterator();
141:
142:            protected static final MultiChangeSignaller NULL_SIGNALLER = new MultiChangeSignaller() {
143:                public void signal(IProject project) {/**/
144:                }
145:            };
146:
147:            /*
148:             * In Eclipse 3.3 JavaElementImageDescriptor, used by TcPlugin.createImage, started having problems with transparent
149:             * images. The code below creates a transparent image manually.
150:             */
151:            protected static Image BLANK_ICON;
152:
153:            static {
154:                final ImageData blankImageData = new ImageData(16, 16, 1,
155:                        new PaletteData(new RGB[] { new RGB(255, 0, 0) }));
156:                blankImageData.transparentPixel = 0;
157:                BLANK_ICON = ImageDescriptor
158:                        .createFromImageData(blankImageData).createImage();
159:            }
160:
161:            public AbstractApplicationEventDialog(Shell parentShell,
162:                    String dialogTitle, AbstractApplicationEvent event,
163:                    String[] buttonLabels, int defaultButtonIndex) {
164:                super (parentShell, dialogTitle, null, event.getMessage(),
165:                        MessageDialog.ERROR, buttonLabels, defaultButtonIndex);
166:                setShellStyle(SWT.DIALOG_TRIM | getDefaultOrientation()
167:                        | SWT.RESIZE);
168:                fEvent = event;
169:                fJavaProject = getJavaProject(fEvent);
170:                fNewConfig = (TcConfig) TcPlugin.getDefault().getConfiguration(
171:                        fJavaProject.getProject()).copy();
172:                fConfigHelper = new ConfigHelper();
173:                fFormToolkit = new FormToolkit(parentShell.getDisplay());
174:                fFormToolkit.getHyperlinkGroup().setHyperlinkUnderlineMode(
175:                        HyperlinkSettings.UNDERLINE_HOVER);
176:            }
177:
178:            public AbstractApplicationEvent getApplicationEvent() {
179:                return fEvent;
180:            }
181:
182:            protected IDialogSettings getDialogBoundsSettings() {
183:                return getDialogSettings();
184:            }
185:
186:            protected FormToolkit getFormToolkit() {
187:                return fFormToolkit;
188:            }
189:
190:            /*
191:             * (non-Javadoc)
192:             * 
193:             * @see org.eclipse.jface.window.Window#initializeBounds()
194:             */
195:            protected void initializeBounds() {
196:                IDialogSettings settings = getDialogSettings();
197:                if (fTopSashForm != null) {
198:                    int w1, w2;
199:                    try {
200:                        w1 = settings.getInt(DIALOG_TOP_SASH_WEIGHTS_1);
201:                        w2 = settings.getInt(DIALOG_TOP_SASH_WEIGHTS_2);
202:                    } catch (NumberFormatException nfe) {
203:                        w1 = DEFAULT_TOP_SASH_WEIGHTS[0];
204:                        w2 = DEFAULT_TOP_SASH_WEIGHTS[1];
205:                    }
206:                    fTopSashForm.setWeights(new int[] { w1, w2 });
207:                }
208:                if (fBottomSashForm != null) {
209:                    int w1, w2;
210:                    try {
211:                        w1 = settings.getInt(DIALOG_BOTTOM_SASH_WEIGHTS_1);
212:                        w2 = settings.getInt(DIALOG_BOTTOM_SASH_WEIGHTS_2);
213:                    } catch (NumberFormatException nfe) {
214:                        w1 = DEFAULT_BOTTOM_SASH_WEIGHTS[0];
215:                        w2 = DEFAULT_BOTTOM_SASH_WEIGHTS[1];
216:                    }
217:                    fBottomSashForm.setWeights(new int[] { w1, w2 });
218:                }
219:                super .initializeBounds();
220:            }
221:
222:            protected void persistSashWeights() {
223:                IDialogSettings settings = getDialogSettings();
224:                if (fTopSashForm != null) {
225:                    int[] sashWeights = fTopSashForm.getWeights();
226:                    settings.put(DIALOG_TOP_SASH_WEIGHTS_1, sashWeights[0]);
227:                    settings.put(DIALOG_TOP_SASH_WEIGHTS_2, sashWeights[1]);
228:                }
229:                if (fBottomSashForm != null) {
230:                    int[] sashWeights = fTopSashForm.getWeights();
231:                    settings.put(DIALOG_BOTTOM_SASH_WEIGHTS_1, sashWeights[0]);
232:                    settings.put(DIALOG_BOTTOM_SASH_WEIGHTS_2, sashWeights[1]);
233:                }
234:            }
235:
236:            protected IDialogSettings getDialogSettings() {
237:                IDialogSettings settings = TcPlugin.getDefault()
238:                        .getDialogSettings();
239:                IDialogSettings section = settings
240:                        .getSection(getDialogSettingsSectionName());
241:                if (section == null) {
242:                    section = settings
243:                            .addNewSection(getDialogSettingsSectionName());
244:                }
245:                return section;
246:            }
247:
248:            public boolean close() {
249:                persistSashWeights();
250:                return super .close();
251:            }
252:
253:            private IJavaProject getJavaProject(AbstractApplicationEvent event) {
254:                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace()
255:                        .getRoot();
256:                String name = event.getApplicationEventContext()
257:                        .getProjectName();
258:                return JavaCore.create(workspaceRoot.getProject(name));
259:            }
260:
261:            class ConfigHelper extends ConfigurationHelper {
262:                ConfigHelper() {
263:                    super (fJavaProject.getProject());
264:                }
265:
266:                public TcConfig getConfig() {
267:                    return fNewConfig;
268:                }
269:            }
270:
271:            protected Control createCustomArea(Composite parent) {
272:                fFormToolkit.setBackground(parent.getBackground());
273:
274:                Composite composite = new Composite(parent, SWT.NONE);
275:                composite.setLayoutData(new GridData(GridData.FILL_BOTH));
276:                composite.setLayout(new GridLayout());
277:
278:                SashForm sash = new SashForm(composite, SWT.SMOOTH);
279:                sash.setOrientation(SWT.HORIZONTAL);
280:                sash.setLayoutData(new GridData(GridData.FILL_BOTH));
281:                sash.setFont(parent.getFont());
282:                sash.setVisible(true);
283:                fTopSashForm = sash;
284:
285:                Group listGroup = new Group(sash, SWT.SHADOW_NONE);
286:                listGroup.setText(NonPortableMessages.getString("ISSUES")); //$NON-NLS-1$
287:                listGroup.setLayout(new GridLayout());
288:                listGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
289:                fIssueTable = new Table(listGroup, SWT.BORDER | SWT.SINGLE
290:                        | SWT.V_SCROLL | SWT.SINGLE);
291:                fIssueTable
292:                        .addSelectionListener(new IssueTableSelectionListener());
293:                GridData gridData = new GridData(GridData.FILL_BOTH);
294:                gridData.widthHint = SWTUtil.textColumnsToPixels(fIssueTable,
295:                        60);
296:                gridData.heightHint = SWTUtil
297:                        .tableRowsToPixels(fIssueTable, 10);
298:                fIssueTable.setLayoutData(gridData);
299:
300:                Group treePanel = new Group(sash, SWT.SHADOW_NONE);
301:                treePanel.setText(NonPortableMessages
302:                        .getString("OBJECT_BROWSER")); //$NON-NLS-1$
303:                treePanel.setLayout(new GridLayout());
304:                treePanel.setLayoutData(new GridData(GridData.FILL_BOTH));
305:                fObjectTree = new Tree(treePanel, SWT.SINGLE | SWT.V_SCROLL
306:                        | SWT.H_SCROLL | SWT.BORDER);
307:                fObjectTree.setLayoutData(new GridData(GridData.FILL_BOTH));
308:                fObjectTree
309:                        .addSelectionListener(new IssueTreeSelectionListener());
310:
311:                fDetailsPanel = new Group(composite, SWT.SHADOW_NONE);
312:                fDetailsPanel.setText(NonPortableMessages
313:                        .getString("ISSUE_DETAILS")); //$NON-NLS-1$
314:                fDetailsPanel.setLayout(new GridLayout());
315:                fDetailsPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
316:                fSummaryLabel = new CLabel(fDetailsPanel, SWT.NONE);
317:                fSummaryLabel.setLayoutData(new GridData(
318:                        GridData.FILL_HORIZONTAL));
319:
320:                createIssueDescriptionArea(fDetailsPanel);
321:
322:                fResolutionsPanel = new Group(composite, SWT.SHADOW_NONE);
323:                fResolutionsPanel.setText(NonPortableMessages
324:                        .getString("RESOLUTIONS")); //$NON-NLS-1$
325:                fResolutionsPanel.setLayout(new GridLayout(2, false));
326:                gridData = new GridData(GridData.FILL_BOTH);
327:                gridData.horizontalSpan = 2;
328:                fResolutionsPanel.setLayoutData(gridData);
329:
330:                sash = new SashForm(fResolutionsPanel, SWT.SMOOTH);
331:                sash.setOrientation(SWT.HORIZONTAL);
332:                sash.setLayoutData(new GridData(GridData.FILL_BOTH));
333:                sash.setFont(parent.getFont());
334:                sash.setVisible(true);
335:                fBottomSashForm = sash;
336:
337:                Group actionGroup = new Group(sash, SWT.NONE);
338:                actionGroup.setText(NonPortableMessages.getString("ACTIONS"));
339:                actionGroup.setLayout(new GridLayout());
340:                actionGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
341:                fActionTreeViewer = new CheckboxTreeViewer(actionGroup,
342:                        SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
343:                fActionTreeViewer.getTree().setLayoutData(
344:                        new GridData(GridData.FILL_BOTH));
345:                fActionTreeViewer
346:                        .addCheckStateListener(new ActionCheckStateHandler());
347:                fActionTreeViewer
348:                        .addSelectionChangedListener(new ActionSelectionChangedHandler());
349:                fActionTreeViewer
350:                        .setContentProvider(new ActionTreeContentProvider());
351:                fActionTreeViewer.setLabelProvider(new ActionLabelProvider());
352:
353:                Group actionPanelGroup = new Group(sash, SWT.SHADOW_NONE);
354:                actionPanelGroup.setText(NonPortableMessages
355:                        .getString("SELECTED_ACTION")); //$NON-NLS-1$
356:                actionPanelGroup.setLayout(new GridLayout());
357:                actionPanelGroup
358:                        .setLayoutData(new GridData(GridData.FILL_BOTH));
359:                fActionPanel = new Composite(actionPanelGroup, SWT.NONE);
360:                fActionPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
361:                fActionPanel.setLayout(fActionStackLayout = new StackLayout());
362:
363:                fIncludeRuleView = new IncludeRulePanel(fActionPanel);
364:                fNoActionView = new Label(fActionPanel, SWT.NONE);
365:
366:                fActionStackLayout.topControl = fNoActionView;
367:
368:                populateTree();
369:
370:                initIssueList();
371:                if (fIssueTable.getItemCount() > 0) {
372:                    fIssueTable.setSelection(0);
373:                    handleTableSelectionChange();
374:                }
375:
376:                return composite;
377:            }
378:
379:            protected void buttonPressed(int buttonId) {
380:                switch (buttonId) {
381:                case 0:
382:                    cancelPressed();
383:                    break;
384:                case 1:
385:                    apply();
386:                    okPressed();
387:                    break;
388:                }
389:            }
390:
391:            protected void apply() {
392:                TcPlugin plugin = TcPlugin.getDefault();
393:                TcConfigDocument configDoc = TcConfigDocument.Factory
394:                        .newInstance();
395:
396:                configDoc.setTcConfig(fNewConfig);
397:                try {
398:                    IProject project = fJavaProject.getProject();
399:                    plugin.setConfigurationFromString(project, plugin
400:                            .configDocumentAsString(configDoc));
401:                    ConfigurationEditor configEditor = plugin
402:                            .getConfigurationEditor(project);
403:                    if (configEditor == null) {
404:                        plugin.saveConfiguration(project);
405:                    }
406:                } catch (IOException ioe) {
407:                    ioe.printStackTrace();
408:                }
409:            }
410:
411:            protected static Image imageFor(AbstractWorkState workState) {
412:                if (workState instanceof  NonPortableWorkState) {
413:                    NonPortableWorkState nonPortableWorkState = (NonPortableWorkState) workState;
414:
415:                    if (nonPortableWorkState.isRepeated()) {
416:                        return OBJ_CYCLE_ICON;
417:                    } else if (nonPortableWorkState.isPreInstrumented()) {
418:                        return PRE_INSTRUMENTED_ICON;
419:                    } else if (nonPortableWorkState.isNeverPortable()) {
420:                        return NEVER_PORTABLE_ICON;
421:                    } else if (!nonPortableWorkState.isPortable()) {
422:                        return NOT_PORTABLE_ICON;
423:                    } else if (nonPortableWorkState.isTransient()) {
424:                        return TRANSIENT_ICON;
425:                    } else {
426:                        return PORTABLE_ICON;
427:                    }
428:                }
429:
430:                return null;
431:            }
432:
433:            protected void initTreeItem(TreeItem item,
434:                    DefaultMutableTreeNode node) {
435:                item.setData(node);
436:
437:                String text = null;
438:                Image image = PORTABLE_ICON;
439:
440:                Object userObject = node.getUserObject();
441:                if (userObject instanceof  NonPortableObjectState) {
442:                    userObject = new NonPortableWorkState(
443:                            (NonPortableObjectState) userObject);
444:                    node.setUserObject(userObject);
445:                }
446:                if (userObject instanceof  NonPortableWorkState) {
447:                    NonPortableWorkState workState = (NonPortableWorkState) userObject;
448:                    text = workState.getLabel();
449:                    image = imageFor(workState);
450:                }
451:
452:                item.setText(text != null ? text : userObject.toString());
453:                item.setImage(image);
454:
455:                for (int i = 0; i < node.getChildCount(); i++) {
456:                    TreeItem childItem = new TreeItem(item, SWT.NONE);
457:                    DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node
458:                            .getChildAt(i);
459:                    initTreeItem(childItem, childNode);
460:                }
461:            }
462:
463:            void populateTree() {
464:                DefaultTreeModel treeModel = fEvent
465:                        .getApplicationEventContext().getTreeModel();
466:
467:                if (treeModel != null) {
468:                    DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel
469:                            .getRoot();
470:                    DefaultMutableTreeNode node;
471:                    TreeItem item;
472:
473:                    for (int i = 0; i < root.getChildCount(); i++) {
474:                        item = new TreeItem(fObjectTree, SWT.NONE);
475:                        node = (DefaultMutableTreeNode) root.getChildAt(i);
476:                        initTreeItem(item, node);
477:                    }
478:                }
479:            }
480:
481:            private void handleTableSelectionChange() {
482:                TableItem[] selection = fIssueTable.getSelection();
483:
484:                if (selection.length > 0) {
485:                    TreeItem treeItem = (TreeItem) selection[0].getData();
486:                    fObjectTree.setSelection(treeItem);
487:                    handleTreeSelectionChange();
488:                }
489:            }
490:
491:            class IssueTableSelectionListener extends SelectionAdapter {
492:                public void widgetSelected(SelectionEvent e) {
493:                    handleTableSelectionChange();
494:                }
495:            }
496:
497:            class IssueTreeSelectionListener extends SelectionAdapter {
498:                public void widgetSelected(SelectionEvent e) {
499:                    handleTreeSelectionChange();
500:                }
501:            }
502:
503:            protected void hideResolutionsPanel() {
504:                fResolutionsPanel.setVisible(false);
505:            }
506:
507:            protected void showResolutionsPanel() {
508:                fResolutionsPanel.setVisible(true);
509:            }
510:
511:            protected AbstractResolutionAction[] getActions(
512:                    AbstractWorkState state) {
513:                AbstractResolutionAction[] actions = state.getActions();
514:
515:                if (actions == null) {
516:                    state.setActions(actions = createActions(state));
517:                }
518:
519:                return actions;
520:            }
521:
522:            private void handleActionSelectionChanged(
523:                    IStructuredSelection selection) {
524:                Object obj = selection.getFirstElement();
525:
526:                if (obj == NO_ACTION_ITEM) {
527:                    hideActionPanel();
528:                } else {
529:                    AbstractResolutionAction action = (AbstractResolutionAction) obj;
530:                    if (action != null) {
531:                        if (action.isSelected()) {
532:                            action.showControl(this );
533:                        } else {
534:                            hideActionPanel();
535:                        }
536:                    }
537:                }
538:            }
539:
540:            class ActionSelectionChangedHandler implements 
541:                    ISelectionChangedListener {
542:                public void selectionChanged(SelectionChangedEvent event) {
543:                    IStructuredSelection selection = (IStructuredSelection) event
544:                            .getSelection();
545:                    handleActionSelectionChanged(selection);
546:                }
547:            }
548:
549:            protected boolean haveAnyActions() {
550:                ActionTreeContentProvider contentProvider = (ActionTreeContentProvider) fActionTreeViewer
551:                        .getContentProvider();
552:                AbstractResolutionAction[] actions = contentProvider
553:                        .getEnabledActions();
554:                return actions != null && actions.length > 0;
555:            }
556:
557:            protected boolean anyActionSelected() {
558:                ActionTreeContentProvider contentProvider = (ActionTreeContentProvider) fActionTreeViewer
559:                        .getContentProvider();
560:                AbstractResolutionAction[] actions = contentProvider
561:                        .getEnabledActions();
562:
563:                if (actions != null) {
564:                    for (AbstractResolutionAction action : actions) {
565:                        if (action.isSelected()) {
566:                            return true;
567:                        }
568:                    }
569:                }
570:
571:                return false;
572:            }
573:
574:            protected void setNoAction(boolean checked) {
575:                fActionTreeViewer.setChecked(NO_ACTION_ITEM, checked);
576:                fIssueTable.getSelection()[0].setImage(checked ? BLANK_ICON
577:                        : RESOLVED_ICON);
578:            }
579:
580:            private boolean isSetNoAction() {
581:                return fActionTreeViewer.getChecked(NO_ACTION_ITEM);
582:            }
583:
584:            class ActionCheckStateHandler implements  ICheckStateListener {
585:                public void checkStateChanged(CheckStateChangedEvent event) {
586:                    Object obj = event.getElement();
587:
588:                    if (obj == NO_ACTION_ITEM) {
589:                        handleNoActionItemSelected();
590:                    } else {
591:                        AbstractResolutionAction action = (AbstractResolutionAction) obj;
592:                        if (action != null) {
593:                            boolean isChecked = fActionTreeViewer
594:                                    .getChecked(action);
595:
596:                            action.setSelected(isChecked);
597:                            if (isChecked) {
598:                                setNoAction(false);
599:                            } else if (!anyActionSelected()) {
600:                                setNoAction(true);
601:                            }
602:                        }
603:                    }
604:
605:                    StructuredSelection newSelection = new StructuredSelection(
606:                            obj);
607:                    fActionTreeViewer.setSelection(newSelection);
608:                    handleActionSelectionChanged(newSelection);
609:                    updateButtons();
610:                }
611:            }
612:
613:            protected void updateButtons() {
614:                /**/
615:            }
616:
617:            protected void hideActionPanel() {
618:                fActionStackLayout.topControl = fNoActionView;
619:                fActionPanel.layout();
620:                fActionPanel.redraw();
621:            }
622:
623:            private void handleNoActionItemSelected() {
624:                if (isSetNoAction()) {
625:                    hideActionPanel();
626:
627:                    ActionTreeContentProvider contentProvider = (ActionTreeContentProvider) fActionTreeViewer
628:                            .getContentProvider();
629:                    AbstractResolutionAction[] actions = contentProvider
630:                            .getEnabledActions();
631:
632:                    for (int i = 0; i < actions.length; i++) {
633:                        actions[i].setSelected(false);
634:                        fActionTreeViewer.setChecked(actions[i], false);
635:                    }
636:
637:                    TableItem[] selection = fIssueTable.getSelection();
638:                    if (selection.length > 0) {
639:                        selection[0].setImage(BLANK_ICON);
640:                    }
641:                }
642:            }
643:
644:            public void widgetDefaultSelected(SelectionEvent e) {/**/
645:            }
646:
647:            protected static final Object NO_ACTION_ITEM = new Object();
648:
649:            class ActionTreeContentProvider implements  ITreeContentProvider {
650:                AbstractWorkState fWorkState;
651:                AbstractResolutionAction[] fEnabledActions;
652:
653:                public void inputChanged(Viewer viewer, Object oldInput,
654:                        Object newInput) {
655:                    fWorkState = (AbstractWorkState) newInput;
656:                    fEnabledActions = null;
657:
658:                    if (fWorkState != null) {
659:                        ArrayList list = new ArrayList();
660:                        AbstractResolutionAction[] actions = getActions(fWorkState);
661:
662:                        if (actions != null && actions.length > 0) {
663:                            for (AbstractResolutionAction action : actions) {
664:                                if (action.isEnabled()) {
665:                                    list.add(action);
666:                                }
667:                            }
668:                        }
669:                        fEnabledActions = (AbstractResolutionAction[]) list
670:                                .toArray(new AbstractResolutionAction[0]);
671:                    }
672:                }
673:
674:                public AbstractResolutionAction[] getEnabledActions() {
675:                    return fEnabledActions;
676:                }
677:
678:                public Object[] getChildren(Object parentElement) {
679:                    return (parentElement == NO_ACTION_ITEM) ? fEnabledActions
680:                            : null;
681:                }
682:
683:                public Object getParent(Object element) {
684:                    return (element != NO_ACTION_ITEM) ? NO_ACTION_ITEM : null;
685:                }
686:
687:                public boolean hasChildren(Object element) {
688:                    return element == NO_ACTION_ITEM;
689:                }
690:
691:                public Object[] getElements(Object inputElement) {
692:                    return new Object[] { NO_ACTION_ITEM };
693:                }
694:
695:                public void dispose() {/**/
696:                }
697:            }
698:
699:            private static class ActionLabelProvider implements  ILabelProvider {
700:                public String getText(Object element) {
701:                    if (element == NO_ACTION_ITEM)
702:                        return NonPortableMessages.getString("TAKE_NO_ACTION");
703:                    return element.toString();
704:                }
705:
706:                public Image getImage(Object element) {
707:                    return null;
708:                }
709:
710:                public void addListener(ILabelProviderListener listener) {/**/
711:                }
712:
713:                public void dispose() {/**/
714:                }
715:
716:                public boolean isLabelProperty(Object element, String property) {
717:                    return false;
718:                }
719:
720:                public void removeListener(ILabelProviderListener listener) {/**/
721:                }
722:            }
723:
724:            protected Include ensureIncludeRuleFor(String classExpr) {
725:                Include include = fConfigHelper.includeRuleFor(classExpr);
726:
727:                if (include == null) {
728:                    include = fConfigHelper.addIncludeRule(classExpr);
729:                }
730:
731:                return include;
732:            }
733:
734:            protected class IncludeRulePanel extends Composite implements 
735:                    SelectionListener {
736:                Button honorTransientButton, doNothingButton, callMethodButton,
737:                        executeCodeButton;
738:                Text includePatternText, executeCodeText;
739:                Combo callMethodCombo;
740:                Include include;
741:
742:                IncludeRulePanel(Composite parent) {
743:                    super (parent, SWT.NONE);
744:
745:                    setLayout(new GridLayout(2, false));
746:                    CLabel label = new CLabel(this , SWT.NONE);
747:                    label.setText(NonPortableMessages
748:                            .getString("INCLUDE_PATTERN")); //$NON-NLS-1$
749:                    includePatternText = new Text(this , SWT.BORDER
750:                            | SWT.READ_ONLY);
751:                    includePatternText.setLayoutData(new GridData(
752:                            GridData.FILL_HORIZONTAL));
753:                    honorTransientButton = new Button(this , SWT.CHECK);
754:                    honorTransientButton.setText(NonPortableMessages
755:                            .getString("HONOR_TRANSIENT")); //$NON-NLS-1$
756:                    GridData gridData = new GridData();
757:                    gridData.horizontalSpan = 2;
758:                    honorTransientButton.setLayoutData(gridData);
759:                    honorTransientButton.addSelectionListener(this );
760:                    Group onLoadGroup = new Group(this , SWT.NO_RADIO_GROUP
761:                            | SWT.SHADOW_NONE);
762:                    onLoadGroup.setText(NonPortableMessages
763:                            .getString("ON_LOAD")); //$NON-NLS-1$
764:                    onLoadGroup.setLayout(new GridLayout(2, false));
765:                    doNothingButton = new Button(onLoadGroup, SWT.RADIO);
766:                    doNothingButton.setText(NonPortableMessages
767:                            .getString("DO_NOTHING")); //$NON-NLS-1$
768:                    gridData = new GridData();
769:                    gridData.horizontalSpan = 2;
770:                    doNothingButton.setLayoutData(gridData);
771:                    doNothingButton.addSelectionListener(this );
772:                    callMethodButton = new Button(onLoadGroup, SWT.RADIO);
773:                    callMethodButton.setText(NonPortableMessages
774:                            .getString("CALL_METHOD")); //$NON-NLS-1$
775:                    callMethodButton.setLayoutData(new GridData(SWT.BEGINNING,
776:                            SWT.BEGINNING, false, false));
777:                    callMethodButton.addSelectionListener(this );
778:                    callMethodCombo = new Combo(onLoadGroup, SWT.BORDER);
779:                    callMethodCombo.setLayoutData(new GridData(
780:                            GridData.FILL_HORIZONTAL));
781:                    callMethodCombo.addFocusListener(new FocusAdapter() {
782:                        public void focusLost(FocusEvent e) {
783:                            OnLoad onLoad = include.getOnLoad();
784:                            onLoad.setMethod(callMethodCombo.getText());
785:                        }
786:                    });
787:                    executeCodeButton = new Button(onLoadGroup, SWT.RADIO);
788:                    executeCodeButton.setText(NonPortableMessages
789:                            .getString("EXECUTE_CODE")); //$NON-NLS-1$
790:                    executeCodeButton.setLayoutData(new GridData(SWT.BEGINNING,
791:                            SWT.BEGINNING, false, false));
792:                    executeCodeButton.addSelectionListener(this );
793:                    executeCodeText = new Text(onLoadGroup, SWT.MULTI
794:                            | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
795:                    gridData = new GridData(GridData.FILL_BOTH);
796:                    gridData.widthHint = SWTUtil.textColumnsToPixels(
797:                            executeCodeText, 60);
798:                    gridData.heightHint = SWTUtil.textRowsToPixels(
799:                            executeCodeText, 3);
800:                    executeCodeText.setLayoutData(gridData);
801:                    executeCodeText.addModifyListener(new ModifyListener() {
802:                        public void modifyText(ModifyEvent e) {
803:                            if (include == null)
804:                                return;
805:                            OnLoad onLoad = include.getOnLoad();
806:                            if (onLoad == null)
807:                                return;
808:                            String executeText = executeCodeText.getText();
809:                            onLoad.setExecute(executeText);
810:                        }
811:                    });
812:                    gridData = new GridData(GridData.FILL_BOTH);
813:                    gridData.horizontalSpan = 2;
814:                    onLoadGroup.setLayoutData(gridData);
815:                }
816:
817:                void setInclude(Include include) {
818:                    this .include = include;
819:                    includePatternText.setText(include.getClassExpression());
820:                    honorTransientButton.setSelection(include
821:                            .getHonorTransient());
822:                    OnLoad onLoad = include.getOnLoad();
823:                    if (onLoad != null) {
824:                        if (onLoad.isSetExecute()) {
825:                            setExecuteCode();
826:                        } else if (onLoad.isSetMethod()) {
827:                            setCallMethod();
828:                        }
829:                    } else {
830:                        setDoNothing();
831:                    }
832:                }
833:
834:                private void setExecuteCode() {
835:                    OnLoad onLoad = include.getOnLoad();
836:
837:                    executeCodeButton.setSelection(true);
838:                    executeCodeText.setEnabled(true);
839:                    executeCodeText.setText(onLoad != null
840:                            && onLoad.isSetExecute() ? onLoad.getExecute()
841:                            : EMPTY_STRING);
842:                    doNothingButton.setSelection(false);
843:                    callMethodButton.setSelection(false);
844:                    callMethodCombo.setEnabled(false);
845:                    callMethodCombo.setText(EMPTY_STRING);
846:                }
847:
848:                private void setCallMethod() {
849:                    OnLoad onLoad = include.getOnLoad();
850:
851:                    executeCodeButton.setSelection(false);
852:                    executeCodeText.setEnabled(false);
853:                    executeCodeText.setText(EMPTY_STRING);
854:                    doNothingButton.setSelection(false);
855:                    callMethodButton.setSelection(true);
856:                    callMethodCombo.setEnabled(true);
857:                    initMethodCombo();
858:                    callMethodCombo.setText(onLoad != null
859:                            && onLoad.isSetMethod() ? onLoad.getMethod()
860:                            : EMPTY_STRING);
861:                }
862:
863:                private void setDoNothing() {
864:                    executeCodeButton.setSelection(false);
865:                    executeCodeText.setEnabled(false);
866:                    executeCodeText.setText(EMPTY_STRING);
867:                    doNothingButton.setSelection(true);
868:                    callMethodButton.setSelection(false);
869:                    callMethodCombo.setEnabled(false);
870:                    callMethodCombo.setText(EMPTY_STRING);
871:                }
872:
873:                private void initMethodCombo() {
874:                    callMethodCombo.removeAll();
875:
876:                    try {
877:                        IType type = fJavaProject.findType(include
878:                                .getClassExpression());
879:                        if (type != null) {
880:                            IMethod[] methods = type.getMethods();
881:                            for (int i = 0; i < methods.length; i++) {
882:                                if (methods[i].getParameterNames().length == 0) {
883:                                    callMethodCombo.add(methods[i]
884:                                            .getElementName());
885:                                }
886:                            }
887:                        }
888:                    } catch (JavaModelException jme) {/**/
889:                    }
890:                }
891:
892:                public void widgetDefaultSelected(SelectionEvent e) {/**/
893:                }
894:
895:                public void widgetSelected(SelectionEvent e) {
896:                    OnLoad onLoad = include.getOnLoad();
897:
898:                    if (e.widget == doNothingButton
899:                            && doNothingButton.getSelection()) {
900:                        setDoNothing();
901:                        include.unsetOnLoad();
902:                    } else if (e.widget == executeCodeButton
903:                            && executeCodeButton.getSelection()) {
904:                        setExecuteCode();
905:                        if (onLoad != null) {
906:                            onLoad.unsetMethod();
907:                        } else {
908:                            include.addNewOnLoad();
909:                        }
910:                    } else if (e.widget == callMethodButton
911:                            && callMethodButton.getSelection()) {
912:                        setCallMethod();
913:                        if (onLoad != null) {
914:                            onLoad.unsetExecute();
915:                        } else {
916:                            include.addNewOnLoad();
917:                        }
918:                    } else if (e.widget == honorTransientButton) {
919:                        include.setHonorTransient(honorTransientButton
920:                                .getSelection());
921:                    }
922:                }
923:            }
924:
925:            protected abstract String getDialogSettingsSectionName();
926:
927:            protected abstract void initIssueList();
928:
929:            protected abstract AbstractResolutionAction[] createActions(
930:                    AbstractWorkState workState);
931:
932:            protected abstract boolean anySelectedActions();
933:
934:            protected abstract void handleTreeSelectionChange();
935:
936:            protected abstract void createIssueDescriptionArea(Composite parent);
937:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.