View | Details | Raw Unified | Return to bug 189703 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gmf/internal/common/migrate/MigrationDelegate.java (-3 / +5 lines)
Lines 15-21 Link Here
15
import org.eclipse.emf.ecore.EFactory;
15
import org.eclipse.emf.ecore.EFactory;
16
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.EStructuralFeature;
17
import org.eclipse.emf.ecore.EStructuralFeature;
18
import org.eclipse.emf.ecore.xmi.XMLResource;
18
import org.eclipse.emf.ecore.resource.Resource;
19
19
20
public interface MigrationDelegate {
20
public interface MigrationDelegate {
21
	
21
	
Lines 33-39 Link Here
33
33
34
	public boolean isMigrationApplied();
34
	public boolean isMigrationApplied();
35
35
36
	public String getID(EObject obj);
36
	public void setResource(Resource resource);
37
37
38
	public void setResource(XMLResource resource);
38
	public boolean setManyReference(EObject object, EStructuralFeature feature, Object[] values);
39
40
	public EObject findEObject(String uriFragment);
39
}
41
}
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationHelper.java (-8 / +11 lines)
Lines 10-20 Link Here
10
 */
10
 */
11
package org.eclipse.gmf.internal.common.migrate;
11
package org.eclipse.gmf.internal.common.migrate;
12
12
13
import java.util.List;
14
13
import org.eclipse.emf.ecore.EClass;
15
import org.eclipse.emf.ecore.EClass;
14
import org.eclipse.emf.ecore.EClassifier;
16
import org.eclipse.emf.ecore.EClassifier;
15
import org.eclipse.emf.ecore.EFactory;
17
import org.eclipse.emf.ecore.EFactory;
16
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.ecore.EStructuralFeature;
20
import org.eclipse.emf.ecore.xmi.XMIException;
18
import org.eclipse.emf.ecore.xmi.XMLResource;
21
import org.eclipse.emf.ecore.xmi.XMLResource;
19
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
22
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
20
23
Lines 43-60 Link Here
43
	}
46
	}
44
47
45
	@Override
48
	@Override
46
	public String getID(EObject obj) {
49
	public List<XMIException> setManyReference(ManyReference reference, String location) {
47
		String result = myDelegate.getID(obj);
50
		List<XMIException> result = null;
48
		if (result == null) {
51
		if (!myDelegate.setManyReference(reference.getObject(), reference.getFeature(), reference.getValues())) {
49
			result = super.getID(obj);
52
			result = super.setManyReference(reference, location);
50
		}
53
		}
51
		return result;
54
		return result;
52
	}
55
	}
53
56
54
	public void setXMLMap(XMLResource.XMLMap map) {
55
		//map.setIDAttributeName("");
56
	}
57
58
	@Override
57
	@Override
59
	public void setValue(EObject object, EStructuralFeature feature, Object value, int position) {
58
	public void setValue(EObject object, EStructuralFeature feature, Object value, int position) {
60
		if (!myDelegate.setValue(object, feature, value, position)) {
59
		if (!myDelegate.setValue(object, feature, value, position)) {
Lines 86-89 Link Here
86
		myDelegate.postProcess();
85
		myDelegate.postProcess();
87
	}
86
	}
88
87
88
	public EObject findEObject(String uriFragment) {
89
		return myDelegate.findEObject(uriFragment);
90
	}
91
89
}
92
}
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationResource.java (+7 lines)
Lines 16-21 Link Here
16
import java.util.Map;
16
import java.util.Map;
17
17
18
import org.eclipse.emf.common.util.URI;
18
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.resource.Resource;
20
import org.eclipse.emf.ecore.resource.Resource;
20
import org.eclipse.emf.ecore.xmi.XMLHelper;
21
import org.eclipse.emf.ecore.xmi.XMLHelper;
21
import org.eclipse.gmf.internal.common.ToolingResourceFactory.ToolResource;
22
import org.eclipse.gmf.internal.common.ToolingResourceFactory.ToolResource;
Lines 42-47 Link Here
42
		}
43
		}
43
	}
44
	}
44
45
46
	@Override
47
	public EObject getEObject(String uriFragment) {
48
		EObject result = myMigrationHelper != null ? myMigrationHelper.findEObject(uriFragment) : null;
49
		return result == null ? super.getEObject(uriFragment) : result;
50
	}
