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

The following examples show how to use org.eclipse.core.resources.IResourceChangeEvent#getType() . 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: XBookmarksPlugin.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
        try {
            event.getDelta().accept(new IResourceDeltaVisitor() {
                @Override
                public boolean visit(IResourceDelta delta) throws CoreException {
                    IResource res = delta.getResource();
                    switch (delta.getKind()) {
                    case IResourceDelta.REMOVED:
                        XBookmarksUtils.removeBookmarksFrom(res);
                        break;
                    }
                    return true; // visit the children
                }
            });
        } catch (CoreException e) {}
    }
}
 
Example 2
Source File: SharedResourcesManager.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
private void logPauseWarning(IResourceChangeEvent event) {
  if (event.getType() == IResourceChangeEvent.POST_CHANGE) {

    IResourceDelta delta = event.getDelta();
    if (delta == null) {
      log.error(
          "Resource changed while paused"
              + " but unexpected empty delta in "
              + "SharedResourcesManager: "
              + event);
      return;
    }

    log.warn("Resource changed while paused:\n" + deltaToString(delta));
  } else {
    log.error("Unexpected event type in in logPauseWarning: " + event);
  }
}
 
Example 3
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 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: 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 6
Source File: FileEntry.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	if (project != null) {
		if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			try {
				event.getDelta().accept(new IResourceDeltaVisitor() {
					public boolean visit(IResourceDelta delta) throws CoreException {
						IProject p = delta.getResource().getProject();
						if (p != null && p.getName().equals(project.getName())) {
							generateAllowedValues();
							notifyListeners();
						}
						return true;
					}
				});
			} catch (CoreException e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 7
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 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: StartupHandler.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {

	IResourceDelta delta = event.getDelta();

	IResourceDelta[] affectedChildren = delta.getAffectedChildren();
	if (affectedChildren.length == 0) {
		return;
	}
	IResource deltaResource = affectedChildren[0].getResource();
	if (event.getType() == IResourceChangeEvent.POST_CHANGE && deltaResource instanceof IProject
			&& (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED)) {
		try {
			IProject project = (IProject) deltaResource;
			if (!CrySLBuilderUtils.hasCrySLBuilder(project) && CrySLBuilderUtils.hasCrySLFiles(project)) {
				CrySLBuilderUtils.addCrySLBuilderToProject(project);
			}
		}
		catch (CoreException e) {}
	}
}
 
Example 10
Source File: JavaHotCodeReplaceProvider.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the class file visitor after visiting the resource change. The
 * visitor contains the changed class files and qualified type names. Returns
 * <code>null</code> if the visitor encounters an exception, or the delta is not
 * a POST_BUILD.
 */
private ChangedClassFilesVisitor getChangedClassFiles(IResourceChangeEvent event) {
    IResourceDelta delta = event.getDelta();
    if (event.getType() != IResourceChangeEvent.POST_BUILD || delta == null) {
        return null;
    }
    classFilesVisitor.reset();
    try {
        delta.accept(classFilesVisitor);
    } catch (CoreException e) {
        return null; // quiet failure
    }
    return classFilesVisitor;
}
 
Example 11
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 12
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	if (event.getType() != IResourceChangeEvent.POST_BUILD && event
			.getType() != IResourceChangeEvent.POST_CHANGE) {
		return;
	}
	IResourceDelta rootDelta = event.getDelta();
	try {
		rootDelta.accept(resourceVisitor);
	} catch (CoreException e) {
		DotActivatorEx.logError(e);
	}
}
 
Example 13
Source File: SyncGraphvizExportHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	if (event.getType() != IResourceChangeEvent.POST_BUILD
			&& event.getType() != IResourceChangeEvent.POST_CHANGE) {
		return;
	}
	IResourceDelta rootDelta = event.getDelta();
	try {
		rootDelta.accept(resourceDeltaVisitor);
	} catch (CoreException e) {
		DotActivatorEx.logError(e);
	}
}
 
Example 14
Source File: ResourceChangeListener.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {

    boolean postBuild = event.getType() == IResourceChangeEvent.POST_BUILD;
    boolean accepted = false;

    /*
     * gather all marker changes from the delta. be sure to do this in the
     * calling thread, as the delta is destroyed when this method returns
     */
    IMarkerDelta[] markerDeltas = event.findMarkerDeltas(FindBugsMarker.NAME, true);
    for (IMarkerDelta mdelta : markerDeltas) {
        IMarker marker = mdelta.getMarker();
        if (marker == null) {
            continue;
        }
        DeltaInfo deltaInfo = new DeltaInfo(marker, mdelta.getKind());
        if (BugContentProvider.DEBUG) {
            System.out.println("resource change for: " + deltaInfo);
        }

        accepted |= refreshJob.addToQueue(deltaInfo);
    }

    if (!accepted) {
        return;
    }

    if (postBuild) {
        scheduleRefreshJob(SHORT_DELAY);
    } else {
        // After some time do updates anyways
        scheduleRefreshJob(LONG_DELAY);
    }
}
 
Example 15
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 16
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 17
Source File: ProjectStateChangeListener.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	IWorkspace workspace = getWorkspace();
	if (workspace != null) {
		if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			try {
				final Set<IProject> affectedProjects = Sets.newLinkedHashSet();
				event.getDelta().accept(projectCollector(affectedProjects));
				if (!affectedProjects.isEmpty()) {
					ToBeBuilt toBeBuilt = new ToBeBuilt();
					Set<URI> toBeUpdated = toBeBuilt.getToBeUpdated();
					Set<String> projectNames = new LinkedHashSet<>();
					for (IProject project : affectedProjects) {
						IFile file = project.getFile(N4JSGlobals.PACKAGE_JSON);
						if (file.exists()) {
							projectNames.add(project.getName());
							toBeUpdated.add(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
						}

					}
					packageJsonQueue.enqueue(projectNames, toBeBuilt, false);
					syncIndexJob.schedule();
				}
			} catch (CoreException e) {
				LOGGER.error(e.getMessage(), e);
			}
		}
	}
	super.resourceChanged(event);
}
 
Example 18
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 19
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;
	}
 
Example 20
Source File: ResourceManager.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	if (BLOCKED) {
		BLOCKED_EVENTS.add(event);
		return;
	}
	if (DEBUG.IS_ON()) {
		DEBUG.OUT("========= New Event =========");
	}
	try {
		if (event == null) { return; }
		// begin();
		final int type = event.getType();
		switch (type) {
			case POST_CHANGE:
				if (viewer.isBusy()) {
					WorkbenchHelper.runInUI("Resource changes", 50, (m) -> delegate.resourceChanged(event));
				} else {
					delegate.resourceChanged(event);
				}
				try {
					event.getDelta().accept(this);
				} catch (final CoreException e) {
					e.printStackTrace();
				}
				break;
			case IResourceChangeEvent.PRE_REFRESH:
				if (DEBUG.IS_ON()) {
					DEBUG.OUT("Project " + event.getResource().getName() + " about to be refreshed");
				}
				break;
			case PRE_CLOSE:
			case PRE_DELETE:
				if (DEBUG.IS_ON()) {
					DEBUG.OUT("Project " + event.getResource().getName() + " about to be closed or deleted");
				}
				break;
			default:

		}
	} finally {
		runPostEventActions();
	}
}