private IResource createSourceResource(IResourceDelta delta) {
   IPath sourcePath = delta.getMovedFromPath();
   IResource resource = delta.getResource();
   IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
   switch (resource.getType()) {
     case IResource.PROJECT:
       return wsRoot.getProject(sourcePath.segment(0));
     case IResource.FOLDER:
       return wsRoot.getFolder(sourcePath);
     case IResource.FILE:
       return wsRoot.getFile(sourcePath);
   }
   return null;
 }
  /**
   * The worker method. It will find the container, create the file if missing or just replace its
   * contents, and open the editor on the newly created file.
   */
  private void doFinish(String containerName, String fileName, IProgressMonitor monitor)
      throws CoreException {
    // create a sample file
    monitor.beginTask("Creating " + fileName, 2);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(new Path(containerName));

    // if (!(resource.exists()) || !(resource instanceof IContainer)) {
    if (resource == null || !(resource.exists()) || !(resource instanceof IContainer)) {
      // throwCoreException("Container \"" + containerName +
      // "\" does not exist.");
      IProject datamapperProject = root.getProject(containerName);
      datamapperProject.create(null);
      datamapperProject.open(null);
      // datamapperProject.
    }
    IContainer container = (IContainer) resource;
    //
    //
    // final IFile file = container.getFile(new Path(fileName));
    // try {
    // InputStream stream = openContentStream();
    // if (file.exists()) {
    // // file.setContents(null, true, true, monitor);
    // } else {
    // file.create(null, true, monitor);
    //
    // }
    // stream.close();`
    // } catch (IOException e) {
    // }
    // monitor.worked(1);
    // monitor.setTaskName("Opening file for editing...");
    // getShell().getDisplay().asyncExec(new Runnable() {
    // public void run() {
    // IWorkbenchPage page =
    // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    // try {
    // IDE.openEditor(page, file);
    // } catch (PartInitException e) {
    // }
    // }
    // });
    // monitor.worked(1);
  }
Example #3
0
  /**
   * The worker method. It will create a new project, then create the appropriate Soar heirarchy and
   * files.
   */
  private void doFinish(String projectName, IProgressMonitor monitor) throws CoreException {

    monitor.beginTask("Creating " + projectName, 7);

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject newProject = root.getProject(projectName);

    // creation of the project
    if (newProject.exists()) {
      throwCoreException("Project \"" + projectName + "\" already exists");
    } else {

      newProject.create(monitor);
      newProject.open(monitor);

      try {

        IProjectDescription description = newProject.getDescription();
        String[] natures = description.getNatureIds();
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = SoarProjectNature.NATURE_ID;
        description.setNatureIds(newNatures);

        newProject.setDescription(description, IResource.FORCE, monitor);

        newProject.setPersistentProperty(DataMap.VERTEX_ID, "0");

      } catch (CoreException e) {
        e.printStackTrace();
      } // catch
    } // else

    monitor.worked(2);

    // Create the contents of the project's root directory
    IFolder folderAll = newProject.getFolder("all");
    if (!folderAll.exists()) {
      folderAll.create(true, true, monitor);
    } // if
    FileMarker.markResource(folderAll, "file");

    IFolder folderElaborations = newProject.getFolder("elaborations");
    if (!folderElaborations.exists()) {
      folderElaborations.create(true, true, monitor);
    } // if
    FileMarker.markResource(folderElaborations, "file");

    IFile file_firstload = newProject.getFile("_firstload.soar");
    if (!file_firstload.exists()) {
      file_firstload.create(
          Utility.getFileTemplate(file_firstload, "_firstload.soar"), true, monitor);
    } // if
    FileMarker.markResource(file_firstload, "file");

    IFile filedatamap = newProject.getFile("datamap.xdm");
    if (!filedatamap.exists()) {
      filedatamap.create(Utility.getFileTemplate(filedatamap, "datamap.xdm"), true, monitor);
    } // if

    monitor.worked(3);

    // Create the contents of the elaborations folder
    IFile file_all = folderElaborations.getFile("_all.soar");
    if (!file_all.exists()) {
      file_all.create(Utility.getFileTemplate(file_all, "_all.soar"), true, monitor);
    } // if
    FileMarker.markResource(file_all, "file");

    IFile filetopstate = folderElaborations.getFile("top-state.soar");
    if (!filetopstate.exists()) {
      filetopstate.create(Utility.getFileTemplate(filetopstate, "top-state.soar"), true, monitor);
    } // if
    FileMarker.markResource(filetopstate, "file");

    SourcingFile.createSourcingFile(newProject, monitor);

    newProject.close(monitor);
    newProject.open(monitor);

    monitor.worked(2);
    monitor.done();
  } // void doFinish(...)
  private void createProject(IFeatureModel model, IProgressMonitor monitor) throws CoreException {
    String name = model.getFeature().getId();

    IFeaturePlugin[] plugins = model.getFeature().getPlugins();
    for (int i = 0; i < plugins.length; i++) {
      if (name.equals(plugins[i].getId())) {
        name += "-feature"; // $NON-NLS-1$
        break;
      }
    }

    String task = NLS.bind(MDEUIMessages.FeatureImportWizard_operation_creating2, name);
    monitor.beginTask(task, 9);
    try {
      IProject project = fRoot.getProject(name);

      if (project.exists() || new File(project.getParent().getLocation().toFile(), name).exists()) {
        if (queryReplace(project)) {
          if (!project.exists()) project.create(new SubProgressMonitor(monitor, 1));
          project.delete(true, true, new SubProgressMonitor(monitor, 1));
          try {
            RepositoryProvider.unmap(project);
          } catch (TeamException e) {
          }
        } else {
          return;
        }
      } else {
        monitor.worked(1);
      }

      IProjectDescription description = MDEPlugin.getWorkspace().newProjectDescription(name);
      if (fTargetPath != null) description.setLocation(fTargetPath.append(name));

      project.create(description, new SubProgressMonitor(monitor, 1));
      if (!project.isOpen()) {
        project.open(null);
      }
      File featureDir = new File(model.getInstallLocation());

      importContent(
          featureDir,
          project.getFullPath(),
          FileSystemStructureProvider.INSTANCE,
          null,
          new SubProgressMonitor(monitor, 1));
      IFolder folder = project.getFolder("META-INF"); // $NON-NLS-1$
      if (folder.exists()) {
        folder.delete(true, null);
      }
      if (fBinary) {
        // Mark this project so that we can show image overlay
        // using the label decorator
        project.setPersistentProperty(
            MDECore.EXTERNAL_PROJECT_PROPERTY, MDECore.BINARY_PROJECT_VALUE);
      }
      createBuildProperties(project);
      setProjectNatures(project, model, monitor);
      if (project.hasNature(JavaCore.NATURE_ID)) setClasspath(project, model, monitor);

    } finally {
      monitor.done();
    }
  }