51
45
	protected void handlePostLoadSuccess() {
52
	protected void handlePostLoadSuccess() {
46
		if (myMigrationHelper != null && myMigrationHelper.isMigrationApplied()) {
53
		if (myMigrationHelper != null && myMigrationHelper.isMigrationApplied()) {
47
			Diagnostic diagnostic = MigrationResource.createMessageDiagnostic(this, Messages.oldModelVersionLoadedMigrationRequired);
54
			Diagnostic diagnostic = MigrationResource.createMessageDiagnostic(this, Messages.oldModelVersionLoadedMigrationRequired);
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationDelegateImpl.java (-9 / +13 lines)
Lines 26-32 Link Here
26
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.emf.ecore.EStructuralFeature;
27
import org.eclipse.emf.ecore.EcoreFactory;
27
import org.eclipse.emf.ecore.EcoreFactory;
28
import org.eclipse.emf.ecore.EcorePackage;
28
import org.eclipse.emf.ecore.EcorePackage;
29
import org.eclipse.emf.ecore.xmi.XMLResource;
29
import org.eclipse.emf.ecore.resource.Resource;
30
30
31
public class MigrationDelegateImpl implements MigrationDelegate {
31
public class MigrationDelegateImpl implements MigrationDelegate {
32
	private final EStructuralFeature myDeletedAttribute = EcoreFactory.eINSTANCE.createEAttribute();
32
	private final EStructuralFeature myDeletedAttribute = EcoreFactory.eINSTANCE.createEAttribute();
Lines 44-50 Link Here
44
	private Map<EClass, Map<String, EStructuralFeature>> myRenamedAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
44
	private Map<EClass, Map<String, EStructuralFeature>> myRenamedAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
45
	private Map<String, EClassifier> myRenamedTypes = new HashMap<String, EClassifier>();
45
	private Map<String, EClassifier> myRenamedTypes = new HashMap<String, EClassifier>();
46
	private Map<EClass, Map<String, EStructuralFeature>> myRenamedParentAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
46
	private Map<EClass, Map<String, EStructuralFeature>> myRenamedParentAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
47
	private XMLResource myResource;
47
	private Resource myResource;
48
	
48
	
49
	public void registerDeletedAttributes(EClassifier classifier, String... deletedAttrNames) {
49
	public void registerDeletedAttributes(EClassifier classifier, String... deletedAttrNames) {
50
		assert !myDeletedAttributes.containsKey(classifier);
50
		assert !myDeletedAttributes.containsKey(classifier);
Lines 113-119 Link Here
113
		}
113
		}
114
		return result;
114
		return result;
115
	}
115
	}
116
116
	
117
	public EClassifier getRenamedType(String typeName) {
117
	public EClassifier getRenamedType(String typeName) {
118
		return myRenamedTypes.get(typeName);
118
		return myRenamedTypes.get(typeName);
119
	}
119
	}
Lines 156-171 Link Here
156
		return null;
156
		return null;
157
	}
157
	}
158
	
158
	
159
	public String getID(EObject obj) {
160
		return null;
161
	}
162
	
163
	public void postProcess() {
159
	public void postProcess() {
164
	}
160
	}
165
161
166
	public void processObject(EObject result) {
162
	public void processObject(EObject result) {
167
	}
163
	}
168
164
165
	public boolean setManyReference(EObject object, EStructuralFeature feature, Object[] values) {
166
		return false;
167
	}
168
	
169
	public boolean isMigrationApplied() {
169
	public boolean isMigrationApplied() {
170
		return isMigrationApplied;
170
		return isMigrationApplied;
171
	}
171
	}
Lines 201-211 Link Here
201
		return attr;
201
		return attr;
202
	}
202
	}
203
203
204
	public void setResource(XMLResource resource) {
204
	public void setResource(Resource resource) {
205
		myResource = resource;
205
		myResource = resource;
206
	}
206
	}
207
	
207
	
208
	protected XMLResource getResource() {
208
	protected Resource getResource() {
209
		return myResource;
209
		return myResource;
210
	}
210
	}
211
212
	public EObject findEObject(String uriFragment) {
213
		return null;
214
	}
211
}
215
}
(-)src/org/eclipse/gmf/internal/graphdef/util/MigrationDelegate.java (-40 / +215 lines)
Lines 10-40 Link Here
10
 */
10
 */
11
package org.eclipse.gmf.internal.graphdef.util;
11
package org.eclipse.gmf.internal.graphdef.util;
12
12
13
import java.util.ArrayList;
14
import java.util.Collection;
13
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.Iterator;
14
import java.util.Map;
17
import java.util.Map;
15
18
16
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.EReference;
20
import org.eclipse.emf.ecore.EReference;
18
import org.eclipse.emf.ecore.EStructuralFeature;
21
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.ecore.resource.Resource;
22
import org.eclipse.emf.ecore.resource.Resource;
20
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
23
import org.eclipse.emf.ecore.util.EcoreUtil;
21
import org.eclipse.gmf.gmfgraph.ChildAccess;
24
import org.eclipse.gmf.gmfgraph.ChildAccess;
22
import org.eclipse.gmf.gmfgraph.Compartment;
25
import org.eclipse.gmf.gmfgraph.Compartment;
26
import org.eclipse.gmf.gmfgraph.CustomFigure;
27
import org.eclipse.gmf.gmfgraph.DecorationFigure;
23
import org.eclipse.gmf.gmfgraph.DiagramElement;
28
import org.eclipse.gmf.gmfgraph.DiagramElement;
24
import org.eclipse.gmf.gmfgraph.DiagramLabel;
29
import org.eclipse.gmf.gmfgraph.DiagramLabel;
25
import org.eclipse.gmf.gmfgraph.Figure;
30
import org.eclipse.gmf.gmfgraph.Figure;
31
import org.eclipse.gmf.gmfgraph.FigureAccessor;
26
import org.eclipse.gmf.gmfgraph.FigureDescriptor;
32
import org.eclipse.gmf.gmfgraph.FigureDescriptor;
27
import org.eclipse.gmf.gmfgraph.FigureGallery;
33
import org.eclipse.gmf.gmfgraph.FigureGallery;
28
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
34
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
29
import org.eclipse.gmf.gmfgraph.GMFGraphPackage;
35
import org.eclipse.gmf.gmfgraph.GMFGraphPackage;
30
import org.eclipse.gmf.gmfgraph.Node;
36
import org.eclipse.gmf.gmfgraph.PolylineConnection;
31
import org.eclipse.gmf.gmfgraph.RealFigure;
37
import org.eclipse.gmf.gmfgraph.RealFigure;
32
import org.eclipse.gmf.internal.common.migrate.MigrationDelegateImpl;
38
import org.eclipse.gmf.internal.common.migrate.MigrationDelegateImpl;
33
39
34
class MigrationDelegate extends MigrationDelegateImpl {
40
class MigrationDelegate extends MigrationDelegateImpl {
35
	private EReference myFigure_RefElements;
41
	private EReference myFigure_RefElements;
36
	
42
	private Map<String, EObject> myId2EObject;
37
	//private FigureGallery myDefaultCreatedFigureGallery;
43
	private boolean isPostprocessingFinished;
44
	private Collection<EObject> myProxiesToResolve;
38
	
45
	
39
	MigrationDelegate() {
46
	MigrationDelegate() {
40
	}
47
	}
Lines 45-62 Link Here
45
		
52
		
46
		registerDeletedAttributes(GMFGraphPackage.eINSTANCE.getCustomClass(), "bundleName"); //$NON-NLS-1$
53
		registerDeletedAttributes(GMFGraphPackage.eINSTANCE.getCustomClass(), "bundleName"); //$NON-NLS-1$
47
		
54
		
48
		myFigure_RefElements = createNewReference("referencingElements", GMFGraphPackage.eINSTANCE.getDiagramElement(), false); //$NON-NLS-1$
55
		myFigure_RefElements = createNewReference("referencingElementsFake", GMFGraphPackage.eINSTANCE.getDiagramElement(), false); //$NON-NLS-1$
49
		registerRenamedParentAttribute(GMFGraphPackage.eINSTANCE.getFigure(), "referencingElements", myFigure_RefElements); //$NON-NLS-1$
56
		registerRenamedParentAttribute(GMFGraphPackage.eINSTANCE.getFigure(), "referencingElements", myFigure_RefElements); //$NON-NLS-1$
57
		registerRenamedAttribute(GMFGraphPackage.eINSTANCE.getFigureAccessor(), "referencingElements", myFigure_RefElements); //$NON-NLS-1$
58
		
59
		myId2EObject = null;
60
		isPostprocessingFinished = false;
50
	}
61
	}
