1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import java.io.File ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.core.runtime.Status; 20 import org.eclipse.debug.core.ILaunchConfiguration; 21 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 22 import org.eclipse.jface.dialogs.Dialog; 23 import org.eclipse.jface.viewers.Viewer; 24 import org.eclipse.jface.viewers.ViewerFilter; 25 import org.eclipse.pde.internal.core.PDECore; 26 import org.eclipse.pde.internal.ui.IHelpContextIds; 27 import org.eclipse.pde.internal.ui.PDEPlugin; 28 import org.eclipse.pde.internal.ui.PDEPluginImages; 29 import org.eclipse.pde.internal.ui.PDEUIMessages; 30 import org.eclipse.pde.internal.ui.util.SWTUtil; 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.events.ModifyEvent; 33 import org.eclipse.swt.events.ModifyListener; 34 import org.eclipse.swt.events.SelectionAdapter; 35 import org.eclipse.swt.events.SelectionEvent; 36 import org.eclipse.swt.graphics.Image; 37 import org.eclipse.swt.layout.GridData; 38 import org.eclipse.swt.layout.GridLayout; 39 import org.eclipse.swt.widgets.Button; 40 import org.eclipse.swt.widgets.Composite; 41 import org.eclipse.swt.widgets.DirectoryDialog; 42 import org.eclipse.swt.widgets.Group; 43 import org.eclipse.swt.widgets.Label; 44 import org.eclipse.swt.widgets.Text; 45 import org.eclipse.ui.PlatformUI; 46 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; 47 import org.eclipse.ui.dialogs.ISelectionStatusValidator; 48 import org.eclipse.ui.model.WorkbenchContentProvider; 49 import org.eclipse.ui.model.WorkbenchLabelProvider; 50 51 public class ConfigurationTab extends AbstractLauncherTab implements ILauncherSettings { 52 private Button fClearConfig; 53 private Image fImage; 54 55 private Button fUseDefaultLocationButton; 56 private Label fConfigAreaLabel; 57 private Text fConfigAreaText; 58 private Button fConfigAreaBrowse; 59 60 private Button fGenerateFileButton; 61 private Button fUseTemplateButton; 62 private Label fTemplateLocationLabel; 63 private Text fTemplateLocationText; 64 private Button fTemplateLocationBrowse; 65 66 private String fLastEnteredConfigArea = ""; private String fConfigName; 68 private boolean fBlockChanges; 69 private boolean fJUnitConfig; 70 71 72 public ConfigurationTab() { 73 this(false); 74 } 75 76 public ConfigurationTab(boolean isJUnitConfig) { 77 fImage = PDEPluginImages.DESC_PLUGIN_CONFIG_OBJ.createImage(); 78 fJUnitConfig = isJUnitConfig; 79 } 80 83 public void createControl(Composite parent) { 84 Composite container = new Composite(parent, SWT.NONE); 85 container.setLayout(new GridLayout()); 86 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 87 88 createConfigAreaGroup(container); 89 createStartingSpace(container, 1); 90 createConfigFileGroup(container); 91 92 Dialog.applyDialogFont(container); 93 setControl(container); 94 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.LAUNCHER_CONFIGURATION); 95 } 96 97 private void createConfigAreaGroup(Composite parent) { 98 Group group = new Group(parent, SWT.NONE); 99 group.setText(PDEUIMessages.ConfigurationTab_configAreaGroup); group.setLayout(new GridLayout(3, false)); 101 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 102 103 fUseDefaultLocationButton = new Button(group, SWT.CHECK); 104 GridData gd = new GridData(); 105 gd.horizontalSpan = 3; 106 fUseDefaultLocationButton.setLayoutData(gd); 107 fUseDefaultLocationButton.setText(PDEUIMessages.ConfigurationTab_useDefaultLoc); fUseDefaultLocationButton.addSelectionListener(new SelectionAdapter() { 109 public void widgetSelected(SelectionEvent e) { 110 boolean selected = fUseDefaultLocationButton.getSelection(); 111 fConfigAreaLabel.setEnabled(!selected); 112 fConfigAreaText.setEnabled(!selected); 113 fConfigAreaBrowse.setEnabled(!selected); 114 if (!selected) 115 fConfigAreaText.setText(fLastEnteredConfigArea); 116 else 117 fConfigAreaText.setText(PDECore.getDefault().getStateLocation().append(fConfigName).toOSString()); 118 updateStatus(); 119 } 120 }); 121 122 fConfigAreaLabel = new Label(group, SWT.NONE); 123 fConfigAreaLabel.setText(PDEUIMessages.ConfigurationTab_configLog); gd = new GridData(); 125 gd.horizontalIndent = 20; 126 fConfigAreaLabel.setLayoutData(gd); 127 128 fConfigAreaText = new Text(group, SWT.SINGLE|SWT.BORDER); 129 gd = new GridData(GridData.FILL_HORIZONTAL); 130 gd.widthHint = 300; 131 fConfigAreaText.setLayoutData(gd); 132 fConfigAreaText.addModifyListener(new ModifyListener() { 133 public void modifyText(ModifyEvent e) { 134 if (!fBlockChanges) 135 updateStatus(); 136 } 137 }); 138 139 fConfigAreaBrowse = new Button(group, SWT.PUSH); 140 fConfigAreaBrowse.setText(PDEUIMessages.ConfigurationTab_configBrowse); fConfigAreaBrowse.setLayoutData(new GridData()); 142 SWTUtil.setButtonDimensionHint(fConfigAreaBrowse); 143 fConfigAreaBrowse.addSelectionListener(new SelectionAdapter() { 144 public void widgetSelected(SelectionEvent e) { 145 handleBrowseDirectory(); 146 } 147 }); 148 149 fClearConfig = new Button(group, SWT.CHECK); 150 fClearConfig.setText(PDEUIMessages.ConfigurationTab_clearArea); gd = new GridData(); 152 gd.horizontalSpan = 3; 153 fClearConfig.setLayoutData(gd); 154 fClearConfig.addSelectionListener(new SelectionAdapter() { 155 public void widgetSelected(SelectionEvent e) { 156 updateLaunchConfigurationDialog(); 157 } 158 }); 159 } 160 161 protected void handleBrowseDirectory() { 162 DirectoryDialog dialog = new DirectoryDialog(getControl().getShell()); 163 dialog.setFilterPath(fConfigAreaText.getText().trim()); 164 dialog.setText(PDEUIMessages.ConfigurationTab_configLocTitle); dialog.setMessage(PDEUIMessages.ConfigurationTab_configLocMessage); String res = dialog.open(); 167 if (res != null) 168 fConfigAreaText.setText(res); 169 } 170 171 protected void updateStatus() { 172 if (!fUseDefaultLocationButton.getSelection() && fConfigAreaText.getText().trim().length() == 0) { 173 updateStatus(createStatus(IStatus.ERROR, PDEUIMessages.ConfigurationTab_noConfigLoc)); return; 175 } 176 177 if (fUseTemplateButton.getSelection()) { 178 String location = fTemplateLocationText.getText().trim(); 179 if (location.length() == 0) { 180 updateStatus(createStatus(IStatus.ERROR, PDEUIMessages.ConfigurationTab_noTemplateLoc)); return; 182 } 183 File file = new File (location); 184 if (!file.exists() || !file.isFile()) { 185 updateStatus(createStatus(IStatus.ERROR, PDEUIMessages.ConfigurationTab_templateNotExists)); return; 187 } 188 } 189 updateStatus(createStatus(IStatus.OK, "")); } 191 192 private void createConfigFileGroup(Composite parent) { 193 Group group = new Group(parent, SWT.NONE); 194 group.setText(PDEUIMessages.ConfigurationTab_configFileGroup); group.setLayout(new GridLayout(3, false)); 196 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 197 198 fGenerateFileButton = new Button(group, SWT.RADIO); 199 fGenerateFileButton.setText(PDEUIMessages.ConfigurationTab_defaultConfigIni); GridData gd = new GridData(); 201 gd.horizontalSpan = 3; 202 fGenerateFileButton.setLayoutData(gd); 203 fGenerateFileButton.addSelectionListener(new SelectionAdapter() { 204 public void widgetSelected(SelectionEvent e) { 205 boolean selected = fGenerateFileButton.getSelection(); 206 fTemplateLocationLabel.setEnabled(!selected); 207 fTemplateLocationText.setEnabled(!selected); 208 fTemplateLocationBrowse.setEnabled(!selected); 209 updateStatus(); 210 } 211 }); 212 213 fUseTemplateButton = new Button(group, SWT.RADIO); 214 fUseTemplateButton.setText(PDEUIMessages.ConfigurationTab_existingConfigIni); gd = new GridData(); 216 gd.horizontalSpan = 3; 217 fUseTemplateButton.setLayoutData(gd); 218 219 fTemplateLocationLabel = new Label(group, SWT.NONE); 220 fTemplateLocationLabel.setText(PDEUIMessages.ConfigurationTab_templateLoc); gd = new GridData(); 222 gd.horizontalIndent = 20; 223 fTemplateLocationLabel.setLayoutData(gd); 224 225 fTemplateLocationText = new Text(group, SWT.SINGLE|SWT.BORDER); 226 gd = new GridData(GridData.FILL_HORIZONTAL); 227 gd.widthHint = 300; 228 fTemplateLocationText.setLayoutData(gd); 229 fTemplateLocationText.addModifyListener(new ModifyListener() { 230 public void modifyText(ModifyEvent e) { 231 if (!fBlockChanges) 232 updateStatus(); 233 } 234 }); 235 236 fTemplateLocationBrowse = new Button(group, SWT.PUSH); 237 fTemplateLocationBrowse.setText(PDEUIMessages.ConfigurationTab_templateBrowse); fTemplateLocationBrowse.setLayoutData(new GridData()); 239 SWTUtil.setButtonDimensionHint(fTemplateLocationBrowse); 240 fTemplateLocationBrowse.addSelectionListener(new SelectionAdapter() { 241 public void widgetSelected(SelectionEvent e) { 242 handleBrowseWorkspaceFile(); 243 } 244 }); 245 } 246 247 protected void handleBrowseWorkspaceFile() { 248 ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( 249 getControl().getShell(), new WorkbenchLabelProvider(), 250 new WorkbenchContentProvider()); 251 252 IFile file = PDEPlugin.getWorkspace().getRoot().getFileForLocation(new Path(fTemplateLocationText.getText())); 253 if (file != null) 254 dialog.setInitialSelection(file); 255 dialog.setInput(PDEPlugin.getWorkspace().getRoot()); 256 dialog.addFilter(new ViewerFilter() { 257 public boolean select(Viewer viewer, Object parentElement, Object element) { 258 if (element instanceof IFile) 259 return ((IFile)element).getName().equals("config.ini"); return true; 261 } 262 }); 263 dialog.setAllowMultiple(false); 264 dialog.setTitle(PDEUIMessages.ConfigurationTab_fileSelection); dialog.setMessage(PDEUIMessages.ConfigurationTab_fileDialogMessage); dialog.setValidator(new ISelectionStatusValidator() { 267 public IStatus validate(Object [] selection) { 268 if (selection != null && selection.length > 0 269 && selection[0] instanceof IFile) 270 return new Status(IStatus.OK, PDEPlugin.getPluginId(), 271 IStatus.OK, "", null); 273 return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), 274 IStatus.ERROR, "", null); } 276 }); 277 if (dialog.open() == ElementTreeSelectionDialog.OK) { 278 file = (IFile) dialog.getFirstResult(); 279 fTemplateLocationText.setText(file.getLocation().toOSString()); 280 } 281 } 282 283 286 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { 287 configuration.setAttribute(CONFIG_USE_DEFAULT_AREA, true); 288 configuration.setAttribute(CONFIG_LOCATION, ""); configuration.setAttribute(CONFIG_CLEAR_AREA, fJUnitConfig); 290 configuration.setAttribute(CONFIG_GENERATE_DEFAULT, true); 291 configuration.setAttribute(CONFIG_TEMPLATE_LOCATION, ""); } 293 296 public void initializeFrom(ILaunchConfiguration configuration) { 297 try { 298 fBlockChanges = true; 299 boolean useDefaultArea = configuration.getAttribute(CONFIG_USE_DEFAULT_AREA, true); 300 fUseDefaultLocationButton.setSelection(useDefaultArea); 301 fConfigAreaLabel.setEnabled(!useDefaultArea); 302 fConfigAreaText.setEnabled(!useDefaultArea); 303 fConfigAreaBrowse.setEnabled(!useDefaultArea); 304 fClearConfig.setSelection(configuration.getAttribute(CONFIG_CLEAR_AREA, false)); 305 fConfigName = configuration.getName(); 306 fLastEnteredConfigArea = configuration.getAttribute(CONFIG_LOCATION, ""); if (useDefaultArea) 308 fConfigAreaText.setText(PDECore.getDefault().getStateLocation().append(configuration.getName()).toOSString()); 309 else 310 fConfigAreaText.setText(fLastEnteredConfigArea); 311 312 boolean generateDefault = configuration.getAttribute(CONFIG_GENERATE_DEFAULT, true); 313 fGenerateFileButton.setSelection(generateDefault); 314 fUseTemplateButton.setSelection(!generateDefault); 315 fTemplateLocationLabel.setEnabled(!generateDefault); 316 fTemplateLocationText.setEnabled(!generateDefault); 317 fTemplateLocationBrowse.setEnabled(!generateDefault); 318 fTemplateLocationText.setText(configuration.getAttribute(CONFIG_TEMPLATE_LOCATION, "")); } catch (CoreException e) { 320 } finally { 321 fBlockChanges = false; 322 } 323 updateStatus(); 324 } 325 326 329 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 330 configuration.setAttribute(CONFIG_USE_DEFAULT_AREA, fUseDefaultLocationButton.getSelection()); 331 if (!fUseDefaultLocationButton.getSelection()) { 332 fLastEnteredConfigArea = fConfigAreaText.getText().trim(); 333 configuration.setAttribute(CONFIG_LOCATION, fLastEnteredConfigArea); 334 } 335 configuration.setAttribute(CONFIG_CLEAR_AREA, fClearConfig.getSelection()); 336 configuration.setAttribute(CONFIG_GENERATE_DEFAULT, fGenerateFileButton.getSelection()); 337 if (!fGenerateFileButton.getSelection()) 338 configuration.setAttribute(CONFIG_TEMPLATE_LOCATION, fTemplateLocationText.getText().trim()); 339 } 340 343 public String getName() { 344 return PDEUIMessages.ConfigurationTab_name; } 346 347 350 public Image getImage() { 351 return fImage; 352 } 353 354 357 public void dispose() { 358 if (fImage != null) 359 fImage.dispose(); 360 } 361 } 362 | Popular Tags |