Java Code Examples for org.eclipse.core.runtime.SubMonitor#isCanceled()

The following examples show how to use org.eclipse.core.runtime.SubMonitor#isCanceled() . 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: CodewindConnectionManager.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void createConnection(ConnectionInfo info, boolean connect, IProgressMonitor monitor) throws Exception {
	SubMonitor mon = SubMonitor.convert(monitor, 100);
	URI uri = new URI(info.getURL());
	AuthToken auth = null;
	try {
		auth = AuthUtil.getAuthToken(info.getUsername(), info.getId(), mon.split(20));
	} catch (Exception e) {
		Logger.logError("An error occurred trying to get the authorization token for: " + info.getId(), e); //$NON-NLS-1$
	}
	if (mon.isCanceled()) {
		return;
	}
	CodewindConnection conn = CodewindObjectFactory.createRemoteConnection(info.getLabel(), uri, info.getId(), info.getUsername(), auth);
	connections.add(conn);
	if (connect && auth != null) {
		conn.connect(mon.split(80));
		if (conn.isConnected()) {
			// Refresh again to make sure no incorrect project link errors
			conn.refreshApps(null);
		}
	}
}
 
Example 2
Source File: CodewindSocket.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
boolean blockUntilFirstConnection(IProgressMonitor monitor) {
	SubMonitor mon = SubMonitor.convert(monitor, 2500);
	final int delay = 100;
	final int timeout = 2500;
	int waited = 0;
	while(!hasConnected && waited < timeout) {
		mon.split(100);
		try {
			Thread.sleep(delay);
			waited += delay;

			if (waited % (5 * delay) == 0) {
				Logger.log("Waiting for CodewindSocket initial connection"); //$NON-NLS-1$
			}
		}
		catch(InterruptedException e) {
			Logger.logError(e);
		}
		if (mon.isCanceled()) {
			return false;
		}
	}
	Logger.log("CodewindSocket initialized in time ? " + hasConnected); //$NON-NLS-1$
	return hasConnected;
}
 
Example 3
Source File: ReferenceFinder.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void findReferences(
		TargetURIs targetURIs,
		Set<URI> candidates,
		IResourceAccess resourceAccess,
		IResourceDescriptions descriptions,
		Acceptor acceptor,
		IProgressMonitor monitor) {
	if (!targetURIs.isEmpty() && !candidates.isEmpty()) {
		SubMonitor subMonitor = SubMonitor.convert(monitor, targetURIs.size() / MONITOR_CHUNK_SIZE + 1);
		IProgressMonitor useMe = subMonitor.newChild(1);
		int i = 0;
		for (URI candidate : candidates) {
			if (subMonitor.isCanceled())
				throw new OperationCanceledException();
			IReferenceFinder languageSpecific = getLanguageSpecificReferenceFinder(candidate);
			doFindReferencesWith(languageSpecific, targetURIs, candidate, resourceAccess, descriptions, acceptor, useMe);
			i++;
			if (i % MONITOR_CHUNK_SIZE == 0) {
				useMe = subMonitor.newChild(1);
			}
		}
	}
}
 
Example 4
Source File: IDETypeScriptProject.java    From typescript.java with MIT License 6 votes vote down vote up
/**
 * Compile ts files list with tsserver.
 * 
 * @param tsFilesToCompile
 * @param client
 * @param subMonitor
 * @throws Exception
 */
private void compileTsFiles(List<String> tsFilesToCompile, ITypeScriptServiceClient client, SubMonitor subMonitor)
		throws Exception {
	SubMonitor loopMonitor = subMonitor.newChild(50).setWorkRemaining(tsFilesToCompile.size());// subMonitor.split(50).setWorkRemaining(tsFilesToCompile.size());
	loopMonitor.subTask(TypeScriptCoreMessages.IDETypeScriptProject_compile_compiling_step);
	for (String filename : tsFilesToCompile) {
		try {
			if (loopMonitor.isCanceled()) {
				throw new OperationCanceledException();
			}
			loopMonitor.subTask(
					NLS.bind(TypeScriptCoreMessages.IDETypeScriptProject_compile_compiling_file, filename));
			compileTsFile(filename, client);
			loopMonitor.worked(1);
			// loopMonitor.split(1);
		} catch (ExecutionException e) {
			if (e.getCause() instanceof TypeScriptNoContentAvailableException) {
				// Ignore "No content available" error.
			} else {
				throw e;
			}
		}
	}
	// subMonitor.setWorkRemaining(100);
}
 