51
62
52
	@Override
63
	@Override
53
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
64
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
54
		if (myFigure_RefElements.equals(feature)) {
65
		// during load
66
		
67
		if (object instanceof Figure && "name".equals(feature.getName())) {
68
			// this feature used to be id in old versions, so need to emulate this during processing
69
			String name = (String) value;
70
			saveEObjectIdLocally(object, name);
71
		}
72
		
73
		// after end of document, handling forward references:
74
		
75
		if (GMFGraphPackage.eINSTANCE.getFigureAccessor_TypedFigure().equals(feature) && value instanceof CustomFigure) {
76
			CustomFigure custom = (CustomFigure) value;
77
			if (custom.eIsProxy()) {
78
				// this could happen in case of having "href" attribute, i.e. 
79
				// in the case of reference, that now has changed to be containment
80
				saveReferenceToGetContainmentLater(custom);
81
			}
82
		}
83
		if (myFigure_RefElements.equals(feature) && object instanceof Figure) {
55
			Figure figure = (Figure) object; // can be FigureRef as well
84
			Figure figure = (Figure) object; // can be FigureRef as well
85
			FigureDescriptor figureDescriptor = figure.getDescriptor();
56
			RealFigure topLevel = findTopLevelFigure(figure);
86
			RealFigure topLevel = findTopLevelFigure(figure);
57
			FigureDescriptor figureDescriptor = getOrCreateFigureDescriptorFor(topLevel);
87
			if (figureDescriptor == null) {
58
			if (figure instanceof RealFigure) { //XXX!!! think smth out!
88
				figureDescriptor = getOrCreateFigureDescriptorFor(topLevel);
59
				replaceFigureIdWithDescriptorIdInResolve(figureDescriptor, ((RealFigure) figure).getName());
60
			}
89
			}
61
			if (!figure.equals(topLevel)) {
90
			if (!figure.equals(topLevel)) {
62
				ChildAccess access = getOrCreateChildAccessForNested(figure, figureDescriptor);
91
				ChildAccess access = getOrCreateChildAccessForNested(figure, figureDescriptor);
Lines 64-69 Link Here
64
				setNestedFigureAccessFor(node, access);
93
				setNestedFigureAccessFor(node, access);
65
			}
94
			}
66
			fireMigrationApplied(true);
95
			fireMigrationApplied(true);
96
		} else if (myFigure_RefElements.equals(feature) && object instanceof FigureAccessor) {
97
			FigureAccessor accessor = (FigureAccessor) object;
98
			CustomFigure customFigure = findParentCustomFigure(accessor);
99
			RealFigure figure = getOrCreateTypedFigure(accessor);
100
			FigureDescriptor figureDescriptor = figure.getDescriptor();
101
			RealFigure topLevel = findTopLevelFigure(customFigure);
102
			if (figureDescriptor == null) {
103
				figureDescriptor = getOrCreateFigureDescriptorFor(topLevel);
104
			}
105
			if (!figure.equals(topLevel)) {
106
				ChildAccess access = getOrCreateChildAccessForNested(figure, figureDescriptor);
107
				DiagramElement node = (DiagramElement) value;
108
				setNestedFigureAccessFor(node, access);
109
			}
110
			fireMigrationApplied(true);
111
		} else if (GMFGraphPackage.eINSTANCE.getDiagramElement_Figure().equals(feature) && value instanceof Figure) {
112
			// as long as we have added ids for figure references in postProcess(), the id used here
113
			// can be resolved either as Figure (old version) or FigureDescriptor(new ones) - and this 
114
			// should happen ONLY for old versions (or due to our wrong id reference resolving with 
115
			// myId2EObject map)
116
			Figure figure = (Figure) value;
117
			if (figure.eIsProxy()) {
118
				figure = (Figure) EcoreUtil.resolve(figure, object);
119
			}
120
			FigureDescriptor figureDescriptor = figure.getDescriptor();
121
			if (figureDescriptor == null) {
122
				RealFigure topLevel = findTopLevelFigure(figure);
123
				figureDescriptor = getOrCreateFigureDescriptorFor(topLevel);
124
			}
125
			DiagramElement diagramElement = (DiagramElement) object;
126
			diagramElement.setFigure(figureDescriptor);
127
			fireMigrationApplied(true);
128
		} else if (GMFGraphPackage.eINSTANCE.getDiagramElement_Figure().equals(feature) && value instanceof FigureAccessor) {
129
			// as FigureAccess could be referenced before in DiagramLabels and Containments along with Figures,
130
			// but, since now being not a Figure, do not have a Descriptor, so we use its TypedFigure's one
131
			// (creating default one if none exists) - and this should happen ONLY for old versions (or due to our
132
			// wrong id reference resolving with myId2EObject map).
133
			FigureAccessor accessor = (FigureAccessor) value;
134
			if (accessor.eIsProxy()) {
135
				accessor = (FigureAccessor) EcoreUtil.resolve(accessor, object);
136
			}
137
			RealFigure figure = getOrCreateTypedFigure(accessor);
138
			FigureDescriptor figureDescriptor = figure.getDescriptor();
139
			if (figureDescriptor == null) {
140
				CustomFigure customFigure = findParentCustomFigure(accessor);
141
				RealFigure topLevel = findTopLevelFigure(customFigure);
142
				figureDescriptor = getOrCreateFigureDescriptorFor(topLevel);
143
			}
144
			DiagramElement diagramElement = (DiagramElement) object;
145
			diagramElement.setFigure(figureDescriptor);
146
			ChildAccess access = getOrCreateChildAccessForNested(figure, figureDescriptor);
147
			setNestedFigureAccessFor(diagramElement, access);
148
			fireMigrationApplied(true);
149
		} else if (GMFGraphPackage.eINSTANCE.getPolylineConnection_SourceDecoration().equals(feature) && value instanceof FigureDescriptor) {
150
			// as in old version a name is used for id of referenced figure, and now we set this name
151
			// for its figure descriptor, if the figure is directly nested into it, - we could receive 
152
			// an instanceof descriptor resolved for this id value
153
			FigureDescriptor figureDescriptor = (FigureDescriptor) value;
154
			// ClassCast here will signal us of our id resolving mistakes:
155
			DecorationFigure toplevelFigureInstead = (DecorationFigure) figureDescriptor.getActualFigure();
156
			PolylineConnection connection = (PolylineConnection) object;
157
			connection.setSourceDecoration(toplevelFigureInstead);
158
			fireMigrationApplied(true);
159
		} else if (GMFGraphPackage.eINSTANCE.getPolylineConnection_TargetDecoration().equals(feature) && value instanceof FigureDescriptor) {
160
			// as in old version a name is used for id of referenced figure, and now we set this name
161
			// for its figure descriptor, if the figure is directly nested into it, - we could receive 
162
			// an instanceof descriptor resolved for this id value
163
			FigureDescriptor figureDescriptor = (FigureDescriptor) value;
164
			// ClassCast here will signal us of our id resolving mistakes:
165
			DecorationFigure toplevelFigureInstead = (DecorationFigure) figureDescriptor.getActualFigure();
166
			PolylineConnection connection = (PolylineConnection) object;
167
			connection.setTargetDecoration(toplevelFigureInstead);
168
			fireMigrationApplied(true);
67
		} else {
169
		} else {
68
			// other cases are would be processed as defaults
170
			// other cases are would be processed as defaults
69
			return super.setValue(object, feature, value, position);
171
			return super.setValue(object, feature, value, position);
Lines 71-104 Link Here
71
		return true;
173
		return true;
72
	}
174
	}
