org.eclipse.core.resources.IResourceChangeEvent Java Examples

The following examples show how to use org.eclipse.core.resources.IResourceChangeEvent. 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: ImpexPageEditor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Closes all project files on project close.
 */
public void resourceChanged(final IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.PRE_CLOSE) {
		Display.getDefault().asyncExec(new Runnable() {
			public void run() {
				IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
				for (int i = 0; i < pages.length; i++) {
					if (((FileEditorInput) editor.getEditorInput()).getFile().getProject()
					                .equals(event.getResource())) {
						IEditorPart editorPart = pages[i].findEditor(editor.getEditorInput());
						pages[i].closeEditor(editorPart, true);
					}
				}
			}
		});
	}
}
 
Example #2
Source File: PlatformContentProvider.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if (viewer == null || delta == null)
		return;
	IResourceDelta[] deltas = delta.getAffectedChildren();
	for (int i = 0; i < deltas.length; i++) {
		if (deltas[i].findMember(new Path(PlatformConstants.DIR_PLATFORMS)) != null) {
			viewer.getControl().getDisplay().asyncExec(new Runnable() {
				@Override
				public void run() {
					viewer.refresh();
				}
			});
			return;
		}
	}
}
 
Example #3
Source File: DerbyServerUtils.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event){
   if(event.getType()==IResourceChangeEvent.PRE_CLOSE){
   	try{
   		if(event.getResource().getProject().isNatureEnabled(CommonNames.DERBY_NATURE)){
   			if(getRunning(event.getResource().getProject())){
   				stopDerbyServer(event.getResource().getProject());
   			}
   		}
   	}catch(SWTException swe){
   		//The SWTException is thrown during the Shell creation
   		//Logger.log("Exception shutting down "+swe,IStatus.ERROR);
   		//e.printStackTrace();
   	}catch(Exception e){
   		Logger.log("Exception shutting down "+e,IStatus.ERROR);
   	}
   }
}
 
Example #4
Source File: SharedResourcesManager.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/** This method is called from Eclipse when changes to resource are detected */
@Override
public void resourceChanged(IResourceChangeEvent event) {

  /*
   * FIXME this is REAL GARBAGE ! This is sometimes set by the
   * IncomingProjectNegotiation. So when it is set every change in an
   * already shared project is just SILENTLY IGNORED !!!
   */
  if (fileReplacementInProgressObservable.isReplacementInProgress()) return;

  if (pause) {
    logPauseWarning(event);
    return;
  }

  // Creations, deletions, modifications of files and folders.
  if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
    handlePostChange(event);
  } else {
    log.warn("cannot handle event type : " + event);
  }
}
 
Example #5
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void toggleResourceListener() {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	ISelectionService service = getSite().getWorkbenchWindow()
			.getSelectionService();
	if (listenToDotContent) {
		IWorkbenchPart activeEditor = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor();
		checkActiveEditorAndUpdateGraph(activeEditor);
		workspace.addResourceChangeListener(resourceChangeListener,
				IResourceChangeEvent.POST_BUILD
						| IResourceChangeEvent.POST_CHANGE);
		service.addSelectionListener(selectionChangeListener);
	} else {
		workspace.removeResourceChangeListener(resourceChangeListener);
		service.removeSelectionListener(selectionChangeListener);
	}
}
 
Example #6
Source File: ProjectFileChangeListener.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    try {
        if (event != null && event.getDelta() != null) {
            event.getDelta().accept(new IResourceDeltaVisitor() {

                @Override
                public boolean visit(IResourceDelta delta) throws CoreException {
                    IProject project = repository.getProject();
                    if (project.isAccessible()) {
                        IFile projectFile = project.getFile(".project");
                        final IResource resource = delta.getResource();
                        if (Objects.equals(resource, projectFile)) {
                            return checkVersion(project);
                        }
                    }
                    return true;
                }
            });
        }
    } catch (CoreException e) {
        BonitaStudioLog.error(e);
    }
}
 
Example #7
Source File: HierarchicalDataWorkspaceModelFactory.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the IHierarchicalDataModel. If one does not exists, this method
 * will create one and register a workspace listener.
 *
 * @return
 */
