Java Code Examples for org.eclipse.core.resources.IResourceDelta#getFlags()

The following examples show how to use org.eclipse.core.resources.IResourceDelta#getFlags() . 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: HierarchicalDataWorkspaceModelFactory.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(IResourceDelta delta) {
	boolean clear = false;
	IResource resource = delta.getResource();

	if (resource instanceof IFile) {
		switch (delta.getKind()) {
		case IResourceDelta.ADDED:
		case IResourceDelta.REMOVED:
			clear = true;
			break;
		case IResourceDelta.CHANGED:
			int flags = delta.getFlags();
			if ((flags & (IResourceDelta.CONTENT | IResourceDelta.LOCAL_CHANGED)) != 0) {
				clear = true;
			}
		default:
			break;
		}
		if (clear) {
			model.clearFileCache((IFile) resource);
		}
	}
	return true;
}
 
Example 2
Source File: ConfigEditor.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(IResourceDelta delta) {
	if (delta == null
			|| !delta.getResource().equals(
					((FileEditorInput) getEditorInput()).getFile())){
		return true;
	}

	if (delta.getKind() == IResourceDelta.REMOVED) {
		if ((IResourceDelta.MOVED_TO & delta.getFlags()) == 0) {
			if (!isDirty())
				closeEditor();
		} else { 
			final IFile newFile = ResourcesPlugin.getWorkspace()
					.getRoot().getFile(delta.getMovedToPath());
			Display display = getSite().getShell().getDisplay();
			display.asyncExec(new Runnable() {
				public void run() {
					editorPart.setInput(new FileEditorInput(newFile));
				}
			});
		}
	}
	return false;
}
 
Example 3
Source File: OpenResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 4
Source File: ProblemManager.java    From typescript.java with MIT License 6 votes vote down vote up
private boolean isProblemDelta(IResourceDelta delta) {
	if ((delta.getFlags() & IResourceDelta.MARKERS) == 0) {
		return false;
	}
	for (IMarkerDelta markerDelta : delta.getMarkerDeltas()) {
		if (markerDelta.isSubtypeOf(IMarker.PROBLEM)) {

			// Detect added/removed problem markers
			int kind = markerDelta.getKind();
			if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED) {
				return true;
			}

			// Detect changes in problem marker severity
			int oldSeverity = markerDelta.getAttribute(IMarker.SEVERITY, -1);
			int newSeverity = markerDelta.getMarker().getAttribute(IMarker.SEVERITY, -1);
			if (newSeverity != oldSeverity) {
				return true;
			}
		}
	}
	return false;
}
 
Example 5
Source File: UnifiedBuilder.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public boolean visit(IResourceDelta delta) throws CoreException
{
	IResource resource = delta.getResource();
	if (resource instanceof IFile)
	{
		if (delta.getKind() == IResourceDelta.ADDED
				|| (delta.getKind() == IResourceDelta.CHANGED && ((delta.getFlags() & (IResourceDelta.CONTENT | IResourceDelta.ENCODING)) != 0)))
		{
			updatedFiles.add((IFile) resource);
		}
		else if (delta.getKind() == IResourceDelta.REMOVED)
		{
			removedFiles.add((IFile) resource);
		}
	}
	return true;
}
 
Example 6
Source File: CloseResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 7
Source File: ProjectOpenedOrClosedListener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @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 8
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource resource = delta.getResource();
	if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) {
		if (resource.getType() == IResource.FILE) {
			IFile file = (IFile) resource;
			changedFiles.add(file);
		}
	}
	return true;
}
 
Example 9
Source File: BundleMonitor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public boolean visit(IResourceDelta delta) throws CoreException
{
	// process project bundle files, but ignore user bundles since file watcher will take care of those
	if (isProjectBundleFile(delta))
	{
		this.processFile(delta);
	}
	else
	{
		if (delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT) != 0)
		{
			IResource resource = delta.getResource();

			if (resource != null)
			{
				IPath location = resource.getLocation();

				if (location != null)
				{
					File file = location.toFile();

					if (file != null)
					{
						this.reloadDependentScripts(file);
					}
				}
			}
		}
	}

	return true;
}
 
Example 10
Source File: UIResourceChangeRegistry.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private boolean hasContentsChanged(final IResourceDelta delta) {
  int _kind = delta.getKind();
  boolean _equals = (_kind == IResourceDelta.CHANGED);
  if (_equals) {
    return ((delta.getFlags() & UIResourceChangeRegistry.HAS_CONTENTS_CHANGED_FLAGS) != 0);
  } else {
    return false;
  }
}
 