73
175
176
	@Override
177
	public boolean setManyReference(EObject object, EStructuralFeature feature, Object[] values) {
178
		return myFigure_RefElements.equals(feature);
179
	}
180
181
	@Override
182
	public void postProcess() {
183
		super.postProcess();
184
		Resource resource = getResource();
185
		// this is run BEFORE forward references handling 
186
		for (Iterator<EObject> it=resource.getAllContents();it.hasNext();) {
187
			EObject next = it.next();
188
			// we have changed metamodel structure, so URI-fragment references for Accessor could get 
189
			// invalid after resolving references in postprocessing, so we need to save them to preserve
190
			if (next instanceof FigureAccessor) {
191
				FigureAccessor customAccessor = (FigureAccessor) next;
192
				String accessorUri = resource.getURIFragment(customAccessor);
193
				saveEObjectIdLocally(customAccessor, accessorUri);
194
			}
195
		}
196
		if (myId2EObject == null) {
197
			isPostprocessingFinished = true;
198
			return;
199
		}
200
		for (Iterator<Map.Entry<String, EObject>> it = myId2EObject.entrySet().iterator(); it.hasNext();) {
201
			Map.Entry<String, EObject> next = it.next();
202
			String id = next.getKey();
203
			EObject found = resource.getEObject(id);
204
			if (found != null) {
205
				next.setValue(found);
206
			}
207
		}
208
		if (myProxiesToResolve == null) {
209
			isPostprocessingFinished = true;
210
			return;
211
		}
212
		for (EObject proxy : myProxiesToResolve) {
213
			// these proxies are expected just to be references, used to be non-containment in the past,
214
			// and interpreted by loader as proxies because of having "href" attribute 
215
			String last = EcoreUtil.getURI(proxy).lastSegment();
216
			EObject saved = myId2EObject.get(last);
217
			if (proxy.eContainer() instanceof FigureAccessor) {
218
				FigureAccessor accessor = (FigureAccessor) proxy.eContainer();
219
				// saved could be FigureDescriptor for migrated resources with proxy customFigure references
220
				if (saved instanceof RealFigure) {
221
					RealFigure copyOfResolved = (RealFigure) EcoreUtil.copy(saved);
222
					accessor.setTypedFigure(copyOfResolved);
223
				} else if (saved instanceof FigureDescriptor) {
224
					FigureDescriptor descriptor = (FigureDescriptor) saved;
225
					RealFigure copyOfResolved = (RealFigure) EcoreUtil.copy(descriptor.getActualFigure());
226
					accessor.setTypedFigure(copyOfResolved);
227
				}
228
			}
229
		}
230
		isPostprocessingFinished = true;
231
	}
