diff options
author | Martin Fluegge | 2010-10-30 09:58:41 +0000 |
---|---|---|
committer | Martin Fluegge | 2010-10-30 09:58:41 +0000 |
commit | 1fa75dcde1b95c493bc50a7ed6dd2cc57d751cf9 (patch) | |
tree | b990a0c97349373d086267f60bef628b87baf92c /plugins/org.eclipse.emf.cdo.dawn | |
parent | 8c3aedca087a0556394b1464d97bd0394a5aad68 (diff) | |
download | cdo-1fa75dcde1b95c493bc50a7ed6dd2cc57d751cf9.tar.gz cdo-1fa75dcde1b95c493bc50a7ed6dd2cc57d751cf9.tar.xz cdo-1fa75dcde1b95c493bc50a7ed6dd2cc57d751cf9.zip |
fixed minor bugs and moved ResourceHelper to dawn.util
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn')
6 files changed, 18 insertions, 1077 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.dawn/META-INF/MANIFEST.MF index d40f608090..e8ff091d1a 100644 --- a/plugins/org.eclipse.emf.cdo.dawn/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.dawn/META-INF/MANIFEST.MF @@ -33,7 +33,6 @@ Export-Package: org.eclipse.emf.cdo.dawn;version="1.0.0", org.eclipse.emf.cdo.dawn.editors;version="1.0.0", org.eclipse.emf.cdo.dawn.editors.impl;version="1.0.0", org.eclipse.emf.cdo.dawn.elementtypes;version="1.0.0", - org.eclipse.emf.cdo.dawn.exceptions;version="1.0.0", org.eclipse.emf.cdo.dawn.handlers;version="1.0.0";x-internal:=true, org.eclipse.emf.cdo.dawn.helper;version="1.0.0", org.eclipse.emf.cdo.dawn.notifications;version="1.0.0", diff --git a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/exceptions/EClassIncompatibleException.java b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/exceptions/EClassIncompatibleException.java deleted file mode 100644 index 01cbe24ec6..0000000000 --- a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/exceptions/EClassIncompatibleException.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Martin Flüuege - initial API and implementation - ******************************************************************************/ -package org.eclipse.emf.cdo.dawn.exceptions; - -/** - * @author Martin Fluegge - */ -public class EClassIncompatibleException extends Exception -{ - - private static final long serialVersionUID = 1L; - - public EClassIncompatibleException() - { - super(); - } - - public EClassIncompatibleException(String s) - { - super(s); - } -} diff --git a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/notifications/impl/DawnGMFHandler.java b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/notifications/impl/DawnGMFHandler.java index d799e622ec..7286319eca 100644 --- a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/notifications/impl/DawnGMFHandler.java +++ b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/notifications/impl/DawnGMFHandler.java @@ -209,7 +209,13 @@ public class DawnGMFHandler extends BasicDawnListener private void handleObject(CDOObject dirtyObject) { + + if (dirtyObject.cdoInvalid()) + { + return; + } EObject element = CDOUtil.getEObject(dirtyObject); // either sementic object or notational + View view = DawnDiagramUpdater.findView(element); if (DawnConflictHelper.isConflicted(dirtyObject)) diff --git a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/synchronize/DawnChangeHelper.java b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/synchronize/DawnChangeHelper.java index c1b839374b..d555e9df29 100644 --- a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/synchronize/DawnChangeHelper.java +++ b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/synchronize/DawnChangeHelper.java @@ -10,8 +10,9 @@ ******************************************************************************/ package org.eclipse.emf.cdo.dawn.synchronize; -import org.eclipse.emf.cdo.dawn.exceptions.EClassIncompatibleException; import org.eclipse.emf.cdo.dawn.util.DawnDiagramUpdater; +import org.eclipse.emf.cdo.dawn.util.DawnResourceHelper; +import org.eclipse.emf.cdo.dawn.util.exceptions.EClassIncompatibleException; import org.eclipse.emf.cdo.internal.dawn.bundle.OM; import org.eclipse.net4j.util.om.trace.ContextTracer; @@ -414,14 +415,14 @@ public class DawnChangeHelper { Edge edge = (Edge)edgeEditpart.getModel(); - edge.setBendpoints((Bendpoints)ResourceHelper.createCopy(oldEdge.getBendpoints())); + edge.setBendpoints((Bendpoints)DawnResourceHelper.createCopy(oldEdge.getBendpoints())); if (oldEdge.getSourceAnchor() != null) { - edge.setSourceAnchor((Anchor)ResourceHelper.createCopy(oldEdge.getSourceAnchor())); + edge.setSourceAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getSourceAnchor())); } if (oldEdge.getTargetAnchor() != null) { - edge.setTargetAnchor((Anchor)ResourceHelper.createCopy(oldEdge.getTargetAnchor())); + edge.setTargetAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getTargetAnchor())); } edgeEditpart.refresh(); @@ -603,7 +604,7 @@ public class DawnChangeHelper { try { - ResourceHelper.updateEObject(element, model); + DawnResourceHelper.updateEObject(element, model); } catch (EClassIncompatibleException e) { diff --git a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/synchronize/ResourceHelper.java b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/synchronize/ResourceHelper.java deleted file mode 100644 index 07ca41dd34..0000000000 --- a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/synchronize/ResourceHelper.java +++ /dev/null @@ -1,1040 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Martin Fluegge - initial API and implementation - ******************************************************************************/ -package org.eclipse.emf.cdo.dawn.synchronize; - -/** - * - * @author Martin Fluegge - */ -import org.eclipse.emf.cdo.dawn.exceptions.EClassIncompatibleException; -import org.eclipse.emf.cdo.internal.dawn.bundle.OM; - -import org.eclipse.net4j.util.om.trace.ContextTracer; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EAnnotation; -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EGenericType; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EOperation; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.xmi.XMIResource; -import org.eclipse.emf.ecore.xmi.XMLHelper; -import org.eclipse.emf.ecore.xmi.XMLResource; -import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl; -import org.eclipse.emf.ecore.xmi.impl.XMILoadImpl; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; -import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl; -import org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl; - -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.gef.EditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; -import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; -import org.eclipse.gmf.runtime.notation.Bounds; -import org.eclipse.gmf.runtime.notation.Diagram; -import org.eclipse.gmf.runtime.notation.Edge; -import org.eclipse.gmf.runtime.notation.Node; -import org.eclipse.gmf.runtime.notation.RelativeBendpoints; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class ResourceHelper -{ - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ResourceHelper.class); - - public static String getXmiId(EObject eObject) - { - Resource xmiResource = eObject.eResource(); - if (xmiResource == null) - { - return null; - } - - return ((XMLResource)xmiResource).getID(eObject); - } - - public static String getXmiId(EObject eObject, Resource xmiResource) - { - - if (xmiResource == null) - { - return null; - } - - return ((XMLResource)xmiResource).getID(eObject); - } - - public static void setXmiId(EObject eObject, String id) - { - Resource xmiResource = eObject.eResource(); - if (xmiResource != null) - { - ((XMLResource)xmiResource).setID(eObject, id); - } - else - { - if (TRACER.isEnabled()) - { - TRACER.trace("Could set xmi id, because object is not attached to a resource!"); //$NON-NLS-1$ - } - } - } - - // public static String resourceToString(Resource res) - // { - // - // StringBuffer s = new StringBuffer(); - // Diagram dia = null; - // for (Object o : res.getContents()) - // { - // LOG.info(o); - // if (o instanceof Diagram) - // { - // dia = (Diagram)o; - // break; - // } - // } - // - // LOG.info("-----------------------------------------------------"); - // - // LOG.info("Diagram" + dia + ""); - // if (dia != null) - // { - // try - // { - // for (Object o : dia.getChildren()) - // { - // Node n = (Node)o; - // EObject element = n.getElement(); - // - // LOG.info(o + " (" + ResourceHelper.getXmiId((EObject)o) + ")"); - // - // for (EAttribute attribute : element.eClass().getEAllAttributes()) - // { - // LOG.info("\t" + attribute.getName() + ": " + element.eGet(attribute)); - // } - // - // LOG.info("- LayoutContraint: " + n.getLayoutConstraint() + ""); - // } - // - // EObject semanticConainer = dia.getElement(); - // LOG.info("SemanticConatiner" + semanticConainer + ""); - // - // for (EObject k : semanticConainer.eContents()) - // { - // LOG.info("Semantic Container Element: " + k + " (" + ResourceHelper.getXmiId(k) + ")" + ""); - // } - // } - // catch (Exception e) - // { - // e.printStackTrace(); - // } - // - // } - // LOG.info("-----------------------------------------------------"); - // return s.toString(); - // } - - public static Resource loadFromFile(String file, ResourceSet rsSet) - { - URI uri = URI.createURI("file:/" + file); - - Resource res = rsSet.getResource(uri, true); - return res; - } - - public static void writeToFile(String path, String xml) throws IOException - { - File file = new File(path); - FileWriter writer = new FileWriter(file); - writer.write(xml); - writer.close(); - } - - public static String saveToXML(XMLResource resource) throws IOException - { - - resource.setXMLVersion("1.0"); - - Map<Object, Object> saveOptions = new HashMap<Object, Object>(); - // options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); - // options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); - // options.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); - saveOptions.putAll(resource.getDefaultSaveOptions()); - saveOptions.put(XMIResource.OPTION_DECLARE_XML, Boolean.TRUE); - saveOptions.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_DISCARD); - saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); - saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE); - saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE); - saveOptions.put(XMIResource.OPTION_SKIP_ESCAPE_URI, Boolean.FALSE); - saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8"); - - final XMLHelper xmlHelper = new XMIHelperImpl(resource); - - XMISaveImpl x = new XMISaveImpl(xmlHelper); - - StringWriter sw = new StringWriter(); - x.save(resource, sw, saveOptions); - return sw.toString(); - } - - public static Resource loadFromXML(String xml, ResourceSet rsSet) throws IOException - { - final Resource res; - - res = new XMIResourceImpl(); - final XMLHelper xmlHelper = new XMLHelperImpl(); - ByteArrayInputStream stringreader = new ByteArrayInputStream(xml.getBytes()); - XMILoadImpl xmiload = new XMILoadImpl(xmlHelper); - xmiload.load((XMLResource)res, stringreader, Collections.EMPTY_MAP); - - /* setdummy URI */ - if (res.getURI() == null) - { - res.setURI(URI.createURI("")); - } - return res; - } - - /** - * returns the diagram from the resource if no diagram can be found it returns null. - * - * @param res - * @return if it exists the diagram otherwise null - */ - public static Diagram getDiagramFromResource(Resource res) - { - for (Object o : res.getContents()) - { - if (o instanceof Diagram) - { - return (Diagram)o; - } - } - return null; - } - - /** - * compares two eObjects by there xmi-id whether the are equal or not - * - * @param oldNode - * @param newNode - * @return true if xmi-id equal, else otherwise - */ - public static boolean areSameObjects(EObject oldNode, EObject newNode) - { - String newXMI = getXmiId(newNode); - String oldXMI = getXmiId(oldNode); - - if (newXMI.equals(oldXMI)) - { - return true; - } - return false; - } - - /** - * returns the same Object in the other resource. The Object is identified by the xmi ID - * - * @param e - * @param resource - * @return an object in the given resource with the same xmi Id - */ - public static EObject getSameEObjectFromOtherResource(EObject e, XMLResource resource) - { - String xmiId = ResourceHelper.getXmiId(e); - // EObject ret = resource.getIDToEObjectMap().get(xmiId); - EObject ret = resource.getEObject(xmiId); - return ret; - } - - /** - * finds changed objects - * - * @param serverO - * @param clientO - * @return true if the obejcts are different - */ - public static boolean objectsHaveChanged(Object serverO, Object clientO) - { - if (serverO instanceof Node && clientO instanceof Node) - { - Node s = (Node)serverO; - Node c = (Node)clientO; - - if (objectsHaveChanged(s.getLayoutConstraint(), c.getLayoutConstraint())) - { - return true; - } - if (objectsHaveChanged(s.getElement(), c.getElement())) - { - return true; - } - - } - else if (serverO instanceof Edge && clientO instanceof Edge) // compare edges - { - Edge s = (Edge)serverO; - Edge c = (Edge)clientO; - RelativeBendpoints sr = (RelativeBendpoints)s.getBendpoints(); - RelativeBendpoints cr = (RelativeBendpoints)c.getBendpoints(); - if (sr.getPoints().size() != cr.getPoints().size()) - { - return true; - } - int i = 0; - for (Object o : sr.getPoints()) - { - RelativeBendpoint sb = (RelativeBendpoint)o; - RelativeBendpoint cb = (RelativeBendpoint)cr.getPoints().get(i); - if (objectsHaveChanged(sb, cb)) - { - return true; - } - i++; - } - } - else if (serverO instanceof RelativeBendpoint && clientO instanceof RelativeBendpoint) - { - RelativeBendpoint sb = (RelativeBendpoint)serverO; - RelativeBendpoint cb = (RelativeBendpoint)clientO; - if (sb.getSourceX() != cb.getSourceX()) - { - return true; - } - if (sb.getSourceY() != cb.getSourceY()) - { - return true; - } - if (sb.getTargetX() != cb.getTargetX()) - { - return true; - } - if (sb.getTargetY() != cb.getTargetY()) - { - return true; - } - } - else if (serverO instanceof Bounds && clientO instanceof Bounds) - { - if (((Bounds)serverO).getX() != ((Bounds)clientO).getX()) - { - return true; - } - if (((Bounds)serverO).getY() != ((Bounds)clientO).getY()) - { - return true; - } - if (((Bounds)serverO).getWidth() != ((Bounds)clientO).getWidth()) - { - return true; - } - if (((Bounds)serverO).getHeight() != ((Bounds)clientO).getHeight()) - { - return true; - } - } - else if (serverO instanceof EObject && clientO instanceof EObject) - { - EObject s = (EObject)serverO; - EObject c = (EObject)clientO; - - for (EAttribute attribute : s.eClass().getEAllAttributes()) - { - Object co = c.eGet(attribute); - Object so = s.eGet(attribute); - if (co == null || so == null) - { - return false; - } - if (!co.equals(so)) - { - return true; - } - } - - // checking size of chidlren - if (s.eContents().size() != c.eContents().size()) - { - return true; - } - int i = 0; - // chekcing every child - for (EObject sChild : s.eContents()) - { - EObject cChild = c.eContents().get(i); - if (objectsHaveChanged(sChild, cChild)) - { - return true; - } - i++; - } - } - else - { - if (TRACER.isEnabled()) - { - TRACER.format("classes are not identical...no match {0} / {1}", serverO, clientO); //$NON-NLS-1$ - } - } - return false; - } - - public static Resource loadResourceFromFileString(String filePath, ResourceSet rsSet) throws IOException - { - try - { - File file = new File(filePath); - FileReader reader = new FileReader(file); - BufferedReader Ein = new BufferedReader(reader); - String s; - StringBuffer buff = new StringBuffer(); - while ((s = Ein.readLine()) != null) // Null-Referenz - { - buff.append(s + System.getProperty("line.separator")); - } - Ein.close(); - Resource resource = ResourceHelper.loadFromXML(buff.toString(), rsSet); - return resource; - } - catch (FileNotFoundException e) - { - e.printStackTrace(); - } - return null; - } - - public static String readFromFile(String filePath) throws IOException - { - try - { - File file = new File(filePath); - FileReader reader = new FileReader(file); - BufferedReader Ein = new BufferedReader(reader); - String s; - StringBuffer buff = new StringBuffer(); - while ((s = Ein.readLine()) != null) // Null-Referenz - { - buff.append(s + System.getProperty("line.separator")); - } - Ein.close(); - return buff.toString(); - - } - catch (FileNotFoundException e) - { - e.printStackTrace(); - } - return null; - } - - /** - * copies the XMI-id from oldElement to new Element - * - * @param newElement - * @param oldElement - */ - public static void copyXmiId(EObject oldElement, EObject newElement) - { - ResourceHelper.setXmiId(newElement, ResourceHelper.getXmiId(oldElement)); - } - - /** - * sets the objects id in the old resource to the new resource - * - * @param v - * @param oldResource - */ - public static void setXmiId(EObject v, XMLResource oldResource) - { - ResourceHelper.setXmiId(v, getXmiId(v, oldResource)); - } - - /** - * creates a deep Copy and also copies xmi ids This method can be used if the copy should be insertet into newParent - * - * @param oldObject - * @param newParent - * @return the copy of the oldObject - */ - @SuppressWarnings("unchecked") - public static EObject createCopyAndInsert(EObject oldObject, EObject newParent) - { - EObject ret = EcoreUtil.copy(oldObject); - - EStructuralFeature containingFeature = oldObject.eContainingFeature(); - - Object get = newParent.eGet(containingFeature); - if (get instanceof Collection<?>) - { - Collection<EObject> list = (Collection<EObject>)get; - list.add(ret); - } - else - { - newParent.eSet(containingFeature, ret); - } - - setXmiIdForChildren(oldObject, ret); - - return ret; - } - - public static EObject createCopy(EObject v) - { - EObject ret = EcoreUtil.copy(v); - return ret; - } - - private static int setXmiIdForChildren(EObject oldChild, EObject newChild) - { - ResourceHelper.setXmiId(newChild, ResourceHelper.getXmiId(oldChild)); - int i = 0; - for (EObject oldC : oldChild.eContents()) - { - EObject newC = newChild.eContents().get(i); - setXmiIdForChildren(oldC, newC); - i++; - } - return i; - } - - /** - * This method provides deep copying of all childrens xmi ids from oldObject to newObject - * - * @param oldObject - * @param newObject - */ - public static void copyXmiIds(EObject oldObject, EObject newObject) - { - setXmiIdForChildren(oldObject, newObject); - } - - /** - * this Method copies the values from one Element to the other curretnly only for attributes and not for references - */ - @Deprecated - public static void updateElement(EObject oldElement, EObject newElement) - { - if (oldElement == null) - { - newElement = oldElement; - return; - } - - for (EAttribute attribute : oldElement.eClass().getEAllAttributes()) - { - newElement.eSet(attribute, oldElement.eGet(attribute)); - } - } - - /** - * @param leftObject - * @param rightObject - * @throws EClassIncompatibleException - */ - // TODO delte removed references - public static void updateEObject(EObject leftObject, EObject rightObject) throws EClassIncompatibleException - { - if (rightObject == null) // remove left Object - { - removeEObjectFromParent(leftObject); - return; - } - - if (!leftObject.eClass().equals(rightObject.eClass())) - { - throw new EClassIncompatibleException(leftObject.eClass().getName() + "(" + ResourceHelper.getXmiId(leftObject) - + ")" + "/" + rightObject.eClass().getName() + "(" + ResourceHelper.getXmiId(leftObject) + ")"); - } - - updateEAttributes(leftObject, rightObject); - updateEReferences(leftObject, rightObject); - - for (Object o : rightObject.eContents()) - { - EObject rightChild = (EObject)o; - EObject leftChild = getSameEObjectFromOtherResource(rightChild, (XMLResource)leftObject.eResource()); - if (leftChild != null)// child exists - { - updateEObject(leftChild, rightChild); // removes it - } - else - // child must be created - { - if (o instanceof View) - { - View childView = (View)o; - EObject childViewElement = childView.getElement(); - View childViewCopy = (View)createCopyAndInsert(rightChild, leftObject); - if (childViewElement != null) - { - EObject childElementCopy = getSameEObjectFromOtherResource(childViewElement, - (XMLResource)leftObject.eResource()); - - updateEObject(childElementCopy, childViewElement);// not shure whether this is needed here - childViewCopy.setElement(childElementCopy); - } - - updateEObject(childViewCopy, childView);// not shure whether this is needed here - } - else - { - EObject childCopy = createCopyAndInsert(rightChild, leftObject); - updateEObject(childCopy, rightChild); // not shure whether this is needed here - } - } - } - - ArrayList<EObject> tempDeletionList = new ArrayList<EObject>(); - - for (Object leftChild : leftObject.eContents()) - { - tempDeletionList.add((EObject)leftChild); - } - - // here delete all which are not in the right object - for (EObject leftChild : tempDeletionList) - { - EObject rightChild = getSameEObjectFromOtherResource(leftChild, (XMLResource)rightObject.eResource()); - updateEObject(leftChild, rightChild); - } - } - - private static void removeEObjectFromParent(EObject leftObject) - { - if (leftObject instanceof View) - { - View view = (View)leftObject; - if (view.getElement() != null) - { - removeEObjectFromParent(view.getElement()); - } - } - - EObject parent = leftObject.eContainer(); - EStructuralFeature containingFeature = leftObject.eContainingFeature(); - if (parent != null) - { - Object container = parent.eGet(containingFeature); - - if (container instanceof Collection<?>) - { - Collection<?> collection = (Collection<?>)container; - collection.remove(leftObject); - } - else - { - parent.eSet(containingFeature, null); - } - } - else - { - if (TRACER.isEnabled()) - { - TRACER.format("arent is null, object ist still removed from parent : {0} ", leftObject); //$NON-NLS-1$ - } - } - } - - private static void updateEReferences(EObject leftObject, EObject rightObject) throws EClassIncompatibleException - { - for (EReference reference : rightObject.eClass().getEReferences()) - { - updateReference(leftObject, rightObject, reference); - } - } - - @SuppressWarnings("unchecked") - public static void updateReference(EObject leftParent, EObject rightParent, EReference reference) - throws EClassIncompatibleException - { - - if (reference.getName().equals("element")) - { - return; - } - Object leftReferenceObject = leftParent.eGet(reference); - Object rightReferenceObject = rightParent.eGet(reference); - - if (leftReferenceObject != null) - { - - if (leftReferenceObject instanceof Collection<?>) - { - Collection<EObject> leftCollection = (Collection<EObject>)leftReferenceObject; - Collection<?> rightCollection = (Collection<?>)rightReferenceObject; - for (Object o : rightCollection) - { - EObject rightCollectionChild = (EObject)o; - EObject leftCollectionChild = getSameEObjectFromOtherResource(rightCollectionChild, - (XMLResource)leftParent.eResource()); - - if (leftCollectionChild == null)// create - { - leftCollectionChild = ResourceHelper.createCopy(rightCollectionChild); - leftCollection.add(leftCollectionChild); - } - else - { - if (!rightCollectionChild.eResource().equals(leftParent.eResource())) // reference to another resource - { - leftCollection.remove(rightCollectionChild); - leftCollection.add(leftCollectionChild); - } - - updateEObject(leftCollectionChild, rightCollectionChild); - } - } - } - else - { - updateEObject((EObject)leftParent.eGet(reference), (EObject)rightParent.eGet(reference)); - } - } - else - // create - { - if (rightReferenceObject != null) - { - leftParent.eSet(reference, EcoreUtil.copy((EObject)rightReferenceObject)); - } - } - } - - private static void updateEAttributes(EObject leftObject, EObject rightObject) - { - for (EAttribute attribute : rightObject.eClass().getEAllAttributes()) - { - leftObject.eSet(attribute, rightObject.eGet(attribute)); - } - } - - public static void deleteViewInResource(XMLResource projectResource, EObject e) - { - Diagram diagram = ResourceHelper.getDiagramFromResource(projectResource); - EObject element = ((View)e).getElement(); - - if (element != null) - { - removeElementFromContainer(element); - } - - if (e instanceof Node) - { - diagram.removeChild((View)e);// ..getChildren().add(v); - } - else if (e instanceof Edge) - { - diagram.removeEdge((Edge)e);// ..getChildren().add(v); - } - } - - private static void removeElementFromContainer(EObject element) - { - EStructuralFeature containingFeature = element.eContainingFeature(); - EObject container = element.eContainer(); - Object get = container.eGet(containingFeature); - if (get instanceof Collection<?>) - { - Collection<?> list = (Collection<?>)get; - list.remove(element); - } - else - { - container.eSet(containingFeature, null); - } - } - - @SuppressWarnings("unchecked") - public static void addElementToContainer(EObject element, EObject container, EStructuralFeature containingFeature) - { - // EStructuralFeature containingFeature = element.eContainingFeature(); - Object get = container.eGet(containingFeature); - if (get instanceof Collection<?>) - { - Collection<EObject> list = (Collection<EObject>)get; - list.add(element); - } - else - { - container.eSet(containingFeature, element); - } - } - - /** - * checks if an element with element's id exists in the give resource - * - * @param res - * @param element - * @return true is the object with the same xmi id as element is contained in the given resource - */ - public static boolean isObjectInResource(Resource res, EObject element) - { - EObject object = res.getEObject(ResourceHelper.getXmiId(element)); - if (object == null) - { - return false; - } - - return true; - } - - public static void printResource(Resource r) - { - for (EObject o : r.getContents()) - { - printEObjectFull(o, 0); - } - } - - public static void printResourceSysout(Resource r) - { - for (EObject o : r.getContents()) - { - printEObjectFullSysout(o, 0); - } - } - - public static void printEObject(EObject o, int level) - { - for (Object child : o.eContents()) - { - printEObject((EObject)child, level + 1); - } - } - - public static void printEObjectFull(EObject o, int level) - { - System.out.println(tabs(level) + "--------------------------------------------"); - System.out.println(tabs(level) + "Object: " + o); - System.out.println(tabs(level) + "o.eContainer: " + o.eContainer()); - System.out.println(tabs(level) + "o.eContainingFeature: " + o.eContainingFeature()); - System.out.println(tabs(level) + "o.eContainmentFeature: " + o.eContainmentFeature()); - System.out.println(tabs(level) + "o.eIsProxy: " + o.eIsProxy()); - System.out.println(tabs(level) + "o.eResource: " + o.eResource()); - System.out.println(tabs(level) + "o.getClass: " + o.getClass()); - System.out.println(tabs(level) + "o.eClass: " + o.eClass()); - System.out.println(tabs(level) + "o.eCrossReferences: " + o.eCrossReferences()); - - System.out.println(tabs(level) + "o.eClass.getClassifierID: " + o.eClass().getClassifierID()); - System.out.println(tabs(level) + "o.eClass.getFeatureCount: " + o.eClass().getFeatureCount()); - System.out.println(tabs(level) + "o.eClass.getInstanceClassName: " + o.eClass().getInstanceClassName()); - System.out.println(tabs(level) + "o.eClass.getInstanceTypeName: " + o.eClass().getInstanceTypeName()); - System.out.println(tabs(level) + "o.eClass.getName: " + o.eClass().getName()); - System.out.println(tabs(level) + "o.eClass.getDefaultValue: " + o.eClass().getDefaultValue()); - System.out.println(tabs(level) + "o.eClass.getEPackage: " + o.eClass().getEPackage()); - System.out.println(tabs(level) + "o.eClass.getEIDAttribute: " + o.eClass().getEIDAttribute()); - System.out.println(tabs(level) + "o.eClass.getInstanceClass: " + o.eClass().getInstanceClass()); - - for (EAttribute attribute : o.eClass().getEAllAttributes()) - { - System.out.println(tabs(level + 1) + "o.eClass.getEAllAttributes.attribute: '" + attribute.getName() + "': " - + o.eGet(attribute)); - } - for (EAnnotation annotation : o.eClass().getEAnnotations()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAnnotations().annotation: '" + annotation); - } - for (EReference containment : o.eClass().getEAllContainments()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllContainments().containment: '" + containment); - } - for (EGenericType genericSupertype : o.eClass().getEAllGenericSuperTypes()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllGenericSuperTypes().genericSupertype: '" - + genericSupertype); - } - for (EOperation operation : o.eClass().getEAllOperations()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllOperations().operation: '" + operation); - } - - for (EReference reference : o.eClass().getEAllReferences()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllReferences().reference: '" + reference); - } - for (EClass supertype : o.eClass().getEAllSuperTypes()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllSuperTypes().supertype: '" + supertype); - } - for (EStructuralFeature structuralFeature : o.eClass().getEAllStructuralFeatures()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllStructuralFeatures().structuralFeature: '" - + structuralFeature); - } - for (EAnnotation annotation : o.eClass().getEAnnotations()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAnnotations().annotation: '" + annotation); - } - for (EAttribute attribute : o.eClass().getEAttributes()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAttributes().annotation: '" + attribute); - } - for (Adapter adapter : o.eClass().eAdapters()) - { - System.out.println(tabs(level + 1) + "o.eClass().eAdapters().adapter: '" + adapter); - } - - for (Object child : o.eContents()) - { - printEObjectFull((EObject)child, level + 2); - } - } - - public static void printEObjectFullSysout(EObject o, int level) - { - System.out.println(tabs(level) + "--------------------------------------------"); - System.out.println(tabs(level) + "Object: " + o); - System.out.println(tabs(level) + "o.eContainer: " + o.eContainer()); - System.out.println(tabs(level) + "o.eContainingFeature: " + o.eContainingFeature()); - System.out.println(tabs(level) + "o.eContainmentFeature: " + o.eContainmentFeature()); - System.out.println(tabs(level) + "o.eIsProxy: " + o.eIsProxy()); - System.out.println(tabs(level) + "o.eResource: " + o.eResource()); - System.out.println(tabs(level) + "o.getClass: " + o.getClass()); - System.out.println(tabs(level) + "o.eClass: " + o.eClass()); - System.out.println(tabs(level) + "o.eCrossReferences: " + o.eCrossReferences()); - - System.out.println(tabs(level) + "o.eClass.getClassifierID: " + o.eClass().getClassifierID()); - System.out.println(tabs(level) + "o.eClass.getFeatureCount: " + o.eClass().getFeatureCount()); - System.out.println(tabs(level) + "o.eClass.getInstanceClassName: " + o.eClass().getInstanceClassName()); - System.out.println(tabs(level) + "o.eClass.getInstanceTypeName: " + o.eClass().getInstanceTypeName()); - System.out.println(tabs(level) + "o.eClass.getName: " + o.eClass().getName()); - System.out.println(tabs(level) + "o.eClass.getDefaultValue: " + o.eClass().getDefaultValue()); - System.out.println(tabs(level) + "o.eClass.getEPackage: " + o.eClass().getEPackage()); - System.out.println(tabs(level) + "o.eClass.getEIDAttribute: " + o.eClass().getEIDAttribute()); - System.out.println(tabs(level) + "o.eClass.getInstanceClass: " + o.eClass().getInstanceClass()); - - for (EAttribute attribute : o.eClass().getEAllAttributes()) - { - System.out.println(tabs(level + 1) + "o.eClass.getEAllAttributes.attribute: '" + attribute.getName() + "': " - + o.eGet(attribute)); - } - for (EAnnotation annotation : o.eClass().getEAnnotations()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAnnotations().annotation: '" + annotation); - } - for (EReference containment : o.eClass().getEAllContainments()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllContainments().containment: '" + containment); - } - for (EGenericType genericSupertype : o.eClass().getEAllGenericSuperTypes()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllGenericSuperTypes().genericSupertype: '" - + genericSupertype); - } - for (EOperation operation : o.eClass().getEAllOperations()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllOperations().operation: '" + operation); - } - - for (EReference reference : o.eClass().getEAllReferences()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllReferences().reference: '" + reference); - } - for (EClass supertype : o.eClass().getEAllSuperTypes()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllSuperTypes().supertype: '" + supertype); - } - for (EStructuralFeature structuralFeature : o.eClass().getEAllStructuralFeatures()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAllStructuralFeatures().structuralFeature: '" - + structuralFeature); - } - for (EAnnotation annotation : o.eClass().getEAnnotations()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAnnotations().annotation: '" + annotation); - } - for (EAttribute attribute : o.eClass().getEAttributes()) - { - System.out.println(tabs(level + 1) + "o.eClass().getEAttributes().annotation: '" + attribute); - } - for (Adapter adapter : o.eClass().eAdapters()) - { - System.out.println(tabs(level + 1) + "o.eClass().eAdapters().adapter: '" + adapter); - } - - for (Object child : o.eContents()) - { - printEObjectFullSysout((EObject)child, level + 2); - } - } - - private static String tabs(int level) - { - String s = ""; - for (int i = 0; i < level; i++) - { - s += "\t"; - } - return s; - } - - public static String getLocationFromResource(Resource r) throws MalformedURLException, IOException - { - return FileLocator.resolve(new URL(r.getURI().toString())).toString().replace("file:", ""); - } - - /**************************************************************************************************** - * finds EditPart from a View - * - * @param view - * @param dawnDiagramEditor - * @return find an Editpart for a view with the same xmi id - ***************************************************************************************************/ - @Deprecated - public static EditPart findEditPartByXMIId(View view, DiagramDocumentEditor dawnDiagramEditor) - { - DiagramEditPart diagramEditPart = dawnDiagramEditor.getDiagramEditPart(); - - for (Object e : diagramEditPart.getChildren()) - { - EditPart ep = (EditPart)e; - if (ResourceHelper.getXmiId((EObject)ep.getModel()).equals(ResourceHelper.getXmiId(view))) - { - return ep; - } - } - - for (Object e : diagramEditPart.getConnections()) - { - EditPart ep = (EditPart)e; - if (ResourceHelper.getXmiId((EObject)ep.getModel()).equals(ResourceHelper.getXmiId(view))) - { - return ep; - } - } - return null; - } -} diff --git a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/transaction/DawnTransactionChangeRecorder.java b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/transaction/DawnTransactionChangeRecorder.java index eaa5e870e7..8437ab282e 100644 --- a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/transaction/DawnTransactionChangeRecorder.java +++ b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/transaction/DawnTransactionChangeRecorder.java @@ -1,5 +1,7 @@ package org.eclipse.emf.cdo.dawn.transaction; +import org.eclipse.emf.cdo.CDODeltaNotification; + import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain; @@ -21,7 +23,10 @@ public class DawnTransactionChangeRecorder extends TransactionChangeRecorder if (!(notification.getOldValue() instanceof ResourceSet && notification.getNewValue() == null && notification .getEventType() == Notification.SET)) { - super.notifyChanged(notification); + if (!(notification instanceof CDODeltaNotification)) + { + super.notifyChanged(notification); + } } } } |