org.eclipse.ui.actions.WorkspaceModifyOperation Java Examples

The following examples show how to use org.eclipse.ui.actions.WorkspaceModifyOperation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KickStartNewProjectAction.java    From solidity-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IIntroSite site, Properties params) {
	WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
		@Override
		protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
			IProject project = createProject(monitor);
			createExample(project);
		}
	};
	try {
		PlatformUI.getWorkbench().getProgressService().run(true, true, op);
		final IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager();
		IIntroPart part = introManager.getIntro();
		introManager.closeIntro(part);
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IDE.openEditor(page, ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("hello-world/greeter.sol")));
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #2
Source File: Repository.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void rename(String newName) {
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, false,
                new WorkspaceModifyOperation() {

                    @Override
                    protected void execute(IProgressMonitor monitor)
                            throws CoreException, InvocationTargetException, InterruptedException {
                        closeAllEditors();
                        projectListeners.stream().forEach(l -> l.projectClosed(Repository.this, monitor));
                        disableBuild();
                        getProject().move(org.eclipse.core.runtime.Path.fromOSString(newName), true, monitor);
                        RepositoryManager.getInstance().setRepository(newName, monitor);
                    }
                });
    } catch (InvocationTargetException | InterruptedException e) {
        new BonitaErrorDialog(Display.getDefault().getActiveShell(), "Rename failed", e.getMessage(), e).open();
    }
}
 
Example #3
Source File: IDEOpenSampleReportAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void refreshReportProject( final IProject project )
{
	WorkspaceModifyOperation op = new WorkspaceModifyOperation( ) {

		protected void execute( IProgressMonitor monitor )
				throws CoreException
		{
			project.refreshLocal( IResource.DEPTH_INFINITE, monitor );
		}
	};

	try
	{
		new ProgressMonitorDialog( composite.getShell( ) ).run( false,
				true,
				op );
	}
	catch ( Exception e )
	{
		ExceptionUtil.handle( e );
	}
}
 
Example #4
Source File: WorkbenchTestHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create a file.
 * 
 * @param file the name of the file to create.
 * @param content the content of the file.
 * @return the file.
 * @throws Exception
 */
public IFile createFileImpl(IFile file, InputStream content) throws Exception {
	new WorkspaceModifyOperation() {
		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			create(file.getParent());
			file.delete(true, new NullProgressMonitor());
			file.create(content, true, new NullProgressMonitor());
		}

	}.run(new NullProgressMonitor());
	getFiles().add(file);
	return file;
}
 
Example #5
Source File: WorkbenchTestHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create a file.
 * 
 * @param fullFileName the name of the file to create.
 * @param content the content of the file.
 * @return the file.
 * @throws Exception
 */
public IFile createFileImpl(String fullFileName, String content) throws Exception {
	final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullFileName));
	new WorkspaceModifyOperation() {
		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			create(file.getParent());
			file.delete(true, new NullProgressMonitor());
			try (final InputStream is = new StringInputStream(content)) {
				file.create(is, true, new NullProgressMonitor());
			} catch (Exception exception) {
				//
			}
		}

	}.run(new NullProgressMonitor());
	getFiles().add(file);
	return file;
}
 
Example #6
Source File: WorkbenchTestHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create the container tree.
 *
 * @param container the container
 * @throws InvocationTargetException in case of error.
 * @throws InterruptedException in case of errir.
 */
public static void create(org.eclipse.core.resources.IContainer container)
		throws InvocationTargetException, InterruptedException {
	new WorkspaceModifyOperation() {

		@SuppressWarnings("synthetic-access")
		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			if (!container.exists()) {
				create(container.getParent());
				if (container instanceof IFolder) {
					((IFolder) container).create(true, true, new NullProgressMonitor());
				} else {
					IProject iProject = (IProject) container;
					createProject(iProject);
				}
			}
		}
	}.run(new NullProgressMonitor());
}
 
Example #7
Source File: RefreshAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
final protected IRunnableWithProgress createOperation(final IStatus[] errorStatus) {
	return new WorkspaceModifyOperation() {
		@Override
		public void execute(final IProgressMonitor monitor) {
			final Iterator<? extends IResource> resourcesEnum = resources.iterator();
			try {
				while (resourcesEnum.hasNext()) {
					try {
						final IResource resource = resourcesEnum.next();
						refreshResource(resource, null);
					} catch (final CoreException e) {}
					if (monitor.isCanceled()) { throw new OperationCanceledException(); }
				}
			} finally {
				monitor.done();
			}
		}
	};
}
 
