Source Code Cross Referenced for PropertiesFileEditorPreferencePage.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, 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.preferences;
011:
012:        import java.io.BufferedReader;
013:        import java.io.IOException;
014:        import java.io.InputStreamReader;
015:        import java.util.ArrayList;
016:        import java.util.Iterator;
017:        import java.util.List;
018:
019:        import org.eclipse.core.runtime.Assert;
020:        import org.eclipse.core.runtime.IStatus;
021:
022:        import org.eclipse.swt.SWT;
023:        import org.eclipse.swt.events.DisposeEvent;
024:        import org.eclipse.swt.events.DisposeListener;
025:        import org.eclipse.swt.events.SelectionAdapter;
026:        import org.eclipse.swt.events.SelectionEvent;
027:        import org.eclipse.swt.events.SelectionListener;
028:        import org.eclipse.swt.graphics.Color;
029:        import org.eclipse.swt.graphics.Font;
030:        import org.eclipse.swt.graphics.RGB;
031:        import org.eclipse.swt.layout.GridData;
032:        import org.eclipse.swt.layout.GridLayout;
033:        import org.eclipse.swt.widgets.Button;
034:        import org.eclipse.swt.widgets.Composite;
035:        import org.eclipse.swt.widgets.Control;
036:        import org.eclipse.swt.widgets.Label;
037:        import org.eclipse.swt.widgets.Link;
038:
039:        import org.eclipse.jface.dialogs.Dialog;
040:        import org.eclipse.jface.preference.ColorSelector;
041:        import org.eclipse.jface.preference.IPreferenceStore;
042:        import org.eclipse.jface.preference.PreferenceConverter;
043:        import org.eclipse.jface.preference.PreferencePage;
044:        import org.eclipse.jface.resource.JFaceResources;
045:        import org.eclipse.jface.util.IPropertyChangeListener;
046:        import org.eclipse.jface.util.PropertyChangeEvent;
047:        import org.eclipse.jface.viewers.IColorProvider;
048:        import org.eclipse.jface.viewers.ISelectionChangedListener;
049:        import org.eclipse.jface.viewers.IStructuredContentProvider;
050:        import org.eclipse.jface.viewers.IStructuredSelection;
051:        import org.eclipse.jface.viewers.LabelProvider;
052:        import org.eclipse.jface.viewers.SelectionChangedEvent;
053:        import org.eclipse.jface.viewers.StructuredSelection;
054:        import org.eclipse.jface.viewers.TableViewer;
055:        import org.eclipse.jface.viewers.Viewer;
056:
057:        import org.eclipse.jface.text.Document;
058:        import org.eclipse.jface.text.IDocument;
059:        import org.eclipse.jface.text.source.SourceViewer;
060:
061:        import org.eclipse.ui.IWorkbench;
062:        import org.eclipse.ui.IWorkbenchPreferencePage;
063:        import org.eclipse.ui.PlatformUI;
064:        import org.eclipse.ui.dialogs.PreferencesUtil;
065:        import org.eclipse.ui.model.WorkbenchViewerSorter;
066:        import org.eclipse.ui.texteditor.ChainedPreferenceStore;
067:
068:        import org.eclipse.jdt.ui.PreferenceConstants;
069:        import org.eclipse.jdt.ui.text.IColorManager;
070:
071:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
072:        import org.eclipse.jdt.internal.ui.JavaPlugin;
073:        import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
074:        import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
075:        import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
076:        import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions;
077:        import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileDocumentSetupParticipant;
078:        import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileSourceViewerConfiguration;
079:        import org.eclipse.jdt.internal.ui.text.JavaColorManager;
080:        import org.eclipse.jdt.internal.ui.util.PixelConverter;
081:
082:        /**
083:         * The page for setting the properties file editor preferences.
084:         * 
085:         * @since 3.1
086:         */
087:        public class PropertiesFileEditorPreferencePage extends PreferencePage
088:                implements  IWorkbenchPreferencePage {
089:
090:            private static class SourcePreviewerUpdater {
091:
092:                /**
093:                 * Creates a Java source preview updater for the given viewer, configuration and preference store.
094:                 *
095:                 * @param viewer the viewer
096:                 * @param configuration the configuration
097:                 * @param preferenceStore the preference store
098:                 */
099:                SourcePreviewerUpdater(
100:                        final SourceViewer viewer,
101:                        final PropertiesFileSourceViewerConfiguration configuration,
102:                        final IPreferenceStore preferenceStore) {
103:                    Assert.isNotNull(viewer);
104:                    Assert.isNotNull(configuration);
105:                    Assert.isNotNull(preferenceStore);
106:                    final IPropertyChangeListener fontChangeListener = new IPropertyChangeListener() {
107:                        /*
108:                         * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
109:                         */
110:                        public void propertyChange(PropertyChangeEvent event) {
111:                            if (event
112:                                    .getProperty()
113:                                    .equals(
114:                                            PreferenceConstants.PROPERTIES_FILE_EDITOR_TEXT_FONT)) {
115:                                Font font = JFaceResources
116:                                        .getFont(PreferenceConstants.PROPERTIES_FILE_EDITOR_TEXT_FONT);
117:                                viewer.getTextWidget().setFont(font);
118:                            }
119:                        }
120:                    };
121:                    final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
122:                        /*
123:                         * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
124:                         */
125:                        public void propertyChange(PropertyChangeEvent event) {
126:                            if (configuration.affectsTextPresentation(event)) {
127:                                configuration.handlePropertyChangeEvent(event);
128:                                viewer.invalidateTextPresentation();
129:                            }
130:                        }
131:                    };
132:                    viewer.getTextWidget().addDisposeListener(
133:                            new DisposeListener() {
134:                                /*
135:                                 * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
136:                                 */
137:                                public void widgetDisposed(DisposeEvent e) {
138:                                    preferenceStore
139:                                            .removePropertyChangeListener(propertyChangeListener);
140:                                    JFaceResources.getFontRegistry()
141:                                            .removeListener(fontChangeListener);
142:                                }
143:                            });
144:                    JFaceResources.getFontRegistry().addListener(
145:                            fontChangeListener);
146:                    preferenceStore
147:                            .addPropertyChangeListener(propertyChangeListener);
148:                }
149:            }
150:
151:            /**
152:             * Item in the highlighting color list.
153:             */
154:            private static class HighlightingColorListItem {
155:                /** Display name */
156:                private String fDisplayName;
157:                /** Color preference key */
158:                private String fColorKey;
159:                /** Bold preference key */
160:                private String fBoldKey;
161:                /** Italic preference key */
162:                private String fItalicKey;
163:                /** 
164:                 * Strikethrough preference key.
165:                 * @since 3.1
166:                 */
167:                private String fStrikethroughKey;
168:                /**
169:                 * Underline preference key.
170:                 * @since 3.1
171:                 */
172:                private String fUnderlineKey;
173:                /** Item color */
174:                private Color fItemColor;
175:
176:                /**
177:                 * Initialize the item with the given values.
178:                 * 
179:                 * @param displayName the display name
180:                 * @param colorKey the color preference key
181:                 * @param boldKey the bold preference key
182:                 * @param italicKey the italic preference key
183:                 * @param strikethroughKey the strikethrough preference key
184:                 * @param underlineKey the underline preference key
185:                 * @param itemColor the item color
186:                 */
187:                public HighlightingColorListItem(String displayName,
188:                        String colorKey, String boldKey, String italicKey,
189:                        String strikethroughKey, String underlineKey,
190:                        Color itemColor) {
191:                    fDisplayName = displayName;
192:                    fColorKey = colorKey;
193:                    fBoldKey = boldKey;
194:                    fItalicKey = italicKey;
195:                    fStrikethroughKey = strikethroughKey;
196:                    fUnderlineKey = underlineKey;
197:                    fItemColor = itemColor;
198:                }
199:
200:                /**
201:                 * @return the bold preference key
202:                 */
203:                public String getBoldKey() {
204:                    return fBoldKey;
205:                }
206:
207:                /**
208:                 * @return the italic preference key
209:                 */
210:                public String getItalicKey() {
211:                    return fItalicKey;
212:                }
213:
214:                /**
215:                 * @return the strikethrough preference key
216:                 * @since 3.1
217:                 */
218:                public String getStrikethroughKey() {
219:                    return fStrikethroughKey;
220:                }
221:
222:                /**
223:                 * @return the underline preference key
224:                 * @since 3.1
225:                 */
226:                public String getUnderlineKey() {
227:                    return fUnderlineKey;
228:                }
229:
230:                /**
231:                 * @return the color preference key
232:                 */
233:                public String getColorKey() {
234:                    return fColorKey;
235:                }
236:
237:                /**
238:                 * @return the display name
239:                 */
240:                public String getDisplayName() {
241:                    return fDisplayName;
242:                }
243:
244:                /**
245:                 * @return the item color
246:                 */
247:                public Color getItemColor() {
248:                    return fItemColor;
249:                }
250:            }
251:
252:            /**
253:             * Color list label provider.
254:             */
255:            private class ColorListLabelProvider extends LabelProvider
256:                    implements  IColorProvider {
257:
258:                /*
259:                 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
260:                 */
261:                public String getText(Object element) {
262:                    return ((HighlightingColorListItem) element)
263:                            .getDisplayName();
264:                }
265:
266:                /*
267:                 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
268:                 */
269:                public Color getForeground(Object element) {
270:                    return ((HighlightingColorListItem) element).getItemColor();
271:                }
272:
273:                /*
274:                 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
275:                 */
276:                public Color getBackground(Object element) {
277:                    return null;
278:                }
279:            }
280:
281:            /**
282:             * Color list content provider.
283:             */
284:            private class ColorListContentProvider implements 
285:                    IStructuredContentProvider {
286:
287:                /*
288:                 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
289:                 */
290:                public Object[] getElements(Object inputElement) {
291:                    return ((java.util.List) inputElement).toArray();
292:                }
293:
294:                /*
295:                 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
296:                 */
297:                public void dispose() {
298:                }
299:
300:                /*
301:                 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
302:                 */
303:                public void inputChanged(Viewer viewer, Object oldInput,
304:                        Object newInput) {
305:                }
306:            }
307:
308:            private static final String BOLD = PreferenceConstants.EDITOR_BOLD_SUFFIX;
309:            /**
310:             * Preference key suffix for italic preferences.
311:             */
312:            private static final String ITALIC = PreferenceConstants.EDITOR_ITALIC_SUFFIX;
313:
314:            /**
315:             * Preference key suffix for strikethrough preferences.
316:             * @since 3.1
317:             */
318:            private static final String STRIKETHROUGH = PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX;
319:
320:            /**
321:             * Preference key suffix for underline preferences.
322:             * @since 3.1
323:             */
324:            private static final String UNDERLINE = PreferenceConstants.EDITOR_UNDERLINE_SUFFIX;
325:
326:            /** The keys of the overlay store. */
327:            private final String[][] fSyntaxColorListModel = new String[][] {
328:                    {
329:                            PreferencesMessages.PropertiesFileEditorPreferencePage_key,
330:                            PreferenceConstants.PROPERTIES_FILE_COLORING_KEY },
331:                    {
332:                            PreferencesMessages.PropertiesFileEditorPreferencePage_value,
333:                            PreferenceConstants.PROPERTIES_FILE_COLORING_VALUE },
334:                    {
335:                            PreferencesMessages.PropertiesFileEditorPreferencePage_assignment,
336:                            PreferenceConstants.PROPERTIES_FILE_COLORING_ASSIGNMENT },
337:                    {
338:                            PreferencesMessages.PropertiesFileEditorPreferencePage_argument,
339:                            PreferenceConstants.PROPERTIES_FILE_COLORING_ARGUMENT },
340:                    {
341:                            PreferencesMessages.PropertiesFileEditorPreferencePage_comment,
342:                            PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT } };
343:
344:            private OverlayPreferenceStore fOverlayStore;
345:
346:            private ColorSelector fSyntaxForegroundColorEditor;
347:            private Button fBoldCheckBox;
348:
349:            /**
350:             * Check box for italic preference.
351:             */
352:            private Button fItalicCheckBox;
353:
354:            /**
355:             * Check box for strikethrough preference.
356:             * @since 3.1
357:             */
358:            private Button fStrikethroughCheckBox;
359:
360:            /**
361:             * Check box for underline preference.
362:             * @since 3.1
363:             */
364:            private Button fUnderlineCheckBox;
365:
366:            private SourceViewer fPreviewViewer;
367:
368:            /**
369:             * Tells whether the fields are initialized.
370:             */
371:            private boolean fFieldsInitialized = false;
372:
373:            /**
374:             * List of master/slave listeners when there's a dependency.
375:             * 
376:             * @see #createDependency(Button, String, Control)
377:             */
378:            private ArrayList fMasterSlaveListeners = new ArrayList();
379:
380:            /**
381:             * Highlighting color list
382:             */
383:            private final List fHighlightingColorList = new ArrayList();
384:            /**
385:             * Highlighting color list viewer
386:             */
387:            private TableViewer fHighlightingColorListViewer;
388:
389:            /**
390:             * The color manager.
391:             */
392:            private IColorManager fColorManager;
393:
394:            /**
395:             * Creates a new preference page.
396:             */
397:            public PropertiesFileEditorPreferencePage() {
398:                setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore());
399:
400:                fOverlayStore = new OverlayPreferenceStore(
401:                        getPreferenceStore(), createOverlayStoreKeys());
402:            }
403:
404:            private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
405:
406:                ArrayList overlayKeys = new ArrayList();
407:
408:                for (int i = 0; i < fSyntaxColorListModel.length; i++) {
409:                    String colorKey = fSyntaxColorListModel[i][1];
410:                    overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
411:                            OverlayPreferenceStore.STRING, colorKey));
412:                    overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
413:                            OverlayPreferenceStore.BOOLEAN, colorKey + BOLD));
414:                    overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
415:                            OverlayPreferenceStore.BOOLEAN, colorKey + ITALIC));
416:                    overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
417:                            OverlayPreferenceStore.BOOLEAN, colorKey
418:                                    + STRIKETHROUGH));
419:                    overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
420:                            OverlayPreferenceStore.BOOLEAN, colorKey
421:                                    + UNDERLINE));
422:                }
423:
424:                OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys
425:                        .size()];
426:                overlayKeys.toArray(keys);
427:                return keys;
428:            }
429:
430:            /*
431:             * @see IWorkbenchPreferencePage#init()
432:             */
433:            public void init(IWorkbench workbench) {
434:            }
435:
436:            /*
437:             * @see PreferencePage#createControl(Composite)
438:             */
439:            public void createControl(Composite parent) {
440:                super .createControl(parent);
441:                PlatformUI
442:                        .getWorkbench()
443:                        .getHelpSystem()
444:                        .setHelp(
445:                                getControl(),
446:                                IJavaHelpContextIds.PROPERTIES_FILE_EDITOR_PREFERENCE_PAGE);
447:            }
448:
449:            private void handleSyntaxColorListSelection() {
450:                HighlightingColorListItem item = getHighlightingColorListItem();
451:                RGB rgb = PreferenceConverter.getColor(fOverlayStore, item
452:                        .getColorKey());
453:                fSyntaxForegroundColorEditor.setColorValue(rgb);
454:                fBoldCheckBox.setSelection(fOverlayStore.getBoolean(item
455:                        .getBoldKey()));
456:                fItalicCheckBox.setSelection(fOverlayStore.getBoolean(item
457:                        .getItalicKey()));
458:                fStrikethroughCheckBox.setSelection(fOverlayStore
459:                        .getBoolean(item.getStrikethroughKey()));
460:                fUnderlineCheckBox.setSelection(fOverlayStore.getBoolean(item
461:                        .getUnderlineKey()));
462:
463:                fSyntaxForegroundColorEditor.getButton().setEnabled(true);
464:                fBoldCheckBox.setEnabled(true);
465:                fItalicCheckBox.setEnabled(true);
466:                fStrikethroughCheckBox.setEnabled(true);
467:                fUnderlineCheckBox.setEnabled(true);
468:            }
469:
470:            private Control createSyntaxPage(Composite parent) {
471:
472:                Label label = new Label(parent, SWT.LEFT);
473:                label
474:                        .setText(PreferencesMessages.PropertiesFileEditorPreferencePage_foreground);
475:                label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
476:
477:                Composite editorComposite = new Composite(parent, SWT.NONE);
478:                GridLayout layout = new GridLayout();
479:                layout.numColumns = 2;
480:                layout.marginHeight = 0;
481:                layout.marginWidth = 0;
482:                editorComposite.setLayout(layout);
483:                GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
484:                editorComposite.setLayoutData(gd);
485:
486:                fHighlightingColorListViewer = new TableViewer(editorComposite,
487:                        SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER
488:                                | SWT.FULL_SELECTION);
489:                fHighlightingColorListViewer
490:                        .setLabelProvider(new ColorListLabelProvider());
491:                fHighlightingColorListViewer
492:                        .setContentProvider(new ColorListContentProvider());
493:                fHighlightingColorListViewer
494:                        .setComparator(new WorkbenchViewerSorter());
495:                gd = new GridData(SWT.BEGINNING, SWT.FILL, false, true);
496:                gd.heightHint = convertHeightInCharsToPixels(5);
497:                fHighlightingColorListViewer.getControl().setLayoutData(gd);
498:
499:                Composite stylesComposite = new Composite(editorComposite,
500:                        SWT.NONE);
501:                layout = new GridLayout();
502:                layout.marginHeight = 0;
503:                layout.marginWidth = 0;
504:                layout.numColumns = 2;
505:                stylesComposite.setLayout(layout);
506:                stylesComposite.setLayoutData(new GridData(SWT.BEGINNING,
507:                        SWT.BEGINNING, false, false));
508:
509:                gd = new GridData(GridData.FILL_HORIZONTAL);
510:                gd.horizontalAlignment = GridData.BEGINNING;
511:                gd.horizontalSpan = 2;
512:
513:                label = new Label(stylesComposite, SWT.LEFT);
514:                label
515:                        .setText(PreferencesMessages.PropertiesFileEditorPreferencePage_color);
516:                gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
517:                gd.horizontalIndent = 20;
518:                label.setLayoutData(gd);
519:
520:                fSyntaxForegroundColorEditor = new ColorSelector(
521:                        stylesComposite);
522:                Button foregroundColorButton = fSyntaxForegroundColorEditor
523:                        .getButton();
524:                gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
525:                foregroundColorButton.setLayoutData(gd);
526:
527:                fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
528:                fBoldCheckBox
529:                        .setText(PreferencesMessages.PropertiesFileEditorPreferencePage_bold);
530:                gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
531:                gd.horizontalIndent = 20;
532:                gd.horizontalSpan = 2;
533:                fBoldCheckBox.setLayoutData(gd);
534:
535:                fItalicCheckBox = new Button(stylesComposite, SWT.CHECK);
536:                fItalicCheckBox
537:                        .setText(PreferencesMessages.PropertiesFileEditorPreferencePage_italic);
538:                gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
539:                gd.horizontalIndent = 20;
540:                gd.horizontalSpan = 2;
541:                fItalicCheckBox.setLayoutData(gd);
542:
543:                fStrikethroughCheckBox = new Button(stylesComposite, SWT.CHECK);
544:                fStrikethroughCheckBox
545:                        .setText(PreferencesMessages.PropertiesFileEditorPreferencePage_strikethrough);
546:                gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
547:                gd.horizontalIndent = 20;
548:                gd.horizontalSpan = 2;
549:                fStrikethroughCheckBox.setLayoutData(gd);
550:
551:                fUnderlineCheckBox = new Button(stylesComposite, SWT.CHECK);
552:                fUnderlineCheckBox
553:                        .setText(PreferencesMessages.PropertiesFileEditorPreferencePage_underline);
554:                gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
555:                gd.horizontalIndent = 20;
556:                gd.horizontalSpan = 2;
557:                fUnderlineCheckBox.setLayoutData(gd);
558:
559:                label = new Label(parent, SWT.LEFT);
560:                label
561:                        .setText(PreferencesMessages.PropertiesFileEditorPreferencePage_preview);
562:                label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
563:
564:                Control previewer = createPreviewer(parent);
565:                gd = new GridData(GridData.FILL_BOTH);
566:                gd.widthHint = convertWidthInCharsToPixels(20);
567:                gd.heightHint = convertHeightInCharsToPixels(5);
568:                previewer.setLayoutData(gd);
569:
570:                fHighlightingColorListViewer
571:                        .addSelectionChangedListener(new ISelectionChangedListener() {
572:                            public void selectionChanged(
573:                                    SelectionChangedEvent event) {
574:                                handleSyntaxColorListSelection();
575:                            }
576:                        });
577:
578:                foregroundColorButton
579:                        .addSelectionListener(new SelectionListener() {
580:                            public void widgetDefaultSelected(SelectionEvent e) {
581:                                // do nothing
582:                            }
583:
584:                            public void widgetSelected(SelectionEvent e) {
585:                                HighlightingColorListItem item = getHighlightingColorListItem();
586:                                PreferenceConverter.setValue(fOverlayStore,
587:                                        item.getColorKey(),
588:                                        fSyntaxForegroundColorEditor
589:                                                .getColorValue());
590:                            }
591:                        });
592:
593:                fBoldCheckBox.addSelectionListener(new SelectionListener() {
594:                    public void widgetDefaultSelected(SelectionEvent e) {
595:                        // do nothing
596:                    }
597:
598:                    public void widgetSelected(SelectionEvent e) {
599:                        HighlightingColorListItem item = getHighlightingColorListItem();
600:                        fOverlayStore.setValue(item.getBoldKey(), fBoldCheckBox
601:                                .getSelection());
602:                    }
603:                });
604:
605:                fItalicCheckBox.addSelectionListener(new SelectionListener() {
606:                    public void widgetDefaultSelected(SelectionEvent e) {
607:                        // do nothing
608:                    }
609:
610:                    public void widgetSelected(SelectionEvent e) {
611:                        HighlightingColorListItem item = getHighlightingColorListItem();
612:                        fOverlayStore.setValue(item.getItalicKey(),
613:                                fItalicCheckBox.getSelection());
614:                    }
615:                });
616:
617:                fStrikethroughCheckBox
618:                        .addSelectionListener(new SelectionListener() {
619:                            public void widgetDefaultSelected(SelectionEvent e) {
620:                                // do nothing
621:                            }
622:
623:                            public void widgetSelected(SelectionEvent e) {
624:                                HighlightingColorListItem item = getHighlightingColorListItem();
625:                                fOverlayStore.setValue(item
626:                                        .getStrikethroughKey(),
627:                                        fStrikethroughCheckBox.getSelection());
628:                            }
629:                        });
630:
631:                fUnderlineCheckBox
632:                        .addSelectionListener(new SelectionListener() {
633:                            public void widgetDefaultSelected(SelectionEvent e) {
634:                                // do nothing
635:                            }
636:
637:                            public void widgetSelected(SelectionEvent e) {
638:                                HighlightingColorListItem item = getHighlightingColorListItem();
639:                                fOverlayStore.setValue(item.getUnderlineKey(),
640:                                        fUnderlineCheckBox.getSelection());
641:                            }
642:                        });
643:
644:                parent.layout();
645:
646:                return parent;
647:            }
648:
649:            private Control createPreviewer(Composite parent) {
650:
651:                IPreferenceStore store = new ChainedPreferenceStore(
652:                        new IPreferenceStore[] {
653:                                fOverlayStore,
654:                                JavaPlugin.getDefault()
655:                                        .getCombinedPreferenceStore() });
656:                fPreviewViewer = new JavaSourceViewer(parent, null, null,
657:                        false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store);
658:                fColorManager = new JavaColorManager(false);
659:                PropertiesFileSourceViewerConfiguration configuration = new PropertiesFileSourceViewerConfiguration(
660:                        fColorManager, store, null,
661:                        IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING);
662:                fPreviewViewer.configure(configuration);
663:                Font font = JFaceResources
664:                        .getFont(PreferenceConstants.PROPERTIES_FILE_EDITOR_TEXT_FONT);
665:                fPreviewViewer.getTextWidget().setFont(font);
666:                new SourcePreviewerUpdater(fPreviewViewer, configuration, store);
667:                fPreviewViewer.setEditable(false);
668:
669:                String content = loadPreviewContentFromFile("PropertiesFileEditorColorSettingPreviewCode.txt"); //$NON-NLS-1$
670:                IDocument document = new Document(content);
671:                PropertiesFileDocumentSetupParticipant.setupDocument(document);
672:                fPreviewViewer.setDocument(document);
673:
674:                return fPreviewViewer.getControl();
675:            }
676:
677:            private static void indent(Control control) {
678:                GridData gridData = new GridData();
679:                gridData.horizontalIndent = 20;
680:                control.setLayoutData(gridData);
681:            }
682:
683:            private void createDependency(final Button master,
684:                    String masterKey, final Control slave) {
685:                indent(slave);
686:                boolean masterState = fOverlayStore.getBoolean(masterKey);
687:                slave.setEnabled(masterState);
688:                SelectionListener listener = new SelectionListener() {
689:                    public void widgetSelected(SelectionEvent e) {
690:                        slave.setEnabled(master.getSelection());
691:                    }
692:
693:                    public void widgetDefaultSelected(SelectionEvent e) {
694:                    }
695:                };
696:                master.addSelectionListener(listener);
697:                fMasterSlaveListeners.add(listener);
698:            }
699:
700:            /*
701:             * @see PreferencePage#createContents(Composite)
702:             */
703:            protected Control createContents(Composite parent) {
704:                fOverlayStore.load();
705:                fOverlayStore.start();
706:
707:                Composite contents = new Composite(parent, SWT.NONE);
708:                GridLayout layout = new GridLayout();
709:                layout.marginHeight = 0;
710:                layout.marginWidth = 0;
711:                contents.setLayout(layout);
712:                contents.setLayoutData(new GridData(GridData.FILL_BOTH));
713:
714:                createHeader(contents);
715:
716:                createSyntaxPage(contents);
717:
718:                initialize();
719:
720:                Dialog.applyDialogFont(contents);
721:                return contents;
722:            }
723:
724:            private void createHeader(Composite contents) {
725:                String text = PreferencesMessages.PropertiesFileEditorPreferencePage_link;
726:                Link link = new Link(contents, SWT.NONE);
727:                link.setText(text);
728:                link.addSelectionListener(new SelectionAdapter() {
729:                    public void widgetSelected(SelectionEvent e) {
730:                        PreferencesUtil
731:                                .createPreferenceDialogOn(
732:                                        getShell(),
733:                                        "org.eclipse.ui.preferencePages.GeneralTextEditor", null, null); //$NON-NLS-1$
734:                    }
735:                });
736:                // TODO replace by link-specific tooltips when
737:                // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88866 gets fixed
738:                link
739:                        .setToolTipText(PreferencesMessages.PropertiesFileEditorPreferencePage_link_tooltip);
740:
741:                GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true,
742:                        false);
743:                gridData.widthHint = 150; // only expand further if anyone else requires it
744:                link.setLayoutData(gridData);
745:
746:                addFiller(contents);
747:            }
748:
749:            private void addFiller(Composite composite) {
750:                PixelConverter pixelConverter = new PixelConverter(composite);
751:
752:                Label filler = new Label(composite, SWT.LEFT);
753:                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
754:                gd.horizontalSpan = 2;
755:                gd.heightHint = pixelConverter.convertHeightInCharsToPixels(1) / 2;
756:                filler.setLayoutData(gd);
757:            }
758:
759:            private void initialize() {
760:
761:                initializeFields();
762:
763:                for (int i = 0, n = fSyntaxColorListModel.length; i < n; i++)
764:                    fHighlightingColorList.add(new HighlightingColorListItem(
765:                            fSyntaxColorListModel[i][0],
766:                            fSyntaxColorListModel[i][1],
767:                            fSyntaxColorListModel[i][1] + BOLD,
768:                            fSyntaxColorListModel[i][1] + ITALIC,
769:                            fSyntaxColorListModel[i][1] + STRIKETHROUGH,
770:                            fSyntaxColorListModel[i][1] + UNDERLINE, null));
771:
772:                fHighlightingColorListViewer.setInput(fHighlightingColorList);
773:                fHighlightingColorListViewer
774:                        .setSelection(new StructuredSelection(
775:                                fHighlightingColorListViewer.getElementAt(0)));
776:            }
777:
778:            private void initializeFields() {
779:                fFieldsInitialized = true;
780:                updateStatus(new StatusInfo());
781:
782:                // Update slaves
783:                Iterator iter = fMasterSlaveListeners.iterator();
784:                while (iter.hasNext()) {
785:                    SelectionListener listener = (SelectionListener) iter
786:                            .next();
787:                    listener.widgetSelected(null);
788:                }
789:            }
790:
791:            /*
792:             * @see PreferencePage#performOk()
793:             */
794:            public boolean performOk() {
795:                fOverlayStore.propagate();
796:                JavaPlugin.getDefault().savePluginPreferences();
797:                return true;
798:            }
799:
800:            /*
801:             * @see PreferencePage#performDefaults()
802:             */
803:            protected void performDefaults() {
804:
805:                fOverlayStore.loadDefaults();
806:
807:                initializeFields();
808:
809:                handleSyntaxColorListSelection();
810:
811:                super .performDefaults();
812:
813:                fPreviewViewer.invalidateTextPresentation();
814:            }
815:
816:            /*
817:             * @see DialogPage#dispose()
818:             */
819:            public void dispose() {
820:
821:                if (fOverlayStore != null) {
822:                    fOverlayStore.stop();
823:                    fOverlayStore = null;
824:                }
825:
826:                fColorManager.dispose();
827:
828:                super .dispose();
829:            }
830:
831:            private String loadPreviewContentFromFile(String filename) {
832:                String line;
833:                String separator = System.getProperty("line.separator"); //$NON-NLS-1$
834:                StringBuffer buffer = new StringBuffer(512);
835:                BufferedReader reader = null;
836:                try {
837:                    reader = new BufferedReader(new InputStreamReader(
838:                            getClass().getResourceAsStream(filename)));
839:                    while ((line = reader.readLine()) != null) {
840:                        buffer.append(line);
841:                        buffer.append(separator);
842:                    }
843:                } catch (IOException io) {
844:                    JavaPlugin.log(io);
845:                } finally {
846:                    if (reader != null) {
847:                        try {
848:                            reader.close();
849:                        } catch (IOException e) {
850:                        }
851:                    }
852:                }
853:                return buffer.toString();
854:            }
855:
856:            void updateStatus(IStatus status) {
857:                if (!fFieldsInitialized)
858:                    return;
859:
860:                setValid(!status.matches(IStatus.ERROR));
861:                StatusUtil.applyToStatusLine(this , status);
862:            }
863:
864:            /**
865:             * Returns the current highlighting color list item.
866:             * 
867:             * @return the current highlighting color list item
868:             */
869:            private HighlightingColorListItem getHighlightingColorListItem() {
870:                IStructuredSelection selection = (IStructuredSelection) fHighlightingColorListViewer
871:                        .getSelection();
872:                return (HighlightingColorListItem) selection.getFirstElement();
873:            }
874:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.