/**
  * Utility method for refreshing the current view on all relevant input and output folders. This
  * makes sure, that methods determining and moving files get the current workspace contents.
  *
  * @param monitor progress monitor
  * @throws CoreException if an error occurs
  */
 private void refreshView(IProgressMonitor monitor) throws CoreException {
   sourceDir.refreshLocal(IProject.DEPTH_INFINITE, monitor);
   if (outputDir != null
       && !sourceDir.getProjectRelativePath().isPrefixOf(outputDir.getProjectRelativePath())) {
     outputDir.refreshLocal(IProject.DEPTH_ONE, monitor);
   }
   if (tempDir != null
       && !sourceDir.getProjectRelativePath().isPrefixOf(tempDir.getProjectRelativePath())) {
     tempDir.refreshLocal(IProject.DEPTH_INFINITE, monitor);
   }
   if (!sourceDir.getLocation().equals(project.getLocation())) {
     project.refreshLocal(IProject.DEPTH_ONE, monitor);
   }
 }
  /**
   * get a string status indicator for the modelName status label, given the modelName
   *
   * @param modelName the model name to test
   * @return the status of the supplied model name
   */
  private String getModelNameStatus(String sModelName) {
    // Check for null or zero-length
    if (sModelName == null || sModelName.length() == 0) {
      return MODEL_CREATE_ERROR_NO_NAME;
      // Check for valid model name
    }
    String fileNameMessage = ModelUtilities.validateModelName(sModelName, FILE_EXT);
    if (fileNameMessage != null) {
      return MODEL_CREATE_ERROR_INVALID_NAME;
    }
    // Check if already exists
    String sFileName = getFileName(sModelName);
    IPath modelFullPath = null;
    IPath modelRelativePath = null;

    if (newModelParent != null) {
      modelFullPath = newModelParent.getFullPath().append(sFileName);
      modelRelativePath = newModelParent.getProjectRelativePath().append(sFileName);
    }

    if (newModelParent != null && newModelParent.getProject().exists(modelRelativePath)) {
      return MODEL_CREATE_ERROR_ALREADY_EXISTS;
    }

    if (targetFilePath != null && targetFilePath.equals(modelFullPath)) {
      return MODEL_CREATE_ERROR_SAME_NAME_AS;
    }

    // success
    return MODEL_CREATE_ERROR_IS_VALID;
  }
  /**
   * test whether the supplied modelName is valid
   *
   * @param modelName the model name to test
   * @return 'true' if the name is valid, 'false' if not.
   */
  private boolean isValidModelName(String sModelName) {

    // Check for null or zero-length
    if (sModelName == null || sModelName.length() == 0) {
      return false;
    }
    // Check for valid model name
    String fileNameMessage = ModelUtilities.validateModelName(sModelName, FILE_EXT);
    if (fileNameMessage != null) {
      return false;
    }

    // Check if already exists
    String sFileName = getFileName(sModelName);
    IPath modelFullPath = null;
    IPath modelRelativePath = null;
    if (newModelParent != null) {
      modelFullPath = newModelParent.getFullPath().append(sFileName);
      modelRelativePath = newModelParent.getProjectRelativePath().append(sFileName);
    }

    if (newModelParent != null && newModelParent.getProject().exists(modelRelativePath)) {
      return false;
    }

    // Check if it is the same path as the relational model being generated
    if (targetFilePath != null && targetFilePath.equals(modelFullPath)) {
      return false;
    }

    // success
    return true;
  }
