1 11 package org.eclipse.jdt.internal.ui.macbundler; 12 13 import java.util.*; 14 import java.util.ArrayList ; 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 [] JVMS= { 33 "1.3+", "1.3*", "1.4.1", "1.4+", "1.4*" }; 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); } 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); 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); createLabel(c2, Util.getString("page1.mainClass.label"), GridData.VERTICAL_ALIGN_CENTER); Composite c7a= createHBox(c2); 80 81 fMainClass= createText(c7a, MAINCLASS, 1); 82 Button b1= createButton(c7a, SWT.NONE, Util.getString("page1.mainClass.chooseButton.label")); 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")); mb.setText(Util.getString("page1.mainClass.dialog.title")); mb.open(); 89 } 90 }); 91 92 createLabel(c2, Util.getString("page1.arguments.label"), GridData.VERTICAL_ALIGN_BEGINNING); fArguments= createText(c2, ARGUMENTS, 2); 94 95 Group c5= createGroup(c, "Destination", 2); createLabel(c5, Util.getString("page1.appName.label"), GridData.VERTICAL_ALIGN_CENTER); fAppName= createText(c5, APPNAME, 1); 98 99 createLabel(c5, Util.getString("page1.appFolder.label"), GridData.VERTICAL_ALIGN_CENTER); 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")); 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")); dd.setText(Util.getString("page1.appFolder.browseDialog.title")); String name= dd.open(); 111 if (name != null) 112 fLocation.setText(name); 113 } 114 }); 115 116 Group g6= createGroup(c, "Options", 2); 118 createLabel(g6, Util.getString("page1.jvm.label"), GridData.VERTICAL_ALIGN_CENTER); 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); createLabel(c8, Util.getString("page1.useSWT.label"), GridData.VERTICAL_ALIGN_CENTER); fUseSWT= createButton(c8, SWT.CHECK, null); hookButton(fUseSWT, USES_SWT); 131 132 createLabel(g6, Util.getString("page1.appIcon.label"), GridData.VERTICAL_ALIGN_CENTER); 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")); 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")); fd.setFilterExtensions(new String [] { "icns" }); String 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, "")); if (fMainClass != null) 158 fMainClass.setText(fBundleDescription.get(MAINCLASS, "")); if (fJVMVersion != null) 160 fJVMVersion.setText(fBundleDescription.get(JVMVERSION, "")); if (fUseSWT != null) 162 fUseSWT.setSelection(fBundleDescription.get(USES_SWT, false)); } 164 165 public boolean isPageComplete() { 166 return fAppName != null && fAppName.getText().length() > 0 && fLocation.getText().length() > 0; 167 } 168 169 171 private void collectLaunchConfigs() { 172 ArrayList configs= new ArrayList (); 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 } 185 fConfigurations= (ILaunchConfiguration[]) configs.toArray(new ILaunchConfiguration[configs.size()]); 186 Arrays.sort(fConfigurations, new Comparator() { 187 public int compare(Object o1, Object 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 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 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 |