Example 5
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a visitor that is used to traverse the information that is obtained from {@link #getDelta(IProject)}. It
 * accumulates its findings in the given <code>toBeBuilt</code>.
 */
protected IResourceDeltaVisitor createDeltaVisitor(ToBeBuiltComputer toBeBuiltComputer, ToBeBuilt toBeBuilt,
		final SubMonitor progress) {
	IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
		@Override
		public boolean visit(IResourceDelta delta) throws CoreException {
			if (progress.isCanceled())
				throw new OperationCanceledException();
			if (delta.getResource() instanceof IProject) {
				return true;
			}
			if (delta.getResource() instanceof IStorage) {
				if (delta.getKind() == IResourceDelta.REMOVED) {
					return toBeBuiltComputer.removeStorage(null, toBeBuilt, (IStorage) delta.getResource());
				} else if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) {
					return toBeBuiltComputer.updateStorage(null, toBeBuilt, (IStorage) delta.getResource());
				}
			}
			return true;
		}
	};
	return visitor;
}
 
Example 6
Source File: SyncUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void doReconcileAndBuild(final boolean saveAll, IProgressMonitor monitor)
		throws InterruptedException {
	try {
		SubMonitor progress = SubMonitor.convert(monitor, 6);
		reconcileAllEditors(workbench, saveAll, progress.newChild(1));
		if (progress.isCanceled()) {
			throw new InterruptedException();
		}
		waitForBuild(progress.newChild(4));
		if (progress.isCanceled()) {
			throw new InterruptedException();
		}
		yieldToQueuedDisplayJobs(progress.newChild(1));
	} catch(OperationCanceledException e) {
		throw new InterruptedException(); 
	}
}
 
