Exemplo n.º 1
0
  /**
   * @param files
   * @param lastFileAsScript if true, does not install the last arg as a resource to load, but as a
   *     script to launch
   * @return
   */
  public static String getProgramArguments(
      IProject project, IFile[] files, boolean lastFileAsScript) {
    StringBuilder args = new StringBuilder();

    int lastIndex = lastFileAsScript ? files.length - 1 : files.length;

    for (int i = 0; i < lastIndex; i++) {
      String fileArg = fileArg(project, files[i]);
      if (!StringUtils.isEmpty(fileArg)) {
        args.append(" -i" + fileArg);
      }
    }
    if (lastFileAsScript) {
      args.append(fileArg(project, files[lastIndex]));
    }
    return args.toString();
  }
Exemplo n.º 2
0
  /** @see org.eclipse.jface.wizard.IWizard#performFinish() */
  public boolean performFinish() {
    IContainer dest = dest();
    if (dest == null) {
      mainPage.setErrorMessage("Must select an existing destination folder.");
      return false;
    }
    String name = name();
    String suffix = suffix();
    if (name.length() == 0) {
      mainPage.setErrorMessage("Empty file name.");
      return false;
    }
    if (!Character.isJavaIdentifierStart(name.charAt(0))) {
      mainPage.setErrorMessage(
          "Invalid character \'"
              + name.charAt(0)
              + "\' at index "
              + 0
              + " for Clojure namespace file \'"
              + name
              + "'");
      return false;
    }
    for (int i = 1; i < name.length(); i++)
      if (!Character.isJavaIdentifierPart(name.charAt(i))) {
        mainPage.setErrorMessage(
            "Invalid character \'"
                + name.charAt(i)
                + "\' at index "
                + i
                + " for Clojure namespace file \'"
                + name
                + "'");
        return false;
      }

    // check if file already exists.
    IFile file;
    if (mainPage.dest instanceof IProject) {
      file = ((IProject) mainPage.dest).getFile(name + suffix);
    } else if (mainPage.dest instanceof IFolder) {
      file = ((IFolder) mainPage.dest).getFile(name + suffix);
    } else {
      return false;
    }

    if (file.exists()) {
      mainPage.setErrorMessage("File " + file.getName() + " already exists.");
      return false;
    }

    try {
      String namespace =
          ((StringUtils.isEmpty(mainPage.packageName) ? "" : mainPage.packageName + ".") + name)
              .replaceAll("_", "-");
      String contents = "(ns " + namespace + ")\n\n";
      file.create(new StringBufferInputStream(contents), true, null);
      IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
      if (dw != null) {
        IWorkbenchPage page = dw.getActivePage();
        if (page != null) {
          TextEditor editor = (TextEditor) IDE.openEditor(page, file, true);
          editor.selectAndReveal(contents.length(), 0);
        }
      }
    } catch (CoreException e) {
      CCWPlugin.logError(e);
      return false;
    }

    return true;
  }