Source Code Cross Referenced for ResourceSelectionDialog.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » 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.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.dialogs;
011:
012:        import java.util.ArrayList;
013:        import java.util.Iterator;
014:
015:        import org.eclipse.core.resources.IContainer;
016:        import org.eclipse.core.resources.IResource;
017:        import org.eclipse.core.runtime.CoreException;
018:        import org.eclipse.core.runtime.IAdaptable;
019:        import org.eclipse.jface.viewers.CheckStateChangedEvent;
020:        import org.eclipse.jface.viewers.ICheckStateListener;
021:        import org.eclipse.jface.viewers.ITreeContentProvider;
022:        import org.eclipse.swt.SWT;
023:        import org.eclipse.swt.events.ControlEvent;
024:        import org.eclipse.swt.events.ControlListener;
025:        import org.eclipse.swt.widgets.Composite;
026:        import org.eclipse.swt.widgets.Control;
027:        import org.eclipse.swt.widgets.Shell;
028:        import org.eclipse.swt.widgets.TableColumn;
029:        import org.eclipse.ui.PlatformUI;
030:        import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
031:        import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
032:        import org.eclipse.ui.internal.ide.misc.CheckboxTreeAndListGroup;
033:        import org.eclipse.ui.model.WorkbenchContentProvider;
034:        import org.eclipse.ui.model.WorkbenchLabelProvider;
035:
036:        /**
037:         * A standard resource selection dialog which solicits a list of resources from
038:         * the user. The <code>getResult</code> method returns the selected resources.
039:         * <p>
040:         * This class may be instantiated; it is not intended to be subclassed.
041:         * </p>
042:         * <p>
043:         * Example:
044:         * <pre>
045:         * 	ResourceSelectionDialog dialog =
046:         *		new ResourceSelectionDialog(getShell(), rootResource, msg);
047:         *	dialog.setInitialSelections(selectedResources);
048:         *	dialog.open();
049:         *	return dialog.getResult();
050:         * </pre>
051:         * </p>
052:         */
053:        public class ResourceSelectionDialog extends SelectionDialog {
054:            // the root element to populate the viewer with
055:            private IAdaptable root;
056:
057:            // the visual selection widget group
058:            private CheckboxTreeAndListGroup selectionGroup;
059:
060:            // constants
061:            private final static int SIZING_SELECTION_WIDGET_WIDTH = 400;
062:
063:            private final static int SIZING_SELECTION_WIDGET_HEIGHT = 300;
064:
065:            /**
066:             * Creates a resource selection dialog rooted at the given element.
067:             *
068:             * @param parentShell the parent shell
069:             * @param rootElement the root element to populate this dialog with
070:             * @param message the message to be displayed at the top of this dialog, or
071:             *    <code>null</code> to display a default message
072:             */
073:            public ResourceSelectionDialog(Shell parentShell,
074:                    IAdaptable rootElement, String message) {
075:                super (parentShell);
076:                setTitle(IDEWorkbenchMessages.ResourceSelectionDialog_title);
077:                root = rootElement;
078:                if (message != null) {
079:                    setMessage(message);
080:                } else {
081:                    setMessage(IDEWorkbenchMessages.ResourceSelectionDialog_message);
082:                }
083:            }
084:
085:            /**
086:             * Visually checks the previously-specified elements in the container (left)
087:             * portion of this dialog's resource selection viewer.
088:             */
089:            private void checkInitialSelections() {
090:                Iterator itemsToCheck = getInitialElementSelections()
091:                        .iterator();
092:
093:                while (itemsToCheck.hasNext()) {
094:                    IResource currentElement = (IResource) itemsToCheck.next();
095:
096:                    if (currentElement.getType() == IResource.FILE) {
097:                        selectionGroup.initialCheckListItem(currentElement);
098:                    } else {
099:                        selectionGroup.initialCheckTreeItem(currentElement);
100:                    }
101:                }
102:            }
103:
104:            /**
105:             * @param event the event
106:             */
107:            public void checkStateChanged(CheckStateChangedEvent event) {
108:                getOkButton().setEnabled(
109:                        selectionGroup.getCheckedElementCount() > 0);
110:            }
111:
112:            /* (non-Javadoc)
113:             * Method declared in Window.
114:             */
115:            protected void configureShell(Shell shell) {
116:                super .configureShell(shell);
117:                PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
118:                        IIDEHelpContextIds.RESOURCE_SELECTION_DIALOG);
119:            }
120:
121:            public void create() {
122:                super .create();
123:                initializeDialog();
124:            }
125:
126:            /* (non-Javadoc)
127:             * Method declared on Dialog.
128:             */
129:            protected Control createDialogArea(Composite parent) {
130:                // page group
131:                Composite composite = (Composite) super 
132:                        .createDialogArea(parent);
133:
134:                //create the input element, which has the root resource
135:                //as its only child
136:                ArrayList input = new ArrayList();
137:                input.add(root);
138:
139:                createMessageArea(composite);
140:                selectionGroup = new CheckboxTreeAndListGroup(
141:                        composite,
142:                        input,
143:                        getResourceProvider(IResource.FOLDER
144:                                | IResource.PROJECT | IResource.ROOT),
145:                        WorkbenchLabelProvider
146:                                .getDecoratingWorkbenchLabelProvider(),
147:                        getResourceProvider(IResource.FILE),
148:                        WorkbenchLabelProvider
149:                                .getDecoratingWorkbenchLabelProvider(),
150:                        SWT.NONE,
151:                        // since this page has no other significantly-sized
152:                        // widgets we need to hardcode the combined widget's
153:                        // size, otherwise it will open too small
154:                        SIZING_SELECTION_WIDGET_WIDTH,
155:                        SIZING_SELECTION_WIDGET_HEIGHT);
156:
157:                composite.addControlListener(new ControlListener() {
158:                    public void controlMoved(ControlEvent e) {
159:                    }
160:
161:                    public void controlResized(ControlEvent e) {
162:                        //Also try and reset the size of the columns as appropriate
163:                        TableColumn[] columns = selectionGroup.getListTable()
164:                                .getColumns();
165:                        for (int i = 0; i < columns.length; i++) {
166:                            columns[i].pack();
167:                        }
168:                    }
169:                });
170:
171:                return composite;
172:            }
173:
174:            /**
175:             * Returns a content provider for <code>IResource</code>s that returns 
176:             * only children of the given resource type.
177:             */
178:            private ITreeContentProvider getResourceProvider(
179:                    final int resourceType) {
180:                return new WorkbenchContentProvider() {
181:                    public Object[] getChildren(Object o) {
182:                        if (o instanceof  IContainer) {
183:                            IResource[] members = null;
184:                            try {
185:                                members = ((IContainer) o).members();
186:                            } catch (CoreException e) {
187:                                //just return an empty set of children
188:                                return new Object[0];
189:                            }
190:
191:                            //filter out the desired resource types
192:                            ArrayList results = new ArrayList();
193:                            for (int i = 0; i < members.length; i++) {
194:                                //And the test bits with the resource types to see if they are what we want
195:                                if ((members[i].getType() & resourceType) > 0) {
196:                                    results.add(members[i]);
197:                                }
198:                            }
199:                            return results.toArray();
200:                        }
201:                        //input element case
202:                        if (o instanceof  ArrayList) {
203:                            return ((ArrayList) o).toArray();
204:                        }
205:                        return new Object[0];
206:                    }
207:                };
208:            }
209:
210:            /**
211:             * Initializes this dialog's controls.
212:             */
213:            private void initializeDialog() {
214:                selectionGroup.addCheckStateListener(new ICheckStateListener() {
215:                    public void checkStateChanged(CheckStateChangedEvent event) {
216:                        getOkButton().setEnabled(
217:                                selectionGroup.getCheckedElementCount() > 0);
218:                    }
219:                });
220:
221:                if (getInitialElementSelections().isEmpty()) {
222:                    getOkButton().setEnabled(false);
223:                } else {
224:                    checkInitialSelections();
225:                }
226:            }
227:
228:            /**
229:             * The <code>ResourceSelectionDialog</code> implementation of this 
230:             * <code>Dialog</code> method builds a list of the selected resources for later 
231:             * retrieval by the client and closes this dialog.
232:             */
233:            protected void okPressed() {
234:                Iterator resultEnum = selectionGroup.getAllCheckedListItems();
235:                ArrayList list = new ArrayList();
236:                while (resultEnum.hasNext()) {
237:                    list.add(resultEnum.next());
238:                }
239:                setResult(list);
240:                super.okPressed();
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.