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

(-)src/org/eclipse/gmf/internal/map/util/MigrationDelegate.java (-45 / +76 lines)
Lines 10-92 Link Here
10
 */
10
 */
11
package org.eclipse.gmf.internal.map.util;
11
package org.eclipse.gmf.internal.map.util;
12
12
13
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.Arrays;
14
import java.util.Map;
15
import java.util.Collection;
16
15
17
import org.eclipse.emf.common.util.EList;
16
import org.eclipse.emf.common.util.EList;
17
import org.eclipse.emf.ecore.EAttribute;
18
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.EReference;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
import org.eclipse.emf.ecore.util.EcoreUtil;
19
import org.eclipse.gmf.internal.common.migrate.MigrationHelperDelegateImpl;
22
import org.eclipse.gmf.internal.common.migrate.MigrationHelperDelegateImpl;
20
import org.eclipse.gmf.mappings.FeatureLabelMapping;
23
import org.eclipse.gmf.mappings.FeatureLabelMapping;
24
import org.eclipse.gmf.mappings.GMFMapFactory;
21
import org.eclipse.gmf.mappings.GMFMapPackage;
25
import org.eclipse.gmf.mappings.GMFMapPackage;
22
import org.eclipse.gmf.mappings.LabelMapping;
26
import org.eclipse.gmf.mappings.LabelMapping;
23
import org.eclipse.gmf.mappings.MappingEntry;
27
import org.eclipse.gmf.mappings.MappingEntry;
24
28
25
class MigrationDelegate extends MigrationHelperDelegateImpl {
29
class MigrationDelegate extends MigrationHelperDelegateImpl {
26
	private Collection<FeatureLabelMapping> myFeatureLabelMappings;
30
	private Map<LabelMapping, FeatureLabelMapping> myLabelMappingMigrations;
27
	private Collection<String> myBackwardSupportedURIs;
31
	private EAttribute myLabelMapping_ViewPattern;
32
	private EAttribute myLabelMapping_EditPattern;
33
	private EReference myLabelMapping_Features;
28
	
34
	
29
	MigrationDelegate() {
35
	MigrationDelegate() {
30
	}
36
	}
31
37
32
	void init() {
38
	void init() {
33
		registerNarrowReferenceType(GMFMapPackage.eINSTANCE.getFeatureSeqInitializer_Initializers(), GMFMapPackage.eINSTANCE.getFeatureValueSpec());
39
		//registerNarrowReferenceType(GMFMapPackage.eINSTANCE.getFeatureSeqInitializer_Initializers(), GMFMapPackage.eINSTANCE.getFeatureValueSpec());
34
		registerNarrowReferenceType(GMFMapPackage.eINSTANCE.getMappingEntry_LabelMappings(), GMFMapPackage.eINSTANCE.getFeatureLabelMapping());
40
		// -->
35
		myFeatureLabelMappings = null;
41
		registerNarrowedAbstractType("FeatureInitializer", GMFMapPackage.eINSTANCE.getFeatureValueSpec());
42
		
43
		//registerNarrowReferenceType(GMFMapPackage.eINSTANCE.getMappingEntry_LabelMappings(), GMFMapPackage.eINSTANCE.getFeatureLabelMapping());
44
		// -->
45
		myLabelMapping_Features = (EReference) EcoreUtil.copy(GMFMapPackage.eINSTANCE.getFeatureLabelMapping_Features());
46
		myLabelMapping_ViewPattern = (EAttribute) EcoreUtil.copy(GMFMapPackage.eINSTANCE.getFeatureLabelMapping_ViewPattern());
47
		myLabelMapping_EditPattern = (EAttribute) EcoreUtil.copy(GMFMapPackage.eINSTANCE.getFeatureLabelMapping_EditPattern());
48
		{
49
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
50
			renamings.put(myLabelMapping_ViewPattern.getName(), myLabelMapping_ViewPattern);
51
			renamings.put(myLabelMapping_EditPattern.getName(), myLabelMapping_EditPattern);
52
			renamings.put(myLabelMapping_Features.getName(), myLabelMapping_Features);
53
			registerRenamedAttributes(GMFMapPackage.eINSTANCE.getLabelMapping(), renamings);
54
		}
55
		
56
		myLabelMappingMigrations = null;
36
	}
57
	}
37
58
38
	@Override
59
	@Override
39
	public boolean isOldVersionDetected(String uriString) {
60
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
40
		return !getMetamodelNsURI().equals(uriString) && getBackwardSupportedURIs().contains(uriString);
61
		if (myLabelMapping_ViewPattern.equals(feature)) {
62
			LabelMapping mapping = (LabelMapping) object;
63
			String viewPattern = (String) value;
64
			FeatureLabelMapping migratedMapping = saveFeatureLabelMappingFor(mapping);
65
			migratedMapping.setViewPattern(viewPattern);
66
			fireMigrationApplied(true);
67
		} else if (myLabelMapping_EditPattern.equals(feature)) {
68
			LabelMapping mapping = (LabelMapping) object;
69
			String editPattern = (String) value;
70
			FeatureLabelMapping migratedMapping = saveFeatureLabelMappingFor(mapping);
71
			migratedMapping.setViewPattern(editPattern);
72
			fireMigrationApplied(true);
73
		} else if (myLabelMapping_Features.equals(feature)) {
74
			LabelMapping mapping = (LabelMapping) object;
75
			EAttribute attribute = (EAttribute) value;
76
			FeatureLabelMapping migratedMapping = saveFeatureLabelMappingFor(mapping);
77
			migratedMapping.getFeatures().add(attribute);
78
			fireMigrationApplied(true);
79
		} else {
80
			// other cases are would be processed as defaults
81
			return super.setValue(object, feature, value, position);
82
		}
83
		return true;
84
	}
85
86
	private FeatureLabelMapping saveFeatureLabelMappingFor(LabelMapping labelMapping) {
87
		if (myLabelMappingMigrations == null) {
88
			myLabelMappingMigrations = new HashMap<LabelMapping, FeatureLabelMapping>();
89
		}
90
		FeatureLabelMapping migrated = myLabelMappingMigrations.get(labelMapping);
91
		if (migrated == null) {
92
			migrated = GMFMapFactory.eINSTANCE.createFeatureLabelMapping();
93
			myLabelMappingMigrations.put(labelMapping, migrated);
94
		}
95
		return migrated;
96
	}
97
	
98
	private Map<LabelMapping, FeatureLabelMapping> getSavedLabelMappingMigrations() {
99
		return myLabelMappingMigrations;
41
	}
100
	}
42
101
43
	@Override
102
	@Override
44
	public void postProcess() {
103
	public void postProcess() {
45
		if (myFeatureLabelMappings == null) {
104
		if (getSavedLabelMappingMigrations() == null) {
46
			return;
105
			return;
47
		}
106
		}
48
		for (FeatureLabelMapping mapping : getSavedFeatureLabelMappings()) {
107
		for (LabelMapping mapping : getSavedLabelMappingMigrations().keySet()) {
49
			if (mapping.getFeatures().isEmpty()) {
108
			FeatureLabelMapping migrated = getSavedLabelMappingMigrations().get(mapping);
109
			if (!migrated.getFeatures().isEmpty()) {
50
				MappingEntry entry = mapping.getMapEntry();
110
				MappingEntry entry = mapping.getMapEntry();
51
				EList<LabelMapping> labelMappings = entry.getLabelMappings();
111
				EList<LabelMapping> labelMappings = entry.getLabelMappings();
52
				int originalIndex = labelMappings.indexOf(mapping);
112
				int originalIndex = labelMappings.indexOf(mapping);
53
				if (originalIndex != -1) {
113
				if (originalIndex != -1) {
54
					LabelMapping newMapping = GMFMapPackage.eINSTANCE.getGMFMapFactory().createLabelMapping();
114
					migrated.setDiagramLabel(mapping.getDiagramLabel());
55
					newMapping.setDiagramLabel(mapping.getDiagramLabel());
56
					if (mapping.isReadOnly()) {
115
					if (mapping.isReadOnly()) {
57
						newMapping.setReadOnly(true);
116
						migrated.setReadOnly(true);
58
					}
117
					}
59
					labelMappings.set(originalIndex, newMapping);
118
					labelMappings.set(originalIndex, migrated);
60
				}
119
				}
61
			}
120
			}
62
		}
121
		}
63
	}
122
	}
64
65
	@Override
66
	public void processObject(EObject result) {
67
		if (result instanceof FeatureLabelMapping) {
68
			getSavedFeatureLabelMappings().add((FeatureLabelMapping) result);
69
		}
70
	}
71
	
72
	private Collection<FeatureLabelMapping> getSavedFeatureLabelMappings() {
73
		if (myFeatureLabelMappings == null) {
74
			myFeatureLabelMappings = new ArrayList<FeatureLabelMapping>();
75
		}
76
		return myFeatureLabelMappings;
77
	}
78
79
	protected Collection<String> getBackwardSupportedURIs() {
80
		if (myBackwardSupportedURIs == null) {
81
			myBackwardSupportedURIs = Arrays.asList(new String[] {
82
					"http://www.eclipse.org/gmf/2005/mappings", //$NON-NLS-1$
83
					"http://www.eclipse.org/gmf/2005/mappings/2.0" //$NON-NLS-1$
84
			});
85
		}
86
		return myBackwardSupportedURIs;
87
	}
88
89
	protected String getMetamodelNsURI() {
90
		return GMFMapPackage.eNS_URI;
91
	}
92
}
123
}
(-)src/org/eclipse/gmf/internal/codegen/util/MigrationDelegate.java (-36 / +30 lines)
Lines 35-46 Link Here
35
35
36
class MigrationDelegate extends MigrationHelperDelegateImpl {
36
class MigrationDelegate extends MigrationHelperDelegateImpl {
37
	private EReference myGenAuditContainer_ChildContainers;
37
	private EReference myGenAuditContainer_ChildContainers;
38
	private EReference myGenAuditContainer_Audits;
38
	private EReference myGenAuditRoot_Audits;
39
	private EAttribute myGenAuditRoot_Id;
39
	private EAttribute myGenAuditRoot_Id;
40
	private EAttribute myGenAuditRoot_Name;
40
	private EAttribute myGenAuditRoot_Name;
41
	private EAttribute myGenAuditRoot_Description;
41
	private EAttribute myGenAuditRoot_Description;
42
	private GenAuditContainer myRootContainer;
42
	private GenAuditContainer myRootContainer;
43
	private Collection<String> myBackwardSupportedURIs;
44
	private Map<GenExpressionInterpreter, Collection<String>> myRequiredPlugins;
43
	private Map<GenExpressionInterpreter, Collection<String>> myRequiredPlugins;
45
	private GenExpressionProviderContainer myProvidersContainer;
44
	private GenExpressionProviderContainer myProvidersContainer;
46
	
45
	
Lines 71-77 Link Here
71
			renamings.put("requiredPluginIDs", GMFGenPackage.eINSTANCE.getGenPlugin_RequiredPlugins()); //$NON-NLS-1$
70
			renamings.put("requiredPluginIDs", GMFGenPackage.eINSTANCE.getGenPlugin_RequiredPlugins()); //$NON-NLS-1$
72
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getGenExpressionInterpreter(), renamings);
71
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getGenExpressionInterpreter(), renamings);
73
		}
