Ejemplo n.º 1
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);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Creating a copy of IMakeTarget in a different project.
   *
   * @param name - name of new target.
   * @param makeTarget - make target.
   * @param project - project where to assign the make target.
   * @return newly created make target.
   * @throws CoreException if there is a problem with creating or copying the target.
   */
  private static IMakeTarget cloneTarget(String name, IMakeTarget makeTarget, IProject project)
      throws CoreException {
    IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager();
    String[] ids = makeTargetManager.getTargetBuilders(project);
    String builderId = ids[0];

    IMakeTarget newMakeTarget = makeTargetManager.createTarget(project, name, builderId);
    copyTargetData(makeTarget, newMakeTarget);
    if (makeTarget
        .getName()
        .equals(makeTarget.getBuildAttribute(IMakeTarget.BUILD_TARGET, ""))) { // $NON-NLS-1$
      newMakeTarget.setBuildAttribute(IMakeTarget.BUILD_TARGET, name);
    }
    return newMakeTarget;
  }