示例#1
0
  @Override
  protected void buttonSelected(Button button, int index) {
    try {
      switch (index) {
        case ADD_TARGET:
          {
            MakeTargetDialog dialog = new MakeTargetDialog(getControl().getShell(), fContainer);
            dialog.open();
          }
          break;
        case REMOVE_TARGET:
          IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager();
          manager.removeTarget(
              (IMakeTarget) ((IStructuredSelection) getViewer().getSelection()).getFirstElement());
          break;
        case EDIT_TARGET:
          {
            MakeTargetDialog dialog =
                new MakeTargetDialog(
                    getControl().getShell(),
                    (IMakeTarget)
                        ((IStructuredSelection) getViewer().getSelection()).getFirstElement());
            dialog.open();
          }

          break;
      }
    } catch (CoreException e) {
      MakeUIPlugin.errorDialog(
          getControl().getShell(),
          MakeUIPlugin.getResourceString("TargetListViewer.exception.error"), // $NON-NLS-1$
          MakeUIPlugin.getResourceString("TargetListViewer.exception.message"), // $NON-NLS-1$
          e);
    }
  }
示例#2
0
  /**
   * Copy/move one make target to the specified container.
   *
   * @param makeTarget - make target.
   * @param container - container to copy/move to.
   * @param operation - copying operation. Should be one of {@link org.eclipse.swt.dnd.DND}
   *     operations.
   * @param shell - shell to display user warnings.
   * @param offerOverwriteDialog - whether overwrite dialog is provided.
   * @throws CoreException on the failure of {@link IMakeTargetManager} or {@link IMakeTarget}
   *     operation.
   * @see DND#DROP_NONE
   * @see DND#DROP_COPY
   * @see DND#DROP_MOVE
   * @see DND#DROP_LINK
   * @see DND#DROP_DEFAULT
   */
  public static void copyOneTarget(
      IMakeTarget makeTarget,
      IContainer container,
      final int operation,
      Shell shell,
      boolean offerOverwriteDialog)
      throws CoreException {

    IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager();
    IMakeTarget exists = makeTargetManager.findTarget(container, makeTarget.getName());
    if (exists != null) {
      int userAnswer = IDialogConstants.CANCEL_ID;
      if (offerOverwriteDialog) {
        userAnswer = overwriteMakeTargetDialog(makeTarget.getName(), shell);
      } else {
        userAnswer = RENAME_ID;
      }
      if (userAnswer == IDialogConstants.YES_ID || userAnswer == IDialogConstants.YES_TO_ALL_ID) {
        copyTargetData(makeTarget, exists);
        if (operation == DND.DROP_MOVE) {
          makeTargetManager.removeTarget(makeTarget);
        }
      } else if (userAnswer == RENAME_ID || userAnswer == RENAME_TO_ALL_ID) {
        String name = generateUniqueName(makeTarget.getName(), container);
        IMakeTarget newMakeTarget = cloneTarget(name, makeTarget, container.getProject());
        newMakeTarget.setContainer(container);
        int dialogReturnCode = Window.OK;
        if (userAnswer == RENAME_ID) {
          MakeTargetDialog dialog;
          try {
            dialog = new MakeTargetDialog(shell, newMakeTarget);
            dialogReturnCode = dialog.open();
          } catch (CoreException e) {
            MakeUIPlugin.errorDialog(
                shell,
                MakeUIPlugin.getResourceString("AddBuildTargetAction.exception.internal"),
                e.toString(),
                e); //$NON-NLS-1$
          }
        } else if (userAnswer == RENAME_TO_ALL_ID) {
          makeTargetManager.addTarget(container, newMakeTarget);
        }
        if (operation == DND.DROP_MOVE && dialogReturnCode != Window.CANCEL) {
          makeTargetManager.removeTarget(makeTarget);
        }
      }
    } else {
      makeTargetManager.addTarget(
          container, cloneTarget(makeTarget.getName(), makeTarget, container.getProject()));
      if (operation == DND.DROP_MOVE) {
        makeTargetManager.removeTarget(makeTarget);
      }
    }
  }