KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > macbundler > BundleWizardPage1


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.macbundler;
12
13 import java.util.*;
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.debug.core.*;
18 import org.eclipse.jdt.core.*;
19 import org.eclipse.jdt.core.IJavaElement;
20 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.*;
23 import org.eclipse.swt.layout.*;
24 import org.eclipse.swt.widgets.*;
25
26 import org.eclipse.jface.util.PropertyChangeEvent;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28
29
30 public class BundleWizardPage1 extends BundleWizardBasePage {
31     
32     static String JavaDoc[] JVMS= {
33         "1.3+", //$NON-NLS-1$
34
"1.3*", //$NON-NLS-1$
35
"1.4.1", //$NON-NLS-1$
36
"1.4+", //$NON-NLS-1$
37
"1.4*" //$NON-NLS-1$
38
};
39
40     ILaunchConfiguration[] fConfigurations= new ILaunchConfiguration[0];
41     Combo fLocation;
42     Combo fLaunchConfigs;
43     Combo fJVMVersion;
44     Text fAppName;
45     Text fMainClass;
46     Text fArguments;
47     Text fIconFileName;
48     Button fUseSWT;
49     
50     
51     public BundleWizardPage1(BundleDescription bd) {
52         super("page1", bd); //$NON-NLS-1$
53
}
54
55     public void createContents(Composite c) {
56         
57         final Shell shell= c.getShell();
58                 
59         Composite c1= createComposite(c, 2);
60             createLabel(c1, Util.getString("page1.launchConfig.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
61

62             fLaunchConfigs= new Combo(c1, SWT.READ_ONLY);
63             fillCombo(fLaunchConfigs);
64             fLaunchConfigs.addSelectionListener(
65                 new SelectionAdapter() {
66                     public void widgetSelected(SelectionEvent e) {
67                         int ix= fLaunchConfigs.getSelectionIndex();
68                         if (ix > 0 && ix < fConfigurations.length) {
69                             fBundleDescription.clear();
70                             fBundleDescription.inititialize(fConfigurations[ix]);
71                         }
72                     }
73                 }
74             );
75             
76                     
77         Group c2= createGroup(c, "Main", 2); //$NON-NLS-1$
78
createLabel(c2, Util.getString("page1.mainClass.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
79
Composite c7a= createHBox(c2);
80             
81                 fMainClass= createText(c7a, MAINCLASS, 1);
82                 Button b1= createButton(c7a, SWT.NONE, Util.getString("page1.mainClass.chooseButton.label")); //$NON-NLS-1$
83
b1.addSelectionListener(new SelectionAdapter() {
84                     public void widgetSelected(SelectionEvent e) {
85                         MessageBox mb= new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
86                         mb.setMessage(Util.getString("page1.mainClass.dialog.message")); //$NON-NLS-1$
87
mb.setText(Util.getString("page1.mainClass.dialog.title")); //$NON-NLS-1$
88
mb.open();
89                     }
90                 });
91                 
92                 createLabel(c2, Util.getString("page1.arguments.label"), GridData.VERTICAL_ALIGN_BEGINNING); //$NON-NLS-1$
93
fArguments= createText(c2, ARGUMENTS, 2);
94                     
95         Group c5= createGroup(c, "Destination", 2); //$NON-NLS-1$
96
createLabel(c5, Util.getString("page1.appName.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
97
fAppName= createText(c5, APPNAME, 1);
98         
99             createLabel(c5, Util.getString("page1.appFolder.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
100
Composite c3a= createHBox(c5);
101             
102                 fLocation= createCombo(c3a, DESTINATIONDIRECTORY);
103                 
104                 final Button browse= createButton(c3a, SWT.NONE, Util.getString("page1.appFolder.browseButton.label")); //$NON-NLS-1$
105
browse.addSelectionListener(new SelectionAdapter() {
106                     public void widgetSelected(SelectionEvent e) {
107                         DirectoryDialog dd= new DirectoryDialog(browse.getShell(), SWT.SAVE);
108                         dd.setMessage(Util.getString("page1.appFolder.browseDialog.message")); //$NON-NLS-1$
109
dd.setText(Util.getString("page1.appFolder.browseDialog.title")); //$NON-NLS-1$
110
String JavaDoc name= dd.open();
111                         if (name != null)
112                             fLocation.setText(name);
113                     }
114                 });
115         
116         Group g6= createGroup(c, "Options", 2); //$NON-NLS-1$
117

118             createLabel(g6, Util.getString("page1.jvm.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
119

120             Composite c8= createComposite(g6, 4);
121             
122                 fJVMVersion= new Combo(c8, SWT.READ_ONLY);
123                 for (int i= 0; i < JVMS.length; i++)
124                     fJVMVersion.add(JVMS[i]);
125                 fJVMVersion.setText(JVMS[4]);
126                 hookField(fJVMVersion, JVMVERSION);
127                 createLabel(c8, " ", GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
128
createLabel(c8, Util.getString("page1.useSWT.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
129
fUseSWT= createButton(c8, SWT.CHECK, null); //$NON-NLS-1$
130
hookButton(fUseSWT, USES_SWT);
131             
132             createLabel(g6, Util.getString("page1.appIcon.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
133
Composite c7= createComposite(g6, 2);
134                 fIconFileName= createText(c7, ICONFILE, 1);
135                 final Button b= createButton(c7, SWT.NONE, Util.getString("page1.appIcon.chooseButton.label")); //$NON-NLS-1$
136
b.addSelectionListener(new SelectionAdapter() {
137                     public void widgetSelected(SelectionEvent e) {
138                         FileDialog fd= new FileDialog(b.getShell(), SWT.OPEN);
139                         fd.setText(Util.getString("page1.appIcon.chooseDialog.title")); //$NON-NLS-1$
140
fd.setFilterExtensions(new String JavaDoc[] { "icns" }); //$NON-NLS-1$
141
String JavaDoc name= fd.open();
142                         if (name != null)
143                             fIconFileName.setText(name);
144                     }
145                 });
146             
147     }
148     
149     void enterPage() {
150         super.enterPage();
151         initCombo(fLaunchConfigs);
152     }
153     
154     public void propertyChange(PropertyChangeEvent event) {
155         if (fAppName != null)
156             fAppName.setText(fBundleDescription.get(APPNAME, "")); //$NON-NLS-1$
157
if (fMainClass != null)
158             fMainClass.setText(fBundleDescription.get(MAINCLASS, "")); //$NON-NLS-1$
159
if (fJVMVersion != null)
160             fJVMVersion.setText(fBundleDescription.get(JVMVERSION, "")); //$NON-NLS-1$
161
if (fUseSWT != null)
162             fUseSWT.setSelection(fBundleDescription.get(USES_SWT, false)); //$NON-NLS-1$
163
}
164     
165     public boolean isPageComplete() {
166         return fAppName != null && fAppName.getText().length() > 0 && fLocation.getText().length() > 0;
167     }
168
169     // private stuff
170

171     private void collectLaunchConfigs() {
172         ArrayList JavaDoc configs= new ArrayList JavaDoc();
173         ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
174         ILaunchConfigurationType type= manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
175         try {
176             ILaunchConfiguration[] configurations= manager.getLaunchConfigurations(type);
177             for (int i= 0; i < configurations.length; i++) {
178                 ILaunchConfiguration configuration= configurations[i];
179                 if (BundleDescription.verify(configuration))
180                     configs.add(configuration);
181             }
182         } catch (CoreException e) {
183             //
184
}
185         fConfigurations= (ILaunchConfiguration[]) configs.toArray(new ILaunchConfiguration[configs.size()]);
186         Arrays.sort(fConfigurations, new Comparator() {
187             public int compare(Object JavaDoc o1, Object JavaDoc o2) {
188                 ILaunchConfiguration lc1= (ILaunchConfiguration) o1;
189                 ILaunchConfiguration lc2= (ILaunchConfiguration) o2;
190                 return lc1.getName().compareTo(lc2.getName());
191             }
192
193             public boolean equals(Object JavaDoc obj) {
194                 return false;
195             }
196         });
197     }
198     
199     private void fillCombo(Combo c) {
200         collectLaunchConfigs();
201         for (int i= 0; i < fConfigurations.length; i++) {
202             ILaunchConfiguration configuration= fConfigurations[i];
203             c.add(configuration.getName());
204         }
205     }
206     
207     private void initCombo(Combo c) {
208         IStructuredSelection sel= ((MacBundleWizard)getWizard()).getSelection();
209         Object JavaDoc o= sel.getFirstElement();
210         if (o instanceof IJavaElement) {
211             IJavaProject project= ((IJavaElement) o).getJavaProject();
212             if (project != null) {
213                 for (int i= 0; i < fConfigurations.length; i++) {
214                     ILaunchConfiguration configuration= fConfigurations[i];
215                     if (BundleDescription.matches(configuration, project)) {
216                         c.setText(configuration.getName());
217                         fBundleDescription.inititialize(configuration);
218                         return;
219                     }
220                 }
221             }
222         }
223     }
224 }
225
Popular Tags