Source Code Cross Referenced for IDEWorkspacePreferencePage.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » internal » ide » 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 ide » org.eclipse.ui.internal.ide.dialogs 
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.ui.internal.ide.dialogs;
011:
012:        import java.util.Collections;
013:        import java.util.List;
014:
015:        import org.eclipse.core.resources.IWorkspaceDescription;
016:        import org.eclipse.core.resources.ResourcesPlugin;
017:        import org.eclipse.core.runtime.CoreException;
018:        import org.eclipse.core.runtime.Preferences;
019:        import org.eclipse.jface.preference.FieldEditor;
020:        import org.eclipse.jface.preference.IPreferenceStore;
021:        import org.eclipse.jface.preference.IntegerFieldEditor;
022:        import org.eclipse.jface.preference.PreferencePage;
023:        import org.eclipse.jface.preference.RadioGroupFieldEditor;
024:        import org.eclipse.jface.preference.StringFieldEditor;
025:        import org.eclipse.jface.util.IPropertyChangeListener;
026:        import org.eclipse.jface.util.PropertyChangeEvent;
027:        import org.eclipse.osgi.util.NLS;
028:        import org.eclipse.swt.SWT;
029:        import org.eclipse.swt.layout.GridData;
030:        import org.eclipse.swt.layout.GridLayout;
031:        import org.eclipse.swt.widgets.Button;
032:        import org.eclipse.swt.widgets.Composite;
033:        import org.eclipse.swt.widgets.Control;
034:        import org.eclipse.swt.widgets.Label;
035:        import org.eclipse.ui.IWorkbenchPreferencePage;
036:        import org.eclipse.ui.PlatformUI;
037:        import org.eclipse.ui.WorkbenchEncoding;
038:        import org.eclipse.ui.dialogs.PreferenceLinkArea;
039:        import org.eclipse.ui.ide.IDEEncoding;
040:        import org.eclipse.ui.ide.dialogs.ResourceEncodingFieldEditor;
041:        import org.eclipse.ui.internal.ide.IDEInternalPreferences;
042:        import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
043:        import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
044:        import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
045:        import org.eclipse.ui.internal.ide.LineDelimiterEditor;
046:        import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
047:
048:        /**
049:         * The IDEWorkspacePreferencePage is the page used to set IDE-specific preferences settings
050:         * related to workspace.
051:
052:         *Note:This class extends from PreferencePage,and there's no WorkspacePreferencePage class.
053:         *Hence when the IDE settings doesn't appear in this preference page, this page will be empty.
054:         */
055:        public class IDEWorkspacePreferencePage extends PreferencePage
056:                implements  IWorkbenchPreferencePage {
057:
058:            private Button autoBuildButton;
059:
060:            private Button autoSaveAllButton;
061:
062:            private IntegerFieldEditor saveInterval;
063:
064:            private Button autoRefreshButton;
065:
066:            private ResourceEncodingFieldEditor encodingEditor;
067:
068:            private LineDelimiterEditor lineSeparatorEditor;
069:
070:            //A boolean to indicate if the user settings were cleared.
071:            private boolean clearUserSettings = false;
072:
073:            private RadioGroupFieldEditor openReferencesEditor;
074:
075:            /*
076:             * (non-Javadoc)
077:             * 
078:             * @see org.eclipse.jface.preference.PreferencePage
079:             */
080:            protected Control createContents(Composite parent) {
081:
082:                PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
083:                        IIDEHelpContextIds.WORKSPACE_PREFERENCE_PAGE);
084:
085:                Composite composite = createComposite(parent);
086:
087:                PreferenceLinkArea area = new PreferenceLinkArea(
088:                        composite,
089:                        SWT.NONE,
090:                        "org.eclipse.ui.preferencePages.Startup", IDEWorkbenchMessages.IDEWorkspacePreference_relatedLink,//$NON-NLS-1$
091:                        (IWorkbenchPreferenceContainer) getContainer(), null);
092:
093:                GridData data = new GridData(GridData.FILL_HORIZONTAL
094:                        | GridData.GRAB_HORIZONTAL);
095:                area.getControl().setLayoutData(data);
096:
097:                Label space = new Label(composite, SWT.NONE);
098:                space.setLayoutData(new GridData());
099:
100:                createAutoBuildPref(composite);
101:                createAutoRefreshControls(composite);
102:                createSaveAllBeforeBuildPref(composite);
103:
104:                createSpace(composite);
105:                createSaveIntervalGroup(composite);
106:                createSpace(composite);
107:
108:                createOpenPrefControls(composite);
109:
110:                Composite lower = new Composite(composite, SWT.NONE);
111:                GridLayout lowerLayout = new GridLayout();
112:                lowerLayout.marginWidth = 0;
113:                lowerLayout.numColumns = 2;
114:                lowerLayout.makeColumnsEqualWidth = true;
115:                lower.setLayout(lowerLayout);
116:
117:                lower.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL
118:                        | GridData.GRAB_HORIZONTAL));
119:
120:                createEncodingEditorControls(lower);
121:                createLineSeparatorEditorControls(lower);
122:                applyDialogFont(composite);
123:
124:                return composite;
125:            }
126:
127:            /**
128:             * Creates controls for the preference to open required projects when
129:             * opening a project.
130:             * @param parent The parent control
131:             */
132:            private void createOpenPrefControls(Composite parent) {
133:                String name = IDEInternalPreferences.OPEN_REQUIRED_PROJECTS;
134:                String label = IDEWorkbenchMessages.IDEWorkspacePreference_openReferencedProjects;
135:                String[][] namesAndValues = {
136:                        { IDEWorkbenchMessages.Always,
137:                                IDEInternalPreferences.PSPM_ALWAYS },
138:                        { IDEWorkbenchMessages.Never,
139:                                IDEInternalPreferences.PSPM_NEVER },
140:                        { IDEWorkbenchMessages.Prompt,
141:                                IDEInternalPreferences.PSPM_PROMPT } };
142:                openReferencesEditor = new RadioGroupFieldEditor(name, label,
143:                        3, namesAndValues, parent, true);
144:                openReferencesEditor
145:                        .setPreferenceStore(getIDEPreferenceStore());
146:                openReferencesEditor.setPage(this );
147:                openReferencesEditor.load();
148:            }
149:
150:            protected void createSaveAllBeforeBuildPref(Composite composite) {
151:                autoSaveAllButton = new Button(composite, SWT.CHECK);
152:                autoSaveAllButton
153:                        .setText(IDEWorkbenchMessages.IDEWorkspacePreference_savePriorToBuilding);
154:                autoSaveAllButton
155:                        .setToolTipText(IDEWorkbenchMessages.IDEWorkspacePreference_savePriorToBuildingToolTip);
156:                autoSaveAllButton.setSelection(getIDEPreferenceStore()
157:                        .getBoolean(
158:                                IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD));
159:            }
160:
161:            protected void createAutoBuildPref(Composite composite) {
162:                autoBuildButton = new Button(composite, SWT.CHECK);
163:                autoBuildButton
164:                        .setText(IDEWorkbenchMessages.IDEWorkspacePreference_autobuild);
165:                autoBuildButton
166:                        .setToolTipText(IDEWorkbenchMessages.IDEWorkspacePreference_autobuildToolTip);
167:                autoBuildButton.setSelection(ResourcesPlugin.getWorkspace()
168:                        .isAutoBuilding());
169:            }
170:
171:            /**
172:             * Create a composite that contains entry fields specifying save interval
173:             * preference.
174:             * 
175:             * @param composite the Composite the group is created in.
176:             */
177:            private void createSaveIntervalGroup(Composite composite) {
178:                Composite groupComposite = new Composite(composite, SWT.LEFT);
179:                GridLayout layout = new GridLayout();
180:                layout.numColumns = 2;
181:                groupComposite.setLayout(layout);
182:                GridData gd = new GridData();
183:                gd.horizontalAlignment = GridData.FILL;
184:                gd.grabExcessHorizontalSpace = true;
185:                groupComposite.setLayoutData(gd);
186:
187:                saveInterval = new IntegerFieldEditor(
188:                        IDEInternalPreferences.SAVE_INTERVAL,
189:                        IDEWorkbenchMessages.WorkbenchPreference_saveInterval,
190:                        groupComposite);
191:
192:                // @issue we should drop our preference constant and let clients use
193:                // core's pref. ours is not up-to-date anyway if someone changes this
194:                // interval directly thru core api.
195:                saveInterval.setPreferenceStore(getIDEPreferenceStore());
196:                saveInterval.setPage(this );
197:                saveInterval.setTextLimit(Integer.toString(
198:                        IDEInternalPreferences.MAX_SAVE_INTERVAL).length());
199:                saveInterval
200:                        .setErrorMessage(NLS
201:                                .bind(
202:                                        IDEWorkbenchMessages.WorkbenchPreference_saveIntervalError,
203:                                        new Integer(
204:                                                IDEInternalPreferences.MAX_SAVE_INTERVAL)));
205:                saveInterval
206:                        .setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);
207:                saveInterval.setValidRange(1,
208:                        IDEInternalPreferences.MAX_SAVE_INTERVAL);
209:
210:                IWorkspaceDescription description = ResourcesPlugin
211:                        .getWorkspace().getDescription();
212:                long interval = description.getSnapshotInterval() / 60000;
213:                saveInterval.setStringValue(Long.toString(interval));
214:
215:                saveInterval
216:                        .setPropertyChangeListener(new IPropertyChangeListener() {
217:
218:                            public void propertyChange(PropertyChangeEvent event) {
219:                                if (event.getProperty().equals(
220:                                        FieldEditor.IS_VALID)) {
221:                                    setValid(saveInterval.isValid());
222:                                }
223:                            }
224:                        });
225:
226:            }
227:
228:            /**
229:             * Create the Refresh controls
230:             * 
231:             * @param parent
232:             */
233:            private void createAutoRefreshControls(Composite parent) {
234:
235:                this .autoRefreshButton = new Button(parent, SWT.CHECK);
236:                this .autoRefreshButton
237:                        .setText(IDEWorkbenchMessages.IDEWorkspacePreference_RefreshButtonText);
238:                this .autoRefreshButton
239:                        .setToolTipText(IDEWorkbenchMessages.IDEWorkspacePreference_RefreshButtonToolTip);
240:
241:                boolean autoRefresh = ResourcesPlugin.getPlugin()
242:                        .getPluginPreferences().getBoolean(
243:                                ResourcesPlugin.PREF_AUTO_REFRESH);
244:                this .autoRefreshButton.setSelection(autoRefresh);
245:            }
246:
247:            /**
248:             * Create a composite that contains the encoding controls
249:             * 
250:             * @param parent
251:             */
252:            private void createEncodingEditorControls(Composite parent) {
253:                Composite encodingComposite = new Composite(parent, SWT.NONE);
254:                encodingComposite.setLayout(new GridLayout());
255:                encodingComposite.setLayoutData(new GridData(
256:                        GridData.HORIZONTAL_ALIGN_FILL
257:                                | GridData.GRAB_HORIZONTAL));
258:
259:                encodingEditor = new ResourceEncodingFieldEditor(
260:                        IDEWorkbenchMessages.WorkbenchPreference_encoding,
261:                        encodingComposite, ResourcesPlugin.getWorkspace()
262:                                .getRoot());
263:
264:                encodingEditor.setPage(this );
265:                encodingEditor.load();
266:                encodingEditor
267:                        .setPropertyChangeListener(new IPropertyChangeListener() {
268:                            /* (non-Javadoc)
269:                             * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
270:                             */
271:                            public void propertyChange(PropertyChangeEvent event) {
272:                                if (event.getProperty().equals(
273:                                        FieldEditor.IS_VALID)) {
274:                                    setValid(encodingEditor.isValid());
275:                                }
276:
277:                            }
278:                        });
279:            }
280:
281:            /**
282:             * Create a composite that contains the line delimiter controls
283:             * 
284:             * @param parent
285:             */
286:            private void createLineSeparatorEditorControls(Composite parent) {
287:                Composite lineComposite = new Composite(parent, SWT.NONE);
288:                final GridLayout gridLayout = new GridLayout();
289:                gridLayout.marginWidth = 0;
290:                gridLayout.marginHeight = 0;
291:                lineComposite.setLayout(gridLayout);
292:
293:                lineComposite.setLayoutData(new GridData(
294:                        GridData.HORIZONTAL_ALIGN_FILL
295:                                | GridData.GRAB_HORIZONTAL));
296:
297:                lineSeparatorEditor = new LineDelimiterEditor(lineComposite);
298:                lineSeparatorEditor.doLoad();
299:            }
300:
301:            /**
302:             * Returns the IDE preference store.
303:             * @return the preference store.
304:             */
305:            protected IPreferenceStore getIDEPreferenceStore() {
306:                return IDEWorkbenchPlugin.getDefault().getPreferenceStore();
307:            }
308:
309:            /**
310:             * Creates a tab of one horizontal spans.
311:             * 
312:             * @param parent
313:             *            the parent in which the tab should be created
314:             */
315:            protected static void createSpace(Composite parent) {
316:                Label vfiller = new Label(parent, SWT.LEFT);
317:                GridData gridData = new GridData();
318:                gridData = new GridData();
319:                gridData.horizontalAlignment = GridData.BEGINNING;
320:                gridData.grabExcessHorizontalSpace = false;
321:                gridData.verticalAlignment = GridData.CENTER;
322:                gridData.grabExcessVerticalSpace = false;
323:                vfiller.setLayoutData(gridData);
324:            }
325:
326:            /**
327:             * Creates the composite which will contain all the preference controls for
328:             * this page.
329:             * 
330:             * @param parent
331:             *            the parent composite
332:             * @return the composite for this page
333:             */
334:            protected Composite createComposite(Composite parent) {
335:                Composite composite = new Composite(parent, SWT.NONE);
336:                GridLayout layout = new GridLayout();
337:                layout.marginWidth = 0;
338:                layout.marginHeight = 0;
339:                composite.setLayout(layout);
340:                composite.setLayoutData(new GridData(
341:                        GridData.VERTICAL_ALIGN_FILL
342:                                | GridData.HORIZONTAL_ALIGN_FILL));
343:                return composite;
344:            }
345:
346:            public void init(org.eclipse.ui.IWorkbench workbench) {
347:                //no-op
348:            }
349:
350:            /**
351:             * The default button has been pressed.
352:             */
353:            protected void performDefaults() {
354:
355:                // core holds onto this preference.
356:                boolean autoBuild = ResourcesPlugin.getPlugin()
357:                        .getPluginPreferences().getDefaultBoolean(
358:                                ResourcesPlugin.PREF_AUTO_BUILDING);
359:                autoBuildButton.setSelection(autoBuild);
360:
361:                IPreferenceStore store = getIDEPreferenceStore();
362:                autoSaveAllButton
363:                        .setSelection(store
364:                                .getDefaultBoolean(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD));
365:                saveInterval.loadDefault();
366:
367:                boolean autoRefresh = ResourcesPlugin.getPlugin()
368:                        .getPluginPreferences().getDefaultBoolean(
369:                                ResourcesPlugin.PREF_AUTO_REFRESH);
370:                autoRefreshButton.setSelection(autoRefresh);
371:
372:                clearUserSettings = true;
373:
374:                List encodings = WorkbenchEncoding.getDefinedEncodings();
375:                Collections.sort(encodings);
376:                encodingEditor.loadDefault();
377:                lineSeparatorEditor.loadDefault();
378:                openReferencesEditor.loadDefault();
379:
380:                super .performDefaults();
381:            }
382:
383:            /**
384:             * The user has pressed Ok. Store/apply this page's values appropriately.
385:             */
386:            public boolean performOk() {
387:                // set the workspace auto-build flag
388:                IWorkspaceDescription description = ResourcesPlugin
389:                        .getWorkspace().getDescription();
390:                if (autoBuildButton.getSelection() != ResourcesPlugin
391:                        .getWorkspace().isAutoBuilding()) {
392:                    try {
393:                        description.setAutoBuilding(autoBuildButton
394:                                .getSelection());
395:                        ResourcesPlugin.getWorkspace().setDescription(
396:                                description);
397:                    } catch (CoreException e) {
398:                        IDEWorkbenchPlugin
399:                                .log(
400:                                        "Error changing auto build workspace setting.", e//$NON-NLS-1$
401:                                                .getStatus());
402:                    }
403:                }
404:
405:                IPreferenceStore store = getIDEPreferenceStore();
406:
407:                // store the save all prior to build setting
408:                store.setValue(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD,
409:                        autoSaveAllButton.getSelection());
410:
411:                // store the workspace save interval
412:                // @issue we should drop our preference constant and let clients use
413:                // core's pref. ours is not up-to-date anyway if someone changes this
414:                // interval directly thru core api.
415:                long oldSaveInterval = description.getSnapshotInterval() / 60000;
416:                long newSaveInterval = new Long(saveInterval.getStringValue())
417:                        .longValue();
418:                if (oldSaveInterval != newSaveInterval) {
419:                    try {
420:                        description
421:                                .setSnapshotInterval(newSaveInterval * 60000);
422:                        ResourcesPlugin.getWorkspace().setDescription(
423:                                description);
424:                        store.firePropertyChangeEvent(
425:                                IDEInternalPreferences.SAVE_INTERVAL,
426:                                new Integer((int) oldSaveInterval),
427:                                new Integer((int) newSaveInterval));
428:                    } catch (CoreException e) {
429:                        IDEWorkbenchPlugin.log(
430:                                "Error changing save interval preference", e //$NON-NLS-1$
431:                                        .getStatus());
432:                    }
433:                }
434:
435:                Preferences preferences = ResourcesPlugin.getPlugin()
436:                        .getPluginPreferences();
437:
438:                boolean autoRefresh = autoRefreshButton.getSelection();
439:                preferences.setValue(ResourcesPlugin.PREF_AUTO_REFRESH,
440:                        autoRefresh);
441:
442:                if (clearUserSettings) {
443:                    IDEEncoding.clearUserEncodings();
444:                }
445:                encodingEditor.store();
446:                lineSeparatorEditor.store();
447:                openReferencesEditor.store();
448:                return super.performOk();
449:            }
450:
451:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.