Java Code Examples for org.eclipse.core.resources.IResourceDelta#REPLACED

The following examples show how to use org.eclipse.core.resources.IResourceDelta#REPLACED . 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: ResourceUtils.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 2
Source File: AbstractEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent e) {
    IResourceDelta delta = e.getDelta();
    final FileEditorInput fInput = (FileEditorInput) getEditorInput();
    final IFile file = fInput.getFile();
    if (delta != null) {
        delta = delta.findMember(file.getFullPath());
    }
    if (delta != null) {
        final int flags = delta.getFlags();
        if (delta.getKind() == IResourceDelta.REMOVED && (IResourceDelta.MOVED_TO & flags) != 0) {
            updateEditorInput(
                    new FileEditorInput(file.getWorkspace().getRoot().getFile(delta.getMovedToPath())));
        } else if (delta.getKind() == IResourceDelta.CHANGED) {
            if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.REPLACED) != 0) {
                if (!resourceChangeEventSkip) {
                    FileEditorInput newEditorInput = new FileEditorInput(delta.getResource().getAdapter(IFile.class));
                    Display.getDefault().asyncExec(() -> updateEditorInput(newEditorInput));
                }
            }
        }
    }
}
 
Example 3
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 4
Source File: CodewindResourceChangeListener.java    From codewind-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource resource = delta.getResource();

	if (resource == null) {
		return false;
	}

	// Exclude parent folder or project
	if (delta.getKind() == IResourceDelta.CHANGED && delta.getFlags() == 0) {
		return true;
	}

	ChangeEntryEventType ceet = null;

	switch (delta.getKind()) {
	case IResourceDelta.ADDED:
		ceet = ChangeEntryEventType.CREATE;
		break;
	case IResourceDelta.REMOVED:
		ceet = ChangeEntryEventType.DELETE;
		break;
	case IResourceDelta.CHANGED:
		ceet = ChangeEntryEventType.MODIFY;
		break;
	default:
		break;
	}

	if (ceet == null) {
		// Ignore and return for any unrecognized types.
		return true;
	}

	if (ceet == ChangeEntryEventType.MODIFY && ((delta.getFlags() & IResourceDelta.CONTENT) == 0
			&& (delta.getFlags() & IResourceDelta.REPLACED) == 0)) {
		// Some workbench operations, such as adding/removing a debug breakpoint, will
		// trigger a resource delta, even though the actual file contents is the same.
		// We ignore those, and return here.

		// However, these non-file-changed resources will always have the
		// IResourceDelta.CHANGED kind, so we only filter out events of this kind.
		return true;
	}

	// We have already checked that the resource is not null above, but some of the
	// underlying file system resources may still not (or no longer) have a backing
	// object, for example on project deletion events, so we check them here.
	IPath path = resource.getLocation();
	if (path == null) {
		return true;
	}

	File resourceFile = path.toFile();
	if (resourceFile == null) {
		return true;
	}

	IProject project = resource.getProject();
	if (project == null) {
		return true;
	}

	FileChangeEntryEclipse fcee = new FileChangeEntryEclipse(resourceFile, ceet,
			resource.getType() == IResource.FOLDER, project);

	result.add(fcee);

	return true;
}
 
Example 5
Source File: BundleMonitor.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * processFile
 * 
 * @param delta
 */
private void processFile(IResourceDelta delta)
{
	IResource resource = delta.getResource();

	if (resource != null && resource.getLocation() != null)
	{
		BundleManager manager = getBundleManager();
		File file = resource.getLocation().toFile();
		String fullProjectPath = delta.getFullPath().toString();

		BundlePrecedence scope = manager.getBundlePrecedence(file);

		// don't process user bundles that are projects since file watcher will handle those
		if (scope != BundlePrecedence.USER)
		{
			switch (delta.getKind())
			{
				case IResourceDelta.ADDED:
					this.showResourceEvent("Added: " + file); //$NON-NLS-1$

					if (BUNDLE_PATTERN_DEPRECATED.matcher(fullProjectPath).matches()
							|| BUNDLE_PATTERN.matcher(fullProjectPath).matches())
					{
						manager.loadBundle(file.getParentFile());
					}
					else
					{
						manager.loadScript(file);
					}
					break;

				case IResourceDelta.REMOVED:
					this.showResourceEvent("Removed: " + file); //$NON-NLS-1$

					if (BUNDLE_PATTERN_DEPRECATED.matcher(fullProjectPath).matches()
							|| BUNDLE_PATTERN.matcher(fullProjectPath).matches())
					{
						// NOTE: we have to both unload all scripts associated with this bundle
						// and the bundle file itself. Technically, the bundle file doesn't
						// exist any more so it won't get unloaded
						manager.unloadBundle(file.getParentFile());
					}

					manager.unloadScript(file);
					break;

				case IResourceDelta.CHANGED:
					if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0)
					{
						IPath movedFromPath = delta.getMovedFromPath();
						IResource movedFrom = ResourcesPlugin.getWorkspace().getRoot()
								.getFileForLocation(movedFromPath);

						if (movedFrom != null && movedFrom instanceof IFile)
						{
							this.showResourceEvent(MessageFormat.format("Added: {0}=>{1}", movedFrom.getLocation() //$NON-NLS-1$
									.toFile(), file));

							manager.unloadScript(movedFrom.getLocation().toFile());
							manager.loadScript(file);
						}
					}
					else if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0)
					{
						IPath movedToPath = delta.getMovedToPath();
						IResource movedTo = ResourcesPlugin.getWorkspace().getRoot()
								.getFileForLocation(movedToPath);

						if (movedTo != null && movedTo instanceof IFile)
						{
							this.showResourceEvent(MessageFormat.format("Added: {0}=>{1}", file, movedTo //$NON-NLS-1$
									.getLocation().toFile()));

							manager.unloadScript(file);
							manager.loadScript(movedTo.getLocation().toFile());
						}
					}
					else if ((delta.getFlags() & IResourceDelta.REPLACED) != 0)
					{
						this.showResourceEvent("Reload: " + file); //$NON-NLS-1$

						manager.reloadScript(file);
					}
					else if ((delta.getFlags() & IResourceDelta.CONTENT) != 0)
					{
						this.showResourceEvent("Reload: " + file); //$NON-NLS-1$

						manager.reloadScript(file);
					}
					break;
			}
		}
	}
}