KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > omg > lifl > eclipse > plugin > project > utils > SWT > DirectoryChooser


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Offroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 /*
27  * Created on 10 juin 2003 by jerome OFFROY (offroy@lifl.fr)
28  *
29  */

30
31 package org.omg.lifl.eclipse.plugin.project.utils.SWT;
32
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.events.ModifyEvent;
35 import org.eclipse.swt.events.ModifyListener;
36 import org.eclipse.swt.layout.RowLayout;
37 import org.eclipse.swt.widgets.Button;
38 import org.eclipse.swt.widgets.DirectoryDialog;
39 import org.eclipse.swt.widgets.Event;
40 import org.eclipse.swt.widgets.Group;
41 import org.eclipse.swt.widgets.Label;
42 import org.eclipse.swt.widgets.Listener;
43 import org.eclipse.swt.widgets.Text;
44 import org.omg.lifl.eclipse.plugin.project.OpenCCM.utils.ProjectMessages;
45
46 /**
47  * This abstract class is used to make a basic SWT area
48  * which allow configuration of some preferences store in a SetterGroupPreference
49  *
50  * @author offroy@lifl.fr
51  *
52  * @version 0.1
53  */

54 public abstract class DirectoryChooser {
55
56     private Group _parent;
57     protected Group subGroup;
58     protected boolean subGroupVisible;
59
60     private DirectoryDialog directoryDialog;
61     protected Text _text;
62     protected Label _label;
63     protected Button _btnChooser;
64     protected SetterGroupPreference _preference;
65
66     private static final String JavaDoc BLANK_END =
67         ProjectMessages.getString("DirectoryChooser.Blank_space");
68
69     /**
70      * Constructor
71      * @param parent is the SWT parent group
72      * @param preference the preferences to manage
73      */

74     public DirectoryChooser(Group parent, SetterGroupPreference preference) {
75         subGroupVisible = true;
76         set_preference(preference);
77         directoryDialog = new DirectoryDialog(parent.getShell());
78         set_parent(parent);
79         groupToSet(get_parent());
80     }
81
82     /**
83      * create a subGroup which parent is parent_group
84      * @param parent_group the main parent group
85      */

86     public void groupToSet(Group parent_group) {
87         String JavaDoc buttonTittle =
88             ProjectMessages.getString("DirectoryChooser.BrowseButtonLabel");
89         subGroup = new Group(parent_group, SWT.NONE);
90         subGroup.setLayout(new RowLayout());
91         subGroup.setText(_preference.get_GroupLabel());
92
93         setCheckButton();
94
95         _label = new Label(subGroup, SWT.LEFT);
96         _label.setText(_preference.get_Label());
97         set_text(new Text(subGroup, SWT.SINGLE | SWT.BORDER));
98         _text.setText(_preference.get_Name());
99         _text.addModifyListener(new ModifyListener() {
100             public void modifyText(ModifyEvent e) {
101                 //TODO add verification generic function
102
_preference.set_Name(_text.getText().trim());
103             }
104         });
105
106         directoryDialog.setFilterPath(_preference.get_Name());
107         _btnChooser = new Button(subGroup, SWT.NONE);
108         _btnChooser.setText(buttonTittle);
109
110         _btnChooser.addListener(SWT.Selection, new Listener() {
111
112             public void handleEvent(Event e) {
113                 String JavaDoc buffer = directoryDialog.open();
114                 if (buffer != null)
115                     config(buffer);
116             }
117         });
118
119     }
120
121     /**
122      * @param buffer
123      */

124     protected abstract void config(String JavaDoc buffer);
125
126     /**
127      *
128      */

129     protected abstract void setCheckButton();
130
131     /**
132      * @return the SWT Text widget
133      */

134     public Text get_text() {
135         return _text;
136     }
137
138     /**
139      * @param text is the SWT Text widget to set
140      */

141     public void set_text(Text text) {
142         _text = text;
143     }
144
145     /**
146      * @return the SetterGroupPreference which stores preference
147      */

148     public SetterGroupPreference get_preference() {
149         return _preference;
150     }
151
152     /**
153      * @param preference is the new SetterGroupPreference
154      */

155     public void set_preference(SetterGroupPreference preference) {
156         _preference = preference;
157     }
158
159     /**
160      * @return the parent SWT Group
161      */

162     public Group get_parent() {
163         return _parent;
164     }
165
166     /**
167      * set the parent SWT Group
168      * @param group to set the parent SWT Group
169      */

170     public void set_parent(Group group) {
171         _parent = group;
172     }
173
174     /**
175      * @return the internal SWT subGroup
176      */

177     public Group getSubGroup() {
178         return subGroup;
179     }
180
181     /**
182      * set the internal SWT subGroup
183      * @param group to set internal SWT subGroup
184      */

185     public void setSubGroup(Group group) {
186         subGroup = group;
187     }
188
189     /**
190      * @return the visibility of the SWT internal subGroup
191      */

192     public boolean isSubGroupVisible() {
193         return subGroupVisible;
194     }
195
196     /**
197      * @param b boolean to set visibility of the SWT internal subGroup
198      */

199     public void setSubGroupVisible(boolean b) {
200         subGroupVisible = b;
201     }
202
203 }
204
Popular Tags