View | Details | Raw Unified | Return to bug 131829
Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java (-22 / +309 lines)
Lines 11-30 Link Here
11
11
12
package org.eclipse.gmf.runtime.emf.core.internal.resources;
12
package org.eclipse.gmf.runtime.emf.core.internal.resources;
13
13
14
import java.io.File;
14
import java.io.IOException;
15
import java.io.IOException;
15
import java.net.URL;
16
import java.net.URL;
16
import java.util.Collection;
17
import java.util.Collection;
17
import java.util.Collections;
18
import java.util.Collections;
18
import java.util.HashMap;
19
import java.util.HashMap;
20
import java.util.HashSet;
19
import java.util.Iterator;
21
import java.util.Iterator;
20
import java.util.List;
22
import java.util.List;
21
import java.util.Map;
23
import java.util.Map;
22
import java.util.Set;
24
import java.util.Set;
25
import java.util.StringTokenizer;
23
import java.util.WeakHashMap;
26
import java.util.WeakHashMap;
24
import java.util.Map.Entry;
27
import java.util.Map.Entry;
25
28
29
import org.eclipse.core.resources.IContainer;
30
import org.eclipse.core.resources.IFile;
31
import org.eclipse.core.resources.IPathVariableChangeEvent;
32
import org.eclipse.core.resources.IPathVariableChangeListener;
33
import org.eclipse.core.resources.IPathVariableManager;
34
import org.eclipse.core.resources.ResourcesPlugin;
35
import org.eclipse.core.runtime.FileLocator;
26
import org.eclipse.core.runtime.IConfigurationElement;
36
import org.eclipse.core.runtime.IConfigurationElement;
37
import org.eclipse.core.runtime.IPath;
38
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Platform;
39
import org.eclipse.core.runtime.Platform;
40
import org.eclipse.core.runtime.Status;
41
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
42
import org.eclipse.core.runtime.preferences.IScopeContext;
43
import org.eclipse.core.runtime.preferences.InstanceScope;
44
import org.eclipse.emf.common.notify.Notification;
28
import org.eclipse.emf.common.notify.Notifier;
45
import org.eclipse.emf.common.notify.Notifier;
29
import org.eclipse.emf.common.notify.impl.AdapterImpl;
46
import org.eclipse.emf.common.notify.impl.AdapterImpl;
30
import org.eclipse.emf.common.util.URI;
47
import org.eclipse.emf.common.util.URI;
Lines 37-42 Link Here
37
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
54
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
38
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
55
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
39
import org.osgi.framework.Bundle;
56
import org.osgi.framework.Bundle;
57
import org.osgi.service.prefs.BackingStoreException;
40
58
41
/**
59
/**
42
 * This class manages GMF path mappings for URI conversion.
60
 * This class manages GMF path mappings for URI conversion.
Lines 44-51 Link Here
44
 * @author rafikj
62
 * @author rafikj
45
 */
63
 */
46
public class PathmapManager extends AdapterImpl {
64
public class PathmapManager extends AdapterImpl {
47
65
	// path maps can be defined using an extension point: Pathmaps
48
	// path maps can be defined using an extension point: Pathmaps.
66
	//  or by referencing an eclipse path variable
67
	//  or by adding a pathmap manually
49
68
50
	// The variable name.
69
	// The variable name.
51
	private static final String NAME = "name"; //$NON-NLS-1$
70
	private static final String NAME = "name"; //$NON-NLS-1$
Lines 55-66 Link Here
55
74
56
	// The path.
75
	// The path.
57
	private static final String PATH = "path"; //$NON-NLS-1$
76
	private static final String PATH = "path"; //$NON-NLS-1$
77
	
78
	private static final String NODE_QUALIFIER = EMFCorePlugin.getDefault().getBundle().getSymbolicName();
79
	private static final String PREFERENCE_KEY = "referenced.path.variables"; //$NON-NLS-1$
58
80
59
	// The path map as defined by the extensions
81
	// The path map as defined by the extensions and the referenced path variables and the manually
82
	//  added pathmaps.
60
	private static final Map PATH_MAP = Collections.synchronizedMap(configure());
83
	private static final Map PATH_MAP = Collections.synchronizedMap(configure());
61
84
	
62
	private static final Map instances = Collections.synchronizedMap(new WeakHashMap());
85
	private static final Map instances = Collections.synchronizedMap(new WeakHashMap());
63
	
86
	
87
	// The list of eclipse path variables that are being used in this path map manager
88
	private static Set referencedPathVariablesList;
89
	
90
	private static IEclipsePreferences preferenceStore = null;
91
	
92
	static {
93
		IPathVariableManager pathManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
94
		
95
		// We will get the initial list of referenced path variables from our preference store
96
		IEclipsePreferences preferences = getPreferenceStore();
97
		String referencedPathVariables = preferences.get(PREFERENCE_KEY, ""); //$NON-NLS-1$
98
		StringTokenizer tokenizer = new StringTokenizer(referencedPathVariables, " "); //$NON-NLS-1$
99
		referencedPathVariablesList = new HashSet(tokenizer.countTokens());
100
		for (;tokenizer.hasMoreTokens();) {
101
			String pathVariable = tokenizer.nextToken();
102
			addPathVariableReference(pathVariable);
103
		}
104
		// Update the preference store in case some path variables have been deleted since the
105
		//  last time we saved the store.
106
		updatePreferenceStore();
107
		
108
		// Register this listener to keep up-to-date with the eclipse path variables and update our
109
		//  referenced path variables appropriately.
110
		pathManager.addChangeListener(new IPathVariableChangeListener() {
111
			public void pathVariableChanged(IPathVariableChangeEvent event) {
112
				switch (event.getType()) {
113
					case IPathVariableChangeEvent.VARIABLE_DELETED:
114
						removePathVariableReference(event.getVariableName());
115
						updatePreferenceStore();
116
						break;
117
					case IPathVariableChangeEvent.VARIABLE_CHANGED:
118
						// We only care about variables that we are referencing that
119
						//  have changed.
120
						if (referencedPathVariablesList.contains(event.getVariableName())) {
121
							// Check to see if it has become incompatible
122
							if (!isDirectory(event.getValue())) {
123
								removePathVariableReference(event.getVariableName());
124
							} else {
125
								setPathVariable(event.getVariableName(), URI.createFileURI(event.getValue().toString()).toString());
126
							}
127
							
128
							updatePreferenceStore();
129
						}
130
						break;
131
				}
132
			}
133
		});
134
	}
135
136
	private static IEclipsePreferences getPreferenceStore() {
137
		if (preferenceStore == null) {
138
			IScopeContext ctx = new InstanceScope();
139
			preferenceStore = ctx.getNode(NODE_QUALIFIER);
140
		}
141
		
142
		return preferenceStore;
143
	}
144
	
145
	/**
146
	 * Adds a new reference to a path variable defined in eclipse
147
	 *  to be used by this pathmap manager. It is assumed that this
148
	 *  path variable is declared in the eclipes path variable manager
149
	 *  and that it is a valid path variable for our purposes. 
150
	 *  See {@link #isCompatiblePathVariable(String)} for more details.
151
	 *  
152
	 * @param pathVariable A valid path variable that has been defined in the
153
	 *  eclipse {@link IPathVariableManager} and is compatible with our path maps.
154
	 */
155
	public static void addPathVariableReference(String pathVariable) {
156
		if (referencedPathVariablesList.contains(pathVariable)) {
157
			// We already reference this path variable so we can assume that it is added
158
			//  and is compatible.
159
			return;
160
		}
161
		
162
		if (!isCompatiblePathVariable(pathVariable)) {
163
			return;
164
		}
165
		
166
		IPathVariableManager pathManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
167
		IPath value = pathManager.getValue(pathVariable);
168
		if (value != null) {
169
			referencedPathVariablesList.add(pathVariable);
170
			setPathVariable(pathVariable, URI.createFileURI(value.toString()).toString());
171
		}
172
	}
173
	
174
	/**
175
	 * Updates the preference store with the current set of path variables that this manager
176
	 *  is currently referencing from the eclipse {@link IPathVariableManager}.
177
	 */
178
	public static void updatePreferenceStore() {
179
		StringBuffer referencedPathVariables = new StringBuffer();
180
		for (Iterator i = referencedPathVariablesList.iterator(); i.hasNext();) {
181
			referencedPathVariables.append((String)i.next());
182
			referencedPathVariables.append(' ');
183
		}
184
		
185
		getPreferenceStore().put(PREFERENCE_KEY, referencedPathVariables.toString());
186
		try {
187
			getPreferenceStore().flush();
188
		} catch (BackingStoreException e) {
189
			EMFCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR, EMFCorePlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e));
190
		}
191
	}
