1 12 package org.eclipse.ui.externaltools.internal.launchConfigurations; 13 14 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.resources.IncrementalProjectBuilder; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IAdaptable; 20 import org.eclipse.core.variables.VariablesPlugin; 21 import org.eclipse.debug.core.DebugPlugin; 22 import org.eclipse.debug.core.ILaunchConfiguration; 23 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 24 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 25 import org.eclipse.debug.ui.IDebugUIConstants; 26 import org.eclipse.debug.ui.RefreshTab; 27 import org.eclipse.debug.ui.StringVariableSelectionDialog; 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.jface.window.Window; 30 import org.eclipse.jface.wizard.WizardDialog; 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.events.SelectionListener; 37 import org.eclipse.swt.graphics.Image; 38 import org.eclipse.swt.layout.GridData; 39 import org.eclipse.swt.layout.GridLayout; 40 import org.eclipse.swt.widgets.Button; 41 import org.eclipse.swt.widgets.Composite; 42 import org.eclipse.swt.widgets.FileDialog; 43 import org.eclipse.swt.widgets.Group; 44 import org.eclipse.swt.widgets.Label; 45 import org.eclipse.swt.widgets.Text; 46 import org.eclipse.ui.IWorkingSet; 47 import org.eclipse.ui.IWorkingSetManager; 48 import org.eclipse.ui.PlatformUI; 49 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; 50 import org.eclipse.ui.dialogs.IWorkingSetEditWizard; 51 import org.eclipse.ui.externaltools.internal.model.BuilderUtils; 52 import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin; 53 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; 54 import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds; 55 import org.eclipse.ui.ide.IDE; 56 import org.eclipse.ui.model.WorkbenchContentProvider; 57 import org.eclipse.ui.model.WorkbenchLabelProvider; 58 import org.eclipse.ui.views.navigator.ResourceComparator; 59 60 public class ExternalToolsBuilderTab extends AbstractLaunchConfigurationTab { 61 62 protected Button afterClean; 63 protected Button fDuringClean; 64 protected Button autoBuildButton; 65 protected Button manualBuild; 66 protected Button workingSetButton; 67 protected Button specifyResources; 68 protected Button fLaunchInBackgroundButton; 69 protected IWorkingSet workingSet; 70 protected ILaunchConfiguration fConfiguration; 71 72 private boolean fCreateBuildScheduleComponent= true; 73 74 private Button fConsoleOutput; 76 private Button fFileOutput; 77 private Button fFileBrowse; 78 private Text fFileText; 79 private Button fVariables; 80 private Button fAppend; 81 private Button fWorkspaceBrowse; 82 83 public ExternalToolsBuilderTab() { 84 } 85 86 public ExternalToolsBuilderTab(boolean createBuildScheduleComponent) { 87 fCreateBuildScheduleComponent= createBuildScheduleComponent; 88 } 89 90 protected SelectionListener selectionListener= new SelectionAdapter() { 91 94 public void widgetSelected(SelectionEvent e) { 95 boolean enabled= !fCreateBuildScheduleComponent || autoBuildButton.getSelection() || manualBuild.getSelection(); 96 workingSetButton.setEnabled(enabled); 97 specifyResources.setEnabled(enabled && workingSetButton.getSelection()); 98 updateLaunchConfigurationDialog(); 99 } 100 }; 101 102 public void createControl(Composite parent) { 103 Composite mainComposite = new Composite(parent, SWT.NONE); 104 setControl(mainComposite); 105 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IExternalToolsHelpContextIds.EXTERNAL_TOOLS_LAUNCH_CONFIGURATION_DIALOG_BUILDER_TAB); 106 107 GridLayout layout = new GridLayout(); 108 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); 109 gridData.horizontalSpan = 2; 110 layout.numColumns = 2; 111 layout.makeColumnsEqualWidth = false; 112 mainComposite.setLayout(layout); 113 mainComposite.setLayoutData(gridData); 114 mainComposite.setFont(parent.getFont()); 115 createOutputCaptureComponent(mainComposite); 116 createLaunchInBackgroundComposite(mainComposite); 117 createBuildScheduleComponent(mainComposite); 118 } 119 120 126 protected void createLaunchInBackgroundComposite(Composite parent) { 127 fLaunchInBackgroundButton = createCheckButton(parent, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_14); 128 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 129 data.horizontalSpan = 2; 130 fLaunchInBackgroundButton.setLayoutData(data); 131 fLaunchInBackgroundButton.addSelectionListener(new SelectionAdapter() { 132 public void widgetSelected(SelectionEvent e) { 133 updateLaunchConfigurationDialog(); 134 } 135 }); 136 } 137 138 protected void createBuildScheduleComponent(Composite parent) { 139 if (fCreateBuildScheduleComponent) { 140 Label label= new Label(parent, SWT.NONE); 141 label.setText(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_Run_this_builder_for__1); 142 label.setFont(parent.getFont()); 143 afterClean= createButton(parent, selectionListener, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab__Full_builds_2, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_Full, 2); 144 manualBuild= createButton(parent, selectionListener, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab__Incremental_builds_4, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_Inc, 2); 145 autoBuildButton= createButton(parent, selectionListener, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab__Auto_builds__Not_recommended__6, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_Auto, 2); 146 fDuringClean= createButton(parent, selectionListener, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_0, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_1, 2); 147 148 createVerticalSpacer(parent, 2); 149 } 150 151 workingSetButton= createButton(parent, selectionListener, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_workingSet_label, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_workingSet_tooltip, 1); 152 specifyResources= createPushButton(parent, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_13, null); 153 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END); 154 specifyResources.setLayoutData(gd); 155 specifyResources.addSelectionListener(new SelectionAdapter() { 156 public void widgetSelected(SelectionEvent e) { 157 selectResources(); 158 } 159 }); 160 Label label= new Label(parent, SWT.NONE); 161 label.setText(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_2); 162 label.setFont(parent.getFont()); 163 } 164 165 private void createOutputCaptureComponent(Composite parent) { 166 Group group = new Group(parent, SWT.NONE); 167 group.setText(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_17); 168 GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false); 169 gd.horizontalSpan = 2; 170 group.setLayoutData(gd); 171 GridLayout layout = new GridLayout(5, false); 172 group.setLayout(layout); 173 group.setFont(parent.getFont()); 174 175 fConsoleOutput = createCheckButton(group, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_18); 176 gd = new GridData(SWT.BEGINNING, SWT.NORMAL, true, false); 177 gd.horizontalSpan = 5; 178 fConsoleOutput.setLayoutData(gd); 179 180 fConsoleOutput.addSelectionListener(new SelectionAdapter() { 181 public void widgetSelected(SelectionEvent e) { 182 updateLaunchConfigurationDialog(); 183 } 184 }); 185 186 fFileOutput = createCheckButton(group, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_19); 187 fFileOutput.setLayoutData(new GridData(SWT.BEGINNING, SWT.NORMAL, false, false)); 188 189 fFileText = new Text(group, SWT.SINGLE | SWT.BORDER); 190 gd = new GridData(SWT.FILL, SWT.NORMAL, true, false); 191 gd.horizontalSpan = 4; 192 fFileText.setLayoutData(gd); 193 fFileText.setFont(parent.getFont()); 194 195 Label spacer = new Label(group,SWT.NONE); 196 gd = new GridData(SWT.FILL, SWT.NORMAL, true, false); 197 gd.horizontalSpan=2; 198 spacer.setLayoutData(gd); 199 fWorkspaceBrowse = createPushButton(group, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_20, null); 200 fFileBrowse = createPushButton(group, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_21, null); 201 fVariables = createPushButton(group, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_22, null); 202 203 spacer = new Label(group,SWT.NONE); 204 spacer.setLayoutData(new GridData(SWT.FILL, SWT.NORMAL, false, false)); 205 fAppend = createCheckButton(group, ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_23); 206 gd = new GridData(SWT.LEFT, SWT.TOP, true, false); 207 gd.horizontalSpan = 4; 208 fAppend.setLayoutData(gd); 209 210 fFileOutput.addSelectionListener(new SelectionAdapter() { 211 public void widgetSelected(SelectionEvent e) { 212 boolean enabled = fFileOutput.getSelection(); 213 fFileText.setEnabled(enabled); 214 fFileBrowse.setEnabled(enabled); 215 fWorkspaceBrowse.setEnabled(enabled); 216 fVariables.setEnabled(enabled); 217 fAppend.setEnabled(enabled); 218 updateLaunchConfigurationDialog(); 219 } 220 }); 221 222 fAppend.addSelectionListener(new SelectionAdapter() { 223 public void widgetSelected(SelectionEvent e) { 224 updateLaunchConfigurationDialog(); 225 } 226 }); 227 228 fWorkspaceBrowse.addSelectionListener(new SelectionAdapter() { 229 public void widgetSelected(SelectionEvent e) { 230 ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider()); 231 dialog.setTitle(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_24); 232 dialog.setMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_25); 233 dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); 234 dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); 235 int buttonId = dialog.open(); 236 if (buttonId == IDialogConstants.OK_ID) { 237 IResource resource = (IResource) dialog.getFirstResult(); 238 String arg = resource.getFullPath().toString(); 239 String fileLoc = VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", arg); fFileText.setText(fileLoc); 241 } 242 } 243 }); 244 245 fFileBrowse.addSelectionListener(new SelectionAdapter() { 246 public void widgetSelected(SelectionEvent e) { 247 String filePath = fFileText.getText(); 248 FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); 249 250 filePath = dialog.open(); 251 if (filePath != null) { 252 fFileText.setText(filePath); 253 } 254 } 255 }); 256 257 fFileText.addModifyListener(new ModifyListener() { 258 public void modifyText(ModifyEvent e) { 259 updateLaunchConfigurationDialog(); 260 } 261 }); 262 263 fVariables.addSelectionListener(new SelectionListener() { 264 public void widgetSelected(SelectionEvent e) { 265 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); 266 dialog.open(); 267 String variable = dialog.getVariableExpression(); 268 if (variable != null) { 269 fFileText.insert(variable); 270 } 271 } 272 public void widgetDefaultSelected(SelectionEvent e) { 273 } 274 }); 275 } 276 277 280 protected Button createButton(Composite parent, SelectionListener listener, String text, String tooltipText, int columns) { 281 Button button= createCheckButton(parent, text); 282 button.setToolTipText(tooltipText); 283 button.addSelectionListener(listener); 284 GridData gd= new GridData(GridData.FILL_HORIZONTAL); 285 gd.horizontalSpan = columns; 286 button.setLayoutData(gd); 287 return button; 288 } 289 290 293 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { 294 StringBuffer buffer= new StringBuffer (IExternalToolConstants.BUILD_TYPE_FULL); 295 buffer.append(','); 296 buffer.append(IExternalToolConstants.BUILD_TYPE_INCREMENTAL); 297 buffer.append(','); 298 configuration.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, buffer.toString()); 299 configuration.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false); 300 configuration.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, true); 301 } 302 303 306 public void initializeFrom(ILaunchConfiguration configuration) { 307 fConfiguration= configuration; 308 if (fCreateBuildScheduleComponent) { 309 afterClean.setSelection(false); 310 manualBuild.setSelection(false); 311 autoBuildButton.setSelection(false); 312 fDuringClean.setSelection(false); 313 } 314 315 String buildKindString= null; 316 String buildScope= null; 317 try { 318 buildKindString= configuration.getAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, ""); buildScope= configuration.getAttribute(IExternalToolConstants.ATTR_BUILD_SCOPE, (String )null); 320 } catch (CoreException e) { 321 } 322 323 workingSetButton.setSelection(buildScope != null); 324 workingSetButton.setEnabled(buildScope != null); 325 326 if (buildScope != null) { 327 workingSet = RefreshTab.getWorkingSet(buildScope); 328 } 329 330 if (fCreateBuildScheduleComponent) { 331 int buildTypes[]= BuilderUtils.buildTypesToArray(buildKindString); 332 for (int i = 0; i < buildTypes.length; i++) { 333 switch (buildTypes[i]) { 334 case IncrementalProjectBuilder.FULL_BUILD: 335 afterClean.setSelection(true); 336 break; 337 case IncrementalProjectBuilder.INCREMENTAL_BUILD: 338 manualBuild.setSelection(true); 339 break; 340 case IncrementalProjectBuilder.AUTO_BUILD: 341 autoBuildButton.setSelection(true); 342 break; 343 case IncrementalProjectBuilder.CLEAN_BUILD: 344 fDuringClean.setSelection(true); 345 break; 346 } 347 } 348 } 349 350 boolean enabled= true; 351 if (fCreateBuildScheduleComponent) { 352 enabled= autoBuildButton.getSelection() || manualBuild.getSelection(); 353 } 354 workingSetButton.setEnabled(enabled); 355 specifyResources.setEnabled(enabled && workingSetButton.getSelection()); 356 updateRunInBackground(configuration); 357 updateConsoleOutput(configuration); 358 } 359 360 protected void updateRunInBackground(ILaunchConfiguration configuration) { 361 fLaunchInBackgroundButton.setSelection(isLaunchInBackground(configuration)); 362 } 363 364 private void updateConsoleOutput(ILaunchConfiguration configuration) { 365 boolean outputToConsole = true; 366 String outputFile = null; 367 boolean append = false; 368 369 try { 370 outputToConsole = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true); 371 outputFile = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, (String )null); 372 append = configuration.getAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, false); 373 } catch (CoreException e) { 374 } 375 376 fConsoleOutput.setSelection(outputToConsole); 377 fAppend.setSelection(append); 378 boolean haveOutputFile= outputFile != null; 379 if (haveOutputFile) { 380 fFileText.setText(outputFile); 381 } 382 fFileOutput.setSelection(haveOutputFile); 383 fFileText.setEnabled(haveOutputFile); 384 fFileBrowse.setEnabled(haveOutputFile); 385 fWorkspaceBrowse.setEnabled(haveOutputFile); 386 fVariables.setEnabled(haveOutputFile); 387 fAppend.setEnabled(haveOutputFile); 388 } 389 390 396 public static boolean isLaunchInBackground(ILaunchConfiguration configuration) { 397 boolean launchInBackground= false; 398 try { 399 launchInBackground= configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false); 400 } catch (CoreException ce) { 401 ExternalToolsPlugin.getDefault().log(ce); 402 } 403 return launchInBackground; 404 } 405 406 409 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 410 if (fCreateBuildScheduleComponent) { 411 StringBuffer buffer= new StringBuffer (); 412 if (afterClean.getSelection()) { 413 buffer.append(IExternalToolConstants.BUILD_TYPE_FULL).append(','); 414 } 415 if (manualBuild.getSelection()){ 416 buffer.append(IExternalToolConstants.BUILD_TYPE_INCREMENTAL).append(','); 417 } 418 if (autoBuildButton.getSelection()) { 419 buffer.append(IExternalToolConstants.BUILD_TYPE_AUTO).append(','); 420 } 421 422 if (fDuringClean.getSelection()) { 423 buffer.append(IExternalToolConstants.BUILD_TYPE_CLEAN); 424 } 425 configuration.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, buffer.toString()); 426 } 427 if (workingSetButton.getSelection()) { 428 String scope = RefreshTab.getRefreshAttribute(workingSet); 429 configuration.setAttribute(IExternalToolConstants.ATTR_BUILD_SCOPE, scope); 430 } else { 431 configuration.setAttribute(IExternalToolConstants.ATTR_BUILD_SCOPE, (String )null); 432 } 433 configuration.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, fLaunchInBackgroundButton.getSelection()); 434 435 boolean captureOutput = false; 436 if (fConsoleOutput.getSelection()) { 437 captureOutput = true; 438 configuration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, (String )null); 439 } else { 440 configuration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, false); 441 } 442 if (fFileOutput.getSelection()) { 443 captureOutput = true; 444 String file = fFileText.getText(); 445 configuration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, file); 446 if(fAppend.getSelection()) { 447 configuration.setAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, true); 448 } else { 449 configuration.setAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, (String )null); 450 } 451 } else { 452 configuration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, (String )null); 453 } 454 455 if (!captureOutput) { 456 configuration.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, false); 457 } else { 458 configuration.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, (String )null); 459 } 460 } 461 462 465 public String getName() { 466 return ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_Build_Options_9; 467 } 468 469 472 public Image getImage() { 473 return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT); 474 } 475 476 479 public boolean isValid(ILaunchConfiguration launchConfig) { 480 setErrorMessage(null); 481 setMessage(null); 482 if (fCreateBuildScheduleComponent) { 483 boolean buildKindSelected= afterClean.getSelection() || manualBuild.getSelection() || autoBuildButton.getSelection() || fDuringClean.getSelection(); 484 if (!buildKindSelected) { 485 setErrorMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_buildKindError); 486 return false; 487 } 488 } 489 if (workingSetButton.getSelection() && (workingSet == null || workingSet.getElements().length == 0)) { 490 setErrorMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_16); 491 return false; 492 } 493 494 return validateRedirectFile(); 495 } 496 499 public boolean canSave() { 500 return isValid(null); 501 } 502 503 506 private void selectResources() { 507 IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager(); 508 509 if (workingSet == null){ 510 workingSet = workingSetManager.createWorkingSet(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_15, new IAdaptable[0]); 511 } 512 IWorkingSetEditWizard wizard= workingSetManager.createWorkingSetEditWizard(workingSet); 513 WizardDialog dialog = new WizardDialog(ExternalToolsPlugin.getStandardDisplay().getActiveShell(), wizard); 514 dialog.create(); 515 516 if (dialog.open() == Window.CANCEL) { 517 return; 518 } 519 workingSet = wizard.getSelection(); 520 updateLaunchConfigurationDialog(); 521 } 522 525 public void activated(ILaunchConfigurationWorkingCopy workingCopy) { 526 } 528 529 532 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { 533 } 535 536 private boolean validateRedirectFile() { 537 if(fFileOutput.getSelection()) { 538 int len = fFileText.getText().trim().length(); 539 if (len == 0) { 540 setErrorMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsBuilderTab_26); 541 return false; 542 } 543 } 544 return true; 545 } 546 } | Popular Tags |