public static IHierarchicalDataModel getHierarchicalDataModel() {
	IHierarchicalDataModelGetFileModel getModel = new GetFileModelFactory();
	final HierarchicalDataModel model = new HierarchicalDataModel(getModel);

	IResourceChangeListener listener = new IResourceChangeListener() {

		@Override
		public void resourceChanged(IResourceChangeEvent event) {
			IResourceDelta delta = event.getDelta();
			if (delta != null) {
				try {
					delta.accept(new DeltaVisitor(model));
				} catch (CoreException e) {
					// our visitor does not throw CoreException
				}
			}
		}
	};
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	workspace.addResourceChangeListener(listener);

	return model;
}
 
Example #8
Source File: SendPingJob.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event)
{
	if (event.getType() == IResourceChangeEvent.PRE_DELETE)
	{
		// check if it is a studio project and then send the ping out
		try
		{
			IProject project = event.getResource().getProject();
			IProjectDescription description = project.getDescription();
			String[] natures = description.getNatureIds();
			if (!ArrayUtil.isEmpty(natures))
			{
				// just checking the primary nature
				String projectType = STUDIO_NATURE_MAP.get(natures[0]);
				if (!StringUtil.isEmpty(projectType))
				{
					sendProjectDeleteEvent(project, projectType);
				}
			}
		}
		catch (Exception e)
		{
			UsagePlugin.logError(e);
		}
	}
}
 
Example #9
Source File: DefaultResourceChangeToIssueProcessor.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ResourceDeltaToIssueResult process(IResourceChangeEvent event, Resource connectedResource,
		Multimap<String, SCTIssue> visibleIssues) {
	final IFile file = WorkspaceSynchronizer.getFile(connectedResource);
	if (file == null) {
	    return null;
	}
	final IResourceDelta deltaForFile = getDeltaForFile(event, file);
	if (deltaForFile == null) {
		return null;
	}
	currentIssues = HashMultimap.create(visibleIssues);
	changedIssuesElementIDs = Sets.newHashSet();
	
	if ((IResourceDelta.CHANGED == deltaForFile.getKind()) && ((deltaForFile.getFlags() & IResourceDelta.MARKERS) != 0)) {
		processMarkerDelta(deltaForFile);
	}
	return new ResourceDeltaToIssueResult(currentIssues,changedIssuesElementIDs);
}
 
Example #10
Source File: ApplicationWorkbenchWindowAdvisor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public void addWorkplaceListener(){
	   IWorkspace workspace = ResourcesPlugin.getWorkspace(); 
	   workspace.addResourceChangeListener(new IResourceChangeListener() {
		
		public void resourceChanged(IResourceChangeEvent event) {
			//刷新项目导航视图
			Display.getDefault().syncExec(new Runnable() {		
				public void run() {
					IViewPart findView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
							.findView("net.heartsome.cat.common.ui.navigator.view");
					if(null == findView){
						return ;
					}
					IAction refreshActionHandler = findView.getViewSite().getActionBars()
							.getGlobalActionHandler(ActionFactory.REFRESH.getId());
					if(null == refreshActionHandler){
						return;
					}
					refreshActionHandler.run();
				}
			});
		}
	});
}
 
Example #11
Source File: ProblemManager.java    From typescript.java with MIT License 6 votes vote down vote up
private void handleResourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if (delta == null) {
		return;
	}

	// Find resourced whose problems changed and report them to listeners
	Set<IResource> changedResources = new HashSet<>();
	try {
		delta.accept(new ProblemMarkerDeltaVisitor(changedResources));
	} catch (CoreException e) {
		TypeScriptCorePlugin.logError(e);
	}
	if (!changedResources.isEmpty()) {
		notifyListeners(Collections.unmodifiableSet(changedResources));
	}
}
 
Example #12
Source File: BundleMonitor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event)
{
	if (event.getType() == IResourceChangeEvent.PRE_DELETE)
	{
		handleProjectDeleteEvent((IProject) event.getResource());
	}
	else
	{
		try
		{
			event.getDelta().accept(this);
		}
		catch (CoreException e)
		{
			IdeLog.logError(ScriptingActivator.getDefault(),
					Messages.BundleMonitor_Error_Processing_Resource_Change, e);
		}
	}
}
 
