### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.runtime.emf.core Index: src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.core/src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java,v retrieving revision 1.1 diff -u -r1.1 PathmapManager.java --- src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java 8 Feb 2006 14:52:11 -0000 1.1 +++ src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java 7 Apr 2006 14:09:21 -0000 @@ -11,20 +11,37 @@ package org.eclipse.gmf.runtime.emf.core.internal.resources; +import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.StringTokenizer; import java.util.WeakHashMap; import java.util.Map.Entry; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IPathVariableChangeEvent; +import org.eclipse.core.resources.IPathVariableChangeListener; +import org.eclipse.core.resources.IPathVariableManager; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.common.util.URI; @@ -37,6 +54,7 @@ import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants; import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil; import org.osgi.framework.Bundle; +import org.osgi.service.prefs.BackingStoreException; /** * This class manages GMF path mappings for URI conversion. @@ -44,8 +62,9 @@ * @author rafikj */ public class PathmapManager extends AdapterImpl { - - // path maps can be defined using an extension point: Pathmaps. + // path maps can be defined using an extension point: Pathmaps + // or by referencing an eclipse path variable + // or by adding a pathmap manually // The variable name. private static final String NAME = "name"; //$NON-NLS-1$ @@ -55,12 +74,165 @@ // The path. private static final String PATH = "path"; //$NON-NLS-1$ + + private static final String NODE_QUALIFIER = EMFCorePlugin.getDefault().getBundle().getSymbolicName(); + private static final String PREFERENCE_KEY = "referenced.path.variables"; //$NON-NLS-1$ - // The path map as defined by the extensions + // The path map as defined by the extensions and the referenced path variables and the manually + // added pathmaps. private static final Map PATH_MAP = Collections.synchronizedMap(configure()); - + private static final Map instances = Collections.synchronizedMap(new WeakHashMap()); + // The list of eclipse path variables that are being used in this path map manager + private static Set referencedPathVariablesList; + + private static IEclipsePreferences preferenceStore = null; + + static { + IPathVariableManager pathManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); + + // We will get the initial list of referenced path variables from our preference store + IEclipsePreferences preferences = getPreferenceStore(); + String referencedPathVariables = preferences.get(PREFERENCE_KEY, ""); //$NON-NLS-1$ + StringTokenizer tokenizer = new StringTokenizer(referencedPathVariables, " "); //$NON-NLS-1$ + referencedPathVariablesList = new HashSet(tokenizer.countTokens()); + for (;tokenizer.hasMoreTokens();) { + String pathVariable = tokenizer.nextToken(); + addPathVariableReference(pathVariable); + } + // Update the preference store in case some path variables have been deleted since the + // last time we saved the store. + updatePreferenceStore(); + + // Register this listener to keep up-to-date with the eclipse path variables and update our + // referenced path variables appropriately. + pathManager.addChangeListener(new IPathVariableChangeListener() { + public void pathVariableChanged(IPathVariableChangeEvent event) { + switch (event.getType()) { + case IPathVariableChangeEvent.VARIABLE_DELETED: + removePathVariableReference(event.getVariableName()); + updatePreferenceStore(); + break; + case IPathVariableChangeEvent.VARIABLE_CHANGED: + // We only care about variables that we are referencing that + // have changed. + if (referencedPathVariablesList.contains(event.getVariableName())) { + // Check to see if it has become incompatible + if (!isDirectory(event.getValue())) { + removePathVariableReference(event.getVariableName()); + } else { + setPathVariable(event.getVariableName(), URI.createFileURI(event.getValue().toString()).toString()); + } + + updatePreferenceStore(); + } + break; + } + } + }); + } + + private static IEclipsePreferences getPreferenceStore() { + if (preferenceStore == null) { + IScopeContext ctx = new InstanceScope(); + preferenceStore = ctx.getNode(NODE_QUALIFIER); + } + + return preferenceStore; + } + + /** + * Adds a new reference to a path variable defined in eclipse + * to be used by this pathmap manager. It is assumed that this + * path variable is declared in the eclipes path variable manager + * and that it is a valid path variable for our purposes. + * See {@link #isCompatiblePathVariable(String)} for more details. + * + * @param pathVariable A valid path variable that has been defined in the + * eclipse {@link IPathVariableManager} and is compatible with our path maps. + */ + public static void addPathVariableReference(String pathVariable) { + if (referencedPathVariablesList.contains(pathVariable)) { + // We already reference this path variable so we can assume that it is added + // and is compatible. + return; + } + + if (!isCompatiblePathVariable(pathVariable)) { + return; + } + + IPathVariableManager pathManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); + IPath value = pathManager.getValue(pathVariable); + if (value != null) { + referencedPathVariablesList.add(pathVariable); + setPathVariable(pathVariable, URI.createFileURI(value.toString()).toString()); + } + } + + /** + * Updates the preference store with the current set of path variables that this manager + * is currently referencing from the eclipse {@link IPathVariableManager}. + */ + public static void updatePreferenceStore() { + StringBuffer referencedPathVariables = new StringBuffer(); + for (Iterator i = referencedPathVariablesList.iterator(); i.hasNext();) { + referencedPathVariables.append((String)i.next()); + referencedPathVariables.append(' '); + } + + getPreferenceStore().put(PREFERENCE_KEY, referencedPathVariables.toString()); + try { + getPreferenceStore().flush(); + } catch (BackingStoreException e) { + EMFCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR, EMFCorePlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e)); + } + } + + /** + * Removes a reference to a path variable defined in eclipse that was being + * used by this pathmap manager. + * + * @param pathVariable A path variable that was once referenced by this pathmap + * manager pointing to a variable declared in the eclipse {@link IPathVariableManager}. + */ + public static void removePathVariableReference(String pathVariable) { + if (referencedPathVariablesList.contains(pathVariable)) { + referencedPathVariablesList.remove(pathVariable); + removePathVariable(pathVariable); + } + } + + public static Set getPathVariableReferences() { + return Collections.unmodifiableSet(referencedPathVariablesList); + } + + public static boolean isCompatiblePathVariable(String variable) { + if (referencedPathVariablesList.contains(variable)) { + // We assume that if this variable is already referenced then it is valid. + return true; + } + + IPathVariableManager pathManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); + IPath value = pathManager.getValue(variable); + + if (value == null) + return false; + + // Check to see if it is a directory first. + // EMF will not correctly handle extension parsing + // of a pathmap URI if we point directly to a file. This + // means that the wrong resource factory could be called. + // This could possibly change in the future. + return isDirectory(value); + } + + private static boolean isDirectory(IPath value) { + File f = new File(value.toString()); + return (f.isDirectory()); + } + /** * Constructor. */ @@ -105,9 +277,27 @@ * Set the value of a pathmap variable. * * @param var the path map variable name - * @param val the path map variable value (a URI) + * @param val the path map variable value (a file URI) */ public static void setPathVariable(String var, String val) { + // We must try to determine if this pathmap resides in the workspace as some container + // so that we store into the pathmap a substitution that is a platform:/resource + // type of substitution. This is required because otherwise, pathmap URIs normalize + // to file URIs while platform URIs do not normalize, they remain as platform URIs. + // This will break some comparisons that might occur when trying to load a resource + // that is already loaded because the normalized version of the platform URI to be loaded + // will not match the normalized version of the pathmap URI causing two instances of + // the same resource to be loaded. + java.net.URI valURI = java.net.URI.create(val); + IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(valURI); + if (containers.length == 1) { + val = URI.createPlatformResourceURI(containers[0].getFullPath().toString(),true).toString(); + } + IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(valURI); + if (files.length == 1) { + val = URI.createPlatformResourceURI(files[0].getFullPath().toString(),true).toString(); + } + PATH_MAP.put(var, val); for (Iterator i = allInstances().iterator(); i.hasNext();) { @@ -131,7 +321,7 @@ * * @return my resource set */ - public ResourceSet getResourceSet() { + private ResourceSet getResourceSet() { return (ResourceSet) getTarget(); } @@ -199,7 +389,7 @@ String plugin = element.getAttribute(PLUGIN); if ((plugin == null) || (plugin.length() == 0)) - plugin = element.getDeclaringExtension().getNamespace(); + plugin = element.getDeclaringExtension().getNamespaceIdentifier(); Bundle bundle = Platform.getBundle(plugin); @@ -213,7 +403,7 @@ try { - url = Platform.resolve(url); + url = FileLocator.resolve(url); if (url == null) continue; @@ -230,6 +420,29 @@ return paths; } + + public void notifyChanged(Notification msg) { + if (msg.getFeatureID(ResourceSet.class) == ResourceSet.RESOURCE_SET__RESOURCES) { + switch (msg.getEventType()) { + case Notification.ADD: + denormalize((Resource) msg.getNewValue(), getResourceSet().getURIConverter()); + break; + case Notification.ADD_MANY: + for (Iterator i = ((List)msg.getNewValue()).iterator(); i.hasNext();) { + denormalize((Resource)msg.getNewValue(), getResourceSet().getURIConverter()); + } + break; + case Notification.REMOVE: + normalize((Resource)msg.getOldValue(), getResourceSet().getURIConverter()); + break; + case Notification.REMOVE_MANY: + for (Iterator i = ((List)msg.getNewValue()).iterator(); i.hasNext();) { + normalize((Resource)msg.getNewValue(), getResourceSet().getURIConverter()); + } + break; + } + } + } public void setTarget(Notifier newTarget) { // get the old resource set @@ -260,6 +473,9 @@ Map savedURIs = new HashMap(); ResourceSet rset = getResourceSet(); + + if (rset == null) + return; for (Iterator i = rset.getResources().iterator(); i.hasNext();) { @@ -387,18 +603,24 @@ .hasNext();) { Resource resource = (Resource) i.next(); - - URI uri = resource.getURI(); - - if ((EMFCoreConstants.PATH_MAP_SCHEME.equals(uri.scheme())) - && (resource instanceof GMFResource)) { - - ((GMFResource) resource) - .setRawURI(converter.normalize(uri)); - } + normalize(resource, converter); } } } + + private void normalize(Resource resource, URIConverter converter) { + URI uri = resource.getURI(); + + if (uri == null) + return; + + if ((EMFCoreConstants.PATH_MAP_SCHEME.equals(uri.scheme())) + && (resource instanceof GMFResource)) { + + ((GMFResource) resource) + .setRawURI(converter.normalize(uri)); + } + } /** * Denormalize the URI of a set of resources. @@ -415,14 +637,20 @@ .hasNext();) { Resource resource = (Resource) i.next(); - - URI uri = resource.getURI(); - - if (resource instanceof GMFResource) - ((GMFResource) resource).setURI(converter.normalize(uri)); + denormalize(resource, converter); } } } + + private void denormalize(Resource resource, URIConverter converter) { + URI uri = resource.getURI(); + + if (uri == null) + return; + + if (resource instanceof GMFResource) + ((GMFResource) resource).setURI(converter.normalize(uri)); + } /** * Make a pathmap uri from a pathmap variable name. @@ -454,4 +682,63 @@ private Map getURIMap() { return getResourceSet().getURIConverter().getURIMap(); } + + /** + * Denormalizes a given resource's URI to a pathmap URI if it is possible. + * + * @param uri A file or platform URI that has been denormalized as much + * possible. + * + * @return The original URI if it could not be denormalized any further + * or a new pathmap URI otherwise. + */ + public static URI denormalizeURI(URI uri) { + if (!uri.isFile()) { + if (!uri.scheme().equals("platform")) { //$NON-NLS-1$ + return uri; + } else if (!uri.segment(0).equals("resource")) { //$NON-NLS-1$ + return uri; + } + } + + String uriAsString = uri.toString(); + + String maxValueString = null; + String maxKey = null; + + synchronized(PATH_MAP) { + for (Iterator i = PATH_MAP.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + String valueString = (String)entry.getValue(); + + // Wipe out the trailing separator from the value if necessary + if (valueString.endsWith("/")) { //$NON-NLS-1$ + valueString = valueString.substring(0,valueString.length()-1); + } + + if (uriAsString.startsWith(valueString) + && (maxValueString == null || + maxValueString.length() < valueString.length())) { + maxValueString = valueString; + maxKey = (String)entry.getKey(); + } + } + } + + if (maxKey != null) { + URI valueURI = URI.createURI(maxValueString); + URI pathmapURI = makeURI(maxKey); + + int segmentStart = valueURI.segmentCount(); + int segmentCount = uri.segmentCount(); + + for (int j=segmentStart; j < segmentCount; j++) { + pathmapURI = pathmapURI.appendSegment(uri.segment(j)); + } + + return pathmapURI; + } + + return uri; + } } \ No newline at end of file Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.core/META-INF/MANIFEST.MF,v retrieving revision 1.14 diff -u -r1.14 MANIFEST.MF --- META-INF/MANIFEST.MF 7 Apr 2006 01:01:56 -0000 1.14 +++ META-INF/MANIFEST.MF 7 Apr 2006 14:09:21 -0000 @@ -11,7 +11,7 @@ org.eclipse.gmf.runtime.emf.core.internal.exceptions;x-internal:=true, org.eclipse.gmf.runtime.emf.core.internal.l10n;x-internal:=true, org.eclipse.gmf.runtime.emf.core.internal.plugin;x-internal:=true, - org.eclipse.gmf.runtime.emf.core.internal.resources;x-internal:=true, + org.eclipse.gmf.runtime.emf.core.internal.resources;x-friends:="org.eclipse.gmf.runtime.emf.ui", org.eclipse.gmf.runtime.emf.core.internal.util;x-friends:="org.eclipse.gmf.runtime.emf.type.core", org.eclipse.gmf.runtime.emf.core.internal.validation;x-internal:=true, org.eclipse.gmf.runtime.emf.core.resources, Index: src/org/eclipse/gmf/runtime/emf/core/internal/util/Util.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.core/src/org/eclipse/gmf/runtime/emf/core/internal/util/Util.java,v retrieving revision 1.4 diff -u -r1.4 Util.java --- src/org/eclipse/gmf/runtime/emf/core/internal/util/Util.java 28 Mar 2006 21:43:18 -0000 1.4 +++ src/org/eclipse/gmf/runtime/emf/core/internal/util/Util.java 7 Apr 2006 14:09:21 -0000 @@ -11,21 +11,11 @@ package org.eclipse.gmf.runtime.emf.core.internal.util; -import java.io.File; -import java.io.IOException; -import java.net.URL; import java.util.Iterator; -import java.util.Map; import java.util.Set; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; @@ -34,11 +24,8 @@ import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gmf.runtime.common.core.util.Trace; -import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCoreDebugOptions; -import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCorePlugin; +import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager; import org.eclipse.gmf.runtime.emf.core.resources.IResourceHelper; -import org.osgi.framework.Bundle; import com.ibm.icu.util.StringTokenizer; @@ -166,295 +153,21 @@ * @return the URI denormalized as much as possible */ public static URI denormalizeURI(URI uri, ResourceSet rset) { + URI denormalizedURI = uri; - URI resolvedURI = uri; - - if (EMFCoreConstants.PLATFORM_SCHEME.equals(resolvedURI.scheme())) { - - String filePath = getFilePath(rset, resolvedURI); - - if ((filePath != null) && (filePath.length() > 0)) - resolvedURI = URI.createFileURI(filePath); - } - - if ((resolvedURI != null) && (resolvedURI.isFile())) { - - String fileName = resolvedURI.lastSegment(); - - // attempt to convert the URI to a path map URI. - if (fileName != null) { - - URI prefix = resolvedURI.trimSegments(1); - - // find a matching pathmap. - URI foundKeyURI = null; - URI foundValURI = null; - int minDiff = Integer.MAX_VALUE; - - Iterator i = rset.getURIConverter().getURIMap() - .entrySet().iterator(); - - while (i.hasNext()) { - - Map.Entry entry = (Map.Entry) i.next(); - - if (entry != null) { - - URI keyURI = (URI) entry.getKey(); - URI valURI = (URI) entry.getValue(); - - if ((keyURI.isHierarchical()) - && (EMFCoreConstants.PATH_MAP_SCHEME.equals(keyURI - .scheme())) && (valURI.isFile())) { - - int diff = computeDiff(valURI, prefix); - - if ((diff >= 0) && (diff < minDiff)) { - - minDiff = diff; - - foundKeyURI = keyURI; - foundValURI = valURI; - - if (minDiff == 0) - break; - } - } - } - } - - if ((foundKeyURI != null) && (foundValURI != null)) - return resolvedURI.replacePrefix(foundValURI, foundKeyURI); + // First, check to see if this is a file URI and it is in the workspace. + // If so, we will denormalize first to a platform URI. + if ("file".equals(denormalizedURI.scheme())) { //$NON-NLS-1$ + IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(java.net.URI.create(denormalizedURI.toString())); + if (containers.length == 1) { + denormalizedURI = URI.createPlatformResourceURI(containers[0].getFullPath().toString(),true); } - - // attempt to convert URI to a platform URI. - URI platformURI = getPlatformURI(uri); - - if (platformURI != null) - return platformURI; } + + // Second, we will now attempt to find a pathmap for this URI + denormalizedURI = PathmapManager.denormalizeURI(denormalizedURI); - return uri; - } - - /** - * Obtains, if possible, an absolute filesystem path corresponding to the - * specified URI. - * - * @param resourceSet a resource set context for the URI normalization - * @param uri the URI to normalize to a file path - * - * @return the file path, or null if the URI does not resolve - * to a file - */ - private static String getFilePath(ResourceSet resourceSet, URI uri) { - - String filePath = null; - - if (uri == null) { - - filePath = EMFCoreConstants.EMPTY_STRING; - return filePath; - } - - if ((resourceSet != null) - && (EMFCoreConstants.PATH_MAP_SCHEME.equals(uri.scheme()))) - uri = resourceSet.getURIConverter().normalize(uri); - - if (uri.isFile()) - filePath = uri.toFileString(); - - else if (EMFCoreConstants.PLATFORM_SCHEME.equals(uri.scheme())) { - - String[] segments = uri.segments(); - - if (segments.length > 2) { - - if (EMFCoreConstants.RESOURCE.equals(segments[0])) { - - IProject project = null; - - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - - if (workspace != null) { - - IWorkspaceRoot root = workspace.getRoot(); - - if (root != null) - project = root.getProject(URI.decode(segments[1])); - } - - if ((project != null) && (project.exists())) { - - StringBuffer path = new StringBuffer(); - - path.append(project.getLocation().toString()); - - for (int i = 2; i < segments.length; i++) { - - path.append(EMFCoreConstants.PATH_SEPARATOR); - - path.append(URI.decode(segments[i])); - } - - filePath = path.toString(); - } - - } else if (EMFCoreConstants.PLUGIN.equals(segments[0])) { - - Bundle bundle = Platform.getBundle(URI.decode(segments[1])); - - if (bundle != null) { - - StringBuffer path = new StringBuffer(); - - for (int i = 2; i < segments.length; i++) { - - path.append(URI.decode(segments[i])); - - path.append(EMFCoreConstants.PATH_SEPARATOR); - } - - URL url = bundle.getEntry(path.toString()); - - if (url != null) { - - try { - - url = FileLocator.resolve(url); - - if (url != null) { - - if (EMFCoreConstants.FILE_SCHEME.equals(url - .getProtocol())) - filePath = url.getPath(); - } - - } catch (IOException e) { - - Trace.catching(EMFCorePlugin.getDefault(), - EMFCoreDebugOptions.EXCEPTIONS_CATCHING, - Util.class, "getFilePath", e); //$NON-NLS-1$ - } - } - } - } - } - } - - if (filePath == null) - filePath = EMFCoreConstants.EMPTY_STRING; - - else { - - if (File.separatorChar != EMFCoreConstants.PATH_SEPARATOR) - filePath = filePath.replace(EMFCoreConstants.PATH_SEPARATOR, - File.separatorChar); - } - - return filePath; - } - - /** - * Converts a file URI to a platform URI. - */ - private static URI getPlatformURI(URI uri) { - - if (EMFCoreConstants.PLATFORM_SCHEME.equals(uri.scheme())) - return URI.createURI(uri.toString(), true); - - IFile file = findFileInWorkspace(uri); - - if (file != null) { - - IProject project = file.getProject(); - - if (project != null) { - - StringBuffer pathName = new StringBuffer(project.getName()); - - pathName.append(EMFCoreConstants.PATH_SEPARATOR); - pathName.append(file.getProjectRelativePath().toString()); - - return URI.createURI(URI.createPlatformResourceURI( - pathName.toString(),true).toString(), true); - } - } - - return null; - } - - /** - * Finds a file in the workspace given its file URI. - */ - private static IFile findFileInWorkspace(URI uri) { - - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - - if (workspace != null) { - - IWorkspaceRoot root = workspace.getRoot(); - - if (root != null) { - - IFile[] files = root.findFilesForLocation(new Path(uri - .toFileString())); - - if (files != null) { - - for (int i = 0; i < files.length; i++) { - - IFile file = files[i]; - - IProject project = file.getProject(); - - if (project != null) - return file; - } - } - } - } - - return null; - } - - /** - * Computes segement count difference between two URIs if one is a subset of - * the other. - */ - private static int computeDiff(URI subURI, URI containerURI) { - - int subSegmentCount = subURI.segmentCount(); - int containerSegmentCount = containerURI.segmentCount(); - - if ((subSegmentCount > 0) - && (subURI.segment(subSegmentCount - 1) - .equals(EMFCoreConstants.EMPTY_STRING))) { - - subURI = subURI.trimSegments(1); - subSegmentCount--; - } - - if ((containerSegmentCount > 0) - && (containerURI.segment(containerSegmentCount - 1) - .equals(EMFCoreConstants.EMPTY_STRING))) { - - containerURI = containerURI.trimSegments(1); - containerSegmentCount--; - } - - int diff = containerSegmentCount - subSegmentCount; - - if (diff < 0) - return -1; - - else if (diff > 0) - containerURI = containerURI.trimSegments(diff); - - if (!subURI.equals(containerURI)) - return -1; - - return diff; + return denormalizedURI; } /** #P org.eclipse.gmf.runtime.emf.ui Index: plugin.properties =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.ui/plugin.properties,v retrieving revision 1.3 diff -u -r1.3 plugin.properties --- plugin.properties 16 Nov 2005 03:05:05 -0000 1.3 +++ plugin.properties 7 Apr 2006 14:09:22 -0000 @@ -22,3 +22,5 @@ createWizardCategory = Modeling ext.modelingNewWizards = New Modeling Wizards +# Path map preference page title +pathMapLabel=Path Maps \ No newline at end of file Index: plugin.xml =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.ui/plugin.xml,v retrieving revision 1.3 diff -u -r1.3 plugin.xml --- plugin.xml 10 Mar 2006 15:02:59 -0000 1.3 +++ plugin.xml 7 Apr 2006 14:09:22 -0000 @@ -25,4 +25,13 @@ id="org.eclipse.gmf.runtime.emf.ui.modeling"> + + + + Index: src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.ui/src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties,v retrieving revision 1.2 diff -u -r1.2 EMFUIMessages.properties --- src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties 6 Apr 2006 20:31:19 -0000 1.2 +++ src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties 7 Apr 2006 14:09:22 -0000 @@ -60,3 +60,18 @@ # Output view category for live validation problem messages. Validation_outputProviderCategory=Rational Modeling + +# +# Messages pertaining to the assigning pathmaps to existing eclipse path variables +# to be used in modeling. These messages are used in a preference page. +# +# ================================ BEGIN ================================================== +PathmapsPreferencePage_mainDescription=Choose path variables defined in ''{0}'' to use for modeling artifacts. +PathmapsPreferencePage_availablePathVariables=Available path variables: +PathmapsPreferencePage_pathVariablesUsedInModeling=Path variables for modeling: +PathmapsPreferencePage_addChevron=\ > +PathmapsPreferencePage_removeChevron=\ < +PathmapsPreferencePage_addAllChevron=\ >> +PathmapsPreferencePage_removeAllChevron=\ << +PathmapsPreferencePage_incompatiblePathVariableErrorMessage=The selected path variable(s) cannot be supported in a modeling environment. +# ==================================== END ================================================= Index: src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.ui/src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java,v retrieving revision 1.2 diff -u -r1.2 EMFUIMessages.java --- src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java 6 Apr 2006 20:31:19 -0000 1.2 +++ src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java 7 Apr 2006 14:09:22 -0000 @@ -44,6 +44,14 @@ public static String Validation_liveDialogTitle; public static String Validation_dontShowCheck; public static String Validation_outputProviderCategory; + public static String PathmapsPreferencePage_availablePathVariables; + public static String PathmapsPreferencePage_pathVariablesUsedInModeling; + public static String PathmapsPreferencePage_addChevron; + public static String PathmapsPreferencePage_removeChevron; + public static String PathmapsPreferencePage_incompatiblePathVariableErrorMessage; + public static String PathmapsPreferencePage_mainDescription; + public static String PathmapsPreferencePage_addAllChevron; + public static String PathmapsPreferencePage_removeAllChevron; static { NLS.initializeMessages(BUNDLE_NAME, EMFUIMessages.class); Index: src/org/eclipse/gmf/runtime/emf/ui/internal/preferences/PathmapsPreferencePage.java =================================================================== RCS file: src/org/eclipse/gmf/runtime/emf/ui/internal/preferences/PathmapsPreferencePage.java diff -N src/org/eclipse/gmf/runtime/emf/ui/internal/preferences/PathmapsPreferencePage.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/runtime/emf/ui/internal/preferences/PathmapsPreferencePage.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,308 @@ +package org.eclipse.gmf.runtime.emf.ui.internal.preferences; + +import java.util.Iterator; + +import org.eclipse.core.resources.IPathVariableChangeEvent; +import org.eclipse.core.resources.IPathVariableChangeListener; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager; +import org.eclipse.gmf.runtime.emf.ui.internal.l10n.EMFUIMessages; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.dialogs.PreferenceLinkArea; +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; + + +public class PathmapsPreferencePage + extends PreferencePage implements IWorkbenchPreferencePage { + + private List referencedPathVariables; + private List pathVariables; + private Button add; + private IPathVariableChangeListener pathVariableChangeListener; + private boolean disposed = true; + + protected void initHelp() { + // No context-sensitive help for now. + } + + protected Control createContents(Composite parent) { + GridData gridData = null; + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(3, false)); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalSpan = 2; + composite.setLayoutData(gridData); + + PreferenceLinkArea pathVariablesArea = new PreferenceLinkArea( + composite, + SWT.NONE, + "org.eclipse.ui.preferencePages.LinkedResources", EMFUIMessages.PathmapsPreferencePage_mainDescription, //$NON-NLS-1$ + (IWorkbenchPreferenceContainer) getContainer(), null); + gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = false; + gridData.horizontalSpan = 3; + pathVariablesArea.getControl().setLayoutData(gridData); + + Label pathVariablesLabel = new Label(composite, SWT.LEFT); + gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = false; + gridData.horizontalSpan = 2; + gridData.verticalIndent = 20; + pathVariablesLabel.setLayoutData(gridData); + pathVariablesLabel.setText(EMFUIMessages.PathmapsPreferencePage_availablePathVariables); + + Label referencedPathVariablesLabel = new Label(composite, SWT.LEFT); + gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = false; + gridData.horizontalSpan = 1; + gridData.verticalIndent = 20; + referencedPathVariablesLabel.setLayoutData(gridData); + referencedPathVariablesLabel.setText(EMFUIMessages.PathmapsPreferencePage_pathVariablesUsedInModeling); + + pathVariables = new List(composite,SWT.MULTI | SWT.BORDER); + gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + gridData.horizontalSpan = 1; + pathVariables.setLayoutData(gridData); + + Composite buttonComposite = new Composite(composite, SWT.NONE); + buttonComposite.setLayout(new GridLayout(1, false)); + add = new Button(buttonComposite, SWT.CENTER); + add.setText(EMFUIMessages.PathmapsPreferencePage_addChevron); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = false; + gridData.horizontalSpan = 1; + add.setLayoutData(gridData); + Button addAll = new Button(buttonComposite, SWT.CENTER); + addAll.setText(EMFUIMessages.PathmapsPreferencePage_addAllChevron); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = false; + addAll.setLayoutData(gridData); + Button remove = new Button(buttonComposite,SWT.CENTER); + remove.setText(EMFUIMessages.PathmapsPreferencePage_removeChevron); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = false; + gridData.horizontalSpan = 1; + gridData.verticalIndent = 10; + remove.setLayoutData(gridData); + Button removeAll = new Button(buttonComposite, SWT.CENTER); + removeAll.setText(EMFUIMessages.PathmapsPreferencePage_removeAllChevron); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = false; + gridData.horizontalSpan=1; + removeAll.setLayoutData(gridData); + + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.grabExcessHorizontalSpace = false; + gridData.grabExcessVerticalSpace = false; + gridData.horizontalSpan = 1; + buttonComposite.setLayoutData(gridData); + + referencedPathVariables = new List(composite,SWT.MULTI | SWT.BORDER); + gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + gridData.horizontalSpan = 1; + referencedPathVariables.setLayoutData(gridData); + + pathVariables.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + referencedPathVariables.deselectAll(); + + if (!validateSelections(pathVariables.getSelection())) { + setMessage(EMFUIMessages.PathmapsPreferencePage_incompatiblePathVariableErrorMessage,ERROR); + add.setEnabled(false); + } else { + setMessage(null); + add.setEnabled(true); + } + } + + public void widgetDefaultSelected(SelectionEvent e) { + // No action necessary + } + }); + + referencedPathVariables.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + setMessage(null); + add.setEnabled(true); + pathVariables.deselectAll(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + // No action necessary + } + }); + + add.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + String[] selections = pathVariables.getSelection(); + + for (int i=0; i 0) { result = files[0]; } } else { - result = WorkspaceSynchronizer.getFile(resource); + if ("platform".equals(normalizedURI.scheme()) && (normalizedURI.segmentCount() > 2)) { //$NON-NLS-1$ + if ("resource".equals(normalizedURI.segment(0))) { //$NON-NLS-1$ + IPath path = new Path(URI.decode(normalizedURI.path())).removeFirstSegments(1); + + result = ResourcesPlugin.getWorkspace().getRoot().getFile(path); + } + } } return result; }