Source Code Cross Referenced for FeatureSelectionDialog.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » internal » ide » 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.internal.ide 
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.ide;
011:
012:        import com.ibm.icu.text.Collator;
013:        import java.util.Arrays;
014:        import java.util.Comparator;
015:        import java.util.Locale;
016:
017:        import org.eclipse.jface.viewers.DoubleClickEvent;
018:        import org.eclipse.jface.viewers.IDoubleClickListener;
019:        import org.eclipse.jface.viewers.ISelectionChangedListener;
020:        import org.eclipse.jface.viewers.IStructuredSelection;
021:        import org.eclipse.jface.viewers.LabelProvider;
022:        import org.eclipse.jface.viewers.ListViewer;
023:        import org.eclipse.jface.viewers.SelectionChangedEvent;
024:        import org.eclipse.jface.viewers.StructuredSelection;
025:        import org.eclipse.swt.SWT;
026:        import org.eclipse.swt.layout.GridData;
027:        import org.eclipse.swt.widgets.Composite;
028:        import org.eclipse.swt.widgets.Control;
029:        import org.eclipse.swt.widgets.Shell;
030:        import org.eclipse.ui.PlatformUI;
031:        import org.eclipse.ui.dialogs.SelectionDialog;
032:        import org.eclipse.ui.internal.ide.dialogs.SimpleListContentProvider;
033:
034:        /**
035:         * Dialog to allow the user to select a feature from a list.
036:         */
037:        public class FeatureSelectionDialog extends SelectionDialog {
038:            /**
039:             * List width in characters.
040:             */
041:            private final static int LIST_WIDTH = 60;
042:
043:            /**
044:             * List height in characters.
045:             */
046:            private final static int LIST_HEIGHT = 10;
047:
048:            /**
049:             * The feature about infos.
050:             */
051:            private AboutInfo[] features;
052:
053:            /**
054:             * List to display the resolutions.
055:             */
056:            private ListViewer listViewer;
057:
058:            /**
059:             * The help context id
060:             */
061:            private String helpContextId;
062:
063:            /**
064:             * Creates an instance of this dialog to display
065:             * the given features.
066:             * <p>
067:             * There must be at least one feature.
068:             * </p>
069:             * 
070:             * @param shell  the parent shell
071:             * @param features  the features to display
072:             * @param primaryFeatureId  the id of the primary feature or null if none
073:             * @param shellTitle  shell title
074:             * @param shellMessage  shell message
075:             * @param helpContextId  help context id
076:             */
077:            public FeatureSelectionDialog(Shell shell, AboutInfo[] features,
078:                    String primaryFeatureId, String shellTitle,
079:                    String shellMessage, String helpContextId) {
080:
081:                super (shell);
082:                if (features == null || features.length == 0) {
083:                    throw new IllegalArgumentException();
084:                }
085:                this .features = features;
086:                this .helpContextId = helpContextId;
087:                setTitle(shellTitle);
088:                setMessage(shellMessage);
089:
090:                // Sort ascending
091:                Arrays.sort(features, new Comparator() {
092:                    Collator coll = Collator.getInstance(Locale.getDefault());
093:
094:                    public int compare(Object a, Object b) {
095:                        AboutInfo i1, i2;
096:                        String name1, name2;
097:                        i1 = (AboutInfo) a;
098:                        name1 = i1.getFeatureLabel();
099:                        i2 = (AboutInfo) b;
100:                        name2 = i2.getFeatureLabel();
101:                        if (name1 == null) {
102:                            name1 = ""; //$NON-NLS-1$
103:                        }
104:                        if (name2 == null) {
105:                            name2 = ""; //$NON-NLS-1$
106:                        }
107:                        return coll.compare(name1, name2);
108:                    }
109:                });
110:
111:                // Find primary feature
112:                for (int i = 0; i < features.length; i++) {
113:                    if (features[i].getFeatureId().equals(primaryFeatureId)) {
114:                        setInitialSelections(new Object[] { features[i] });
115:                        return;
116:                    }
117:                }
118:
119:                // set a safe default		
120:                setInitialSelections(new Object[0]);
121:            }
122:
123:            /* (non-Javadoc)
124:             * Method declared on Window.
125:             */
126:            protected void configureShell(Shell newShell) {
127:                super .configureShell(newShell);
128:                PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell,
129:                        helpContextId);
130:            }
131:
132:            /* (non-Javadoc)
133:             * Method declared on Dialog.
134:             */
135:            protected Control createDialogArea(Composite parent) {
136:                Composite composite = (Composite) super 
137:                        .createDialogArea(parent);
138:
139:                // Create label
140:                createMessageArea(composite);
141:                // Create list viewer	
142:                listViewer = new ListViewer(composite, SWT.SINGLE
143:                        | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
144:                GridData data = new GridData(GridData.FILL_BOTH);
145:                data.heightHint = convertHeightInCharsToPixels(LIST_HEIGHT);
146:                data.widthHint = convertWidthInCharsToPixels(LIST_WIDTH);
147:                listViewer.getList().setLayoutData(data);
148:                listViewer.getList().setFont(parent.getFont());
149:                // Set the label provider		
150:                listViewer.setLabelProvider(new LabelProvider() {
151:                    public String getText(Object element) {
152:                        // Return the features's label.
153:                        return element == null ? "" : ((AboutInfo) element).getFeatureLabel(); //$NON-NLS-1$
154:                    }
155:                });
156:
157:                // Set the content provider
158:                SimpleListContentProvider cp = new SimpleListContentProvider();
159:                cp.setElements(features);
160:                listViewer.setContentProvider(cp);
161:                listViewer.setInput(new Object());
162:                // it is ignored but must be non-null
163:
164:                // Set the initial selection
165:                listViewer.setSelection(new StructuredSelection(
166:                        getInitialElementSelections()), true);
167:
168:                // Add a selection change listener
169:                listViewer
170:                        .addSelectionChangedListener(new ISelectionChangedListener() {
171:                            public void selectionChanged(
172:                                    SelectionChangedEvent event) {
173:                                // Update OK button enablement
174:                                getOkButton().setEnabled(
175:                                        !event.getSelection().isEmpty());
176:                            }
177:                        });
178:
179:                // Add double-click listener
180:                listViewer.addDoubleClickListener(new IDoubleClickListener() {
181:                    public void doubleClick(DoubleClickEvent event) {
182:                        okPressed();
183:                    }
184:                });
185:                return composite;
186:            }
187:
188:            /* (non-Javadoc)
189:             * Method declared on Dialog.
190:             */
191:            protected void okPressed() {
192:                IStructuredSelection selection = (IStructuredSelection) listViewer
193:                        .getSelection();
194:                setResult(selection.toList());
195:                super.okPressed();
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.