KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > browser > BrowserPreferences


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common.widgets.browser;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
26 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
27 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
28 import org.eclipse.core.runtime.Preferences;
29 import org.eclipse.jface.util.IPropertyChangeListener;
30 import org.eclipse.jface.util.PropertyChangeEvent;
31 import org.eclipse.jface.viewers.TreeViewer;
32
33
34 /**
35  * This class is a wrapper for the preferences of the browser widget.
36  *
37  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
38  * @version $Rev$, $Date$
39  */

40 public class BrowserPreferences implements IPropertyChangeListener, Preferences.IPropertyChangeListener
41 {
42
43     /** The tree viewer */
44     protected TreeViewer viewer;
45
46
47     /**
48      * Creates a new instance of BrowserPreferences.
49      */

50     public BrowserPreferences()
51     {
52         BrowserCommonActivator.getDefault().getPreferenceStore().addPropertyChangeListener( this );
53         BrowserCorePlugin.getDefault().getPluginPreferences().addPropertyChangeListener( this );
54     }
55
56
57     /**
58      * Connects the tree viewer to this preferences.
59      *
60      * @param viewer the tree viewer
61      */

62     public void connect( TreeViewer viewer )
63     {
64         this.viewer = viewer;
65     }
66
67
68     /**
69      * Disposes this preferences.
70      */

71     public void dispose()
72     {
73         BrowserCommonActivator.getDefault().getPreferenceStore().removePropertyChangeListener( this );
74         BrowserCorePlugin.getDefault().getPluginPreferences().removePropertyChangeListener( this );
75         viewer = null;
76     }
77
78
79     /**
80      * Gets the sort by, one of BrowserCoreConstants.SORT_BY_NONE,
81      * BrowserCoreConstants.SORT_BY_RDN or BrowserCoreConstants.SORT_BY_RDN_VALUE.
82      *
83      * @return the sort by
84      */

85     public int getSortBy()
86     {
87         return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY );
88     }
89
90
91     /**
92      * Gets the sort order, one of one of BrowserCoreConstants.SORT_ORDER_NONE,
93      * BrowserCoreConstants.SORT_ORDER_ASCENDING or BrowserCoreConstants.SORT_ORDER_DESCENDING.
94      *
95      * @return the sort order
96      */

97     public int getSortOrder()
98     {
99         return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
100             BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER );
101     }
102
103
104     /**
105      * Gets the sort limit.
106      *
107      * @return the sort limit
108      */

109     public int getSortLimit()
110     {
111         return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
112             BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT );
113     }
114
115
116     /**
117      * Returns true if leaf entries should be shown before non-leaf entries.
118      *
119      * @return true, if leaf entries should be shown first
120      */

121     public boolean isLeafEntriesFirst()
122     {
123         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
124             BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST );
125     }
126
127
128     /**
129      * Returns true if meta entries should be shown after non-meta entries.
130      *
131      * @return true, if meta entries should be shown first
132      */

133     public boolean isMetaEntriesLast()
134     {
135         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
136             BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST );
137     }
138
139
140     /**
141      * Returns true if the bookmark category should be visible.
142      *
143      * @return true if the bookmark category should be visible
144      */

145     public boolean isShowBookmarks()
146     {
147         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
148             BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_BOOKMARKS );
149     }
150
151
152     /**
153      * Returns true if the DIT category should be visible.
154      *
155      * @return true if the DIT category should be visible
156      */

157     public boolean isShowDIT()
158     {
159         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
160             BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIT );
161     }
162
163
164     /**
165      * Returns true if the searches category should be visible.
166      *
167      * @return true if the searches category should be visible
168      */

169     public boolean isShowSearches()
170     {
171         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
172             BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_SEARCHES );
173     }
174
175
176     /**
177      * Gets the folding size.
178      *
179      * @return the folding size
180      */

181     public int getFoldingSize()
182     {
183         return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
184             BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE );
185     }
186
187
188     /**
189      * Returns true if folding is enabled.
190      *
191      * @return true if folding is enabled
192      */

193     public boolean isUseFolding()
194     {
195         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
196             BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING );
197     }
198
199
200     /**
201      * Returns true if meta entries should be visible.
202      *
203      * @return true if meta entries should be visible
204      */

205     public boolean isShowDirectoryMetaEntries()
206     {
207         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
208             BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIRECTORY_META_ENTRIES );
209     }
210
211
212     /**
213      * Returns true if entry lables should be abbreviated.
214      *
215      * @return true if entry lables should be abbreviated
216      */

217     public boolean isEntryAbbreviate()
218     {
219         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
220             BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE );
221     }
222
223
224     /**
225      * Gets the entry's maximum label length.
226      *
227      * @return the entry's maximum label length
228      */

229     public int getEntryAbbreviateMaxLength()
230     {
231         return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
232             BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH );
233     }
234
235
236     /**
237      * Gets the entry label, one of BrowserWidgetsConstants.SHOW_DN,
238      * BrowserWidgetsConstants.SHOW_RDN or BrowserWidgetsConstants.SHOW_RDN_VALUE.
239      *
240      * @return the entry label
241      */

242     public int getEntryLabel()
243     {
244         return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
245             BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL );
246     }
247
248
249     /**
250      * Returns true if search result lables should be abbreviated.
251      *
252      * @return true if search result lables should be abbreviated
253      */

254     public boolean isSearchResultAbbreviate()
255     {
256         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
257             BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE );
258     }
259
260
261     /**
262      * Gets the search result's maximum label length.
263      *
264      * @return the search result's maximum label length
265      */

266     public int getSearchResultAbbreviateMaxLength()
267     {
268         return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
269             BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH );
270     }
271
272
273     /**
274      * Gets the search result label, one of BrowserWidgetsConstants.SHOW_DN,
275      * BrowserWidgetsConstants.SHOW_RDN or BrowserWidgetsConstants.SHOW_RDN_VALUE.
276      *
277      * @return the entry label
278      */

279     public int getSearchResultLabel()
280     {
281         return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
282             BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL );
283     }
284
285
286     /**
287      * Returns true if the base entries should be expanded when
288      * opening connection.
289      *
290      * @return true if the base entries should be expanded
291      */

292     public boolean isExpandBaseEntries()
293     {
294         return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
295             BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES );
296     }
297
298
299     /**
300      * Returns true if the browser should check for children
301      * while browsing the directory.
302      *
303      * @return true if the browser should check for children
304      */

305     public boolean isCheckForChildren()
306     {
307         Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
308         return coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN );
309     }
310
311
312     /**
313      * Returns true if the browser should dereference aliases and referrals.
314      *
315      *
316      * @return true if the browser should dereference aliases and referrals
317      */

318     public boolean isDerefAliasesAndReferralsWhileBrowsing()
319     {
320         Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
321         return coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS );
322     }
323
324
325     /**
326      * Returns true if subentries should be fetched while browsing.
327      *
328      *
329      * @return true if subentries should be fetched while browsing
330      */

331     public boolean isFetchSubentries()
332     {
333         Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
334         return coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES );
335     }
336
337
338     /**
339      * {@inheritDoc}
340      */

341     public void propertyChange( PropertyChangeEvent event )
342     {
343         if ( viewer != null )
344         {
345             viewer.refresh();
346         }
347     }
348
349
350     /**
351      * {@inheritDoc}
352      */

353     public void propertyChange( org.eclipse.core.runtime.Preferences.PropertyChangeEvent event )
354     {
355         if ( viewer != null )
356         {
357             viewer.refresh();
358         }
359     }
360
361 }
362
Popular Tags