Example #13
Source File: PlatformHolder.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
void workspaceChanged(IResourceChangeEvent event) {
	try {
		if (event.getType() == IResourceChangeEvent.PRE_DELETE || event.getType() == IResourceChangeEvent.PRE_CLOSE) {
			if (Platform.isPlatformProject((IProject)event.getResource())) {
				clear();
			}
		}
		else if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			event.getDelta().accept(new IResourceDeltaVisitor() {

				@Override
				public boolean visit(IResourceDelta delta) throws CoreException {
					if (delta.getKind() == IResourceDelta.ADDED
							&& delta.getResource().getType() == IResource.PROJECT) {
						projectAdded((IProject) delta.getResource());
					}
					return delta.getResource().getType() == IResource.ROOT;
				}

			});
		}
	} catch (CoreException e) {
		log.log(new Status(Status.ERROR, log.getBundle().getSymbolicName(), "Error when handling IResourceChangedEvent", e));
	}
}
 
Example #14
Source File: ProjectOpenedOrClosedListener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	if (workspace != null && workspace.isAutoBuilding()) {
		if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			try {
				final Set<IProject> toUpdate = findNewProjectsToBuild(event);
				scheduleBuildIfNecessary(toUpdate);
			} catch (CoreException e) {
				log.error(e.getMessage(), e);
			}
		} else if ((event.getType() == IResourceChangeEvent.PRE_CLOSE || event.getType() == IResourceChangeEvent.PRE_DELETE)) {
			if (event.getResource() instanceof IProject && (XtextProjectHelper.hasNature((IProject) event.getResource())
					|| event.getResource().isAccessible() && event.getResource().isHidden())) {
				scheduleRemoveProjectJob((IProject) event.getResource());
			}
		}
	}
}
 
Example #15
Source File: DerbyServerUtils.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event){
   if(event.getType()==IResourceChangeEvent.PRE_CLOSE){
   	try{
   		if(event.getResource().getProject().isNatureEnabled(CommonNames.DERBY_NATURE)){
   			if(getRunning(event.getResource().getProject())){
   				stopDerbyServer(event.getResource().getProject());
   			}
   		}
   	}catch(SWTException swe){
   		//The SWTException is thrown during the Shell creation
   		//Logger.log("Exception shutting down "+swe,IStatus.ERROR);
   		//e.printStackTrace();
   	}catch(Exception e){
   		Logger.log("Exception shutting down "+e,IStatus.ERROR);
   	}
   }
}
 
Example #16
Source File: ImageViewer.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	final IResourceDelta delta = event.getDelta().findMember(imageFile.getFullPath());
	if (delta != null) {
		// file deleted -- close the editor
		if (delta.getKind() == IResourceDelta.REMOVED) {
			final Runnable r = () -> getSite().getPage().closeEditor(ImageViewer.this, false);
			getSite().getShell().getDisplay().asyncExec(r);
		}
		// file changed -- reload image
		else if (delta.getKind() == IResourceDelta.CHANGED) {
			final int flags = delta.getFlags();
			if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.LOCAL_CHANGED) != 0) {
				startImageLoad();
			}
		}
	}
}
 
Example #17
Source File: CloseResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handles a resource changed event by updating the enablement if one of the selected projects is opened or closed.
 */
@Override
public synchronized void resourceChanged(final IResourceChangeEvent event) {
	// Warning: code duplicated in OpenResourceAction
	final List<? extends IResource> sel = getSelectedResources();
	// don't bother looking at delta if selection not applicable
	if (selectionIsOfType(IResource.PROJECT)) {
		final IResourceDelta delta = event.getDelta();
		if (delta != null) {
			final IResourceDelta[] projDeltas = delta.getAffectedChildren(IResourceDelta.CHANGED);
			for (final IResourceDelta projDelta : projDeltas) {
				if ((projDelta.getFlags() & IResourceDelta.OPEN) != 0) {
					if (sel.contains(projDelta.getResource())) {
						selectionChanged(getStructuredSelection());
						return;
					}
				}
			}
		}
	}
}
 
Example #18
Source File: StatusCacheManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {	
	flushCache = false;
	try {
           event.getDelta().accept(new IResourceDeltaVisitor() {
               public boolean visit(IResourceDelta delta) throws CoreException {
               	IResource resource = delta.getResource();
               	if (resource.getType()==IResource.PROJECT) {
               		IProject project = (IProject)resource;
					if (!project.isAccessible()) {
						return false; // i.e., closed project
					}
					if (SVNWorkspaceRoot.isManagedBySubclipse(project)) {
						flushCache = true;
					}
					return false; // No need to check deeper than project.
               	}
                   return true;
               }
           });			
    } catch (CoreException e) {
      SVNProviderPlugin.log(e.getStatus());
    }
	if (flushCache) {
		statusCache.flushPendingStatuses();
	}
}
 