示例#4
0
  @Override
  protected StructuredViewer createStructuredViewer(Composite parent, int style) {
    tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.BORDER);
    Table table = (Table) tableViewer.getControl();
    TableLayout layout = new TableLayout();

    layout.addColumnData(new ColumnWeightData(50));
    TableColumn tc = new TableColumn(table, SWT.NONE, 0);
    tc.setText(MakeUIPlugin.getResourceString("TargetListViewer.lable.target")); // $NON-NLS-1$

    layout.addColumnData(new ColumnWeightData(50));
    tc = new TableColumn(table, SWT.NONE, 1);
    tc.setText(MakeUIPlugin.getResourceString("TargetListViewer.lable.location")); // $NON-NLS-1$

    table.setLayout(layout);
    table.setHeaderVisible(true);

    tableViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {

          @Override
          public void selectionChanged(SelectionChangedEvent e) {
            TargetListViewerPart.this.selectionChanged((IStructuredSelection) e.getSelection());
          }
        });
    tableViewer.setContentProvider(new MakeContentProvider(recursive));
    tableViewer.addFilter(
        new ViewerFilter() {

          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return (element instanceof IMakeTarget);
          }
        });
    tableViewer.setLabelProvider(new MakeLabelProvider(fContainer.getProjectRelativePath()));
    tableViewer.setInput(fContainer);

    return tableViewer;
  }
 @Override
 public boolean visit(IResourceProxy proxy) throws CoreException {
   try {
     if (proxy.getType() != IResource.FOLDER && proxy.getType() != IResource.PROJECT) {
       return false;
     }
     IContainer container = (IContainer) proxy.requestResource();
     monitor.subTask(container.getProjectRelativePath().toString());
     QualifiedName qName =
         new QualifiedName("org.eclipse.cdt.make", "goals"); // $NON-NLS-1$ //$NON-NLS-2$
     String goal = container.getPersistentProperty(qName);
     if (goal != null) {
       goal = goal.trim();
       IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager();
       String[] builder = manager.getTargetBuilders(container.getProject());
       IMakeTarget target = manager.createTarget(container.getProject(), goal, builder[0]);
       target.setBuildAttribute(IMakeTarget.BUILD_TARGET, goal);
       manager.addTarget(container, target);
       container.setPersistentProperty(qName, null);
     }
     return true;
   } finally {
     if (--nextProgress <= 0) {
       // we have exhausted the current increment, so report progress
       monitor.worked(1);
       worked++;
       if (worked >= halfWay) {
         // we have passed the current halfway point, so double the
         // increment and reset the halfway point.
         currentIncrement *= 2;
         halfWay += (TOTAL_WORK - halfWay) / 2;
       }
       // reset the progress counter to another full increment
       nextProgress = currentIncrement;
     }
   }
 }
  /**
   * Moves a set of files from the source container to the destination. All files need to be inside
   * the source container or any of its subfolders. Existing folders are not removed, if left empty.
   * If source and destination container are identical, files are if applicable only marked as
   * derived.
   *
   * @param source source container
   * @param dest destination folder (can be null, for only marking files as derived)
   * @param nameSet set of file paths to move
   * @param markAsDerived mark files as derived after moving
   * @param force overwrite exiting files and create subfolders in destination folder, if necessary
   * @param monitor progress monitor
   * @return a new set of file paths in their new location. This only includes files which have
   *     actually been moved.
   * @throws CoreException if an error occurs
   */
  private Set<IPath> moveFiles(
      final IContainer source,
      final IContainer dest,
      final Set<IPath> nameSet,
      boolean markAsDerived,
      boolean force,
      IProgressMonitor monitor)
      throws CoreException {
    Set<IPath> newNames = new HashSet<IPath>();
    if (nameSet != null && !nameSet.isEmpty()) {
      IPath sourcePath = source.getProjectRelativePath();
      IPath destPath;
      if (dest != null) {
        destPath = dest.getProjectRelativePath();
      } else {
        destPath = sourcePath;
      }
      boolean moveFiles = !sourcePath.equals(destPath);
      int sourceSeg = sourcePath.segmentCount();
      // Sort paths for running through file system structure incrementally
      IPath[] sortedNames = nameSet.toArray(new IPath[0]);
      Arrays.sort(
          sortedNames,
          new Comparator<IPath>() {
            public int compare(IPath o1, IPath o2) {
              return o1.toString().compareTo(o2.toString());
            }
          });

      for (IPath filePath : sortedNames) {
        if (sourcePath.isPrefixOf(filePath)) {
          IFile currentFile = project.getFile(filePath);
          if (moveFiles) {
            // Generate new path
            IPath destFilePath = destPath.append(filePath.removeFirstSegments(sourceSeg));
            IFile destFile = project.getFile(destFilePath);
            if (currentFile.exists() && (force || !destFile.exists())) {
              // Retrieve destination parent folder
              IContainer destFolder = destFile.getParent();
              if (destFolder instanceof IFolder && !destFolder.exists() && force) {
                // Create destination folder if necessary
                ((IFolder) destFolder).create(true, true, monitor);
                if (markAsDerived) {
                  destFolder.setDerived(true);
                }
              }
              if (destFolder.exists()) {
                // Move file
                if (destFile.exists() && force) {
                  destFile.delete(true, monitor);
                }
                currentFile.move(destFile.getFullPath(), true, monitor);
                if (markAsDerived && destFile.exists()) {
                  destFile.setDerived(true);
                }
                // Store path for later reversal
                newNames.add(destFilePath);
              }
            }
          } else {
            if (markAsDerived && currentFile.exists()) {
              currentFile.setDerived(true);
            }
          }
          monitor.worked(1);
        }
      }
    }
    return newNames;
  }