KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > views > connection > ConnectionView


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.ui.views.connection;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.connection.ConnectionConfiguration;
25 import org.apache.directory.ldapstudio.browser.common.widgets.connection.ConnectionWidget;
26 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
27 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
28 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
29 import org.eclipse.jface.viewers.ISelection;
30 import org.eclipse.jface.viewers.StructuredSelection;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.layout.GridData;
33 import org.eclipse.swt.layout.GridLayout;
34 import org.eclipse.swt.widgets.Composite;
35 import org.eclipse.ui.PlatformUI;
36 import org.eclipse.ui.part.ViewPart;
37
38
39 /**
40  * This class implements the connection view. It displays all connections.
41  *
42  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
43  * @version $Rev$, $Date$
44  */

45 public class ConnectionView extends ViewPart
46 {
47
48     /** The configuration. */
49     private ConnectionConfiguration configuration;
50
51     /** The actions */
52     private ConnectionViewActionGroup actionGroup;
53
54     /** The main widget */
55     private ConnectionWidget mainWidget;
56
57     /** The listeners */
58     private ConnectionViewUniversalListener universalListener;
59
60
61     /**
62      * Returns the connection view ID.
63      *
64      * @return the connection view ID.
65      */

66     public static String JavaDoc getId()
67     {
68         return ConnectionView.class.getName();
69     }
70
71
72     /**
73      * Creates a new instance of ConnectionView.
74      */

75     public ConnectionView()
76     {
77     }
78
79
80     /**
81      * {@inheritDoc}
82      *
83      * This implementation sets focus to the viewer's control.
84      */

85     public void setFocus()
86     {
87         mainWidget.getViewer().getControl().setFocus();
88     }
89
90
91     /**
92      * {@inheritDoc}
93      */

94     public void dispose()
95     {
96         if ( configuration != null )
97         {
98             actionGroup.dispose();
99             actionGroup = null;
100             configuration.dispose();
101             configuration = null;
102             universalListener.dispose();
103             universalListener = null;
104             mainWidget.dispose();
105             mainWidget = null;
106             getSite().setSelectionProvider( null );
107         }
108
109         super.dispose();
110     }
111
112
113     /**
114      * {@inheritDoc}
115      */

116     public void createPartControl( Composite parent )
117     {
118
119         Composite composite = new Composite( parent, SWT.NONE );
120         composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
121         GridLayout layout = new GridLayout();
122         layout.marginWidth = 0;
123         layout.marginHeight = 0;
124         composite.setLayout( layout );
125
126         PlatformUI.getWorkbench().getHelpSystem().setHelp( composite,
127             BrowserUIPlugin.PLUGIN_ID + "." + "tools_connections_view" );
128
129         // create configuration
130
configuration = new ConnectionConfiguration();
131
132         // create main widget
133
mainWidget = new ConnectionWidget( configuration, getViewSite().getActionBars() );
134         mainWidget.createWidget( composite );
135         mainWidget.setInput( BrowserCorePlugin.getDefault().getConnectionManager() );
136
137         // create actions and context menu (and register global actions)
138
actionGroup = new ConnectionViewActionGroup( this );
139         actionGroup.fillToolBar( mainWidget.getToolBarManager() );
140         actionGroup.fillMenu( mainWidget.getMenuManager() );
141         actionGroup.enableGlobalActionHandlers( getViewSite().getActionBars() );
142         actionGroup.fillContextMenu( configuration.getContextMenuManager( mainWidget.getViewer() ) );
143
144         // create the listener
145
getSite().setSelectionProvider( mainWidget.getViewer() );
146         universalListener = new ConnectionViewUniversalListener( this );
147
148         // default selection
149
IConnection[] connections = BrowserCorePlugin.getDefault().getConnectionManager().getConnections();
150         if ( connections.length > 0 )
151         {
152             ISelection selection = new StructuredSelection( connections[0] );
153             mainWidget.getViewer().setSelection( selection );
154             //this.universalListener.selectionChanged( this, selection );
155
}
156
157     }
158
159
160     /**
161      * Selects the given object in the tree. The object
162      * must be an IConnection.
163      *
164      * @param obj the object to select
165      */

166     public void select( Object JavaDoc obj )
167     {
168         if ( obj instanceof IConnection )
169         {
170             IConnection connection = ( IConnection ) obj;
171
172             mainWidget.getViewer().reveal( connection );
173             mainWidget.getViewer().refresh( connection, true );
174             mainWidget.getViewer().setSelection( new StructuredSelection( connection ), true );
175         }
176     }
177
178
179     /**
180      * Gets the action group.
181      *
182      * @return the action group
183      */

184     public ConnectionViewActionGroup getActionGroup()
185     {
186         return actionGroup;
187     }
188
189
190     /**
191      * Gets the configuration.
192      *
193      * @return the configuration
194      */

195     public ConnectionConfiguration getConfiguration()
196     {
197         return configuration;
198     }
199
200
201     /**
202      * Gets the main widget.
203      *
204      * @return the main widget
205      */

206     public ConnectionWidget getMainWidget()
207     {
208         return mainWidget;
209     }
210
211
212     /**
213      * Gets the universal listener.
214      *
215      * @return the universal listener
216      */

217     public ConnectionViewUniversalListener getUniversalListener()
218     {
219         return universalListener;
220     }
221
222 }
223
Popular Tags