Example #19
Source File: RestoreProjectListener.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta[] projectDeltas = event.getDelta().getAffectedChildren();
	for (IResourceDelta delta : projectDeltas) {
		if((delta.getResource().getType() == IResource.PROJECT) && 
			(delta.getKind() == IResourceDelta.CHANGED || delta.getKind() == IResourceDelta.ADDED) 
				&& (delta.getFlags() & IResourceDelta.OPEN) != 0){
			IProject project = delta.getResource().getProject();
			if(project.isOpen()){
				HybridProject hybridProject  = HybridProject.getHybridProject(project);
				if(hybridProject != null ) {
					RestoreProjectJob job = new RestoreProjectJob(project);
					ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(project);
					job.setRule(rule);
					job.schedule();
				}
			}
		}
	}
}
 
Example #20
Source File: CodewindResourceChangeListener.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();

	CodewindResourceDeltaVisitor visitor = new CodewindResourceDeltaVisitor();

	try {

		// If the delta is null (as happens with some events), just pass the empty array
		// list below.
		if (delta != null) {
			delta.accept(visitor);
		}

		parent.handleResourceChanges(visitor.getResult());

	} catch (CoreException e1) {
		// TODO: Log me.
		e1.printStackTrace();
	}

}
 
Example #21
Source File: PluginContentProvider.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if (viewer == null || delta == null)
		return;
	IResourceDelta[] deltas = delta.getAffectedChildren();
	for (int i = 0; i < deltas.length; i++) {
		if (deltas[i].findMember(new Path(PlatformConstants.DIR_PLUGINS)) != null) {
			viewer.getControl().getDisplay().asyncExec(new Runnable() {
				@Override
				public void run() {
					viewer.refresh();
				}
			});
			return;
		}
	}
}
 
Example #22
Source File: BeansEditor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * This is called during startup.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void init(IEditorSite site, IEditorInput editorInput) {
	setSite(site);
	setInputWithNotify(editorInput);
	setPartName(editorInput.getName());
	site.setSelectionProvider(this);
	site.getPage().addPartListener(partListener);
	ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
}
 
Example #23
Source File: MultiPageCSVEditor.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Closes all project files on project close.
 *
 * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
 */
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.PRE_CLOSE || event.getType() == IResourceChangeEvent.PRE_DELETE) {
		WorkbenchHelper.asyncRun(() -> {
			final IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
			for (final IWorkbenchPage page : pages) {
				if (((FileEditorInput) editor.getEditorInput()).getFile().getProject()
						.equals(event.getResource())) {
					final IEditorPart editorPart = page.findEditor(editor.getEditorInput());
					page.closeEditor(editorPart, true);
				}
			}
		});
	} else {

		final IResourceDelta delta = event.getDelta().findMember(getFileFor(getEditorInput()).getFullPath());
		if (delta != null) {
			// file deleted -- close the editor
			if (delta.getKind() == IResourceDelta.REMOVED) {
				final Runnable r = () -> getSite().getPage().closeEditor(MultiPageCSVEditor.this, false);
				getSite().getShell().getDisplay().asyncExec(r);
			}
			// file changed -- reload
			else if (delta.getKind() == IResourceDelta.CHANGED) {
				final int flags = delta.getFlags();
				if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.LOCAL_CHANGED) != 0) {
					WorkbenchHelper.asyncRun(() -> MultiPageCSVEditor.this.updateTableFromTextEditor());
				}
			}
		}

	}
}
 