Example #8
Source File: NewStatechartProjectWizard.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean createNewStatechart() {
	final DiagramCreationDesccription create = getDiagramDescription();

	IRunnableWithProgress op = new WorkspaceModifyOperation(null) {
		@Override
		protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException {
			diagram = new DiagramCreator().createDiagram(create, monitor);
		}
	};
	try {
		getContainer().run(false, true, op);
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
	return diagram != null;
}
 
Example #9
Source File: SGenNewFileWizard.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean performFinish() {
	IRunnableWithProgress op = new WorkspaceModifyOperation(null) {
		@Override
		protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException {
			ensureSCTNature(getProject(modelFilePage.getContainerFullPath()));
			Resource resource = createDefaultModel(modelFilePage.getURI());
			openModel(resource);
		}
	};
	try {
		getContainer().run(false, true, op);
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
	return true;
}
 
Example #10
Source File: UIResourceChangeRegistryTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testFolderChildren() {
  try {
    final IProject project = WorkbenchTestHelper.createPluginProject("foo");
    final String folderPath = "/foo/bar";
    this.resourceChangeRegistry.registerGetChildren(folderPath, this.uri);
    Assert.assertTrue(this.resourceChangeRegistry.getChildrenListeners().containsKey(folderPath));
    final IFolder folder = project.getFolder("bar");
    final WorkspaceModifyOperation _function = new WorkspaceModifyOperation() {
      @Override
      protected void execute(final IProgressMonitor it) throws CoreException, InvocationTargetException, InterruptedException {
        folder.create(true, true, null);
      }
    };
    this.modifyWorkspace(_function);
    Assert.assertFalse(this.resourceChangeRegistry.getChildrenListeners().containsKey(folderPath));
    Assert.assertEquals(1, this.resourceChangeRegistry.queuedURIs.size());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #11
Source File: UIResourceChangeRegistryTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testFolderExists() {
  try {
    final String folderPath = "/foo/bar";
    this.resourceChangeRegistry.registerExists(folderPath, this.uri);
    Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
    final IProject project = WorkbenchTestHelper.createPluginProject("foo");
    Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
    final IFolder folder = project.getFolder("bar");
    Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
    final WorkspaceModifyOperation _function = new WorkspaceModifyOperation() {
      @Override
      protected void execute(final IProgressMonitor it) throws CoreException, InvocationTargetException, InterruptedException {
        folder.create(true, true, null);
      }
    };
    this.modifyWorkspace(_function);
    Assert.assertFalse(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
    Assert.assertEquals(1, this.resourceChangeRegistry.queuedURIs.size());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #12
Source File: TestedWorkspace.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public <Result> Result run(IWorkspaceModifyOperationWithResult<? extends Result> op) {
	try {
		return new WorkspaceModifyOperation(op.getRule()) {
			Result result;
			@Override
			protected void execute(IProgressMonitor monitor) throws InvocationTargetException, CoreException, InterruptedException {
				this.result = op.compute(monitor);
			}
			protected Result getResult() throws InvocationTargetException, InterruptedException {
				run(monitor());
				return result;
			}
		}.getResult();
	} catch (InvocationTargetException | InterruptedException e) {
		return Exceptions.throwUncheckedException(e);
	}
}
 
Example #13
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private static void create(final IContainer container)
		throws CoreException, InvocationTargetException,
		InterruptedException {
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			if (!container.exists()) {
				create(container.getParent());
				if (container instanceof IFolder) {
					((IFolder) container).create(true, true, monitor());
				} else {
					IProject iProject = (IProject) container;
					createProject(iProject);
				}
			}
		}
	}.run(monitor());
}
 
Example #14
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static IFolder createFolder(IPath wsRelativePath) throws InvocationTargetException, InterruptedException {
	final IFolder folder = root().getFolder(wsRelativePath);
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			create(folder.getParent());
			folder.delete(true, monitor());
			folder.create(true, true, monitor());
		}

	}.run(monitor());
	return folder;
}
 
Example #15
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static IFile createFile(IPath wsRelativePath, final String s)
		throws CoreException, InvocationTargetException,
		InterruptedException {
	final IFile file = root().getFile(wsRelativePath);
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			create(file.getParent());
			file.delete(true, monitor());
			try (InputStream stream = new StringInputStream(s, file.getCharset(true))) {
				file.create(stream, true, monitor());
			} catch (IOException exc) {
				throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.xtext.ui.testing", exc.getMessage(), exc));
			}
		}

	}.run(monitor());
	return file;
}
 
Example #16
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static IFolder createFolder(IPath wsRelativePath) throws InvocationTargetException, InterruptedException {
	final IFolder folder = root().getFolder(wsRelativePath);
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			create(folder.getParent());
			folder.delete(true, monitor());
			folder.create(true, true, monitor());
		}

	}.run(monitor());
	return folder;
}
 
