KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.directory.ldapstudio.browser.common.widgets.ViewFormWidget;
25 import org.eclipse.jface.action.IMenuManager;
26 import org.eclipse.jface.action.IToolBarManager;
27 import org.eclipse.jface.viewers.TableViewer;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Table;
33 import org.eclipse.ui.IActionBars;
34
35
36 /**
37  * The ConnectionWidget is a reusable widget that displays all connections
38  * in a table viewer. It is used by
39  * {@link org.apache.directory.ldapstudio.browser.ui.views.connection.ConnectionView},
40  * {@link org.apache.directory.ldapstudio.browser.common.dialogs.SelectConnectionDialog} and
41  * {@link org.apache.directory.ldapstudio.browser.common.dialogs.SelectReferralConnectionDialog}.
42  *
43  * It includes a content and label provider to display connections with a nice icon.
44  *
45  * Further is provides a context menu and a local toolbar with actions to
46  * add, modify, delete, open and close connections.
47  *
48  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
49  * @version $Rev$, $Date$
50  */

51 public class ConnectionWidget extends ViewFormWidget
52 {
53
54     /** The widget's configuration with the content provider, label provider and menu manager */
55     private ConnectionConfiguration configuration;
56
57     /** The action bars */
58     private IActionBars actionBars;
59
60     /** The table widget used by the table viewer */
61     private Table table;
62
63     /** The table viewer */
64     private TableViewer viewer;
65
66
67     /**
68      * Creates a new instance of ConnectionWidget.
69      *
70      * @param configuration the configuration
71      * @param actionBars the action bars
72      */

73     public ConnectionWidget( ConnectionConfiguration configuration, IActionBars actionBars )
74     {
75         this.configuration = configuration;
76         this.actionBars = actionBars;
77     }
78
79
80     /**
81      * {@inheritDoc}
82      */

83     public void createWidget( Composite parent )
84     {
85         if ( actionBars == null )
86         {
87             super.createWidget( parent );
88         }
89         else
90         {
91             createContent( parent );
92         }
93     }
94
95
96     /**
97      * {@inheritDoc}
98      */

99     public IToolBarManager getToolBarManager()
100     {
101         if ( actionBars == null )
102         {
103             return super.getToolBarManager();
104         }
105         else
106         {
107             return actionBars.getToolBarManager();
108         }
109     }
110
111
112     /**
113      * {@inheritDoc}
114      */

115     public IMenuManager getMenuManager()
116     {
117         if ( actionBars == null )
118         {
119             return super.getMenuManager();
120
121         }
122         else
123         {
124             return actionBars.getMenuManager();
125         }
126     }
127
128
129     /**
130      * {@inheritDoc}
131      */

132     public IMenuManager getContextMenuManager()
133     {
134         if ( actionBars == null )
135         {
136             return super.getContextMenuManager();
137         }
138         else
139         {
140             return configuration.getContextMenuManager( viewer );
141         }
142     }
143
144
145     /**
146      * {@inheritDoc}
147      */

148     protected Control createContent( Composite parent )
149     {
150
151         table = new Table( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
152         GridData data = new GridData( GridData.FILL_BOTH );
153         data.widthHint = 450;
154         data.heightHint = 250;
155         table.setLayoutData( data );
156         viewer = new TableViewer( table );
157
158         // setup providers
159
viewer.setContentProvider( configuration.getContentProvider( viewer ) );
160         viewer.setLabelProvider( configuration.getLabelProvider( viewer ) );
161
162         return table;
163     }
164
165
166     /**
167      * Sets the input to the table viewer.
168      *
169      * @param input the input
170      */

171     public void setInput( Object JavaDoc input )
172     {
173         viewer.setInput( input );
174     }
175
176
177     /**
178      * Sets focus to the table viewer.
179      */

180     public void setFocus()
181     {
182         viewer.getTable().setFocus();
183     }
184
185
186     /**
187      * {@inheritDoc}
188      */

189     public void dispose()
190     {
191         if ( viewer != null )
192         {
193             configuration.dispose();
194             configuration = null;
195
196             table.dispose();
197             table = null;
198             viewer = null;
199         }
200     }
201
202
203     /**
204      * Gets the table viewer.
205      *
206      * @return the table viewer
207      */

208     public TableViewer getViewer()
209     {
210         return viewer;
211     }
212
213 }
214
Popular Tags