Java Code Examples for org.eclipse.core.resources.IResourceChangeEvent#getResource()

The following examples show how to use org.eclipse.core.resources.IResourceChangeEvent#getResource() . 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: 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 2
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private void handleCloseEvent(IResourceChangeEvent event) {
	if (event.getResource() instanceof IProject) {
		IProject project = ((IProject) event.getResource());
		for (IDebugTarget target : activeTargets) {
			EObject object = (EObject) target.getAdapter(EObject.class);
			IFile file = WorkspaceSynchronizer.getFile(object.eResource());
			if (project.equals(file.getProject())) {
				try {
					target.terminate();
				} catch (DebugException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
 
Example 3
Source File: ProjectChangeListener.java    From ADT_Frontend with MIT License 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	if (this.view != null && this.project != null) {
		IResource resource = event.getResource();
		if (resource instanceof IProject) {
			if (event.getType() == IResourceChangeEvent.PRE_DELETE || event.getType() == IResourceChangeEvent.PRE_CLOSE) {
				if (this.project.equals(resource)) {
					//reset the staging view to initial
					Display.getDefault().syncExec(() -> ProjectChangeListener.this.view.resetStagingView());
				}
			}
		}
	}
}
 
Example 4
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);
        }
    }
}
 
Example 5
Source File: WorkspaceSpecManager.java    From tlaplus with MIT License 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event)
{
    /*
     * remove elements from the storage if the projects are deleted
     */
    IResource resource = event.getResource();
    if (resource != null && IResource.PROJECT == resource.getType()
            && IResourceChangeEvent.PRE_DELETE == event.getType())
    {
        specStorage.remove(resource.getName());
    }

}
 
Example 6
Source File: ResourcesWatcher.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	try {
		IResource resource = event.getResource();
		switch (event.getType()) {
		case IResourceChangeEvent.PRE_DELETE:
			if (resource != null) {
				switch (resource.getType()) {
				case IResource.PROJECT:
					// called when project is deleted.
					deleteProject((IProject) resource);
					break;
				}
			}
			break;
		case IResourceChangeEvent.PRE_CLOSE:
			if (resource != null) {
				switch (resource.getType()) {
				case IResource.PROJECT:
					// called when project is closed.
					closeProject((IProject) resource);
					break;
				}
			}
			break;
		case IResourceChangeEvent.POST_CHANGE:
			IResourceDelta delta = event.getDelta();
			if (delta != null) {
				delta.accept(this);
			}
			break;
		}
	} catch (Throwable e) {
		Trace.trace(Trace.SEVERE, "Error while TypeScript resource changed", e);
	}
}
 
Example 7
Source File: BibtexEntryView.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handle deletion of resources (does only handle deletion of projects)
 * 
 * @param event
 */
private void handleResourceDeleteEvent(IResourceChangeEvent event) {
	IResource resource = event.getResource();
	if (!(resource instanceof IProject)) {
		return;
	}
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			IProject[] input = (IProject[]) combo.getInput();
			IStructuredSelection selection = combo.getStructuredSelection();

			// Deleted project is selected
			if (selection.getFirstElement() == resource) {
				if (input.length > 1) {
					int currentIndex = combo.getCombo().getSelectionIndex();
					Object newItem = combo.getElementAt(currentIndex + 1);
					if (newItem != null) {
						combo.setSelection(new StructuredSelection(newItem));
					} else {
						newItem = combo.getElementAt(currentIndex - 1);
						if (newItem != null) {
							combo.setSelection(new StructuredSelection(newItem));
						}
					}
				} else if (input.length == 1) {
					combo.setSelection(StructuredSelection.EMPTY);
				}
			}
			combo.remove(resource);
		}
	});
}
 
Example 8
Source File: WidgetModel.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
	IResource resource = event.getResource();
	if (resource instanceof IProject) {
		HybridProject prj = HybridProject.getHybridProject(resource.getProject());
		if (prj != null) {
			WidgetModel model = widgetModels.remove(prj);
			if (model != null) {
				model.dispose();
			}
		}
	}
}
 
Example 9
Source File: XdsResourceChangeListener.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
protected VisitResult doVisit(IResourceChangeEvent event) {
		final VisitResult visitResult = new VisitResult();
		IResourceDelta delta = event.getDelta();
        try {
            if (delta != null) { // it can be null for project removals
//            	printDelta(delta);
                beginDeltaProcessing(delta);
                delta.accept(new IResourceDeltaVisitor() {
                    @Override
                    public boolean visit(IResourceDelta childDelta) throws CoreException {
                        IResource affectedResource = childDelta.getResource();
                        if (!(affectedResource instanceof IWorkspaceRoot)) {
                            if (!NatureUtils.hasNature(affectedResource.getProject(), NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID)) {
                                return false; // DONT visit children of non-XDS nature project
                            }
                            
                            if (ResourceUtils.isInsideFolder(SpecialFolderNames.SETTINGS_DIR_NAME, affectedResource) ||
                            	ResourceUtils.isInsideFolder(SpecialFolderNames.EXTERNAL_DEPENDENCIES_DIR_NAME, affectedResource)) {
                                return false; // DONT visit children of .settings and .mnt directories
                            }
                            
                            boolean isChildrenShouldBeVisited;
                            switch (childDelta.getKind()) {
                            case IResourceDelta.ADDED:
                                isChildrenShouldBeVisited = handleResourceAdded(delta, childDelta, affectedResource);
                                visitResult.addedResourceDeltas.add(childDelta);
                                break;
                            case IResourceDelta.REMOVED:
                                isChildrenShouldBeVisited = handleResourceRemoved(delta, childDelta, affectedResource);
                            	visitResult.removedResourceDeltas.add(childDelta);
                                break;
                            case IResourceDelta.CHANGED:
                            	isChildrenShouldBeVisited = handleResourceChanged(delta, childDelta, affectedResource);
                            	visitResult.changedResourceDeltas.add(childDelta);
                                break;
                            default:
                            	isChildrenShouldBeVisited = true;
                                break;
                            }
                            return isChildrenShouldBeVisited;
                        }
                        return true;
                    }
                });
            } else {
            	boolean isPreDeleteEvent = event.getType() == IResourceChangeEvent.PRE_DELETE;
                if (isPreDeleteEvent || event.getType() == IResourceChangeEvent.PRE_CLOSE) {
                    IResource resource = event.getResource();
                    if (resource instanceof IProject) {
                        IProject project = (IProject)resource;
                        if (NatureUtils.hasNature(project, NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID)) {
                            handleProjectRemoved(delta, project, isPreDeleteEvent);
                            visitResult.removedResourceDeltas.add(delta);
                        }
                    }
            		
            	}
            }
        } catch (CoreException e) {
            LogHelper.logError(e);
        }
        finally{
        	endDeltaProcessing(delta);
        }
        return visitResult;
	}