Skip to content
Snippets Groups Projects
Commit 4180aa39 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

implemented kernel DND

refs 265
parent f9faca4f
No related branches found
No related tags found
No related merge requests found
Showing
with 103 additions and 54 deletions
...@@ -25,6 +25,7 @@ import org.fortiss.tooling.base.ui.editpart.policy.RelayCreateCommandEditPolicyB ...@@ -25,6 +25,7 @@ import org.fortiss.tooling.base.ui.editpart.policy.RelayCreateCommandEditPolicyB
import org.fortiss.tooling.base.ui.editpart.request.CreateConnectionCompositionRequest; import org.fortiss.tooling.base.ui.editpart.request.CreateConnectionCompositionRequest;
import org.fortiss.tooling.kernel.service.IConnectionCompositorService; import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
import org.fortiss.tooling.kernel.ui.dnd.CompositionServiceLocalTransfer; import org.fortiss.tooling.kernel.ui.dnd.CompositionServiceLocalTransfer;
import org.fortiss.tooling.kernel.ui.dnd.ConnectionCompositionDropTargetAdapter;
import org.fortiss.tooling.kernel.ui.dnd.ConnectionCompositionSource; import org.fortiss.tooling.kernel.ui.dnd.ConnectionCompositionSource;
/** /**
...@@ -34,13 +35,18 @@ import org.fortiss.tooling.kernel.ui.dnd.ConnectionCompositionSource; ...@@ -34,13 +35,18 @@ import org.fortiss.tooling.kernel.ui.dnd.ConnectionCompositionSource;
* handled by the target edit part's {@link RelayCreateCommandEditPolicyBase}, * handled by the target edit part's {@link RelayCreateCommandEditPolicyBase},
* which completes the DND operation with the target information. It then relays * which completes the DND operation with the target information. It then relays
* the completed DND operation to the {@link IConnectionCompositorService}. * the completed DND operation to the {@link IConnectionCompositorService}.
* <p>
* This class mimics the behavior of the kernel's SWT-based
* {@link ConnectionCompositionDropTargetAdapter}, but uses the GEF abstraction
* {@link AbstractTransferDropTargetListener} super class.
* *
* @see RelayCreateCommandEditPolicyBase * @see RelayCreateCommandEditPolicyBase
* @see ConnectionCompositionDropTargetAdapter
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: * @ConQAT.Rating YELLOW Hash: 6B5AA2803FE1DC027D2BC94E176D4B37
*/ */
public class ConnectionCompositionDropTargetListener extends public class ConnectionCompositionDropTargetListener extends
AbstractTransferDropTargetListener { AbstractTransferDropTargetListener {
......
...@@ -22,17 +22,24 @@ import org.eclipse.gef.EditPart; ...@@ -22,17 +22,24 @@ import org.eclipse.gef.EditPart;
import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext; import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext;
/** /**
* A {@link ConnectionDragContext} stores information obtained from user's drag gesture, * A {@link ConnectionDragContext} stores information obtained from user's drag
* i.e. the source edit part and the location w.r.t. this edit part and the * gesture, i.e. the source edit part and the location w.r.t. this edit part and
* target edit part and the location w.r.t. this edit part. * the target edit part and the location w.r.t. this edit part.
* <p>
* This information is usually provided to the connection compositor in order to
* provide the UI data necessary to construct layout information based on the
* drag gesture positions.
* <p>
* Note that this context is used for drag operations within a single editor,
* e.g. from one displayed edit part to another in the same diagram.
* *
* TODO: the class comments of {@link ConnectionDragContext} and {@link ElementDropContext} are * @see ConnectionDropContext
* highly different. Can we make them more homogeneous? * @see ElementDropContext
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: 3C9A44958574E4B1F774160841886315 * @ConQAT.Rating YELLOW Hash: FF0ECBEE0FEA5E701F5C9CB7AB0D3B06
*/ */
public class ConnectionDragContext implements IConnectionCompositionContext { public class ConnectionDragContext implements IConnectionCompositionContext {
...@@ -49,8 +56,8 @@ public class ConnectionDragContext implements IConnectionCompositionContext { ...@@ -49,8 +56,8 @@ public class ConnectionDragContext implements IConnectionCompositionContext {
private Point targetPosition; private Point targetPosition;
/** Constructor. */ /** Constructor. */
public ConnectionDragContext(EditPart source, Point sourcePosition, EditPart target, public ConnectionDragContext(EditPart source, Point sourcePosition,
Point targetPosition) { EditPart target, Point targetPosition) {
this.source = source; this.source = source;
this.sourcePosition = sourcePosition; this.sourcePosition = sourcePosition;
this.target = target; this.target = target;
......
...@@ -23,12 +23,31 @@ import org.fortiss.tooling.base.ui.editpart.DiagramEditPartBase; ...@@ -23,12 +23,31 @@ import org.fortiss.tooling.base.ui.editpart.DiagramEditPartBase;
import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext; import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext;
/** /**
* TODO * A {@link ConnectionDropContext} stores the target edit part and the relative
* position of the user's drag gesture, when the drag source is not in the same
* diagram or editor. Depending on the concrete connection compositor this
* information may be relevant.
* <p>
* The editpart can also be a diagram edit part, e.g. the background of some
* diagram editor. In this case {@link #isRoot()} returns <code>true</code>.
* <p>
* Note that this context is usually used during a drag and drop operation
* between a JFace viewer source (e.g a tree) and GEF-based graphical editor
* when the result of the gesture should be handled by the connection compositor
* service.
* <P>
* Example scenario: the user drags a model element from the navigator onto an
* edit part in some editor and drops it there. As a result the dragged element
* is connected to the target edit part's model element by reference link in the
* model.
*
* @see ConnectionDragContext
* @see ElementDropContext
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: 70B8E48635907E7922445C6DBE918F76 * @ConQAT.Rating YELLOW Hash: ED316779B97B25D6691EB4EF09E9A5DA
*/ */
public class ConnectionDropContext implements IConnectionCompositionContext { public class ConnectionDropContext implements IConnectionCompositionContext {
......
...@@ -25,6 +25,7 @@ import org.fortiss.tooling.base.ui.editpart.policy.RelayCreateCommandEditPolicyB ...@@ -25,6 +25,7 @@ import org.fortiss.tooling.base.ui.editpart.policy.RelayCreateCommandEditPolicyB
import org.fortiss.tooling.base.ui.editpart.request.CreateElementCompositionRequest; import org.fortiss.tooling.base.ui.editpart.request.CreateElementCompositionRequest;
import org.fortiss.tooling.kernel.service.IElementCompositorService; import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.ui.dnd.CompositionServiceLocalTransfer; import org.fortiss.tooling.kernel.ui.dnd.CompositionServiceLocalTransfer;
import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionDropTargetAdapter;
import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionSource; import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionSource;
/** /**
...@@ -34,13 +35,18 @@ import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionSource; ...@@ -34,13 +35,18 @@ import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionSource;
* target edit part's {@link RelayCreateCommandEditPolicyBase}, which completes * target edit part's {@link RelayCreateCommandEditPolicyBase}, which completes
* the DND operation with the target information. It then relays the completed * the DND operation with the target information. It then relays the completed
* DND operation to the {@link IElementCompositorService}. * DND operation to the {@link IElementCompositorService}.
* <p>
* This class mimics the behavior of the kernel's SWT-based
* {@link ElementCompositionDropTargetAdapter}, but uses the GEF abstraction
* {@link AbstractTransferDropTargetListener} super class.
* *
* @see RelayCreateCommandEditPolicyBase * @see RelayCreateCommandEditPolicyBase
* @see ElementCompositionDropTargetAdapter
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: * @ConQAT.Rating YELLOW Hash: D1E8D0E560B9BF7F51F5BB2A7FA1EACA
*/ */
public class ElementCompositionDropTargetListener extends public class ElementCompositionDropTargetListener extends
AbstractTransferDropTargetListener { AbstractTransferDropTargetListener {
......
...@@ -23,20 +23,27 @@ import org.fortiss.tooling.base.ui.editpart.DiagramEditPartBase; ...@@ -23,20 +23,27 @@ import org.fortiss.tooling.base.ui.editpart.DiagramEditPartBase;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext; import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
/** /**
* Composition context for GEF edit parts initiated by a drop gesture. The * A {@link ElementDropContext} stores information obtained from user's drop
* context content is defined by the editpart that was the drop target and the * gesture, i.e. the target edit part and the location w.r.t. this edit part.
* mouse position. * Depending on the concrete element compositor this information may be
* relevant, e.g., to create proper initial layout information using the user's
* gesture position.
* <P> * <P>
* The editpart can also be a diagram edit part, e.g. the background of some * The editpart can also be a diagram edit part, e.g. the background of some
* diagram editor. * diagram editor. In this case {@link #isRoot()} returns <code>true</code>.
* <p>
* Example scenario: an element of the model library view is dragged onto a
* graphical editor. The model element is composed by some element compositor
* and the gesture position is used to make the added element appear at the
* user's target location.
* *
* TODO: the class comments of {@link ConnectionDragContext} and {@link ElementDropContext} are * @see ConnectionDragContext
* highly different. Can we make them more homogeneous? * @see ConnectionDropContext
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: 70B8E48635907E7922445C6DBE918F76 * @ConQAT.Rating YELLOW Hash: 01605EE831D52FCF0C2849835AC66C26
*/ */
public class ElementDropContext implements IElementCompositionContext { public class ElementDropContext implements IElementCompositionContext {
......
...@@ -24,6 +24,7 @@ import org.eclipse.jface.viewers.TreeViewer; ...@@ -24,6 +24,7 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerDropAdapter; import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent; import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData; import org.eclipse.swt.dnd.TransferData;
...@@ -34,13 +35,17 @@ import org.fortiss.tooling.kernel.ui.util.DragAndDropUtils; ...@@ -34,13 +35,17 @@ import org.fortiss.tooling.kernel.ui.util.DragAndDropUtils;
import org.fortiss.tooling.kernel.utils.ModelUtils; import org.fortiss.tooling.kernel.utils.ModelUtils;
/** /**
* {@link ElementCompositionDropTargetAdapter} implementation for a JFace * {@link ViewerDropAdapter} implementation for a JFace {@link TreeViewer}. This
* {@link TreeViewer}. * implementation mimics the behavior of SWT-based
* {@link ElementCompositionDropTargetAdapter}, but uses the JFace super class
* {@link ViewerDropAdapter} instead of SWT's {@link DropTargetAdapter}.
*
* @see ElementCompositionDropTargetAdapter
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: * @ConQAT.Rating YELLOW Hash: 571453E48E7AA8DE7879B78664C0E805
*/ */
public class ViewerElementCompositionDropAdapter extends ViewerDropAdapter { public class ViewerElementCompositionDropAdapter extends ViewerDropAdapter {
......
...@@ -28,16 +28,14 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService; ...@@ -28,16 +28,14 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: E8FE5EC5C36C0A8456AEBC887D735DDF * @ConQAT.Rating YELLOW Hash: 4B64D3A6F78734C6CDEC152437300DC0
*/ */
public class CompositionServiceLocalTransfer extends SimpleObjectTransfer { public class CompositionServiceLocalTransfer extends SimpleObjectTransfer {
/** Singleton instance. */ /** Singleton instance. */
private static final CompositionServiceLocalTransfer INSTANCE = new CompositionServiceLocalTransfer(); private static final CompositionServiceLocalTransfer INSTANCE = new CompositionServiceLocalTransfer();
/** Transfer type name. */ /** Transfer type name. */
// TODO @review CD: Why does it need such a complex name? Super class private static final String TYPE_NAME = CompositionServiceLocalTransfer.class
// already handles timing . .getName();
private static final String TYPE_NAME = "Fortiss kernel composition transfer"
+ System.currentTimeMillis() + ":" + INSTANCE.hashCode();
/** Transfer type ID. */ /** Transfer type ID. */
private static final int TYPEID = registerType(TYPE_NAME); private static final int TYPEID = registerType(TYPE_NAME);
......
...@@ -28,11 +28,14 @@ import org.eclipse.swt.dnd.DragSourceAdapter; ...@@ -28,11 +28,14 @@ import org.eclipse.swt.dnd.DragSourceAdapter;
* {@link #getParentElement()}, and transfers an * {@link #getParentElement()}, and transfers an
* {@link ConnectionCompositionSource} object via * {@link ConnectionCompositionSource} object via
* {@link CompositionServiceLocalTransfer}. * {@link CompositionServiceLocalTransfer}.
* <p>
* This implementation uses the raw SWT DND mechanism.
*
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: E262C53D9770AA7BD12D6D71CEB4C586 * @ConQAT.Rating YELLOW Hash: 5EA6BE06BED62D8859B23FB423E02B1D
*/ */
public abstract class ConnectionCompositionDragSourceAdapter extends public abstract class ConnectionCompositionDragSourceAdapter extends
ElementCompositionDragSourceAdapter { ElementCompositionDragSourceAdapter {
......
...@@ -28,18 +28,17 @@ import org.fortiss.tooling.kernel.service.IConnectionCompositorService; ...@@ -28,18 +28,17 @@ import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
* {@link DropTargetAdapter} for completing an EObject connection via a drop * {@link DropTargetAdapter} for completing an EObject connection via a drop
* gesture. If the {@link IConnectionCompositorService} allows the composition * gesture. If the {@link IConnectionCompositorService} allows the composition
* the {@link DND#DROP_LINK} detail is set as user feedback. * the {@link DND#DROP_LINK} detail is set as user feedback.
* <p>
* This implementation uses the raw SWT DND mechanism.
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: 0BFB86B105FFC704BA4114BD223C57B8 * @ConQAT.Rating YELLOW Hash: EDF3A3B3D1E14E3840A6A73DA83D3D2C
*/ */
public abstract class ConnectionCompositionDropTargetAdapter extends public abstract class ConnectionCompositionDropTargetAdapter extends
DropTargetAdapter { DropTargetAdapter {
// TODO @review CD: This class sure is useful yet has never been
// implemented. Has it ever been tested?
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void drop(DropTargetEvent event) { public void drop(DropTargetEvent event) {
...@@ -59,14 +58,13 @@ public abstract class ConnectionCompositionDropTargetAdapter extends ...@@ -59,14 +58,13 @@ public abstract class ConnectionCompositionDropTargetAdapter extends
event.detail = DND.DROP_NONE; event.detail = DND.DROP_NONE;
return; return;
} }
// TODO @review CD: abort when canConnect succeeds?
if (IConnectionCompositorService.INSTANCE.canConnect( if (IConnectionCompositorService.INSTANCE.canConnect(
dragSource.getDesignatedElement(), target, dragSource.getDesignatedElement(), target,
dragSource.getDesignatedParentElement(), null)) { dragSource.getDesignatedParentElement(), null)) {
event.detail = DND.DROP_NONE; event.detail = DND.DROP_LINK;
return; return;
} }
event.detail = DND.DROP_LINK; event.detail = DND.DROP_NONE;
} }
/** Returns the current target element. */ /** Returns the current target element. */
......
...@@ -28,25 +28,20 @@ import org.fortiss.tooling.kernel.service.IConnectionCompositorService; ...@@ -28,25 +28,20 @@ import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: D19FC49278D9C24C478FFE4613695AD5 * @ConQAT.Rating YELLOW Hash: F146EB39DD806F5A40DED1CA93D74F7A
*/ */
public class ConnectionCompositionSource extends ElementCompositionSource { public class ConnectionCompositionSource extends ElementCompositionSource {
/** Stores the designated parent element. */ /** Stores the parent element for use in connection composition. */
// TODO @review CD: make final? private final EObject parentElement;
private EObject designatedParentElement;
/** Constructor. */ /** Constructor. */
public ConnectionCompositionSource(EObject element, EObject parent) { public ConnectionCompositionSource(EObject element, EObject parent) {
super(element); super(element);
this.designatedParentElement = parent; this.parentElement = parent;
} }
/** Returns the designated parent element. */ /** Returns the designated parent element. */
public EObject getDesignatedParentElement() { public EObject getDesignatedParentElement() {
return designatedParentElement; return parentElement;
} }
// TODO @review CD: This class is a 95% clone of ElementCompositionSource.
// Moreover derivation does not make sense - neither from the code's nor
// from the semantics' point of view.
} }
\ No newline at end of file
...@@ -28,11 +28,13 @@ import org.eclipse.swt.dnd.Transfer; ...@@ -28,11 +28,13 @@ import org.eclipse.swt.dnd.Transfer;
* gesture. The implementation takes a source model element provided by * gesture. The implementation takes a source model element provided by
* {@link #getSourceElement()} and transfers an {@link ElementCompositionSource} * {@link #getSourceElement()} and transfers an {@link ElementCompositionSource}
* object using {@link CompositionServiceLocalTransfer}. * object using {@link CompositionServiceLocalTransfer}.
* <p>
* This implementation uses the raw SWT DND mechanism.
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 6F0E5F8DCFDB6BDECBC70C85507F2552 * @ConQAT.Rating YELLOW Hash: A8B19348C86670BE63B6242EF15F297D
*/ */
public abstract class ElementCompositionDragSourceAdapter extends public abstract class ElementCompositionDragSourceAdapter extends
DragSourceAdapter { DragSourceAdapter {
......
...@@ -28,11 +28,13 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService; ...@@ -28,11 +28,13 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
* {@link DropTargetAdapter} for completing an EObject composition via a drop * {@link DropTargetAdapter} for completing an EObject composition via a drop
* gesture. If the {@link IElementCompositorService} allows the composition the * gesture. If the {@link IElementCompositorService} allows the composition the
* {@link DND#DROP_COPY} detail is set as user feedback. * {@link DND#DROP_COPY} detail is set as user feedback.
* <p>
* This implementation uses the raw SWT DND mechanism.
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: 194552CC8315FA75482EAFCE4852E161 * @ConQAT.Rating YELLOW Hash: D04EA768686154B53725E567D3D70A7C
*/ */
public abstract class ElementCompositionDropTargetAdapter extends public abstract class ElementCompositionDropTargetAdapter extends
DropTargetAdapter { DropTargetAdapter {
......
...@@ -28,21 +28,20 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService; ...@@ -28,21 +28,20 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: B601637F018D099C468F5470DBE8A605 * @ConQAT.Rating YELLOW Hash: C8BE422248D89555D262BED1F8815C99
*/ */
public class ElementCompositionSource { public class ElementCompositionSource {
/** Stores the element designated for composition. */ /** Stores the element designated for composition. */
// TODO @review CD: make final? private EObject element;
private EObject designatedElement;
/** Constructor. */ /** Constructor. */
public ElementCompositionSource(EObject element) { public ElementCompositionSource(EObject element) {
this.designatedElement = element; this.element = element;
} }
/** Returns the designated element. */ /** Returns the designated element. */
public EObject getDesignatedElement() { public EObject getDesignatedElement() {
return designatedElement; return element;
} }
} }
<!-- <!--
$Id: package.html 835 2011-06-28 07:31:00Z ratiu $ $Id: package.html 835 2011-06-28 07:31:00Z ratiu $
@version $Rev: 835 $ @version $Rev: 835 $
@ConQAT.Rating RED Hash: 7CD025BCFEDE1B96A0EBDE550A6AD6EE @ConQAT.Rating YELLOW Hash: CC56D6574A670E6853219571BF8D1708
--> -->
<body> <body>
Support classes for using the drag and drop mechanism. Support classes for using the SWT-based drag and drop mechanism.
We distinguish between DND operation, which should result in calling the element composition, and those,
which result in calling the connection composition.
</body> </body>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment