1 11 package org.eclipse.jdt.debug.ui.launchConfigurations; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.ResourcesPlugin; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.ILaunchConfiguration; 18 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 19 import org.eclipse.jdt.core.IJavaElement; 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jdt.core.IType; 22 import org.eclipse.jdt.core.JavaCore; 23 import org.eclipse.jdt.core.JavaModelException; 24 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; 25 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 26 import org.eclipse.jdt.internal.debug.ui.SWTFactory; 27 import org.eclipse.jdt.internal.debug.ui.launcher.AppletLaunchConfigurationUtils; 28 import org.eclipse.jdt.internal.debug.ui.launcher.DebugTypeSelectionDialog; 29 import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages; 30 import org.eclipse.jdt.internal.debug.ui.launcher.SharedJavaMainTab; 31 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 32 import org.eclipse.jdt.launching.IVMInstall; 33 import org.eclipse.jdt.launching.JavaRuntime; 34 import org.eclipse.jdt.ui.ISharedImages; 35 import org.eclipse.jdt.ui.JavaUI; 36 import org.eclipse.jface.window.Window; 37 import org.eclipse.swt.events.SelectionEvent; 38 import org.eclipse.swt.events.SelectionListener; 39 import org.eclipse.swt.graphics.Font; 40 import org.eclipse.swt.graphics.Image; 41 import org.eclipse.swt.layout.GridData; 42 import org.eclipse.swt.layout.GridLayout; 43 import org.eclipse.swt.widgets.Button; 44 import org.eclipse.swt.widgets.Composite; 45 import org.eclipse.swt.widgets.Group; 46 import org.eclipse.swt.widgets.Text; 47 import org.eclipse.ui.PlatformUI; 48 49 57 public class AppletMainTab extends SharedJavaMainTab { 58 59 private Text fAppletViewerClassText; 61 private Button fAppletViewerClassDefaultButton; 62 63 67 private void createAppletViewerControl(Composite parent) { 68 Font font = parent.getFont(); 69 Group group = SWTFactory.createGroup(parent, LauncherMessages.AppletMainTab_1, 2, 1, GridData.FILL_HORIZONTAL); 70 Composite comp = SWTFactory.createComposite(group, font, 2, 2, GridData.FILL_BOTH, 0, 0); 71 fAppletViewerClassText= SWTFactory.createSingleText(comp, 2); 72 fAppletViewerClassText.addModifyListener(getDefaultListener()); 73 createVerticalSpacer(comp, 1); 74 fAppletViewerClassDefaultButton= createCheckButton(comp, LauncherMessages.AppletMainTab_2); 75 fAppletViewerClassDefaultButton.addSelectionListener(new SelectionListener() { 76 public void widgetDefaultSelected(SelectionEvent e) {} 77 public void widgetSelected(SelectionEvent e) { 78 handleAppletViewerClassDefaultSelected(); 79 } 80 }); 81 } 82 83 86 public void createControl(Composite parent) { 87 Composite projComp = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, GridData.FILL_BOTH); 88 ((GridLayout)projComp.getLayout()).verticalSpacing = 0; 89 createProjectEditor(projComp); 90 createVerticalSpacer(projComp, 1); 91 createMainTypeEditor(projComp, LauncherMessages.appletlauncher_maintab_mainclasslabel_name); 92 createVerticalSpacer(projComp, 1); 93 createAppletViewerControl(projComp); 94 setControl(projComp); 95 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_APPLET_MAIN_TAB); 96 } 97 98 101 public Image getImage() { 102 return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS); 103 } 104 105 108 public String getName() { 109 return LauncherMessages.appletlauncher_maintab_name; 110 } 111 112 115 private void handleAppletViewerClassDefaultSelected() { 116 setAppletViewerTextEnabledState(); 117 if (isDefaultAppletViewerClassName()) { 118 fAppletViewerClassText.setText(IJavaLaunchConfigurationConstants.DEFAULT_APPLETVIEWER_CLASS); 119 } 120 else { 121 fAppletViewerClassText.setText(EMPTY_STRING); 122 } 123 } 124 125 128 protected void handleSearchButtonSelected() { 129 IJavaElement[] scope= null; 130 IJavaProject project = getJavaProject(); 131 if (project == null) { 132 try { 133 scope = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects(); 134 } 135 catch (JavaModelException e) { 136 setErrorMessage(e.getMessage()); 137 return; 138 } 139 } 140 else { 141 scope = new IJavaElement[]{project}; 142 } 143 IType[] types = null; 144 try { 145 types = AppletLaunchConfigurationUtils.findApplets(getLaunchConfigurationDialog(), scope); 146 } 147 catch (InterruptedException e) {return;} 148 catch (InvocationTargetException e) { 149 setErrorMessage(e.getTargetException().getMessage()); 150 return; 151 } 152 DebugTypeSelectionDialog dialog = new DebugTypeSelectionDialog(getShell(), types, LauncherMessages.appletlauncher_maintab_selection_applet_dialog_title); 153 if (dialog.open() == Window.CANCEL) { 154 return; 155 } 156 Object [] results = dialog.getResult(); 157 IType type = (IType)results[0]; 158 if (type != null) { 159 fMainText.setText(type.getFullyQualifiedName()); 160 fProjText.setText(type.getJavaProject().getElementName()); 161 } 162 } 163 164 167 private void initializeAppletViewerClass(ILaunchConfigurationWorkingCopy config) { 168 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_APPLETVIEWER_CLASS, (String )null); 169 } 170 171 175 private void initializeDefaults(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { 176 initializeJavaProject(javaElement, config); 177 initializeMainTypeAndName(javaElement, config); 178 initializeHardCodedDefaults(config); 179 initializeAppletViewerClass(config); 180 } 181 182 185 private void initializeDefaultVM(ILaunchConfigurationWorkingCopy config) { 186 IVMInstall vmInstall= JavaRuntime.getDefaultVMInstall(); 187 if (vmInstall == null) { 188 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, (String )null); 189 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String )null); 190 } 191 else { 192 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, vmInstall.getName()); 193 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmInstall.getVMInstallType().getId()); 194 } 195 } 196 197 200 public void initializeFrom(ILaunchConfiguration config) { 201 super.initializeFrom(config); 202 updateMainTypeFromConfig(config); 203 updateAppletViewerClassNameFromConfig(config); 204 } 205 206 209 private void initializeHardCodedDefaults(ILaunchConfigurationWorkingCopy config) { 210 initializeDefaultVM(config); 211 } 212 213 216 private boolean isDefaultAppletViewerClassName() { 217 return fAppletViewerClassDefaultButton.getSelection(); 218 } 219 220 223 public boolean isValid(ILaunchConfiguration launchConfig) { 224 setErrorMessage(null); 225 setMessage(null); 226 String name= fProjText.getText().trim(); 227 if (name.length() > 0) { 228 if (!ResourcesPlugin.getWorkspace().getRoot().getProject(name).exists()) { 229 setErrorMessage(LauncherMessages.appletlauncher_maintab_project_error_doesnotexist); 230 return false; 231 } 232 } 233 name = fMainText.getText().trim(); 234 if (name.length() == 0) { 235 setErrorMessage(LauncherMessages.appletlauncher_maintab_type_error_doesnotexist); 236 return false; 237 } 238 name = fAppletViewerClassText.getText().trim(); 239 if (name.length() == 0) { 240 setErrorMessage(LauncherMessages.AppletMainTab_3); 241 return false; 242 } 243 return true; 244 } 245 246 249 public void performApply(ILaunchConfigurationWorkingCopy config) { 250 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.getText()); 251 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, fMainText.getText()); 252 mapResources(config); 253 String appletViewerClassName= null; 254 if (!isDefaultAppletViewerClassName()) { 255 appletViewerClassName= fAppletViewerClassText.getText().trim(); 256 if (appletViewerClassName.length() <= 0) { 257 appletViewerClassName= null; 258 } 259 } 260 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_APPLETVIEWER_CLASS, appletViewerClassName); 261 } 262 263 266 private void setAppletViewerTextEnabledState() { 267 if (isDefaultAppletViewerClassName()) { 268 fAppletViewerClassText.setEnabled(false); 269 } 270 else { 271 fAppletViewerClassText.setEnabled(true); 272 } 273 } 274 275 278 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 279 IJavaElement je= getContext(); 280 if (je == null) { 281 initializeHardCodedDefaults(config); 282 } 283 else { 284 initializeDefaults(je, config); 285 } 286 } 287 288 292 private void updateAppletViewerClassNameFromConfig(ILaunchConfiguration config) { 293 String appletViewerClassName = EMPTY_STRING; 294 try { 295 appletViewerClassName= config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_APPLETVIEWER_CLASS, EMPTY_STRING); 296 if (appletViewerClassName.equals(EMPTY_STRING)) { 297 fAppletViewerClassText.setText(IJavaLaunchConfigurationConstants.DEFAULT_APPLETVIEWER_CLASS); 298 fAppletViewerClassDefaultButton.setSelection(true); 299 } 300 else { 301 fAppletViewerClassText.setText(appletViewerClassName); 302 fAppletViewerClassDefaultButton.setSelection(false); 303 } 304 setAppletViewerTextEnabledState(); 305 } 306 catch (CoreException ce) {JDIDebugUIPlugin.log(ce);} 307 } 308 309 314 public String getId() { 315 return "org.eclipse.jdt.debug.ui.appletMainTab"; } 317 } 318 | Popular Tags |