KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > search > 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.search;
22
23
24 import org.apache.directory.ldapstudio.browser.common.dialogs.SelectConnectionDialog;
25 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
26 import org.apache.directory.ldapstudio.browser.common.widgets.BrowserWidget;
27 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Text;
33
34
35 /**
36  * The ConnectionWidget could be used to select a connection.
37  * It is composed of a text to display the selected connection
38  * and a browse button to open a {@link SelectConnectionDialog}.
39  *
40  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
41  * @version $Rev$, $Date$
42  */

43 public class ConnectionWidget extends BrowserWidget
44 {
45
46     /** The connection text, displays the selected connection */
47     private Text connectionText;
48
49     /** The connection browse button, opens the dialog */
50     private Button connectionBrowseButton;
51
52     /** The selected connection */
53     private IConnection selectedConnection;
54
55
56     /**
57      * Creates a new instance of ConnectionWidget.
58      *
59      * @param connection the initial connection
60      */

61     public ConnectionWidget( IConnection connection )
62     {
63         this.selectedConnection = connection;
64     }
65
66
67     /**
68      * Creates a new instance of ConnectionWidget with no initial connection.
69      */

70     public ConnectionWidget()
71     {
72         this.selectedConnection = null;
73     }
74
75
76     /**
77      * Creates the widget.
78      *
79      * @param parent the parent
80      */

81     public void createWidget( final Composite parent )
82     {
83
84         // Text
85
connectionText = BaseWidgetUtils.createReadonlyText( parent, "", 1 );
86
87         // Button
88
connectionBrowseButton = BaseWidgetUtils.createButton( parent, "B&rowse...", 1 );
89         connectionBrowseButton.addSelectionListener( new SelectionAdapter()
90         {
91             public void widgetSelected( SelectionEvent e )
92             {
93                 // if(selectedConnection != null) {
94
SelectConnectionDialog dialog = new SelectConnectionDialog( parent.getShell(), "Select Connection",
95                     selectedConnection );
96                 dialog.open();
97                 IConnection connection = dialog.getSelectedConnection();
98                 if ( connection != null )
99                 {
100                     setConnection( connection );
101                     notifyListeners();
102                 }
103                 // }
104
}
105         } );
106
107         // initial values
108
setConnection( selectedConnection );
109
110     }
111
112
113     /**
114      * Gets the selected connection.
115      *
116      * @return the connection
117      */

118     public IConnection getConnection()
119     {
120         return selectedConnection;
121     }
122
123
124     /**
125      * Sets the selected connection.
126      *
127      * @param connection the connection
128      */

129     public void setConnection( IConnection connection )
130     {
131         selectedConnection = connection;
132         connectionText.setText( selectedConnection != null ? selectedConnection.getName() : "" );
133     }
134
135
136     /**
137      * Sets the enabled state of the widget.
138      *
139      * @param b true to enable the widget, false to disable the widget
140      */

141     public void setEnabled( boolean b )
142     {
143         connectionText.setEnabled( b );
144         connectionBrowseButton.setEnabled( b );
145     }
146
147 }
148
Popular Tags