KickJava   Java API By Example, From Geeks To Geeks.

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


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.eclipse.jface.action.IMenuManager;
26 import org.eclipse.jface.action.MenuManager;
27 import org.eclipse.jface.viewers.DecoratingLabelProvider;
28 import org.eclipse.jface.viewers.TreeViewer;
29 import org.eclipse.swt.widgets.Menu;
30
31
32 /**
33  * The BrowserConfiguration contains the content provider, the
34  * label provider, the sorter, the context menu manager and the
35  * preferences for 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 BrowserConfiguration
41 {
42
43     /** The disposed flag */
44     private boolean disposed = false;
45
46     /** The sorter. */
47     protected BrowserSorter sorter;
48
49     /** The preferences. */
50     protected BrowserPreferences preferences;
51
52     /** The content provider. */
53     protected BrowserContentProvider contentProvider;
54
55     /** The label provider. */
56     protected BrowserLabelProvider labelProvider;
57
58     /** The decorating label provider. */
59     protected DecoratingLabelProvider decoratingLabelProvider;
60
61     /** The context menu manager. */
62     protected MenuManager contextMenuManager;
63
64
65     /**
66      * Creates a new instance of BrowserConfiguration.
67      */

68     public BrowserConfiguration()
69     {
70     }
71
72
73     /**
74      * Disposes this configuration.
75      */

76     public void dispose()
77     {
78         if ( !disposed )
79         {
80             if ( sorter != null )
81             {
82                 sorter.dispose();
83                 sorter = null;
84             }
85
86             if ( preferences != null )
87             {
88                 preferences.dispose();
89                 preferences = null;
90             }
91
92             if ( contentProvider != null )
93             {
94                 contentProvider.dispose();
95                 contentProvider = null;
96             }
97
98             if ( labelProvider != null )
99             {
100                 labelProvider.dispose();
101                 labelProvider = null;
102                 decoratingLabelProvider.dispose();
103                 decoratingLabelProvider = null;
104             }
105
106             if ( contextMenuManager != null )
107             {
108                 contextMenuManager.dispose();
109                 contextMenuManager = null;
110             }
111
112             disposed = true;
113         }
114     }
115
116
117     /**
118      * Gets the context menu manager.
119      *
120      * @param viewer the browser widget's tree viewer
121      *
122      * @return the context menu manager
123      */

124     public IMenuManager getContextMenuManager( TreeViewer viewer )
125     {
126         if ( contextMenuManager == null )
127         {
128             contextMenuManager = new MenuManager();
129             Menu menu = contextMenuManager.createContextMenu( viewer.getControl() );
130             viewer.getControl().setMenu( menu );
131         }
132
133         return contextMenuManager;
134     }
135
136
137     /**
138      * Gets the content provider.
139      *
140      * @param viewer the browser widget's tree viewer
141      *
142      * @return the content provider
143      */

144     public BrowserContentProvider getContentProvider( TreeViewer viewer )
145     {
146         if ( contentProvider == null )
147         {
148             contentProvider = new BrowserContentProvider( getPreferences(), getSorter() );
149         }
150
151         return contentProvider;
152     }
153
154
155     /**
156      * Gets the label provider.
157      *
158      * @param viewer the browser widget's tree viewer
159      *
160      * @return the label provider
161      */

162     public DecoratingLabelProvider getLabelProvider( TreeViewer viewer )
163     {
164         if ( labelProvider == null )
165         {
166             labelProvider = new BrowserLabelProvider( getPreferences() );
167             decoratingLabelProvider = new DecoratingLabelProvider( labelProvider, BrowserCommonActivator.getDefault().getWorkbench()
168                 .getDecoratorManager().getLabelDecorator() );
169         }
170
171         return decoratingLabelProvider;
172     }
173
174
175     /**
176      * Gets the sorter.
177      *
178      * @return the sorter
179      */

180     public BrowserSorter getSorter()
181     {
182         if ( sorter == null )
183         {
184             sorter = new BrowserSorter( getPreferences() );
185         }
186
187         return sorter;
188     }
189
190
191     /**
192      * Gets the preferences.
193      *
194      * @return the preferences
195      */

196     public BrowserPreferences getPreferences()
197     {
198         if ( preferences == null )
199         {
200             preferences = new BrowserPreferences();
201         }
202
203         return preferences;
204     }
205
206 }
207
Popular Tags