72
		}
74
		registerNarrowReferenceType(GMFGenPackage.eINSTANCE.getGenFeatureSeqInitializer_Initializers(),	GMFGenPackage.eINSTANCE.getGenFeatureValueSpec());
75
		{
73
		{
76
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
74
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
77
			renamings.put("metaFeature", GMFGenPackage.eINSTANCE.getFeatureLabelModelFacet_MetaFeatures()); //$NON-NLS-1$
75
			renamings.put("metaFeature", GMFGenPackage.eINSTANCE.getFeatureLabelModelFacet_MetaFeatures()); //$NON-NLS-1$
Lines 79-130 Link Here
79
		}
77
		}
80
		registerRenamedType("CompositeFeatureLabelModelFacet", GMFGenPackage.eINSTANCE.getFeatureLabelModelFacet()); //$NON-NLS-1$
78
		registerRenamedType("CompositeFeatureLabelModelFacet", GMFGenPackage.eINSTANCE.getFeatureLabelModelFacet()); //$NON-NLS-1$
81
		myGenAuditContainer_ChildContainers = createNewReference("childContainers", GMFGenPackage.eINSTANCE.getGenAuditContainer(), true); //$NON-NLS-1$
79
		myGenAuditContainer_ChildContainers = createNewReference("childContainers", GMFGenPackage.eINSTANCE.getGenAuditContainer(), true); //$NON-NLS-1$
82
		myGenAuditContainer_Audits = createNewReference("audits", GMFGenPackage.eINSTANCE.getGenAuditRule(), true); //$NON-NLS-1$
83
		myGenAuditRoot_Id = (EAttribute) EcoreUtil.copy(GMFGenPackage.eINSTANCE.getGenAuditContainer_Id());
84
		myGenAuditRoot_Name = (EAttribute) EcoreUtil.copy(GMFGenPackage.eINSTANCE.getGenAuditContainer_Name());
85
		myGenAuditRoot_Description = (EAttribute) EcoreUtil.copy(GMFGenPackage.eINSTANCE.getGenAuditContainer_Description());
86
		{
80
		{
87
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
81
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
88
			renamings.put(myGenAuditContainer_Audits.getName(), myGenAuditContainer_Audits);
89
			renamings.put(myGenAuditContainer_ChildContainers.getName(), myGenAuditContainer_ChildContainers);
82
			renamings.put(myGenAuditContainer_ChildContainers.getName(), myGenAuditContainer_ChildContainers);
90
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getGenAuditContainer(), renamings);
83
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getGenAuditContainer(), renamings);
91
		}
84
		}
85
		myGenAuditRoot_Id = (EAttribute) EcoreUtil.copy(GMFGenPackage.eINSTANCE.getGenAuditContainer_Id());