232
233
	@Override
234
	public EObject findEObject(String uriFragment) {
235
		if (!isPostprocessingFinished || myId2EObject == null) {
236
			return null;
237
		}
238
		EObject result = myId2EObject.get(uriFragment);
239
		return result;
240
	}
241
242
	private void saveEObjectIdLocally(EObject object, String id) {
243
		if (myId2EObject == null) {
244
			myId2EObject = new HashMap<String, EObject>();
245
		}
246
		if (myId2EObject.get(id) == null) {
247
			myId2EObject.put(id, object);
248
		} else {
249
			// collision with figure name expected only in new versions, as old ones used this as id 
250
		}
251
	}
252
253
	private void saveReferenceToGetContainmentLater(EObject custom) {
254
		if (myProxiesToResolve == null) {
255
			myProxiesToResolve = new ArrayList<EObject>();
256
		}
257
		myProxiesToResolve.add(custom);
258
	}
259
260
	private RealFigure getOrCreateTypedFigure(FigureAccessor accessor) {
261
		RealFigure result = accessor.getTypedFigure();
262
		if (result == null) {
263
			CustomFigure custom = GMFGraphFactory.eINSTANCE.createCustomFigure();
264
			// @see org.eclipse.gmf.codegen/templates/xpt/diagram/editparts/TextAware.xpt::labelSetterFigureClassName
265
			custom.setQualifiedClassName("org.eclipse.draw2d.IFigure"); //$NON-NLS-1$
266
			accessor.setTypedFigure(custom);
267
			result = custom;
268
		}
269
		return result;
270
	}
271
272
	private CustomFigure findParentCustomFigure(FigureAccessor accessor) {
273
		CustomFigure result = null;
274
		if (accessor.eContainer() instanceof CustomFigure) {
275
			result = (CustomFigure) accessor.eContainer();
276
		}
277
		return result;
278
	}
279
74
	private void setNestedFigureAccessFor(DiagramElement dElem, ChildAccess access) {
280
	private void setNestedFigureAccessFor(DiagramElement dElem, ChildAccess access) {
75
		if (dElem instanceof DiagramLabel) {
281
		if (dElem instanceof DiagramLabel) {
76
			DiagramLabel label = (DiagramLabel) dElem;
282
			DiagramLabel label = (DiagramLabel) dElem;
77
			label.setAccessor(access);
283
			label.setAccessor(access);
78
		} else if (dElem instanceof Node) {
79
			Node node = (Node) dElem;
80
			node.setContentPane(access);
81
		} else if (dElem instanceof Compartment) {
284
		} else if (dElem instanceof Compartment) {
82
			Compartment bag = (Compartment) dElem;
285
			Compartment bag = (Compartment) dElem;
83
			bag.setAccessor(access);
286
			bag.setAccessor(access);
84
		}
287
		}
85
	}
288
	}
86
289
87
	private void replaceFigureIdWithDescriptorIdInResolve(EObject figure, String name) {
88
		//XXX: there is still problem with references for figures, when not only
89
		// figureDescriptors are needed. For ex., see PolylineConnection.targetDecoration
90
		Resource resource = getResource();
91
		if (resource instanceof ResourceImpl) {
92
			ResourceImpl resourceImpl = (ResourceImpl) resource;
93
			Map<String, EObject> idMap = resourceImpl.getIntrinsicIDToEObjectMap();
94
			if (idMap == null) {
95
				idMap = new HashMap<String, EObject>();
96
				resourceImpl.setIntrinsicIDToEObjectMap(idMap);
97
			}
98
			idMap.put(name, figure);
99
		}
100
	}
101
102
	private RealFigure findTopLevelFigure(Figure figure) {
290
	private RealFigure findTopLevelFigure(Figure figure) {
103
		RealFigure result = figure instanceof RealFigure ? (RealFigure) figure : null;
291
		RealFigure result = figure instanceof RealFigure ? (RealFigure) figure : null;
104
		while (result.eContainer() instanceof RealFigure) {
292
		while (result.eContainer() instanceof RealFigure) {
Lines 135-151 Link Here
135
		}
323
		}
136
		return descriptor;
324
		return descriptor;
137
	}
325
	}
138
	
139
//	private FigureGallery getOrCreateFigureGalleryOnce(Figure figure) {
140
//		if (myDefaultCreatedFigureGallery == null) {
141
//			myDefaultCreatedFigureGallery = GMFGraphFactory.eINSTANCE.createFigureGallery();
142
//			if (figure.eContainer() instanceof Canvas) {
143
//				Canvas canvas = (Canvas) figure.eContainer();
144
//				canvas.getFigures().add(myDefaultCreatedFigureGallery);
145
//			} else {
146
//				figure.eResource().getContents().add(myDefaultCreatedFigureGallery);
147
//			}
148
//		}
149
//		return myDefaultCreatedFigureGallery;
150
//	}
151
}
326
}
(-)plugin.xml (+13 lines)
Lines 62-67 Link Here
62
		</action>
62
		</action>
63
  		<filter name="extension" value="gmfmap"/>
63
  		<filter name="extension" value="gmfmap"/>
64
	</objectContribution>	
64
	</objectContribution>	
65
	<objectContribution
66
    		adaptable="true"
67
	        id="gmf.codegen.ui.migrate.model.gmfgraph"
68
    	    objectClass="org.eclipse.core.resources.IFile">
69
		<action
70
				label="%migrate.model.action"