Example 7
Source File: StartRuntimeProgress.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
@Override
public void run(IProgressMonitor parentMonitor) throws InvocationTargetException, InterruptedException {
    SubMonitor subMonitor = SubMonitor.convert(parentMonitor, 100);
    subMonitor.setTaskName(RunContainerMessages.getString("StartRuntimeAction.Starting")); //$NON-NLS-1$
    if (!checkRunning()) {
        try {
            IPreferenceStore store = ESBRunContainerPlugin.getDefault().getPreferenceStore();
            Process proc = RuntimeServerController.getInstance().startLocalRuntimeServer(
                    store.getString(RunContainerPreferenceInitializer.P_ESB_RUNTIME_LOCATION));
            int i = 0;
            String dot = "."; //$NON-NLS-1$
            while (JMXUtil.createJMXconnection() == null && ++i < 101 && !subMonitor.isCanceled() && proc.isAlive()) {
                subMonitor.subTask(RunContainerMessages.getString("StartRuntimeAction.Try") + dot); //$NON-NLS-1$
                dot += "."; //$NON-NLS-1$
                subMonitor.worked(1);
                Thread.sleep(3000);
            }
            if (!proc.isAlive()) {
                RuntimeServerController.getInstance().stopLocalRuntimeServer();
                throw new InterruptedException(RunContainerMessages.getString("RunContainerPreferencePage.InitailzeDialog8",
                        proc.exitValue()));
            }
            if (JMXUtil.createJMXconnection() == null) {
                throw new InterruptedException(RunContainerMessages.getString("RunContainerPreferencePage.InitailzeDialog5"));
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
            throw new InvocationTargetException(e, e.getMessage());
        }
    }
    loadConsole();
}
 
Example 8
Source File: RegistryBuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void build(IBuildContext buildContext, IProgressMonitor monitor) throws CoreException {
	ImmutableList<IXtextBuilderParticipant> participants = getParticipants();
	if (participants.isEmpty())
		return;
	SubMonitor progress = SubMonitor.convert(monitor, participants.size());
	progress.subTask(Messages.RegistryBuilderParticipant_InvokingBuildParticipants);
	for (IXtextBuilderParticipant participant : participants) {
		if (progress.isCanceled())
			throw new OperationCanceledException();
		participant.build(buildContext, progress.split(1));
	}
	if (progress.isCanceled())
		throw new OperationCanceledException();
}
 
Example 9
Source File: JavaSearchHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void search(URI uri, IProgressMonitor monitor) {
	int numResources = Iterables.size(resourceDescriptions.getAllResourceDescriptions());
	SubMonitor subMonitor = SubMonitor.convert(monitor, numResources / 10);
	subMonitor.subTask("Find references in EMF resources");
	try {
		int i = 0;
		for (IResourceDescription resourceDescription : resourceDescriptions.getAllResourceDescriptions()) {
			URI resourceURI = resourceDescription.getURI();
			IResourceServiceProvider resourceServiceProvider = serviceProviderRegistry.getResourceServiceProvider(resourceURI);
			if(resourceServiceProvider != null) {
				IJavaSearchParticipation javaSearchParticipation = resourceServiceProvider
						.get(IJavaSearchParticipation.class);
				if(javaSearchParticipation == null || javaSearchParticipation.canContainJvmReferences(resourceURI))
					searchIn(uri, resourceDescription);
			}
			if (++i % 10 == 0) {
				if (subMonitor.isCanceled()) {
					return; // not throwing OperationCanceledException, as the client in JDT doesn't seem to handle it properly
				}
				subMonitor.worked(1);
			}
		}
		for(ResourceSet resourceSet: projectToResourceSet.values()) {
			resourceSet.getResources().clear();
			resourceSet.eAdapters().clear();
		}
	} finally {
		subMonitor.done();
	}
}
 
Example 10
Source File: UnifiedBuilder.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void buildFile(BuildContext context, List<IBuildParticipant> participants, IProgressMonitor monitor)
		throws CoreException
{
	if (CollectionsUtil.isEmpty(participants))
	{
		return;
	}

	SubMonitor sub = SubMonitor.convert(monitor, 2 * participants.size());
	for (IBuildParticipant participant : participants)
	{
		long startTime = System.nanoTime();
		participant.buildFile(context, sub.newChild(1));
		if (traceParticipantsEnabled)
		{
			double endTime = ((double) System.nanoTime() - startTime) / 1000000;
			IdeLog.logTrace(
					BuildPathCorePlugin.getDefault(),
					MessageFormat
							.format("Executed build participant ''{0}'' on ''{1}'' in {2} ms.", participant.getName(), context.getURI(), endTime), IDebugScopes.BUILDER_PARTICIPANTS); //$NON-NLS-1$
		}

		// stop building if it has been canceled
		if (sub.isCanceled())
		{
			break;
		}
	}
	updateMarkers(context, sub.newChild(participants.size()));
	sub.done();
}
 
Example 11
Source File: OccurrenceMarker.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
	final XtextEditor editor = initialEditor;
	final boolean isMarkOccurrences = initialIsMarkOccurrences;
	final ITextSelection selection = initialSelection;
	final SubMonitor progress = SubMonitor.convert(monitor, 2);
	if (!progress.isCanceled()) {
		final Map<Annotation, Position> annotations = (isMarkOccurrences) ? occurrenceComputer.createAnnotationMap(editor, selection,
				progress.newChild(1)) : Collections.<Annotation, Position>emptyMap();
		if (!progress.isCanceled()) {
			Display.getDefault().asyncExec(new Runnable() {
				@Override
				public void run() {
					if (!progress.isCanceled()) {
						final IAnnotationModel annotationModel = getAnnotationModel(editor);
						if (annotationModel instanceof IAnnotationModelExtension)
							((IAnnotationModelExtension) annotationModel).replaceAnnotations(
									getExistingOccurrenceAnnotations(annotationModel), annotations);
						else if(annotationModel != null)
							throw new IllegalStateException(
									"AnnotationModel does not implement IAnnotationModelExtension");  //$NON-NLS-1$
					}
				}
			});
			return Status.OK_STATUS;
		}
	}
	return Status.CANCEL_STATUS;
}
 
