Source Code Cross Referenced for ComboDialogField.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » wizards » dialogfields » 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 » jdt » org.eclipse.jdt.internal.ui.wizards.dialogfields 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 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.jdt.internal.ui.wizards.dialogfields;
011:
012:        import org.eclipse.swt.events.ModifyEvent;
013:        import org.eclipse.swt.events.ModifyListener;
014:        import org.eclipse.swt.events.SelectionEvent;
015:        import org.eclipse.swt.events.SelectionListener;
016:        import org.eclipse.swt.layout.GridData;
017:        import org.eclipse.swt.widgets.Combo;
018:        import org.eclipse.swt.widgets.Composite;
019:        import org.eclipse.swt.widgets.Control;
020:        import org.eclipse.swt.widgets.Label;
021:
022:        /**
023:         * Dialog field containing a label and a combo control.
024:         */
025:        public class ComboDialogField extends DialogField {
026:
027:            private String fText;
028:            private int fSelectionIndex;
029:            private String[] fItems;
030:            private Combo fComboControl;
031:            private ModifyListener fModifyListener;
032:            private int fFlags;
033:
034:            public ComboDialogField(int flags) {
035:                super ();
036:                fText = ""; //$NON-NLS-1$
037:                fItems = new String[0];
038:                fFlags = flags;
039:                fSelectionIndex = -1;
040:            }
041:
042:            // ------- layout helpers
043:
044:            /*
045:             * @see DialogField#doFillIntoGrid
046:             */
047:            public Control[] doFillIntoGrid(Composite parent, int nColumns) {
048:                assertEnoughColumns(nColumns);
049:
050:                Label label = getLabelControl(parent);
051:                label.setLayoutData(gridDataForLabel(1));
052:                Combo combo = getComboControl(parent);
053:                combo.setLayoutData(gridDataForCombo(nColumns - 1));
054:
055:                return new Control[] { label, combo };
056:            }
057:
058:            /*
059:             * @see DialogField#getNumberOfControls
060:             */
061:            public int getNumberOfControls() {
062:                return 2;
063:            }
064:
065:            protected static GridData gridDataForCombo(int span) {
066:                GridData gd = new GridData();
067:                gd.horizontalAlignment = GridData.FILL;
068:                gd.grabExcessHorizontalSpace = false;
069:                gd.horizontalSpan = span;
070:                return gd;
071:            }
072:
073:            // ------- focus methods
074:
075:            /*
076:             * @see DialogField#setFocus
077:             */
078:            public boolean setFocus() {
079:                if (isOkToUse(fComboControl)) {
080:                    fComboControl.setFocus();
081:                }
082:                return true;
083:            }
084:
085:            // ------- ui creation			
086:
087:            /**
088:             * Creates or returns the created combo control.
089:             * @param parent The parent composite or <code>null</code> when the widget has
090:             * already been created.
091:             */
092:            public Combo getComboControl(Composite parent) {
093:                if (fComboControl == null) {
094:                    assertCompositeNotNull(parent);
095:                    fModifyListener = new ModifyListener() {
096:                        public void modifyText(ModifyEvent e) {
097:                            doModifyText(e);
098:                        }
099:                    };
100:                    SelectionListener selectionListener = new SelectionListener() {
101:                        public void widgetSelected(SelectionEvent e) {
102:                            doSelectionChanged(e);
103:                        }
104:
105:                        public void widgetDefaultSelected(SelectionEvent e) {
106:                        }
107:                    };
108:
109:                    fComboControl = new Combo(parent, fFlags);
110:                    // moved up due to 1GEUNW2
111:                    fComboControl.setItems(fItems);
112:                    if (fSelectionIndex != -1) {
113:                        fComboControl.select(fSelectionIndex);
114:                    } else {
115:                        fComboControl.setText(fText);
116:                    }
117:                    fComboControl.setFont(parent.getFont());
118:                    fComboControl.addModifyListener(fModifyListener);
119:                    fComboControl.addSelectionListener(selectionListener);
120:                    fComboControl.setEnabled(isEnabled());
121:                }
122:                return fComboControl;
123:            }
124:
125:            private void doModifyText(ModifyEvent e) {
126:                if (isOkToUse(fComboControl)) {
127:                    fText = fComboControl.getText();
128:                    fSelectionIndex = fComboControl.getSelectionIndex();
129:                }
130:                dialogFieldChanged();
131:            }
132:
133:            private void doSelectionChanged(SelectionEvent e) {
134:                if (isOkToUse(fComboControl)) {
135:                    fItems = fComboControl.getItems();
136:                    fText = fComboControl.getText();
137:                    fSelectionIndex = fComboControl.getSelectionIndex();
138:                }
139:                dialogFieldChanged();
140:            }
141:
142:            // ------ enable / disable management
143:
144:            /*
145:             * @see DialogField#updateEnableState
146:             */
147:            protected void updateEnableState() {
148:                super .updateEnableState();
149:                if (isOkToUse(fComboControl)) {
150:                    fComboControl.setEnabled(isEnabled());
151:                }
152:            }
153:
154:            // ------ text access 
155:
156:            /**
157:             * Gets the combo items.
158:             */
159:            public String[] getItems() {
160:                return fItems;
161:            }
162:
163:            /**
164:             * Sets the combo items. Triggers a dialog-changed event.
165:             */
166:            public void setItems(String[] items) {
167:                fItems = items;
168:                if (isOkToUse(fComboControl)) {
169:                    fComboControl.setItems(items);
170:                }
171:                dialogFieldChanged();
172:            }
173:
174:            /**
175:             * Gets the text.
176:             */
177:            public String getText() {
178:                return fText;
179:            }
180:
181:            /**
182:             * Sets the text. Triggers a dialog-changed event.
183:             */
184:            public void setText(String text) {
185:                fText = text;
186:                if (isOkToUse(fComboControl)) {
187:                    fComboControl.setText(text);
188:                } else {
189:                    dialogFieldChanged();
190:                }
191:            }
192:
193:            /**
194:             * Selects an item.
195:             */
196:            public boolean selectItem(int index) {
197:                boolean success = false;
198:                if (isOkToUse(fComboControl)) {
199:                    fComboControl.select(index);
200:                    success = fComboControl.getSelectionIndex() == index;
201:                } else {
202:                    if (index >= 0 && index < fItems.length) {
203:                        fText = fItems[index];
204:                        fSelectionIndex = index;
205:                        success = true;
206:                    }
207:                }
208:                if (success) {
209:                    dialogFieldChanged();
210:                }
211:                return success;
212:            }
213:
214:            /**
215:             * Selects an item.
216:             */
217:            public boolean selectItem(String name) {
218:                for (int i = 0; i < fItems.length; i++) {
219:                    if (fItems[i].equals(name)) {
220:                        return selectItem(i);
221:                    }
222:                }
223:                return false;
224:            }
225:
226:            public int getSelectionIndex() {
227:                return fSelectionIndex;
228:            }
229:
230:            /**
231:             * Sets the text without triggering a dialog-changed event.
232:             */
233:            public void setTextWithoutUpdate(String text) {
234:                fText = text;
235:                if (isOkToUse(fComboControl)) {
236:                    fComboControl.removeModifyListener(fModifyListener);
237:                    fComboControl.setText(text);
238:                    fComboControl.addModifyListener(fModifyListener);
239:                }
240:            }
241:
242:            /* (non-Javadoc)
243:             * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField#refresh()
244:             */
245:            public void refresh() {
246:                super.refresh();
247:                setTextWithoutUpdate(fText);
248:            }
249:
250:        }
ww_w_.___jav_a__2s._com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.