protected IResource[] checkOverwriteOfDirtyResources(
      IResource[] resources, IProgressMonitor monitor) throws CVSException, InterruptedException {
    List dirtyResources = new ArrayList();
    IResource[] selectedResources = getSelectedResources();

    try {
      monitor = Policy.monitorFor(monitor);
      monitor.beginTask(null, selectedResources.length * 100);
      monitor.setTaskName(CVSUIMessages.ReplaceWithAction_calculatingDirtyResources);
      for (int i = 0; i < selectedResources.length; i++) {
        IResource resource = selectedResources[i];
        ICVSResource cvsResource = getCVSResourceFor(resource);
        if (cvsResource.isModified(Policy.subMonitorFor(monitor, 100))) {
          dirtyResources.add(resource);
        }
      }
    } finally {
      monitor.done();
    }

    PromptingDialog dialog =
        new PromptingDialog(
            getShell(),
            selectedResources,
            getPromptCondition(
                (IResource[]) dirtyResources.toArray(new IResource[dirtyResources.size()])),
            CVSUIMessages.ReplaceWithAction_confirmOverwrite);
    return dialog.promptForMultiple();
  }
Exemple #2
0
 /**
  * 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)) {
     throwCoreException("Container \"" + containerName + "\" does not exist.");
   }
   IContainer container = (IContainer) resource;
   final IFile file = container.getFile(new Path(fileName));
   try {
     InputStream stream = openContentStream();
     if (file.exists()) {
       file.setContents(stream, true, true, monitor);
     } else {
       file.create(stream, 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, true);
               } catch (PartInitException e) {
               }
             }
           });
   monitor.worked(1);
 }