public void overwriteTemplate(Template template) throws CoreException {
    try {
      // get the directory
      String projectName = folderSelected.getProject().getName();
      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      IProject project = root.getProject(projectName);
      IPath pathFolder = folderSelected.getProjectRelativePath();
      String templateFileName = template.getFileName();

      DataHandler dh = template.getContent();
      InputStream is = dh.getInputStream();

      IPath pathNewFile = pathFolder.append(templateFileName);
      IFile newFile = project.getFile(pathNewFile);

      // create new File
      if (newFile.exists()) {
        newFile.delete(true, null);
      }
      newFile.create(is, true, null);
      // set the dirty property to true
      newFile.setPersistentProperty(SpagoBIStudioConstants.DIRTY_MODEL, "true");

    } catch (IOException e1) {

      MessageDialog.openError(
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
          "Error",
          "Error in writing the file");
      logger.error("Error in writing the file", e1);

      return;
    }
  }
  /**
   * We will accept the selection in the workbench to see if we can initialize from it.
   *
   * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
   */
  public void init(IWorkbench _workbench, IStructuredSelection _selection) {
    this.selection = _selection;
    this.workbench = _workbench;

    Object objSel = selection.toList().get(0);
    Folder fileSelected = (Folder) objSel;
    projectName = fileSelected.getProject().getName();
    folderSelected = fileSelected;
  }
示例#3
0
 /**
  * scans the folders recursively and adds one entry (parent folder name -> .project) for every
  * .project file found
  *
  * @param workingSet2dotProjects the map of workings set names -> .project files
  * @param folders the folders to scan
  * @return the in-parameter workingSet2dotProjects
  */
 static Map<String, Set<IFile>> seekProjects(
     Map<String, Set<IFile>> workingSet2dotProjects, Folder... folders) throws Exception {
   for (Folder folder : folders) {
     addIfProject(folder, workingSet2dotProjects);
     for (IResource res : folder.members()) {
       if (res instanceof Folder) {
         seekProjects(workingSet2dotProjects, (Folder) res);
       }
     }
   }
   return workingSet2dotProjects;
 }
示例#4
0
 static void addIfProject(Folder folder, Map<String, Set<IFile>> workingSet2dotProjects) {
   IFile dotProject = folder.getFile(".project");
   if (dotProject.exists()) {
     workingSet2dotProjects.get(folder.getParent().getName()).add(dotProject);
   }
 }