1 11 package org.eclipse.jdt.internal.debug.ui.snippeteditor; 12 13 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 18 import org.eclipse.debug.core.ILaunchManager; 19 import org.eclipse.debug.ui.ILaunchConfigurationDialog; 20 import org.eclipse.debug.ui.ILaunchConfigurationTab; 21 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab; 22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 23 import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock; 24 import org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock; 25 import org.eclipse.jface.operation.IRunnableWithProgress; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.layout.GridLayout; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Control; 30 import org.eclipse.ui.dialogs.PropertyPage; 31 32 35 public class SnippetEditorPropertyPage extends PropertyPage { 36 37 private WorkingDirectoryBlock fWorkingDirBlock = new WorkingDirectoryBlock(); 38 39 private JavaJRETab fJRETab = new JavaJRETab(); 40 41 private VMArgumentsBlock fVMArgumentsBlock = new VMArgumentsBlock(); 42 43 private ILaunchConfiguration fConfig; 45 private ILaunchConfigurationWorkingCopy fWorkingCopy; 46 47 private Proxy fProxy; 48 49 class Proxy implements ILaunchConfigurationDialog { 50 53 public String generateName(String name) { 54 return null; 55 } 56 57 60 public String getMode() { 61 return ILaunchManager.DEBUG_MODE; 62 } 63 64 67 public ILaunchConfigurationTab[] getTabs() { 68 return new ILaunchConfigurationTab[] {fWorkingDirBlock}; 69 } 70 71 74 public ILaunchConfigurationTab getActiveTab() { 75 return fWorkingDirBlock; 76 } 77 78 81 public void setName(String name) { 82 } 83 84 87 public void updateButtons() { 88 89 } 90 91 94 public void updateMessage() { 95 setValid(isValid()); 96 setMessage(getMessage()); 97 setErrorMessage(getErrorMessage()); 98 } 99 100 103 public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) { 104 } 105 106 109 public void setActiveTab(ILaunchConfigurationTab tab) { 110 } 111 112 115 public void setActiveTab(int index) { 116 } 117 } 118 119 122 protected Control createContents(Composite parent) { 123 Composite comp = new Composite(parent, SWT.NONE); 124 GridLayout topLayout = new GridLayout(); 125 topLayout.numColumns = 1; 126 comp.setLayout(topLayout); 127 comp.setFont(parent.getFont()); 128 129 fProxy = new Proxy(); 131 132 try { 133 fConfig = ScrapbookLauncher.getLaunchConfigurationTemplate(getFile()); 134 if (fConfig != null) { 135 fWorkingCopy = fConfig.getWorkingCopy(); 136 } 137 } catch (CoreException e) { 138 fConfig = null; 140 fWorkingCopy = null; 141 JDIDebugUIPlugin.statusDialog(SnippetMessages.getString("ScrapbookLauncher.Unable_to_retrieve_settings"), e.getStatus()); } 143 144 if (fConfig == null) { 145 try { 146 fConfig = ScrapbookLauncher.createLaunchConfigurationTemplate(getFile()); 147 fWorkingCopy = fConfig.getWorkingCopy(); 148 } catch (CoreException e) { 149 JDIDebugUIPlugin.statusDialog(SnippetMessages.getString("ScrapbookLauncher.Unable_to_retrieve_settings"), e.getStatus()); } 151 } 152 153 fWorkingDirBlock.setLaunchConfigurationDialog(fProxy); 154 fWorkingDirBlock.createControl(comp); 155 fWorkingDirBlock.initializeFrom(fConfig); 156 157 fVMArgumentsBlock.setLaunchConfigurationDialog(fProxy); 158 fVMArgumentsBlock.createControl(comp); 159 fVMArgumentsBlock.initializeFrom(fConfig); 160 161 fJRETab.setLaunchConfigurationDialog(fProxy); 162 fJRETab.setVMSpecificArgumentsVisible(false); 163 fJRETab.createControl(comp); 164 fJRETab.initializeFrom(fConfig); 165 166 return comp; 167 } 168 169 172 protected IFile getFile() { 173 return (IFile)getElement(); 174 } 175 176 179 protected void performDefaults() { 180 super.performDefaults(); 181 fWorkingDirBlock.setDefaults(fWorkingCopy); 182 fJRETab.setDefaults(fWorkingCopy); 183 fVMArgumentsBlock.setDefaults(fWorkingCopy); 184 fWorkingDirBlock.initializeFrom(fWorkingCopy); 185 fJRETab.initializeFrom(fWorkingCopy); 186 fVMArgumentsBlock.initializeFrom(fWorkingCopy); 187 } 188 189 192 public boolean isValid() { 193 return fWorkingDirBlock.isValid(fConfig); 194 } 195 196 199 public String getErrorMessage() { 200 String message = fWorkingDirBlock.getErrorMessage(); 201 if (message == null) { 202 return fJRETab.getErrorMessage(); 203 } 204 return message; 205 } 206 207 210 public String getMessage() { 211 String message = fWorkingDirBlock.getMessage(); 212 if (message == null) { 213 return fJRETab.getMessage(); 214 } 215 return message; 216 } 217 218 221 public boolean performOk() { 222 fWorkingDirBlock.performApply(fWorkingCopy); 223 fJRETab.performApply(fWorkingCopy); 224 fVMArgumentsBlock.performApply(fWorkingCopy); 225 try { 226 if (!fWorkingCopy.contentsEqual(fConfig)) { 227 fConfig = fWorkingCopy.doSave(); 228 fWorkingCopy = fConfig.getWorkingCopy(); 229 } 230 } catch (CoreException e) { 231 JDIDebugUIPlugin.statusDialog(e.getStatus()); 232 } 233 return super.performOk(); 234 } 235 } 236 | Popular Tags |