001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.macbundler;
011:
012: import java.util.*;
013: import java.util.ArrayList;
014:
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.debug.core.*;
017: import org.eclipse.jdt.core.*;
018: import org.eclipse.jdt.core.IJavaElement;
019: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.events.*;
022: import org.eclipse.swt.layout.*;
023: import org.eclipse.swt.widgets.*;
024:
025: import org.eclipse.jface.util.PropertyChangeEvent;
026: import org.eclipse.jface.viewers.IStructuredSelection;
027:
028: public class BundleWizardPage1 extends BundleWizardBasePage {
029:
030: static String[] JVMS = { "1.3+", //$NON-NLS-1$
031: "1.3*", //$NON-NLS-1$
032: "1.4.2", //$NON-NLS-1$
033: "1.4+", //$NON-NLS-1$
034: "1.4*", //$NON-NLS-1$
035: "1.5+", //$NON-NLS-1$
036: "1.5*", //$NON-NLS-1$
037: "1.6+", //$NON-NLS-1$
038: "1.6*" //$NON-NLS-1$
039: };
040:
041: ILaunchConfiguration[] fConfigurations = new ILaunchConfiguration[0];
042: Combo fLocation;
043: Combo fLaunchConfigs;
044: Combo fJVMVersion;
045: Text fAppName;
046: Text fMainClass;
047: Text fArguments;
048: Text fIconFileName;
049: Button fUseSWT;
050:
051: public BundleWizardPage1(BundleDescription bd) {
052: super ("page1", bd); //$NON-NLS-1$
053: }
054:
055: public void createContents(Composite c) {
056:
057: final Shell shell = c.getShell();
058:
059: Composite c1 = createComposite(c, 2);
060: createLabel(
061: c1,
062: Util.getString("page1.launchConfig.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
063:
064: fLaunchConfigs = new Combo(c1, SWT.READ_ONLY);
065: fillCombo(fLaunchConfigs);
066: fLaunchConfigs.addSelectionListener(new SelectionAdapter() {
067: public void widgetSelected(SelectionEvent e) {
068: int ix = fLaunchConfigs.getSelectionIndex();
069: if (ix > 0 && ix < fConfigurations.length) {
070: fBundleDescription.clear();
071: fBundleDescription
072: .inititialize(fConfigurations[ix]);
073: }
074: }
075: });
076:
077: Group c2 = createGroup(c, "Main", 2); //$NON-NLS-1$
078: createLabel(
079: c2,
080: Util.getString("page1.mainClass.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
081: Composite c7a = createHBox(c2);
082:
083: fMainClass = createText(c7a, MAINCLASS, 1);
084: Button b1 = createButton(c7a, SWT.NONE, Util
085: .getString("page1.mainClass.chooseButton.label")); //$NON-NLS-1$
086: b1.addSelectionListener(new SelectionAdapter() {
087: public void widgetSelected(SelectionEvent e) {
088: MessageBox mb = new MessageBox(shell,
089: SWT.ICON_INFORMATION | SWT.OK);
090: mb.setMessage(Util
091: .getString("page1.mainClass.dialog.message")); //$NON-NLS-1$
092: mb.setText(Util
093: .getString("page1.mainClass.dialog.title")); //$NON-NLS-1$
094: mb.open();
095: }
096: });
097:
098: createLabel(
099: c2,
100: Util.getString("page1.arguments.label"), GridData.VERTICAL_ALIGN_BEGINNING); //$NON-NLS-1$
101: fArguments = createText(c2, ARGUMENTS, 2);
102:
103: Group c5 = createGroup(c, "Destination", 2); //$NON-NLS-1$
104: createLabel(
105: c5,
106: Util.getString("page1.appName.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
107: fAppName = createText(c5, APPNAME, 1);
108:
109: createLabel(
110: c5,
111: Util.getString("page1.appFolder.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
112: Composite c3a = createHBox(c5);
113:
114: fLocation = createCombo(c3a, DESTINATIONDIRECTORY);
115:
116: final Button browse = createButton(c3a, SWT.NONE, Util
117: .getString("page1.appFolder.browseButton.label")); //$NON-NLS-1$
118: browse.addSelectionListener(new SelectionAdapter() {
119: public void widgetSelected(SelectionEvent e) {
120: DirectoryDialog dd = new DirectoryDialog(browse
121: .getShell(), SWT.SAVE);
122: dd
123: .setMessage(Util
124: .getString("page1.appFolder.browseDialog.message")); //$NON-NLS-1$
125: dd
126: .setText(Util
127: .getString("page1.appFolder.browseDialog.title")); //$NON-NLS-1$
128: String name = dd.open();
129: if (name != null)
130: fLocation.setText(name);
131: }
132: });
133:
134: Group g6 = createGroup(c, "Options", 2); //$NON-NLS-1$
135:
136: createLabel(
137: g6,
138: Util.getString("page1.jvm.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
139:
140: Composite c8 = createComposite(g6, 4);
141:
142: fJVMVersion = new Combo(c8, SWT.READ_ONLY);
143: for (int i = 0; i < JVMS.length; i++)
144: fJVMVersion.add(JVMS[i]);
145: fJVMVersion.setText(JVMS[4]);
146: hookField(fJVMVersion, JVMVERSION);
147: createLabel(c8, " ", GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
148: createLabel(
149: c8,
150: Util.getString("page1.useSWT.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
151: fUseSWT = createButton(c8, SWT.CHECK, null);
152: hookButton(fUseSWT, USES_SWT);
153:
154: createLabel(
155: g6,
156: Util.getString("page1.appIcon.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
157: Composite c7 = createComposite(g6, 2);
158: fIconFileName = createText(c7, ICONFILE, 1);
159: final Button b = createButton(c7, SWT.NONE, Util
160: .getString("page1.appIcon.chooseButton.label")); //$NON-NLS-1$
161: b.addSelectionListener(new SelectionAdapter() {
162: public void widgetSelected(SelectionEvent e) {
163: FileDialog fd = new FileDialog(b.getShell(), SWT.OPEN);
164: fd.setText(Util
165: .getString("page1.appIcon.chooseDialog.title")); //$NON-NLS-1$
166: fd.setFilterExtensions(new String[] { "icns" }); //$NON-NLS-1$
167: String name = fd.open();
168: if (name != null)
169: fIconFileName.setText(name);
170: }
171: });
172:
173: }
174:
175: void enterPage() {
176: super .enterPage();
177: initCombo(fLaunchConfigs);
178: }
179:
180: public void propertyChange(PropertyChangeEvent event) {
181: if (fAppName != null)
182: fAppName.setText(fBundleDescription.get(APPNAME, "")); //$NON-NLS-1$
183: if (fMainClass != null)
184: fMainClass.setText(fBundleDescription.get(MAINCLASS, "")); //$NON-NLS-1$
185: if (fJVMVersion != null)
186: fJVMVersion.setText(fBundleDescription.get(JVMVERSION, "")); //$NON-NLS-1$
187: if (fUseSWT != null)
188: fUseSWT.setSelection(fBundleDescription
189: .get(USES_SWT, false));
190: }
191:
192: public boolean isPageComplete() {
193: return fAppName != null && fAppName.getText().length() > 0
194: && fLocation.getText().length() > 0;
195: }
196:
197: // private stuff
198:
199: private void collectLaunchConfigs() {
200: ArrayList configs = new ArrayList();
201: ILaunchManager manager = DebugPlugin.getDefault()
202: .getLaunchManager();
203: ILaunchConfigurationType type = manager
204: .getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
205: try {
206: ILaunchConfiguration[] configurations = manager
207: .getLaunchConfigurations(type);
208: for (int i = 0; i < configurations.length; i++) {
209: ILaunchConfiguration configuration = configurations[i];
210: if (BundleDescription.verify(configuration))
211: configs.add(configuration);
212: }
213: } catch (CoreException e) {
214: //
215: }
216: fConfigurations = (ILaunchConfiguration[]) configs
217: .toArray(new ILaunchConfiguration[configs.size()]);
218: Arrays.sort(fConfigurations, new Comparator() {
219: public int compare(Object o1, Object o2) {
220: ILaunchConfiguration lc1 = (ILaunchConfiguration) o1;
221: ILaunchConfiguration lc2 = (ILaunchConfiguration) o2;
222: return lc1.getName().compareTo(lc2.getName());
223: }
224:
225: public boolean equals(Object obj) {
226: return false;
227: }
228: });
229: }
230:
231: private void fillCombo(Combo c) {
232: collectLaunchConfigs();
233: for (int i = 0; i < fConfigurations.length; i++) {
234: ILaunchConfiguration configuration = fConfigurations[i];
235: c.add(configuration.getName());
236: }
237: }
238:
239: private void initCombo(Combo c) {
240: IStructuredSelection sel = ((MacBundleWizard) getWizard())
241: .getSelection();
242: Object o = sel.getFirstElement();
243: if (o instanceof IJavaElement) {
244: IJavaProject project = ((IJavaElement) o).getJavaProject();
245: if (project != null) {
246: for (int i = 0; i < fConfigurations.length; i++) {
247: ILaunchConfiguration configuration = fConfigurations[i];
248: if (BundleDescription.matches(configuration,
249: project)) {
250: c.setText(configuration.getName());
251: fBundleDescription.inititialize(configuration);
252: return;
253: }
254: }
255: }
256: }
257: }
258: }
|