192
	
193
	/**
194
	 * Removes a reference to a path variable defined in eclipse that was being
195
	 *  used by this pathmap manager.
196
	 *  
197
	 * @param pathVariable A path variable that was once referenced by this pathmap
198
	 *  manager pointing to a variable declared in the eclipse {@link IPathVariableManager}.
199
	 */
200
	public static void removePathVariableReference(String pathVariable) {
201
		if (referencedPathVariablesList.contains(pathVariable)) {
202
			referencedPathVariablesList.remove(pathVariable);
203
			removePathVariable(pathVariable);
204
		}
205
	}
206
	
207
	public static Set getPathVariableReferences() {
208
		return Collections.unmodifiableSet(referencedPathVariablesList);
209
	}
210
	
211
	public static boolean isCompatiblePathVariable(String variable) {
212
		if (referencedPathVariablesList.contains(variable)) {
213
			// We assume that if this variable is already referenced then it is valid.
214
			return true;
215
		}
216
		
217
		IPathVariableManager pathManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
218
		IPath value = pathManager.getValue(variable);
219
		
220
		if (value == null)
221
			return false;
222
		
223
		// Check to see if it is a directory first.
224
		// EMF will not correctly handle extension parsing
225
		//  of a pathmap URI if we point directly to a file. This
226
		//  means that the wrong resource factory could be called.
227
		// This could possibly change in the future.
228
		return isDirectory(value);
229
	}
230
231
	private static boolean isDirectory(IPath value) {
232
		File f = new File(value.toString());
233
		return (f.isDirectory());
234
	}
235
64
	/**
236
	/**
65
	 * Constructor.
237
	 * Constructor.
66
	 */
238
	 */
Lines 105-113 Link Here
105
	 * Set the value of a pathmap variable.
277
	 * Set the value of a pathmap variable.
106
	 * 
278
	 * 
107
	 * @param var the path map variable name
279
	 * @param var the path map variable name
108
	 * @param val the path map variable value (a URI)
280
	 * @param val the path map variable value (a file URI)
109
	 */
281
	 */