86
		myGenAuditRoot_Name = (EAttribute) EcoreUtil.copy(GMFGenPackage.eINSTANCE.getGenAuditContainer_Name());
87
		myGenAuditRoot_Description = (EAttribute) EcoreUtil.copy(GMFGenPackage.eINSTANCE.getGenAuditContainer_Description());
88
		myGenAuditRoot_Audits = createNewReference("audits", GMFGenPackage.eINSTANCE.getGenAuditRule(), true); //$NON-NLS-1$
92
		{
89
		{
93
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
90
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
94
			renamings.put(myGenAuditContainer_Audits.getName(), myGenAuditContainer_Audits);
91
			renamings.put(myGenAuditRoot_Audits.getName(), myGenAuditRoot_Audits);
95
			renamings.put(myGenAuditContainer_ChildContainers.getName(), myGenAuditContainer_ChildContainers);
92
			renamings.put(myGenAuditContainer_ChildContainers.getName(), myGenAuditContainer_ChildContainers);
96
			renamings.put(myGenAuditRoot_Id.getName(), myGenAuditRoot_Id);
93
			renamings.put(myGenAuditRoot_Id.getName(), myGenAuditRoot_Id);
97
			renamings.put(myGenAuditRoot_Name.getName(), myGenAuditRoot_Name);
94
			renamings.put(myGenAuditRoot_Name.getName(), myGenAuditRoot_Name);
98
			renamings.put(myGenAuditRoot_Description.getName(), myGenAuditRoot_Description);
95
			renamings.put(myGenAuditRoot_Description.getName(), myGenAuditRoot_Description);
99
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getGenAuditRoot(), renamings);
96
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getGenAuditRoot(), renamings);
100
		}
97
		}
98
99
		//registerNarrowReferenceType(GMFGenPackage.eINSTANCE.getGenFeatureSeqInitializer_Initializers(), GMFGenPackage.eINSTANCE.getGenFeatureValueSpec());
100
		// --->
101
		registerNarrowedAbstractType("GenFeatureInitializer", GMFGenPackage.eINSTANCE.getGenFeatureValueSpec()); //$NON-NLS-1$
102
101
		myRootContainer = null;
103
		myRootContainer = null;
102
		myProvidersContainer = null;
104
		myProvidersContainer = null;
103
		myRequiredPlugins = null;
105
		myRequiredPlugins = null;
104
	}
106
	}
105
107
	
106
	@Override
107
	public boolean isOldVersionDetected(String uriString) {
108
		return !getMetamodelNsURI().equals(uriString) && getBackwardSupportedURIs().contains(uriString);
109
	}
110
111
	@Override
108
	@Override
112
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
109
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
113
		if (myGenAuditRoot_Id.equals(feature)) {
110
		if (GMFGenPackage.eINSTANCE.getGenPlugin_RequiredPlugins().equals(feature) && object instanceof GenExpressionInterpreter) {
111
			GenExpressionInterpreter expressionInterpreter = (GenExpressionInterpreter) object;
112
			String requiredPlugin = (String) value;
113
			saveRequiredPlugin(expressionInterpreter, requiredPlugin);
114
	    } else if (myGenAuditRoot_Id.equals(feature)) {
114
			GenAuditRoot root = (GenAuditRoot) object;
115
			GenAuditRoot root = (GenAuditRoot) object;
115
			String id = (String) value;
116
			String id = (String) value;
116
			GenAuditContainer rootContainer = getOrCreateRootContainerOnce(root);
117
			GenAuditContainer rootContainer = getOrCreateRootContainerOnce(root);
117
			rootContainer.setId(id);
118
			rootContainer.setId(id);
119
			fireMigrationApplied(true);
118
		} else if (myGenAuditRoot_Name.equals(feature)) {
120
		} else if (myGenAuditRoot_Name.equals(feature)) {
119
			GenAuditRoot root = (GenAuditRoot) object;
121
			GenAuditRoot root = (GenAuditRoot) object;
120
			String name = (String) value;
122
			String name = (String) value;
121
			GenAuditContainer rootContainer = getOrCreateRootContainerOnce(root);
123
			GenAuditContainer rootContainer = getOrCreateRootContainerOnce(root);
122
			rootContainer.setName(name);
124
			rootContainer.setName(name);
125
			fireMigrationApplied(true);
123
		} else if (myGenAuditRoot_Description.equals(feature)) {
126
		} else if (myGenAuditRoot_Description.equals(feature)) {
124
			GenAuditRoot root = (GenAuditRoot) object;
127
			GenAuditRoot root = (GenAuditRoot) object;
125
			String description = (String) value;
128
			String description = (String) value;
126
			GenAuditContainer rootContainer = getOrCreateRootContainerOnce(root);
129
			GenAuditContainer rootContainer = getOrCreateRootContainerOnce(root);
127
			rootContainer.setDescription(description);
130
			rootContainer.setDescription(description);
131
			fireMigrationApplied(true);
128
		} else if (myGenAuditContainer_ChildContainers.equals(feature) && object instanceof GenAuditRoot) {
132
		} else if (myGenAuditContainer_ChildContainers.equals(feature) && object instanceof GenAuditRoot) {
129
			GenAuditRoot root = (GenAuditRoot)object;
133
			GenAuditRoot root = (GenAuditRoot)object;
130
			GenAuditContainer container = (GenAuditContainer)value;
134
			GenAuditContainer container = (GenAuditContainer)value;
Lines 132-142 Link Here
132
				container.getPath().add(myRootContainer);
136
				container.getPath().add(myRootContainer);
133
			}
137
			}
134
			root.getCategories().add(container);
138
			root.getCategories().add(container);
