KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > UIPreferenceInitializer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Kiryl Kazakevich, Intel - bug 88359
11  *******************************************************************************/

12 package org.eclipse.ui.internal;
13
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
18 import org.eclipse.core.runtime.preferences.DefaultScope;
19 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20 import org.eclipse.core.runtime.preferences.IScopeContext;
21 import org.eclipse.core.runtime.preferences.InstanceScope;
22 import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
23 import org.eclipse.ui.IWorkbenchPreferenceConstants;
24 import org.eclipse.ui.keys.IBindingService;
25 import org.osgi.service.prefs.BackingStoreException;
26
27 /**
28  * Implementation of the UI plugin's preference extension's customization
29  * element. This is needed in order to force the UI plugin's preferences to be
30  * initialized properly when running without
31  * org.eclipse.core.runtime.compatibility. For more details, see bug 58975 - New
32  * preference mechanism does not properly initialize defaults.
33  *
34  * @since 3.0
35  */

36 public class UIPreferenceInitializer extends AbstractPreferenceInitializer {
37
38     
39      
40     public void initializeDefaultPreferences() {
41
42         
43         IScopeContext context = new DefaultScope();
44         IEclipsePreferences node = context.getNode(UIPlugin.getDefault()
45                 .getBundle().getSymbolicName());
46         node.put(IWorkbenchPreferenceConstants.OPEN_NEW_PERSPECTIVE,
47                 IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE);
48
49         // Deprecated but kept for backwards compatibility
50
node.put(IWorkbenchPreferenceConstants.PROJECT_OPEN_NEW_PERSPECTIVE,
51                 IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE);
52         node.put(IWorkbenchPreferenceConstants.SHIFT_OPEN_NEW_PERSPECTIVE,
53                 IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE);
54         node.put(IWorkbenchPreferenceConstants.ALTERNATE_OPEN_NEW_PERSPECTIVE,
55                 IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE);
56
57         // Although there is no longer any item on the preference pages
58
// for setting the linking preference, since it is now a per-part
59
// setting, it remains as a preference to allow product overrides of the
60
// initial state of linking in the Navigator. By default, linking is
61
// off.
62
node.putBoolean(IWorkbenchPreferenceConstants.LINK_NAVIGATOR_TO_EDITOR,
63                 false);
64
65         // Appearance / Presentation preferences
66
node.put(IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID,
67                 IWorkbenchConstants.DEFAULT_PRESENTATION_ID);
68         node
69                 .putBoolean(
70                         IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
71                         true);
72         node.putBoolean(IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS, true);
73         node.put(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR,
74                 IWorkbenchPreferenceConstants.TOP_LEFT);
75         node.putBoolean(
76                 IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR,
77                 true);
78
79         // the fast view bar should be on the bottom of a fresh workspace
80
node.put(IWorkbenchPreferenceConstants.INITIAL_FAST_VIEW_BAR_LOCATION,
81                 IWorkbenchPreferenceConstants.BOTTOM);
82
83         // default to showing intro on startup
84
node.putBoolean(IWorkbenchPreferenceConstants.SHOW_INTRO, true);
85
86         // Default to the standard key configuration.
87
node.put(IWorkbenchPreferenceConstants.KEY_CONFIGURATION_ID,
88                 IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID);
89
90         // Preference for showing system jobs in the jobs view
91
node.putBoolean(IWorkbenchPreferenceConstants.SHOW_SYSTEM_JOBS, false);
92
93         // The default minimum character width for editor tabs is undefined
94
// (i.e., -1)
95
node
96                 .putInt(
97                         IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS,
98                         -1);
99
100         // The default minimum character width for view tabs is 1
101
node.putInt(IWorkbenchPreferenceConstants.VIEW_MINIMUM_CHARACTERS, 1);
102
103         // Default for closing editors on exit.
104
node.putBoolean(IWorkbenchPreferenceConstants.CLOSE_EDITORS_ON_EXIT,
105                 false);
106
107         // Default for using window working sets
108
node
109                 .putBoolean(
110                         IWorkbenchPreferenceConstants.USE_WINDOW_WORKING_SET_BY_DEFAULT,
111                         false);
112
113         // Default for showing filter text widget that determines what is shown
114
// in a FilteredTree
115
node
116                 .putBoolean(IWorkbenchPreferenceConstants.SHOW_FILTERED_TEXTS,
117                         true);
118
119         // Default for enabling detached views
120
node.putBoolean(IWorkbenchPreferenceConstants.ENABLE_DETACHED_VIEWS,
121                 true);
122
123         // Default for prompting for save when saveables are still held on to by other parts
124
node.putBoolean(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN,
125                 true);
126
127         // Default the min/max behaviour to the old (3.2) style
128
node.putBoolean(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX, true);
129         
130         // By default the Fast View Bar allows to select a new fast view from the view list
131
node.putBoolean(IWorkbenchPreferenceConstants.DISABLE_NEW_FAST_VIEW, false);
132         
133         // Default the sticky view close behaviour to the new style
134
node.putBoolean(IWorkbenchPreferenceConstants.ENABLE_32_STICKY_CLOSE_BEHAVIOR, false);
135
136         IEclipsePreferences rootNode = (IEclipsePreferences) Platform
137                 .getPreferencesService().getRootNode()
138                 .node(InstanceScope.SCOPE);
139
140         final String JavaDoc uiName = UIPlugin.getDefault().getBundle()
141                 .getSymbolicName();
142         try {
143             if (rootNode.nodeExists(uiName)) {
144                 ((IEclipsePreferences) rootNode.node(uiName))
145                         .addPreferenceChangeListener(PlatformUIPreferenceListener
146                                 .getSingleton());
147             }
148         } catch (BackingStoreException e) {
149             IStatus status = new Status(IStatus.ERROR, UIPlugin.getDefault()
150                     .getBundle().getSymbolicName(), IStatus.ERROR, e
151                     .getLocalizedMessage(), e);
152             UIPlugin.getDefault().getLog().log(status);
153         }
154
155         rootNode
156                 .addNodeChangeListener(new IEclipsePreferences.INodeChangeListener() {
157                     /*
158                      * (non-Javadoc)
159                      *
160                      * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
161                      */

162                     public void added(NodeChangeEvent event) {
163                         if (!event.getChild().name().equals(uiName)) {
164                             return;
165                         }
166                         ((IEclipsePreferences) event.getChild())
167                                 .addPreferenceChangeListener(PlatformUIPreferenceListener
168                                         .getSingleton());
169
170                     }
171
172                     /*
173                      * (non-Javadoc)
174                      *
175                      * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
176                      */

177                     public void removed(NodeChangeEvent event) {
178                         // Nothing to do here
179

180                     }
181
182                 });
183     }
184
185 }
186
Popular Tags