KickJava   Java API By Example, From Geeks To Geeks.

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


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.connection;
22
23
24 import org.eclipse.jface.action.IMenuManager;
25 import org.eclipse.jface.action.MenuManager;
26 import org.eclipse.jface.viewers.TableViewer;
27 import org.eclipse.swt.widgets.Menu;
28
29
30 /**
31  * The ConnectionConfiguration contains the content provider, the
32  * label provider and the context menu manager for the
33  * connection widget.
34  *
35  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
36  * @version $Rev$, $Date$
37  */

38 public class ConnectionConfiguration
39 {
40
41     /** The disposed flag */
42     private boolean disposed = false;
43
44     /** The content provider. */
45     private ConnectionContentProvider contentProvider;
46
47     /** The label provider. */
48     private ConnectionLabelProvider labelProvider;
49
50     /** The context menu manager. */
51     private MenuManager contextMenuManager;
52
53
54     /**
55      * Creates a new instance of ConnectionConfiguration.
56      */

57     public ConnectionConfiguration()
58     {
59     }
60
61
62     /**
63      * Disposes this configuration.
64      */

65     public void dispose()
66     {
67         if ( !disposed )
68         {
69
70             if ( contentProvider != null )
71             {
72                 contentProvider.dispose();
73                 contentProvider = null;
74             }
75
76             if ( labelProvider != null )
77             {
78                 labelProvider.dispose();
79                 labelProvider = null;
80             }
81
82             if ( contextMenuManager != null )
83             {
84                 contextMenuManager.dispose();
85                 contextMenuManager = null;
86             }
87
88             disposed = true;
89         }
90     }
91
92
93     /**
94      * Gets the context menu manager.
95      *
96      * @param viewer the connection widget's table viewer
97      *
98      * @return the context menu manager
99      */

100     public IMenuManager getContextMenuManager( TableViewer viewer )
101     {
102         if ( this.contextMenuManager == null )
103         {
104             this.contextMenuManager = new MenuManager();
105             Menu menu = this.contextMenuManager.createContextMenu( viewer.getControl() );
106             viewer.getControl().setMenu( menu );
107         }
108         return this.contextMenuManager;
109     }
110
111
112     /**
113      * Gets the content provider.
114      *
115      * @param viewer the connection widget's table viewer
116      *
117      * @return the content provider
118      */

119     public ConnectionContentProvider getContentProvider( TableViewer viewer )
120     {
121         if ( contentProvider == null )
122         {
123             contentProvider = new ConnectionContentProvider();
124         }
125
126         return contentProvider;
127     }
128
129
130     /**
131      * Gets the label provider.
132      *
133      * @param viewer the connection widget's table viewer
134      *
135      * @return the label provider
136      */

137     public ConnectionLabelProvider getLabelProvider( TableViewer viewer )
138     {
139         if ( labelProvider == null )
140         {
141             labelProvider = new ConnectionLabelProvider();
142         }
143
144         return labelProvider;
145     }
146
147 }
148
Popular Tags