Source Code Cross Referenced for QuickDiffConfigurationBlock.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » editors » text » 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 » org.eclipse.ui.internal.editors.text 
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:         *     hiroyuki.inaba@jp.fujitsu.com (Hiroyuki Inaba) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=82224
011:         *******************************************************************************/package org.eclipse.ui.internal.editors.text;
012:
013:        import java.util.ArrayList;
014:        import java.util.HashMap;
015:        import java.util.Iterator;
016:        import java.util.Map;
017:
018:        import org.eclipse.swt.SWT;
019:        import org.eclipse.swt.events.SelectionEvent;
020:        import org.eclipse.swt.events.SelectionListener;
021:        import org.eclipse.swt.layout.GridData;
022:        import org.eclipse.swt.layout.GridLayout;
023:        import org.eclipse.swt.widgets.Button;
024:        import org.eclipse.swt.widgets.Combo;
025:        import org.eclipse.swt.widgets.Composite;
026:        import org.eclipse.swt.widgets.Control;
027:        import org.eclipse.swt.widgets.Group;
028:        import org.eclipse.swt.widgets.Label;
029:
030:        import org.eclipse.core.runtime.Assert;
031:
032:        import org.eclipse.jface.action.LegacyActionTools;
033:        import org.eclipse.jface.preference.ColorSelector;
034:        import org.eclipse.jface.preference.PreferenceConverter;
035:
036:        import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
037:        import org.eclipse.ui.texteditor.AnnotationPreference;
038:        import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
039:        import org.eclipse.ui.texteditor.quickdiff.QuickDiff;
040:        import org.eclipse.ui.texteditor.quickdiff.ReferenceProviderDescriptor;
041:        import org.eclipse.ui.texteditor.spelling.SpellingService;
042:
043:        /**
044:         * Configures quick diff preferences
045:         *
046:         * @since 3.0
047:         */
048:        class QuickDiffConfigurationBlock implements 
049:                IPreferenceConfigurationBlock {
050:
051:            private OverlayPreferenceStore fStore;
052:
053:            private Map fCheckBoxes = new HashMap();
054:            private SelectionListener fCheckBoxListener = new SelectionListener() {
055:                public void widgetDefaultSelected(SelectionEvent e) {
056:                }
057:
058:                public void widgetSelected(SelectionEvent e) {
059:                    Button button = (Button) e.widget;
060:                    fStore.setValue((String) fCheckBoxes.get(button), button
061:                            .getSelection());
062:                }
063:            };
064:
065:            /**
066:             * List for the reference provider default.
067:             * @since 3.0
068:             */
069:            private Combo fQuickDiffProviderCombo;
070:            /**
071:             * The reference provider default's list model.
072:             * @since 3.0
073:             */
074:            private String[][] fQuickDiffProviderListModel;
075:            /**
076:             * The quick diff color model.
077:             * @since 3.0
078:             */
079:            private String[][] fQuickDiffModel;
080:            /**
081:             * The color editors for quick diff.
082:             * @since 3.0
083:             */
084:            private ColorSelector[] fQuickDiffColorEditors;
085:            /**
086:             * The checkbox for the quick diff overview ruler property.
087:             * @since 3.0
088:             */
089:            private Button fQuickDiffOverviewRulerCheckBox;
090:
091:            /**
092:             * The enablement checkbox.
093:             * @since 3.3.
094:             */
095:            private Button fEnablementCheckbox;
096:
097:            public QuickDiffConfigurationBlock(OverlayPreferenceStore store) {
098:                Assert.isNotNull(store);
099:                fStore = store;
100:                MarkerAnnotationPreferences markerAnnotationPreferences = EditorsPlugin
101:                        .getDefault().getMarkerAnnotationPreferences();
102:                fStore
103:                        .addKeys(createOverlayStoreKeys(markerAnnotationPreferences));
104:                fQuickDiffModel = createQuickDiffModel(markerAnnotationPreferences);
105:                fQuickDiffProviderListModel = createQuickDiffReferenceListModel();
106:            }
107:
108:            private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys(
109:                    MarkerAnnotationPreferences preferences) {
110:                ArrayList overlayKeys = new ArrayList();
111:
112:                overlayKeys
113:                        .add(new OverlayPreferenceStore.OverlayKey(
114:                                OverlayPreferenceStore.BOOLEAN,
115:                                AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON));
116:                overlayKeys
117:                        .add(new OverlayPreferenceStore.OverlayKey(
118:                                OverlayPreferenceStore.STRING,
119:                                AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER));
120:
121:                Iterator e = preferences.getAnnotationPreferences().iterator();
122:                while (e.hasNext()) {
123:                    AnnotationPreference info = (AnnotationPreference) e.next();
124:
125:                    if (info
126:                            .getAnnotationType()
127:                            .equals(
128:                                    "org.eclipse.ui.workbench.texteditor.quickdiffChange") //$NON-NLS-1$
129:                            || (info.getAnnotationType()
130:                                    .equals("org.eclipse.ui.workbench.texteditor.quickdiffAddition")) //$NON-NLS-1$
131:                            || (info.getAnnotationType()
132:                                    .equals("org.eclipse.ui.workbench.texteditor.quickdiffDeletion")) //$NON-NLS-1$
133:                    ) {
134:                        overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
135:                                OverlayPreferenceStore.STRING, info
136:                                        .getColorPreferenceKey()));
137:                        overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
138:                                OverlayPreferenceStore.BOOLEAN, info
139:                                        .getOverviewRulerPreferenceKey()));
140:                    }
141:                }
142:
143:                OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys
144:                        .size()];
145:                overlayKeys.toArray(keys);
146:                return keys;
147:            }
148:
149:            private String[][] createQuickDiffModel(
150:                    MarkerAnnotationPreferences preferences) {
151:                String[][] items = new String[3][];
152:
153:                Iterator e = preferences.getAnnotationPreferences().iterator();
154:                while (e.hasNext()) {
155:                    AnnotationPreference info = (AnnotationPreference) e.next();
156:                    if (info
157:                            .getAnnotationType()
158:                            .equals(
159:                                    "org.eclipse.ui.workbench.texteditor.quickdiffChange")) //$NON-NLS-1$
160:                        items[0] = new String[] {
161:                                info.getColorPreferenceKey(),
162:                                info.getOverviewRulerPreferenceKey(),
163:                                TextEditorMessages.QuickDiffConfigurationBlock_changeColor };
164:                    else if (info
165:                            .getAnnotationType()
166:                            .equals(
167:                                    "org.eclipse.ui.workbench.texteditor.quickdiffAddition")) //$NON-NLS-1$
168:                        items[1] = new String[] {
169:                                info.getColorPreferenceKey(),
170:                                info.getOverviewRulerPreferenceKey(),
171:                                TextEditorMessages.QuickDiffConfigurationBlock_additionColor };
172:                    else if (info
173:                            .getAnnotationType()
174:                            .equals(
175:                                    "org.eclipse.ui.workbench.texteditor.quickdiffDeletion")) //$NON-NLS-1$
176:                        items[2] = new String[] {
177:                                info.getColorPreferenceKey(),
178:                                info.getOverviewRulerPreferenceKey(),
179:                                TextEditorMessages.QuickDiffConfigurationBlock_deletionColor };
180:                }
181:                return items;
182:            }
183:
184:            private String[][] createQuickDiffReferenceListModel() {
185:                java.util.List descriptors = new QuickDiff()
186:                        .getReferenceProviderDescriptors();
187:                ArrayList listModelItems = new ArrayList();
188:                for (Iterator it = descriptors.iterator(); it.hasNext();) {
189:                    ReferenceProviderDescriptor descriptor = (ReferenceProviderDescriptor) it
190:                            .next();
191:                    String label = LegacyActionTools.removeMnemonics(descriptor
192:                            .getLabel());
193:                    listModelItems
194:                            .add(new String[] { descriptor.getId(), label });
195:                }
196:                String[][] items = new String[listModelItems.size()][];
197:                listModelItems.toArray(items);
198:                return items;
199:            }
200:
201:            private Button addCheckBox(Composite parent, String label,
202:                    String key, int indentation) {
203:                Button checkBox = new Button(parent, SWT.CHECK);
204:                checkBox.setText(label);
205:
206:                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
207:                gd.horizontalIndent = indentation;
208:                gd.horizontalSpan = 2;
209:                checkBox.setLayoutData(gd);
210:                checkBox.addSelectionListener(fCheckBoxListener);
211:
212:                fCheckBoxes.put(checkBox, key);
213:
214:                return checkBox;
215:            }
216:
217:            /**
218:             * Creates page for hover preferences.
219:             *
220:             * @param parent the parent composite
221:             * @return the created child composite
222:             */
223:            public Control createControl(Composite parent) {
224:                Composite composite = new Composite(parent, SWT.NONE);
225:                GridLayout layout = new GridLayout();
226:                layout.numColumns = 2;
227:                layout.marginHeight = 0;
228:                layout.marginWidth = 0;
229:                composite.setLayout(layout);
230:
231:                String label = TextEditorMessages.QuickDiffConfigurationBlock_showForNewEditors;
232:                fEnablementCheckbox = addCheckBox(
233:                        composite,
234:                        label,
235:                        AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON,
236:                        0);
237:                fEnablementCheckbox
238:                        .addSelectionListener(new SelectionListener() {
239:                            public void widgetSelected(SelectionEvent e) {
240:                                boolean enabled = fEnablementCheckbox
241:                                        .getSelection();
242:                                fStore
243:                                        .setValue(
244:                                                SpellingService.PREFERENCE_SPELLING_ENABLED,
245:                                                enabled);
246:                                updateEnablement();
247:                            }
248:
249:                            public void widgetDefaultSelected(SelectionEvent e) {
250:                            }
251:                        });
252:
253:                addFiller(composite);
254:
255:                label = TextEditorMessages.QuickDiffConfigurationBlock_showInOverviewRuler;
256:                fQuickDiffOverviewRulerCheckBox = new Button(composite,
257:                        SWT.CHECK);
258:                fQuickDiffOverviewRulerCheckBox.setText(label);
259:
260:                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
261:                gd.horizontalIndent = 0;
262:                gd.horizontalSpan = 2;
263:                gd.horizontalIndent = 10;
264:                fQuickDiffOverviewRulerCheckBox.setLayoutData(gd);
265:                fQuickDiffOverviewRulerCheckBox
266:                        .addSelectionListener(new SelectionListener() {
267:                            public void widgetSelected(SelectionEvent e) {
268:                                for (int i = 0; i < fQuickDiffModel.length; i++) {
269:                                    fStore.setValue(fQuickDiffModel[i][1],
270:                                            fQuickDiffOverviewRulerCheckBox
271:                                                    .getSelection());
272:                                }
273:                            }
274:
275:                            public void widgetDefaultSelected(SelectionEvent e) {
276:                            }
277:                        });
278:
279:                // spacer
280:                Label l = new Label(composite, SWT.LEFT);
281:                gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
282:                gd.horizontalSpan = 2;
283:                gd.horizontalIndent = 10;
284:                gd.heightHint = 5;
285:                l.setLayoutData(gd);
286:
287:                Group group = new Group(composite, SWT.NONE);
288:                group
289:                        .setText(TextEditorMessages.QuickDiffConfigurationBlock_colorTitle);
290:                layout = new GridLayout();
291:                layout.numColumns = 2;
292:                group.setLayout(layout);
293:                gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
294:                gd.horizontalSpan = 2;
295:                gd.horizontalIndent = 10;
296:                group.setLayoutData(gd);
297:
298:                fQuickDiffColorEditors = new ColorSelector[3];
299:                for (int i = 0; i < fQuickDiffModel.length; i++) {
300:                    label = fQuickDiffModel[i][2];
301:                    l = new Label(group, SWT.LEFT);
302:                    l.setText(label);
303:                    final ColorSelector editor = new ColorSelector(group);
304:                    fQuickDiffColorEditors[i] = editor;
305:                    Button changeColorButton = editor.getButton();
306:                    gd = new GridData(GridData.FILL_HORIZONTAL);
307:                    gd.horizontalAlignment = GridData.BEGINNING;
308:                    changeColorButton.setLayoutData(gd);
309:                    final int index = i;
310:                    changeColorButton
311:                            .addSelectionListener(new SelectionListener() {
312:                                public void widgetDefaultSelected(
313:                                        SelectionEvent e) {
314:                                    // do nothing
315:                                }
316:
317:                                public void widgetSelected(SelectionEvent e) {
318:                                    String key = fQuickDiffModel[index][0];
319:                                    PreferenceConverter.setValue(fStore, key,
320:                                            editor.getColorValue());
321:                                }
322:                            });
323:                }
324:
325:                addFiller(composite);
326:
327:                l = new Label(composite, SWT.LEFT);
328:                l
329:                        .setText(TextEditorMessages.QuickDiffConfigurationBlock_referenceProviderTitle);
330:                gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
331:                gd.horizontalSpan = 2;
332:                gd.horizontalIndent = 10;
333:                l.setLayoutData(gd);
334:
335:                Composite editorComposite = new Composite(composite, SWT.NONE);
336:                layout = new GridLayout();
337:                layout.numColumns = 2;
338:                layout.marginHeight = 0;
339:                layout.marginWidth = 0;
340:                editorComposite.setLayout(layout);
341:                gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL
342:                        | GridData.FILL_VERTICAL);
343:                gd.horizontalSpan = 2;
344:                gd.horizontalIndent = 10;
345:                editorComposite.setLayoutData(gd);
346:
347:                fQuickDiffProviderCombo = new Combo(editorComposite,
348:                        SWT.DROP_DOWN | SWT.READ_ONLY);
349:                gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
350:                        | GridData.FILL_HORIZONTAL);
351:                fQuickDiffProviderCombo.setLayoutData(gd);
352:
353:                Composite stylesComposite = new Composite(editorComposite,
354:                        SWT.NONE);
355:                layout = new GridLayout();
356:                layout.marginHeight = 0;
357:                layout.marginWidth = 0;
358:                layout.numColumns = 2;
359:                stylesComposite.setLayout(layout);
360:                stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
361:
362:                fQuickDiffProviderCombo
363:                        .addSelectionListener(new SelectionListener() {
364:                            public void widgetDefaultSelected(SelectionEvent e) {
365:                                // do nothing
366:                            }
367:
368:                            public void widgetSelected(SelectionEvent e) {
369:                                int i = fQuickDiffProviderCombo
370:                                        .getSelectionIndex();
371:                                fStore
372:                                        .setValue(
373:                                                AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER,
374:                                                fQuickDiffProviderListModel[i][0]);
375:                            }
376:
377:                        });
378:
379:                return composite;
380:            }
381:
382:            private void addFiller(Composite composite) {
383:                PixelConverter pixelConverter = new PixelConverter(composite);
384:
385:                Label filler = new Label(composite, SWT.LEFT);
386:                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
387:                gd.horizontalSpan = 2;
388:                gd.heightHint = pixelConverter.convertHeightInCharsToPixels(1) / 2;
389:                filler.setLayoutData(gd);
390:            }
391:
392:            private void updateEnablement() {
393:                final boolean enabled = fEnablementCheckbox.getSelection();
394:                fQuickDiffOverviewRulerCheckBox.setEnabled(enabled);
395:                fQuickDiffProviderCombo.setEnabled(enabled);
396:                for (int i = 0; i < fQuickDiffColorEditors.length; i++)
397:                    fQuickDiffColorEditors[i].setEnabled(enabled);
398:            }
399:
400:            private void updateProviderList() {
401:                String defaultProvider = fStore
402:                        .getString(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER);
403:                for (int j = 0; j < fQuickDiffProviderListModel.length; j++) {
404:                    if (defaultProvider
405:                            .equals(fQuickDiffProviderListModel[j][0])) {
406:                        fQuickDiffProviderCombo.select(j);
407:                    }
408:                }
409:                fQuickDiffProviderCombo.redraw();
410:            }
411:
412:            public void initialize() {
413:
414:                for (int i = 0; i < fQuickDiffProviderListModel.length; i++) {
415:                    String label = fQuickDiffProviderListModel[i][1];
416:                    fQuickDiffProviderCombo.add(label);
417:                }
418:                fQuickDiffProviderCombo.getDisplay().asyncExec(new Runnable() {
419:                    public void run() {
420:                        updateProviderList();
421:                    }
422:                });
423:
424:                initializeFields();
425:            }
426:
427:            private void initializeFields() {
428:                Iterator e = fCheckBoxes.keySet().iterator();
429:                while (e.hasNext()) {
430:                    Button b = (Button) e.next();
431:                    String key = (String) fCheckBoxes.get(b);
432:                    b.setSelection(fStore.getBoolean(key));
433:                }
434:
435:                updateQuickDiffControls();
436:            }
437:
438:            public boolean canPerformOk() {
439:                return true;
440:            }
441:
442:            public void performOk() {
443:            }
444:
445:            public void performDefaults() {
446:                initializeFields();
447:                updateProviderList();
448:            }
449:
450:            private void updateQuickDiffControls() {
451:                boolean quickdiffOverviewRuler = false;
452:                for (int i = 0; i < fQuickDiffModel.length; i++) {
453:                    fQuickDiffColorEditors[i].setColorValue(PreferenceConverter
454:                            .getColor(fStore, fQuickDiffModel[i][0]));
455:                    quickdiffOverviewRuler |= fStore
456:                            .getBoolean(fQuickDiffModel[i][1]);
457:                }
458:                fQuickDiffOverviewRulerCheckBox
459:                        .setSelection(quickdiffOverviewRuler);
460:            }
461:
462:            /*
463:             * @see org.eclipse.ui.internal.editors.text.IPreferenceConfigurationBlock#dispose()
464:             * @since 3.0
465:             */
466:            public void dispose() {
467:            }
468:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.