KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > preferencepages > JonasPreferencePage


1 package com.bull.eclipse.jonas.preferencepages;
2
3 /*
4  * (c) Copyright Bull SA 2003.
5  * All Rights Reserved.
6  */

7
8 import java.io.File JavaDoc;
9
10 import org.eclipse.jface.preference.BooleanFieldEditor;
11 import org.eclipse.jface.preference.DirectoryFieldEditor;
12 import org.eclipse.jface.preference.FieldEditor;
13 import org.eclipse.jface.preference.PreferencePage;
14 import org.eclipse.jface.preference.RadioGroupFieldEditor;
15 import org.eclipse.jface.util.IPropertyChangeListener;
16 import org.eclipse.jface.util.PropertyChangeEvent;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.ModifyListener;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.ui.IWorkbench;
25 import org.eclipse.ui.IWorkbenchPreferencePage;
26
27 import com.bull.eclipse.jonas.JonasLauncherPlugin;
28 import com.bull.eclipse.jonas.JonasPluginResources;
29 import com.bull.eclipse.jonas.editors.ClasspathFieldEditor;
30
31
32 public class JonasPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, JonasPluginResources {
33
34     static final private int FIELD_WIDTH = 50;
35     private RadioGroupFieldEditor version;
36     private DirectoryFieldEditor home;
37     private DirectoryFieldEditor base;
38     private RadioGroupFieldEditor orb;
39     private ClasspathFieldEditor xtraClasspath;
40     
41     private BooleanFieldEditor debugModeEditor;
42     private ModifyListener fModifyListener;
43         
44     public JonasPreferencePage() {
45         super();
46         setPreferenceStore(JonasLauncherPlugin.getDefault().getPreferenceStore());
47 // setDescription("");
48

49     }
50
51     /*
52      * @see PreferencePage#createContents(Composite)
53      */

54
55     protected Control createContents(Composite parent) {
56
57
58         Composite composite = new Composite(parent, SWT.NULL);
59         composite.setLayout(new GridLayout());
60
61         Composite versionGroup = new Composite(composite,SWT.NONE);
62         
63         version = new RadioGroupFieldEditor(
64                 JonasLauncherPlugin.JONAS_PREF_VERSION_KEY,
65                 PREF_PAGE_CHOOSEVERSION_LABEL,
66                 1,
67                 new String JavaDoc[][] {
68                     {PREF_PAGE_VERSION30_LABEL, JonasLauncherPlugin.JONAS_VERSION30},
69                     {PREF_PAGE_VERSION31_LABEL, JonasLauncherPlugin.JONAS_VERSION31},
70                     {PREF_PAGE_VERSION40_LABEL, JonasLauncherPlugin.JONAS_VERSION40},
71                     {PREF_PAGE_VERSION41_LABEL, JonasLauncherPlugin.JONAS_VERSION41},
72                     {PREF_PAGE_VERSION414_LABEL, JonasLauncherPlugin.JONAS_VERSION414},
73                 },
74                 versionGroup);
75                 
76         new Label(composite, SWT.NULL); //blank
77

78                         
79         Composite homeGroup = new Composite(composite,SWT.NONE);
80         GridData gd = new GridData();
81         gd.horizontalAlignment = GridData.FILL;
82         homeGroup.setLayoutData(gd);
83         home = new DirectoryFieldEditor(
84                 JonasLauncherPlugin.JONAS_PREF_HOME_KEY,
85                 PREF_PAGE_HOME_LABEL,
86                 homeGroup);
87                 
88         base = new DirectoryFieldEditor(
89                 JonasLauncherPlugin.JONAS_PREF_BASE_KEY,
90                 PREF_PAGE_BASE_LABEL,
91                 homeGroup);
92                     
93         home.setPropertyChangeListener(new IPropertyChangeListener() {
94             public void propertyChange(PropertyChangeEvent event) {
95                 if(event.getProperty().equals(FieldEditor.VALUE)) {
96                     computeConfigFile();
97                 }
98             }
99         });
100
101
102     
103         new Label(composite, SWT.NULL); //blank
104

105         final Composite orbGroup = new Composite(composite,SWT.NONE);
106         
107         orb = new RadioGroupFieldEditor(
108                         JonasLauncherPlugin.JONAS_PREF_ORB_KEY,
109                         PREF_PAGE_ORB_LABEL,
110                         1,
111                         new String JavaDoc[][] {
112                             {PREF_PAGE_RMI_LABEL, JonasLauncherPlugin.JONAS_ORB_RMI},
113                             {PREF_PAGE_JEREMIE_LABEL, JonasLauncherPlugin.JONAS_ORB_JEREMIE},
114                         },
115                         orbGroup);
116         
117         
118         version.setPropertyChangeListener(new IPropertyChangeListener() {
119             public void propertyChange(PropertyChangeEvent event) {
120                 String JavaDoc newValue = (String JavaDoc)event.getNewValue();
121                 if (!newValue.equals(event.getOldValue())) {
122                     if (!newValue.equals(JonasLauncherPlugin.JONAS_VERSION30)) {
123                         orb.setEnabled(false,orbGroup);
124                     } else {
125                         orb.setEnabled(true,orbGroup);
126                     }
127                 }
128             }
129         });
130             
131         new Label(composite, SWT.NULL); //blank
132

133         xtraClasspath = new ClasspathFieldEditor(
134                         JonasLauncherPlugin.JONAS_PREF_XTRA_CLASSPATH_KEY,
135                         PREF_PAGE_XTRACLASSPATH_LABEL,
136                         composite);
137
138         new Label(composite, SWT.NULL);
139
140
141         this.initField(version);
142         this.initField(home);
143         this.initField(base);
144         this.initField(xtraClasspath);
145         this.initField(orb);
146         
147         if (!version.getPreferenceStore().getString(JonasLauncherPlugin.JONAS_PREF_VERSION_KEY).equals(JonasLauncherPlugin.JONAS_VERSION30))
148             orb.setEnabled(false,orbGroup);
149         
150         if(base.getStringValue().length() == 0) {
151             computeConfigFile();
152         }
153         
154         new Label(composite, SWT.NULL); //blank
155

156         Composite debugModeGroup = new Composite(composite,SWT.NONE);
157         debugModeEditor = new BooleanFieldEditor(
158             JonasLauncherPlugin.JONAS_PREF_DEBUGMODE_KEY,
159             PREF_PAGE_DEBUGMODE_LABEL,
160             debugModeGroup);
161         if (File.separator.equals("/")) {
162             debugModeEditor.setEnabled(false,debugModeGroup);
163         }
164         this.initField(debugModeEditor);
165
166         return composite;
167     }
168
169     /*
170      * @see IWorkbenchPreferencePage#init(IWorkbench)
171      */

172     public void init(IWorkbench workbench) {
173     }
174
175
176     public boolean performOk() {
177         version.store();
178         home.store();
179         JonasLauncherPlugin.getDefault().initJonasClasspathVariable();
180         base.store();
181         debugModeEditor.store();
182         orb.store();
183         xtraClasspath.store();
184
185         JonasLauncherPlugin.getDefault().savePluginPreferences();
186
187         return true;
188     }
189     
190     private void initField(FieldEditor field) {
191         field.setPreferenceStore(getPreferenceStore());
192         field.setPreferencePage(this);
193         field.load();
194     }
195     
196     private void computeConfigFile() {
197         base.setStringValue(home.getStringValue());
198     }
199     
200 }
201
202
Popular Tags