KickJava   Java API By Example, From Geeks To Geeks.

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


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

7
8 import java.util.ArrayList JavaDoc;
9
10 import org.eclipse.jdt.internal.debug.ui.launcher.ComboFieldEditor;
11 import org.eclipse.jdt.launching.IVMInstall;
12 import org.eclipse.jdt.launching.IVMInstallType;
13 import org.eclipse.jdt.launching.JavaRuntime;
14 import org.eclipse.jface.preference.FieldEditor;
15 import org.eclipse.jface.preference.PreferencePage;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.ui.IWorkbench;
22 import org.eclipse.ui.IWorkbenchPreferencePage;
23
24 import com.bull.eclipse.jonas.JonasLauncherPlugin;
25 import com.bull.eclipse.jonas.JonasPluginResources;
26 import com.bull.eclipse.jonas.editors.ClasspathFieldEditor;
27 import com.bull.eclipse.jonas.editors.ListFieldEditor;
28
29
30 public class JonasJVMPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, JonasPluginResources {
31
32     static final private int FIELD_WIDTH = 50;
33     private ComboFieldEditor jvmChoice;
34     private ListFieldEditor jvmParamaters;
35     private ClasspathFieldEditor jvmClasspath;
36     private ClasspathFieldEditor jvmBootClasspath;
37     
38     public JonasJVMPreferencePage() {
39         super();
40         setPreferenceStore(JonasLauncherPlugin.getDefault().getPreferenceStore());
41 // setDescription("");
42
}
43
44     /*
45      * @see PreferencePage#createContents(Composite)
46      */

47     protected Control createContents(Composite parent) {
48         Composite composite = new Composite(parent, SWT.NULL);
49         GridLayout gl = new GridLayout();
50         gl.numColumns = 1;
51         composite.setLayout(gl);
52         GridData gd = new GridData(GridData.FILL_BOTH);
53         gd.grabExcessVerticalSpace = true;
54         gd.grabExcessHorizontalSpace = true;
55         composite.setLayoutData(gd);
56                 
57         Composite group1 = new Composite(composite,SWT.NONE);
58         GridLayout gl2 = new GridLayout(3,false);
59         group1.setLayout(gl2);
60         gd = new GridData();
61         gd.horizontalAlignment = GridData.FILL;
62         group1.setLayoutData(gd);
63
64         // Collect all JREs
65
ArrayList JavaDoc allVMs = new ArrayList JavaDoc();
66         IVMInstallType[] vmTypes = JavaRuntime.getVMInstallTypes();
67         for (int i = 0; i < vmTypes.length; i++) {
68             IVMInstall[] vms = vmTypes[i].getVMInstalls();
69             for (int j = 0; j < vms.length; j++) {
70                 allVMs.add(vms[j]);
71             }
72         }
73         
74         String JavaDoc[][] namesAndValues = new String JavaDoc[allVMs.size()][2];
75         for (int i=0; i<allVMs.size(); i++) {
76             namesAndValues[i][0] = ((IVMInstall)allVMs.get(i)).getName();
77             namesAndValues[i][1] = ((IVMInstall)allVMs.get(i)).getId();
78         }
79     
80         jvmChoice = new ComboFieldEditor(
81                 JonasLauncherPlugin.JONAS_PREF_JRE_KEY,
82                 PREF_PAGE_JRE_LABEL,
83                 namesAndValues,
84                 group1);
85         
86         jvmParamaters = new ListFieldEditor(
87                 JonasLauncherPlugin.JONAS_PREF_JVM_PARAMETERS_KEY,
88                 PREF_PAGE_PARAMETERS_LABEL,
89                 composite);
90                         
91         jvmClasspath = new ClasspathFieldEditor(
92                 JonasLauncherPlugin.JONAS_PREF_JVM_CLASSPATH_KEY,
93                 PREF_PAGE_CLASSPATH_LABEL,
94                 composite);
95
96         jvmBootClasspath = new ClasspathFieldEditor(
97                 JonasLauncherPlugin.JONAS_PREF_JVM_BOOTCLASSPATH_KEY,
98                 PREF_PAGE_BOOTCLASSPATH_LABEL,
99                 composite);
100
101         this.initField(jvmChoice);
102         this.initField(jvmParamaters);
103         this.initField(jvmClasspath);
104         this.initField(jvmBootClasspath);
105
106         return composite;
107     }
108
109     /*
110      * @see IWorkbenchPreferencePage#init(IWorkbench)
111      */

112     public void init(IWorkbench workbench) {
113     }
114
115
116     public boolean performOk() {
117         jvmChoice.store();
118         jvmBootClasspath.store();
119         jvmClasspath.store();
120         jvmParamaters.store();
121         JonasLauncherPlugin.getDefault().savePluginPreferences();
122         return true;
123     }
124     
125     private void initField(FieldEditor field) {
126         field.setPreferenceStore(getPreferenceStore());
127         field.setPreferencePage(this);
128         field.load();
129     }
130
131 }
132
133
Popular Tags