110
	public static void setPathVariable(String var, String val) {
282
	public static void setPathVariable(String var, String val) {
283
		// We must try to determine if this pathmap resides in the workspace as some container
284
		//  so that we store into the pathmap a substitution that is a platform:/resource 
285
		//  type of substitution. This is required because otherwise, pathmap URIs normalize
286
		//  to file URIs while platform URIs do not normalize, they remain as platform URIs.
287
		//  This will break some comparisons that might occur when trying to load a resource
288
		//  that is already loaded because the normalized version of the platform URI to be loaded
289
		//  will not match the normalized version of the pathmap URI causing two instances of
290
		//  the same resource to be loaded.
291
		java.net.URI valURI = java.net.URI.create(val);
292
		IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(valURI);
293
		if (containers.length == 1) {
294
			val = URI.createPlatformResourceURI(containers[0].getFullPath().toString(),true).toString();
295
		}
296
		IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(valURI);
297
		if (files.length == 1) {
298
			val = URI.createPlatformResourceURI(files[0].getFullPath().toString(),true).toString();
299
		}
300
		
111
		PATH_MAP.put(var, val);
301
		PATH_MAP.put(var, val);
112
302
113
		for (Iterator i = allInstances().iterator(); i.hasNext();) {
303
		for (Iterator i = allInstances().iterator(); i.hasNext();) {
Lines 131-137 Link Here
131
	 * 
321
	 * 
132
	 * @return my resource set
322
	 * @return my resource set
133
	 */
323
	 */
134
	public ResourceSet getResourceSet() {
324
	private ResourceSet getResourceSet() {
135
		return (ResourceSet) getTarget();
325
		return (ResourceSet) getTarget();
136
	}
326
	}
137
327
Lines 199-205 Link Here
199
			String plugin = element.getAttribute(PLUGIN);
389
			String plugin = element.getAttribute(PLUGIN);
200
390
201
			if ((plugin == null) || (plugin.length() == 0))
391
			if ((plugin == null) || (plugin.length() == 0))
202
				plugin = element.getDeclaringExtension().getNamespace();
392
				plugin = element.getDeclaringExtension().getNamespaceIdentifier();
203
393
204
			Bundle bundle = Platform.getBundle(plugin);
394
			Bundle bundle = Platform.getBundle(plugin);
205
395
Lines 213-219 Link Here
213
403
214
			try {
404
			try {
215
405
216
				url = Platform.resolve(url);
406
				url = FileLocator.resolve(url);
217
407
218
				if (url == null)
408
				if (url == null)
219
					continue;
409
					continue;
Lines 230-235 Link Here
230
420
231
		return paths;
421
		return paths;
232
	}
422
	}
423
	
424
	public void notifyChanged(Notification msg) {
425
		if (msg.getFeatureID(ResourceSet.class) == ResourceSet.RESOURCE_SET__RESOURCES) {
426
			switch (msg.getEventType()) {
427
			case Notification.ADD:
428
				denormalize((Resource) msg.getNewValue(), getResourceSet().getURIConverter());
429
				break;
430
			case Notification.ADD_MANY:
431
				for (Iterator i = ((List)msg.getNewValue()).iterator(); i.hasNext();) {
432
					denormalize((Resource)msg.getNewValue(), getResourceSet().getURIConverter());
433
				}
434
				break;
435
			case Notification.REMOVE:
436
				normalize((Resource)msg.getOldValue(), getResourceSet().getURIConverter());
437
				break;
438
			case Notification.REMOVE_MANY:
439
				for (Iterator i = ((List)msg.getNewValue()).iterator(); i.hasNext();) {
440
					normalize((Resource)msg.getNewValue(), getResourceSet().getURIConverter());
441
				}
442
				break;
443
			}
444
		}
445
	}
233
446
234
	public void setTarget(Notifier newTarget) {
447
	public void setTarget(Notifier newTarget) {
235
		// get the old resource set
448
		// get the old resource set
Lines 260-265 Link Here
260
		Map savedURIs = new HashMap();
473
		Map savedURIs = new HashMap();
261
474
262
		ResourceSet rset = getResourceSet();
475
		ResourceSet rset = getResourceSet();
476
		
477
		if (rset == null)
478
			return;
263
479
264
		for (Iterator i = rset.getResources().iterator(); i.hasNext();) {
480
		for (Iterator i = rset.getResources().iterator(); i.hasNext();) {
265
481
Lines 387-404 Link Here
387
				.hasNext();) {
603
				.hasNext();) {
388
604
389
				Resource resource = (Resource) i.next();
605
				Resource resource = (Resource) i.next();
390
606
				normalize(resource, converter);
391
				URI uri = resource.getURI();
392
393
				if ((EMFCoreConstants.PATH_MAP_SCHEME.equals(uri.scheme()))
394
					&& (resource instanceof GMFResource)) {
395
396
					((GMFResource) resource)
397
						.setRawURI(converter.normalize(uri));
398
				}
399
			}
607
			}
400
		}
608
		}
401
	}
609
	}
610
	
611
	private void normalize(Resource resource, URIConverter converter) {
612
		URI uri = resource.getURI();
613
		
614
		if (uri == null)
615
			return;
616
		
617
		if ((EMFCoreConstants.PATH_MAP_SCHEME.equals(uri.scheme()))
618
				&& (resource instanceof GMFResource)) {
619
620
				((GMFResource) resource)
621
					.setRawURI(converter.normalize(uri));
622
			}
623
	}
402
624
403
	/**
625
	/**
404
	 * Denormalize the URI of a set of resources.
626
	 * Denormalize the URI of a set of resources.
Lines 415-428 Link Here
415
				.hasNext();) {
637
				.hasNext();) {
416
638
417
				Resource resource = (Resource) i.next();
639
				Resource resource = (Resource) i.next();
418
640
				denormalize(resource, converter);
419
				URI uri = resource.getURI();
420
421
				if (resource instanceof GMFResource)
422
					((GMFResource) resource).setURI(converter.normalize(uri));
423
			}
641
			}
424
		}
642
		}
425
	}
643
	}
644
	
645
	private void denormalize(Resource resource, URIConverter converter) {
646
		URI uri = resource.getURI();
647
		
648
		if (uri == null)
649
			return;
650
651
		if (resource instanceof GMFResource)
652
			((GMFResource) resource).setURI(converter.normalize(uri));
653
	}
426
654
427
	/**
655
	/**
428
	 * Make a pathmap uri from a pathmap variable name.
656
	 * Make a pathmap uri from a pathmap variable name.
Lines 454-457 Link Here
454
	private Map getURIMap() {
682
	private Map getURIMap() {
455
		return getResourceSet().getURIConverter().getURIMap();
683
		return getResourceSet().getURIConverter().getURIMap();
456
	}
684
	}
685
686
	/**
687
	 * Denormalizes a given resource's URI to a pathmap URI if it is possible.
688
	 * 
689
	 * @param uri A file or platform URI that has been denormalized as much
690
	 *  possible.
691
	 *  
692
	 * @return The original URI if it could not be denormalized any further
693
	 *  or a new pathmap URI otherwise.
694
	 */
695
	public static URI denormalizeURI(URI uri) {
696
		if (!uri.isFile()) {
697
			if (!uri.scheme().equals("platform")) { //$NON-NLS-1$
698
				return uri;
699
			} else if (!uri.segment(0).equals("resource")) { //$NON-NLS-1$
700
				return uri;
701
			}
702
		}
703
		
704
		String uriAsString = uri.toString();
705
		
706
		String maxValueString = null;
707
		String maxKey = null;
708
		
709
		synchronized(PATH_MAP) {
710
			for (Iterator i = PATH_MAP.entrySet().iterator(); i.hasNext();) {
711
				Map.Entry entry = (Map.Entry)i.next();
712
				String valueString = (String)entry.getValue();
713
				
714
				// Wipe out the trailing separator from the value if necessary
715
				if (valueString.endsWith("/")) { //$NON-NLS-1$
716
					valueString = valueString.substring(0,valueString.length()-1);
717
				}
718
				
719
				if (uriAsString.startsWith(valueString)
720
					&& (maxValueString == null || 
721
							maxValueString.length() < valueString.length())) {
722
					maxValueString = valueString;
723
					maxKey = (String)entry.getKey();
724
				}
725
			}
726
		}
727
		
728
		if (maxKey != null) {
729
			URI valueURI = URI.createURI(maxValueString);
730
			URI pathmapURI = makeURI(maxKey);
731
			
732
			int segmentStart = valueURI.segmentCount();
733
			int segmentCount = uri.segmentCount();
734
			
735
			for (int j=segmentStart; j < segmentCount; j++) {
736
				pathmapURI = pathmapURI.appendSegment(uri.segment(j));
737
			}
738
			
739
			return pathmapURI;
740
		}
741
		
742
		return uri;
743
	}
457
}
744
}
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 11-17 Link Here
11
 org.eclipse.gmf.runtime.emf.core.internal.exceptions;x-internal:=true,
