Source Code Cross Referenced for ListSelectionDialog.java in  » IDE-Eclipse » ui-workbench » 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 workbench » 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:         * 	   Sebastian Davids <sdavids@gmx.de> - Fix for bug 90273 - [Dialogs] 
011:         * 			ListSelectionDialog dialog alignment
012:         *******************************************************************************/package org.eclipse.ui.dialogs;
013:
014:        import java.util.ArrayList;
015:        import java.util.Iterator;
016:
017:        import org.eclipse.jface.dialogs.Dialog;
018:        import org.eclipse.jface.dialogs.IDialogConstants;
019:        import org.eclipse.jface.viewers.CheckboxTableViewer;
020:        import org.eclipse.jface.viewers.ILabelProvider;
021:        import org.eclipse.jface.viewers.IStructuredContentProvider;
022:        import org.eclipse.swt.SWT;
023:        import org.eclipse.swt.events.SelectionAdapter;
024:        import org.eclipse.swt.events.SelectionEvent;
025:        import org.eclipse.swt.events.SelectionListener;
026:        import org.eclipse.swt.layout.GridData;
027:        import org.eclipse.swt.layout.GridLayout;
028:        import org.eclipse.swt.widgets.Button;
029:        import org.eclipse.swt.widgets.Composite;
030:        import org.eclipse.swt.widgets.Control;
031:        import org.eclipse.swt.widgets.Shell;
032:        import org.eclipse.ui.PlatformUI;
033:        import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
034:        import org.eclipse.ui.internal.WorkbenchMessages;
035:
036:        /**
037:         * A standard dialog which solicits a list of selections from the user.
038:         * This class is configured with an arbitrary data model represented by content
039:         * and label provider objects. The <code>getResult</code> method returns the
040:         * selected elements.
041:         * <p>
042:         * This class may be instantiated; it is not intended to be subclassed.
043:         * </p>
044:         * <p>
045:         * Example:
046:         * <pre>
047:         * ListSelectionDialog dlg =
048:         *   new ListSelectionDialog(
049:         *       getShell(),
050:         *       input,
051:         *       new BaseWorkbenchContentProvider(),
052:         *		 new WorkbenchLabelProvider(),
053:         *		 "Select the resources to save:");
054:         *	dlg.setInitialSelections(dirtyEditors);
055:         *	dlg.setTitle("Save Resources");
056:         *	dlg.open();
057:         * </pre>
058:         * </p>
059:         */
060:        public class ListSelectionDialog extends SelectionDialog {
061:            // the root element to populate the viewer with
062:            private Object inputElement;
063:
064:            // providers for populating this dialog
065:            private ILabelProvider labelProvider;
066:
067:            private IStructuredContentProvider contentProvider;
068:
069:            // the visual selection widget group
070:            CheckboxTableViewer listViewer;
071:
072:            // sizing constants
073:            private final static int SIZING_SELECTION_WIDGET_HEIGHT = 250;
074:
075:            private final static int SIZING_SELECTION_WIDGET_WIDTH = 300;
076:
077:            /**
078:             * Creates a list selection dialog.
079:             *
080:             * @param parentShell the parent shell
081:             * @param input	the root element to populate this dialog with
082:             * @param contentProvider the content provider for navigating the model
083:             * @param labelProvider the label provider for displaying model elements
084:             * @param message the message to be displayed at the top of this dialog, or
085:             *    <code>null</code> to display a default message
086:             */
087:            public ListSelectionDialog(Shell parentShell, Object input,
088:                    IStructuredContentProvider contentProvider,
089:                    ILabelProvider labelProvider, String message) {
090:                super (parentShell);
091:                setTitle(WorkbenchMessages.ListSelection_title);
092:                inputElement = input;
093:                this .contentProvider = contentProvider;
094:                this .labelProvider = labelProvider;
095:                if (message != null) {
096:                    setMessage(message);
097:                } else {
098:                    setMessage(WorkbenchMessages.ListSelection_message);
099:                }
100:            }
101:
102:            /**
103:             * Add the selection and deselection buttons to the dialog.
104:             * @param composite org.eclipse.swt.widgets.Composite
105:             */
106:            private void addSelectionButtons(Composite composite) {
107:                Composite buttonComposite = new Composite(composite, SWT.NONE);
108:                GridLayout layout = new GridLayout();
109:                layout.numColumns = 0;
110:                layout.marginWidth = 0;
111:                layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
112:                buttonComposite.setLayout(layout);
113:                buttonComposite.setLayoutData(new GridData(SWT.END, SWT.TOP,
114:                        true, false));
115:
116:                Button selectButton = createButton(buttonComposite,
117:                        IDialogConstants.SELECT_ALL_ID, SELECT_ALL_TITLE, false);
118:
119:                SelectionListener listener = new SelectionAdapter() {
120:                    public void widgetSelected(SelectionEvent e) {
121:                        listViewer.setAllChecked(true);
122:                    }
123:                };
124:                selectButton.addSelectionListener(listener);
125:
126:                Button deselectButton = createButton(buttonComposite,
127:                        IDialogConstants.DESELECT_ALL_ID, DESELECT_ALL_TITLE,
128:                        false);
129:
130:                listener = new SelectionAdapter() {
131:                    public void widgetSelected(SelectionEvent e) {
132:                        listViewer.setAllChecked(false);
133:                    }
134:                };
135:                deselectButton.addSelectionListener(listener);
136:            }
137:
138:            /**
139:             * Visually checks the previously-specified elements in this dialog's list 
140:             * viewer.
141:             */
142:            private void checkInitialSelections() {
143:                Iterator itemsToCheck = getInitialElementSelections()
144:                        .iterator();
145:
146:                while (itemsToCheck.hasNext()) {
147:                    listViewer.setChecked(itemsToCheck.next(), true);
148:                }
149:            }
150:
151:            /*
152:             *  (non-Javadoc)
153:             * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
154:             */
155:            protected void configureShell(Shell shell) {
156:                super .configureShell(shell);
157:                PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
158:                        IWorkbenchHelpContextIds.LIST_SELECTION_DIALOG);
159:            }
160:
161:            /* (non-Javadoc)
162:             * Method declared on Dialog.
163:             */
164:            protected Control createDialogArea(Composite parent) {
165:                // page group
166:                Composite composite = (Composite) super 
167:                        .createDialogArea(parent);
168:
169:                initializeDialogUnits(composite);
170:
171:                createMessageArea(composite);
172:
173:                listViewer = CheckboxTableViewer.newCheckList(composite,
174:                        SWT.BORDER);
175:                GridData data = new GridData(GridData.FILL_BOTH);
176:                data.heightHint = SIZING_SELECTION_WIDGET_HEIGHT;
177:                data.widthHint = SIZING_SELECTION_WIDGET_WIDTH;
178:                listViewer.getTable().setLayoutData(data);
179:
180:                listViewer.setLabelProvider(labelProvider);
181:                listViewer.setContentProvider(contentProvider);
182:
183:                addSelectionButtons(composite);
184:
185:                initializeViewer();
186:
187:                // initialize page
188:                if (!getInitialElementSelections().isEmpty()) {
189:                    checkInitialSelections();
190:                }
191:
192:                Dialog.applyDialogFont(composite);
193:
194:                return composite;
195:            }
196:
197:            /**
198:             * Returns the viewer used to show the list.
199:             * 
200:             * @return the viewer, or <code>null</code> if not yet created
201:             */
202:            protected CheckboxTableViewer getViewer() {
203:                return listViewer;
204:            }
205:
206:            /**
207:             * Initializes this dialog's viewer after it has been laid out.
208:             */
209:            private void initializeViewer() {
210:                listViewer.setInput(inputElement);
211:            }
212:
213:            /**
214:             * The <code>ListSelectionDialog</code> implementation of this 
215:             * <code>Dialog</code> method builds a list of the selected elements for later
216:             * retrieval by the client and closes this dialog.
217:             */
218:            protected void okPressed() {
219:
220:                // Get the input children.
221:                Object[] children = contentProvider.getElements(inputElement);
222:
223:                // Build a list of selected children.
224:                if (children != null) {
225:                    ArrayList list = new ArrayList();
226:                    for (int i = 0; i < children.length; ++i) {
227:                        Object element = children[i];
228:                        if (listViewer.getChecked(element)) {
229:                            list.add(element);
230:                        }
231:                    }
232:                    setResult(list);
233:                }
234:
235:                super.okPressed();
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.