Example 11
Source File: ResourceChangeReporter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final IResourceDelta delta) {
	if (!DEBUG.IS_ON()) { return false; }
	final IResource res = delta.getResource();
	switch (delta.getKind()) {
		case IResourceDelta.ADDED:
			DEBUG.OUT("Resource " + res.getFullPath() + " was added.");
			break;
		case IResourceDelta.REMOVED:
			DEBUG.OUT("Resource " + res.getFullPath() + " was removed.");
			break;
		case IResourceDelta.CHANGED:
			DEBUG.OUT("Resource " + delta.getFullPath() + " has changed.");
			final int flags = delta.getFlags();
			if ((flags & IResourceDelta.CONTENT) != 0) {
				DEBUG.OUT("--> Content Change");
			}
			if ((flags & IResourceDelta.REPLACED) != 0) {
				DEBUG.OUT("--> Content Replaced");
			}
			if ((flags & IResourceDelta.MARKERS) != 0) {
				DEBUG.OUT("--> Marker Change");
				// final IMarkerDelta[] markers = delta.getMarkerDeltas();
				// if interested in markers, check these deltas
			}
			break;
	}
	return true; // visit the children
}
 
Example 12
Source File: ExternalBreakpointWatcher.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if(delta == null) {
		return;
	}
	
	IResource res = delta.getResource();
	if(res instanceof IWorkspaceRoot && (delta.getFlags() & IResourceDelta.MARKERS) != 0) {
		
		IMarkerDelta[] markerDeltas = delta.getMarkerDeltas();
		for (IMarkerDelta markerDelta : markerDeltas) {
			int kind = markerDelta.getKind();
			
			if(markerDelta.isSubtypeOf(CBREAKPOINT_MARKER_TYPE)) {
				
				if (kind == IResourceDelta.ADDED) {
					addMarkerAnnotation(markerDelta.getMarker());
				}
				
				if (kind == IResourceDelta.REMOVED) {
					removeMarkerAnnotation(markerDelta.getMarker());
				}
				
				if (kind == IResourceDelta.CHANGED) {
					updateMarkerAnnotation(markerDelta.getMarker());
				}
				
			}
		}
	}
}
 
Example 13
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isOpened(IResourceDelta delta) {
	return delta.getResource() instanceof IProject 
			&& (delta.getFlags() & IResourceDelta.OPEN) != 0
			&& ((IProject) delta.getResource()).isOpen();
}
 
Example 14
Source File: ProjectDeltaVisitor.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isMovedTo(IResourceDelta delta) {
  return ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0);
}
 
Example 15
Source File: UIResourceChangeRegistryTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public static String toReadableString(final IResourceDelta delta) {
  StringConcatenation _builder = new StringConcatenation();
  IPath _fullPath = delta.getFullPath();
  _builder.append(_fullPath);
  _builder.append(" ");
  String _switchResult = null;
  int _kind = delta.getKind();
  switch (_kind) {
    case IResourceDelta.ADDED:
      _switchResult = "ADDED";
      break;
    case IResourceDelta.REMOVED:
      _switchResult = "REMOVED";
      break;
    case IResourceDelta.CHANGED:
      _switchResult = "CHANGED";
      break;
  }
  _builder.append(_switchResult);
  _builder.append(" ");
  Pair<Integer, String> _mappedTo = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.CONTENT), "CONTENT");
  Pair<Integer, String> _mappedTo_1 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.DERIVED_CHANGED), "DERIVED_CHANGED");
  Pair<Integer, String> _mappedTo_2 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.DESCRIPTION), "DESCRIPTION");
  Pair<Integer, String> _mappedTo_3 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.ENCODING), "ENCODING");
  Pair<Integer, String> _mappedTo_4 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.LOCAL_CHANGED), "LOCAL_CHANGED");
  Pair<Integer, String> _mappedTo_5 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.OPEN), "OPEN");
  Pair<Integer, String> _mappedTo_6 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MOVED_TO), "MOVED_TO");
  Pair<Integer, String> _mappedTo_7 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MOVED_FROM), "MOVED_FROM");
  Pair<Integer, String> _mappedTo_8 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.COPIED_FROM), "COPIED_FROM");
  Pair<Integer, String> _mappedTo_9 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.TYPE), "TYPE");
  Pair<Integer, String> _mappedTo_10 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.SYNC), "SYNC");
  Pair<Integer, String> _mappedTo_11 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MARKERS), "MARKERS");
  Pair<Integer, String> _mappedTo_12 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.REPLACED), "REPLACED");
  final Function1<Pair<Integer, String>, String> _function = (Pair<Integer, String> it) -> {
    String _xifexpression = null;
    if (((delta.getFlags() & (it.getKey()).intValue()) != 0)) {
      _xifexpression = it.getValue();
    } else {
      _xifexpression = null;
    }
    return _xifexpression;
  };
  String _join = IterableExtensions.join(IterableExtensions.<String>filterNull(ListExtensions.<Pair<Integer, String>, String>map(Collections.<Pair<Integer, String>>unmodifiableList(CollectionLiterals.<Pair<Integer, String>>newArrayList(_mappedTo, _mappedTo_1, _mappedTo_2, _mappedTo_3, _mappedTo_4, _mappedTo_5, _mappedTo_6, _mappedTo_7, _mappedTo_8, _mappedTo_9, _mappedTo_10, _mappedTo_11, _mappedTo_12)), _function)), ",");
  _builder.append(_join);
  _builder.append(" {");
  _builder.newLineIfNotEmpty();
  {
    IResourceDelta[] _affectedChildren = delta.getAffectedChildren();
    for(final IResourceDelta child : _affectedChildren) {
      _builder.append("\t");
      String _readableString = UIResourceChangeRegistryTest.TestUiResourceChangeRegistry.toReadableString(child);
      _builder.append(_readableString, "\t");
      _builder.newLineIfNotEmpty();
    }
  }
  _builder.append("}");
  _builder.newLine();
  return _builder.toString();
}
 
