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

(-)src/org/eclipse/gmf/runtime/emf/core/clipboard/CopyingResource.java (-4 / +28 lines)
Lines 77-82 Link Here
77
	 *  
77
	 *  
78
	 */
78
	 */
79
	private void createNewIDs() {
79
	private void createNewIDs() {
80
		// OK to get all contents because we have to copy
81
		//    the entire model content of this resource
80
		Iterator it = xmlResource.getAllContents();
82
		Iterator it = xmlResource.getAllContents();
81
		while (it.hasNext()) {
83
		while (it.hasNext()) {
82
			setID((EObject) it.next(), EcoreUtil.generateUUID());
84
			setID((EObject) it.next(), EcoreUtil.generateUUID());
Lines 234-240 Link Here
234
	}
236
	}
235
237
236
	private boolean isInResource(EObject eObject) {
238
	private boolean isInResource(EObject eObject) {
237
		return (eObject.eResource() == xmlResource);
239
		// in case of cross-resource containment, the 'eObject' may be in a
240
		//     different resource than xmlResource, though one of its containers
241
		//     may be
242
		while (eObject != null) {
243
			if (((InternalEObject) eObject).eDirectResource() == xmlResource) {
244
				return true;
245
			}
246
			
247
			eObject = eObject.eContainer();
248
		}
249
		
250
		return false;
238
	}
251
	}
239
252
240
	public EList getContents() {
253
	public EList getContents() {
Lines 320-329 Link Here
320
	}
333
	}
321
334
322
	private void copyIDs() {
335
	private void copyIDs() {
336
		// OK to get all contents because we have to copy
337
		//    the entire model content of this resource
338
		XMLResource lastRes = null;
339
		
323
		for (Iterator iter = xmlResource.getAllContents(); iter.hasNext(); ) {
340
		for (Iterator iter = xmlResource.getAllContents(); iter.hasNext(); ) {
324
			EObject eObject = (EObject)iter.next();
341
			InternalEObject eObject = (InternalEObject)iter.next();
325
			getEObjectToIDMap().put(eObject, xmlResource.getID(eObject));
342
			
326
			getIDToEObjectMap().put(xmlResource.getID(eObject), eObject);
343
			if (eObject.eDirectResource() != null) {
344
				// ensure that we only ask the resource that actually contains
345
				//    an object for that object's ID
346
				lastRes = (XMLResource) eObject.eDirectResource();
347
			}
348
			
349
			getEObjectToIDMap().put(eObject, lastRes.getID(eObject));
350
			getIDToEObjectMap().put(lastRes.getID(eObject), eObject);
327
		}
351
		}
328
	}
352
	}
329
}
353
}
(-)src/org/eclipse/gmf/runtime/emf/clipboard/core/CopyOperation.java (-3 / +5 lines)
Lines 160-167 Link Here
160
			originalEObject = (EObject) mainEObjectIt.next();
160
			originalEObject = (EObject) mainEObjectIt.next();
161
			getCopyAlwaysObjects(originalEObject, copyAlwaysSet,
161
			getCopyAlwaysObjects(originalEObject, copyAlwaysSet,
162
				combinedCopyAlwaysSet);
162
				combinedCopyAlwaysSet);
163
			//now get copy-always for the originalObject's children
163
			//now get copy-always for the originalObject's children,
164
			// -recursively
164
			//   recursively.  Use eAllContents() instead of
165
			//   EcoreUtil.getAllProperContents() because we really need all
166
			//   of the model sub-tree
165
			Iterator childrenIt = originalEObject.eAllContents();
167
			Iterator childrenIt = originalEObject.eAllContents();
166
			EObject directChild = null;
168
			EObject directChild = null;
167
			while (childrenIt.hasNext()) {
169
			while (childrenIt.hasNext()) {
Lines 357-363 Link Here
357
	}
359
	}