Example #17
Source File: Storage2UriMapperJavaImplTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testOnRemoveTwoProjects() {
  try {
    Assert.assertEquals(0, this.getCachedPackageFragmentRootData().size());
    final IJavaProject project = JavaProjectSetupUtil.createJavaProject("testProject");
    final IJavaProject project2 = JavaProjectSetupUtil.createJavaProject("testProject2");
    final int sizeBefore = this.getCachedPackageFragmentRootData().size();
    final IFile file = this.createJar(project);
    JavaProjectSetupUtil.addJarToClasspath(project, file);
    JavaProjectSetupUtil.addJarToClasspath(project2, file);
    this.assertBothProjects(sizeBefore);
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
      @Override
      protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
        project.getProject().delete(true, monitor);
        project2.getProject().delete(true, monitor);
      }
    };
    op.run(IResourcesSetupUtil.monitor());
    this.assertNonProjects();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #18
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void setReference(final IProject from, final IProject to)
		throws CoreException, InvocationTargetException,
		InterruptedException {
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			IProjectDescription projectDescription = from.getDescription();
			IProject[] projects = projectDescription
					.getReferencedProjects();
			IProject[] newProjects = new IProject[projects.length + 1];
			System.arraycopy(projects, 0, newProjects, 0, projects.length);
			newProjects[projects.length] = to;
			projectDescription.setReferencedProjects(newProjects);
			from.setDescription(projectDescription, monitor());
		}
	}.run(monitor());
}
 
Example #19
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private static void create(final IContainer container)
		throws CoreException, InvocationTargetException,
		InterruptedException {
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			if (!container.exists()) {
				create(container.getParent());
				if (container instanceof IFolder) {
					((IFolder) container).create(true, true, monitor());
				} else {
					IProject iProject = (IProject) container;
					createProject(iProject);
				}
			}
		}
	}.run(monitor());
}
 
Example #20
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void setReference(final IProject from, final IProject to)
		throws CoreException, InvocationTargetException,
		InterruptedException {
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			IProjectDescription projectDescription = from.getDescription();
			IProject[] projects = projectDescription
					.getReferencedProjects();
			IProject[] newProjects = new IProject[projects.length + 1];
			System.arraycopy(projects, 0, newProjects, 0, projects.length);
			newProjects[projects.length] = to;
			projectDescription.setReferencedProjects(newProjects);
			from.setDescription(projectDescription, monitor());
		}
	}.run(monitor());
}
 
Example #21
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static IFile createFile(IPath wsRelativePath, final String s)
		throws CoreException, InvocationTargetException,
		InterruptedException {
	final IFile file = root().getFile(wsRelativePath);
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			create(file.getParent());
			file.delete(true, monitor());
			try {
				file.create(new StringInputStream(s, file.getCharset(true)), true, monitor());
			} catch (UnsupportedEncodingException exc) {
				throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.xtext.junit4", exc.getMessage(), exc));
			}
		}

	}.run(monitor());
	return file;
}
 
Example #22
Source File: SetSvnPropertyAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void execute(final IAction action) throws InvocationTargetException, InterruptedException {
       if (action != null && !action.isEnabled()) { 
       	action.setEnabled(true);
       } 
       else {
       	if(getSelectedResources().length > 0) {
			run(new WorkspaceModifyOperation() {
				public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
					IResource resource = getSelectedResources()[0];
					ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
					SvnWizardSetPropertyPage setPropertyPage = new SvnWizardSetPropertyPage(svnResource);
					SvnWizard wizard = new SvnWizard(setPropertyPage);
				    SvnWizardDialog dialog = new SvnWizardDialog(getShell(), wizard);
				    wizard.setParentDialog(dialog);  
					if (dialog.open() != SvnWizardDialog.OK) return;
				
					try {
						if (setPropertyPage.getPropertyValue() != null) {
							svnResource.setSvnProperty(setPropertyPage.getPropertyName(), setPropertyPage.getPropertyValue(),setPropertyPage.getRecurse());
						} else {
							svnResource.setSvnProperty(setPropertyPage.getPropertyName(), setPropertyPage.getPropertyFile(),setPropertyPage.getRecurse());
						}
						SvnPropertiesView.refreshView();
					} catch (SVNException e) {
						throw new InvocationTargetException(e);
					}
				} 
			}, false /* cancelable */, PROGRESS_BUSYCURSOR);
       	}
       }
}
 
