@Override
  public boolean performFinish() {

    IPath locationPath = new Path(page.getLocationURI().getPath());

    DartToolsPlugin.getDefault()
        .getDialogSettingsSection(NewApplicationCreationPage.NEW_APPPLICATION_SETTINGS)
        .put(
            NewApplicationCreationPage.PARENT_DIR,
            locationPath.removeLastSegments(1).toPortableString());

    if (isNestedByAnExistingProject(locationPath)) {
      createFolder(locationPath);
    } else {
      createNewProject();
    }

    if (newProject == null) {
      return false;
    }

    if (createdFile != null) {
      selectAndReveal(createdFile);

      try {
        IDE.openEditor(getWorkbench().getActiveWorkbenchWindow().getActivePage(), createdFile);
      } catch (PartInitException e) {
        DartToolsPlugin.log(e);
      }
    } else {
      selectAndReveal(newProject);
    }

    return true;
  }
  /**
   * Creates a new project resource with the selected name.
   *
   * <p>In normal usage, this method is invoked after the user has pressed Finish on the wizard; the
   * enablement of the Finish button implies that all controls on the pages currently contain valid
   * values.
   *
   * <p>Note that this wizard caches the new project once it has been successfully created;
   * subsequent invocations of this method will answer the same project resource without attempting
   * to create it again.
   *
   * @return the created project resource, or <code>null</code> if the project was not created
   */
  private IProject createNewProject() {
    if (newProject != null) {
      return newProject;
    }

    // get a project handle
    final String projectName = page.getProjectName();
    IProject projectHandle = page.getProjectHandle(projectName);
    if (projectHandle.exists()) {
      String newProjectName = ProjectUtils.generateUniqueNameFrom(projectName);
      projectHandle = page.getProjectHandle(newProjectName);
    }
    final AbstractSample sampleContent = page.getCurrentSample();
    final IProject newProjectHandle = projectHandle;
    // get a project descriptor
    URI location = page.getLocationURI();

    final IProjectDescription description = createProjectDescription(newProjectHandle, location);

    // create the new project operation
    IRunnableWithProgress op =
        new IRunnableWithProgress() {
          @Override
          public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op =
                new CreateProjectOperation(description, ResourceMessages.NewProject_windowTitle);
            try {
              IStatus status = op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));

              if (status.isOK()) {
                createdFile =
                    createProjectContent(newProjectHandle, null, projectName, sampleContent);
              }
            } catch (ExecutionException e) {
              throw new InvocationTargetException(e);
            } catch (CoreException e) {
              throw new InvocationTargetException(e);
            }
          }
        };

    try {
      getContainer().run(true, true, op);
    } catch (InterruptedException e) {
      return null;
    } catch (InvocationTargetException e) {
      Throwable t = e.getTargetException();
      if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
        CoreException cause = (CoreException) t.getCause();
        StatusAdapter status;
        if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
          status =
              new StatusAdapter(
                  StatusUtil.newStatus(
                      IStatus.WARNING,
                      NLS.bind(
                          ResourceMessages.NewProject_caseVariantExistsError,
                          newProjectHandle.getName()),
                      cause));
        } else {
          status =
              new StatusAdapter(
                  StatusUtil.newStatus(
                      cause.getStatus().getSeverity(),
                      ResourceMessages.NewProject_errorMessage,
                      cause));
        }
        status.setProperty(
            IStatusAdapterConstants.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage);
        StatusManager.getManager().handle(status, StatusManager.BLOCK);
      } else {
        StatusAdapter status =
            new StatusAdapter(
                new Status(
                    IStatus.WARNING,
                    IDEWorkbenchPlugin.IDE_WORKBENCH,
                    0,
                    NLS.bind(ResourceMessages.NewProject_internalError, t.getMessage()),
                    t));
        status.setProperty(
            IStatusAdapterConstants.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage);
        StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
      }
      return null;
    }

    newProject = newProjectHandle;

    return newProject;
  }