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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.dialogs;
011:
012:        import org.eclipse.jface.dialogs.IDialogConstants;
013:        import org.eclipse.jface.dialogs.MessageDialog;
014:        import org.eclipse.jface.viewers.ISelectionChangedListener;
015:        import org.eclipse.jface.viewers.IStructuredSelection;
016:        import org.eclipse.jface.viewers.SelectionChangedEvent;
017:        import org.eclipse.jface.viewers.StructuredSelection;
018:        import org.eclipse.jface.viewers.TableViewer;
019:        import org.eclipse.jface.viewers.ViewerComparator;
020:        import org.eclipse.osgi.util.NLS;
021:        import org.eclipse.swt.SWT;
022:        import org.eclipse.swt.events.ModifyListener;
023:        import org.eclipse.swt.graphics.Font;
024:        import org.eclipse.swt.layout.GridData;
025:        import org.eclipse.swt.layout.GridLayout;
026:        import org.eclipse.swt.widgets.Button;
027:        import org.eclipse.swt.widgets.Composite;
028:        import org.eclipse.swt.widgets.Control;
029:        import org.eclipse.swt.widgets.Label;
030:        import org.eclipse.swt.widgets.Shell;
031:        import org.eclipse.swt.widgets.Text;
032:        import org.eclipse.ui.IPerspectiveDescriptor;
033:        import org.eclipse.ui.PlatformUI;
034:        import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
035:        import org.eclipse.ui.internal.WorkbenchMessages;
036:        import org.eclipse.ui.internal.activities.ws.ActivityViewerFilter;
037:        import org.eclipse.ui.internal.registry.PerspectiveRegistry;
038:        import org.eclipse.ui.model.PerspectiveLabelProvider;
039:
040:        /**
041:         * The SavePerspectiveDialog can be used to get the name of a new
042:         * perspective or the descriptor of an old perspective.  The results
043:         * are returned by <code>getNewPerspName</code> and 
044:         * <code>getOldPersp</code>.
045:         */
046:        public class SavePerspectiveDialog extends
047:                org.eclipse.jface.dialogs.Dialog implements 
048:                ISelectionChangedListener, ModifyListener {
049:            private Text text;
050:
051:            private TableViewer list;
052:
053:            private Button okButton;
054:
055:            private PerspectiveRegistry perspReg;
056:
057:            private String perspName;
058:
059:            private IPerspectiveDescriptor persp;
060:
061:            private IPerspectiveDescriptor initialSelection;
062:
063:            private boolean ignoreSelection = false;
064:
065:            final private static int LIST_WIDTH = 40;
066:
067:            final private static int TEXT_WIDTH = 40;
068:
069:            final private static int LIST_HEIGHT = 14;
070:
071:            /**
072:             * PerspectiveDialog constructor comment.
073:             * @param parentShell the parent shell
074:             * @param perspReg the perspective registry
075:             */
076:            public SavePerspectiveDialog(Shell parentShell,
077:                    PerspectiveRegistry perspReg) {
078:                super (parentShell);
079:                this .perspReg = perspReg;
080:            }
081:
082:            /* (non-Javadoc)
083:             * Method declared in Window.
084:             */
085:            protected void configureShell(Shell shell) {
086:                super .configureShell(shell);
087:                shell.setText(WorkbenchMessages.SavePerspective_shellTitle);
088:                PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
089:                        IWorkbenchHelpContextIds.SAVE_PERSPECTIVE_DIALOG);
090:            }
091:
092:            /**
093:             * Add buttons to the dialog's button bar.
094:             *
095:             * @param parent the button bar composite
096:             */
097:            protected void createButtonsForButtonBar(Composite parent) {
098:                okButton = createButton(parent, IDialogConstants.OK_ID,
099:                        IDialogConstants.OK_LABEL, true);
100:                createButton(parent, IDialogConstants.CANCEL_ID,
101:                        IDialogConstants.CANCEL_LABEL, false);
102:                updateButtons();
103:                text.setFocus();
104:            }
105:
106:            /**
107:             * Creates and returns the contents of the upper part 
108:             * of this dialog (above the button bar).
109:             *
110:             * @param parent the parent composite to contain the dialog area
111:             * @return the dialog area control
112:             */
113:            protected Control createDialogArea(Composite parent) {
114:                Font font = parent.getFont();
115:                // Run super.
116:                Composite composite = (Composite) super 
117:                        .createDialogArea(parent);
118:
119:                // description
120:                Label descLabel = new Label(composite, SWT.WRAP);
121:                descLabel
122:                        .setText(WorkbenchMessages.SavePerspectiveDialog_description);
123:                descLabel.setFont(parent.getFont());
124:
125:                // Spacer.
126:                Label label = new Label(composite, SWT.NONE);
127:                GridData data = new GridData();
128:                data.heightHint = 8;
129:                label.setLayoutData(data);
130:
131:                // Create name group.
132:                Composite nameGroup = new Composite(composite, SWT.NONE);
133:                nameGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
134:                GridLayout layout = new GridLayout();
135:                layout.numColumns = 2;
136:                layout.marginWidth = layout.marginHeight = 0;
137:                nameGroup.setLayout(layout);
138:
139:                // Create name label.
140:                label = new Label(nameGroup, SWT.NONE);
141:                label.setText(WorkbenchMessages.SavePerspective_name);
142:                label.setFont(font);
143:
144:                // Add text field.
145:                text = new Text(nameGroup, SWT.BORDER);
146:                text.setFocus();
147:                data = new GridData(GridData.FILL_HORIZONTAL);
148:                data.widthHint = convertWidthInCharsToPixels(TEXT_WIDTH);
149:                text.setLayoutData(data);
150:                text.setFont(font);
151:                text.addModifyListener(this );
152:
153:                // Spacer.
154:                label = new Label(composite, SWT.NONE);
155:                data = new GridData();
156:                data.heightHint = 5;
157:                label.setLayoutData(data);
158:
159:                // Another label.
160:                label = new Label(composite, SWT.NONE);
161:                label.setText(WorkbenchMessages.SavePerspective_existing);
162:                label.setFont(font);
163:
164:                // Add perspective list.
165:                list = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL
166:                        | SWT.BORDER);
167:                list.setLabelProvider(new PerspectiveLabelProvider());
168:                list.setContentProvider(new PerspContentProvider());
169:                list.addFilter(new ActivityViewerFilter());
170:                list.setComparator(new ViewerComparator());
171:                list.setInput(perspReg);
172:                list.addSelectionChangedListener(this );
173:                list.getTable().setFont(font);
174:
175:                // Set perspective list size.
176:                Control ctrl = list.getControl();
177:                GridData spec = new GridData(GridData.FILL_BOTH);
178:                spec.widthHint = convertWidthInCharsToPixels(LIST_WIDTH);
179:                spec.heightHint = convertHeightInCharsToPixels(LIST_HEIGHT);
180:                ctrl.setLayoutData(spec);
181:
182:                // Set the initial selection
183:                if (initialSelection != null) {
184:                    StructuredSelection sel = new StructuredSelection(
185:                            initialSelection);
186:                    list.setSelection(sel, true);
187:                }
188:                text.selectAll();
189:
190:                // Return results.
191:                return composite;
192:            }
193:
194:            /**
195:             * Returns the target name.
196:             * 
197:             * @return the target name
198:             */
199:            public IPerspectiveDescriptor getPersp() {
200:                return persp;
201:            }
202:
203:            /**
204:             * Returns the target name.
205:             * 
206:             * @return the target name
207:             */
208:            public String getPerspName() {
209:                return perspName;
210:            }
211:
212:            /**
213:             * The user has typed some text.
214:             */
215:            public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
216:                // Get text.
217:                perspName = text.getText();
218:
219:                // Transfer text to persp list.
220:                ignoreSelection = true;
221:                persp = perspReg.findPerspectiveWithLabel(perspName);
222:                if (persp == null) {
223:                    StructuredSelection sel = new StructuredSelection();
224:                    list.setSelection(sel);
225:                } else {
226:                    StructuredSelection sel = new StructuredSelection(persp);
227:                    list.setSelection(sel);
228:                }
229:                ignoreSelection = false;
230:
231:                updateButtons();
232:            }
233:
234:            /**
235:             * Notifies that the ok button of this dialog has been pressed.
236:             * <p>
237:             * The default implementation of this framework method sets
238:             * this dialog's return code to <code>Window.OK</code>
239:             * and closes the dialog. Subclasses may override.
240:             * </p>
241:             */
242:            protected void okPressed() {
243:                perspName = text.getText();
244:                persp = perspReg.findPerspectiveWithLabel(perspName);
245:                if (persp != null) {
246:                    // Confirm ok to overwrite
247:                    String message = NLS
248:                            .bind(
249:                                    WorkbenchMessages.SavePerspective_overwriteQuestion,
250:                                    perspName);
251:                    String[] buttons = new String[] {
252:                            IDialogConstants.YES_LABEL,
253:                            IDialogConstants.NO_LABEL,
254:                            IDialogConstants.CANCEL_LABEL };
255:                    MessageDialog d = new MessageDialog(this .getShell(),
256:                            WorkbenchMessages.SavePerspective_overwriteTitle,
257:                            null, message, MessageDialog.QUESTION, buttons, 0);
258:
259:                    switch (d.open()) {
260:                    case 0: //yes
261:                        break;
262:                    case 1: //no
263:                        return;
264:                    case 2: //cancel
265:                        cancelPressed();
266:                        return;
267:                    default:
268:                        return;
269:                    }
270:                }
271:
272:                super .okPressed();
273:            }
274:
275:            /**
276:             * Notifies that the selection has changed.
277:             *
278:             * @param event event object describing the change
279:             */
280:            public void selectionChanged(SelectionChangedEvent event) {
281:                // If a selection is caused by modifyText ignore it.
282:                if (ignoreSelection) {
283:                    return;
284:                }
285:
286:                // Get selection.
287:                IStructuredSelection sel = (IStructuredSelection) list
288:                        .getSelection();
289:                persp = null;
290:                if (!sel.isEmpty()) {
291:                    persp = (IPerspectiveDescriptor) sel.getFirstElement();
292:                }
293:
294:                // Transfer selection to text field.
295:                if (persp != null) {
296:                    perspName = persp.getLabel();
297:                    text.setText(perspName);
298:                }
299:
300:                updateButtons();
301:            }
302:
303:            /**
304:             * Sets the initial selection in this dialog.
305:             *
306:             * @param selectedElement the perspective descriptor to select
307:             */
308:            public void setInitialSelection(
309:                    IPerspectiveDescriptor selectedElement) {
310:                initialSelection = selectedElement;
311:            }
312:
313:            /**
314:             * Update the OK button.
315:             */
316:            private void updateButtons() {
317:                if (okButton != null) {
318:                    String label = text.getText();
319:                    okButton.setEnabled(perspReg.validateLabel(label));
320:                }
321:            }
322:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.