Example 12
Source File: CombinedJvmJdtRenameProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
	SubMonitor monitor = SubMonitor.convert(pm, jvmElements2jdtProcessors.size() + 1);
	CompositeChange compositeChange = new CompositeChange(getProcessorName());
	compositeChange.add(super.createChange(monitor.newChild(1)));
	for (JavaRenameProcessor processor : jvmElements2jdtProcessors.values()) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		compositeChange.add(processor.createChange(monitor.newChild(1)));
	}
	return compositeChange;
}
 
Example 13
Source File: JdtToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void updateProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) throws CoreException {
	SubMonitor progress = SubMonitor.convert(monitor, 2);
	if (progress.isCanceled()) {
		throw new OperationCanceledException();
	}
	if (!project.isAccessible())
		return;
	IJavaProject javaProject = JavaCore.create(project);
	if (javaProject.exists()) {
		IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
		progress.setWorkRemaining(roots.length);
		final Map<String, Long> updated = Maps.newHashMap();
		ProjectOrder orderedProjects = workspace.computeProjectOrder(workspace.getRoot().getProjects());
		for (final IPackageFragmentRoot root : roots) {
			if (progress.isCanceled())
				throw new OperationCanceledException();
			if (shouldHandle(root) && !isBuiltByUpstream(root, project, orderedProjects.projects)) {
				Map<URI, IStorage> rootData = jdtUriMapperExtension.getAllEntries(root);
				for (Map.Entry<URI, IStorage> e : rootData.entrySet())
					if (uriValidator.canBuild(e.getKey(), e.getValue())) {
						toBeBuilt.getToBeDeleted().add(e.getKey());
						toBeBuilt.getToBeUpdated().add(e.getKey());
					}
			}
			progress.worked(1);
		}
		synchronized (modificationStampCache) {
			modificationStampCache.projectToModificationStamp.putAll(updated);
		}
	}
}
 
Example 14
Source File: CodewindConnectionComposite.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IStatus updateConnection(IProgressMonitor monitor) {
	SubMonitor mon = SubMonitor.convert(monitor, 100);
	
	if (connection.isConnected()) {
		connection.disconnect();
	}
	try {
		ConnectionUtil.updateConnection(connection.getConid(), name, url, user, mon.split(20));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
		connection.setName(name);
		connection.setBaseURI(new URI(url));
		connection.setUsername(user);
		
		AuthToken token = AuthUtil.genAuthToken(user, pass, connection.getConid(), mon.split(30));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
		connection.setAuthToken(token);
		
		connection.connect(mon.split(50));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
	} catch (Exception e) {
		return new Status(IStatus.ERROR, CodewindUIPlugin.PLUGIN_ID, NLS.bind(Messages.CodewindConnectionUpdateError, name), e);
	} finally {
		ViewHelper.openCodewindExplorerView();
		CodewindUIPlugin.getUpdateHandler().updateConnection(connection);
	}
	
	return Status.OK_STATUS;
}
 
Example 15
Source File: TsvBuilder.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
void checkTsv(final Collection<IFile> files, IProgressMonitor monitor) throws CoreException {
	final SubMonitor subMonitor = SubMonitor.convert(monitor, files.size() * 5);
	final ItemsXmlValidator validator = getValidator();
	for (final IFile file : files) {
		if (subMonitor.isCanceled()) {
			throw new OperationCanceledException("TSV Check cancelled");
		}
		subMonitor.subTask("Checking typesystem: " + file.getFullPath());
		
		processResults(file, validator.analyze(file, subMonitor.newChild(4)), subMonitor.newChild(1));
		
	}
}
 
