1 11 package org.eclipse.ant.internal.ui.launchConfigurations; 12 13 14 import java.io.File ; 15 import java.lang.reflect.InvocationTargetException ; 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 20 import org.eclipse.ant.internal.ui.AntUIImages; 21 import org.eclipse.ant.internal.ui.AntUIPlugin; 22 import org.eclipse.ant.internal.ui.AntUtil; 23 import org.eclipse.ant.internal.ui.IAntUIConstants; 24 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 25 import org.eclipse.ant.internal.ui.model.AntElementNode; 26 import org.eclipse.ant.internal.ui.model.AntModelContentProvider; 27 import org.eclipse.ant.internal.ui.model.AntProjectNode; 28 import org.eclipse.ant.internal.ui.model.AntTargetNode; 29 import org.eclipse.ant.internal.ui.model.InternalTargetFilter; 30 import org.eclipse.core.resources.ResourcesPlugin; 31 import org.eclipse.core.runtime.CoreException; 32 import org.eclipse.core.runtime.IProgressMonitor; 33 import org.eclipse.core.runtime.IStatus; 34 import org.eclipse.core.runtime.jobs.ISchedulingRule; 35 import org.eclipse.core.variables.IStringVariableManager; 36 import org.eclipse.core.variables.VariablesPlugin; 37 import org.eclipse.debug.core.ILaunchConfiguration; 38 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 39 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 40 import org.eclipse.jface.dialogs.Dialog; 41 import org.eclipse.jface.dialogs.IDialogConstants; 42 import org.eclipse.jface.operation.IRunnableContext; 43 import org.eclipse.jface.operation.IRunnableWithProgress; 44 import org.eclipse.jface.viewers.CheckStateChangedEvent; 45 import org.eclipse.jface.viewers.CheckboxTableViewer; 46 import org.eclipse.jface.viewers.ColumnWeightData; 47 import org.eclipse.jface.viewers.DoubleClickEvent; 48 import org.eclipse.jface.viewers.ICheckStateListener; 49 import org.eclipse.jface.viewers.IDoubleClickListener; 50 import org.eclipse.jface.viewers.ISelection; 51 import org.eclipse.jface.viewers.IStructuredSelection; 52 import org.eclipse.jface.viewers.TableLayout; 53 import org.eclipse.jface.viewers.Viewer; 54 import org.eclipse.jface.viewers.ViewerComparator; 55 import org.eclipse.jface.viewers.ViewerFilter; 56 import org.eclipse.jface.window.Window; 57 import org.eclipse.swt.SWT; 58 import org.eclipse.swt.events.SelectionAdapter; 59 import org.eclipse.swt.events.SelectionEvent; 60 import org.eclipse.swt.events.ShellAdapter; 61 import org.eclipse.swt.events.ShellEvent; 62 import org.eclipse.swt.graphics.Font; 63 import org.eclipse.swt.graphics.Image; 64 import org.eclipse.swt.layout.GridData; 65 import org.eclipse.swt.layout.GridLayout; 66 import org.eclipse.swt.widgets.Button; 67 import org.eclipse.swt.widgets.Composite; 68 import org.eclipse.swt.widgets.Label; 69 import org.eclipse.swt.widgets.Table; 70 import org.eclipse.swt.widgets.TableColumn; 71 import org.eclipse.swt.widgets.Text; 72 import org.eclipse.ui.PlatformUI; 73 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; 74 75 import com.ibm.icu.text.MessageFormat; 76 77 82 public class AntTargetsTab extends AbstractLaunchConfigurationTab { 83 84 private AntTargetNode fDefaultTarget = null; 85 private AntTargetNode[] fAllTargets= null; 86 private List fOrderedTargets = null; 87 88 private CheckboxTableViewer fTableViewer = null; 89 private Label fSelectionCountLabel = null; 90 private Text fTargetOrderText = null; 91 private Button fOrderButton = null; 92 private Button fFilterInternalTargets; 93 private InternalTargetFilter fInternalTargetFilter= null; 94 private Button fSortButton; 95 96 private ILaunchConfiguration fLaunchConfiguration; 97 private int fSortDirection= 0; 98 private boolean fInitializing= false; 99 100 103 public final static int SORT_NONE= 0; 104 public final static int SORT_NAME= 1; 105 public final static int SORT_NAME_REVERSE= -1; 106 public final static int SORT_DESCRIPTION= 2; 107 public final static int SORT_DESCRIPTION_REVERSE= -2; 108 109 113 private class AntTargetsComparator extends ViewerComparator { 114 117 public int compare(Viewer viewer, Object e1, Object e2) { 118 if (!(e1 instanceof AntTargetNode && e2 instanceof AntTargetNode)) { 119 return super.compare(viewer, e1, e2); 120 } 121 if (fSortDirection == SORT_NONE) { 122 return 0; 123 } 124 String string1, string2; 125 int result= 0; 126 if (fSortDirection == SORT_NAME || fSortDirection == SORT_NAME_REVERSE) { 127 string1= ((AntTargetNode) e1).getLabel(); 128 string2= ((AntTargetNode) e2).getLabel(); 129 } else { 130 string1= ((AntTargetNode) e1).getTarget().getDescription(); 131 string2= ((AntTargetNode) e2).getTarget().getDescription(); 132 } 133 if (string1 != null && string2 != null) { 134 result= getComparator().compare(string1, string2); 135 } else if (string1 == null) { 136 result= 1; 137 } else if (string2 == null) { 138 result= -1; 139 } 140 if (fSortDirection < 0) { if (result == 0) { 142 result= -1; 143 } else { 144 result= -result; 145 } 146 } 147 return result; 148 } 149 } 150 151 154 public void createControl(Composite parent) { 155 Font font = parent.getFont(); 156 157 Composite comp = new Composite(parent, SWT.NONE); 158 setControl(comp); 159 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IAntUIHelpContextIds.ANT_TARGETS_TAB); 160 GridLayout topLayout = new GridLayout(); 161 comp.setLayout(topLayout); 162 GridData gd = new GridData(GridData.FILL_BOTH); 163 comp.setLayoutData(gd); 164 comp.setFont(font); 165 166 createTargetsTable(comp); 167 createSelectionCount(comp); 168 169 Composite buttonComposite= new Composite(comp, SWT.NONE); 170 GridLayout layout= new GridLayout(); 171 layout.verticalSpacing = 0; 172 layout.marginHeight = 0; 173 layout.marginWidth = 0; 174 buttonComposite.setLayout(layout); 175 buttonComposite.setFont(font); 176 177 createSortTargets(buttonComposite); 178 createFilterInternalTargets(buttonComposite); 179 180 createVerticalSpacer(comp, 1); 181 createTargetOrder(comp); 182 Dialog.applyDialogFont(parent); 183 } 184 185 189 private void createSelectionCount(Composite parent) { 190 fSelectionCountLabel = new Label(parent, SWT.NONE); 191 fSelectionCountLabel.setFont(parent.getFont()); 192 fSelectionCountLabel.setText(AntLaunchConfigurationMessages.AntTargetsTab_0_out_of_0_selected_2); 193 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 194 fSelectionCountLabel.setLayoutData(gd); 195 } 196 197 201 private void createTargetOrder(Composite parent) { 202 Font font= parent.getFont(); 203 204 Label label = new Label(parent, SWT.NONE); 205 label.setText(AntLaunchConfigurationMessages.AntTargetsTab_Target_execution_order__3); 206 label.setFont(font); 207 208 Composite orderComposite = new Composite(parent, SWT.NONE); 209 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 210 orderComposite.setLayoutData(gd); 211 GridLayout layout = new GridLayout(2, false); 212 layout.marginHeight = 0; 213 layout.marginWidth = 0; 214 orderComposite.setLayout(layout); 215 orderComposite.setFont(font); 216 217 fTargetOrderText = new Text(orderComposite, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY); 218 fTargetOrderText.setFont(font); 219 gd = new GridData(GridData.FILL_HORIZONTAL); 220 gd.heightHint = 40; 221 gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; 222 fTargetOrderText.setLayoutData(gd); 223 224 fOrderButton = createPushButton(orderComposite, AntLaunchConfigurationMessages.AntTargetsTab__Order____4, null); 225 gd = (GridData)fOrderButton.getLayoutData(); 226 gd.verticalAlignment = GridData.BEGINNING; 227 fOrderButton.setFont(font); 228 fOrderButton.addSelectionListener(new SelectionAdapter() { 229 public void widgetSelected(SelectionEvent e) { 230 handleOrderPressed(); 231 } 232 }); 233 } 234 235 239 private void createFilterInternalTargets(Composite parent) { 240 fFilterInternalTargets= createCheckButton(parent, AntLaunchConfigurationMessages.AntTargetsTab_12); 241 fFilterInternalTargets.addSelectionListener(new SelectionAdapter() { 242 public void widgetSelected(SelectionEvent e) { 243 handleFilterTargetsSelected(); 244 } 245 }); 246 } 247 248 252 private void createSortTargets(Composite parent) { 253 fSortButton= createCheckButton(parent, AntLaunchConfigurationMessages.AntTargetsTab_14); 254 fSortButton.addSelectionListener(new SelectionAdapter() { 255 public void widgetSelected(SelectionEvent e) { 256 handleSortTargetsSelected(); 257 } 258 }); 259 } 260 261 266 private void handleFilterTargetsSelected() { 267 boolean filter= fFilterInternalTargets.getSelection(); 268 if (filter) { 269 fTableViewer.addFilter(getInternalTargetsFilter()); 270 } else { 271 fTableViewer.removeFilter(getInternalTargetsFilter()); 272 } 273 274 updateSelectionCount(); 278 if (!fInitializing) { 279 updateLaunchConfigurationDialog(); 280 } 281 } 282 283 private ViewerFilter getInternalTargetsFilter() { 284 if (fInternalTargetFilter == null) { 285 fInternalTargetFilter= new InternalTargetFilter(); 286 } 287 return fInternalTargetFilter; 288 } 289 290 294 private void handleSortTargetsSelected() { 295 setSort(fSortButton.getSelection() ? SORT_NAME : SORT_NONE); 296 } 297 298 304 private void setSort(int column) { 305 fSortDirection= column; 306 fTableViewer.refresh(); 307 if (!fInitializing) { 308 updateLaunchConfigurationDialog(); 309 } 310 } 311 312 316 private void handleOrderPressed() { 317 TargetOrderDialog dialog = new TargetOrderDialog(getShell(), fOrderedTargets.toArray()); 318 int ok = dialog.open(); 319 if (ok == Window.OK) { 320 fOrderedTargets.clear(); 321 Object [] targets = dialog.getTargets(); 322 for (int i = 0; i < targets.length; i++) { 323 fOrderedTargets.add(targets[i]); 324 updateSelectionCount(); 325 updateLaunchConfigurationDialog(); 326 } 327 } 328 } 329 330 334 private void createTargetsTable(Composite parent) { 335 Font font= parent.getFont(); 336 Label label = new Label(parent, SWT.NONE); 337 label.setFont(font); 338 label.setText(AntLaunchConfigurationMessages.AntTargetsTab_Check_targets_to_e_xecute__1); 339 340 final Table table= new Table(parent, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION | SWT.RESIZE); 341 342 GridData data= new GridData(GridData.FILL_BOTH); 343 int availableRows= availableRows(parent); 344 data.heightHint = table.getItemHeight() * (availableRows / 20); 345 data.widthHint= 250; 346 table.setLayoutData(data); 347 table.setFont(font); 348 349 table.setHeaderVisible(true); 350 table.setLinesVisible(true); 351 352 TableLayout tableLayout= new TableLayout(); 353 ColumnWeightData weightData = new ColumnWeightData(30, true); 354 tableLayout.addColumnData(weightData); 355 weightData = new ColumnWeightData(70, true); 356 tableLayout.addColumnData(weightData); 357 table.setLayout(tableLayout); 358 359 final TableColumn column1= new TableColumn(table, SWT.NULL); 360 column1.setText(AntLaunchConfigurationMessages.AntTargetsTab_Name_5); 361 362 final TableColumn column2= new TableColumn(table, SWT.NULL); 363 column2.setText(AntLaunchConfigurationMessages.AntTargetsTab_Description_6); 364 365 366 getShell().addShellListener(new ShellAdapter() { 373 public void shellActivated(ShellEvent e) { 374 if(!table.isDisposed()) { 375 int tableWidth = table.getSize().x; 376 if (tableWidth > 0) { 377 int c1 = tableWidth / 3; 378 column1.setWidth(c1); 379 column2.setWidth(tableWidth - c1); 380 } 381 getShell().removeShellListener(this); 382 } 383 } 384 }); 385 386 fTableViewer = new CheckboxTableViewer(table); 387 fTableViewer.setLabelProvider(new TargetTableLabelProvider()); 388 fTableViewer.setContentProvider(new AntModelContentProvider()); 389 fTableViewer.setComparator(new AntTargetsComparator()); 390 391 fTableViewer.addDoubleClickListener(new IDoubleClickListener() { 392 public void doubleClick(DoubleClickEvent event) { 393 ISelection selection= event.getSelection(); 394 if (!selection.isEmpty() && selection instanceof IStructuredSelection) { 395 IStructuredSelection ss= (IStructuredSelection)selection; 396 Object element= ss.getFirstElement(); 397 boolean checked= !fTableViewer.getChecked(element); 398 fTableViewer.setChecked(element, checked); 399 updateOrderedTargets(element, checked); 400 } 401 } 402 }); 403 404 fTableViewer.addCheckStateListener(new ICheckStateListener() { 405 public void checkStateChanged(CheckStateChangedEvent event) { 406 updateOrderedTargets(event.getElement(), event.getChecked()); 407 } 408 }); 409 410 TableColumn[] columns= fTableViewer.getTable().getColumns(); 411 for (int i = 0; i < columns.length; i++) { 412 final int index= i; 413 columns[index].addSelectionListener(new SelectionAdapter() { 414 public void widgetSelected(SelectionEvent e) { 415 if (fSortButton.getSelection()) { 416 int column= index + 1; 419 if (column == fSortDirection) { 420 column= -column; } 422 setSort(column); 423 } 424 } 425 }); 426 } 427 } 428 429 435 private int availableRows(Composite parent) { 436 437 int fontHeight = (parent.getFont().getFontData())[0].getHeight(); 438 int displayHeight = parent.getDisplay().getClientArea().height; 439 440 return displayHeight / fontHeight; 441 } 442 443 451 private void updateOrderedTargets(Object element , boolean checked) { 452 if (checked) { 453 fOrderedTargets.add(element); 454 } else { 455 fOrderedTargets.remove(element); 456 } 457 updateSelectionCount(); 458 updateLaunchConfigurationDialog(); 459 } 460 461 465 private void updateSelectionCount() { 466 Object [] checked = fTableViewer.getCheckedElements(); 467 String numSelected = Integer.toString(checked.length); 468 469 int all= fAllTargets == null ? 0 : fAllTargets.length; 470 int visible= fTableViewer.getTable().getItemCount(); 471 String total = Integer.toString(visible); 472 int numHidden= all - visible; 473 if (numHidden > 0) { 474 fSelectionCountLabel.setText(MessageFormat.format(AntLaunchConfigurationMessages.AntTargetsTab_13, new String []{numSelected, String.valueOf(all), String.valueOf(numHidden)})); 475 } else { 476 fSelectionCountLabel.setText(MessageFormat.format(AntLaunchConfigurationMessages.AntTargetsTab__0__out_of__1__selected_7, new String []{numSelected, total})); 477 } 478 479 fOrderButton.setEnabled(checked.length > 1); 480 481 StringBuffer buffer = new StringBuffer (); 482 Iterator iter = fOrderedTargets.iterator(); 483 while (iter.hasNext()) { 484 buffer.append(((AntTargetNode)iter.next()).getTargetName()); 485 buffer.append(", "); } 487 if (buffer.length() > 2) { 488 buffer.setLength(buffer.length() - 2); 490 } 491 fTargetOrderText.setText(buffer.toString()); 492 } 493 494 498 private AntTargetNode[] getTargets() { 499 if (fAllTargets == null || isDirty()) { 500 fAllTargets= null; 501 fDefaultTarget= null; 502 setDirty(false); 503 setErrorMessage(null); 504 setMessage(null); 505 506 final String expandedLocation= validateLocation(); 507 if (expandedLocation == null) { 508 return fAllTargets; 509 } 510 final CoreException[] exceptions= new CoreException[1]; 511 try { 512 IRunnableWithProgress operation= new IRunnableWithProgress() { 513 516 public void run(IProgressMonitor monitor) { 517 try { 518 fAllTargets = AntUtil.getTargets(expandedLocation, fLaunchConfiguration); 519 } catch (CoreException ce) { 520 exceptions[0]= ce; 521 } 522 } 523 }; 524 525 IRunnableContext context= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 526 if (context == null) { 527 context= getLaunchConfigurationDialog(); 528 } 529 530 ISchedulingRule rule= null; 531 if (!ResourcesPlugin.getWorkspace().isTreeLocked()) { 532 rule= AntUtil.getFileForLocation(expandedLocation, null); 534 } 535 PlatformUI.getWorkbench().getProgressService().runInUI(context, operation, rule); 536 } catch (InvocationTargetException e) { 537 AntUIPlugin.log("Internal error occurred retrieving targets", e.getTargetException()); setErrorMessage(AntLaunchConfigurationMessages.AntTargetsTab_1); 539 fAllTargets= null; 540 return null; 541 } catch (InterruptedException e) { 542 AntUIPlugin.log("Internal error occurred retrieving targets", e); setErrorMessage(AntLaunchConfigurationMessages.AntTargetsTab_1); 544 fAllTargets= null; 545 return null; 546 } 547 548 if (exceptions[0] != null) { 549 IStatus exceptionStatus= exceptions[0].getStatus(); 550 IStatus[] children= exceptionStatus.getChildren(); 551 StringBuffer message= new StringBuffer (exceptions[0].getMessage()); 552 for (int i = 0; i < children.length; i++) { 553 message.append(' '); 554 IStatus childStatus = children[i]; 555 message.append(childStatus.getMessage()); 556 } 557 setErrorMessage(message.toString()); 558 fAllTargets= null; 559 return fAllTargets; 560 } 561 562 if (fAllTargets == null) { 563 return fAllTargets; 565 } 566 567 AntTargetNode target= fAllTargets[0]; 568 AntProjectNode projectNode= target.getProjectNode(); 569 setErrorMessageFromNode(projectNode); 570 for (int i=0; i < fAllTargets.length; i++) { 571 target= fAllTargets[i]; 572 if (target.isDefaultTarget()) { 573 fDefaultTarget= target; 574 } 575 setErrorMessageFromNode(target); 576 } 577 } 578 579 return fAllTargets; 580 } 581 582 private void setErrorMessageFromNode(AntElementNode node) { 583 if (getErrorMessage() != null) { 584 return; 585 } 586 if (node.isErrorNode() || node.isWarningNode()) { 587 String message= node.getProblemMessage(); 588 if (message != null) { 589 setErrorMessage(message); 590 } else { 591 setErrorMessage(AntLaunchConfigurationMessages.AntTargetsTab_0); 592 } 593 } 594 } 595 596 599 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { 600 } 601 602 605 public void initializeFrom(ILaunchConfiguration configuration) { 606 fInitializing= true; 607 fLaunchConfiguration= configuration; 608 fOrderedTargets = new ArrayList (); 609 setErrorMessage(null); 610 setMessage(null); 611 setDirty(true); 612 boolean hideInternal= false; 613 try { 614 hideInternal = fLaunchConfiguration.getAttribute(IAntLaunchConfigurationConstants.ATTR_HIDE_INTERNAL_TARGETS, false); 615 } catch (CoreException e) { 616 AntUIPlugin.log(e); 617 } 618 fFilterInternalTargets.setSelection(hideInternal); 619 handleFilterTargetsSelected(); 620 int sort= SORT_NONE; 621 try { 622 sort = fLaunchConfiguration.getAttribute(IAntLaunchConfigurationConstants.ATTR_SORT_TARGETS, sort); 623 } catch (CoreException e) { 624 AntUIPlugin.log(e); 625 } 626 fSortButton.setSelection(sort != SORT_NONE); 627 setSort(sort); 628 String configTargets= null; 629 String newLocation= null; 630 631 try { 632 configTargets= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String )null); 633 newLocation= configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String )null); 634 } catch (CoreException ce) { 635 AntUIPlugin.log(AntLaunchConfigurationMessages.AntTargetsTab_Error_reading_configuration_12, ce); 636 } 637 638 if (newLocation == null) { 639 fAllTargets= null; 640 initializeForNoTargets(); 641 return; 642 } 643 644 AntTargetNode[] allTargetNodes= getTargets(); 645 if (allTargetNodes == null) { 646 initializeForNoTargets(); 647 return; 648 } 649 650 String [] targetNames= AntUtil.parseRunTargets(configTargets); 651 if (targetNames.length == 0) { 652 fTableViewer.setAllChecked(false); 653 setExecuteInput(allTargetNodes); 654 if (fDefaultTarget != null) { 655 fOrderedTargets.add(fDefaultTarget); 656 fTableViewer.setChecked(fDefaultTarget, true); 657 updateSelectionCount(); 658 updateLaunchConfigurationDialog(); 659 } 660 fInitializing= false; 661 return; 662 } 663 664 setExecuteInput(allTargetNodes); 665 fTableViewer.setAllChecked(false); 666 for (int i = 0; i < targetNames.length; i++) { 667 for (int j = 0; j < fAllTargets.length; j++) { 668 if (targetNames[i].equals(fAllTargets[j].getTargetName())) { 669 fOrderedTargets.add(fAllTargets[j]); 670 fTableViewer.setChecked(fAllTargets[j], true); 671 } 672 } 673 } 674 updateSelectionCount(); 675 fInitializing= false; 676 } 677 678 private void initializeForNoTargets() { 679 setExecuteInput(new AntTargetNode[0]); 680 fTableViewer.setInput(new AntTargetNode[0]); 681 fInitializing= false; 682 } 683 684 687 private void setExecuteInput(Object input) { 688 fTableViewer.setInput(input); 689 updateSelectionCount(); 690 } 691 692 695 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 696 if (fFilterInternalTargets.getSelection()) { 698 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_HIDE_INTERNAL_TARGETS, true); 699 } else { 700 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_HIDE_INTERNAL_TARGETS, (String )null); 701 } 702 if (fSortDirection != SORT_NONE) { 704 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_SORT_TARGETS, fSortDirection); 705 } else { 706 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_SORT_TARGETS, (String )null); 707 } 708 709 if (fOrderedTargets.size() == 1) { 710 AntTargetNode item = (AntTargetNode)fOrderedTargets.get(0); 711 if (item.isDefaultTarget()) { 712 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String )null); 713 return; 714 } 715 } else if (fOrderedTargets.size() == 0) { 716 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String )null); 717 return; 718 } 719 720 StringBuffer buff= new StringBuffer (); 721 Iterator iter = fOrderedTargets.iterator(); 722 String targets = null; 723 while (iter.hasNext()) { 724 AntTargetNode item = (AntTargetNode)iter.next(); 725 buff.append(item.getTargetName()); 726 buff.append(','); 727 } 728 if (buff.length() > 0) { 729 targets= buff.toString(); 730 } 731 732 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, targets); 733 } 734 735 738 public String getName() { 739 return AntLaunchConfigurationMessages.AntTargetsTab_Tar_gets_14; 740 } 741 742 745 public Image getImage() { 746 return AntUIImages.getImage(IAntUIConstants.IMG_TAB_ANT_TARGETS); 747 } 748 749 752 public boolean isValid(ILaunchConfiguration launchConfig) { 753 if (fAllTargets == null || isDirty()) { 754 if (getErrorMessage() != null && !isDirty()) { 755 return false; 757 } 758 initializeFrom(launchConfig); 760 if (getErrorMessage() != null) { 761 return false; 763 } 764 } 765 766 setErrorMessage(null); 767 return super.isValid(launchConfig); 768 } 769 770 773 protected void setDirty(boolean dirty) { 774 super.setDirty(dirty); 776 } 777 778 781 public void activated(ILaunchConfigurationWorkingCopy workingCopy) { 782 if (isDirty()) { 783 super.activated(workingCopy); 784 } 785 } 786 787 790 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { 791 if (fOrderedTargets.size() == 0) { 792 setDirty(true); 794 } 795 } 796 797 private String validateLocation() { 798 String expandedLocation= null; 799 String location= null; 800 IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); 801 try { 802 location= fLaunchConfiguration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String )null); 803 if (location == null) { 804 return null; 805 } 806 807 expandedLocation= manager.performStringSubstitution(location); 808 if (expandedLocation == null) { 809 return null; 810 } 811 File file = new File (expandedLocation); 812 if (!file.exists()) { 813 setErrorMessage(AntLaunchConfigurationMessages.AntTargetsTab_15); 814 return null; 815 } 816 if (!file.isFile()) { 817 setErrorMessage(AntLaunchConfigurationMessages.AntTargetsTab_16); 818 return null; 819 } 820 821 return expandedLocation; 822 823 } catch (CoreException e1) { 824 if (location != null) { 825 try { 826 manager.validateStringVariables(location); 827 setMessage(AntLaunchConfigurationMessages.AntTargetsTab_17); 828 return null; 829 } catch (CoreException e2) { setErrorMessage(e2.getStatus().getMessage()); 831 return null; 832 } 833 } 834 835 setErrorMessage(e1.getStatus().getMessage()); 836 return null; 837 } 838 } 839 840 protected boolean isTargetSelected() { 841 return !fOrderedTargets.isEmpty(); 842 } 843 } 844 | Popular Tags |