71
				class="org.eclipse.gmf.internal.codegen.popup.actions.MigrateModelAction"
72
				menubarPath="additions"
73
				enablesFor="1"
74
				id="gmf.codegen.ui.migrateAction">
75
		</action>
76
  		<filter name="extension" value="gmfgraph"/>
77
	</objectContribution>	
65
   </extension>
78
   </extension>
66
79
67
   <extension point="org.eclipse.jdt.ui.javaElementFilters">
80
   <extension point="org.eclipse.jdt.ui.javaElementFilters">
(-)src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java (-3 / +50 lines)
Lines 43-50 Link Here
43
import org.eclipse.gmf.gmfgraph.FlowLayout;
43
import org.eclipse.gmf.gmfgraph.FlowLayout;
44
import org.eclipse.gmf.gmfgraph.Label;
44
import org.eclipse.gmf.gmfgraph.Label;
45
import org.eclipse.gmf.gmfgraph.LabeledContainer;
45
import org.eclipse.gmf.gmfgraph.LabeledContainer;
46
import org.eclipse.gmf.gmfgraph.LineKind;
46
import org.eclipse.gmf.gmfgraph.Node;
47
import org.eclipse.gmf.gmfgraph.Node;
47
import org.eclipse.gmf.gmfgraph.PolylineConnection;
48
import org.eclipse.gmf.gmfgraph.PolylineConnection;
49
import org.eclipse.gmf.gmfgraph.PolylineDecoration;
48
import org.eclipse.gmf.gmfgraph.Rectangle;
50
import org.eclipse.gmf.gmfgraph.Rectangle;
49
import org.eclipse.gmf.internal.common.ToolingResourceFactory;
51
import org.eclipse.gmf.internal.common.ToolingResourceFactory;
50
import org.eclipse.gmf.internal.common.migrate.MigrationResource;
52
import org.eclipse.gmf.internal.common.migrate.MigrationResource;
Lines 459-465 Link Here
459
		URI newUri = temporarySaveMigratedModel(gmfgraphFileName, "basic", "gmfgraph");
461
		URI newUri = temporarySaveMigratedModel(gmfgraphFileName, "basic", "gmfgraph");
460
		changeNsUriToOldOne(newUri, "gmfgraph", "http://www.eclipse.org/gmf/2005/GraphicalDefinition");
462
		changeNsUriToOldOne(newUri, "gmfgraph", "http://www.eclipse.org/gmf/2005/GraphicalDefinition");
461
		
463
		
462
		//assertOnLoadModelMigrationDidNothing(newUri);
464
		assertOnLoadModelMigrationDidNothing(newUri);
463
		checkAllFigureReferences(newUri);
465
		checkAllFigureReferences(newUri);
464
	}
466
	}
465
467
Lines 479-487 Link Here
479
		
481
		
480
		FigureGallery fg = canvas.getFigures().get(0);
482
		FigureGallery fg = canvas.getFigures().get(0);
481
		assertEquals("GenericDiagramFigures", fg.getName());
483
		assertEquals("GenericDiagramFigures", fg.getName());
482
		assertTrue(fg.getFigures().isEmpty());
484
		assertFalse(fg.getFigures().isEmpty());
485
		assertEquals(1, fg.getFigures().size());
486
487
		Figure figure0 = fg.getFigures().get(0);
488
		assertTrue(figure0 instanceof PolylineDecoration);
489
		PolylineDecoration linked = (PolylineDecoration) figure0;
490
		assertEquals("ArrowDecoration", linked.getName());
491
		
483
		assertFalse(fg.getDescriptors().isEmpty());
492
		assertFalse(fg.getDescriptors().isEmpty());
484
		assertEquals(5, fg.getDescriptors().size());
493
		assertEquals(6, fg.getDescriptors().size());
485
		
494
		
486
		FigureDescriptor fg1 = fg.getDescriptors().get(0);
495
		FigureDescriptor fg1 = fg.getDescriptors().get(0);
487
		assertTrue(fg1.getAccessors().isEmpty());
496
		assertTrue(fg1.getAccessors().isEmpty());
Lines 545-550 Link Here
545
		assertEquals(1, nnr.getDescriptor().getAccessors().size());
554
		assertEquals(1, nnr.getDescriptor().getAccessors().size());
546
		assertEquals(nnrLabel, nnr.getDescriptor().getAccessors().get(0).getFigure());
555
		assertEquals(nnrLabel, nnr.getDescriptor().getAccessors().get(0).getFigure());
547
556
557
		Figure figure6 = fg.getDescriptors().get(5).getActualFigure();
558
		assertTrue(figure6 instanceof PolylineConnection);
559
		PolylineConnection fcf = (PolylineConnection) figure6;
560
		assertEquals("FigureConnectionFigure", fcf.getName());
561
		assertEquals(LineKind.LINE_DASHDOT_LITERAL, fcf.getLineKind());
562
		assertNotNull(fcf.getTargetDecoration());
563
		assertEquals(linked, fcf.getTargetDecoration());
564
		assertNotNull(fcf.getDescriptor());
565
		assertEquals(fcf, fcf.getDescriptor().getActualFigure());
566
548
		assertNotNull(canvas.getNodes());
567
		assertNotNull(canvas.getNodes());
549
		assertFalse(canvas.getNodes().isEmpty());
568
		assertFalse(canvas.getNodes().isEmpty());
550
		assertEquals(2, canvas.getNodes().size());
569
		assertEquals(2, canvas.getNodes().size());
Lines 583-586 Link Here
583
		assertEquals("LabelWOIcon", l3.getName());
602
		assertEquals("LabelWOIcon", l3.getName());
584
	}
603
	}