135
		} else if (myGenAuditContainer_Audits.equals(feature) && object instanceof GenAuditRoot) {
139
			fireMigrationApplied(true);
140
		} else if (myGenAuditRoot_Audits.equals(feature) && object instanceof GenAuditRoot) {
136
			GenAuditRoot root = (GenAuditRoot)object;
141
			GenAuditRoot root = (GenAuditRoot)object;
137
			GenAuditRule rule = (GenAuditRule)value;
142
			GenAuditRule rule = (GenAuditRule)value;
138
			if (myRootContainer != null) {
143
			if (myRootContainer != null) {
139
				rule.setCategory(myRootContainer);
144
				rule.setCategory(myRootContainer);
145
				fireMigrationApplied(true);
140
			}
146
			}
141
			root.getRules().add(rule);
147
			root.getRules().add(rule);
142
		} else if (myGenAuditContainer_ChildContainers.equals(feature) && object instanceof GenAuditContainer) {
148
		} else if (myGenAuditContainer_ChildContainers.equals(feature) && object instanceof GenAuditContainer) {
Lines 145-159 Link Here
145
			container.getPath().addAll(parent.getPath());
151
			container.getPath().addAll(parent.getPath());
146
			container.getPath().add(parent);
152
			container.getPath().add(parent);
147
			getOrCreateRoot(parent).getCategories().add(container);
153
			getOrCreateRoot(parent).getCategories().add(container);
148
		} else if (myGenAuditContainer_Audits.equals(feature) && object instanceof GenAuditContainer) {
154
			fireMigrationApplied(true);
155
		} else if (GMFGenPackage.eINSTANCE.getGenAuditContainer_Audits().equals(feature) && object instanceof GenAuditContainer) {
149
			GenAuditContainer container = (GenAuditContainer)object;
156
			GenAuditContainer container = (GenAuditContainer)object;
150
			GenAuditRule rule = (GenAuditRule)value;
157
			GenAuditRule rule = (GenAuditRule)value;
151
			rule.setCategory(container);
158
			rule.setCategory(container);
152
			getOrCreateRoot(container).getRules().add(rule);
159
			getOrCreateRoot(container).getRules().add(rule);
153
		} else if (GMFGenPackage.eINSTANCE.getGenPlugin_RequiredPlugins().equals(feature) && object instanceof GenExpressionInterpreter) {
154
			GenExpressionInterpreter expressionInterpreter = (GenExpressionInterpreter) object;
155
			String requiredPlugin = (String) value;
156
			saveRequiredPlugin(expressionInterpreter, requiredPlugin);
157
	    } else {
160
	    } else {
158
			// other cases are would be processed as defaults
161
			// other cases are would be processed as defaults
159
			return super.setValue(object, feature, value, position);
162
			return super.setValue(object, feature, value, position);
Lines 200-205 Link Here
200
				editor.setPlugin(plugin);
203
				editor.setPlugin(plugin);
201
			}
204
			}
202
			plugin.getRequiredPlugins().addAll(getSavedRequiredPlugins().get(expressionProvider));
205
			plugin.getRequiredPlugins().addAll(getSavedRequiredPlugins().get(expressionProvider));
206
			fireMigrationApplied(true);
203
		}
207
		}
204
		getSavedRequiredPlugins().clear();
208
		getSavedRequiredPlugins().clear();
205
	}
209
	}
Lines 224-245 Link Here
224
		GenAuditRoot result = auditContainer.getRoot();
228
		GenAuditRoot result = auditContainer.getRoot();
225
		if (result == null) {
229
		if (result == null) {
226
			result = GMFGenFactory.eINSTANCE.createGenAuditRoot();
230
			result = GMFGenFactory.eINSTANCE.createGenAuditRoot();
231
			if (auditContainer.eContainer() == null) {
232
				auditContainer.eResource().getContents().add(result);
233
				fireMigrationApplied(true);
234
			}
227
			result.getCategories().add(auditContainer);
235
			result.getCategories().add(auditContainer);
228
		}
236
		}
229
		return result;
237
		return result;
230
	}
238
	}
231
232
	protected Collection<String> getBackwardSupportedURIs() {
233
		if (myBackwardSupportedURIs == null) {
234
			myBackwardSupportedURIs = Arrays.asList(new String[] {
235
					"http://www.eclipse.org/gmf/2005/GenModel", //$NON-NLS-1$
236
					"http://www.eclipse.org/gmf/2005/GenModel/2.0" //$NON-NLS-1$
237
			});
238
		}
239
		return myBackwardSupportedURIs;
240
	}
241
242
	protected String getMetamodelNsURI() {
243
		return GMFGenPackage.eNS_URI;
244
	}
245
}
239
}
(-)src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java (-6 / +6 lines)
Lines 299-305 Link Here
299
		//assertTrue(errorMessage.contains(myWidenedRef1.getEType().getName())); //XXX check
299
		//assertTrue(errorMessage.contains(myWidenedRef1.getEType().getName())); //XXX check
300
		
300
		
301
		MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {{
301
		MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {{
302
				registerNarrowReferenceType(myWidenedRef1, myAttrNarrow.getEContainingClass());
302
				registerNarrowedAbstractType(myWidenedRef1.getEType().getName(), myAttrNarrow.getEContainingClass());
303
		}};
303
		}};
304
		
304
		
305
		// try to load mm
305
		// try to load mm
Lines 335-341 Link Here
335
		// assertTrue(errorMessage.contains(myWidenedRef1.getEType().getName())); //XXX
335
		// assertTrue(errorMessage.contains(myWidenedRef1.getEType().getName())); //XXX
336
336
337
		MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {{
337
		MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {{
338
				registerNarrowReferenceType(myWidenedRef1, myAttrNarrow.getEContainingClass());
338
				registerNarrowedAbstractType(myWidenedRef1.getEType().getName(), myAttrNarrow.getEContainingClass());
339
		}};
339
		}};
340
340
341
		// try to load mm
341
		// try to load mm
Lines 385-392 Link Here
385
		// assertTrue(errorMessage.contains(myAttrNarrow.getName())); //XXX
385
		// assertTrue(errorMessage.contains(myAttrNarrow.getName())); //XXX
386
386
387
		MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {{
387
		MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {{
388
				registerNarrowReferenceType(myWidenedRef1, myAttrNarrow.getEContainingClass());
388
				registerNarrowedAbstractType(myWidenedRef1.getEType().getName(), myAttrNarrow.getEContainingClass());
389
				registerNarrowReferenceType(myWidenedRef2, myAttrNarrow.getEContainingClass());
389
				registerNarrowedAbstractType(myWidenedRef2.getEType().getName(), myAttrNarrow.getEContainingClass());
390
		}};
390
		}};
391
391
392
		// try to load mm
392
		// try to load mm
Lines 463-469 Link Here
463
			fail();
463
			fail();
464
		}
464
		}
465
		MigrationHelperDelegate badDelegate = new MigrationHelperDelegateImpl() {{
465
		MigrationHelperDelegate badDelegate = new MigrationHelperDelegateImpl() {{
466
			registerNarrowReferenceType(myWidenedRef1, myAttrNarrowChild.getEContainingClass());
466
			registerNarrowedAbstractType(myWidenedRef1.getEType().getName(), myAttrNarrowChild.getEContainingClass());
467
		}};
467
		}};
468
	
468
	
469
		// try to load mm
469
		// try to load mm
