Java Code Examples for org.eclipse.core.resources.IResourceDelta#OPEN
The following examples show how to use
org.eclipse.core.resources.IResourceDelta#OPEN .
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: WorkspaceRepositoriesProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Handles the given resource delta. * * Fires workspace repository changed event if a project was opened/closed or a project was added/removed. */ private boolean handleResourceDelta(IResourceDelta delta) { IResource affectedResource = delta.getResource(); if (affectedResource instanceof IProject) { // check if kind is CHANGED if ((delta.getKind() & IResourceDelta.CHANGED) == IResourceDelta.CHANGED) { // if project was opened/closed if ((delta.getFlags() & IResourceDelta.OPEN) == IResourceDelta.OPEN) { fireWorkspaceRepositoriesChanged(); return false; } } // check if kind is ADDED or REMOVED else if ((delta.getKind() & IResourceDelta.ADDED | IResourceDelta.REMOVED) != 0) { fireWorkspaceRepositoriesChanged(); return false; } } return true; }
Example 2
Source File: ProjectOpenedOrClosedListener.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.17 */ protected boolean visitResourceDelta(IResourceDelta delta, final Set<IProject> accumulator) { if (delta.getResource() instanceof IWorkspaceRoot) return true; if (delta.getResource() instanceof IProject) { IProject project = (IProject) delta.getResource(); if ((delta.getKind() & IResourceDelta.CHANGED) != 0 && project.isOpen()) { if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { accumulator.add(project); } if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) { if ((delta.findMember(new Path(".project")) != null) && XtextProjectHelper.hasNature(project) && XtextProjectHelper.hasBuilder(project)) accumulator.add(project); else if (!XtextProjectHelper.hasNature(project)) { scheduleRemoveProjectJobIfNecessary(project, delta); } } } } return false; }
Example 3
Source File: ResourceUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Given a resource delta, indicate whether or the delta contains a type of * resource change that GWT generally cares about. */ public static boolean isRelevantResourceChange(IResourceDelta delta) { if (delta == null) { return false; } int relevantChanges = IResourceDelta.CONTENT | IResourceDelta.DESCRIPTION | IRESOURCEDELTA_LOCAL_CHANGED | IResourceDelta.OPEN | IResourceDelta.REPLACED | IResourceDelta.TYPE; // Either added or removed (through != CHANGED), or changed in some // relevant way (through (.. & relevantChanges) != 0) if (delta.getKind() != IResourceDelta.CHANGED || (delta.getFlags() & relevantChanges) != 0) { return true; } return false; }
Example 4
Source File: OpenResourceAction.java From gama with GNU General Public License v3.0 | 6 votes |
/** * Handles a resource changed event by updating the enablement if one of the selected projects is opened or closed. */ @Override public void resourceChanged(final IResourceChangeEvent event) { // Warning: code duplicated in CloseResourceAction final List<?> 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 5
Source File: CloseResourceAction.java From gama with GNU General Public License v3.0 | 6 votes |
/** * 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 6
Source File: RestoreProjectListener.java From thym with Eclipse Public License 1.0 | 6 votes |
@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 7
Source File: N4JSAllContainersState.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Handles the given {@link IResourceDelta} and updates the project state (cache of available projects and project * descriptions) accordingly. * * If so, invalidates the {@link EclipseBasedN4JSWorkspace} cache of project descriptions for the updated projects. */ private boolean updateProjectState(IResourceDelta delta) { if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) { if (IN4JSProject.PACKAGE_JSON.equals(delta.getFullPath().lastSegment())) { return true; } if (delta.getResource() instanceof IProject) { return true; } if (delta.getResource() instanceof IFolder) { if (isSourceContainerModification(delta)) { return true; } } return false; } else if (delta.getKind() == IResourceDelta.CHANGED) { if (delta.getResource() instanceof IProject) { if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { return true; } return false; } if (delta.getResource() instanceof IFolder) { if (N4JSGlobals.NODE_MODULES.equals(delta.getFullPath().lastSegment())) { return true; } return false; } } if (packageJSONFileHasBeenChanged(delta)) { return true; } return false; }
Example 8
Source File: N4JSAllContainersState.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Indicates whether the resource change represented by the given {@code delta} does affect this container state. * * Note that this method will only be invoked until a container-state-affecting delta is found. Thus, it is not * suitable for listening for all resource changes that may occur in the workspace. */ @Override protected boolean isAffectingContainerState(IResourceDelta delta) { if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) { String fileExtension = delta.getFullPath().getFileExtension(); if (null != fileExtension && fileExtensionTypeHelper.isTypable(fileExtension)) { return true; } if (IN4JSProject.PACKAGE_JSON.equals(delta.getFullPath().lastSegment())) { return true; } if (delta.getResource() instanceof IProject) { return true; } if (delta.getResource() instanceof IFolder && isSourceContainerModification(delta)) { return true; } return false; } else if (delta.getKind() == IResourceDelta.CHANGED && delta.getResource() instanceof IProject) { if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) { return true; } if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { return true; } return false; } if (packageJSONFileHasBeenChanged(delta)) { return true; } return false; }
Example 9
Source File: ProjectStateChangeListener.java From n4js with Eclipse Public License 1.0 | 5 votes |
private boolean collectAffectedProjects(IResourceDelta delta, Set<IProject> accumulator) { IResource resource = delta.getResource(); if (resource instanceof IProject && "RemoteSystemsTempFiles".equals(resource.getName())) { return false; } if (resource instanceof IWorkspaceRoot) return true; if (resource instanceof IProject) { IProject project = (IProject) resource; if ("RemoteSystemsTempFiles".equals(resource.getName())) { return false; } if ((delta.getKind() & IResourceDelta.CHANGED) != 0 && project.isOpen()) { if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { accumulator.add(project); } if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) { if ((delta.findMember(new Path(".project")) != null) && XtextProjectHelper.hasNature(project) && XtextProjectHelper.hasBuilder(project)) { accumulator.add(project); } } } return true; } if (resource instanceof IFolder) { if (N4JSGlobals.NODE_MODULES.equals(resource.getName())) { accumulator.add(resource.getProject()); } else if ((delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) && isSourceContainerModification(resource)) { accumulator.add(resource.getProject()); } } return false; }
Example 10
Source File: OpenProjectAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void resourceChanged(IResourceChangeEvent event) { IResourceDelta delta = event.getDelta(); if (delta != null) { IResourceDelta[] projDeltas = delta.getAffectedChildren(IResourceDelta.CHANGED); for (int i = 0; i < projDeltas.length; ++i) { IResourceDelta projDelta = projDeltas[i]; if ((projDelta.getFlags() & IResourceDelta.OPEN) != 0) { setEnabled(hasClosedProjectsInWorkspace()); return; } } } }
Example 11
Source File: JavaWorkingSetUpdater.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void processResourceDelta(WorkingSetDelta result, IResourceDelta delta) { IResource resource= delta.getResource(); int type= resource.getType(); int index= result.indexOf(resource); int kind= delta.getKind(); int flags= delta.getFlags(); if (kind == IResourceDelta.CHANGED && type == IResource.PROJECT && index != -1) { if ((flags & IResourceDelta.OPEN) != 0) { result.set(index, resource); } } if (index != -1 && kind == IResourceDelta.REMOVED) { if ((flags & IResourceDelta.MOVED_TO) != 0) { result.set(index, ResourcesPlugin.getWorkspace().getRoot().findMember(delta.getMovedToPath())); } else { result.remove(index); } } // Don't dive into closed or opened projects if (projectGotClosedOrOpened(resource, kind, flags)) return; IResourceDelta[] children= delta.getAffectedChildren(); for (int i= 0; i < children.length; i++) { processResourceDelta(result, children[i]); } }
Example 12
Source File: XtextBuilder.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected boolean isOpened(IResourceDelta delta) { return delta.getResource() instanceof IProject && (delta.getFlags() & IResourceDelta.OPEN) != 0 && ((IProject) delta.getResource()).isOpen(); }
Example 13
Source File: ResourcesWatcher.java From typescript.java with MIT License | 4 votes |
@Override public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); if (resource == null) { return false; } switch (resource.getType()) { case IResource.ROOT: return true; case IResource.PROJECT: IProject project = (IProject) resource; if (project.isOpen() && delta.getKind() == IResourceDelta.CHANGED && ((delta.getFlags() & IResourceDelta.OPEN) != 0)) { // System.err.println("Open"); } // Continue if project has defined file listeners. return fileListeners.containsKey(resource); case IResource.FOLDER: return true; case IResource.FILE: IFile file = (IFile) resource; synchronized (fileListeners) { Map<String, List<IFileWatcherListener>> listenersForFilename = fileListeners.get(file.getProject()); List<IFileWatcherListener> listeners = listenersForFilename.get(file.getName()); if (listeners != null) { for (IFileWatcherListener listener : listeners) { switch (delta.getKind()) { case IResourceDelta.ADDED: // handle added resource listener.onAdded(file); break; case IResourceDelta.REMOVED: // handle removed resource listener.onDeleted(file); break; default: listener.onChanged(file); } } } } return false; } return false; }
Example 14
Source File: ResourceManager.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public boolean visit(final IResourceDelta delta) { final IResource res = delta.getResource(); boolean update = false; switch (delta.getKind()) { case IResourceDelta.OPEN: if (res.isAccessible()) { update = projectOpened((IProject) res); } else { update = projectClosed((IProject) res); } break; case IResourceDelta.ADDED: update = processAddition(res); break; case IResourceDelta.REMOVED: update = processRemoval(res); break; case IResourceDelta.CHANGED: final int flags = delta.getFlags(); if ((flags & IResourceDelta.MARKERS) != 0) { update = processMarkersChanged(res); } if ((flags & IResourceDelta.TYPE) != 0) { if (DEBUG.IS_ON()) { DEBUG.OUT("Resource type changed: " + res); } } if ((flags & IResourceDelta.CONTENT) != 0) { if (DEBUG.IS_ON()) { DEBUG.OUT("Resource contents changed: " + res); } } if ((flags & IResourceDelta.SYNC) != 0) { if (DEBUG.IS_ON()) { DEBUG.OUT("Resource sync info changed: " + res); } } if ((flags & IResourceDelta.LOCAL_CHANGED) != 0) { if (DEBUG.IS_ON()) { DEBUG.OUT("Linked resource target info changed: " + res); } update = processLinkedTargerChanged(res); } break; } if (update) { updateResource(res); } return true; // visit the children }
Example 15
Source File: PackageExplorerContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Process a resource delta. * * @param delta the delta to process * @param parent the parent * @param runnables the resulting view changes as runnables (type {@link Runnable}) * @return true if the parent got refreshed */ private boolean processResourceDelta(IResourceDelta delta, Object parent, Collection<Runnable> runnables) { int status= delta.getKind(); int flags= delta.getFlags(); IResource resource= delta.getResource(); // filter out changes affecting the output folder if (resource == null) return false; // this could be optimized by handling all the added children in the parent if ((status & IResourceDelta.REMOVED) != 0) { if (parent instanceof IPackageFragment) { // refresh one level above to deal with empty package filtering properly postRefresh(internalGetParent(parent), PARENT, parent, runnables); return true; } else { postRemove(resource, runnables); return false; } } if ((status & IResourceDelta.ADDED) != 0) { if (parent instanceof IPackageFragment) { // refresh one level above to deal with empty package filtering properly postRefresh(internalGetParent(parent), PARENT, parent, runnables); return true; } else { postAdd(parent, resource, runnables); return false; } } if ((status & IResourceDelta.CHANGED) != 0) { if ((flags & IResourceDelta.TYPE) != 0) { postRefresh(parent, PARENT, resource, runnables); return true; } } // open/close state change of a project if ((flags & IResourceDelta.OPEN) != 0) { postProjectStateChanged(internalGetParent(parent), runnables); return true; } IResourceDelta[] resourceDeltas= delta.getAffectedChildren(); int count= 0; for (int i= 0; i < resourceDeltas.length; i++) { int kind= resourceDeltas[i].getKind(); if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED) { count++; if (count > 1) { postRefresh(parent, PARENT, resource, runnables); return true; } } } for (int i= 0; i < resourceDeltas.length; i++) { if (processResourceDelta(resourceDeltas[i], resource, runnables)) { return false; // early return, element got refreshed } } return false; }
Example 16
Source File: JavaWorkingSetUpdater.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private boolean projectGotClosedOrOpened(IResource resource, int kind, int flags) { return resource.getType() == IResource.PROJECT && kind == IResourceDelta.CHANGED && (flags & IResourceDelta.OPEN) != 0; }