585
604
605
	public void testCustomFigures() throws Exception {
606
		URI gmfgraphFileName = createURI("customFigures.gmfgraph"); //$NON-NLS-1$
607
		
608
		Exception caughtGenException = assertOrdinaryLoadModelProblems(gmfgraphFileName);
609
		assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$				
610
611
		assertOnLoadModelMigrationSuccess(gmfgraphFileName);
612
613
		URI newUri = temporarySaveMigratedModel(gmfgraphFileName, "customFigures", "gmfgraph");
614
		changeNsUriToOldOne(newUri, "gmfgraph", "http://www.eclipse.org/gmf/2005/GraphicalDefinition");
615
		
616
		assertOnLoadModelMigrationDidNothing(newUri);
617
	}
618
619
	public void testMultifiles() throws Exception {
620
		URI gmfgraphFileName = createURI("multifile_main.gmfgraph"); //$NON-NLS-1$
621
		
622
		Exception caughtGenException = assertOrdinaryLoadModelProblems(gmfgraphFileName);
623
		assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$				
624
625
		assertOnLoadModelMigrationSuccess(gmfgraphFileName);
626
627
		URI newUri = temporarySaveMigratedModel(gmfgraphFileName, "multifile_main", "gmfgraph");
628
		changeNsUriToOldOne(newUri, "gmfgraph", "http://www.eclipse.org/gmf/2005/GraphicalDefinition");
629
		
630
		assertOnLoadModelMigrationDidNothing(newUri);
631
	}
632
586
}
633
}
(-)models/migration/basic.gmfgraph (+17 lines)
Lines 49-54 Link Here
49
          referencingElements="NamedNode_Name"
49
          referencingElements="NamedNode_Name"
50
          name="NamedNode_NameLabelFigure"/>
50
          name="NamedNode_NameLabelFigure"/>
51
    </figures>
51
    </figures>
52
    <figures
53
        xsi:type="gmfgraph:PolylineConnection"
54
        referencingElements="Link"
55
        name="FigureConnectionFigure"
56
        lineKind="LINE_DASHDOT"
57
        targetDecoration="ArrowDecoration"/>
58
    <figures
59
        xsi:type="gmfgraph:PolylineDecoration"
60
        name="ArrowDecoration">
61
      <template
62
          x="-1"
63
          y="1"/>
64
      <template/>
65
      <template
66
          x="-1"
67
          y="-1"/>
68
    </figures>
52
  </figures>
69
  </figures>
53
  <nodes
70
  <nodes
54
      name="Node"
71
      name="Node"
