Source Code Cross Referenced for EnablementDialog.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » activities » ws » 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 » IDE Eclipse » ui workbench » org.eclipse.ui.internal.activities.ws 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.activities.ws;
011:
012:        import com.ibm.icu.text.MessageFormat;
013:        import java.util.Collection;
014:        import java.util.HashSet;
015:        import java.util.Properties;
016:        import java.util.ResourceBundle;
017:        import java.util.Set;
018:
019:        import org.eclipse.jface.dialogs.Dialog;
020:        import org.eclipse.jface.dialogs.IDialogConstants;
021:        import org.eclipse.jface.viewers.CheckStateChangedEvent;
022:        import org.eclipse.jface.viewers.CheckboxTableViewer;
023:        import org.eclipse.jface.viewers.ICheckStateListener;
024:        import org.eclipse.jface.viewers.ISelectionChangedListener;
025:        import org.eclipse.jface.viewers.IStructuredSelection;
026:        import org.eclipse.jface.viewers.SelectionChangedEvent;
027:        import org.eclipse.jface.window.Window;
028:        import org.eclipse.swt.SWT;
029:        import org.eclipse.swt.graphics.Font;
030:        import org.eclipse.swt.layout.GridData;
031:        import org.eclipse.swt.layout.GridLayout;
032:        import org.eclipse.swt.widgets.Button;
033:        import org.eclipse.swt.widgets.Composite;
034:        import org.eclipse.swt.widgets.Control;
035:        import org.eclipse.swt.widgets.Label;
036:        import org.eclipse.swt.widgets.Shell;
037:        import org.eclipse.swt.widgets.Text;
038:        import org.eclipse.ui.PlatformUI;
039:        import org.eclipse.ui.activities.IActivity;
040:        import org.eclipse.ui.activities.IActivityManager;
041:        import org.eclipse.ui.activities.NotDefinedException;
042:        import org.eclipse.ui.activities.WorkbenchTriggerPointAdvisor;
043:
044:        /**
045:         * Dialog that will prompt the user and confirm that they wish to activate a set
046:         * of activities.
047:         * 
048:         * @since 3.0
049:         */
050:        public class EnablementDialog extends Dialog {
051:
052:            /**
053:             * The translation bundle in which to look up internationalized text.
054:             */
055:            private final static ResourceBundle RESOURCE_BUNDLE = ResourceBundle
056:                    .getBundle(EnablementDialog.class.getName());
057:
058:            private Button dontAskButton;
059:
060:            private Set activitiesToEnable = new HashSet(7);
061:
062:            private Collection activityIds;
063:
064:            private boolean dontAsk;
065:
066:            private Button detailsButton;
067:
068:            boolean showDetails = false;
069:
070:            private Composite detailsComposite;
071:
072:            private Label detailsLabel;
073:
074:            private String selectedActivity;
075:
076:            private Text detailsText;
077:
078:            private Properties strings;
079:
080:            /**
081:             * Create a new instance of the reciever.
082:             * 
083:             * @param parentShell the parent shell
084:             * @param activityIds the candidate activities
085:             * @param strings string overrides
086:             */
087:            public EnablementDialog(Shell parentShell, Collection activityIds,
088:                    Properties strings) {
089:                super (parentShell);
090:                this .activityIds = activityIds;
091:                this .strings = strings;
092:            }
093:
094:            /* (non-Javadoc)
095:             * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
096:             */
097:            protected Control createDialogArea(Composite parent) {
098:                Composite composite = (Composite) super 
099:                        .createDialogArea(parent);
100:                Font dialogFont = parent.getFont();
101:                composite.setFont(dialogFont);
102:                Label text = new Label(composite, SWT.NONE);
103:                text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
104:                text.setFont(dialogFont);
105:                IActivityManager manager = PlatformUI.getWorkbench()
106:                        .getActivitySupport().getActivityManager();
107:
108:                if (activityIds.size() == 1) {
109:                    String activityId = (String) activityIds.iterator().next();
110:                    activitiesToEnable.add(activityId);
111:                    selectedActivity = activityId;
112:
113:                    IActivity activity = manager.getActivity(activityId);
114:                    String activityText;
115:                    try {
116:                        activityText = activity.getName();
117:                    } catch (NotDefinedException e) {
118:                        activityText = activity.getId();
119:                    }
120:                    text.setText(MessageFormat.format(RESOURCE_BUNDLE
121:                            .getString("requiresSingle"), //$NON-NLS-1$
122:                            new Object[] { activityText }));
123:
124:                    text = new Label(composite, SWT.NONE);
125:                    text
126:                            .setText(strings
127:                                    .getProperty(
128:                                            WorkbenchTriggerPointAdvisor.PROCEED_SINGLE,
129:                                            RESOURCE_BUNDLE
130:                                                    .getString(WorkbenchTriggerPointAdvisor.PROCEED_SINGLE)));
131:                    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
132:                    text.setFont(dialogFont);
133:                } else {
134:                    text.setText(RESOURCE_BUNDLE.getString("requiresMulti")); //$NON-NLS-1$
135:                    Set activityIdsCopy = new HashSet(activityIds);
136:                    CheckboxTableViewer viewer = CheckboxTableViewer
137:                            .newCheckList(composite, SWT.CHECK | SWT.BORDER
138:                                    | SWT.SINGLE);
139:                    viewer.setContentProvider(new ActivityContentProvider());
140:                    viewer.setLabelProvider(new ActivityLabelProvider(manager));
141:                    viewer.setInput(activityIdsCopy);
142:                    viewer.setCheckedElements(activityIdsCopy.toArray());
143:                    viewer.addCheckStateListener(new ICheckStateListener() {
144:
145:                        /* (non-Javadoc)
146:                         * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
147:                         */
148:                        public void checkStateChanged(
149:                                CheckStateChangedEvent event) {
150:                            if (event.getChecked()) {
151:                                activitiesToEnable.add(event.getElement());
152:                            } else {
153:                                activitiesToEnable.remove(event.getElement());
154:                            }
155:
156:                            getButton(Window.OK).setEnabled(
157:                                    !activitiesToEnable.isEmpty());
158:                        }
159:                    });
160:                    viewer
161:                            .addSelectionChangedListener(new ISelectionChangedListener() {
162:                                /* (non-Javadoc)
163:                                 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
164:                                 */
165:                                public void selectionChanged(
166:                                        SelectionChangedEvent event) {
167:                                    selectedActivity = (String) ((IStructuredSelection) event
168:                                            .getSelection()).getFirstElement();
169:                                    setDetails();
170:                                }
171:                            });
172:                    activitiesToEnable.addAll(activityIdsCopy);
173:
174:                    viewer.getControl().setLayoutData(
175:                            new GridData(GridData.FILL_HORIZONTAL));
176:                    viewer.getControl().setFont(dialogFont);
177:
178:                    text = new Label(composite, SWT.NONE);
179:                    text
180:                            .setText(strings
181:                                    .getProperty(
182:                                            WorkbenchTriggerPointAdvisor.PROCEED_MULTI,
183:                                            RESOURCE_BUNDLE
184:                                                    .getString(WorkbenchTriggerPointAdvisor.PROCEED_MULTI)));
185:                    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
186:                    text.setFont(dialogFont);
187:                }
188:                Label seperator = new Label(composite, SWT.SEPARATOR
189:                        | SWT.HORIZONTAL);
190:                seperator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
191:
192:                dontAskButton = new Button(composite, SWT.CHECK);
193:                dontAskButton.setSelection(false);
194:                dontAskButton.setLayoutData(new GridData(
195:                        GridData.FILL_HORIZONTAL));
196:                dontAskButton
197:                        .setText(strings
198:                                .getProperty(
199:                                        WorkbenchTriggerPointAdvisor.DONT_ASK,
200:                                        RESOURCE_BUNDLE
201:                                                .getString(WorkbenchTriggerPointAdvisor.DONT_ASK)));
202:                dontAskButton.setFont(dialogFont);
203:
204:                detailsComposite = new Composite(composite, SWT.NONE);
205:                GridLayout layout = new GridLayout();
206:                layout.marginHeight = 0;
207:                layout.marginWidth = 0;
208:                detailsComposite.setLayout(layout);
209:                detailsLabel = new Label(detailsComposite, SWT.NONE);
210:                detailsLabel.setLayoutData(new GridData(
211:                        GridData.FILL_HORIZONTAL));
212:                detailsLabel.setFont(dialogFont);
213:
214:                detailsText = new Text(detailsComposite, SWT.WRAP
215:                        | SWT.V_SCROLL | SWT.BORDER | SWT.READ_ONLY);
216:                detailsText.setLayoutData(new GridData(GridData.FILL_BOTH));
217:                detailsText.setFont(dialogFont);
218:
219:                setDetails();
220:
221:                GridData data = new GridData(GridData.FILL_BOTH);
222:                detailsComposite.setLayoutData(data);
223:                setDetailHints();
224:
225:                return composite;
226:            }
227:
228:            /**
229:             * Set the text of the detail label and text area.
230:             */
231:            protected void setDetails() {
232:                if (selectedActivity == null) {
233:                    detailsLabel
234:                            .setText(strings
235:                                    .getProperty(
236:                                            WorkbenchTriggerPointAdvisor.NO_DETAILS,
237:                                            RESOURCE_BUNDLE
238:                                                    .getString(WorkbenchTriggerPointAdvisor.NO_DETAILS)));
239:                    detailsText.setText(""); //$NON-NLS-1$
240:                } else {
241:                    IActivity activity = PlatformUI.getWorkbench()
242:                            .getActivitySupport().getActivityManager()
243:                            .getActivity(selectedActivity);
244:                    String name;
245:                    try {
246:                        name = activity.getName();
247:                    } catch (NotDefinedException e1) {
248:                        name = selectedActivity;
249:                    }
250:                    String desc;
251:                    try {
252:                        desc = activity.getDescription();
253:                    } catch (NotDefinedException e) {
254:                        desc = RESOURCE_BUNDLE.getString("noDescAvailable"); //$NON-NLS-1$
255:                    }
256:                    detailsLabel.setText(MessageFormat.format(RESOURCE_BUNDLE
257:                            .getString("detailsLabel"), new Object[] { name })); //$NON-NLS-1$
258:                    detailsText.setText(desc);
259:                }
260:            }
261:
262:            /**
263:             * 
264:             */
265:            protected void setDetailHints() {
266:                GridData data = (GridData) detailsComposite.getLayoutData();
267:                if (showDetails) {
268:                    Composite parent = detailsComposite.getParent();
269:                    data.widthHint = parent.getSize().x
270:                            - ((GridLayout) parent.getLayout()).marginWidth * 2;
271:                    data.heightHint = convertHeightInCharsToPixels(5);
272:                } else {
273:                    data.widthHint = 0;
274:                    data.heightHint = 0;
275:                }
276:            }
277:
278:            /**
279:             * Set the label of the detail button based on whether we're currently showing the description text.
280:             */
281:            private void setDetailButtonLabel() {
282:                if (!showDetails) {
283:                    detailsButton.setText(RESOURCE_BUNDLE
284:                            .getString("showDetails")); //$NON-NLS-1$
285:                } else {
286:                    detailsButton.setText(RESOURCE_BUNDLE
287:                            .getString("hideDetails")); //$NON-NLS-1$        
288:                }
289:            }
290:
291:            /* (non-Javadoc)
292:             * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
293:             */
294:            protected void configureShell(Shell newShell) {
295:                super .configureShell(newShell);
296:                newShell.setText(RESOURCE_BUNDLE.getString("title")); //$NON-NLS-1$
297:            }
298:
299:            /** 
300:             * @return Returns whether the user has declared that there is to be no further 
301:             * prompting for the supplied activities
302:             */
303:            public boolean getDontAsk() {
304:                return dontAsk;
305:            }
306:
307:            /**
308:             * @return Returns the activities to enable
309:             */
310:            public Set getActivitiesToEnable() {
311:                return activitiesToEnable;
312:            }
313:
314:            /* (non-Javadoc)
315:             * @see org.eclipse.jface.dialogs.Dialog#okPressed()
316:             */
317:            protected void okPressed() {
318:                dontAsk = dontAskButton.getSelection();
319:                super .okPressed();
320:            }
321:
322:            /* (non-Javadoc)
323:             * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
324:             */
325:            protected void createButtonsForButtonBar(Composite parent) {
326:                super .createButtonsForButtonBar(parent);
327:                detailsButton = createButton(parent,
328:                        IDialogConstants.DETAILS_ID, "", false); //$NON-NLS-1$
329:                setDetailButtonLabel();
330:            }
331:
332:            /* (non-Javadoc)
333:             * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
334:             */
335:            protected void buttonPressed(int buttonId) {
336:                if (buttonId == IDialogConstants.DETAILS_ID) {
337:                    detailsPressed();
338:                    return;
339:                }
340:                super .buttonPressed(buttonId);
341:            }
342:
343:            /**
344:             * Handles selection of the Details button.
345:             */
346:            private void detailsPressed() {
347:                showDetails = !showDetails;
348:                setDetailButtonLabel();
349:                setDetailHints();
350:                setDetails();
351:                ((Composite) getDialogArea()).layout(true);
352:                getShell().setSize(
353:                        getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
354:            }
355:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.