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

The following examples show how to use org.eclipse.core.resources.IResourceChangeEvent#PRE_CLOSE . 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: 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 2
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 3
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 4
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 5
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 6
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public synchronized void resourceChanged(IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.PRE_CLOSE)
		handleCloseEvent(event);

	IResourceDelta delta = event.getDelta();
	try {
		changedFiles.clear();
		if (delta != null)
			delta.accept(this);
		if (changedFiles.size() > 0) {
			handleHotModelReplacement();
		}

	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 7
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 8
Source File: FindBugs2Eclipse.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public FindBugs2Eclipse(IProject project, boolean cacheClassData, Reporter bugReporter) {
    super();
    this.project = project;
    this.cacheClassData = cacheClassData;
    if (cacheClassData) {
        int eventMask = IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_CLOSE;
        ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener, eventMask);
    }
    reporter = bugReporter;
}
 
Example 9
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 10
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 11
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;
	}