(-)models/migration/multifile_main.gmfgraph (+50 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<gmfgraph:Canvas xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gmfgraph="http://www.eclipse.org/gmf/2005/GraphicalDefinition" name="EclipseCon">
3
  <figures name="default">
4
    <figures xsi:type="gmfgraph:Label" name="ResourceTag" text="&lt;&lt;Resource>>"/>
5
    <figures xsi:type="gmfgraph:Rectangle" name="ThickFigure" lineWidth="3">
6
      <children xsi:type="gmfgraph:Label" name="ThickFigureLabel"/>
7
    </figures>
8
    <figures xsi:type="gmfgraph:PolylineConnection" name="SolidLineSquareDec">
9
      <sourceDecoration xsi:type="gmfgraph:PolygonDecoration" href="multifile_linked.gmfgraph#SquareDecoration"/>
10
    </figures>
11
    <figures xsi:type="gmfgraph:RoundedRectangle" name="SlotFigure" lineWidth="2" cornerWidth="20" cornerHeight="20">
12
      <layout xsi:type="gmfgraph:FlowLayout" vertical="true" matchMinorSize="true" forceSingleLine="true" minorAlignment="CENTER"/>
13
      <children xsi:type="gmfgraph:Label" name="LabelStart"/>
14
      <children xsi:type="gmfgraph:Label" name="LabelEnd" text=""/>
15
      <foregroundColor xsi:type="gmfgraph:ConstantColor" value="cyan"/>
16
    </figures>
17
    <figures xsi:type="gmfgraph:Rectangle" name="ResourceFigure">
18
      <children xsi:type="gmfgraph:Label" name="ResourceNameLabel"/>
19
      <children xsi:type="gmfgraph:Label" name="ResourceLocationLabel"/>
20
    </figures>
21
    <figures xsi:type="gmfgraph:Rectangle" name="TutorialFigure">
22
      <children xsi:type="gmfgraph:Label" name="Tag" text="&lt;&lt;Tutorial>>"/>
23
      <children xsi:type="gmfgraph:Label" name="TitleLabel" text=""/>
24
    </figures>
25
  </figures>
26
  <nodes name="ScheduleNode" figure="ThickFigure"/>
27
  <nodes name="PresenterNode">
28
    <figure xsi:type="gmfgraph:Rectangle" href="multifile_linked.gmfgraph#ActorFigure"/>
29
  </nodes>
30
  <nodes name="ResourceNode" figure="ResourceFigure"/>
31
  <nodes name="TutorialNode" figure="TutorialFigure"/>
32
  <nodes name="SlotNode" figure="SlotFigure"/>
33
  <connections name="HandoutLink" figure="SolidLineSquareDec"/>
34
  <connections name="AssignTimeLink">
35
    <figure xsi:type="gmfgraph:PolylineConnection" href="multifile_linked.gmfgraph#DotLineNoDecorations"/>
36
  </connections>
37
  <connections name="PresenterLink">
38
    <figure xsi:type="gmfgraph:PolylineConnection" href="multifile_linked.gmfgraph#DashLineNoDecorations"/>
39
  </connections>
40
  <labels name="PresenterName">
41
    <figure xsi:type="gmfgraph:Label" href="multifile_linked.gmfgraph#Label"/>
42
  </labels>
43
  <labels name="ResourceName" figure="ResourceNameLabel"/>
44
  <labels name="ResourceLocation" figure="ResourceLocationLabel"/>
45
  <labels name="SlotStart" figure="LabelStart"/>
46
  <labels name="SlotEnd" figure="LabelEnd"/>
47
  <labels name="ScheduleName" figure="ThickFigureLabel"/>
48
  <labels name="TutorialLabel" figure="TitleLabel"/>
49
  <labels name="ResourceTagLabel" figure="ResourceTag"/>
50
</gmfgraph:Canvas>
(-)models/migration/multifile_linked.gmfgraph (+38 lines)
Added Link Here
1
<?xml version="1.0" encoding="ASCII"?>
2
<gmfgraph:FigureGallery xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gmfgraph="http://www.eclipse.org/gmf/2005/GraphicalDefinition" name="EclipseConFigures">
3
  <figures xsi:type="gmfgraph:Rectangle" name="ActorFigure" fill="false" outline="false">
4
    <layout xsi:type="gmfgraph:FlowLayout" vertical="true" forceSingleLine="true"/>
5
    <children xsi:type="gmfgraph:Ellipse" name="Head" lineWidth="2">
6
      <size x="60" y="60"/>
7
    </children>
8
    <children xsi:type="gmfgraph:Polygon" name="Body" fill="true">
9
      <template x="30" y="60"/>
10
      <template x="30" y="85"/>
11
      <template y="85"/>
12
      <template y="88"/>
13
      <template x="30" y="88"/>
14
      <template x="30" y="130"/>
15
      <template y="170"/>
16
      <template x="4" y="170"/>
17
      <template x="31" y="133"/>
18
      <template x="60" y="170"/>
19
      <template x="64" y="170"/>
20
      <template x="33" y="130"/>
21
      <template x="33" y="88"/>
22
      <template x="63" y="88"/>
23
      <template x="63" y="85"/>
24
      <template x="33" y="85"/>
25
      <template x="33" y="60"/>
26
    </children>
27
    <children xsi:type="gmfgraph:Label" name="Label"/>
28
  </figures>
29
  <figures xsi:type="gmfgraph:PolygonDecoration" name="SquareDecoration" fill="true">
30
   <foregroundColor xsi:type="gmfgraph:ConstantColor" value="black"/>
31
    <template y="-1"/>
32
    <template y="1"/>
33
    <template x="-2" y="1"/>
34
    <template x="-2" y="-1"/>
35
  </figures>
36
  <figures xsi:type="gmfgraph:PolylineConnection" name="DashLineNoDecorations" lineKind="LINE_DASH"/>
37
  <figures xsi:type="gmfgraph:PolylineConnection" name="DotLineNoDecorations" lineKind="LINE_DOT"/>
38
</gmfgraph:FigureGallery>
(-)models/migration/customFigures.gmfgraph (+73 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<gmfgraph:Canvas xmi:version="2.0"
3
    xmlns:xmi="http://www.omg.org/XMI"
4
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
    xmlns:gmfgraph="http://www.eclipse.org/gmf/2005/GraphicalDefinition">
6
  <figures>
7
    <figures
8
        xsi:type="gmfgraph:CustomFigure"
9
        referencingElements="LocalPreconditionNode"
10
        name="LocalPreconditionFigure"
11
        qualifiedClassName="org.eclipse.uml2.diagram.common.draw2d.ConstraintFigure"
12
        bundleName="">
13
      <attributes
14
          name="FixedLabelText"
15
          value="&quot;\u00ABlocalPrecondition\u00BB&quot;"/>
16
      <customChildren
17
          referencingElements="precondition"
18
          accessor="getContentPane"/>
19
    </figures>
20
    <figures
21
        xsi:type="gmfgraph:CustomFigure"
22
        referencingElements="LocalPostconditionNode"
23
        name="LocalPostconditionFigure"
24
        qualifiedClassName="org.eclipse.uml2.diagram.common.draw2d.ConstraintFigure"
25
        bundleName="">
26
      <attributes
27
          name="FixedLabelText"
28
          value="&quot;\u00ABlocalPostcondition\u00BB&quot;"/>
29
      <customChildren
30
          accessor="getContentPane">
31
        <typedFigure
32
            href="PostconditionContentPane"/>
33
      </customChildren>
34
    </figures>
35
    <figures
36
        xsi:type="gmfgraph:CustomFigure"
37
        name="AnotherPostconditionFigure"
38
        qualifiedClassName="org.eclipse.uml2.diagram.common.draw2d.ConstraintFigure"
39
        bundleName="">
40
      <customChildren
41
          accessor="getContentPane">
42
        <typedFigure
43
            href="AnotherPostconditionContentPane"/>
44
      </customChildren>
45
    </figures>
46
    <figures
47
        xsi:type="gmfgraph:Rectangle"
48
        name="PostconditionContentPane"
49
        outline="false"
50
        fill="false"/>
51
    <figures
52
        xsi:type="gmfgraph:Rectangle"
53
        name="AnotherPostconditionContentPane"
54
        outline="false"
55
        referencingElements="anotherPostcondition"
56
        fill="false"/>
57
  </figures>
58
  <nodes
59
      name="LocalPreconditionNode"
60
      figure="LocalPreconditionFigure"/>
61
  <nodes
62
      name="LocalPostconditionNode"
63
      figure="LocalPostconditionFigure"/>
64
  <compartments
65
      name="postcondition"
66
      figure="//@figures.0/@figures.1/@customChildren.0"/>
67
  <compartments
68
      name="precondition"
69
      figure="//@figures.0/@figures.0/@customChildren.0"/>
70
  <compartments
71
      name="anotherPostcondition"
72
      figure="AnotherPostconditionContentPane"/>
73
</gmfgraph:Canvas>

Return to bug 189703