Example 16
Source File: StopRuntimeProgress.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
@Override
public void run(IProgressMonitor parentMonitor) throws InvocationTargetException, InterruptedException {
    SubMonitor subMonitor = SubMonitor.convert(parentMonitor, 10);
    subMonitor.setTaskName(RunContainerMessages.getString("HaltRuntimeAction.Stoping")); //$NON-NLS-1$
    if (checkRunning()) {
        if (RuntimeServerController.getInstance().isRunning()) {
            try {
                RuntimeServerController.getInstance().stopRuntimeServer();
                int i = 0;
                String dot = "."; //$NON-NLS-1$
                // JMXUtil.connectToRuntime() != null
                while (RuntimeServerController.getInstance().isRunning() && i < 11 && !subMonitor.isCanceled()) {
                    subMonitor.setTaskName(RunContainerMessages.getString("HaltRuntimeAction.Task") + dot); //$NON-NLS-1$
                    dot += "."; //$NON-NLS-1$
                    subMonitor.worked(1);
                    Thread.sleep(3000);
                }
                if (RuntimeServerController.getInstance().isRunning()) {
                    throw new InterruptedException("Stop runtime server failed, please try again or stop it manually.");
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
                e.printStackTrace();
                throw new InvocationTargetException(e);
            }
        }
    }
}
 
Example 17
Source File: AbstractFoldingComputer.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Compute and return the folding positions. In case a folding update should be avoided, the given monitor should be
 * canceled. The default implementation does not cancel the monitor, and in case it's needed, it should be handled
 * by a subclass.
 * 
 * @param monitor
 * @param parseNode
 * @return folding positions
 */
protected Map<ProjectionAnnotation, Position> getPositions(IProgressMonitor monitor, IParseNode parseNode)
{
	Map<ProjectionAnnotation, Position> newPositions = new HashMap<ProjectionAnnotation, Position>();
	IParseNode[] children = getChildren(parseNode);
	SubMonitor sub = SubMonitor.convert(monitor, 2 * children.length);
	for (IParseNode child : children)
	{
		if (sub.isCanceled())
		{
			return newPositions;
		}
		if (isFoldable(child))
		{
			int start = child.getStartingOffset();
			boolean add = true;
			int end = child.getEndingOffset() + 1;
			try
			{
				int line = getDocument().getLineOfOffset(start);
				// Don't bother adding multiple positions for the same starting line
				if (fLines != null && fLines.contains(line))
				{
					add = false;
				}
				else
				{
					// Don't set up folding for stuff starting and ending on same line
					int endLine = getDocument().getLineOfOffset(child.getEndingOffset());
					if (endLine == line)
					{
						add = false;
					}
					else
					{
						// When we can, use the end of the end line as the end offset, so it looks nicer in the
						// editor. Using getLineInformation excludes the line delimiter, so we use the methods that
						// include it!
						end = getDocument().getLineOffset(endLine) + getDocument().getLineLength(endLine);
						if (fLines != null)
						{
							fLines.add(line);
						}
					}
				}
			}
			catch (BadLocationException e)
			{
				// ignore
			}
			if (add)
			{
				end = Math.min(getDocument().getLength(), end);
				if (start <= end)
				{
					newPositions.put(initialReconcile ? new ProjectionAnnotation(isCollapsed(child))
							: new ProjectionAnnotation(), new Position(start, end - start));
				}
				else
				{
					IdeLog.logWarning(CommonEditorPlugin.getDefault(), MessageFormat.format(
							"Was unable to add folding position. Start: {0}, end: {1}", start, end)); //$NON-NLS-1$
				}
			}
		}
		if (traverseInto(child))
		{
			// Recurse into AST!
			newPositions.putAll(getPositions(sub.newChild(1), child));
		}
		sub.worked(1);
	}
	sub.done();
	return newPositions;
}
 
Example 18
Source File: UpdateManager.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
/**
 * Install selected features in to developer studio. Note: call
 * {@link #setSelectedFeaturesToInstall(List) setSelectedFeaturesToInstall}
 * first.
 * 
 * @param monitor
 */
public void installSelectedFeatures(IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_32, 2);

	URI[] repos = new URI[] { getDevStudioReleaseSite() };
	session = new ProvisioningSession(p2Agent);
	installOperation = new InstallOperation(session, selectedFeatures);
	installOperation.getProvisioningContext().setArtifactRepositories(repos);
	installOperation.getProvisioningContext().setMetadataRepositories(repos);
	IStatus status = installOperation.resolveModal(progress.newChild(1));
	if (status.getSeverity() == IStatus.CANCEL || progress.isCanceled()) {
		throw new OperationCanceledException();
	} else if (status.getSeverity() == IStatus.ERROR) {
		String message = status.getChildren()[0].getMessage();
		log.error(Messages.UpdateManager_33 + message);
		UpdateMetaFileReaderJob.promptUserError(message, Messages.UpdateManager_33);
	} else {
		ProvisioningJob provisioningJob = installOperation.getProvisioningJob(progress.newChild(1));
		if (provisioningJob != null) {
			provisioningJob.addJobChangeListener(new JobChangeAdapter() {
				@Override
				public void done(IJobChangeEvent arg0) {
					Display.getDefault().syncExec(new Runnable() {
						@Override
						public void run() {
							boolean restart = MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
									Messages.UpdateManager_34,
									Messages.UpdateManager_35 + Messages.UpdateManager_36);
							if (restart) {
								PlatformUI.getWorkbench().restart();
							}
						}
					});
				}
			});
			provisioningJob.schedule();
			Display.getDefault().syncExec(new Runnable() {
				@Override
				public void run() {
					try {
						PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
								.showView(IProgressConstants.PROGRESS_VIEW_ID);
					} catch (PartInitException e) {
						log.error(e);
					}
				}
			});
		} else {
			log.error(Messages.UpdateManager_37);
		}
	}
}
 
