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


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 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.ide.dialogs;
011:
012:        import org.eclipse.core.filesystem.EFS;
013:        import org.eclipse.core.filesystem.IFileInfo;
014:        import org.eclipse.core.filesystem.IFileStore;
015:        import org.eclipse.core.filesystem.URIUtil;
016:        import org.eclipse.core.runtime.CoreException;
017:        import org.eclipse.core.runtime.IPath;
018:        import org.eclipse.core.runtime.Path;
019:        import org.eclipse.jface.dialogs.ErrorDialog;
020:        import org.eclipse.jface.dialogs.IDialogConstants;
021:        import org.eclipse.jface.window.Window;
022:        import org.eclipse.osgi.util.NLS;
023:        import org.eclipse.swt.widgets.Button;
024:        import org.eclipse.swt.widgets.Composite;
025:        import org.eclipse.swt.widgets.Control;
026:        import org.eclipse.swt.widgets.Event;
027:        import org.eclipse.swt.widgets.Listener;
028:        import org.eclipse.swt.widgets.Shell;
029:        import org.eclipse.ui.PlatformUI;
030:        import org.eclipse.ui.dialogs.SelectionDialog;
031:        import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
032:        import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
033:        import org.eclipse.ui.internal.ide.dialogs.FileFolderSelectionDialog;
034:        import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
035:        import org.eclipse.ui.internal.ide.dialogs.PathVariablesGroup;
036:
037:        /**
038:         * A selection dialog which shows the path variables defined in the 
039:         * workspace.
040:         * The <code>getResult</code> method returns the name(s) of the 
041:         * selected path variable(s).
042:         * <p>
043:         * This class may be instantiated; it is not intended to be subclassed.
044:         * </p>
045:         * <p>
046:         * Example:
047:         * <pre>
048:         *  PathVariableSelectionDialog dialog =
049:         *    new PathVariableSelectionDialog(getShell(), IResource.FOLDER);
050:         *	dialog.open();
051:         *	String[] result = (String[]) dialog.getResult();
052:         * </pre> 	
053:         * </p>
054:         * 
055:         * @since 3.1
056:         */
057:        public final class PathVariableSelectionDialog extends SelectionDialog {
058:            private static final int EXTEND_ID = IDialogConstants.CLIENT_ID + 1;
059:
060:            private PathVariablesGroup pathVariablesGroup;
061:
062:            private int variableType;
063:
064:            /**
065:             * Creates a path variable selection dialog.
066:             *
067:             * @param parentShell the parent shell
068:             * @param variableType the type of variables that are displayed in 
069:             * 	this dialog. <code>IResource.FILE</code> and/or <code>IResource.FOLDER</code>
070:             * 	logically ORed together.
071:             */
072:            public PathVariableSelectionDialog(Shell parentShell,
073:                    int variableType) {
074:                super (parentShell);
075:                setTitle(IDEWorkbenchMessages.PathVariableSelectionDialog_title);
076:                this .variableType = variableType;
077:                pathVariablesGroup = new PathVariablesGroup(false,
078:                        variableType, new Listener() {
079:                            /* (non-Javadoc)
080:                             * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
081:                             */
082:                            public void handleEvent(Event event) {
083:                                updateExtendButtonState();
084:                            }
085:                        });
086:            }
087:
088:            /* (non-Javadoc)
089:             * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
090:             */
091:            protected void buttonPressed(int buttonId) {
092:                if (buttonId == EXTEND_ID) {
093:                    FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(
094:                            getShell(), false, variableType);
095:                    PathVariablesGroup.PathVariableElement selection = pathVariablesGroup
096:                            .getSelection()[0];
097:                    dialog
098:                            .setTitle(IDEWorkbenchMessages.PathVariableSelectionDialog_ExtensionDialog_title);
099:                    dialog
100:                            .setMessage(NLS
101:                                    .bind(
102:                                            IDEWorkbenchMessages.PathVariableSelectionDialog_ExtensionDialog_description,
103:                                            selection.name));
104:                    //XXX This only works for variables that refer to local file system locations
105:                    try {
106:                        dialog.setInput(EFS.getStore(URIUtil
107:                                .toURI(selection.path)));
108:                    } catch (CoreException e) {
109:                        ErrorDialog.openError(getShell(), null, null, e
110:                                .getStatus());
111:                    }
112:                    if (dialog.open() == Window.OK
113:                            && pathVariablesGroup.performOk()) {
114:                        setExtensionResult(selection, (IFileStore) dialog
115:                                .getResult()[0]);
116:                        super .okPressed();
117:                    }
118:                } else {
119:                    super .buttonPressed(buttonId);
120:                }
121:            }
122:
123:            /* (non-Javadoc)
124:             * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
125:             */
126:            protected void configureShell(Shell shell) {
127:                super .configureShell(shell);
128:                PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
129:                        IIDEHelpContextIds.PATH_VARIABLE_SELECTION_DIALOG);
130:            }
131:
132:            /* (non-Javadoc)
133:             * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
134:             */
135:            protected void createButtonsForButtonBar(Composite parent) {
136:                createButton(parent, IDialogConstants.OK_ID,
137:                        IDialogConstants.OK_LABEL, true);
138:                createButton(
139:                        parent,
140:                        EXTEND_ID,
141:                        IDEWorkbenchMessages.PathVariableSelectionDialog_extendButton,
142:                        false);
143:                createButton(parent, IDialogConstants.CANCEL_ID,
144:                        IDialogConstants.CANCEL_LABEL, false);
145:                updateExtendButtonState();
146:            }
147:
148:            /* (non-Javadoc)
149:             * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
150:             */
151:            protected Control createDialogArea(Composite parent) {
152:                // create composite 
153:                Composite dialogArea = (Composite) super 
154:                        .createDialogArea(parent);
155:
156:                pathVariablesGroup.createContents(dialogArea);
157:                return dialogArea;
158:            }
159:
160:            /* (non-Javadoc)
161:             * @see org.eclipse.jface.window.Window#close()
162:             */
163:            public boolean close() {
164:                pathVariablesGroup.dispose();
165:                return super .close();
166:            }
167:
168:            /* (non-Javadoc)
169:             * @see org.eclipse.jface.dialogs.Dialog#okPressed()
170:             */
171:            protected void okPressed() {
172:                //Sets the dialog result to the selected path variable name(s). 
173:                if (pathVariablesGroup.performOk()) {
174:                    PathVariablesGroup.PathVariableElement[] selection = pathVariablesGroup
175:                            .getSelection();
176:                    String[] variableNames = new String[selection.length];
177:
178:                    for (int i = 0; i < selection.length; i++) {
179:                        variableNames[i] = selection[i].name;
180:                    }
181:                    setSelectionResult(variableNames);
182:                } else {
183:                    setSelectionResult(null);
184:                }
185:                super .okPressed();
186:            }
187:
188:            /**
189:             * Sets the dialog result to the concatenated variable name and extension.
190:             * 
191:             * @param variable variable selected in the variables list and extended
192:             * 	by <code>extensionFile</code>
193:             * @param extensionFile file selected to extend the variable.
194:             */
195:            private void setExtensionResult(
196:                    PathVariablesGroup.PathVariableElement variable,
197:                    IFileStore extensionFile) {
198:                IPath extensionPath = new Path(extensionFile.toString());
199:                int matchCount = extensionPath
200:                        .matchingFirstSegments(variable.path);
201:                IPath resultPath = new Path(variable.name);
202:
203:                extensionPath = extensionPath.removeFirstSegments(matchCount);
204:                resultPath = resultPath.append(extensionPath);
205:                setSelectionResult(new String[] { resultPath.toOSString() });
206:            }
207:
208:            /**
209:             * Updates the enabled state of the Extend button based on the 
210:             * current variable selection.
211:             */
212:            private void updateExtendButtonState() {
213:                PathVariablesGroup.PathVariableElement[] selection = pathVariablesGroup
214:                        .getSelection();
215:                Button extendButton = getButton(EXTEND_ID);
216:
217:                if (extendButton == null) {
218:                    return;
219:                }
220:                if (selection.length == 1) {
221:                    IFileInfo info = IDEResourceInfoUtils
222:                            .getFileInfo(selection[0].path);
223:                    if (info.exists() && info.isDirectory()) {
224:                        extendButton.setEnabled(true);
225:                    } else {
226:                        extendButton.setEnabled(false);
227:                    }
228:
229:                } else {
230:                    extendButton.setEnabled(false);
231:                }
232:            }
233:
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.