diff options
author | Martin Fluegge | 2011-09-25 10:07:47 +0000 |
---|---|---|
committer | Martin Fluegge | 2011-09-25 10:07:47 +0000 |
commit | 4e7428cad8fb510b7b1dea2a6bf46105457f76cd (patch) | |
tree | 01107f8b353c9f092c711a7a95385e47834b61c1 /plugins/org.eclipse.emf.cdo.dawn.gmf | |
parent | 53f0bebdc539db62a911cc27dff34cd49e135ee2 (diff) | |
download | cdo-4e7428cad8fb510b7b1dea2a6bf46105457f76cd.tar.gz cdo-4e7428cad8fb510b7b1dea2a6bf46105457f76cd.tar.xz cdo-4e7428cad8fb510b7b1dea2a6bf46105457f76cd.zip |
[319486] [Dawn] Implement locking mechanism for extended editors
https://bugs.eclipse.org/bugs/show_bug.cgi?id=319486
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn.gmf')
10 files changed, 259 insertions, 47 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.dawn.gmf/META-INF/MANIFEST.MF index 424e81b382..5a4d01f9f2 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/META-INF/MANIFEST.MF @@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.6.0,4.0.0)", org.eclipse.gmf.runtime.notation.providers;bundle-version="[1.3.0,2.0.0)", org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="[1.3.0,2.0.0)", org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide;bundle-version="[1.2.0,2.0.0)", - org.eclipse.emf.cdo.dawn.util;bundle-version="[2.0.0,3.0.0)" + org.eclipse.emf.cdo.dawn.util;bundle-version="[2.0.0,3.0.0)", + org.eclipse.emf.cdo.dawn.ui;bundle-version="[2.0.0,3.0.0)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-Vendor: %providerName 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 3dbce67abb..c8e26c81d3 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 @@ -10,11 +10,9 @@ */ package org.eclipse.emf.cdo.dawn.gmf.appearance; -import org.eclipse.draw2d.ColorConstants; import org.eclipse.gef.EditPart; import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.util.EditPartUtilities; -import org.eclipse.swt.graphics.Color; /** * @author Martin Fluegge @@ -26,18 +24,6 @@ public class DawnAppearancer public static final int DEFAULT_LINE_THICKNESS = 3; - public static final Color COLOR_NO_BORDER = new Color(null, 255, 255, 255); - - public static final Color COLOR_LOCKED_REMOTELY = ColorConstants.yellow; - - public static final Color COLOR_LOCKED_LOCALLY = ColorConstants.green; - - public static final Color COLOR_DELETE_CONFLICT = new Color(null, 255, 0, 0); - - public static final Color COLOR_CHANGE_CONFLICT = new Color(null, 0, 0, 255); - - public static final Color COLOR_NO_CONFLICT = new Color(null, 255, 255, 255); - public static final int TYPE_CONFLICT_NONE = -1; public static final int TYPE_CONFLICT_LOCALLY_DELETED = 0; @@ -90,12 +76,12 @@ public class DawnAppearancer /** * @since 2.0 */ - protected static void setEditPartLocked(EditPart editPart, int type) + public static void setEditPartLocked(EditPart editPart, int type) { DawnEditPartStylizer stylizer = DawnEditPartStylizerRegistry.instance.getStylizer(editPart); if (stylizer != null) { - stylizer.setDefault(editPart); + stylizer.setLocked(editPart, type); } } } diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicConnectionEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicConnectionEditPartStylizerImpl.java index 40b658fe3d..d741d8c4fc 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicConnectionEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicConnectionEditPartStylizerImpl.java @@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizer; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; import org.eclipse.emf.workspace.AbstractEMFOperation; @@ -43,7 +44,7 @@ public class DawnBasicConnectionEditPartStylizerImpl implements DawnEditPartStyl */ public void setDefault(EditPart editPart) { - setEdge(editPart, DawnAppearancer.COLOR_NO_CONFLICT); + setEdge(editPart, DawnColorConstants.COLOR_NO_CONFLICT); } /** @@ -51,7 +52,7 @@ public class DawnBasicConnectionEditPartStylizerImpl implements DawnEditPartStyl */ public void setConflicted(EditPart editPart, int type) { - Color color = DawnAppearancer.COLOR_DELETE_CONFLICT; + Color color = DawnColorConstants.COLOR_DELETE_CONFLICT; setEdge(editPart, color); } @@ -97,12 +98,12 @@ public class DawnBasicConnectionEditPartStylizerImpl implements DawnEditPartStyl { case DawnAppearancer.TYPE_LOCKED_LOCALLY: { - color = DawnAppearancer.COLOR_LOCKED_REMOTELY; + color = DawnColorConstants.COLOR_LOCKED_REMOTELY; break; } case DawnAppearancer.TYPE_LOCKED_GLOBALLY: { - color = DawnAppearancer.COLOR_LOCKED_LOCALLY; + color = DawnColorConstants.COLOR_LOCKED_LOCALLY; break; } diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicGraphicalEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicGraphicalEditPartStylizerImpl.java index 79462d1c42..878c359e21 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicGraphicalEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicGraphicalEditPartStylizerImpl.java @@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizer; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; import org.eclipse.draw2d.Border; import org.eclipse.draw2d.IFigure; @@ -40,7 +41,7 @@ public class DawnBasicGraphicalEditPartStylizerImpl implements DawnEditPartStyli */ public void setConflicted(EditPart editPart, int type) { - setBorder(editPart, DawnAppearancer.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + setBorder(editPart, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); } /** @@ -48,7 +49,7 @@ public class DawnBasicGraphicalEditPartStylizerImpl implements DawnEditPartStyli */ public void setLocked(EditPart editPart, int type) { - setBorder(editPart, DawnAppearancer.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + setBorder(editPart, DawnColorConstants.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); } /** diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicNodeEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicNodeEditPartStylizerImpl.java index b8c76131c3..f89c5c0370 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicNodeEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicNodeEditPartStylizerImpl.java @@ -11,6 +11,7 @@ package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; import org.eclipse.gef.EditPart; @@ -23,18 +24,30 @@ public class DawnBasicNodeEditPartStylizerImpl extends DawnBasicGraphicalEditPar @Override public void setDefault(EditPart editPart) { - setBorder(editPart, DawnAppearancer.COLOR_NO_CONFLICT, 0); + setBorder(editPart, DawnColorConstants.COLOR_NO_CONFLICT, 0); } @Override public void setConflicted(EditPart editPart, int type) { - setBorder(editPart, DawnAppearancer.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + setBorder(editPart, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); } @Override public void setLocked(EditPart editPart, int type) { - setBorder(editPart, DawnAppearancer.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + switch (type) + { + case DawnAppearancer.TYPE_LOCKED_GLOBALLY: + { + setBorder(editPart, DawnColorConstants.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + break; + } + case DawnAppearancer.TYPE_LOCKED_LOCALLY: + { + setBorder(editPart, DawnColorConstants.COLOR_LOCKED_LOCALLY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + break; + } + } } } diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicTextAwareEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicTextAwareEditPartStylizerImpl.java index 332f238973..7323bb38b4 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicTextAwareEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicTextAwareEditPartStylizerImpl.java @@ -11,6 +11,7 @@ package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; import org.eclipse.draw2d.Border; import org.eclipse.gef.EditPart; @@ -43,7 +44,7 @@ public class DawnBasicTextAwareEditPartStylizerImpl extends DawnBasicGraphicalEd // e.getFigure().setForegroundColor(DawnAppearancer.COLOR_DELETE_CONFLICT); oldValues.put(e, e.getFigure().getBorder()); - setBorder(editPart, DawnAppearancer.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + setBorder(editPart, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); // View view = (View)e.getModel(); // FontStyle style = (FontStyle)view.getStyle(NotationPackage.eINSTANCE.getFontStyle()); // if (style == null) @@ -59,6 +60,6 @@ public class DawnBasicTextAwareEditPartStylizerImpl extends DawnBasicGraphicalEd @Override public void setLocked(EditPart editPart, int type) { - setBorder(editPart, DawnAppearancer.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + setBorder(editPart, DawnColorConstants.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); } } diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBlinkingNodeEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBlinkingNodeEditPartStylizerImpl.java index 6ccd19b4cb..39c47118dd 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBlinkingNodeEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBlinkingNodeEditPartStylizerImpl.java @@ -11,6 +11,7 @@ package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; import org.eclipse.gef.EditPart; @@ -35,7 +36,7 @@ public class DawnBlinkingNodeEditPartStylizerImpl extends DawnBasicGraphicalEdit public void setDefault(EditPart editPart) { blinkingThread.stop(editPart); - setBorder(editPart, DawnAppearancer.COLOR_NO_CONFLICT, 0); + setBorder(editPart, DawnColorConstants.COLOR_NO_CONFLICT, 0); } @Override @@ -47,7 +48,7 @@ public class DawnBlinkingNodeEditPartStylizerImpl extends DawnBasicGraphicalEdit @Override public void setLocked(EditPart editPart, int type) { - setBorder(editPart, DawnAppearancer.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + setBorder(editPart, DawnColorConstants.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); } /** @@ -68,11 +69,11 @@ public class DawnBlinkingNodeEditPartStylizerImpl extends DawnBasicGraphicalEdit { if (editParts.get(e)) { - setBorder(e, DawnAppearancer.COLOR_NO_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + setBorder(e, DawnColorConstants.COLOR_NO_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); } else { - setBorder(e, DawnAppearancer.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + setBorder(e, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); } editParts.put(e, !editParts.get(e)); diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/editors/impl/DawnGMFEditorSupport.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/editors/impl/DawnGMFEditorSupport.java index 474475682b..94ed9dd306 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/editors/impl/DawnGMFEditorSupport.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/editors/impl/DawnGMFEditorSupport.java @@ -13,26 +13,35 @@ package org.eclipse.emf.cdo.dawn.gmf.editors.impl; 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.appearance.DawnEditPartStylizer; +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizerRegistry; import org.eclipse.emf.cdo.dawn.gmf.notifications.impl.DawnGMFHandler; +import org.eclipse.emf.cdo.dawn.gmf.notifications.impl.DawnGMFLockingHandler; import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; import org.eclipse.emf.cdo.dawn.notifications.BasicDawnListener; -import org.eclipse.emf.cdo.transaction.CDOTransaction; -import org.eclipse.emf.cdo.view.CDOAdapterPolicy; +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.ecore.EObject; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; +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 DawnGMFEditorSupport extends DawnAbstractEditorSupport { + private DawnGMFHandler dawnGMFHandler; + public DawnGMFEditorSupport(IDawnEditor editor) { super(editor); + dawnGMFHandler = new DawnGMFHandler(editor); } public void close() @@ -44,18 +53,37 @@ public class DawnGMFEditorSupport extends DawnAbstractEditorSupport } } - public void registerListeners() + // @Override + // public void registerListeners() + // { + // BasicDawnListener listener = new DawnGMFHandler(getEditor()); + // CDOView view = getView(); + // view.addListener(listener); + // + // if (view instanceof CDOTransaction) + // { + // CDOTransaction transaction = (CDOTransaction)view; + // transaction.addTransactionHandler(listener); + // transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.CDO); + // } + // } + + @Override + protected BasicDawnListener getBasicHandler() { - BasicDawnListener listener = new DawnGMFHandler(getEditor()); - CDOView view = getView(); - view.addListener(listener); + return dawnGMFHandler; + } - if (view instanceof CDOTransaction) - { - CDOTransaction transaction = (CDOTransaction)view; - transaction.addTransactionHandler(listener); - transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.CDO); - } + @Override + protected BasicDawnListener getLockingHandler() + { + return new DawnGMFLockingHandler(getEditor()); + } + + @Override + protected CDOTransactionHandlerBase getTransactionHandler() + { + return dawnGMFHandler; } /** @@ -77,4 +105,68 @@ public class DawnGMFEditorSupport extends DawnAbstractEditorSupport } }); } + + public void refresh() + { + final DiagramDocumentEditor diagramDocumentEditor = (DiagramDocumentEditor)getEditor(); + TransactionalEditingDomain editingDomain = diagramDocumentEditor.getEditingDomain(); + editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) + { + @Override + public void doExecute() + { + DawnDiagramUpdater.refreshEditPart(diagramDocumentEditor.getDiagramEditPart()); + } + }); + } + + public void lockObject(Object objectToBeLocked) + { + if (objectToBeLocked instanceof EditPart) + { + EditPart editPart = (EditPart)objectToBeLocked; + Object model = editPart.getModel(); + + if (model instanceof EObject) + { + CDOUtil.getCDOObject((EObject)model).cdoWriteLock().lock(); + if (model instanceof View) + { + EObject element = ((View)model).getElement(); + CDOUtil.getCDOObject(element).cdoWriteLock().lock(); + } + } + DawnEditPartStylizer stylizer = DawnEditPartStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + stylizer.setLocked(editPart, DawnAppearancer.TYPE_LOCKED_LOCALLY); + } + } + refresh(); + } + + public void unlockObject(Object objectToBeUnlocked) + { + 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 View) + { + EObject element = ((View)model).getElement(); + CDOUtil.getCDOObject(element).cdoWriteLock().unlock(); + } + } + DawnEditPartStylizer stylizer = DawnEditPartStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + stylizer.setDefault(editPart); + } + } + refresh(); + } } diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java index efed2c2d1f..9ce8de2ea5 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java @@ -15,7 +15,7 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta; import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnConflictHelper; import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; -import org.eclipse.emf.cdo.dawn.notifications.BasicDawnListener; +import org.eclipse.emf.cdo.dawn.notifications.BasicDawnTransactionHandler; import org.eclipse.emf.cdo.internal.dawn.bundle.OM; import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.transaction.CDOTransactionConflictEvent; @@ -45,7 +45,7 @@ import org.eclipse.swt.widgets.Display; /** * @author Martin Fluegge */ -public class DawnGMFHandler extends BasicDawnListener +public class DawnGMFHandler extends BasicDawnTransactionHandler { private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnGMFHandler.class); @@ -209,7 +209,6 @@ public class DawnGMFHandler extends BasicDawnListener private void handleObject(CDOObject dirtyObject) { - if (dirtyObject.cdoInvalid()) { return; diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFLockingHandler.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFLockingHandler.java new file mode 100644 index 0000000000..61a0dad7ba --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFLockingHandler.java @@ -0,0 +1,117 @@ +/* + * 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.notifications.impl; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.lock.CDOLockState; +import org.eclipse.emf.cdo.common.revision.CDOIDAndBranch; +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.dawn.notifications.BasicDawnListener; +import org.eclipse.emf.cdo.transaction.CDOTransactionConflictEvent; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.view.CDOViewInvalidationEvent; +import org.eclipse.emf.cdo.view.CDOViewLocksChangedEvent; + +import org.eclipse.net4j.util.event.IEvent; + +import org.eclipse.emf.ecore.EObject; + +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 DawnGMFLockingHandler extends BasicDawnListener +{ + public DawnGMFLockingHandler(IDawnEditor editor) + { + super(editor); + } + + public void handleViewInvalidationEvent(CDOViewInvalidationEvent event) + { + System.out.println("DawnGMFLockingHandler.handleViewInvalidationEvent()"); + } + + public void handleTransactionConflictEvent(CDOTransactionConflictEvent event) + { + System.out.println("DawnGMFLockingHandler.handleTransactionConflictEvent()"); + } + + public void handleEvent(IEvent event) + { + if (event instanceof CDOViewLocksChangedEvent) + { + CDOViewLocksChangedEvent lockEvent = (CDOViewLocksChangedEvent)event; + + CDOLockState[] lockStates = lockEvent.getLockStates(); + for (CDOLockState state : lockStates) + { + Object lockedObject = state.getLockedObject(); + + CDOView view = editor.getDawnEditorSupport().getView(); + CDOID id; + if (lockedObject instanceof CDOID) + { + id = (CDOID)lockedObject; + } + else if (lockedObject instanceof CDOIDAndBranch) + { + id = ((CDOIDAndBranch)lockedObject).getID(); + } + else + { + throw new RuntimeException("Unexpected object type: " + lockedObject); + } + + if (id != null) + { + CDOObject object = view.getObject(id); + handleLock(object, view); + System.out.println(object); + } + } + + System.out.println("DawnGMFLockingHandler.handleEvent()"); + editor.getDawnEditorSupport().refresh(); + } + } + + private void handleLock(CDOObject object, CDOView cdoView) + { + EObject element = CDOUtil.getEObject(object); // either semantic object or notational + View view = DawnDiagramUpdater.findView(element); + if (view != null) + { + // if there is no view, the semantic object is not displayed. + EditPart editPart = DawnDiagramUpdater.createOrFindEditPartIfViewExists(view, (DiagramDocumentEditor)editor); + + if (object.cdoWriteLock().isLocked()) + { + DawnAppearancer.setEditPartLocked(editPart, DawnAppearancer.TYPE_LOCKED_LOCALLY); + } + else if (object.cdoWriteLock().isLockedByOthers()) + { + DawnAppearancer.setEditPartLocked(editPart, DawnAppearancer.TYPE_LOCKED_GLOBALLY); + } + else + { + DawnAppearancer.setEditPartDefault(editPart); + } + } + } +} |