Exemplo n.º 1
0
  /**
   * Opens a project.
   *
   * @param directory Where the project is stored.
   * @return the BProject that describes the newly opened project or null if it cannot be opened.
   */
  public final BProject openProject(File directory) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    // Yes somebody may just call it with null, for fun..
    if (directory == null) return null;

    Project openProj = Project.openProject(directory.getAbsolutePath(), null);
    if (openProj == null) return null;

    // a hack, since bluej does not handle "opening" of projects correctly.
    // this code should really be into openProject or it should not be possible to open
    // a project is the initial package name is not there.
    Package pkg = openProj.getCachedPackage(openProj.getInitialPackageName());
    if (pkg == null) return null;

    // I make a new identifier out of this
    Identifier aProject = new Identifier(openProj, pkg);

    // This will make the frame if not already there. should not be needed...
    try {
      aProject.getPackageFrame();
    } catch (ExtensionException exc) {
    }

    // Note: the previous Identifier is not used here.
    return openProj.getBProject();
  }
Exemplo n.º 2
0
  /**
   * Returns all currently open projects. Returns an empty array if no projects are open.
   *
   * @return The openProjects value
   */
  public BProject[] getOpenProjects() {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    Collection projects = Project.getProjects();
    BProject[] result = new BProject[projects.size()];

    Iterator iter;
    int index;
    for (iter = projects.iterator(), index = 0; iter.hasNext(); index++) {
      Project prj = (Project) iter.next();
      result[index] = prj.getBProject();
    }

    return result;
  }
Exemplo n.º 3
0
  /**
   * Creates a new BlueJ project.
   *
   * @param directory where you want the project be placed, it must be writable.
   * @param projectType the type of project, such as ME or SE.
   * @return the newly created BProject if successful, null otherwise.
   */
  public BProject newProject(File directory, int projectType) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    String pathString = directory.getAbsolutePath();
    if (!pathString.endsWith(File.separator)) pathString += File.separator;

    if (!Project.createNewProject(pathString, projectType == ME_PROJECT)) return null;

    return openProject(directory);
  }