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

The following examples show how to use org.eclipse.core.resources.IResourceDelta#MOVED_FROM . 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: 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;
			}
		}
	}
}
 
Example 2
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);
}