Example #23
Source File: SelectAllProjectExplorer_PluginUITest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/***/
@Before
public void setUp2() throws Exception {
	waitForIdleState();
	projectExplorer = (ProjectExplorer) EclipseUIUtils.showView(ProjectExplorer.VIEW_ID);
	UIUtils.waitForUiThread();
	assertNotNull("Cannot show Project Explorer.", projectExplorer);
	commonViewer = projectExplorer.getCommonViewer();
	assertFalse("Expected projects as top level elements in navigator.", broker.isWorkingSetTopLevel());
	assertNull(
			"Select working set drop down contribution was visible when projects are configured as top level elements.",
			getWorkingSetDropDownContribution());

	final Multimap<ProjectType, String> typeNamesMapping = HashMultimap.create();

	typeNamesMapping.putAll(LIBRARY, LIBRARY_PROJECTS);
	typeNamesMapping.putAll(TEST, TEST_PROJECTS);
	new WorkspaceModifyOperation() {
		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException, InterruptedException {
			for (final Entry<ProjectType, Collection<String>> entry : typeNamesMapping.asMap().entrySet()) {
				for (final String projectName : entry.getValue()) {
					createN4JSProject(projectName, entry.getKey());
				}
			}
			// Actually close "Closed*" projects
			closeProject("ClosedL2");
			closeProject("ClosedT2");
		}
	}.run(new NullProgressMonitor());

	// Wait for workbench to reflect project changes
	waitForIdleState();
	commonViewer.refresh();

	// Disable auto-building, as there is no real code to build involved
	wasAutobuilding = IResourcesSetupUtil.setAutobuild(false);
}
 
Example #24
Source File: UnlockAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    if (action != null && !action.isEnabled()) { 
    	action.setEnabled(true);
    } 
    else {
    	if (getSelectedResources() != null && getSelectedResources().length > 0) {
      final IResource[] resources = getSelectedResources(); 
      run(new WorkspaceModifyOperation() {
          protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
              try {
			Hashtable table = getProviderMapping(getSelectedResources());
			Set keySet = table.keySet();
			Iterator iterator = keySet.iterator();
			while (iterator.hasNext()) {
			    SVNTeamProvider provider = (SVNTeamProvider)iterator.next();
		    	UnlockResourcesCommand command = new UnlockResourcesCommand(provider.getSVNWorkspaceRoot(), resources, false);
		        command.run(Policy.subMonitorFor(monitor,1000));    					
			}
              } catch (TeamException e) {
			throw new InvocationTargetException(e);
		} finally {
			monitor.done();
		}
          }              
      }, true /* cancelable */, PROGRESS_DIALOG);        
    	}
    }
}
 
Example #25
Source File: LockAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    if (action != null && !action.isEnabled()) { 
    	action.setEnabled(true);
    } 
    else {
    	if (getSelectedResources() != null && getSelectedResources().length > 0) {
      final IResource[] resources = getSelectedResources();
      SvnWizardLockPage lockPage = new SvnWizardLockPage(resources);
      SvnWizard wizard = new SvnWizard(lockPage);
      SvnWizardDialog dialog = new SvnWizardDialog(getShell(), wizard);
      wizard.setParentDialog(dialog);
      if (dialog.open() == SvnWizardDialog.OK) {
          final String comment = lockPage.getComment();
          final boolean stealLock = lockPage.isStealLock();
          run(new WorkspaceModifyOperation() {
              protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
                  try {
  					Hashtable table = getProviderMapping(getSelectedResources());
  					Set keySet = table.keySet();
  					Iterator iterator = keySet.iterator();
  					while (iterator.hasNext()) {
  					    SVNTeamProvider provider = (SVNTeamProvider)iterator.next();
  				    	LockResourcesCommand command = new LockResourcesCommand(provider.getSVNWorkspaceRoot(), resources, stealLock, comment);
  				        command.run(Policy.subMonitorFor(monitor,1000));    					
  					}
                  } catch (TeamException e) {
  					throw new InvocationTargetException(e);
  				} finally {
  					monitor.done();
  				}
              }              
          }, true /* cancelable */, PROGRESS_DIALOG);
      }
    	}
    }
}
 