11
 org.eclipse.gmf.runtime.emf.core.internal.exceptions;x-internal:=true,
12
 org.eclipse.gmf.runtime.emf.core.internal.l10n;x-internal:=true,
12
 org.eclipse.gmf.runtime.emf.core.internal.l10n;x-internal:=true,
13
 org.eclipse.gmf.runtime.emf.core.internal.plugin;x-internal:=true,
13
 org.eclipse.gmf.runtime.emf.core.internal.plugin;x-internal:=true,
14
 org.eclipse.gmf.runtime.emf.core.internal.resources;x-internal:=true,
14
 org.eclipse.gmf.runtime.emf.core.internal.resources;x-friends:="org.eclipse.gmf.runtime.emf.ui",
15
 org.eclipse.gmf.runtime.emf.core.internal.util;x-friends:="org.eclipse.gmf.runtime.emf.type.core",
15
 org.eclipse.gmf.runtime.emf.core.internal.util;x-friends:="org.eclipse.gmf.runtime.emf.type.core",
16
 org.eclipse.gmf.runtime.emf.core.internal.validation;x-internal:=true,
16
 org.eclipse.gmf.runtime.emf.core.internal.validation;x-internal:=true,
17
 org.eclipse.gmf.runtime.emf.core.resources,
17
 org.eclipse.gmf.runtime.emf.core.resources,
(-)src/org/eclipse/gmf/runtime/emf/core/internal/util/Util.java (-300 / +13 lines)
Lines 11-31 Link Here
11
11
12
package org.eclipse.gmf.runtime.emf.core.internal.util;
12
package org.eclipse.gmf.runtime.emf.core.internal.util;
13
13
14
import java.io.File;
15
import java.io.IOException;
16
import java.net.URL;
17
import java.util.Iterator;
14
import java.util.Iterator;
18
import java.util.Map;
19
import java.util.Set;
15
import java.util.Set;
20
16
21
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IContainer;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IWorkspace;
24
import org.eclipse.core.resources.IWorkspaceRoot;
25
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.FileLocator;
27
import org.eclipse.core.runtime.Path;
28
import org.eclipse.core.runtime.Platform;
29
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.common.util.URI;
30
import org.eclipse.emf.ecore.EClass;
20
import org.eclipse.emf.ecore.EClass;
31
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EObject;
Lines 34-44 Link Here
34
import org.eclipse.emf.ecore.resource.ResourceSet;
24
import org.eclipse.emf.ecore.resource.ResourceSet;
35
import org.eclipse.emf.ecore.util.EcoreUtil;
25
import org.eclipse.emf.ecore.util.EcoreUtil;
36
import org.eclipse.emf.transaction.TransactionalEditingDomain;
26
import org.eclipse.emf.transaction.TransactionalEditingDomain;
37
import org.eclipse.gmf.runtime.common.core.util.Trace;
27
import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager;
38
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCoreDebugOptions;
39
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCorePlugin;
40
import org.eclipse.gmf.runtime.emf.core.resources.IResourceHelper;
28
import org.eclipse.gmf.runtime.emf.core.resources.IResourceHelper;
41
import org.osgi.framework.Bundle;
42
29
43
import com.ibm.icu.util.StringTokenizer;
30
import com.ibm.icu.util.StringTokenizer;
44
31
Lines 166-460 Link Here
166
	 * @return the URI denormalized as much as possible
153
	 * @return the URI denormalized as much as possible
167
	 */
154
	 */