Example 19
Source File: RemoveIndexOfFilesOfProjectJob.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IStatus run(IProgressMonitor monitor)
{
	SubMonitor sub = SubMonitor.convert(monitor, files.size());
	if (sub.isCanceled())
	{
		return Status.CANCEL_STATUS;
	}
	if (!project.isAccessible() || getContainerURI() == null)
	{
		return Status.CANCEL_STATUS;
	}

	Index index = getIndex();
	if (index == null)
	{
		IdeLog.logError(IndexPlugin.getDefault(),
				MessageFormat.format("Index is null for container: {0}", getContainerURI())); //$NON-NLS-1$
		return Status.CANCEL_STATUS;
	}
	try
	{
		// Cleanup indices for files
		for (IFile file : files)
		{
			if (monitor.isCanceled())
			{
				return Status.CANCEL_STATUS;
			}
			index.remove(file.getLocationURI());
			sub.worked(1);
		}
	}
	finally
	{
		try
		{
			index.save();
		}
		catch (IOException e)
		{
			IdeLog.logError(IndexPlugin.getDefault(), e);
		}
		sub.done();
	}
	return Status.OK_STATUS;
}
 
Example 20
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public synchronized IStatus runInUIThread(IProgressMonitor monitor)
{
	SubMonitor sub = SubMonitor.convert(monitor, 4);
	if (sub.isCanceled())
	{
		return Status.CANCEL_STATUS;
	}

	// manage being a part listener
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null && window.getActivePage() != null)
	{
		if (fIsPartListener && !applyToAllEditors() && !applyToViews())
		{
			window.getActivePage().removePartListener(this);
			fIsPartListener = false;
		}
		else if (!fIsPartListener)
		{
			window.getActivePage().addPartListener(this);
			fIsPartListener = true;
		}
	}

	if (sub.isCanceled())
	{
		return Status.CANCEL_STATUS;
	}
	sub.setWorkRemaining(3);

	// Apply to editors
	applyThemeToEclipseEditors(getCurrentTheme(), !applyToAllEditors(), sub.newChild(1));
	if (sub.isCanceled())
	{
		return Status.CANCEL_STATUS;
	}

	// Apply to consoles
	applyThemeToConsole(getCurrentTheme(), !applyToViews(), sub.newChild(1));
	if (sub.isCanceled())
	{
		return Status.CANCEL_STATUS;
	}

	// Apply to views
	hijackCurrentViews(window, !applyToViews(), sub.newChild(1));

	sub.done();
	return Status.OK_STATUS;
}