Example #26
Source File: AddAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void execute(IAction action) throws InterruptedException, InvocationTargetException {
	// first we ask the user if he really want to add the selected resources if some of them are marked as ignored
       if (!promptForAddOfIgnored()) { 
           return;
       }
	run(new WorkspaceModifyOperation() {
		public void execute(IProgressMonitor monitor) throws InvocationTargetException {
			try {
                   // associate the resources with their respective RepositoryProvider					
				Hashtable table = getProviderMapping(getSelectedResources());
				Set keySet = table.keySet();
				monitor.beginTask("", keySet.size() * 1000); //$NON-NLS-1$
				monitor.setTaskName(Policy.bind("AddAction.adding")); //$NON-NLS-1$
				Iterator iterator = keySet.iterator();
				while (iterator.hasNext()) {
					IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 1000);
					SVNTeamProvider provider = (SVNTeamProvider)iterator.next();
					List list = (List)table.get(provider);
					IResource[] providerResources = (IResource[])list.toArray(new IResource[list.size()]);
					provider.add(providerResources, IResource.DEPTH_INFINITE, subMonitor);
				}
			} catch (TeamException e) {
				throw new InvocationTargetException(e);
			} finally {
				monitor.done();
			}
		}
	}, true /* cancelable */, PROGRESS_DIALOG);

}
 
Example #27
Source File: MarkMergedSynchronizeOperation.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void run(SVNTeamProvider provider, SyncInfoSet set, final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    final IResource[] resources = set.getResources();
    run(new WorkspaceModifyOperation() {
        protected void execute(IProgressMonitor mon) throws CoreException, InvocationTargetException, InterruptedException {
           for (int i = 0; i < resources.length; i++) {
               File tempFile = null;
               try {
                   tempFile = copyToTempFile(resources[i]);
             } catch (Exception e) {
                 SVNUIPlugin.log(e.getMessage());
                 showErrorMessage(e);
                 return;
             }
             if (monitor.isCanceled()) {
             	if (tempFile != null) tempFile.delete();
             	return;
             }
                ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
	if (svnResource instanceof LocalResource) ((LocalResource)svnResource).revert(false);
	else svnResource.revert();
	new UpdateOperation(getPart(), resources[i], SVNRevision.HEAD).run(monitor);
	if (monitor.isCanceled()) {
		if (tempFile != null) tempFile.delete();
		return;
	}
	File file = new File(resources[i].getLocation().toString());
	try {
                    copy(tempFile, file);
                } catch (Exception e1) {
                    SVNUIPlugin.log(e1.getMessage());
                    showErrorMessage(e1);
                }
                if (tempFile != null) tempFile.delete();
           }
        }          
    }, true /* cancelable */, PROGRESS_BUSYCURSOR);
}
 
Example #28
Source File: FileTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
void handleDropMove() {
	final List<IResource> elements= getResources();
	if (elements == null || elements.size() == 0)
		return;

	WorkspaceModifyOperation op= new WorkspaceModifyOperation() {
		@Override
		public void execute(IProgressMonitor monitor) throws CoreException {
			try {
				monitor.beginTask(PackagesMessages.DragAdapter_deleting, elements.size());
				MultiStatus status= createMultiStatus();
				Iterator<IResource> iter= elements.iterator();
				while(iter.hasNext()) {
					IResource resource= iter.next();
					try {
						monitor.subTask(BasicElementLabels.getPathLabel(resource.getFullPath(), true));
						resource.delete(true, null);

					} catch (CoreException e) {
						status.add(e.getStatus());
					} finally {
						monitor.worked(1);
					}
				}
				if (!status.isOK()) {
					throw new CoreException(status);
				}
			} finally {
				monitor.done();
			}
		}
	};
	runOperation(op, true, false);
}
 
Example #29
Source File: FileTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void handleRefresh() {
	final Set<IResource> roots= collectRoots(getResources());

	WorkspaceModifyOperation op= new WorkspaceModifyOperation() {
		@Override
		public void execute(IProgressMonitor monitor) throws CoreException {
			try {
				monitor.beginTask(PackagesMessages.DragAdapter_refreshing, roots.size());
				MultiStatus status= createMultiStatus();
				Iterator<IResource> iter= roots.iterator();
				while (iter.hasNext()) {
					IResource r= iter.next();
					try {
						r.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(monitor, 1));
					} catch (CoreException e) {
						status.add(e.getStatus());
					}
				}
				if (!status.isOK()) {
					throw new CoreException(status);
				}
			} finally {
				monitor.done();
			}
		}
	};

	runOperation(op, true, false);
}
 
Example #30
Source File: RenameRefactoringIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void undoRename() throws Exception {
	IResourcesSetupUtil.waitForBuild();
	new WorkspaceModifyOperation() {
		@Override
		protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException,
				InterruptedException {
			undoChange.perform(monitor);
		}
	}.run(null);
}