Java Code Examples for org.eclipse.core.resources.IResourceChangeEvent#PRE_DELETE

The following examples show how to use org.eclipse.core.resources.IResourceChangeEvent#PRE_DELETE . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: BibtexEntryView.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Fired whenever a resource is changed
 */
@Override
public void resourceChanged(IResourceChangeEvent event) {
	if (event.getType() != IResourceChangeEvent.POST_CHANGE
			&& event.getType() != IResourceChangeEvent.PRE_DELETE) {
		return;
	}
	if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
		handleResourceChangeEvent(event);
	} else if (event.getType() == IResourceChangeEvent.PRE_DELETE) {
		handleResourceDeleteEvent(event);
	}
}
 
Example 10
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;
	}