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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 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.preferences;
011:
012:        import java.util.ArrayList;
013:        import java.util.Arrays;
014:        import java.util.List;
015:        import java.util.StringTokenizer;
016:
017:        import org.eclipse.swt.SWT;
018:        import org.eclipse.swt.layout.GridLayout;
019:        import org.eclipse.swt.widgets.Composite;
020:        import org.eclipse.swt.widgets.Control;
021:
022:        import org.eclipse.jface.dialogs.Dialog;
023:        import org.eclipse.jface.dialogs.IDialogConstants;
024:        import org.eclipse.jface.preference.IPreferenceStore;
025:        import org.eclipse.jface.preference.PreferencePage;
026:        import org.eclipse.jface.viewers.LabelProvider;
027:        import org.eclipse.jface.viewers.ViewerComparator;
028:        import org.eclipse.jface.window.Window;
029:
030:        import org.eclipse.ui.IWorkbench;
031:        import org.eclipse.ui.IWorkbenchPreferencePage;
032:        import org.eclipse.ui.PlatformUI;
033:
034:        import org.eclipse.jdt.core.IPackageFragment;
035:        import org.eclipse.jdt.core.search.IJavaSearchScope;
036:        import org.eclipse.jdt.core.search.SearchEngine;
037:
038:        import org.eclipse.jdt.ui.PreferenceConstants;
039:
040:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
041:        import org.eclipse.jdt.internal.ui.JavaPlugin;
042:        import org.eclipse.jdt.internal.ui.dialogs.PackageSelectionDialog;
043:        import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
044:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.CheckedListDialogField;
045:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
046:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
047:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
048:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
049:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
050:
051:        /*
052:         * The page for setting the type filters
053:         */
054:        public class TypeFilterPreferencePage extends PreferencePage implements 
055:                IWorkbenchPreferencePage {
056:
057:            public static final String TYPE_FILTER_PREF_PAGE_ID = "org.eclipse.jdt.ui.preferences.TypeFilterPreferencePage"; //$NON-NLS-1$
058:
059:            private static final String PREF_FILTER_ENABLED = PreferenceConstants.TYPEFILTER_ENABLED;
060:            private static final String PREF_FILTER_DISABLED = PreferenceConstants.TYPEFILTER_DISABLED;
061:
062:            private static String[] unpackOrderList(String str) {
063:                StringTokenizer tok = new StringTokenizer(str, ";"); //$NON-NLS-1$
064:                int nTokens = tok.countTokens();
065:                String[] res = new String[nTokens];
066:                for (int i = 0; i < nTokens; i++) {
067:                    res[i] = tok.nextToken();
068:                }
069:                return res;
070:            }
071:
072:            private static String packOrderList(List orderList) {
073:                StringBuffer buf = new StringBuffer();
074:                for (int i = 0; i < orderList.size(); i++) {
075:                    buf.append((String) orderList.get(i));
076:                    buf.append(';');
077:                }
078:                return buf.toString();
079:            }
080:
081:            private class TypeFilterAdapter implements  IListAdapter,
082:                    IDialogFieldListener {
083:
084:                private boolean canEdit(ListDialogField field) {
085:                    return field.getSelectedElements().size() == 1;
086:                }
087:
088:                public void customButtonPressed(ListDialogField field, int index) {
089:                    doButtonPressed(index);
090:                }
091:
092:                public void selectionChanged(ListDialogField field) {
093:                    fFilterListField.enableButton(IDX_EDIT, canEdit(field));
094:                }
095:
096:                public void dialogFieldChanged(DialogField field) {
097:                }
098:
099:                public void doubleClicked(ListDialogField field) {
100:                    if (canEdit(field)) {
101:                        doButtonPressed(IDX_EDIT);
102:                    }
103:                }
104:            }
105:
106:            private static final int IDX_ADD = 0;
107:            private static final int IDX_ADD_PACKAGE = 1;
108:            private static final int IDX_EDIT = 2;
109:            private static final int IDX_REMOVE = 3;
110:            private static final int IDX_SELECT = 5;
111:            private static final int IDX_DESELECT = 6;
112:
113:            private CheckedListDialogField fFilterListField;
114:
115:            public TypeFilterPreferencePage() {
116:                super ();
117:                setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore());
118:                setDescription(PreferencesMessages.TypeFilterPreferencePage_description);
119:
120:                String[] buttonLabels = new String[] {
121:                        PreferencesMessages.TypeFilterPreferencePage_add_button,
122:                        PreferencesMessages.TypeFilterPreferencePage_addpackage_button,
123:                        PreferencesMessages.TypeFilterPreferencePage_edit_button,
124:                        PreferencesMessages.TypeFilterPreferencePage_remove_button,
125:                        /* 4 */null,
126:                        PreferencesMessages.TypeFilterPreferencePage_selectall_button,
127:                        PreferencesMessages.TypeFilterPreferencePage_deselectall_button, };
128:
129:                TypeFilterAdapter adapter = new TypeFilterAdapter();
130:
131:                fFilterListField = new CheckedListDialogField(adapter,
132:                        buttonLabels, new LabelProvider());
133:                fFilterListField.setDialogFieldListener(adapter);
134:                fFilterListField
135:                        .setLabelText(PreferencesMessages.TypeFilterPreferencePage_list_label);
136:                fFilterListField.setCheckAllButtonIndex(IDX_SELECT);
137:                fFilterListField.setUncheckAllButtonIndex(IDX_DESELECT);
138:                fFilterListField.setRemoveButtonIndex(IDX_REMOVE);
139:
140:                fFilterListField.enableButton(IDX_EDIT, false);
141:
142:                initialize(false);
143:            }
144:
145:            /*
146:             * @see PreferencePage#createControl(org.eclipse.swt.widgets.Composite)
147:             */
148:            public void createControl(Composite parent) {
149:                super .createControl(parent);
150:                PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
151:                        IJavaHelpContextIds.TYPE_FILTER_PREFERENCE_PAGE);
152:            }
153:
154:            protected Control createContents(Composite parent) {
155:                initializeDialogUnits(parent);
156:
157:                Composite composite = new Composite(parent, SWT.NONE);
158:                composite.setFont(parent.getFont());
159:
160:                GridLayout layout = new GridLayout();
161:                layout.numColumns = 2;
162:                layout.marginWidth = 0;
163:                layout.marginHeight = 0;
164:
165:                composite.setLayout(layout);
166:
167:                fFilterListField.doFillIntoGrid(composite, 3);
168:                LayoutUtil.setHorizontalSpan(fFilterListField
169:                        .getLabelControl(null), 2);
170:                LayoutUtil.setWidthHint(fFilterListField.getLabelControl(null),
171:                        convertWidthInCharsToPixels(40));
172:                LayoutUtil.setHorizontalGrabbing(fFilterListField
173:                        .getListControl(null));
174:
175:                fFilterListField.getTableViewer().setComparator(
176:                        new ViewerComparator());
177:
178:                Dialog.applyDialogFont(composite);
179:                return composite;
180:            }
181:
182:            private void initialize(boolean fromDefault) {
183:                IPreferenceStore store = getPreferenceStore();
184:
185:                String enabled = fromDefault ? store
186:                        .getDefaultString(PREF_FILTER_ENABLED) : store
187:                        .getString(PREF_FILTER_ENABLED);
188:                String disabled = fromDefault ? store
189:                        .getDefaultString(PREF_FILTER_DISABLED) : store
190:                        .getString(PREF_FILTER_DISABLED);
191:
192:                ArrayList res = new ArrayList();
193:
194:                String[] enabledEntries = unpackOrderList(enabled);
195:                for (int i = 0; i < enabledEntries.length; i++) {
196:                    res.add(enabledEntries[i]);
197:                }
198:                String[] disabledEntries = unpackOrderList(disabled);
199:                for (int i = 0; i < disabledEntries.length; i++) {
200:                    res.add(disabledEntries[i]);
201:                }
202:
203:                fFilterListField.setElements(res);
204:                fFilterListField.setCheckedElements(Arrays
205:                        .asList(enabledEntries));
206:            }
207:
208:            private void doButtonPressed(int index) {
209:                if (index == IDX_ADD) { // add new
210:                    List existing = fFilterListField.getElements();
211:                    TypeFilterInputDialog dialog = new TypeFilterInputDialog(
212:                            getShell(), existing);
213:                    if (dialog.open() == Window.OK) {
214:                        Object res = dialog.getResult();
215:                        fFilterListField.addElement(res);
216:                        fFilterListField.setChecked(res, true);
217:                    }
218:                } else if (index == IDX_ADD_PACKAGE) { // add packages
219:                    String[] res = choosePackage();
220:                    if (res != null) {
221:                        fFilterListField.addElements(Arrays.asList(res));
222:                        for (int i = 0; i < res.length; i++) {
223:                            fFilterListField.setChecked(res[i], true);
224:                        }
225:                    }
226:
227:                } else if (index == IDX_EDIT) { // edit
228:                    List selected = fFilterListField.getSelectedElements();
229:                    if (selected.isEmpty()) {
230:                        return;
231:                    }
232:                    String editedEntry = (String) selected.get(0);
233:
234:                    List existing = fFilterListField.getElements();
235:                    existing.remove(editedEntry);
236:
237:                    TypeFilterInputDialog dialog = new TypeFilterInputDialog(
238:                            getShell(), existing);
239:                    dialog.setInitialString(editedEntry);
240:                    if (dialog.open() == Window.OK) {
241:                        fFilterListField.replaceElement(editedEntry, dialog
242:                                .getResult());
243:                    }
244:                }
245:            }
246:
247:            private String[] choosePackage() {
248:                IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
249:                BusyIndicatorRunnableContext context = new BusyIndicatorRunnableContext();
250:                int flags = PackageSelectionDialog.F_SHOW_PARENTS
251:                        | PackageSelectionDialog.F_HIDE_DEFAULT_PACKAGE
252:                        | PackageSelectionDialog.F_REMOVE_DUPLICATES;
253:                PackageSelectionDialog dialog = new PackageSelectionDialog(
254:                        getShell(), context, flags, scope);
255:                dialog
256:                        .setTitle(PreferencesMessages.TypeFilterPreferencePage_choosepackage_label);
257:                dialog
258:                        .setMessage(PreferencesMessages.TypeFilterPreferencePage_choosepackage_description);
259:                dialog.setMultipleSelection(true);
260:                if (dialog.open() == IDialogConstants.OK_ID) {
261:                    Object[] fragments = dialog.getResult();
262:                    String[] res = new String[fragments.length];
263:                    for (int i = 0; i < res.length; i++) {
264:                        res[i] = ((IPackageFragment) fragments[i])
265:                                .getElementName()
266:                                + ".*"; //$NON-NLS-1$
267:                    }
268:                    return res;
269:                }
270:                return null;
271:            }
272:
273:            public void init(IWorkbench workbench) {
274:            }
275:
276:            /*
277:             * @see PreferencePage#performDefaults()
278:             */
279:            protected void performDefaults() {
280:                initialize(true);
281:
282:                super .performDefaults();
283:            }
284:
285:            /*
286:             * @see org.eclipse.jface.preference.IPreferencePage#performOk()
287:             */
288:            public boolean performOk() {
289:                IPreferenceStore prefs = JavaPlugin.getDefault()
290:                        .getPreferenceStore();
291:
292:                List checked = fFilterListField.getCheckedElements();
293:                List unchecked = fFilterListField.getElements();
294:                unchecked.removeAll(checked);
295:
296:                prefs.setValue(PREF_FILTER_ENABLED, packOrderList(checked));
297:                prefs.setValue(PREF_FILTER_DISABLED, packOrderList(unchecked));
298:                JavaPlugin.getDefault().savePluginPreferences();
299:                return true;
300:            }
301:
302:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.