358
360
359
	private void removeNonCopyableObject(Collection collection) {
361
	private void removeNonCopyableObject(Collection collection) {
360
		//basically IModel
362
		// model roots are not copyable
361
		Iterator it = collection.iterator();
363
		Iterator it = collection.iterator();
362
		EObject eObject = null;
364
		EObject eObject = null;
363
		while (it.hasNext()) {
365
		while (it.hasNext()) {
(-)src/org/eclipse/gmf/runtime/emf/clipboard/core/AbstractClipboardSupport.java (-11 / +5 lines)
Lines 24-29 Link Here
24
import org.eclipse.emf.ecore.EReference;
24
import org.eclipse.emf.ecore.EReference;
25
import org.eclipse.emf.ecore.EStructuralFeature;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.emf.ecore.EcorePackage;
26
import org.eclipse.emf.ecore.EcorePackage;
27
import org.eclipse.emf.ecore.util.EcoreUtil;
27
import org.eclipse.emf.ecore.xmi.XMLResource;
28
import org.eclipse.emf.ecore.xmi.XMLResource;
28
29
29
30
Lines 240-257 Link Here
240
	 * Simply removes an <code>eObject</code> from its container.
241
	 * Simply removes an <code>eObject</code> from its container.
241
	 */
242
	 */
242
	public void destroy(EObject eObject) {
243
	public void destroy(EObject eObject) {
243
		EObject container = eObject.eContainer();
244
		EcoreUtil.remove(eObject);
244
		
245
		
245
		if (container != null) {
246
		if (eObject.eResource() != null) {
246
			EReference ref = eObject.eContainmentFeature();
247
			// it was a cross-resource-contained element
247
			
248
			eObject.eResource().getContents().remove(eObject);
248
			if (ref != null) {  // shouldn't be null!
249
				if (ref.isMany()) {
250
					((Collection) container.eGet(ref)).remove(eObject);
251
				} else {
252
					container.eSet(ref, null);
253
				}
254
			}
255
		}
249
		}
256
	}
250
	}
257
251
(-)src/org/eclipse/gmf/runtime/emf/clipboard/core/internal/SavingEMFResource.java (-1 / +14 lines)
Lines 101-108 Link Here
101
		Iterator entryIt = parentObjectMap.entrySet().iterator();
101
		Iterator entryIt = parentObjectMap.entrySet().iterator();
102
		while (entryIt.hasNext()) {
102
		while (entryIt.hasNext()) {
103
			Map.Entry entry = (Map.Entry) entryIt.next();
103
			Map.Entry entry = (Map.Entry) entryIt.next();
104
			
105
			// get the basic list view of the contents list to avoid resolving
106
			//    cross-resource containment proxies
104
			Collections.sort((List) entry.getValue(), new ListIndexComparator(
107
			Collections.sort((List) entry.getValue(), new ListIndexComparator(
105
				((EObject) entry.getKey()).eContents()));
108
				((InternalEList) ((EObject) entry.getKey()).eContents()).basicList()));
106
			list.addAll((List) entry.getValue());
109
			list.addAll((List) entry.getValue());
107
		}
110
		}
108
		contentSet = new LinkedHashSet(list);
111
		contentSet = new LinkedHashSet(list);
Lines 120-125 Link Here
120
		while (it.hasNext()) {
123
		while (it.hasNext()) {
121
			EObject eObj = (EObject) it.next();
124
			EObject eObj = (EObject) it.next();
122
			addToSerializationAnnotation(eAnnotation, eObj);
125
			addToSerializationAnnotation(eAnnotation, eObj);
126
			
127
			// OK to resolve containment proxies because we must load the
128
			//    entire model sub-tree in order to copy it
123
			TreeIterator contentIt = eObj.eAllContents();
129
			TreeIterator contentIt = eObj.eAllContents();
124
			while (contentIt.hasNext()) {
130
			while (contentIt.hasNext()) {
125
				EObject childEObj = (EObject) contentIt.next();
131
				EObject childEObj = (EObject) contentIt.next();
Lines 212-217 Link Here
212
	protected XMLSave createXMLSave() {
218
	protected XMLSave createXMLSave() {
213
		return new XMISaveImpl(createXMLHelper()) {
219
		return new XMISaveImpl(createXMLHelper()) {
214
220
221
			protected void saveElement(InternalEObject o, EStructuralFeature f) {
222
				// do not save cross-resource-contained objects as hrefs, because
223
				//    the clipboard resource must actually duplicate all of the
224
				//    original data
225
				saveElement((EObject) o, f);
226
			}
227
215
			protected void saveElement(EObject o, EStructuralFeature f) {
228
			protected void saveElement(EObject o, EStructuralFeature f) {
216
				if (excludedObjects.contains(o)) {
229
				if (excludedObjects.contains(o)) {
217
					return;
230
					return;
(-)src/org/eclipse/gmf/runtime/emf/clipboard/core/internal/PasteIntoParentOperation.java (-1 / +16 lines)
Lines 208-214 Link Here
208
208
209
		if (!parentRes.getURI().equals(sourceUri)) {
209
		if (!parentRes.getURI().equals(sourceUri)) {
210
			// don't need to check anything when pasting into the source
210
			// don't need to check anything when pasting into the source
211
			//    resource (from which we cut in the first place)
211
			//    resource (from which we cut in the first place).  OK to
212
			//    get all contents of 'toPaste' because the clipboard resource
213
			//    has no cross-resource containment
212
			Iterator iter = EcoreUtil.getAllContents(Collections.singleton(toPaste));
214
			Iterator iter = EcoreUtil.getAllContents(Collections.singleton(toPaste));
213
			while (!result && iter.hasNext()) {
215
			while (!result && iter.hasNext()) {
214
				result = parentRes.getEObject(
216
				result = parentRes.getEObject(
Lines 260-265 Link Here
260
			EObject eObj = (EObject) it.next();
262
			EObject eObj = (EObject) it.next();
261
			if ((eObj instanceof EAnnotation) == false) {
263
			if ((eObj instanceof EAnnotation) == false) {
262
				resolveLocalProxies(eObj);
264
				resolveLocalProxies(eObj);
265
				
266
				// OK to get all contents of 'eObj' because the clipboard resource
267
				//    has no cross-resource containment
263
				Iterator contentIt = eObj.eAllContents();
268
				Iterator contentIt = eObj.eAllContents();
264
				while (contentIt.hasNext()) {
269
				while (contentIt.hasNext()) {
265
					resolveLocalProxies((EObject) contentIt.next());
270
					resolveLocalProxies((EObject) contentIt.next());
Lines 365-370 Link Here
365
370
366
	private void fireCreateEvents() {
371
	private void fireCreateEvents() {
367
		List elements = new ArrayList();
372
		List elements = new ArrayList();
373
		
374
		// OK to get all contents because the elements were all pasted into
375
		//    a single resource (no cross-resource containments)
368
		Iterator it = EcoreUtil.getAllContents(getPastedElementSet());
376
		Iterator it = EcoreUtil.getAllContents(getPastedElementSet());
369
		while (it.hasNext()) {
377
		while (it.hasNext()) {
370
			elements.add(it.next());
378
			elements.add(it.next());
Lines 410-415 Link Here
410
					.getPastedElement();
418
					.getPastedElement();
411
				if (getPastedElementSet().contains(pastedChildElement)) {
419
				if (getPastedElementSet().contains(pastedChildElement)) {
412
					recycleObjectId(pastedChildElement);
420
					recycleObjectId(pastedChildElement);
421
					
422
					// OK to get all contents of 'pastedChildElement' because we
423
					//    paste all elements into the same resource (no
424
					//    cross-resource containment)
413
					TreeIterator contentIt = pastedChildElement.eAllContents();
425
					TreeIterator contentIt = pastedChildElement.eAllContents();
414
					while (contentIt.hasNext()) {
426
					while (contentIt.hasNext()) {
415
						recycleObjectId((EObject) contentIt.next());
427
						recycleObjectId((EObject) contentIt.next());
Lines 461-466 Link Here
461
			pastedEObject = (EObject) it.next();
473
			pastedEObject = (EObject) it.next();
462
			checkReferences(pastedEObject);
474
			checkReferences(pastedEObject);
463
			//now, resolveReferences for contained elements recursively
475
			//now, resolveReferences for contained elements recursively
476
			// OK to get all contents of 'pastedEObject' because we
477
			//    paste all elements into the same resource (no
478
			//    cross-resource containment)
464
			TreeIterator contentIt = pastedEObject.eAllContents();
479
			TreeIterator contentIt = pastedEObject.eAllContents();
465
			while (contentIt.hasNext()) {
480
			while (contentIt.hasNext()) {
466
				checkReferences((EObject) contentIt.next());
481
				checkReferences((EObject) contentIt.next());

Return to bug 139049