Source Code Cross Referenced for TwoPaneElementSelector.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 19346 - Dialog
011:         *    font should be activated and used by other components.
012:         *******************************************************************************/package org.eclipse.ui.dialogs;
013:
014:        import java.util.Arrays;
015:        import java.util.List;
016:
017:        import org.eclipse.jface.dialogs.IDialogConstants;
018:        import org.eclipse.jface.viewers.ILabelProvider;
019:        import org.eclipse.swt.SWT;
020:        import org.eclipse.swt.events.DisposeEvent;
021:        import org.eclipse.swt.events.DisposeListener;
022:        import org.eclipse.swt.layout.GridData;
023:        import org.eclipse.swt.widgets.Composite;
024:        import org.eclipse.swt.widgets.Control;
025:        import org.eclipse.swt.widgets.Event;
026:        import org.eclipse.swt.widgets.Label;
027:        import org.eclipse.swt.widgets.Listener;
028:        import org.eclipse.swt.widgets.Shell;
029:        import org.eclipse.swt.widgets.Table;
030:        import org.eclipse.swt.widgets.TableItem;
031:
032:        /**
033:         * A list selection dialog with two panes. Duplicated entries will be folded
034:         * together and are displayed in the lower pane (qualifier).
035:         * 
036:         * @since 2.0
037:         */
038:        public class TwoPaneElementSelector extends
039:                AbstractElementListSelectionDialog {
040:            private String fUpperListLabel;
041:
042:            private String fLowerListLabel;
043:
044:            private ILabelProvider fQualifierRenderer;
045:
046:            private Object[] fElements = new Object[0];
047:
048:            private Table fLowerList;
049:
050:            private Object[] fQualifierElements;
051:
052:            /**
053:             * Creates the two pane element selector.
054:             * 
055:             * @param parent
056:             *            the parent shell.
057:             * @param elementRenderer
058:             *            the element renderer.
059:             * @param qualifierRenderer
060:             *            the qualifier renderer.
061:             */
062:            public TwoPaneElementSelector(Shell parent,
063:                    ILabelProvider elementRenderer,
064:                    ILabelProvider qualifierRenderer) {
065:                super (parent, elementRenderer);
066:                setSize(50, 15);
067:                setAllowDuplicates(false);
068:                fQualifierRenderer = qualifierRenderer;
069:            }
070:
071:            /**
072:             * Sets the upper list label. If the label is <code>null</code> (default),
073:             * no label is created.
074:             * 
075:             * @param label
076:             */
077:            public void setUpperListLabel(String label) {
078:                fUpperListLabel = label;
079:            }
080:
081:            /**
082:             * Sets the lower list label.
083:             * 
084:             * @param label
085:             *            String or <code>null</code>. If the label is
086:             *            <code>null</code> (default), no label is created.
087:             */
088:            public void setLowerListLabel(String label) {
089:                fLowerListLabel = label;
090:            }
091:
092:            /**
093:             * Sets the elements to be displayed.
094:             * 
095:             * @param elements
096:             *            the elements to be displayed.
097:             */
098:            public void setElements(Object[] elements) {
099:                fElements = elements;
100:            }
101:
102:            /*
103:             * @see Dialog#createDialogArea(Composite)
104:             */
105:            public Control createDialogArea(Composite parent) {
106:                Composite contents = (Composite) super .createDialogArea(parent);
107:                createMessageArea(contents);
108:                createFilterText(contents);
109:                createLabel(contents, fUpperListLabel);
110:                createFilteredList(contents);
111:                createLabel(contents, fLowerListLabel);
112:                createLowerList(contents);
113:                setListElements(fElements);
114:                List initialSelections = getInitialElementSelections();
115:                if (!initialSelections.isEmpty()) {
116:                    Object element = initialSelections.get(0);
117:                    setSelection(new Object[] { element });
118:                    setLowerSelectedElement(element);
119:                }
120:                return contents;
121:            }
122:
123:            /**
124:             * Creates a label if name was not <code>null</code>.
125:             * 
126:             * @param parent
127:             *            the parent composite.
128:             * @param name
129:             *            the name of the label.
130:             * @return returns a label if a name was given, <code>null</code>
131:             *         otherwise.
132:             */
133:            protected Label createLabel(Composite parent, String name) {
134:                if (name == null) {
135:                    return null;
136:                }
137:                Label label = new Label(parent, SWT.NONE);
138:                label.setText(name);
139:                label.setFont(parent.getFont());
140:                return label;
141:            }
142:
143:            /**
144:             * Creates the list widget and sets layout data.
145:             * 
146:             * @param parent
147:             *            the parent composite.
148:             * @return returns the list table widget.
149:             */
150:            protected Table createLowerList(Composite parent) {
151:                Table list = new Table(parent, SWT.BORDER | SWT.V_SCROLL
152:                        | SWT.H_SCROLL);
153:                list.addListener(SWT.Selection, new Listener() {
154:                    public void handleEvent(Event evt) {
155:                        handleLowerSelectionChanged();
156:                    }
157:                });
158:                list.addListener(SWT.MouseDoubleClick, new Listener() {
159:                    public void handleEvent(Event evt) {
160:                        handleDefaultSelected();
161:                    }
162:                });
163:                list.addDisposeListener(new DisposeListener() {
164:                    public void widgetDisposed(DisposeEvent e) {
165:                        fQualifierRenderer.dispose();
166:                    }
167:                });
168:                GridData data = new GridData();
169:                data.widthHint = convertWidthInCharsToPixels(50);
170:                data.heightHint = convertHeightInCharsToPixels(5);
171:                data.grabExcessVerticalSpace = true;
172:                data.grabExcessHorizontalSpace = true;
173:                data.horizontalAlignment = GridData.FILL;
174:                data.verticalAlignment = GridData.FILL;
175:                list.setLayoutData(data);
176:                list.setFont(parent.getFont());
177:                fLowerList = list;
178:                return list;
179:            }
180:
181:            /**
182:             * @see SelectionStatusDialog#computeResult()
183:             */
184:            protected void computeResult() {
185:                Object[] results = new Object[] { getLowerSelectedElement() };
186:                setResult(Arrays.asList(results));
187:            }
188:
189:            /**
190:             * @see AbstractElementListSelectionDialog#handleDefaultSelected()
191:             */
192:            protected void handleDefaultSelected() {
193:                if (validateCurrentSelection()
194:                        && (getLowerSelectedElement() != null)) {
195:                    buttonPressed(IDialogConstants.OK_ID);
196:                }
197:            }
198:
199:            /**
200:             * @see AbstractElementListSelectionDialog#handleSelectionChanged()
201:             */
202:            protected void handleSelectionChanged() {
203:                handleUpperSelectionChanged();
204:            }
205:
206:            private void handleUpperSelectionChanged() {
207:                int index = getSelectionIndex();
208:                fLowerList.removeAll();
209:                if (index >= 0) {
210:                    fQualifierElements = getFoldedElements(index);
211:                    if (fQualifierElements == null) {
212:                        updateLowerListWidget(new Object[] {});
213:                    } else {
214:                        updateLowerListWidget(fQualifierElements);
215:                    }
216:                }
217:                validateCurrentSelection();
218:            }
219:
220:            private void handleLowerSelectionChanged() {
221:                validateCurrentSelection();
222:            }
223:
224:            /**
225:             * Selects an element in the lower pane.
226:             * @param element
227:             */
228:            protected void setLowerSelectedElement(Object element) {
229:                if (fQualifierElements == null) {
230:                    return;
231:                }
232:                // find matching index
233:                int i;
234:                for (i = 0; i != fQualifierElements.length; i++) {
235:                    if (fQualifierElements[i].equals(element)) {
236:                        break;
237:                    }
238:                }
239:                // set selection
240:                if (i != fQualifierElements.length) {
241:                    fLowerList.setSelection(i);
242:                }
243:            }
244:
245:            /**
246:             * Returns the selected element from the lower pane.
247:             * @return Object
248:             */
249:            protected Object getLowerSelectedElement() {
250:                int index = fLowerList.getSelectionIndex();
251:                if (index >= 0) {
252:                    return fQualifierElements[index];
253:                }
254:                return null;
255:            }
256:
257:            private void updateLowerListWidget(Object[] elements) {
258:                int length = elements.length;
259:                String[] qualifiers = new String[length];
260:                for (int i = 0; i != length; i++) {
261:                    String text = fQualifierRenderer.getText(elements[i]);
262:                    if (text == null) {
263:                        text = ""; //$NON-NLS-1$
264:                    }
265:                    qualifiers[i] = text;
266:                }
267:                TwoArrayQuickSorter sorter = new TwoArrayQuickSorter(
268:                        isCaseIgnored());
269:                sorter.sort(qualifiers, elements);
270:                for (int i = 0; i != length; i++) {
271:                    TableItem item = new TableItem(fLowerList, SWT.NONE);
272:                    item.setText(qualifiers[i]);
273:                    item.setImage(fQualifierRenderer.getImage(elements[i]));
274:                }
275:                if (fLowerList.getItemCount() > 0) {
276:                    fLowerList.setSelection(0);
277:                }
278:            }
279:
280:            /*
281:             * @see AbstractElementListSelectionDialog#handleEmptyList()
282:             */
283:            protected void handleEmptyList() {
284:                super .handleEmptyList();
285:                fLowerList.setEnabled(false);
286:            }
287:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.