Example 16
Source File: DeltaProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void elementRemoved(Openable element, IResourceDelta delta, RootInfo rootInfo) {

		int elementType = element.getElementType();
		if (delta == null || (delta.getFlags() & IResourceDelta.MOVED_TO) == 0) {
			// regular element removal
			if (isPrimaryWorkingCopy(element, elementType) ) {
				// filter out changes to primary compilation unit in working copy mode
				// just report a change to the resource (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59500)
				currentDelta().changed(element, IJavaElementDelta.F_PRIMARY_RESOURCE);
			} else {
				close(element);
				removeFromParentInfo(element);
				currentDelta().removed(element);
			}
		} else {
			// element is moved
			close(element);
			removeFromParentInfo(element);
			IPath movedToPath = delta.getMovedToPath();
			IResource res = delta.getResource();
			IResource movedToRes;
			switch (res.getType()) {
				case IResource.PROJECT:
					movedToRes = res.getWorkspace().getRoot().getProject(movedToPath.lastSegment());
					break;
				case IResource.FOLDER:
					movedToRes = res.getWorkspace().getRoot().getFolder(movedToPath);
					break;
				case IResource.FILE:
					movedToRes = res.getWorkspace().getRoot().getFile(movedToPath);
					break;
				default:
					return;
			}

			// find the element type of the moved from element
			IPath rootPath = externalPath(movedToRes);
			RootInfo movedToInfo = enclosingRootInfo(rootPath, IResourceDelta.ADDED);
			int movedToType =
				elementType(
					movedToRes,
					IResourceDelta.ADDED,
					element.getParent().getElementType(),
					movedToInfo);

			// reset current element as it might be inside a nested root (popUntilPrefixOf() may use the outer root)
			this.currentElement = null;

			// create the moved To element
			Openable movedToElement =
				elementType != IJavaElement.JAVA_PROJECT && movedToType == IJavaElement.JAVA_PROJECT ?
					null : // outside classpath
					createElement(movedToRes, movedToType, movedToInfo);
			if (movedToElement == null) {
				// moved outside classpath
				currentDelta().removed(element);
			} else {
				currentDelta().movedFrom(element, movedToElement);
			}
		}

		switch (elementType) {
			case IJavaElement.JAVA_MODEL :
				this.manager.indexManager.reset();
				break;
			case IJavaElement.JAVA_PROJECT :
				this.state.updateRoots(element.getPath(), delta, this);

				// remember that the project's cache must be reset
				this.projectCachesToReset.add(element);

				break;
			case IJavaElement.PACKAGE_FRAGMENT_ROOT :
				JavaProject project = (JavaProject) element.getJavaProject();

				// remember that the project's cache must be reset
				this.projectCachesToReset.add(project);

				break;
			case IJavaElement.PACKAGE_FRAGMENT :
				// reset package fragment cache
				project = (JavaProject) element.getJavaProject();
				this.projectCachesToReset.add(project);

				break;
		}
	}
 
Example 17
Source File: ResourceManager.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@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 18
Source File: ResourcesWatcher.java    From typescript.java with MIT License 4 votes vote down vote up
@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 19
Source File: ProjectDeltaVisitor.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isMovedFrom(IResourceDelta delta) {
  return ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0);
}
 
Example 20
Source File: PubspecChangeListener.java    From dartboard with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Determines whether an {@link IResourceDelta} indicates that a
 * {@link IResource}'s content was changed.
 *
 * @param delta - The {@link IResourceDelta} to be checked
 * @return <code>true</code> if the {@link IResource}'s content was changed,
 *         false otherwise.
 */
private boolean isContentChanged(IResourceDelta delta) {
	return delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT) != 0;
}