Example #24
Source File: BibtexEntryView.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if (delta != null) {
		try {
			delta.accept(markerVisitor);
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
}
 
Example #25
Source File: TeamPrivateListener.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Listen for file modifications
 * 
 * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
 */
public void resourceChanged(IResourceChangeEvent event) {		
	try {
		event.getDelta().accept(new IResourceDeltaVisitor() {
			public boolean visit(IResourceDelta delta) throws CoreException {
				IResource resource = delta.getResource();
				int type = resource.getType();

				if(type==IResource.FOLDER) {
					if (delta.getKind() != IResourceDelta.ADDED)
						return true;
					if (provider.isAdminDirectory(resource.getName())) {
						if (handleSVNDir((IContainer)resource)) {
							return false;
						}
					}
					return true;
				}				
				else if (type==IResource.PROJECT) {
					IProject project = (IProject)resource;
					if (!project.isAccessible()) {
						return false;
					}
					if (!SVNWorkspaceRoot.isManagedBySubclipse(project)) {
						return false; // not a svn handled project
					}
				}
				return true;
			}
		});
	} catch (CoreException e) {
		SVNProviderPlugin.log(e.getStatus());
	}			
}
 
Example #26
Source File: JavaHotCodeReplaceProvider.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (event.getType() == IResourceChangeEvent.POST_BUILD) {
        ChangedClassFilesVisitor visitor = getChangedClassFiles(event);
        if (visitor != null) {
            List<IResource> resources = visitor.getChangedClassFiles();
            List<String> classNames = visitor.getQualifiedNamesList();
            synchronized (this) {
                deltaResources.addAll(resources);
                deltaClassNames.addAll(classNames);
            }
            publishEvent(HotCodeReplaceEvent.EventType.BUILD_COMPLETE, "Build completed.");
        }
    }
}
 
Example #27
Source File: ProblemMarkerManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event)
{
	Set<IResource> changedElements = new HashSet<IResource>();

	try
	{
		IResourceDelta delta = event.getDelta();
		if (delta != null)
			delta.accept(new ProjectErrorVisitor(changedElements));
	}
	catch (CoreException e)
	{
		IdeLog.logError(EditorEplPlugin.getDefault(),
				"Error updating the problem markers after a resource change", e); //$NON-NLS-1$
	}

	if (!changedElements.isEmpty())
	{
		boolean hasChanges = false;
		synchronized (this)
		{
			if (fResourcesWithMarkerChanges.isEmpty())
			{
				fResourcesWithMarkerChanges = changedElements;
				hasChanges = true;
			}
			else
			{
				hasChanges = fResourcesWithMarkerChanges.addAll(changedElements);
			}
		}
		if (hasChanges)
		{
			fireChanges();
		}
	}
}
 
Example #28
Source File: JavaHotCodeReplaceProvider.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void initialize(IDebugAdapterContext context, Map<String, Object> options) {
    if (DebugSettings.getCurrent().hotCodeReplace != DebugSettings.HotCodeReplace.NEVER) {
        // Listen to the built file events.
        ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD);
    }
    this.context = context;
    currentDebugSession = context.getDebugSession();
}
 
Example #29
Source File: OthersWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void init(WorkingSetModel model) {
	fWorkingSetModel= model;
	fResourceChangeListener= new ResourceChangeListener();
	ResourcesPlugin.getWorkspace().addResourceChangeListener(fResourceChangeListener, IResourceChangeEvent.POST_CHANGE);
	fWorkingSetListener= new WorkingSetListener();
	PlatformUI.getWorkbench().getWorkingSetManager().addPropertyChangeListener(fWorkingSetListener);
	fJavaElementChangeListener= new JavaElementChangeListener();
	JavaCore.addElementChangedListener(fJavaElementChangeListener, ElementChangedEvent.POST_CHANGE);
}
 
Example #30
Source File: FindBugs2Eclipse.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (event.getSource() instanceof IProject) {
        cleanClassClache((IProject) event.getSource());
    } else if (event.getResource() instanceof IProject) {
        cleanClassClache((IProject) event.getResource());
    } else if (event.getDelta() != null) {
        final Set<IProject> affectedProjects = new HashSet<>();
        final IResourceDelta delta = event.getDelta();
        try {
            delta.accept(new IResourceDeltaVisitor() {
                @Override
                public boolean visit(IResourceDelta d1) throws CoreException {
                    if (d1 == delta || d1.getFlags() == 0 || d1.getFlags() == IResourceDelta.MARKERS) {
                        return true;
                    }
                    IResource resource = d1.getResource();
                    if (resource instanceof IProject) {
                        affectedProjects.add((IProject) resource);
                        return false;
                    }
                    return true;
                }
            });
        } catch (CoreException e) {
            FindbugsPlugin.getDefault().logException(e, "Error traversing resource delta");
        }
        for (IProject iProject : affectedProjects) {
            cleanClassClache(iProject);
        }
    }
}