Source Code Cross Referenced for CheckedListDialogField.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, 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.jdt.internal.ui.wizards.dialogfields;
011:
012:        import java.util.ArrayList;
013:        import java.util.Collection;
014:        import java.util.List;
015:
016:        import org.eclipse.core.runtime.Assert;
017:
018:        import org.eclipse.swt.SWT;
019:        import org.eclipse.swt.widgets.Composite;
020:        import org.eclipse.swt.widgets.Control;
021:        import org.eclipse.swt.widgets.Table;
022:
023:        import org.eclipse.jface.viewers.CheckStateChangedEvent;
024:        import org.eclipse.jface.viewers.CheckboxTableViewer;
025:        import org.eclipse.jface.viewers.ICheckStateListener;
026:        import org.eclipse.jface.viewers.ILabelProvider;
027:        import org.eclipse.jface.viewers.ISelection;
028:        import org.eclipse.jface.viewers.TableViewer;
029:
030:        /**
031:         * A list with check boxes and a button bar. Typical buttons are 'Check All' and 'Uncheck All'.
032:         * List model is independent of widget creation.
033:         * DialogFields controls are: Label, List and Composite containing buttons.
034:         */
035:        public class CheckedListDialogField extends ListDialogField {
036:
037:            private int fCheckAllButtonIndex;
038:            private int fUncheckAllButtonIndex;
039:
040:            private List fCheckedElements;
041:            private List fGrayedElements;
042:
043:            public CheckedListDialogField(IListAdapter adapter,
044:                    String[] customButtonLabels, ILabelProvider lprovider) {
045:                super (adapter, customButtonLabels, lprovider);
046:                fCheckedElements = new ArrayList();
047:                fGrayedElements = new ArrayList();
048:
049:                fCheckAllButtonIndex = -1;
050:                fUncheckAllButtonIndex = -1;
051:            }
052:
053:            /**
054:             * Sets the index of the 'check' button in the button label array passed in the constructor.
055:             * The behavior of the button marked as the check button will then be handled internally.
056:             * (enable state, button invocation behavior)
057:             */
058:            public void setCheckAllButtonIndex(int checkButtonIndex) {
059:                Assert.isTrue(checkButtonIndex < fButtonLabels.length);
060:                fCheckAllButtonIndex = checkButtonIndex;
061:            }
062:
063:            /**
064:             * Sets the index of the 'uncheck' button in the button label array passed in the constructor.
065:             * The behavior of the button marked as the uncheck button will then be handled internally.
066:             * (enable state, button invocation behavior)
067:             */
068:            public void setUncheckAllButtonIndex(int uncheckButtonIndex) {
069:                Assert.isTrue(uncheckButtonIndex < fButtonLabels.length);
070:                fUncheckAllButtonIndex = uncheckButtonIndex;
071:            }
072:
073:            /*
074:             * @see ListDialogField#createTableViewer
075:             */
076:            protected TableViewer createTableViewer(Composite parent) {
077:                Table table = new Table(parent, SWT.CHECK + getListStyle());
078:                table.setFont(parent.getFont());
079:                CheckboxTableViewer tableViewer = new CheckboxTableViewer(table);
080:                tableViewer.addCheckStateListener(new ICheckStateListener() {
081:                    public void checkStateChanged(CheckStateChangedEvent e) {
082:                        doCheckStateChanged(e);
083:                    }
084:                });
085:                return tableViewer;
086:            }
087:
088:            /*
089:             * @see ListDialogField#getListControl
090:             */
091:            public Control getListControl(Composite parent) {
092:                Control control = super .getListControl(parent);
093:                if (parent != null) {
094:                    ((CheckboxTableViewer) fTable)
095:                            .setCheckedElements(fCheckedElements.toArray());
096:                    ((CheckboxTableViewer) fTable)
097:                            .setGrayedElements(fGrayedElements.toArray());
098:                }
099:                return control;
100:            }
101:
102:            /*
103:             * @see DialogField#dialogFieldChanged
104:             * Hooks in to get element changes to update check model.
105:             */
106:            public void dialogFieldChanged() {
107:                for (int i = fCheckedElements.size() - 1; i >= 0; i--) {
108:                    if (!fElements.contains(fCheckedElements.get(i))) {
109:                        fCheckedElements.remove(i);
110:                    }
111:                }
112:                super .dialogFieldChanged();
113:            }
114:
115:            private void checkStateChanged() {
116:                //call super and do not update check model
117:                super .dialogFieldChanged();
118:            }
119:
120:            /**
121:             * Gets the checked elements.
122:             */
123:            public List getCheckedElements() {
124:                if (isOkToUse(fTableControl)) {
125:                    // workaround for bug 53853
126:                    Object[] checked = ((CheckboxTableViewer) fTable)
127:                            .getCheckedElements();
128:                    ArrayList res = new ArrayList(checked.length);
129:                    for (int i = 0; i < checked.length; i++) {
130:                        res.add(checked[i]);
131:                    }
132:                    return res;
133:                }
134:
135:                return new ArrayList(fCheckedElements);
136:            }
137:
138:            /**
139:             * Returns the number of checked elements.
140:             */
141:            public int getCheckedSize() {
142:                return fCheckedElements.size();
143:            }
144:
145:            /**
146:             * Returns true if the element is checked.
147:             */
148:            public boolean isChecked(Object obj) {
149:                if (isOkToUse(fTableControl)) {
150:                    return ((CheckboxTableViewer) fTable).getChecked(obj);
151:                }
152:
153:                return fCheckedElements.contains(obj);
154:            }
155:
156:            public boolean isGrayed(Object obj) {
157:                if (isOkToUse(fTableControl)) {
158:                    return ((CheckboxTableViewer) fTable).getGrayed(obj);
159:                }
160:
161:                return fGrayedElements.contains(obj);
162:            }
163:
164:            /**
165:             * Sets the checked elements.
166:             */
167:            public void setCheckedElements(Collection list) {
168:                fCheckedElements = new ArrayList(list);
169:                if (isOkToUse(fTableControl)) {
170:                    ((CheckboxTableViewer) fTable).setCheckedElements(list
171:                            .toArray());
172:                }
173:                checkStateChanged();
174:            }
175:
176:            /**
177:             * Sets the checked state of an element.
178:             */
179:            public void setChecked(Object object, boolean state) {
180:                setCheckedWithoutUpdate(object, state);
181:                checkStateChanged();
182:            }
183:
184:            /**
185:             * Sets the checked state of an element. No dialog changed listener is informed.
186:             */
187:            public void setCheckedWithoutUpdate(Object object, boolean state) {
188:                if (state) {
189:                    if (!fCheckedElements.contains(object)) {
190:                        fCheckedElements.add(object);
191:                    }
192:                } else {
193:                    fCheckedElements.remove(object);
194:                }
195:                if (isOkToUse(fTableControl)) {
196:                    ((CheckboxTableViewer) fTable).setChecked(object, state);
197:                }
198:            }
199:
200:            public void setGrayedWithoutUpdate(Object object, boolean state) {
201:                if (state) {
202:                    if (!fGrayedElements.contains(object)) {
203:                        fGrayedElements.add(object);
204:                    }
205:                } else {
206:                    fGrayedElements.remove(object);
207:                }
208:                if (isOkToUse(fTableControl)) {
209:                    ((CheckboxTableViewer) fTable).setGrayed(object, state);
210:                }
211:            }
212:
213:            /**
214:             * Sets the check state of all elements
215:             */
216:            public void checkAll(boolean state) {
217:                if (state) {
218:                    fCheckedElements = getElements();
219:                } else {
220:                    fCheckedElements.clear();
221:                }
222:                if (isOkToUse(fTableControl)) {
223:                    ((CheckboxTableViewer) fTable).setAllChecked(state);
224:                }
225:                checkStateChanged();
226:            }
227:
228:            private void doCheckStateChanged(CheckStateChangedEvent e) {
229:                if (e.getChecked()) {
230:                    fCheckedElements.add(e.getElement());
231:                } else {
232:                    fCheckedElements.remove(e.getElement());
233:                }
234:                checkStateChanged();
235:            }
236:
237:            /* (non-Javadoc)
238:             * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField#replaceElement(java.lang.Object, java.lang.Object)
239:             */
240:            public void replaceElement(Object oldElement, Object newElement)
241:                    throws IllegalArgumentException {
242:                boolean wasChecked = isChecked(oldElement);
243:                super .replaceElement(oldElement, newElement);
244:                setChecked(newElement, wasChecked);
245:            }
246:
247:            // ------ enable / disable management
248:
249:            /*
250:             * @see ListDialogField#getManagedButtonState
251:             */
252:            protected boolean getManagedButtonState(ISelection sel, int index) {
253:                if (index == fCheckAllButtonIndex) {
254:                    return !fElements.isEmpty();
255:                } else if (index == fUncheckAllButtonIndex) {
256:                    return !fElements.isEmpty();
257:                }
258:                return super .getManagedButtonState(sel, index);
259:            }
260:
261:            /*
262:             * @see ListDialogField#extraButtonPressed
263:             */
264:            protected boolean managedButtonPressed(int index) {
265:                if (index == fCheckAllButtonIndex) {
266:                    checkAll(true);
267:                } else if (index == fUncheckAllButtonIndex) {
268:                    checkAll(false);
269:                } else {
270:                    return super .managedButtonPressed(index);
271:                }
272:                return true;
273:            }
274:
275:            public void refresh() {
276:                super .refresh();
277:                if (isOkToUse(fTableControl)) {
278:                    ((CheckboxTableViewer) fTable)
279:                            .setCheckedElements(fCheckedElements.toArray());
280:                    ((CheckboxTableViewer) fTable)
281:                            .setGrayedElements(fGrayedElements.toArray());
282:                }
283:            }
284:
285:        }
w_w___w___.j__a__v___a__2_s_.__c__o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.