diff options
author | Martin Fluegge | 2011-10-26 15:56:08 +0000 |
---|---|---|
committer | Martin Fluegge | 2011-10-26 15:56:08 +0000 |
commit | 4d3bffde32f80b74aa7352025b658b3f32f9c350 (patch) | |
tree | b2c600faebf268121447924f4cd3507311b41b7a | |
parent | e7f88afda636abe81ddb00f5b26b124a1931c84d (diff) | |
download | cdo-4d3bffde32f80b74aa7352025b658b3f32f9c350.tar.gz cdo-4d3bffde32f80b74aa7352025b658b3f32f9c350.tar.xz cdo-4d3bffde32f80b74aa7352025b658b3f32f9c350.zip |
[359656] [Dawn] Provide collaborative extension for Graphiti editors
https://bugs.eclipse.org/bugs/show_bug.cgi?id=359656
7 files changed, 1033 insertions, 931 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnAppearancer.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnAppearancer.java index 125c6abb2a..dc9c0c6c38 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnAppearancer.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnAppearancer.java @@ -1,90 +1,97 @@ -/* - * Copyright (c) 2004 - 2011 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.gmf.appearance; - -import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer; -import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry; - -import org.eclipse.gef.EditPart; -import org.eclipse.gef.GraphicalEditPart; -import org.eclipse.gef.util.EditPartUtilities; - -/** - * @author Martin Fluegge - * @since 2.0 - */ -public class DawnAppearancer -{ - public static final int DEFAULT_BORDER_THICKNESS = 2; - - public static final int DEFAULT_LINE_THICKNESS = 3; - - public static final int TYPE_CONFLICT_NONE = -1; - - public static final int TYPE_CONFLICT_LOCALLY_DELETED = 0; - - public static final int TYPE_CONFLICT_REMOTELY_DELETED = 1; - - public static final int TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED = 2; - - public static final int TYPE_LOCKED_LOCALLY = 3; - - public static final int TYPE_LOCKED_GLOBALLY = 4; - - /** - * @since 2.0 - */ - public static void setEditPartConflicted(EditPart editPart, int type) - { - DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); - if (stylizer != null) - { - stylizer.setConflicted(editPart, type); - } - } - - /** - * @since 2.0 - */ - public static void setEditPartDefaultAllChildren(EditPart editPart) - { - setEditPartDefault(editPart); - - for (Object child : EditPartUtilities.getAllChildren((GraphicalEditPart)editPart)) - { - setEditPartDefaultAllChildren((EditPart)child); - } - } - - /** - * @since 2.0 - */ - public static void setEditPartDefault(EditPart editPart) - { - DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); - if (stylizer != null) - { - stylizer.setDefault(editPart); - } - } - - /** - * @since 2.0 - */ - public static void setEditPartLocked(EditPart editPart, int type) - { - DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); - if (stylizer != null) - { - stylizer.setLocked(editPart, type); - } - } -} +/*
+ * Copyright (c) 2004 - 2011 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.gmf.appearance;
+
+import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer;
+import org.eclipse.emf.cdo.dawn.helper.DawnEditorHelper;
+import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.util.EditPartUtilities;
+
+/**
+ * @author Martin Fluegge
+ * @since 2.0
+ */
+public class DawnAppearancer
+{
+ public static final int DEFAULT_BORDER_THICKNESS = 2;
+
+ public static final int DEFAULT_LINE_THICKNESS = 3;
+
+ public static final int TYPE_CONFLICT_NONE = -1;
+
+ public static final int TYPE_CONFLICT_LOCALLY_DELETED = 0;
+
+ public static final int TYPE_CONFLICT_REMOTELY_DELETED = 1;
+
+ public static final int TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED = 2;
+
+ public static final int TYPE_LOCKED_LOCALLY = 3;
+
+ public static final int TYPE_LOCKED_GLOBALLY = 4;
+
+ /**
+ * @since 2.0
+ */
+ public static void setEditPartConflicted(EditPart editPart, int type)
+ {
+ DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart);
+ if (stylizer != null)
+ {
+ stylizer.setConflicted(editPart, type);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static void setEditPartDefaultAllChildren(EditPart editPart)
+ {
+ setEditPartDefault(editPart);
+
+ for (Object child : EditPartUtilities.getAllChildren((GraphicalEditPart)editPart))
+ {
+ setEditPartDefaultAllChildren((EditPart)child);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static void setEditPartDefault(EditPart editPart)
+ {
+ DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart);
+ if (stylizer != null)
+ {
+ stylizer.setDefault(editPart);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static void setEditPartLocked(final EditPart editPart, final int type)
+ {
+ final DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart);
+ if (stylizer != null)
+ {
+ DawnEditorHelper.getDisplay().syncExec(new Runnable()
+ {
+ public void run()
+ {
+ stylizer.setLocked(editPart, type);
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnChangeHelper.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnChangeHelper.java index c3ae752703..07266e9335 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnChangeHelper.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnChangeHelper.java @@ -1,629 +1,632 @@ -/* - * Copyright (c) 2004 - 2011 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.gmf.synchronize; - -import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; -import org.eclipse.emf.cdo.dawn.gmf.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; - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.Transaction; -import org.eclipse.emf.transaction.TransactionalEditingDomain; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.draw2d.Border; -import org.eclipse.draw2d.LineBorder; -import org.eclipse.draw2d.PositionConstants; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.gef.EditPart; -import org.eclipse.gef.EditPartViewer; -import org.eclipse.gef.GraphicalEditPart; -import org.eclipse.gef.Request; -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.requests.ChangeBoundsRequest; -import org.eclipse.gmf.runtime.common.core.command.ICommand; -import org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCommand; -import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; -import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; -import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredCreateConnectionViewAndElementCommand; -import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; -import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest; -import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest.ConnectionViewAndElementDescriptor; -import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; -import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor; -import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; -import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory; -import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.core.util.PackageUtil; -import org.eclipse.gmf.runtime.emf.type.core.IElementType; -import org.eclipse.gmf.runtime.emf.type.core.IHintedType; -import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; -import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; -import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; -import org.eclipse.gmf.runtime.notation.Anchor; -import org.eclipse.gmf.runtime.notation.Bendpoints; -import org.eclipse.gmf.runtime.notation.Bounds; -import org.eclipse.gmf.runtime.notation.Edge; -import org.eclipse.gmf.runtime.notation.Node; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; - -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - -/** - * @author Martin Fluegge - */ -public class DawnChangeHelper -{ - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnChangeHelper.class); - - protected static final java.util.Map<String, Boolean> options = new HashMap<String, Boolean>(); - - protected static final java.util.Map<Object, Object> setElementOptions = new HashMap<Object, Object>(); - static - { - options.put(Transaction.OPTION_UNPROTECTED, Boolean.FALSE); - options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE); - options.put(Transaction.OPTION_NO_TRIGGERS, Boolean.TRUE); - } - - /** - * generic Method to create an EditPart by the given view - * - * @param node - * @param elementType - * @param diagramEP - * @return the EditPart for the newly created Node - */ - public static EditPart createNode(final Node node, IElementType elementType, DiagramEditPart diagramEP) - { - CreateViewRequest createViewRequest = CreateViewRequestFactory.getCreateShapeRequest(elementType, - diagramEP.getDiagramPreferencesHint()); - - Bounds bounds = (Bounds)node.getLayoutConstraint(); - - Point p = new Point(bounds.getX(), bounds.getY()); - Dimension dimension = new Dimension(bounds.getWidth(), bounds.getHeight()); - createViewRequest.setLocation(p); - createViewRequest.setSize(dimension); - - diagramEP.performRequest(createViewRequest); - - final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0); - final EditPartViewer viewer = diagramEP.getViewer(); - final EditPart kep = (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class)); - return kep; - } - - public static EditPart createAttribute(final Node node, IElementType elementType, IGraphicalEditPart parentEditpart) - { - - if (TRACER.isEnabled()) - { - TRACER.format("ElementType: {0} semanticHint {1}", elementType, ((IHintedType)elementType).getSemanticHint()); //$NON-NLS-1$ - } - - CreateElementRequest request = new CreateElementRequest(elementType); - CreateElementRequestAdapter createElementRequestAdapter = new CreateElementRequestAdapter(request); - - ViewAndElementDescriptor viewAndElementDescriptor = new ViewAndElementDescriptor(createElementRequestAdapter, - Node.class, ((IHintedType)elementType).getSemanticHint(), - - parentEditpart.getDiagramPreferencesHint()); - - CreateViewAndElementRequest createViewRequest = new CreateViewAndElementRequest(viewAndElementDescriptor); - - // Command command = parentEditpart.getCommand(createViewRequest); - - parentEditpart.performRequest(createViewRequest); - - final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0); - final EditPartViewer viewer = parentEditpart.getViewer(); - final EditPart kep = (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class)); - return kep; - } - - /*************************************** - * This method creates an EditPart given by the specified ElemetType and PLaces it to the give coordinates - * Element-Types could be: DawnElementTypes.Klasse_1001 - * - * @param p - * the point where the view shoudl be created - * @param elementType - * @param diagramEditor - * @return the created EditPart - ********************************************************************************************************************/ - public static EditPart createEditPart(Point p, IElementType elementType, DiagramDocumentEditor diagramEditor) - { - DiagramEditPart diagramEP = diagramEditor.getDiagramEditPart(); - - CreateViewRequest createViewRequest = CreateViewRequestFactory.getCreateShapeRequest(elementType, - diagramEP.getDiagramPreferencesHint()); - - createViewRequest.setLocation(p); - diagramEP.performRequest(createViewRequest); - - final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0); - final EditPartViewer viewer = diagramEP.getViewer(); - return (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class)); - } - - /*************************************** - * sets a property for an editpart - * - * @param editPart - * @param name - * @param object - * @param dawnDiagramEditor - ********************************************************************************************************************/ - public static void setProperty(EditPart editPart, String name, String packageUtilPropertyID, Object object, - DiagramDocumentEditor dawnDiagramEditor) - { - SetPropertyCommand setPropertyCommand = new SetPropertyCommand(dawnDiagramEditor.getEditingDomain(), editPart, - packageUtilPropertyID, name, object); - - DiagramEditPart diagramEP = dawnDiagramEditor.getDiagramEditPart(); - - diagramEP.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setPropertyCommand)); - - } - - /*************************************** - * resizes an Editpart to the given dimension - * - * @param editpart - * @param d - * dimension - ********************************************************************************************************************/ - public static void resizeEditPart(EditPart editpart, Dimension d) - { - boolean editModeEnabled = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart) - .isEditModeEnabled(); - if (!editModeEnabled) - { - ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).enableEditMode(); - } - - ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE); - move_req.setResizeDirection(PositionConstants.SOUTH_EAST); - - Bounds b = (Bounds)((Node)editpart.getModel()).getLayoutConstraint(); - Dimension dimensionDelta = new Dimension(d.width - b.getWidth(), d.height - b.getHeight()); - - move_req.setSizeDelta(dimensionDelta); - - Command cmd = editpart.getCommand(move_req); - if (cmd == null || !cmd.canExecute()) - { - throw new IllegalArgumentException("Command is not executable."); - } - ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd); - - if (editModeEnabled) - { - ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).enableEditMode(); - } - else - { - ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).disableEditMode(); - } - } - - /*************************************** - * moves an EdidPart to the given postione - * - * @param editpart - * @param p - ********************************************************************************************************************/ - public static void moveEditPart(EditPart editpart, Point p) - { - ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); - - Bounds b = (Bounds)((Node)editpart.getModel()).getLayoutConstraint(); - Point newPoint = new Point(p.x - b.getX(), p.y - b.getY()); - move_req.setMoveDelta(newPoint); - - Command cmd = editpart.getCommand(move_req); - if (cmd == null || !cmd.canExecute()) - { - throw new IllegalArgumentException("Command is not executable."); - } - ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd); - } - - /** - * Moves the Editpart from the current position to the new Vector - */ - public static void moveEditPartTo(EditPart editpart, Point p) - { - ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); - move_req.setMoveDelta(p); - Command cmd = editpart.getCommand(move_req); - if (cmd == null || !cmd.canExecute()) - { - throw new IllegalArgumentException("Command is not executable."); - } - ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd); - } - - /** - * deletes the EditPart an the concerning model element - * - * @param editPart - * @param editor - */ - public static void deleteEditPart(final EditPart editPart, DiagramDocumentEditor editor) - { - final View view = (View)editPart.getModel(); - - EObject eObject = view.getElement(); - if (eObject != null) - { - DestroyElementRequest destroy = new DestroyElementRequest(editor.getEditingDomain(), eObject, false); - - Request req = new EditCommandRequestWrapper(destroy); - - Command command = editPart.getCommand(req); - editor.getDiagramEditDomain().getDiagramCommandStack().execute(command); - } - TransactionalEditingDomain domain = editor.getEditingDomain(); - if (view instanceof Edge) // also update the lists of the other client - { - domain.getCommandStack().execute(new RecordingCommand(domain) - { - @Override - public void doExecute() - { - Edge e = (Edge)view; - View source = e.getSource(); - View target = e.getTarget(); - if (source != null && target != null) - { - EObject targetElement = target.getElement(); - EObject sourceElement = source.getElement(); - - EStructuralFeature containingFeature = sourceElement.eContainingFeature(); - Collection<?> sourceCrossreferenceCollection = (Collection<?>)sourceElement.eGet(containingFeature); - sourceCrossreferenceCollection.remove(targetElement); - } - } - }); - } - ViewUtil.destroy(view); - } - - /*************************************** - * Deletes a view and it's contained element - * - * @param view - * @param editor - ********************************************************************************************************************/ - public static void deleteView(final View view, DiagramDocumentEditor editor) - { - - if (TRACER.isEnabled()) - { - TRACER.format("Deleting view {0} ", view); //$NON-NLS-1$ - } - - EObject eObject = view.getElement(); - if (eObject != null) - { - DestroyElementRequest destroy = new DestroyElementRequest(editor.getEditingDomain(), eObject, false); - - Request req = new EditCommandRequestWrapper(destroy); - - EditPart findEditPart = DawnDiagramUpdater.findEditPart(view, editor.getDiagramEditPart().getViewer()); - Command command = findEditPart.getCommand(req); - editor.getDiagramEditDomain().getDiagramCommandStack().execute(command); - } - if (view instanceof Edge) // also update the lists of the other client - { - destroyEdge((Edge)view, editor); - } - ViewUtil.destroy(view); - } - - public static void destroyEdge(Edge edge, DiagramDocumentEditor editor) - { - EObject referenceObject = ViewUtil.resolveSemanticElement(edge.getTarget()); - EObject container = ViewUtil.resolveSemanticElement(edge.getSource()); - EditPart parentEditpart = DawnDiagramUpdater.findEditPart(edge, editor.getDiagramEditPart().getViewer()); - DestroyReferenceRequest destroyReferenceRequest = new DestroyReferenceRequest(editor.getEditingDomain(), container, - null, referenceObject, false); - Request req = new EditCommandRequestWrapper(destroyReferenceRequest); - - Command command = parentEditpart.getCommand(req); - editor.getDiagramEditDomain().getDiagramCommandStack().execute(command); - } - - /*************************************** - * creates an edge for a given elementType - * - * @param oldEdge - * @param sourceEditPart - * @param targetEditPart - * @param elementType - * @param root - * @return the newly created EditPart - ********************************************************************************************************************/ - public static EditPart createEdge(Edge oldEdge, EditPart sourceEditPart, EditPart targetEditPart, - IElementType elementType, final DiagramEditPart root) - { - if (TRACER.isEnabled()) - { - TRACER.format("Creaeting Edge from old edge {0} ", oldEdge); //$NON-NLS-1$ - } - - CreateConnectionViewAndElementRequest req = new CreateConnectionViewAndElementRequest(elementType, - ((IHintedType)elementType).getSemanticHint(), root.getDiagramPreferencesHint()); - - ICommand createConnectionCmd = new DeferredCreateConnectionViewAndElementCommand(req, new EObjectAdapter( - (EObject)sourceEditPart.getModel()), new EObjectAdapter((EObject)targetEditPart.getModel()), root.getViewer()); - - root.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(createConnectionCmd)); - - final EditPartViewer viewer = root.getViewer(); - - final EditPart ret = (EditPart)viewer.getEditPartRegistry().get( - ((ConnectionViewAndElementDescriptor)req.getNewObject()).getAdapter(View.class)); - - if (ret != null) - { - setAnchorsAndBendPoints(ret, oldEdge, root); - } - return ret; - } - - /*************************************** - * This Method sets the Anchors and Bendpoint from an old Edge to the edge of the given EditPart - * - * @param edgeEditpart - * @param oldEdge - * @param root - ********************************************************************************************************************/ - public static void setAnchorsAndBendPoints(final EditPart edgeEditpart, final Edge oldEdge, final DiagramEditPart root) - { - TransactionalEditingDomain domain = root.getEditingDomain();// getEditingDomain(); - domain.getCommandStack().execute(new RecordingCommand(domain) - { - @Override - public void doExecute() - { - Edge edge = (Edge)edgeEditpart.getModel(); - - edge.setBendpoints((Bendpoints)DawnResourceHelper.createCopy(oldEdge.getBendpoints())); - if (oldEdge.getSourceAnchor() != null) - { - edge.setSourceAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getSourceAnchor())); - } - if (oldEdge.getTargetAnchor() != null) - { - edge.setTargetAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getTargetAnchor())); - } - - edgeEditpart.refresh(); - root.refresh(); - } - }); - } - - /** - * returns the border color from a given EditPart - * - * @param editPart - * @return the border color of the EditPart - */ - public static Color getBorderColor(EditPart editPart) - { - GraphicalEditPart e = (GraphicalEditPart)editPart; - - Border border = e.getFigure().getBorder(); - - if (border instanceof org.eclipse.draw2d.MarginBorder) - { - // MarginBorder b = ((MarginBorder) e.getFigure().getBorder()); - // if (border != null) - // { - // return b.getColor(); - // } - return null; - } - else if (border instanceof LineBorder) - { - LineBorder b = (LineBorder)e.getFigure().getBorder(); - - return b.getColor(); - } - - return null; - } - - /** - * activates a given EditPart - * - * @param e - */ - public static void activateEditPart(final EditPart e) - { - Display.getDefault().asyncExec(new Runnable() - { - public void run() - { - e.activate(); - org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart g = (org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)e; - g.getFigure().setEnabled(true); - } - }); - - } - - /** - * activates the diagram EditPart - * - * @param diagramEditPart - */ - public static void activateDiagramEditPart(DiagramEditPart diagramEditPart) - { - DawnChangeHelper.activateEditPart(diagramEditPart); - - for (Object e : diagramEditPart.getChildren()) - { - DawnChangeHelper.activateEditPart((EditPart)e); - } - } - - /** - * deactivates the given EditPart - * - * @param e - */ - public static void deactivateEditPart(final EditPart e) - { - Display.getDefault().asyncExec(new Runnable() - { - public void run() - { - e.deactivate(); - e.getViewer().deselect(e); - - org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart g = (org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)e; - g.getFigure().setEnabled(false); - } - }); - } - - /** - * deactivates the DiagramEditPart - * - * @param diagramEditPart - */ - public static void deactivateDiagramEditPart(DiagramEditPart diagramEditPart) - { - DawnChangeHelper.deactivateEditPart(diagramEditPart); - - for (Object e : diagramEditPart.getChildren()) - { - DawnChangeHelper.deactivateEditPart((EditPart)e); - } - - } - - /** - * Deselects the given EditPart EditPart - */ - public static void deselect(final EditPart e) - { - Display.getDefault().asyncExec(new Runnable() - { - - public void run() - { - e.getViewer().deselect(e); - } - }); - } - - /** - * selects the given EditPart - * - * @param e - */ - public static void select(final EditPart e) - { - Display.getDefault().asyncExec(new Runnable() - { - - public void run() - { - e.getViewer().select(e); - } - }); - } - - /*************************************** - * sets a property for an editpart - * - * @param editPart - * @param name - * @param object - * @param dawnDiagramEditor - ********************************************************************************************************************/ - public static void setProperty(EditPart editPart, String name, EAttribute attribute, Object object, - DiagramDocumentEditor dawnDiagramEditor) - { - SetPropertyCommand setPropertyCommand = new SetPropertyCommand(dawnDiagramEditor.getEditingDomain(), editPart, - PackageUtil.getID(attribute), name, object); - DiagramEditPart diagramEP = dawnDiagramEditor.getDiagramEditPart(); - - diagramEP.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setPropertyCommand)); - } - - /*************************************** - * updates the model - * - * @param editPart - * @param model - * @param editor - ********************************************************************************************************************/ - public static void updateModel(final EditPart editPart, final EObject model, DiagramDocumentEditor editor) - { - editPart.getViewer().getEditDomain(); - View view = (View)editPart.getModel(); - final EObject element = view.getElement(); - - if (element.eClass().getName().equals("AnOperation")) // ugliest of all workarounds. Just for the prototype - { - editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain()) - { - @Override - public void doExecute() - { - try - { - DawnResourceHelper.updateEObject(element, model); - } - catch (EClassIncompatibleException e) - { - e.printStackTrace(); - } - } - }); - } - else - { - for (EAttribute attribute : element.eClass().getEAllAttributes()) - { - setProperty(editPart, attribute.getName(), attribute, model.eGet(attribute), editor); - } - } - } - - public static void deleteAttribute(View view, DiagramDocumentEditor editor) - { - deleteView(view, editor); - } -} +/*
+ * Copyright (c) 2004 - 2011 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.gmf.synchronize;
+
+import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
+import org.eclipse.emf.cdo.dawn.gmf.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;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.Border;
+import org.eclipse.draw2d.LineBorder;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCommand;
+import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredCreateConnectionViewAndElementCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest.ConnectionViewAndElementDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
+import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
+import org.eclipse.gmf.runtime.notation.Anchor;
+import org.eclipse.gmf.runtime.notation.Bendpoints;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author Martin Fluegge
+ */
+public class DawnChangeHelper
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnChangeHelper.class);
+
+ protected static final java.util.Map<String, Boolean> options = new HashMap<String, Boolean>();
+
+ protected static final java.util.Map<Object, Object> setElementOptions = new HashMap<Object, Object>();
+ static
+ {
+ options.put(Transaction.OPTION_UNPROTECTED, Boolean.FALSE);
+ options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE);
+ options.put(Transaction.OPTION_NO_TRIGGERS, Boolean.TRUE);
+ }
+
+ /**
+ * generic Method to create an EditPart by the given view
+ *
+ * @param node
+ * @param elementType
+ * @param diagramEP
+ * @return the EditPart for the newly created Node
+ */
+ public static EditPart createNode(final Node node, IElementType elementType, DiagramEditPart diagramEP)
+ {
+ CreateViewRequest createViewRequest = CreateViewRequestFactory.getCreateShapeRequest(elementType,
+ diagramEP.getDiagramPreferencesHint());
+
+ Bounds bounds = (Bounds)node.getLayoutConstraint();
+
+ Point p = new Point(bounds.getX(), bounds.getY());
+ Dimension dimension = new Dimension(bounds.getWidth(), bounds.getHeight());
+ createViewRequest.setLocation(p);
+ createViewRequest.setSize(dimension);
+
+ diagramEP.performRequest(createViewRequest);
+
+ final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0);
+ final EditPartViewer viewer = diagramEP.getViewer();
+ final EditPart kep = (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class));
+ return kep;
+ }
+
+ public static EditPart createAttribute(final Node node, IElementType elementType, IGraphicalEditPart parentEditpart)
+ {
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("ElementType: {0} semanticHint {1}", elementType, ((IHintedType)elementType).getSemanticHint()); //$NON-NLS-1$
+ }
+
+ CreateElementRequest request = new CreateElementRequest(elementType);
+ CreateElementRequestAdapter createElementRequestAdapter = new CreateElementRequestAdapter(request);
+
+ ViewAndElementDescriptor viewAndElementDescriptor = new ViewAndElementDescriptor(createElementRequestAdapter,
+ Node.class, ((IHintedType)elementType).getSemanticHint(),
+
+ parentEditpart.getDiagramPreferencesHint());
+
+ CreateViewAndElementRequest createViewRequest = new CreateViewAndElementRequest(viewAndElementDescriptor);
+
+ // Command command = parentEditpart.getCommand(createViewRequest);
+
+ parentEditpart.performRequest(createViewRequest);
+
+ final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0);
+ final EditPartViewer viewer = parentEditpart.getViewer();
+ final EditPart kep = (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class));
+ return kep;
+ }
+
+ /***************************************
+ * This method creates an EditPart given by the specified ElemetType and PLaces it to the give coordinates
+ * Element-Types could be: DawnElementTypes.Klasse_1001
+ *
+ * @param p
+ * the point where the view shoudl be created
+ * @param elementType
+ * @param diagramEditor
+ * @return the created EditPart
+ ********************************************************************************************************************/
+ public static EditPart createEditPart(Point p, IElementType elementType, DiagramDocumentEditor diagramEditor)
+ {
+ DiagramEditPart diagramEP = diagramEditor.getDiagramEditPart();
+
+ CreateViewRequest createViewRequest = CreateViewRequestFactory.getCreateShapeRequest(elementType,
+ diagramEP.getDiagramPreferencesHint());
+
+ createViewRequest.setLocation(p);
+ diagramEP.performRequest(createViewRequest);
+
+ final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0);
+ final EditPartViewer viewer = diagramEP.getViewer();
+ return (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class));
+ }
+
+ /***************************************
+ * sets a property for an editpart
+ *
+ * @param editPart
+ * @param name
+ * @param object
+ * @param dawnDiagramEditor
+ ********************************************************************************************************************/
+ public static void setProperty(EditPart editPart, String name, String packageUtilPropertyID, Object object,
+ DiagramDocumentEditor dawnDiagramEditor)
+ {
+ SetPropertyCommand setPropertyCommand = new SetPropertyCommand(dawnDiagramEditor.getEditingDomain(), editPart,
+ packageUtilPropertyID, name, object);
+
+ DiagramEditPart diagramEP = dawnDiagramEditor.getDiagramEditPart();
+
+ diagramEP.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setPropertyCommand));
+
+ }
+
+ /***************************************
+ * resizes an Editpart to the given dimension
+ *
+ * @param editpart
+ * @param d
+ * dimension
+ ********************************************************************************************************************/
+ public static void resizeEditPart(EditPart editpart, Dimension d)
+ {
+ boolean editModeEnabled = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart)
+ .isEditModeEnabled();
+ if (!editModeEnabled)
+ {
+ ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).enableEditMode();
+ }
+
+ ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
+ move_req.setResizeDirection(PositionConstants.SOUTH_EAST);
+
+ Bounds b = (Bounds)((Node)editpart.getModel()).getLayoutConstraint();
+ Dimension dimensionDelta = new Dimension(d.width - b.getWidth(), d.height - b.getHeight());
+
+ move_req.setSizeDelta(dimensionDelta);
+
+ Command cmd = editpart.getCommand(move_req);
+ if (cmd == null || !cmd.canExecute())
+ {
+ throw new IllegalArgumentException("Command is not executable.");
+ }
+ ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
+
+ if (editModeEnabled)
+ {
+ ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).enableEditMode();
+ }
+ else
+ {
+ ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).disableEditMode();
+ }
+ }
+
+ /***************************************
+ * moves an EdidPart to the given postione
+ *
+ * @param editpart
+ * @param p
+ ********************************************************************************************************************/
+ public static void moveEditPart(EditPart editpart, Point p)
+ {
+ ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
+
+ Bounds b = (Bounds)((Node)editpart.getModel()).getLayoutConstraint();
+ Point newPoint = new Point(p.x - b.getX(), p.y - b.getY());
+ move_req.setMoveDelta(newPoint);
+
+ Command cmd = editpart.getCommand(move_req);
+ if (cmd == null || !cmd.canExecute())
+ {
+ throw new IllegalArgumentException("Command is not executable.");
+ }
+ ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
+ }
+
+ /**
+ * Moves the Editpart from the current position to the new Vector
+ */
+ public static void moveEditPartTo(EditPart editpart, Point p)
+ {
+ ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
+ move_req.setMoveDelta(p);
+ Command cmd = editpart.getCommand(move_req);
+ if (cmd == null || !cmd.canExecute())
+ {
+ throw new IllegalArgumentException("Command is not executable.");
+ }
+ ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
+ }
+
+ /**
+ * deletes the EditPart an the concerning model element
+ *
+ * @param editPart
+ * @param editor
+ */
+ public static void deleteEditPart(final EditPart editPart, DiagramDocumentEditor editor)
+ {
+ final View view = (View)editPart.getModel();
+
+ EObject eObject = view.getElement();
+ if (eObject != null)
+ {
+ DestroyElementRequest destroy = new DestroyElementRequest(editor.getEditingDomain(), eObject, false);
+
+ Request req = new EditCommandRequestWrapper(destroy);
+
+ Command command = editPart.getCommand(req);
+ editor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
+ }
+ TransactionalEditingDomain domain = editor.getEditingDomain();
+ if (view instanceof Edge) // also update the lists of the other client
+ {
+ domain.getCommandStack().execute(new RecordingCommand(domain)
+ {
+ @Override
+ public void doExecute()
+ {
+ Edge e = (Edge)view;
+ View source = e.getSource();
+ View target = e.getTarget();
+ if (source != null && target != null)
+ {
+ EObject targetElement = target.getElement();
+ EObject sourceElement = source.getElement();
+
+ EStructuralFeature containingFeature = sourceElement.eContainingFeature();
+ Collection<?> sourceCrossreferenceCollection = (Collection<?>)sourceElement.eGet(containingFeature);
+ sourceCrossreferenceCollection.remove(targetElement);
+ }
+ }
+ });
+ }
+ ViewUtil.destroy(view);
+ }
+
+ /***************************************
+ * Deletes a view and it's contained element
+ *
+ * @param view
+ * @param editor
+ ********************************************************************************************************************/
+ public static void deleteView(final View view, DiagramDocumentEditor editor)
+ {
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Deleting view {0} ", view); //$NON-NLS-1$
+ }
+
+ EObject eObject = view.getElement();
+ if (eObject != null)
+ {
+ DestroyElementRequest destroy = new DestroyElementRequest(editor.getEditingDomain(), eObject, false);
+
+ Request req = new EditCommandRequestWrapper(destroy);
+
+ EditPart findEditPart = DawnDiagramUpdater.findEditPart(view, editor.getDiagramEditPart().getViewer());
+ Command command = findEditPart.getCommand(req);
+ editor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
+ }
+ if (view instanceof Edge) // also update the lists of the other client
+ {
+ destroyEdge((Edge)view, editor);
+ }
+ ViewUtil.destroy(view);
+ }
+
+ public static void destroyEdge(Edge edge, DiagramDocumentEditor editor)
+ {
+ EObject referenceObject = ViewUtil.resolveSemanticElement(edge.getTarget());
+ EObject container = ViewUtil.resolveSemanticElement(edge.getSource());
+ EditPart parentEditpart = DawnDiagramUpdater.findEditPart(edge, editor.getDiagramEditPart().getViewer());
+ DestroyReferenceRequest destroyReferenceRequest = new DestroyReferenceRequest(editor.getEditingDomain(), container,
+ null, referenceObject, false);
+ Request req = new EditCommandRequestWrapper(destroyReferenceRequest);
+
+ Command command = parentEditpart.getCommand(req);
+ editor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
+ }
+
+ /***************************************
+ * creates an edge for a given elementType
+ *
+ * @param oldEdge
+ * @param sourceEditPart
+ * @param targetEditPart
+ * @param elementType
+ * @param root
+ * @return the newly created EditPart
+ ********************************************************************************************************************/
+ public static EditPart createEdge(Edge oldEdge, EditPart sourceEditPart, EditPart targetEditPart,
+ IElementType elementType, final DiagramEditPart root)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Creaeting Edge from old edge {0} ", oldEdge); //$NON-NLS-1$
+ }
+
+ CreateConnectionViewAndElementRequest req = new CreateConnectionViewAndElementRequest(elementType,
+ ((IHintedType)elementType).getSemanticHint(), root.getDiagramPreferencesHint());
+
+ ICommand createConnectionCmd = new DeferredCreateConnectionViewAndElementCommand(req, new EObjectAdapter(
+ (EObject)sourceEditPart.getModel()), new EObjectAdapter((EObject)targetEditPart.getModel()), root.getViewer());
+
+ root.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(createConnectionCmd));
+
+ final EditPartViewer viewer = root.getViewer();
+
+ final EditPart ret = (EditPart)viewer.getEditPartRegistry().get(
+ ((ConnectionViewAndElementDescriptor)req.getNewObject()).getAdapter(View.class));
+
+ if (ret != null)
+ {
+ setAnchorsAndBendPoints(ret, oldEdge, root);
+ }
+ return ret;
+ }
+
+ /***************************************
+ * This Method sets the Anchors and Bendpoint from an old Edge to the edge of the given EditPart
+ *
+ * @param edgeEditpart
+ * @param oldEdge
+ * @param root
+ ********************************************************************************************************************/
+ public static void setAnchorsAndBendPoints(final EditPart edgeEditpart, final Edge oldEdge, final DiagramEditPart root)
+ {
+ TransactionalEditingDomain domain = root.getEditingDomain();// getEditingDomain();
+ domain.getCommandStack().execute(new RecordingCommand(domain)
+ {
+ @Override
+ public void doExecute()
+ {
+ Edge edge = (Edge)edgeEditpart.getModel();
+
+ edge.setBendpoints((Bendpoints)DawnResourceHelper.createCopy(oldEdge.getBendpoints()));
+ if (oldEdge.getSourceAnchor() != null)
+ {
+ edge.setSourceAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getSourceAnchor()));
+ }
+ if (oldEdge.getTargetAnchor() != null)
+ {
+ edge.setTargetAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getTargetAnchor()));
+ }
+
+ edgeEditpart.refresh();
+ root.refresh();
+ }
+ });
+ }
+
+ /**
+ * returns the border color from a given EditPart
+ *
+ * @param editPart
+ * @return the border color of the EditPart
+ */
+ public static Color getBorderColor(EditPart editPart)
+ {
+ GraphicalEditPart e = (GraphicalEditPart)editPart;
+
+ Border border = e.getFigure().getBorder();
+
+ if (border instanceof org.eclipse.draw2d.MarginBorder)
+ {
+ // MarginBorder b = ((MarginBorder) e.getFigure().getBorder());
+ // if (border != null)
+ // {
+ // return b.getColor();
+ // }
+ return null;
+ }
+ else if (border instanceof LineBorder)
+ {
+ LineBorder b = (LineBorder)e.getFigure().getBorder();
+
+ return b.getColor();
+ }
+
+ return null;
+ }
+
+ /**
+ * activates a given EditPart
+ *
+ * @param e
+ */
+ public static void activateEditPart(final EditPart e)
+ {
+ Display.getDefault().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ e.activate();
+ org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart g = (org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)e;
+ g.getFigure().setEnabled(true);
+ }
+ });
+
+ }
+
+ /**
+ * activates the diagram EditPart
+ *
+ * @param diagramEditPart
+ */
+ public static void activateDiagramEditPart(DiagramEditPart diagramEditPart)
+ {
+ DawnChangeHelper.activateEditPart(diagramEditPart);
+
+ for (Object e : diagramEditPart.getChildren())
+ {
+ DawnChangeHelper.activateEditPart((EditPart)e);
+ }
+ }
+
+ /**
+ * deactivates the given EditPart
+ *
+ * @param editPart
+ */
+ public static void deactivateEditPart(final EditPart editPart)
+ {
+ Display.getDefault().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ editPart.deactivate();
+ editPart.getViewer().deselect(editPart);
+
+ // org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart g =
+ // (org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)e;
+ AbstractGraphicalEditPart graphicalEditPart = (AbstractGraphicalEditPart)editPart;
+ graphicalEditPart.getFigure().setEnabled(false);
+ }
+ });
+ }
+
+ /**
+ * deactivates the DiagramEditPart
+ *
+ * @param diagramEditPart
+ */
+ public static void deactivateDiagramEditPart(DiagramEditPart diagramEditPart)
+ {
+ DawnChangeHelper.deactivateEditPart(diagramEditPart);
+
+ for (Object e : diagramEditPart.getChildren())
+ {
+ DawnChangeHelper.deactivateEditPart((EditPart)e);
+ }
+
+ }
+
+ /**
+ * Deselects the given EditPart EditPart
+ */
+ public static void deselect(final EditPart e)
+ {
+ Display.getDefault().asyncExec(new Runnable()
+ {
+
+ public void run()
+ {
+ e.getViewer().deselect(e);
+ }
+ });
+ }
+
+ /**
+ * selects the given EditPart
+ *
+ * @param e
+ */
+ public static void select(final EditPart e)
+ {
+ Display.getDefault().asyncExec(new Runnable()
+ {
+
+ public void run()
+ {
+ e.getViewer().select(e);
+ }
+ });
+ }
+
+ /***************************************
+ * sets a property for an editpart
+ *
+ * @param editPart
+ * @param name
+ * @param object
+ * @param dawnDiagramEditor
+ ********************************************************************************************************************/
+ public static void setProperty(EditPart editPart, String name, EAttribute attribute, Object object,
+ DiagramDocumentEditor dawnDiagramEditor)
+ {
+ SetPropertyCommand setPropertyCommand = new SetPropertyCommand(dawnDiagramEditor.getEditingDomain(), editPart,
+ PackageUtil.getID(attribute), name, object);
+ DiagramEditPart diagramEP = dawnDiagramEditor.getDiagramEditPart();
+
+ diagramEP.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setPropertyCommand));
+ }
+
+ /***************************************
+ * updates the model
+ *
+ * @param editPart
+ * @param model
+ * @param editor
+ ********************************************************************************************************************/
+ public static void updateModel(final EditPart editPart, final EObject model, DiagramDocumentEditor editor)
+ {
+ editPart.getViewer().getEditDomain();
+ View view = (View)editPart.getModel();
+ final EObject element = view.getElement();
+
+ if (element.eClass().getName().equals("AnOperation")) // ugliest of all workarounds. Just for the prototype
+ {
+ editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain())
+ {
+ @Override
+ public void doExecute()
+ {
+ try
+ {
+ DawnResourceHelper.updateEObject(element, model);
+ }
+ catch (EClassIncompatibleException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ else
+ {
+ for (EAttribute attribute : element.eClass().getEAllAttributes())
+ {
+ setProperty(editPart, attribute.getName(), attribute, model.eGet(attribute), editor);
+ }
+ }
+ }
+
+ public static void deleteAttribute(View view, DiagramDocumentEditor editor)
+ {
+ deleteView(view, editor);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnConflictHelper.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnConflictHelper.java index a746da2ac8..0210b0dea3 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnConflictHelper.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnConflictHelper.java @@ -1,107 +1,107 @@ -/* - * Copyright (c) 2004 - 2011 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.gmf.synchronize; - -import org.eclipse.emf.cdo.CDOObject; -import org.eclipse.emf.cdo.CDOState; -import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; -import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; -import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; -import org.eclipse.emf.cdo.internal.dawn.bundle.OM; -import org.eclipse.emf.cdo.transaction.CDOTransaction; -import org.eclipse.emf.cdo.util.CDOUtil; -import org.eclipse.emf.cdo.view.CDOView; - -import org.eclipse.net4j.util.om.trace.ContextTracer; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; - -import org.eclipse.gef.EditPart; -import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; -import org.eclipse.gmf.runtime.notation.View; - -/** - * @author Martin Fluegge - */ -public class DawnConflictHelper -{ - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnConflictHelper.class); - - public static boolean handleConflictedView(CDOObject cdoObject, View view, DiagramDocumentEditor editor) - { - boolean cdoConflict = cdoObject.cdoConflict(); - if (cdoConflict && view != null) - { - if (TRACER.isEnabled()) - { - TRACER.format("Object ({0}) is in state conflict!", cdoObject); //$NON-NLS-1$ - } - EditPart editPart = DawnDiagramUpdater.createOrFindEditPartIfViewExists(view, editor); - int typeConflictLocallyDeleted = evaluateConflictType(cdoObject); - DawnAppearancer.setEditPartConflicted(editPart, typeConflictLocallyDeleted); - } - return cdoConflict; - } - - private static int evaluateConflictType(CDOObject cdoObject) - { - if (cdoObject.cdoState() == CDOState.DIRTY) - { - return DawnAppearancer.TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED; - } - return DawnAppearancer.TYPE_CONFLICT_REMOTELY_DELETED; - } - - public static void rollback(final DiagramDocumentEditor editor) - { - CDOView view = ((IDawnEditor)editor).getView(); - - if (view != null && view instanceof CDOTransaction) - { - ((CDOTransaction)view).rollback(); - } - - editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain()) - { - @Override - public void doExecute() - { - DawnAppearancer.setEditPartDefaultAllChildren(editor.getDiagramEditPart()); - DawnDiagramUpdater.refreshEditPart(editor.getDiagramEditPart()); - } - }); - } - - /** - * TODO this method should decide whether the object is conflicted or not using special Policies - * - * @param object - * @return whether the object is conflicted - */ - public static boolean isConflicted(EObject object) - { - CDOObject cdoObject = CDOUtil.getCDOObject(object); - if (cdoObject.cdoConflict()) - { - return true; - } - if (object instanceof View) - { - CDOObject element = CDOUtil.getCDOObject(((View)object).getElement()); - if (element.cdoConflict()) - { - return true; - } - } - return false; - } -} +/*
+ * Copyright (c) 2004 - 2011 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.gmf.synchronize;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOState;
+import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
+import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
+import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
+import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * @author Martin Fluegge
+ */
+public class DawnConflictHelper
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnConflictHelper.class);
+
+ public static boolean handleConflictedView(CDOObject cdoObject, View view, DiagramDocumentEditor editor)
+ {
+ boolean cdoConflict = cdoObject.cdoConflict();
+ if (cdoConflict && view != null)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Object ({0}) is in state conflict!", cdoObject); //$NON-NLS-1$
+ }
+ EditPart editPart = DawnDiagramUpdater.createOrFindEditPartIfViewExists(view, editor);
+ int typeConflictLocallyDeleted = evaluateConflictType(cdoObject);
+ DawnAppearancer.setEditPartConflicted(editPart, typeConflictLocallyDeleted);
+ }
+ return cdoConflict;
+ }
+
+ private static int evaluateConflictType(CDOObject cdoObject)
+ {
+ if (cdoObject.cdoState() == CDOState.DIRTY)
+ {
+ return DawnAppearancer.TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED;
+ }
+ return DawnAppearancer.TYPE_CONFLICT_REMOTELY_DELETED;
+ }
+
+ public static void rollback(final DiagramDocumentEditor editor)
+ {
+ CDOView view = ((IDawnEditor)editor).getView();
+
+ if (view != null && view instanceof CDOTransaction)
+ {
+ ((CDOTransaction)view).rollback();
+ }
+
+ editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain())
+ {
+ @Override
+ public void doExecute()
+ {
+ DawnAppearancer.setEditPartDefaultAllChildren(editor.getDiagramEditPart());
+ DawnDiagramUpdater.refreshEditPart(editor.getDiagramEditPart());
+ }
+ });
+ }
+
+ /**
+ * TODO this method should decide whether the object is conflicted or not using special Policies
+ *
+ * @param object
+ * @return whether the object is conflicted
+ */
+ public static boolean isConflicted(EObject object)
+ {
+ CDOObject cdoObject = CDOUtil.getCDOObject(object);
+ if (cdoObject.cdoConflict())
+ {
+ return true;
+ }
+ if (object instanceof View)
+ {
+ CDOObject element = CDOUtil.getCDOObject(((View)object).getElement());
+ if (element.cdoConflict())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF index 0a382250c6..c25bab3f50 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF @@ -24,5 +24,6 @@ Bundle-Vendor: %providerName Export-Package: org.eclipse.emf.cdo.dawn.graphiti;version="2.0.0", org.eclipse.emf.cdo.dawn.graphiti.editors;version="2.0.0", org.eclipse.emf.cdo.dawn.graphiti.notifications;version="2.0.0", + org.eclipse.emf.cdo.dawn.graphiti.util;version="2.0.0", org.eclipse.emf.cdo.dawn.graphiti.wizards;version="2.0.0" Bundle-Localization: plugin diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/editors/DawnGraphitiEditorSupport.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/editors/DawnGraphitiEditorSupport.java index 43af95d19d..cf25a514bc 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/editors/DawnGraphitiEditorSupport.java +++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/editors/DawnGraphitiEditorSupport.java @@ -10,21 +10,32 @@ */ package org.eclipse.emf.cdo.dawn.graphiti.editors; +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer; import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; import org.eclipse.emf.cdo.dawn.editors.impl.DawnAbstractEditorSupport; +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnChangeHelper; import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; import org.eclipse.emf.cdo.dawn.graphiti.notifications.DawnGraphitiHandler; import org.eclipse.emf.cdo.dawn.graphiti.notifications.DawnGraphitiLockingHandler; +import org.eclipse.emf.cdo.dawn.graphiti.util.DawnGraphitiUtil; import org.eclipse.emf.cdo.dawn.helper.DawnEditorHelper; import org.eclipse.emf.cdo.dawn.notifications.BasicDawnListener; import org.eclipse.emf.cdo.dawn.spi.DawnState; +import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry; import org.eclipse.emf.cdo.transaction.CDOTransactionHandlerBase; import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.EditPart; import org.eclipse.gef.RootEditPart; +import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.ui.editor.DiagramEditor; import java.util.Map; @@ -75,10 +86,22 @@ public class DawnGraphitiEditorSupport extends DawnAbstractEditorSupport } @Override + // TODO: try to move this method to a common base class for Graphiti and GMF public void rollback() { super.rollback(); - refresh(); + final DiagramEditor diagramDocumentEditor = (DiagramEditor)getEditor(); + TransactionalEditingDomain editingDomain = diagramDocumentEditor.getEditingDomain(); + editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) + { + @Override + public void doExecute() + { + RootEditPart rootEditPart = diagramDocumentEditor.getGraphicalViewer().getRootEditPart(); + DawnAppearancer.setEditPartDefaultAllChildren(rootEditPart); + DawnDiagramUpdater.refreshEditPart(rootEditPart); + } + }); } public void refresh() @@ -108,27 +131,97 @@ public class DawnGraphitiEditorSupport extends DawnAbstractEditorSupport public void lockObject(Object objectToBeLocked) { - if (objectToBeLocked instanceof EObject) + if (objectToBeLocked instanceof EditPart) { - CDOUtil.getCDOObject((EObject)objectToBeLocked).cdoWriteLock().lock(); + EditPart editPart = (EditPart)objectToBeLocked; + Object model = editPart.getModel(); + + if (model instanceof EObject) + { + CDOUtil.getCDOObject((EObject)model).cdoWriteLock().lock(); + if (model instanceof PictogramElement) + { + EList<EObject> businessObjects = ((PictogramElement)model).getLink().getBusinessObjects(); + for (EObject element : businessObjects) + { + CDOUtil.getCDOObject(element).cdoWriteLock().lock(); + } + } + } + DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + stylizer.setLocked(editPart, DawnAppearancer.TYPE_LOCKED_LOCALLY); + } } refresh(); } public void unlockObject(Object objectToBeUnlocked) { - CDOUtil.getCDOObject((EObject)objectToBeUnlocked).cdoWriteLock().unlock(); + if (objectToBeUnlocked instanceof EditPart) + { + EditPart editPart = (EditPart)objectToBeUnlocked; + + Object model = editPart.getModel(); + + if (model instanceof EObject) + { + CDOUtil.getCDOObject((EObject)model).cdoWriteLock().unlock(); + if (model instanceof PictogramElement) + { + if (model instanceof PictogramElement) + { + EList<EObject> businessObjects = ((PictogramElement)model).getLink().getBusinessObjects(); + for (EObject element : businessObjects) + { + CDOUtil.getCDOObject(element).cdoWriteLock().unlock(); + } + } + } + } + DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + stylizer.setDefault(editPart); + } + } refresh(); } public void handleRemoteLockChanges(Map<Object, DawnState> changedObjects) { - getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() + for (Object o : changedObjects.keySet()) { - public void run() + handleLock((CDOObject)o, getView()); + } + refresh(); + } + + private void handleLock(CDOObject object, CDOView cdoView) + { + EObject element = CDOUtil.getEObject(object); // either semantic object or notational + PictogramElement pictogramElement = DawnGraphitiUtil.getPictgramElement(element); + if (pictogramElement != null) + { + // if there is no view, the semantic object is not displayed. + EditPart editPart = DawnGraphitiUtil.getEditpart(pictogramElement, ((DiagramEditor)getEditor()) + .getGraphicalViewer().getRootEditPart()); + + if (object.cdoWriteLock().isLocked()) { - refresh(); + DawnAppearancer.setEditPartLocked(editPart, DawnAppearancer.TYPE_LOCKED_LOCALLY); } - }); + else if (object.cdoWriteLock().isLockedByOthers()) + { + DawnAppearancer.setEditPartLocked(editPart, DawnAppearancer.TYPE_LOCKED_GLOBALLY); + DawnChangeHelper.deactivateEditPart(editPart); + } + else + { + DawnAppearancer.setEditPartDefault(editPart); + DawnChangeHelper.activateEditPart(editPart); + } + } } } diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java index a16d5de457..ec3096673a 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java +++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java @@ -13,8 +13,11 @@ package org.eclipse.emf.cdo.dawn.graphiti.notifications; import org.eclipse.emf.cdo.CDOObject; import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta; import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnConflictHelper; import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; +import org.eclipse.emf.cdo.dawn.graphiti.util.DawnGraphitiUtil; +import org.eclipse.emf.cdo.dawn.helper.DawnEditorHelper; import org.eclipse.emf.cdo.dawn.notifications.BasicDawnTransactionHandler; import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.transaction.CDOTransactionConflictEvent; @@ -29,7 +32,10 @@ import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.draw2d.graph.Edge; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalViewer; import org.eclipse.gef.RootEditPart; +import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.ui.editor.DiagramEditor; import org.eclipse.swt.widgets.Display; @@ -44,32 +50,18 @@ public class DawnGraphitiHandler extends BasicDawnTransactionHandler } /** - * @since 1.0 + * @since 2.0 */ @Override public void handleViewInvalidationEvent(CDOViewInvalidationEvent event) { - editor.getDawnEditorSupport().refresh(); - // CDOViewInvalidationEvent e = event; - - // - // adjustDeletedEdges(e); - // - // for (CDOObject dirtyObject : e.getDirtyObjects()) - // { - // handleObject(dirtyObject); - // } - // - // for (CDOObject detachedObject : e.getDetachedObjects()) - // { - // handleObject(detachedObject); - // } } /** - * @since 1.0 + * @since 2.0 */ + @SuppressWarnings("restriction") @Override public void handleTransactionConflictEvent(CDOTransactionConflictEvent event) { @@ -77,55 +69,40 @@ public class DawnGraphitiHandler extends BasicDawnTransactionHandler CDOObject cdoObject = cdoTransactionConflictEvent.getConflictingObject(); - @SuppressWarnings("unused") EObject element = CDOUtil.getEObject(cdoObject); // either semantic object or notational - // View view = DawnDiagramUpdater.findView(element); - // - // if (DawnConflictHelper.isConflicted(cdoObject)) - // { - // DawnConflictHelper.handleConflictedView(cdoObject, view, (DiagramDocumentEditor)editor); - // return; - // } + + PictogramElement pictgramElement = DawnGraphitiUtil.getPictgramElement(element); + + GraphicalViewer graphicalViewer = ((DiagramEditor)editor).getGraphicalViewer(); + final EditPart editpart = DawnGraphitiUtil.getEditpart(pictgramElement, graphicalViewer.getRootEditPart()); + + if (DawnConflictHelper.isConflicted(cdoObject)) + { + DawnEditorHelper.getDisplay().syncExec(new Runnable() + { + public void run() + { + int typeConflictLocallyDeleted = DawnAppearancer.TYPE_CONFLICT_REMOTELY_DELETED; + DawnAppearancer.setEditPartConflicted(editpart, typeConflictLocallyDeleted); + } + }); + } } @Override public void modifyingObject(CDOTransaction transaction, final CDOObject object, CDOFeatureDelta featureDelta) { - // refresh(object); - // editor.setDirty(); - // object.eAdapters().add(new Adapter() - // { - // public void setTarget(Notifier newTarget) - // { - // } - // - // public void notifyChanged(Notification notification) - // { - // DawnDiagramUpdater.refreshEditPart(((DiagramEditor)editor).getGraphicalViewer().getRootEditPart()); - // - // object.eAdapters().remove(this); - // } - // - // public boolean isAdapterForType(Object type) - // { - // return false; - // } - // - // public Notifier getTarget() - // { - // return null; - // } - // }); + editor.getDawnEditorSupport().refresh(); } /** - * @since 1.0 + * @since 2.0 */ @Override public void attachingObject(CDOTransaction transaction, CDOObject object) { - // super.attachingObject(transaction, object); - // refresh(object); + super.attachingObject(transaction, object); + editor.getDawnEditorSupport().refresh(); } /** @@ -176,16 +153,6 @@ public class DawnGraphitiHandler extends BasicDawnTransactionHandler }); } - protected void handleConflicts(CDOViewInvalidationEvent e) - { - // for (CDOObject obj : e.getDetachedObjects()) - // { - // EObject element = CDOUtil.getEObject(obj); - // View view = DawnDiagramUpdater.findViewByContainer(element); - // DawnConflictHelper.handleConflictedView(CDOUtil.getCDOObject(element), view, (DiagramDocumentEditor)editor); - // } - } - @SuppressWarnings("unused") private void handleObject(CDOObject dirtyObject) { @@ -246,39 +213,5 @@ public class DawnGraphitiHandler extends BasicDawnTransactionHandler protected void refresh(CDOObject object) { DawnDiagramUpdater.refreshEditPart(((DiagramEditor)editor).getGraphicalViewer().getRootEditPart()); - - // View view = DawnDiagramUpdater.findViewByContainer(object); - // if (view == null) - // { - // view = DawnDiagramUpdater.findViewForModel(object, (DiagramDocumentEditor)editor); - // } - // if (view == null) - // { - // DawnDiagramUpdater.findViewFromCrossReferences(object); - // } - // - // EditPart relatedEditPart = DawnDiagramUpdater.findEditPart(view, ((DiagramDocumentEditor)editor) - // .getDiagramEditPart().getViewer()); - // - // if (relatedEditPart != null) - // { - // if (TRACER.isEnabled()) - // { - // TRACER.format("Updating EditPart {0} ", relatedEditPart); //$NON-NLS-1$ - // } - // EditPart parent = relatedEditPart.getParent(); - // if (parent instanceof IGraphicalEditPart) - // { - // DawnDiagramUpdater.refresh((IGraphicalEditPart)parent); - // } - // else - // { - // DawnDiagramUpdater.refreshEditPart(parent, (DiagramDocumentEditor)editor); - // } - // } - // else - // { - // DawnDiagramUpdater.refresh(((DiagramDocumentEditor)editor).getDiagramEditPart()); - // } } } diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/util/DawnGraphitiUtil.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/util/DawnGraphitiUtil.java new file mode 100644 index 0000000000..be3259a4f9 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/util/DawnGraphitiUtil.java @@ -0,0 +1,65 @@ +/*
+ * Copyright (c) 2004 - 2011 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.graphiti.util;
+
+import org.eclipse.emf.ecore.EObject;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+
+/**
+ * @author Martin Fluegge
+ */
+public class DawnGraphitiUtil
+{
+ /**
+ * This method tries to find an editpart for a given pictogram element. It recursivly searches all children for the
+ * given editpart if the model matches to pictogramElement.
+ */
+ public static EditPart getEditpart(PictogramElement pictogramElement, EditPart part)
+ {
+ for (Object object : part.getChildren())
+ {
+ EditPart child = (EditPart)object;
+ if (child.getModel().equals(pictogramElement))
+ {
+ return child;
+ }
+ return getEditpart(pictogramElement, child);
+ }
+ return null;
+ }
+
+ /**
+ * Tries to retriev the pictogram element from a given element. If the element itself is a PictogramElement, the
+ * element will be returned. Otherwise all eContainers will be checked until a PictogramElement ist found.
+ */
+ public static PictogramElement getPictgramElement(EObject element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+
+ if (element instanceof PictogramElement)
+ {
+ return (PictogramElement)element;
+ }
+
+ EObject eContainer = element.eContainer();
+
+ if (eContainer instanceof PictogramElement)
+ {
+ return (PictogramElement)eContainer;
+ }
+ return getPictgramElement(eContainer);
+ }
+}
|