コード例 #1
0
  /**
   * Combined operation of creating make targets in Make Target View from multiline text. The method
   * will ask a confirmation if user tries to drop more then 1 target to prevent easily made mistake
   * of unintended copying of old contents of the clipboard.
   *
   * @param multilineText - input make target commands in textual form.
   * @param dropContainer - container where add the targets.
   * @param operation - operation such as copying or moving. Must be a {@link
   *     org.eclipse.swt.dnd.DND} operation.
   * @param shell - a shell to display progress of operation to user.
   * @see DND#DROP_NONE
   * @see DND#DROP_COPY
   * @see DND#DROP_MOVE
   * @see DND#DROP_LINK
   */
  public static void createMultilineTargetsUI(
      String multilineText, IContainer dropContainer, int operation, Shell shell) {

    IMakeTarget[] makeTargets = prepareMakeTargetsFromString(multilineText, dropContainer);
    boolean confirmed = true;
    if (makeTargets.length > 1) {
      String title =
          MakeUIPlugin.getResourceString(
              "MakeTargetDnD.title.createFromTextConfirm"); //$NON-NLS-1$
      String question =
          MessageFormat.format(
              MakeUIPlugin.getResourceString(
                  "MakeTargetDnD.message.createFromTextConfirm"), //$NON-NLS-1$
              new Object[] {new Integer(makeTargets.length)});

      String topTargets = ""; // $NON-NLS-1$
      for (int i = 0; i < makeTargets.length; i++) {
        // limit dimensions of the confirm dialog
        final int HEIGHT_LIMIT = 20;
        final int LENGTH_LIMIT = 200;
        if (i > HEIGHT_LIMIT) {
          topTargets = topTargets + "..."; // $NON-NLS-1$
          break;
        }
        String name = makeTargets[i].getName();
        if (name.length() > LENGTH_LIMIT) {
          name = name.substring(0, LENGTH_LIMIT - 3) + "..."; // $NON-NLS-1$
        }
        topTargets = topTargets + name + "\n"; // $NON-NLS-1$
      }

      confirmed = MessageDialog.openConfirm(shell, title, question + topTargets);
    }
    if (confirmed) {
      MakeTargetDndUtil.copyTargets(makeTargets, dropContainer, operation, shell);
    }
  }
コード例 #2
0
 /**
  * Creates make targets from array of filenames in Make Target View. Each file will be a separate
  * target in the view.
  *
  * @param filenames - array of filenames. Each filename expected to be an actual file otherwise a
  *     user gets a warning popup.
  * @param dropContainer - a container where the targets are being created.
  * @param operation - drop/paste operation.
  * @param shell - a shell to display warnings to the user.
  */
 public static void createFileTargetsUI(
     String[] filenames, IContainer dropContainer, int operation, Shell shell) {
   IMakeTarget[] makeTargets = prepareMakeTargetsFromFiles(filenames, dropContainer, shell);
   MakeTargetDndUtil.copyTargets(makeTargets, dropContainer, operation, shell);
 }