168
	public static URI denormalizeURI(URI uri, ResourceSet rset) {
155
	public static URI denormalizeURI(URI uri, ResourceSet rset) {
156
		URI denormalizedURI = uri;
169
157
170
		URI resolvedURI = uri;
158
		// First, check to see if this is a file URI and it is in the workspace.
171
159
		//  If so, we will denormalize first to a platform URI.
172
		if (EMFCoreConstants.PLATFORM_SCHEME.equals(resolvedURI.scheme())) {
160
		if ("file".equals(denormalizedURI.scheme())) { //$NON-NLS-1$
173
161
			IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(java.net.URI.create(denormalizedURI.toString()));
174
			String filePath = getFilePath(rset, resolvedURI);
162
			if (containers.length == 1) {
175
163
				denormalizedURI = URI.createPlatformResourceURI(containers[0].getFullPath().toString(),true);
176
			if ((filePath != null) && (filePath.length() > 0))
177
				resolvedURI = URI.createFileURI(filePath);
178
		}
179
180
		if ((resolvedURI != null) && (resolvedURI.isFile())) {
181
182
			String fileName = resolvedURI.lastSegment();
183
184
			// attempt to convert the URI to a path map URI.
185
			if (fileName != null) {
186
187
				URI prefix = resolvedURI.trimSegments(1);
188
189
				// find a matching pathmap.
190
				URI foundKeyURI = null;
191
				URI foundValURI = null;
192
				int minDiff = Integer.MAX_VALUE;
193
194
				Iterator i = rset.getURIConverter().getURIMap()
195
					.entrySet().iterator();
196
197
				while (i.hasNext()) {
198
199
					Map.Entry entry = (Map.Entry) i.next();
200
201
					if (entry != null) {
202
203
						URI keyURI = (URI) entry.getKey();
204
						URI valURI = (URI) entry.getValue();
205
206
						if ((keyURI.isHierarchical())
207
							&& (EMFCoreConstants.PATH_MAP_SCHEME.equals(keyURI
208
								.scheme())) && (valURI.isFile())) {
209
210
							int diff = computeDiff(valURI, prefix);
211
212
							if ((diff >= 0) && (diff < minDiff)) {
213
214
								minDiff = diff;
215
216
								foundKeyURI = keyURI;
217
								foundValURI = valURI;
218
219
								if (minDiff == 0)
220
									break;
221
							}
222
						}
223
					}
224
				}
225
226
				if ((foundKeyURI != null) && (foundValURI != null))
227
					return resolvedURI.replacePrefix(foundValURI, foundKeyURI);
228
			}
164
			}
229
230
			// attempt to convert URI to a platform URI.
231
			URI platformURI = getPlatformURI(uri);
232
233
			if (platformURI != null)
234
				return platformURI;
235
		}
165
		}
166
		
167
		// Second, we will now attempt to find a pathmap for this URI
168
		denormalizedURI = PathmapManager.denormalizeURI(denormalizedURI);
236
169
237
		return uri;
170
		return denormalizedURI;
238
	}
239
	
240
	/**
241
	 * Obtains, if possible, an absolute filesystem path corresponding to the
242
	 * specified URI.
243
	 * 
244
	 * @param resourceSet a resource set context for the URI normalization
245
	 * @param uri the URI to normalize to a file path
246
	 * 
247
	 * @return the file path, or <code>null</code> if the URI does not resolve
248
	 *      to a file
249
	 */
250
	private static String getFilePath(ResourceSet resourceSet, URI uri) {
251
252
		String filePath = null;
253
254
		if (uri == null) {
255
256
			filePath = EMFCoreConstants.EMPTY_STRING;
257
			return filePath;
258
		}
259
260
		if ((resourceSet != null)
261
			&& (EMFCoreConstants.PATH_MAP_SCHEME.equals(uri.scheme())))
262
			uri = resourceSet.getURIConverter().normalize(uri);
263
264
		if (uri.isFile())
265
			filePath = uri.toFileString();
266
267
		else if (EMFCoreConstants.PLATFORM_SCHEME.equals(uri.scheme())) {
268
269
			String[] segments = uri.segments();
270
271
			if (segments.length > 2) {
272
273
				if (EMFCoreConstants.RESOURCE.equals(segments[0])) {
274
275
					IProject project = null;
276
277
					IWorkspace workspace = ResourcesPlugin.getWorkspace();
278
279
					if (workspace != null) {
280
281
						IWorkspaceRoot root = workspace.getRoot();
282
283
						if (root != null)
284
							project = root.getProject(URI.decode(segments[1]));
285
					}
286
287
					if ((project != null) && (project.exists())) {
288
289
						StringBuffer path = new StringBuffer();
290
291
						path.append(project.getLocation().toString());
292
293
						for (int i = 2; i < segments.length; i++) {
294
295
							path.append(EMFCoreConstants.PATH_SEPARATOR);
296
297
							path.append(URI.decode(segments[i]));
298
						}
299
300
						filePath = path.toString();
301
					}
302
303
				} else if (EMFCoreConstants.PLUGIN.equals(segments[0])) {
304
305
					Bundle bundle = Platform.getBundle(URI.decode(segments[1]));
306
307
					if (bundle != null) {
308
309
						StringBuffer path = new StringBuffer();
310
311
						for (int i = 2; i < segments.length; i++) {
312
313
							path.append(URI.decode(segments[i]));
314
315
							path.append(EMFCoreConstants.PATH_SEPARATOR);
316
						}
317
318
						URL url = bundle.getEntry(path.toString());
319
320
						if (url != null) {
321
322
							try {
323
324
								url = FileLocator.resolve(url);
325
326
								if (url != null) {
327
328
									if (EMFCoreConstants.FILE_SCHEME.equals(url
329
										.getProtocol()))
330
										filePath = url.getPath();
331
								}
332
333
							} catch (IOException e) {
334
335
								Trace.catching(EMFCorePlugin.getDefault(),
336
									EMFCoreDebugOptions.EXCEPTIONS_CATCHING,
337
									Util.class, "getFilePath", e); //$NON-NLS-1$
338
							}
339
						}
340
					}
341
				}
342
			}
343
		}
344
345
		if (filePath == null)
346
			filePath = EMFCoreConstants.EMPTY_STRING;
347
348
		else {
349
350
			if (File.separatorChar != EMFCoreConstants.PATH_SEPARATOR)
351
				filePath = filePath.replace(EMFCoreConstants.PATH_SEPARATOR,
352
					File.separatorChar);
353
		}
354
355
		return filePath;
356
	}
357
358
	/**
359
	 * Converts a file URI to a platform URI.
360
	 */
361
	private static URI getPlatformURI(URI uri) {
362
363
		if (EMFCoreConstants.PLATFORM_SCHEME.equals(uri.scheme()))
364
			return URI.createURI(uri.toString(), true);
365
366
		IFile file = findFileInWorkspace(uri);
367
368
		if (file != null) {
369
370
			IProject project = file.getProject();
371
372
			if (project != null) {
373
374
				StringBuffer pathName = new StringBuffer(project.getName());
375
376
				pathName.append(EMFCoreConstants.PATH_SEPARATOR);
377
				pathName.append(file.getProjectRelativePath().toString());
378
379
				return URI.createURI(URI.createPlatformResourceURI(
380
					pathName.toString(),true).toString(), true);
381
			}
382
		}
383
384
		return null;
385
	}
386
387
	/**
388
	 * Finds a file in the workspace given its file URI.
389
	 */
390
	private static IFile findFileInWorkspace(URI uri) {
391
392
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
393
394
		if (workspace != null) {
395
396
			IWorkspaceRoot root = workspace.getRoot();
397
398
			if (root != null) {
399
400
				IFile[] files = root.findFilesForLocation(new Path(uri
401
					.toFileString()));
402
403
				if (files != null) {
404
405
					for (int i = 0; i < files.length; i++) {
406
407
						IFile file = files[i];
408
409
						IProject project = file.getProject();
410
411
						if (project != null)
412
							return file;
413
					}
414
				}
415
			}
416
		}
417
418
		return null;
419
	}
420
421
	/**
422
	 * Computes segement count difference between two URIs if one is a subset of
423
	 * the other.
424
	 */
425
	private static int computeDiff(URI subURI, URI containerURI) {
426
427
		int subSegmentCount = subURI.segmentCount();
428
		int containerSegmentCount = containerURI.segmentCount();
429
430
		if ((subSegmentCount > 0)
431
			&& (subURI.segment(subSegmentCount - 1)
432
				.equals(EMFCoreConstants.EMPTY_STRING))) {
433
434
			subURI = subURI.trimSegments(1);
435
			subSegmentCount--;
436
		}
437
438
		if ((containerSegmentCount > 0)
439
			&& (containerURI.segment(containerSegmentCount - 1)
440
				.equals(EMFCoreConstants.EMPTY_STRING))) {
441
442
			containerURI = containerURI.trimSegments(1);
443
			containerSegmentCount--;
444
		}
445
446
		int diff = containerSegmentCount - subSegmentCount;
447
448
		if (diff < 0)
449
			return -1;
450
451
		else if (diff > 0)
452
			containerURI = containerURI.trimSegments(diff);
453
454
		if (!subURI.equals(containerURI))
455
			return -1;
456
457
		return diff;
458
	}
171
	}
