Source Code Cross Referenced for DecoratorsPreferencePage.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » 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.internal.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:         *******************************************************************************/package org.eclipse.ui.internal.dialogs;
011:
012:        import com.ibm.icu.text.Collator;
013:        import java.util.Arrays;
014:        import java.util.Collections;
015:        import java.util.Comparator;
016:
017:        import org.eclipse.jface.preference.IPreferencePage;
018:        import org.eclipse.jface.preference.PreferencePage;
019:        import org.eclipse.jface.viewers.CheckStateChangedEvent;
020:        import org.eclipse.jface.viewers.CheckboxTableViewer;
021:        import org.eclipse.jface.viewers.ICheckStateListener;
022:        import org.eclipse.jface.viewers.ISelectionChangedListener;
023:        import org.eclipse.jface.viewers.IStructuredContentProvider;
024:        import org.eclipse.jface.viewers.IStructuredSelection;
025:        import org.eclipse.jface.viewers.LabelProvider;
026:        import org.eclipse.jface.viewers.SelectionChangedEvent;
027:        import org.eclipse.jface.viewers.StructuredSelection;
028:        import org.eclipse.jface.viewers.Viewer;
029:        import org.eclipse.swt.SWT;
030:        import org.eclipse.swt.graphics.Font;
031:        import org.eclipse.swt.layout.GridData;
032:        import org.eclipse.swt.layout.GridLayout;
033:        import org.eclipse.swt.widgets.Composite;
034:        import org.eclipse.swt.widgets.Control;
035:        import org.eclipse.swt.widgets.Label;
036:        import org.eclipse.swt.widgets.Text;
037:        import org.eclipse.ui.IWorkbench;
038:        import org.eclipse.ui.IWorkbenchPreferencePage;
039:        import org.eclipse.ui.PlatformUI;
040:        import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
041:        import org.eclipse.ui.internal.WorkbenchMessages;
042:        import org.eclipse.ui.internal.WorkbenchPlugin;
043:        import org.eclipse.ui.internal.decorators.DecoratorDefinition;
044:        import org.eclipse.ui.internal.decorators.DecoratorManager;
045:
046:        /**
047:         * The DecoratorsPreferencePage is the preference page for enabling and disabling
048:         * the decorators in the image and for giving the user a description of the decorator.
049:         */
050:        public class DecoratorsPreferencePage extends PreferencePage implements 
051:                IWorkbenchPreferencePage {
052:
053:            private Text descriptionText;
054:
055:            private CheckboxTableViewer checkboxViewer;
056:
057:            /**
058:             * @see PreferencePage#createContents(Composite)
059:             */
060:            protected Control createContents(Composite parent) {
061:
062:                Font font = parent.getFont();
063:
064:                PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
065:                        IWorkbenchHelpContextIds.DECORATORS_PREFERENCE_PAGE);
066:
067:                Composite mainComposite = new Composite(parent, SWT.NONE);
068:                mainComposite.setLayoutData(new GridData(
069:                        GridData.FILL_HORIZONTAL));
070:                mainComposite.setFont(font);
071:
072:                GridLayout layout = new GridLayout();
073:                layout.marginWidth = 0;
074:                layout.marginHeight = 0;
075:                layout.verticalSpacing = 10;
076:                mainComposite.setLayout(layout);
077:
078:                Label topLabel = new Label(mainComposite, SWT.NONE);
079:                topLabel
080:                        .setText(WorkbenchMessages.DecoratorsPreferencePage_explanation);
081:                topLabel.setFont(font);
082:
083:                createDecoratorsArea(mainComposite);
084:                createDescriptionArea(mainComposite);
085:                populateDecorators();
086:
087:                return mainComposite;
088:            }
089:
090:            /** 
091:             * Creates the widgets for the list of decorators.
092:             */
093:            private void createDecoratorsArea(Composite mainComposite) {
094:
095:                Font mainFont = mainComposite.getFont();
096:                Composite decoratorsComposite = new Composite(mainComposite,
097:                        SWT.NONE);
098:                decoratorsComposite.setLayoutData(new GridData(
099:                        GridData.FILL_BOTH));
100:                GridLayout decoratorsLayout = new GridLayout();
101:                decoratorsLayout.marginWidth = 0;
102:                decoratorsLayout.marginHeight = 0;
103:                decoratorsComposite.setLayout(decoratorsLayout);
104:                decoratorsComposite.setFont(mainFont);
105:
106:                Label decoratorsLabel = new Label(decoratorsComposite, SWT.NONE);
107:                decoratorsLabel
108:                        .setText(WorkbenchMessages.DecoratorsPreferencePage_decoratorsLabel);
109:                decoratorsLabel.setFont(mainFont);
110:
111:                // Checkbox table viewer of decorators
112:                checkboxViewer = CheckboxTableViewer.newCheckList(
113:                        decoratorsComposite, SWT.SINGLE | SWT.TOP | SWT.BORDER);
114:                checkboxViewer.getTable().setLayoutData(
115:                        new GridData(GridData.FILL_BOTH));
116:                checkboxViewer.getTable()
117:                        .setFont(decoratorsComposite.getFont());
118:                checkboxViewer.setLabelProvider(new LabelProvider() {
119:                    public String getText(Object element) {
120:                        return ((DecoratorDefinition) element).getName();
121:                    }
122:                });
123:                checkboxViewer.getTable().setFont(mainFont);
124:
125:                checkboxViewer
126:                        .setContentProvider(new IStructuredContentProvider() {
127:                            private final Comparator comparer = new Comparator() {
128:                                private Collator collator = Collator
129:                                        .getInstance();
130:
131:                                public int compare(Object arg0, Object arg1) {
132:                                    String s1 = ((DecoratorDefinition) arg0)
133:                                            .getName();
134:                                    String s2 = ((DecoratorDefinition) arg1)
135:                                            .getName();
136:                                    return collator.compare(s1, s2);
137:                                }
138:                            };
139:
140:                            public void dispose() {
141:                                //Nothing to do on dispose
142:                            }
143:
144:                            public void inputChanged(Viewer viewer,
145:                                    Object oldInput, Object newInput) {
146:                            }
147:
148:                            public Object[] getElements(Object inputElement) {
149:                                //Make an entry for each decorator definition
150:                                Object[] elements = (Object[]) inputElement;
151:                                Object[] results = new Object[elements.length];
152:                                System.arraycopy(elements, 0, results, 0,
153:                                        elements.length);
154:                                Collections.sort(Arrays.asList(results),
155:                                        comparer);
156:                                return results;
157:                            }
158:
159:                        });
160:
161:                checkboxViewer
162:                        .addSelectionChangedListener(new ISelectionChangedListener() {
163:                            public void selectionChanged(
164:                                    SelectionChangedEvent event) {
165:                                if (event.getSelection() instanceof  IStructuredSelection) {
166:                                    IStructuredSelection sel = (IStructuredSelection) event
167:                                            .getSelection();
168:                                    DecoratorDefinition definition = (DecoratorDefinition) sel
169:                                            .getFirstElement();
170:                                    if (definition == null) {
171:                                        clearDescription();
172:                                    } else {
173:                                        showDescription(definition);
174:                                    }
175:                                }
176:                            }
177:                        });
178:
179:                checkboxViewer.addCheckStateListener(new ICheckStateListener() {
180:                    public void checkStateChanged(CheckStateChangedEvent event) {
181:                        checkboxViewer.setSelection(new StructuredSelection(
182:                                event.getElement()));
183:                    }
184:                });
185:            }
186:
187:            /** 
188:             * Creates the widgets for the description.
189:             */
190:            private void createDescriptionArea(Composite mainComposite) {
191:
192:                Font mainFont = mainComposite.getFont();
193:                Composite textComposite = new Composite(mainComposite, SWT.NONE);
194:                textComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
195:                GridLayout textLayout = new GridLayout();
196:                textLayout.marginWidth = 0;
197:                textLayout.marginHeight = 0;
198:                textComposite.setLayout(textLayout);
199:                textComposite.setFont(mainFont);
200:
201:                Label descriptionLabel = new Label(textComposite, SWT.NONE);
202:                descriptionLabel
203:                        .setText(WorkbenchMessages.DecoratorsPreferencePage_description);
204:                descriptionLabel.setFont(mainFont);
205:
206:                descriptionText = new Text(textComposite, SWT.MULTI | SWT.WRAP
207:                        | SWT.READ_ONLY | SWT.BORDER | SWT.H_SCROLL);
208:                descriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));
209:                descriptionText.setFont(mainFont);
210:            }
211:
212:            /**
213:             * Populates the list of decorators.
214:             */
215:            private void populateDecorators() {
216:                DecoratorDefinition[] definitions = getAllDefinitions();
217:                checkboxViewer.setInput(definitions);
218:                for (int i = 0; i < definitions.length; i++) {
219:                    checkboxViewer.setChecked(definitions[i], definitions[i]
220:                            .isEnabled());
221:                }
222:            }
223:
224:            /**
225:             * Show the selected description in the text.
226:             */
227:            private void showDescription(DecoratorDefinition definition) {
228:                if (descriptionText == null || descriptionText.isDisposed()) {
229:                    return;
230:                }
231:                String text = definition.getDescription();
232:                if (text == null || text.length() == 0) {
233:                    descriptionText
234:                            .setText(WorkbenchMessages.PreferencePage_noDescription);
235:                } else {
236:                    descriptionText.setText(text);
237:                }
238:            }
239:
240:            /**
241:             * Clear the selected description in the text.
242:             */
243:            private void clearDescription() {
244:                if (descriptionText == null || descriptionText.isDisposed()) {
245:                    return;
246:                }
247:                descriptionText.setText(""); //$NON-NLS-1$
248:            }
249:
250:            /**
251:             * @see PreferencePage#performDefaults()
252:             */
253:            protected void performDefaults() {
254:                super .performDefaults();
255:                DecoratorManager manager = WorkbenchPlugin.getDefault()
256:                        .getDecoratorManager();
257:                DecoratorDefinition[] definitions = manager
258:                        .getAllDecoratorDefinitions();
259:                for (int i = 0; i < definitions.length; i++) {
260:                    checkboxViewer.setChecked(definitions[i], definitions[i]
261:                            .getDefaultValue());
262:                }
263:            }
264:
265:            /**
266:             * @see IPreferencePage#performOk()
267:             */
268:            public boolean performOk() {
269:                if (super .performOk()) {
270:                    DecoratorManager manager = getDecoratorManager();
271:                    //Clear the caches first to avoid unneccessary updates
272:                    manager.clearCaches();
273:                    DecoratorDefinition[] definitions = manager
274:                            .getAllDecoratorDefinitions();
275:                    for (int i = 0; i < definitions.length; i++) {
276:                        boolean checked = checkboxViewer
277:                                .getChecked(definitions[i]);
278:                        definitions[i].setEnabled(checked);
279:
280:                    }
281:                    //Have the manager clear again as there may have been
282:                    //extra updates fired by the enablement changes.
283:                    manager.clearCaches();
284:                    manager.updateForEnablementChange();
285:                    return true;
286:                }
287:                return false;
288:            }
289:
290:            /**
291:             * @see IWorkbenchPreferencePage#init(IWorkbench)
292:             */
293:            public void init(IWorkbench workbench) {
294:            }
295:
296:            /**
297:             * Get the decorator definitions for the workbench.
298:             */
299:            private DecoratorDefinition[] getAllDefinitions() {
300:                return getDecoratorManager().getAllDecoratorDefinitions();
301:            }
302:
303:            /**
304:             * Get the DecoratorManager being used for this page.
305:             * 
306:             * @return the decorator manager
307:             */
308:            private DecoratorManager getDecoratorManager() {
309:                return WorkbenchPlugin.getDefault().getDecoratorManager();
310:            }
311:
312:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.