Lines 474-480 Link Here
474
474
475
		MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {
475
		MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {
476
			{
476
			{
477
				registerNarrowReferenceType(myWidenedRef1, myAttrNarrowChild.getEContainingClass());
477
				registerNarrowedAbstractType(myWidenedRef1.getEType().getName(), myAttrNarrowChild.getEContainingClass());
478
			}
478
			}
479
			private Collection<EObject> myToBeChecked = new ArrayList<EObject>();
479
			private Collection<EObject> myToBeChecked = new ArrayList<EObject>();
480
480
(-)src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java (-13 / +33 lines)
Lines 26-31 Link Here
26
import org.eclipse.emf.ecore.resource.Resource;
26
import org.eclipse.emf.ecore.resource.Resource;
27
import org.eclipse.emf.ecore.resource.ResourceSet;
27
import org.eclipse.emf.ecore.resource.ResourceSet;
28
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
28
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
29
import org.eclipse.emf.ecore.xmi.XMLResource;
29
import org.eclipse.gmf.codegen.gmfgen.FeatureLabelModelFacet;
30
import org.eclipse.gmf.codegen.gmfgen.FeatureLabelModelFacet;
30
import org.eclipse.gmf.codegen.gmfgen.GenAuditContainer;
31
import org.eclipse.gmf.codegen.gmfgen.GenAuditContainer;
31
import org.eclipse.gmf.codegen.gmfgen.GenAuditRoot;
32
import org.eclipse.gmf.codegen.gmfgen.GenAuditRoot;
Lines 59-65 Link Here
59
		URI newGenUri = temporarySaveMigratedModel(genmodelFileName, "patch_138440", "gmfgen");
60
		URI newGenUri = temporarySaveMigratedModel(genmodelFileName, "patch_138440", "gmfgen");
60
		changeNsUriToOldOne(newGenUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
61
		changeNsUriToOldOne(newGenUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
61
		
62
		
62
		assertOnLoadModelMigrationSuccess(newGenUri);
63
		assertOnLoadModelMigrationDidNothing(newGenUri);
63
		
64
		
64
		URI gmfmapmodelFileName = createURI("patch_138440.gmfmap"); //$NON-NLS-1$
65
		URI gmfmapmodelFileName = createURI("patch_138440.gmfmap"); //$NON-NLS-1$
65
		Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
66
		Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
Lines 70-76 Link Here
70
		URI newMapUri = temporarySaveMigratedModel(gmfmapmodelFileName, "patch_138440", "gmfmap");
71
		URI newMapUri = temporarySaveMigratedModel(gmfmapmodelFileName, "patch_138440", "gmfmap");
71
		changeNsUriToOldOne(newMapUri, "gmfmap", "http://www.eclipse.org/gmf/2005/mappings/2.0");
72
		changeNsUriToOldOne(newMapUri, "gmfmap", "http://www.eclipse.org/gmf/2005/mappings/2.0");
72
		
73
		
73
		assertOnLoadModelMigrationSuccess(newMapUri);
74
		assertOnLoadModelMigrationDidNothing(newMapUri);
74
	}
75
	}
75
76
76
	/*
77
	/*
Lines 86-92 Link Here
86
		URI newGenUri = temporarySaveMigratedModel(genmodelFileName, "patch_138440", "gmfgen");
87
		URI newGenUri = temporarySaveMigratedModel(genmodelFileName, "patch_138440", "gmfgen");
87
		changeNsUriToOldOne(newGenUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
88
		changeNsUriToOldOne(newGenUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
88
		
89
		
89
		assertOnLoadModelMigrationSuccess(newGenUri);
90
		assertOnLoadModelMigrationDidNothing(newGenUri);
90
		
91
		
91
		URI gmfmapmodelFileName = createURI("patch_161380.gmfmap"); //$NON-NLS-1$		
92
		URI gmfmapmodelFileName = createURI("patch_161380.gmfmap"); //$NON-NLS-1$		
92
		Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
93
		Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
Lines 97-103 Link Here
97
		URI newUri = temporarySaveMigratedModel(gmfmapmodelFileName, "patch_161380", "gmfmap");
98
		URI newUri = temporarySaveMigratedModel(gmfmapmodelFileName, "patch_161380", "gmfmap");
98
		changeNsUriToOldOne(newUri, "gmfmap", "http://www.eclipse.org/gmf/2005/mappings/2.0");
99
		changeNsUriToOldOne(newUri, "gmfmap", "http://www.eclipse.org/gmf/2005/mappings/2.0");
99
		
100
		
100
		assertOnLoadModelMigrationSuccess(newUri);
101
		assertOnLoadModelMigrationDidNothing(newUri);
101
	}
102
	}
102
103
103
	private static URI createURI(String testModelFileName) {
104
	private static URI createURI(String testModelFileName) {
Lines 114-125 Link Here
114
		ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
115
		ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
115
		
116
		
116
		EList<Resource.Diagnostic> errors = loadHelper.getLoadedResource().getErrors();
117
		EList<Resource.Diagnostic> errors = loadHelper.getLoadedResource().getErrors();
117
		assertTrue(errors.isEmpty());
118
		assertTrue("Errors found after migration: "+errors, errors.isEmpty()); //$NON-NLS-1$
118
		
119
		
119
		assertTrue("Migration warning load status expected", loadHelper.getStatus().matches(IStatus.WARNING)); //$NON-NLS-1$
120
		assertTrue("Migration warning load status expected", loadHelper.getStatus().matches(IStatus.WARNING)); //$NON-NLS-1$
120
		EList<Resource.Diagnostic> warnings = loadHelper.getLoadedResource().getWarnings();
121
		EList<Resource.Diagnostic> warnings = loadHelper.getLoadedResource().getWarnings();
121
		assertEquals("Single Warning diagnostic expected", 1, warnings.size()); //$NON-NLS-1$		
122
		assertEquals("Single Warning diagnostic expected", 1, warnings.size()); //$NON-NLS-1$		
122
		assertTrue("MigrationDiagnostic expected as warning", warnings.get(0) instanceof MigrationResource.Diagnostic); //$NON-NLS-1$
123
		assertTrue("MigrationDiagnostic expected as warning", warnings.get(0) instanceof MigrationResource.Diagnostic); //$NON-NLS-1$
124
		
125
		assertTrue(loadHelper.getLoadedResource() instanceof XMLResource);
126
		XMLResource xmlResource = (XMLResource) loadHelper.getLoadedResource();
127
		assertEquals("Unknown elements were found after migration", 0, xmlResource.getEObjectToExtensionMap().size());
128
	}
129
130
	void assertOnLoadModelMigrationDidNothing(URI uri) throws Exception {
131
		ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
132
		
133
		EList<Resource.Diagnostic> errors = loadHelper.getLoadedResource().getErrors();
134
		assertTrue("Errors after re-run migration on new migrated model: "+errors, errors.isEmpty());
135
		
136
		EList<Resource.Diagnostic> warnings = loadHelper.getLoadedResource().getWarnings();
137
		assertTrue("Warnings after re-run migration on new migrated model: "+warnings, warnings.isEmpty());
138
		
139
		assertTrue(loadHelper.getLoadedResource() instanceof XMLResource);
140
		XMLResource xmlResource = (XMLResource) loadHelper.getLoadedResource();
141
		assertEquals("Unknown elements were found after re-migration", 0, xmlResource.getEObjectToExtensionMap().size());
123
	}
142
	}
124
143
125
	Exception assertOrdinaryLoadModelProblems(URI uri) throws Exception {
144
	Exception assertOrdinaryLoadModelProblems(URI uri) throws Exception {
Lines 161-167 Link Here
161
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenDiagram", "gmfgen");
180
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenDiagram", "gmfgen");
162
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
181
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
163
		
182
		
164
		assertOnLoadModelMigrationSuccess(newUri);
183
		assertOnLoadModelMigrationDidNothing(newUri);
165
	}
184
	}
166
185
167
	/*
186
	/*
Lines 181-187 Link Here
181
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testFeatureLabelModelFacet", "gmfgen");
200
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testFeatureLabelModelFacet", "gmfgen");
182
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
201
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
183
		
202
		
184
		assertOnLoadModelMigrationSuccess(newUri);
203
		assertOnLoadModelMigrationDidNothing(newUri);
185
		checkFeatureLabelModelFacetsMigrated(newUri);
204
		checkFeatureLabelModelFacetsMigrated(newUri);
186
	}
205
	}
187
206
Lines 210-216 Link Here
210
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAuditRootDefaultAndNested", "gmfgen");
229
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAuditRootDefaultAndNested", "gmfgen");
211
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
230
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
212
		
231
		
213
		assertOnLoadModelMigrationSuccess(newUri);
232
		assertOnLoadModelMigrationDidNothing(newUri);
214
	}
233
	}
215
234
216
	public void testGenAuditRootNoDefaultButNested() throws Exception {
235
	public void testGenAuditRootNoDefaultButNested() throws Exception {
Lines 233-239 Link Here
233
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAudits", "gmfgen");
252
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAudits", "gmfgen");
234
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
253
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
235
		
254
		
236
		assertOnLoadModelMigrationSuccess(newUri);
255
		assertOnLoadModelMigrationDidNothing(newUri);
237
	}
256
	}
238
257
239
	public void testGenEditorAuditRootNoDefaultButNested() throws Exception {
258
	public void testGenEditorAuditRootNoDefaultButNested() throws Exception {
Lines 247-253 Link Here
247
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenEditorAuditRootNoDefaultButNested", "gmfgen");
266
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenEditorAuditRootNoDefaultButNested", "gmfgen");
248
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
267
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
249
		
268
		
250
		assertOnLoadModelMigrationSuccess(newUri);
269
		assertOnLoadModelMigrationDidNothing(newUri);
251
	}
270
	}
252
271
253
	public void testGenAuditsCorrectCategories() throws Exception {
272
	public void testGenAuditsCorrectCategories() throws Exception {
Lines 263-269 Link Here
263
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAuditsCorrectCategories", "gmfgen");
282
		URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAuditsCorrectCategories", "gmfgen");
264
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
283
		changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
265
		
284
		
266
		assertOnLoadModelMigrationSuccess(newUri);
285
		assertOnLoadModelMigrationDidNothing(newUri);
267
		
286
		
268
		checkModelAndCorrectCategories(newUri);
287
		checkModelAndCorrectCategories(newUri);
269
	}
288
	}
Lines 272-277 Link Here
272
		ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
291
		ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
273
		Resource resource = loadHelper.getLoadedResource();
292
		Resource resource = loadHelper.getLoadedResource();
274
		File newGenmodelFile = File.createTempFile(tempFilename, tempFileExtension.startsWith(".") ? tempFileExtension : "."+tempFileExtension);
293
		File newGenmodelFile = File.createTempFile(tempFilename, tempFileExtension.startsWith(".") ? tempFileExtension : "."+tempFileExtension);
294
		newGenmodelFile.deleteOnExit();
275
		URI newUri = URI.createFileURI(newGenmodelFile.getAbsolutePath());
295
		URI newUri = URI.createFileURI(newGenmodelFile.getAbsolutePath());
276
		resource.setURI(newUri);
296
		resource.setURI(newUri);
277
		try {
297
		try {
Lines 335-341 Link Here
335
		URI newMapUri = temporarySaveMigratedModel(gmfmapmodelFileName, "testNotChangingOrderOfLabelMappings", "gmfmap"); //$NON-NLS-1$ //$NON-NLS-2$
355
		URI newMapUri = temporarySaveMigratedModel(gmfmapmodelFileName, "testNotChangingOrderOfLabelMappings", "gmfmap"); //$NON-NLS-1$ //$NON-NLS-2$
336
		changeNsUriToOldOne(newMapUri, "gmfmap", "http://www.eclipse.org/gmf/2005/mappings/2.0"); //$NON-NLS-1$ //$NON-NLS-2$
356
		changeNsUriToOldOne(newMapUri, "gmfmap", "http://www.eclipse.org/gmf/2005/mappings/2.0"); //$NON-NLS-1$ //$NON-NLS-2$
337
		
357
		
338
		assertOnLoadModelMigrationSuccess(newMapUri);
358
		assertOnLoadModelMigrationDidNothing(newMapUri);
339
		checkOrderOfLabelMappings(newMapUri);
359
		checkOrderOfLabelMappings(newMapUri);
340
	}
360
	}
341
361
Lines 350-356 Link Here
350
		URI newMapUri = temporarySaveMigratedModel(gmfmapmodelFileName, "testRequiredPluginsMoved", "gmfgen"); //$NON-NLS-1$ //$NON-NLS-2$
370
		URI newMapUri = temporarySaveMigratedModel(gmfmapmodelFileName, "testRequiredPluginsMoved", "gmfgen"); //$NON-NLS-1$ //$NON-NLS-2$
351
		changeNsUriToOldOne(newMapUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0"); //$NON-NLS-1$ //$NON-NLS-2$
371
		changeNsUriToOldOne(newMapUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0"); //$NON-NLS-1$ //$NON-NLS-2$
352
		
372
		
353
		assertOnLoadModelMigrationSuccess(newMapUri);
373
		assertOnLoadModelMigrationDidNothing(newMapUri);
354
		checkAllRequiredPluginsAreNotLost(newMapUri);
374
		checkAllRequiredPluginsAreNotLost(newMapUri);
355
	}
375
	}
356
376
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationHelper.java (-59 / +2 lines)
Lines 10-31 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.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.emf.ecore.EClass;
13
import org.eclipse.emf.ecore.EClass;
17
import org.eclipse.emf.ecore.EClassifier;
14
import org.eclipse.emf.ecore.EClassifier;
18
import org.eclipse.emf.ecore.EFactory;
15
import org.eclipse.emf.ecore.EFactory;
19
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.EStructuralFeature;
17
import org.eclipse.emf.ecore.EStructuralFeature;
21
import org.eclipse.emf.ecore.util.EcoreUtil;
22
import org.eclipse.emf.ecore.xmi.XMLResource;
18
import org.eclipse.emf.ecore.xmi.XMLResource;
23
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
19
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
24
20
25
public class MigrationHelper extends XMIHelperImpl {
21
public class MigrationHelper extends XMIHelperImpl {
26
	private final MigrationHelperDelegate myDelegate;
22
	private final MigrationHelperDelegate myDelegate;
27
	private boolean myIsDelegateDisabled = true;
28
	private Map<EStructuralFeature, EStructuralFeature> myNarrowedFeatureTypes;
29
23
30
	public MigrationHelper(XMLResource resource, MigrationHelperDelegate delegate) {
24
	public MigrationHelper(XMLResource resource, MigrationHelperDelegate delegate) {
31
		super(resource);
25
		super(resource);
Lines 33-51 Link Here
33
		myDelegate = delegate;
27
		myDelegate = delegate;
34
	}
28
	}
35
29
36
	void enableDelegate(boolean enabled) {
30
	boolean isMigrationApplied() {
37
		myIsDelegateDisabled = !enabled;
31
		return myDelegate.isMigrationApplied();
38
	}
39
40
	boolean isEnabled() {
41
		return !myIsDelegateDisabled;
42
	}
32
	}
43
	
33
	
44
	@Override
34
	@Override
45
	public EObject createObject(EFactory factory, EClassifier type) {
35
	public EObject createObject(EFactory factory, EClassifier type) {
46
		if (myIsDelegateDisabled) {
47
			return super.createObject(factory, type);
48
		}
49
		EObject result = myDelegate.createObject(factory, type);
36
		EObject result = myDelegate.createObject(factory, type);
50
		if (result == null) {
37
		if (result == null) {
51
			result = super.createObject(factory, type);
38
			result = super.createObject(factory, type);
Lines 56-69 Link Here
56
43
57
	@Override
44
	@Override
58
	public void setValue(EObject object, EStructuralFeature feature, Object value, int position) {
45
	public void setValue(EObject object, EStructuralFeature feature, Object value, int position) {
59
		if (myIsDelegateDisabled) {
60
			super.setValue(object, feature, value, position);
61
			return; 
62
		}
63
		EStructuralFeature originalFeature = getOriginalFeature(feature);
64
		if (originalFeature != null) {
65
			feature = originalFeature;
66
		}
67
		if (!myDelegate.setValue(object, feature, value, position)) {
46
		if (!myDelegate.setValue(object, feature, value, position)) {
68
			super.setValue(object, feature, value, position);
47
			super.setValue(object, feature, value, position);
69
		}
48
		}
Lines 71-97 Link Here
71
50
72
	@Override
51
	@Override
73
	public EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement) {
52
	public EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement) {
74
		if (myIsDelegateDisabled) {
75
			return super.getFeature(eClass, namespaceURI, name, isElement);
76
		}
77
		EStructuralFeature result = myDelegate.getFeature(eClass, namespaceURI, name, isElement);
53
		EStructuralFeature result = myDelegate.getFeature(eClass, namespaceURI, name, isElement);
78
		if (result == null) {
54
		if (result == null) {
79
			result = super.getFeature(eClass, namespaceURI, name, isElement);
55
			result = super.getFeature(eClass, namespaceURI, name, isElement);
80
		}
56
		}
81
		EClass narrow = myDelegate.getStructuralFeatureType(result);
82
		if (narrow != null) {
83
			EStructuralFeature fake = addNarrowedFeature(result);
84
			fake.setEType(narrow);
85
			return fake;
86
		}
87
		return result;
57
		return result;
88
	}
58
	}
89
	
59
	
90
	@Override
60
	@Override
91
	public EClassifier getType(EFactory factory, String typeName) {
61
	public EClassifier getType(EFactory factory, String typeName) {
92
		if (myIsDelegateDisabled) {
93
			return super.getType(factory, typeName);
94
		}
95
		EClassifier result = myDelegate.getType(factory, typeName);
62
		EClassifier result = myDelegate.getType(factory, typeName);
96
		if (result == null) {
63
		if (result == null) {
97
			result = super.getType(factory, typeName);
64
			result = super.getType(factory, typeName);
Lines 102-131 Link Here
102
	@Override
69
	@Override
103
	public void popContext() {
70
	public void popContext() {
104
		super.popContext();
71
		super.popContext();
105
		if (myIsDelegateDisabled) {
106
			return;
107
		}
108
		myDelegate.postProcess();
72
		myDelegate.postProcess();
109
	}
73
	}
110
	
111
	@Override
112
	public void addPrefix(String prefix, String uri) {
113
		super.addPrefix(prefix, uri);
114
		if (myDelegate.isOldVersionDetected(uri)) {
115
			enableDelegate(true);
116
		}
117
	}
118
119
	protected EStructuralFeature getOriginalFeature(EStructuralFeature feature) {
120
		return myNarrowedFeatureTypes == null ? null : myNarrowedFeatureTypes.get(feature);
121
	}
122
	
123
	protected EStructuralFeature addNarrowedFeature(EStructuralFeature originalFeature) {
124
		if (myNarrowedFeatureTypes == null) {
125
			myNarrowedFeatureTypes = new HashMap<EStructuralFeature, EStructuralFeature>();
126
		}
127
		EStructuralFeature result = (EStructuralFeature) EcoreUtil.copy(originalFeature);
128
		myNarrowedFeatureTypes.put(result, originalFeature);
129
		return result;
130
	}
131
}
74
}
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationHelperDelegate.java (-3 / +1 lines)
Lines 24-36 Link Here
24
	
24
	
25
	public EClassifier getType(EFactory factory, String typeName);
25
	public EClassifier getType(EFactory factory, String typeName);
26
	
26
	
27
	public EClass getStructuralFeatureType(EStructuralFeature feature);
28
29
	public EObject createObject(EFactory factory, EClassifier type);
27
	public EObject createObject(EFactory factory, EClassifier type);
30
	
28
	
31
	public void postProcess();
29
	public void postProcess();
32
30
33
	public void processObject(EObject result);
31
	public void processObject(EObject result);
34
32
35
	public boolean isOldVersionDetected(String uriString);
33
	public boolean isMigrationApplied();
36
}
34
}
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationHelperDelegateImpl.java (-24 / +28 lines)
Lines 28-42 Link Here
28
28
29
public class MigrationHelperDelegateImpl implements MigrationHelperDelegate {
29
public class MigrationHelperDelegateImpl implements MigrationHelperDelegate {
30
	private final EStructuralFeature myDeletedAttribute = EcoreFactory.eINSTANCE.createEAttribute();
30
	private final EStructuralFeature myDeletedAttribute = EcoreFactory.eINSTANCE.createEAttribute();
31
	private boolean isMigrationApplied;
31
32
32
	public MigrationHelperDelegateImpl() {
33
	public MigrationHelperDelegateImpl() {
33
		super();
34
		super();
34
		myDeletedAttribute.setName("attributeIsDeleted"); //$NON-NLS-1$
35
		myDeletedAttribute.setName("attributeIsDeleted"); //$NON-NLS-1$
35
		myDeletedAttribute.setEType(EcorePackage.eINSTANCE.getEString());
36
		myDeletedAttribute.setEType(EcorePackage.eINSTANCE.getEString());
37
		isMigrationApplied = false;
36
	}
38
	}
37
39
38
	private Map<EClassifier, Collection<String>> myDeletedAttributes = new HashMap<EClassifier, Collection<String>>();
40
	private Map<EClassifier, Collection<String>> myDeletedAttributes = new HashMap<EClassifier, Collection<String>>();
39
	private Map<EReference, EClass> myNarrowReferenceTypes = new HashMap<EReference, EClass>();
41
	private Map<String, EClass> myNarrowedTypes = new HashMap<String, EClass>();
40
	private Map<EClass, Map<String, EStructuralFeature>> myRenamedAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
42
	private Map<EClass, Map<String, EStructuralFeature>> myRenamedAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
41
	private Map<String, EClassifier> myRenamedTypes = new HashMap<String, EClassifier>();
43
	private Map<String, EClassifier> myRenamedTypes = new HashMap<String, EClassifier>();
42
	
44
	
Lines 45-58 Link Here
45
		myDeletedAttributes.put(classifier, Arrays.asList(deletedAttrNames));
47
		myDeletedAttributes.put(classifier, Arrays.asList(deletedAttrNames));
46
	}
48
	}
47
	
49
	
48
	public void registerNarrowReferenceType(EReference reference, EClass concreteType) {
49
		myNarrowReferenceTypes.put(reference, concreteType);
50
	}
51
	
52
	public void registerRenamedAttributes(EClass eClass, Map<String, EStructuralFeature> renamedAttributes) {
50
	public void registerRenamedAttributes(EClass eClass, Map<String, EStructuralFeature> renamedAttributes) {
53
		myRenamedAttributes.put(eClass, renamedAttributes);
51
		myRenamedAttributes.put(eClass, renamedAttributes);
54
	}
52
	}
55
	
53
	
54
	public void registerNarrowedAbstractType(String abstractTypeName, EClass narrowedType) {
55
		myNarrowedTypes.put(abstractTypeName, narrowedType);
56
	}
57
	
56
	public void registerRenamedType(String oldTypeName, EClassifier newType) {
58
	public void registerRenamedType(String oldTypeName, EClassifier newType) {
57
		myRenamedTypes.put(oldTypeName, newType);
59
		myRenamedTypes.put(oldTypeName, newType);
58
	}
60
	}
Lines 76-103 Link Here
76
		return result;
78
		return result;
77
	}
79
	}
78
	
80
	
79
	public EClass getNarrowReferenceType(EStructuralFeature feature) {
81
	public EClass getNarrowReferenceType(String abstractTypeName) {
80
		return myNarrowReferenceTypes.get(feature);
82
		return myNarrowedTypes.get(abstractTypeName);
81
	}
83
	}
82
84
83
	public EStructuralFeature getRenamedFeatureFor(EClass clazz, String name) {
85
	public EStructuralFeature getRenamedFeatureFor(EClass clazz, String name) {
84
	    Map<String, EStructuralFeature> renamings = myRenamedAttributes.get(clazz);
86
	    Map<String, EStructuralFeature> renamings = myRenamedAttributes.get(clazz);
85
		EStructuralFeature result = renamings != null ? renamings.get(name) : null;
87
		return renamings != null ? renamings.get(name) : null;
86
		for (Iterator<EClass> it=clazz.getEAllSuperTypes().iterator(); result == null && it.hasNext();) {
87
			EClass nextParent = it.next();
88
			result = getRenamedFeatureFor(nextParent, name);
89
		}
90
		return result;
91
	}
88
	}
92
89
93
	public EClassifier getRenamedType(String typeName) {
90
	public EClassifier getRenamedType(String typeName) {
94
		return myRenamedTypes.get(typeName);
91
		return myRenamedTypes.get(typeName);
95
	}
92
	}
96
93
97
	public EClass getStructuralFeatureType(EStructuralFeature feature) {
98
		return getNarrowReferenceType(feature);
99
	}
100
101
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
94
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
102
		return myDeletedAttribute.equals(feature);
95
		return myDeletedAttribute.equals(feature);
103
	}
96
	}
Lines 107-125 Link Here
107
		EStructuralFeature rename = null;
100
		EStructuralFeature rename = null;
108
		if ((rename = getRenamedFeatureFor(eClass, name)) != null) {
101
		if ((rename = getRenamedFeatureFor(eClass, name)) != null) {
109
			result = rename;
102
			result = rename;
103
			fireMigrationApplied(true);
110
		} else if (isAttributeDeleted(eClass, name)) {
104
		} else if (isAttributeDeleted(eClass, name)) {
111
			result = myDeletedAttribute;
105
			result = myDeletedAttribute;
106
			fireMigrationApplied(true);
112
		}
107
		}
113
		return result;
108
		return result;
114
	}
109
	}
115
110
116
	public EClassifier getType(EFactory factory, String typeName) {
111
	public EClassifier getType(EFactory factory, String typeName) {
117
		EClassifier result = null;
112
		EClassifier renamedType = getRenamedType(typeName);
118
		EClassifier type = getRenamedType(typeName);
113
		if (renamedType != null) {
119
		if (type != null) {
114
			fireMigrationApplied(true);
120
			result = type;
115
			return renamedType;
121
		}
116
		}
122
		return result;
117
		EClassifier narrowedType = getNarrowReferenceType(typeName);
118
		if (narrowedType != null) {
119
			fireMigrationApplied(true);
120
			return narrowedType;
121
		}
122
		return null;
123
	}
123
	}
124
124
125
	public EObject createObject(EFactory factory, EClassifier type) {
125
	public EObject createObject(EFactory factory, EClassifier type) {
Lines 132-139 Link Here
132
	public void processObject(EObject result) {
132
	public void processObject(EObject result) {
133
	}
133
	}
134
134
135
	public boolean isOldVersionDetected(String uriString) {
135
	public boolean isMigrationApplied() {
136
		return true;
136
		return isMigrationApplied;
137
	}
138
	
139
	protected void fireMigrationApplied(boolean applied) {
140
		isMigrationApplied = applied;
137
	}
141
	}
138
	
142
	
139
	protected static EReference createNewReference(String name, EClass eType, boolean isContainment) {
143
	protected static EReference createNewReference(String name, EClass eType, boolean isContainment) {
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationResource.java (-3 / +5 lines)
Lines 43-57 Link Here
43
	}
43
	}
44
44
45
	protected void handlePostLoadSuccess() {
45
	protected void handlePostLoadSuccess() {
46
		if (myMigrationHelper != null && myMigrationHelper.isEnabled()) {
46
		if (myMigrationHelper != null && myMigrationHelper.isMigrationApplied()) {
47
			Diagnostic diagnostic = MigrationResource.createMessageDiagnostic(this, Messages.oldModelVersionLoadedMigrationRequired);
47
			Diagnostic diagnostic = MigrationResource.createMessageDiagnostic(this, Messages.oldModelVersionLoadedMigrationRequired);
48
			getWarnings().add(0, diagnostic);
48
			getWarnings().add(0, diagnostic);
49
		}
49
		}
50
	}
50
	}
51
51
52
	protected void handlePostLoadException(Exception e) {
52
	protected void handlePostLoadException(Exception e) {
53
		Diagnostic diagnostic = MigrationResource.createMessageDiagnostic(this, Messages.oldModelVersionLoadErrorMigrationMayBeRequired);
53
		if (myMigrationHelper != null && myMigrationHelper.isMigrationApplied()) {
54
		getErrors().add(0, diagnostic);
54
			Diagnostic diagnostic = MigrationResource.createMessageDiagnostic(this, Messages.oldModelVersionLoadErrorMigrationMayBeRequired);
55
			getErrors().add(0, diagnostic);
56
		}
55
	}
57
	}
56
58
57
	@Override
59
	@Override

Return to bug 188768