459
172
460
	/**
173
	/**
(-)plugin.properties (+2 lines)
Lines 22-24 Link Here
22
createWizardCategory = Modeling
22
createWizardCategory = Modeling
23
ext.modelingNewWizards = New Modeling Wizards
23
ext.modelingNewWizards = New Modeling Wizards
24
24
25
# Path map preference page title
26
pathMapLabel=Path Maps
(-)plugin.xml (+9 lines)
Lines 25-28 Link Here
25
            id="org.eclipse.gmf.runtime.emf.ui.modeling">
25
            id="org.eclipse.gmf.runtime.emf.ui.modeling">
26
      </category>
26
      </category>
27
  </extension>
27
  </extension>
28
  
29
  <extension
30
         point="org.eclipse.ui.preferencePages">
31
      <page
32
            category="xtools.modeling"
33
            class="org.eclipse.gmf.runtime.emf.ui.internal.preferences.PathmapsPreferencePage"
34
            id="pathmaps"
35
            name="%pathMapLabel"/>
36
   </extension>
28
</plugin>
37
</plugin>
(-)src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties (+15 lines)
Lines 60-62 Link Here
60
60
61
# Output view category for live validation problem messages.
61
# Output view category for live validation problem messages.
62
Validation_outputProviderCategory=Rational Modeling
62
Validation_outputProviderCategory=Rational Modeling
63
64
#
65
# Messages pertaining to the assigning pathmaps to existing eclipse path variables
66
#  to be used in modeling. These messages are used in a preference page.
67
#
68
# ================================ BEGIN ==================================================
69
PathmapsPreferencePage_mainDescription=Choose path variables defined in <a>''{0}''</a> to use for modeling artifacts.
70
PathmapsPreferencePage_availablePathVariables=Available path variables:
71
PathmapsPreferencePage_pathVariablesUsedInModeling=Path variables for modeling:
72
PathmapsPreferencePage_addChevron=\ >
73
PathmapsPreferencePage_removeChevron=\ <
74
PathmapsPreferencePage_addAllChevron=\ >>
75
PathmapsPreferencePage_removeAllChevron=\ <<
76
PathmapsPreferencePage_incompatiblePathVariableErrorMessage=The selected path variable(s) cannot be supported in a modeling environment.
77
# ==================================== END =================================================
(-)src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java (+8 lines)
Lines 44-49 Link Here
44
	public static String Validation_liveDialogTitle;
44
	public static String Validation_liveDialogTitle;
45
	public static String Validation_dontShowCheck;
45
	public static String Validation_dontShowCheck;
46
	public static String Validation_outputProviderCategory;
46
	public static String Validation_outputProviderCategory;
47
	public static String PathmapsPreferencePage_availablePathVariables;
48
	public static String PathmapsPreferencePage_pathVariablesUsedInModeling;
49
	public static String PathmapsPreferencePage_addChevron;
50
	public static String PathmapsPreferencePage_removeChevron;
51
	public static String PathmapsPreferencePage_incompatiblePathVariableErrorMessage;
52
	public static String PathmapsPreferencePage_mainDescription;
53
	public static String PathmapsPreferencePage_addAllChevron;
54
	public static String PathmapsPreferencePage_removeAllChevron;
47
55
48
	static {
56
	static {
49
		NLS.initializeMessages(BUNDLE_NAME, EMFUIMessages.class);
57
		NLS.initializeMessages(BUNDLE_NAME, EMFUIMessages.class);
(-)src/org/eclipse/gmf/runtime/emf/ui/internal/preferences/PathmapsPreferencePage.java (+308 lines)
Added Link Here
1
package org.eclipse.gmf.runtime.emf.ui.internal.preferences;
2
3
import java.util.Iterator;
4
5
import org.eclipse.core.resources.IPathVariableChangeEvent;
6
import org.eclipse.core.resources.IPathVariableChangeListener;
7
import org.eclipse.core.resources.ResourcesPlugin;
8
import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager;
9
import org.eclipse.gmf.runtime.emf.ui.internal.l10n.EMFUIMessages;
10
import org.eclipse.jface.preference.PreferencePage;
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.events.SelectionEvent;
13
import org.eclipse.swt.events.SelectionListener;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.swt.widgets.List;
21
import org.eclipse.ui.IWorkbench;
22
import org.eclipse.ui.IWorkbenchPreferencePage;
23
import org.eclipse.ui.dialogs.PreferenceLinkArea;
24
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
25
26
27
public class PathmapsPreferencePage
28
	extends PreferencePage implements IWorkbenchPreferencePage {
29
30
	private List referencedPathVariables;
31
	private List pathVariables;
32
	private Button add;
33
	private IPathVariableChangeListener pathVariableChangeListener;
34
	private boolean disposed = true;
35
36
	protected void initHelp() {
37
		// No context-sensitive help for now.
38
	}
39
40
	protected Control createContents(Composite parent) {
41
		GridData gridData = null;
42
		Composite composite = new Composite(parent, SWT.NONE);
43
		composite.setLayout(new GridLayout(3, false));
44
		gridData = new GridData(GridData.FILL_HORIZONTAL);
45
		gridData.grabExcessHorizontalSpace = true;
46
		gridData.horizontalSpan = 2;
47
		composite.setLayoutData(gridData);
48
		
49
        PreferenceLinkArea pathVariablesArea = new PreferenceLinkArea(
50
            composite,
51
            SWT.NONE,
52
            "org.eclipse.ui.preferencePages.LinkedResources", EMFUIMessages.PathmapsPreferencePage_mainDescription, //$NON-NLS-1$
53
            (IWorkbenchPreferenceContainer) getContainer(), null);
54
		gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
55
		gridData.grabExcessHorizontalSpace = true;
56
		gridData.grabExcessVerticalSpace = false;
57
		gridData.horizontalSpan = 3;
58
		pathVariablesArea.getControl().setLayoutData(gridData);
59
		
60
		Label pathVariablesLabel = new Label(composite, SWT.LEFT);
61
		gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
62
		gridData.grabExcessHorizontalSpace = true;
63
		gridData.grabExcessVerticalSpace = false;
64
		gridData.horizontalSpan = 2;
65
		gridData.verticalIndent = 20;
66
		pathVariablesLabel.setLayoutData(gridData);
67
		pathVariablesLabel.setText(EMFUIMessages.PathmapsPreferencePage_availablePathVariables);
68
		
69
		Label referencedPathVariablesLabel = new Label(composite, SWT.LEFT);
70
		gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
71
		gridData.grabExcessHorizontalSpace = true;
72
		gridData.grabExcessVerticalSpace = false;
73
		gridData.horizontalSpan = 1;
74
		gridData.verticalIndent = 20;
75
		referencedPathVariablesLabel.setLayoutData(gridData);
76
		referencedPathVariablesLabel.setText(EMFUIMessages.PathmapsPreferencePage_pathVariablesUsedInModeling);
77
		
78
		pathVariables = new List(composite,SWT.MULTI | SWT.BORDER);
79
		gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
80
		gridData.grabExcessHorizontalSpace = true;
81
		gridData.grabExcessVerticalSpace = true;
82
		gridData.horizontalSpan = 1;
83
		pathVariables.setLayoutData(gridData);
84
		
85
		Composite buttonComposite = new Composite(composite, SWT.NONE);
86
		buttonComposite.setLayout(new GridLayout(1, false));
87
		add = new Button(buttonComposite, SWT.CENTER);
88
		add.setText(EMFUIMessages.PathmapsPreferencePage_addChevron);
89
		gridData = new GridData(GridData.FILL_HORIZONTAL);
90
		gridData.grabExcessHorizontalSpace = true;
91
		gridData.grabExcessVerticalSpace = false;
92
		gridData.horizontalSpan = 1;
93
		add.setLayoutData(gridData);
94
		Button addAll = new Button(buttonComposite, SWT.CENTER);
95
		addAll.setText(EMFUIMessages.PathmapsPreferencePage_addAllChevron);
96
		gridData = new GridData(GridData.FILL_HORIZONTAL);
97
		gridData.grabExcessHorizontalSpace = true;
98
		gridData.grabExcessVerticalSpace = false;
99
		addAll.setLayoutData(gridData);
100
		Button remove = new Button(buttonComposite,SWT.CENTER);
101
		remove.setText(EMFUIMessages.PathmapsPreferencePage_removeChevron);
102
		gridData = new GridData(GridData.FILL_HORIZONTAL);
103
		gridData.grabExcessHorizontalSpace = true;
104
		gridData.grabExcessVerticalSpace = false;
105
		gridData.horizontalSpan = 1;
106
		gridData.verticalIndent = 10;
107
		remove.setLayoutData(gridData);
108
		Button removeAll = new Button(buttonComposite, SWT.CENTER);
109
		removeAll.setText(EMFUIMessages.PathmapsPreferencePage_removeAllChevron);
110
		gridData = new GridData(GridData.FILL_HORIZONTAL);
111
		gridData.grabExcessHorizontalSpace = true;
112
		gridData.grabExcessVerticalSpace = false;
113
		gridData.horizontalSpan=1;
114
		removeAll.setLayoutData(gridData);
115
		
116
		gridData = new GridData(GridData.FILL_HORIZONTAL);
117
		gridData.grabExcessHorizontalSpace = false;
118
		gridData.grabExcessVerticalSpace = false;
119
		gridData.horizontalSpan = 1;
120
		buttonComposite.setLayoutData(gridData);
121
		
122
		referencedPathVariables = new List(composite,SWT.MULTI | SWT.BORDER);
123
		gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
124
		gridData.grabExcessHorizontalSpace = true;
125
		gridData.grabExcessVerticalSpace = true;
126
		gridData.horizontalSpan = 1;
127
		referencedPathVariables.setLayoutData(gridData);
128
		
129
		pathVariables.addSelectionListener(new SelectionListener() {
130
			public void widgetSelected(SelectionEvent e) {
131
				referencedPathVariables.deselectAll();
132
				
133
				if (!validateSelections(pathVariables.getSelection())) {
134
					setMessage(EMFUIMessages.PathmapsPreferencePage_incompatiblePathVariableErrorMessage,ERROR);
135
					add.setEnabled(false);
136
				} else {
137
					setMessage(null);
138
					add.setEnabled(true);
139
				}
140
			}
141
142
			public void widgetDefaultSelected(SelectionEvent e) {
143
				// No action necessary
144
			}
145
		});
146
		
147
		referencedPathVariables.addSelectionListener(new SelectionListener() {
148
			public void widgetSelected(SelectionEvent e) {
149
				setMessage(null);
150
				add.setEnabled(true);
151
				pathVariables.deselectAll();
152
			}
153
154
			public void widgetDefaultSelected(SelectionEvent e) {
155
				// No action necessary
156
			}
157
		});
158
		
159
		add.addSelectionListener(new SelectionListener() {
160
			public void widgetSelected(SelectionEvent e) {
161
				String[] selections = pathVariables.getSelection();
162
				
163
				for (int i=0; i<selections.length; i++) {
164
					referencedPathVariables.add(selections[i]);
165
					pathVariables.remove(selections[i]);
166
				}
167
			}
168
169
			public void widgetDefaultSelected(SelectionEvent e) {
170
				// No action is necessary
171
			}
172
		});
173
		
174
		addAll.addSelectionListener(new SelectionListener() {
175
			public void widgetDefaultSelected(SelectionEvent e) {
176
				// No action necessary
177
			}
178
179
			public void widgetSelected(SelectionEvent e) {
180
				String[] items = pathVariables.getItems();
181
				
182
				for (int i=0; i<items.length; i++) {
183
					if (validateSelections(new String[]{items[i]})) {
184
						referencedPathVariables.add(items[i]);
185
						pathVariables.remove(items[i]);
186
					}
187
				}
188
			}
189
		});
190
		
191
		remove.addSelectionListener(new SelectionListener() {
192
			public void widgetSelected(SelectionEvent e) {
193
				String[] selections = referencedPathVariables.getSelection();
194
				
195
				for (int i=0; i<selections.length; i++) {
196
					pathVariables.add(selections[i]);
197
					referencedPathVariables.remove(selections[i]);
198
				}
199
			}
200
201
			public void widgetDefaultSelected(SelectionEvent e) {
202
				// No action is necessary
203
			}
204
		});
205
		
206
		removeAll.addSelectionListener(new SelectionListener() {
207
			public void widgetDefaultSelected(SelectionEvent e) {
208
				// No action is necessary
209
			}
210
211
			public void widgetSelected(SelectionEvent e) {
212
				String[] items = referencedPathVariables.getItems();
213
				
214
				for (int i=0; i<items.length; i++) {
215
					pathVariables.add(items[i]);
216
					referencedPathVariables.remove(items[i]);
217
				}
218
			}
219
		});
220
		
221
		initializeContents();
222
		
223
		// In case of any changes to the path variables, we will refresh ourselves to show
224
		//  the up-to-date information.
225
		pathVariableChangeListener = new IPathVariableChangeListener() {
226
			public void pathVariableChanged(IPathVariableChangeEvent event) {
227
				referencedPathVariables.getShell().getDisplay().asyncExec(new Runnable() {
228
					public void run() {
229
						if (!PathmapsPreferencePage.this.disposed) {
230
							performDefaults();
231
						}
232
					}
233
				});
234
			}
235
		};
236
		ResourcesPlugin.getWorkspace().getPathVariableManager().addChangeListener(pathVariableChangeListener);
237
		
238
		disposed = false;
239
		
240
		return composite;
241
	}
242
	
243
	private boolean validateSelections(String[] selections) {
244
		if (selections.length == 0)
245
			return false;
246
		
247
		for (int i=0; i<selections.length; i++) {
248
			String selection = selections[i];
249
			
250
			if (!PathmapManager.isCompatiblePathVariable(selection)) {
251
				return false;
252
			}
253
		}
254
		return true;
255
	}
256
257
	private void initializeContents() {
258
		setMessage(null);
259
		add.setEnabled(true);
260
		referencedPathVariables.removeAll();
261
		pathVariables.removeAll();
262
		
263
		String[] pathVariableNames = ResourcesPlugin.getWorkspace().getPathVariableManager().getPathVariableNames();
264
		for (int i=0; i<pathVariableNames.length; i++) {
265
			pathVariables.add(pathVariableNames[i]);
266
		}
267
		
268
		for (Iterator i = PathmapManager.getPathVariableReferences().iterator(); i.hasNext();) {
269
			String pathVariable = (String)i.next();
270
			referencedPathVariables.add(pathVariable);
271
			pathVariables.remove(pathVariable);
272
		}
273
	}
274
275
	public void init(IWorkbench workbench) {
276
		// No initialization is necessary.
277
	}
278
	
279
	protected void performDefaults() {
280
		initializeContents();
281
		super.performDefaults();
282
	}
283
	
284
	public boolean performOk() {
285
		String[] nonReferencedPathVariables = pathVariables.getItems();
286
		for (int i=0; i<nonReferencedPathVariables.length; i++) {
287
			PathmapManager.removePathVariableReference(nonReferencedPathVariables[i]);
288
		}
289
		
290
		String[] variablesToReference = referencedPathVariables.getItems();
291
		for (int i=0; i<variablesToReference.length; i++) {
292
			PathmapManager.addPathVariableReference(variablesToReference[i]);
293
		}
294
		
295
		PathmapManager.updatePreferenceStore();
296
		
297
		return true;
298
	}
299
	
300
	public void dispose() {
301
		disposed = true;
302
		if (pathVariableChangeListener != null) {
303
			ResourcesPlugin.getWorkspace().getPathVariableManager().removeChangeListener(pathVariableChangeListener);
304
			pathVariableChangeListener = null;
305
		}
306
		super.dispose();
307
	}
308
}
(-)src/org/eclipse/gmf/examples/runtime/diagram/logic/semantic/presentation/ResourceLoadedListener.java (-2 / +9 lines)
Lines 21-26 Link Here
21
21
22
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Path;
25
import org.eclipse.emf.common.notify.Notification;
26
import org.eclipse.emf.common.notify.Notification;
26
import org.eclipse.emf.common.util.URI;
27
import org.eclipse.emf.common.util.URI;
Lines 160-172 Link Here
160
		
161
		
161
		URI normalizedURI = domain.getResourceSet().getURIConverter().normalize(resource.getURI());
162
		URI normalizedURI = domain.getResourceSet().getURIConverter().normalize(resource.getURI());
162
		
163
		
163
		if (normalizedURI.scheme().equals("file")) { //$NON-NLS-1$
164
		if ("file".equals(normalizedURI.scheme())) { //$NON-NLS-1$
164
			IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(URI.decode(normalizedURI.devicePath())));
165
			IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(URI.decode(normalizedURI.devicePath())));
165
			if (files.length > 0) {
166
			if (files.length > 0) {
166
				result = files[0];
167
				result = files[0];
167
			}
168
			}
168
		} else  {
169
		} else  {
169
			result = WorkspaceSynchronizer.getFile(resource);
170
			if ("platform".equals(normalizedURI.scheme()) && (normalizedURI.segmentCount() > 2)) { //$NON-NLS-1$
171
				if ("resource".equals(normalizedURI.segment(0))) { //$NON-NLS-1$
172
					IPath path = new Path(URI.decode(normalizedURI.path())).removeFirstSegments(1);
173
					
174
					result = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
175
				}
176
			}
170
		}
177
		}
171
		return result;
178
		return result;
172
	}
179
	}

Return to bug 131829