Home » Eclipse Projects » GEF » Copy on drag
Copy on drag [message #90845] |
Thu, 21 August 2003 01:33  |
Eclipse User |
|
|
|
In the 2.2 milestones is mentioned the "copy on drag" feature. Since I am
trying to implement exaclty that in my application, i would like to know
wheter it is already been implemented, and if not where is the point to
start to do it.
Thanks!
Alex
|
|
| |
Re: Copy on drag [message #90923 is a reply to message #90891] |
Thu, 21 August 2003 22:10   |
Eclipse User |
|
|
|
--nextPart18314671.vWY4RKzR4h
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit
I made a patch to GEF that adds the REQ_COPY.
I have changed 3 files:
RequestConstans (added REQ_COPY)
DragEditPartsTracker (reading of the CTRL mouse and generation of the
request)
and NonResizableEditPolicy (feedback during drag).
I attach here the patch (I hope not to mess up the newsgroup). It is a
little "dirtier" because I had eclipse re-format the code. Do you think
this could go into GEF?
Alex
Eric Bordeau wrote:
> Copy on drag is actually listed under "Deferred to 3.0". I'm not sure
> what
> would be the best approach. You could look at DragEditPartsTracker to
> start with -- maybe change the request based on whether the CTRL key is
> pressed.
>
> Eric
>
> Alex Cozzi wrote:
>> In the 2.2 milestones is mentioned the "copy on drag" feature. Since I am
>> trying to implement exaclty that in my application, i would like to know
>> wheter it is already been implemented, and if not where is the point to
>> start to do it.
>> Thanks!
>> Alex
--nextPart18314671.vWY4RKzR4h
Content-Type: text/x-diff; name="patch.txt"
Content-Transfer-Encoding: 8Bit
Content-Disposition: attachment; filename="patch.txt"
Index: org/eclipse/gef/RequestConstants.java
============================================================ =======
RCS file: /home/tools/org.eclipse.gef/src/org/eclipse/gef/RequestConst ants.java,v
retrieving revision 1.7
diff -u -r1.7 RequestConstants.java
--- org/eclipse/gef/RequestConstants.java 12 Mar 2003 16:40:36 -0000 1.7
+++ org/eclipse/gef/RequestConstants.java 22 Aug 2003 02:08:28 -0000
@@ -138,4 +138,9 @@
*/
String REQ_SELECTION_HOVER = "selection hover"; //$NON-NLS-1$
+
+/**
+ * Indicates that the receiver of the request is being copied.
+ */
+String REQ_COPY = "copy"; //$NON-NLS-1$
}
Index: org/eclipse/gef/editpolicies/NonResizableEditPolicy.java
============================================================ =======
RCS file: /home/tools/org.eclipse.gef/src/org/eclipse/gef/editpolicies /NonResizableEditPolicy.java,v
retrieving revision 1.8
diff -u -r1.8 NonResizableEditPolicy.java
--- org/eclipse/gef/editpolicies/NonResizableEditPolicy.java 2 Jun 2003 17:31:03 -0000 1.8
+++ org/eclipse/gef/editpolicies/NonResizableEditPolicy.java 22 Aug 2003 02:08:29 -0000
@@ -36,199 +36,196 @@
* Subclasses can tailor the feedback.
* @author hudsonr
*/
-public class NonResizableEditPolicy
- extends SelectionHandlesEditPolicy
-{
-
-private IFigure focusRect;
-private IFigure feedback;
-
-/**
- * Creates the figure used for feedback.
- * @return the new feedback figure
- */
-protected IFigure createDragSourceFeedbackFigure() {
- // Use a ghost rectangle for feedback
- RectangleFigure r = new RectangleFigure();
- FigureUtilities.makeGhostShape(r);
- r.setLineStyle(Graphics.LINE_DASHDOT);
- r.setForegroundColor(ColorConstants.white);
- r.setBounds(getBounds());
- addFeedback(r);
- return r;
-}
-
-/**
- * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#crea teSelectionHandles()
- */
-protected List createSelectionHandles() {
- List list = new ArrayList();
- NonResizableHandleKit.addHandles((GraphicalEditPart)getHost( ), list);
- return list;
-}
-
-/**
- * @see org.eclipse.gef.EditPolicy#deactivate()
- */
-public void deactivate() {
- if (feedback != null) {
- removeFeedback(feedback);
+public class NonResizableEditPolicy extends SelectionHandlesEditPolicy {
+
+ private IFigure focusRect;
+ private IFigure feedback;
+
+ /**
+ * Creates the figure used for feedback.
+ * @return the new feedback figure
+ */
+ protected IFigure createDragSourceFeedbackFigure() {
+ // Use a ghost rectangle for feedback
+ RectangleFigure r = new RectangleFigure();
+ FigureUtilities.makeGhostShape(r);
+ r.setLineStyle(Graphics.LINE_DASHDOT);
+ r.setForegroundColor(ColorConstants.white);
+ r.setBounds(getBounds());
+ addFeedback(r);
+ return r;
+ }
+
+ /**
+ * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#crea teSelectionHandles()
+ */
+ protected List createSelectionHandles() {
+ List list = new ArrayList();
+ NonResizableHandleKit.addHandles((GraphicalEditPart) getHost(), list);
+ return list;
+ }
+
+ /**
+ * @see org.eclipse.gef.EditPolicy#deactivate()
+ */
+ public void deactivate() {
+ if (feedback != null) {
+ removeFeedback(feedback);
+ feedback = null;
+ }
+ hideFocus();
+ super.deactivate();
+ }
+
+ /**
+ * Erases drag feedback. This method called whenever an erase feedback request is
+ * received of the appropriate type.
+ * @param request the request
+ */
+ protected void eraseChangeBoundsFeedback(ChangeBoundsRequest request) {
+ if (feedback != null) {
+ removeFeedback(feedback);
+ }
feedback = null;
}
- hideFocus();
- super.deactivate();
-}
-
-/**
- * Erases drag feedback. This method called whenever an erase feedback request is
- * received of the appropriate type.
- * @param request the request
- */
-protected void eraseChangeBoundsFeedback(ChangeBoundsRequest request) {
- if (feedback != null) {
- removeFeedback(feedback);
- }
- feedback = null;
-}
-
-/**
- * @see org.eclipse.gef.EditPolicy#eraseSourceFeedback(org.eclipse.g ef.Request)
- */
-public void eraseSourceFeedback(Request request) {
- if (REQ_MOVE.equals(request.getType())
- || REQ_ADD.equals(request.getType()))
- eraseChangeBoundsFeedback((ChangeBoundsRequest) request);
-}
-
-/**
- * Returns the bounds of the host's figure by reference. The returned Rectangle should
- * not be modified.
- * @return the host figure's bounding Rectangle
- */
-private Rectangle getBounds() {
- return ((GraphicalEditPart)getHost()).getFigure().getBounds();
-}
-
-/**
- * @see org.eclipse.gef.EditPolicy#getCommand(org.eclipse.gef.Reques t)
- */
-public Command getCommand(Request request) {
- Object type = request.getType();
-
- if (REQ_MOVE.equals(type))
- return getMoveCommand((ChangeBoundsRequest)request);
- if (REQ_ORPHAN.equals(type))
- return getOrphanCommand(request);
- if (REQ_ALIGN.equals(type))
- return getAlignCommand((AlignmentRequest)request);
-
- return null;
-}
-
-/**
- * Lazily creates and returns the feedback figure used during drags.
- * @return the feedback figure
- */
-protected IFigure getDragSourceFeedbackFigure() {
- if (feedback == null)
- feedback = createDragSourceFeedbackFigure();
- return feedback;
-}
-
-/**
- * Returns the command contribution to an alignment request
- * @param request the alignment request
- * @return the contribution to the alignment
- */
-protected Command getAlignCommand(AlignmentRequest request) {
- AlignmentRequest req = new AlignmentRequest(REQ_ALIGN_CHILDREN);
- req.setEditParts(getHost());
- req.setAlignment(request.getAlignment());
- req.setAlignmentRectangle(request.getAlignmentRectangle());
- return getHost().getParent().getCommand(req);
-}
-
-/**
- * Returns the command contribution to a change bounds request. The implementation
- * actually redispatches the request to the host's parent editpart as a {@link
- * RequestConstants#REQ_MOVE_CHILDREN} request. The parent's contribution is returned.
- * @param request the change bounds requesgt
- * @return the command contribution to the request
- */
-protected Command getMoveCommand(ChangeBoundsRequest request) {
- ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE_CHILDREN);
- req.setEditParts(getHost());
-
- req.setMoveDelta(request.getMoveDelta());
- req.setSizeDelta(request.getSizeDelta());
- req.setLocation(request.getLocation());
- return getHost().getParent().getCommand(req);
-}
-
-/**
- * Subclasses may override to contribute to the orphan request. By default,
- * <code>null</code> is returned to indicate no participation. Orphan requests are not
- * forwarded to the host's parent here. That is done in {@link ComponentEditPolicy}. So,
- * if the host has a component editpolicy, then the parent will already have a chance to
- * contribute.
- * @param req the orphan request
- * @return <code>null</code> by default
- */
-protected Command getOrphanCommand(Request req) {
- return null;
-}
-
-/**
- * Hides the focus rectangle displayed in <code>showFocus()</code>.
- * @see #showFocus()
- * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#hideFocus()
- */
-protected void hideFocus() {
- if (focusRect != null)
- removeFeedback(focusRect);
- focusRect = null;
-}
-
-/**
- * Shows or updates feedback for a change bounds request.
- * @param request the request
- */
-protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
- IFigure p = getDragSourceFeedbackFigure();
-
- Rectangle r = getHostFigure().getBounds().getCopy();
- getHostFigure().translateToAbsolute(r);
- r.translate(request.getMoveDelta());
- Dimension resize = request.getSizeDelta();
- r.width += resize.width;
- r.height += resize.height;
-
- p.translateToRelative(r);
- p.setBounds(r);
-}
-
-/**
- * Shows a focus rectangle around the host's figure. The focus rectangle is expanded by 5
- * pixels from the figure's bounds.
- * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#showFocus()
- */
-protected void showFocus() {
- focusRect = new AbstractHandle(
- (GraphicalEditPart)getHost(),
- new Locator() {
+
+ /**
+ * @see org.eclipse.gef.EditPolicy#eraseSourceFeedback(org.eclipse.g ef.Request)
+ */
+ public void eraseSourceFeedback(Request request) {
+ if (REQ_MOVE.equals(request.getType())
+ || REQ_ADD.equals(request.getType())
+ || REQ_COPY.equals(request.getType()))
+ eraseChangeBoundsFeedback((ChangeBoundsRequest) request);
+ }
+
+ /**
+ * Returns the bounds of the host's figure by reference. The returned Rectangle should
+ * not be modified.
+ * @return the host figure's bounding Rectangle
+ */
+ private Rectangle getBounds() {
+ return ((GraphicalEditPart) getHost()).getFigure().getBounds();
+ }
+
+ /**
+ * @see org.eclipse.gef.EditPolicy#getCommand(org.eclipse.gef.Reques t)
+ */
+ public Command getCommand(Request request) {
+ Object type = request.getType();
+
+ if (REQ_MOVE.equals(type))
+ return getMoveCommand((ChangeBoundsRequest) request);
+ if (REQ_ORPHAN.equals(type))
+ return getOrphanCommand(request);
+ if (REQ_ALIGN.equals(type))
+ return getAlignCommand((AlignmentRequest) request);
+
+ return null;
+ }
+
+ /**
+ * Lazily creates and returns the feedback figure used during drags.
+ * @return the feedback figure
+ */
+ protected IFigure getDragSourceFeedbackFigure() {
+ if (feedback == null)
+ feedback = createDragSourceFeedbackFigure();
+ return feedback;
+ }
+
+ /**
+ * Returns the command contribution to an alignment request
+ * @param request the alignment request
+ * @return the contribution to the alignment
+ */
+ protected Command getAlignCommand(AlignmentRequest request) {
+ AlignmentRequest req = new AlignmentRequest(REQ_ALIGN_CHILDREN);
+ req.setEditParts(getHost());
+ req.setAlignment(request.getAlignment());
+ req.setAlignmentRectangle(request.getAlignmentRectangle());
+ return getHost().getParent().getCommand(req);
+ }
+
+ /**
+ * Returns the command contribution to a change bounds request. The implementation
+ * actually redispatches the request to the host's parent editpart as a {@link
+ * RequestConstants#REQ_MOVE_CHILDREN} request. The parent's contribution is returned.
+ * @param request the change bounds requesgt
+ * @return the command contribution to the request
+ */
+ protected Command getMoveCommand(ChangeBoundsRequest request) {
+ ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE_CHILDREN);
+ req.setEditParts(getHost());
+
+ req.setMoveDelta(request.getMoveDelta());
+ req.setSizeDelta(request.getSizeDelta());
+ req.setLocation(request.getLocation());
+ return getHost().getParent().getCommand(req);
+ }
+
+ /**
+ * Subclasses may override to contribute to the orphan request. By default,
+ * <code>null</code> is returned to indicate no participation. Orphan requests are not
+ * forwarded to the host's parent here. That is done in {@link ComponentEditPolicy}. So,
+ * if the host has a component editpolicy, then the parent will already have a chance to
+ * contribute.
+ * @param req the orphan request
+ * @return <code>null</code> by default
+ */
+ protected Command getOrphanCommand(Request req) {
+ return null;
+ }
+
+ /**
+ * Hides the focus rectangle displayed in <code>showFocus()</code>.
+ * @see #showFocus()
+ * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#hideFocus()
+ */
+ protected void hideFocus() {
+ if (focusRect != null)
+ removeFeedback(focusRect);
+ focusRect = null;
+ }
+
+ /**
+ * Shows or updates feedback for a change bounds request.
+ * @param request the request
+ */
+ protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
+ IFigure p = getDragSourceFeedbackFigure();
+
+ Rectangle r = getHostFigure().getBounds().getCopy();
+ getHostFigure().translateToAbsolute(r);
+ r.translate(request.getMoveDelta());
+ Dimension resize = request.getSizeDelta();
+ r.width += resize.width;
+ r.height += resize.height;
+
+ p.translateToRelative(r);
+ p.setBounds(r);
+ }
+
+ /**
+ * Shows a focus rectangle around the host's figure. The focus rectangle is expanded by 5
+ * pixels from the figure's bounds.
+ * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#showFocus()
+ */
+ protected void showFocus() {
+ focusRect =
+ new AbstractHandle((GraphicalEditPart) getHost(), new Locator() {
public void relocate(IFigure target) {
IFigure figure = getHostFigure();
Rectangle r;
if (figure instanceof HandleBounds)
- r = ((HandleBounds)figure).getHandleBounds().getCopy();
+ r = ((HandleBounds) figure).getHandleBounds().getCopy();
else
r = getHostFigure().getBounds().getResized(-1, -1);
getHostFigure().translateToAbsolute(r);
target.translateToRelative(r);
target.setBounds(r.expand(5, 5).resize(1, 1));
}
- })
- {
+ }) {
{
setBorder(new FocusBorder());
}
@@ -236,31 +233,33 @@
return null;
}
};
- addFeedback(focusRect);
-}
+ addFeedback(focusRect);
+ }
+
+ /**
+ * Calls other methods as appropriate.
+ * @see org.eclipse.gef.EditPolicy#showSourceFeedback(org.eclipse.ge f.Request)
+ */
+ public void showSourceFeedback(Request request) {
+ if (REQ_MOVE.equals(request.getType())
+ || REQ_ADD.equals(request.getType())
+ || REQ_COPY.equals(request.getType()))
+ showChangeBoundsFeedback((ChangeBoundsRequest) request);
+ }
-/**
- * Calls other methods as appropriate.
- * @see org.eclipse.gef.EditPolicy#showSourceFeedback(org.eclipse.ge f.Request)
- */
-public void showSourceFeedback(Request request) {
- if (REQ_MOVE.equals(request.getType())
- || REQ_ADD.equals(request.getType()))
- showChangeBoundsFeedback((ChangeBoundsRequest) request);
-}
-
-/**
- * Returns <code>true</code> for move, align, add, and orphan request types. This method
- * is never called for some of these types, but they are included for possible future use.
- * @see org.eclipse.gef.EditPolicy#understandsRequest(org.eclipse.ge f.Request)
- */
-public boolean understandsRequest(Request request) {
- if (REQ_MOVE.equals(request.getType())
- || REQ_ADD.equals(request.getType())
- || REQ_ORPHAN.equals(request.getType())
- || REQ_ALIGN.equals(request.getType()))
- return true;
- return super.understandsRequest(request);
-}
+ /**
+ * Returns <code>true</code> for move, align, add, and orphan request types. This method
+ * is never called for some of these types, but they are included for possible future use.
+ * @see org.eclipse.gef.EditPolicy#understandsRequest(org.eclipse.ge f.Request)
+ */
+ public boolean understandsRequest(Request request) {
+ if (REQ_MOVE.equals(request.getType())
+ || REQ_ADD.equals(request.getType())
+ || REQ_COPY.equals(request.getType())
+ || REQ_ORPHAN.equals(request.getType())
+ || REQ_ALIGN.equals(request.getType()))
+ return true;
+ return super.understandsRequest(request);
+ }
}
Index: org/eclipse/gef/tools/DragEditPartsTracker.java
============================================================ =======
RCS file: /home/tools/org.eclipse.gef/src/org/eclipse/gef/tools/DragEd itPartsTracker.java,v
retrieving revision 1.6
diff -u -r1.6 DragEditPartsTracker.java
--- org/eclipse/gef/tools/DragEditPartsTracker.java 18 Jul 2003 15:57:35 -0000 1.6
+++ org/eclipse/gef/tools/DragEditPartsTracker.java 22 Aug 2003 02:08:31 -0000
@@ -23,337 +23,361 @@
import org.eclipse.gef.editparts.LayerManager;
import org.eclipse.gef.requests.ChangeBoundsRequest;
-
/**
* A DragTracker that moves {@link org.eclipse.gef.EditPart EditParts}.
*/
-public class DragEditPartsTracker
- extends SelectEditPartTracker
-{
-
-private static final int FLAG_SOURCE_FEEDBACK = SelectEditPartTracker.MAX_FLAG << 1;
-/** Max flag */
-protected static final int MAX_FLAG = FLAG_SOURCE_FEEDBACK;
-private List operationSet, exclusionSet;
-private PrecisionPoint sourceFigureOffset;
+public class DragEditPartsTracker extends SelectEditPartTracker {
-private Request sourceRequest;
+ private static final int FLAG_SOURCE_FEEDBACK =
+ SelectEditPartTracker.MAX_FLAG << 1;
+ /** Max flag */
+ protected static final int MAX_FLAG = FLAG_SOURCE_FEEDBACK;
+ private List operationSet, exclusionSet;
+ private PrecisionPoint sourceFigureOffset;
+
+ private Request sourceRequest;
+
+ /**
+ * Constructs a new DragEditPartsTracker with the given source edit part.
+ * @param sourceEditPart the source edit part
+ */
+ public DragEditPartsTracker(EditPart sourceEditPart) {
+ super(sourceEditPart);
+ setDisabledCursor(SharedCursors.NO);
+ }
-/**
- * Constructs a new DragEditPartsTracker with the given source edit part.
- * @param sourceEditPart the source edit part
- */
-public DragEditPartsTracker(EditPart sourceEditPart) {
- super(sourceEditPart);
- setDisabledCursor(SharedCursors.NO);
-}
+ /**
+ * Erases feedback and calls {@link #performDrag()}. Sets the state to terminal.
+ * @see org.eclipse.gef.tools.AbstractTool#commitDrag()
+ */
+ public void commitDrag() {
+ eraseSourceFeedback();
+ eraseTargetFeedback();
+ performDrag();
+ setState(STATE_TERMINAL);
+ }
-/**
- * Erases feedback and calls {@link #performDrag()}. Sets the state to terminal.
- * @see org.eclipse.gef.tools.AbstractTool#commitDrag()
- */
-public void commitDrag() {
- eraseSourceFeedback();
- eraseTargetFeedback();
- performDrag();
- setState(STATE_TERMINAL);
-}
+ /**
+ * Returns a List of top-level edit parts excluding dependants (by calling
+ * {@link ToolUtilities#getSelectionWithoutDependants(EditPartViewer)} that understand the
+ * current target request (by calling
+ * {@link ToolUtilities#filterEditPartsUnderstanding(List, Request)}.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#createOperationSet()
+ */
+ protected List createOperationSet() {
+ List list =
+ ToolUtilities.getSelectionWithoutDependants(getCurrentViewer ());
+ ToolUtilities.filterEditPartsUnderstanding(list, getTargetRequest());
+ return list;
+ }
-/**
- * Returns a List of top-level edit parts excluding dependants (by calling
- * {@link ToolUtilities#getSelectionWithoutDependants(EditPartViewer)} that understand the
- * current target request (by calling
- * {@link ToolUtilities#filterEditPartsUnderstanding(List, Request)}.
- *
- * @see org.eclipse.gef.tools.AbstractTool#createOperationSet()
- */
-protected List createOperationSet() {
- List list = ToolUtilities.getSelectionWithoutDependants(
- getCurrentViewer());
- ToolUtilities.filterEditPartsUnderstanding(list, getTargetRequest());
- return list;
-}
+ /**
+ * Creates a {@link ChangeBoundsRequest}. By default, the type is
+ * {@link RequestConstants#REQ_MOVE}. Later on when the edit parts are asked to
+ * contribute to the overall command, the request type will be either
+ * {@link RequestConstants#REQ_MOVE} or {@link RequestConstants#REQ_ORPHAN}, depending on
+ * the result of {@link #isMove()}.
+ *
+ * @see org.eclipse.gef.tools.TargetingTool#createTargetRequest()
+ */
+ protected Request createTargetRequest() {
+ ChangeBoundsRequest request = new ChangeBoundsRequest(REQ_MOVE);
+ return request;
+ }
-/**
- * Creates a {@link ChangeBoundsRequest}. By default, the type is
- * {@link RequestConstants#REQ_MOVE}. Later on when the edit parts are asked to
- * contribute to the overall command, the request type will be either
- * {@link RequestConstants#REQ_MOVE} or {@link RequestConstants#REQ_ORPHAN}, depending on
- * the result of {@link #isMove()}.
- *
- * @see org.eclipse.gef.tools.TargetingTool#createTargetRequest()
- */
-protected Request createTargetRequest() {
- ChangeBoundsRequest request = new ChangeBoundsRequest(REQ_MOVE);
- return request;
-}
+ /**
+ * Erases source feedback and sets the autoexpose helper to <code>null</code>.
+ * @see org.eclipse.gef.Tool#deactivate()
+ */
+ public void deactivate() {
+ eraseSourceFeedback();
+ super.deactivate();
+ operationSet = null;
+ exclusionSet = null;
+ sourceFigureOffset = null;
+ }
-/**
- * Erases source feedback and sets the autoexpose helper to <code>null</code>.
- * @see org.eclipse.gef.Tool#deactivate()
- */
-public void deactivate() {
- eraseSourceFeedback();
- super.deactivate();
- operationSet = null;
- exclusionSet = null;
- sourceFigureOffset = null;
-}
+ /**
+ * Asks the edit parts in the {@link AbstractTool#getOperationSet() operation set} to
+ * erase their source feedback.
+ */
+ protected void eraseSourceFeedback() {
+ if (!getFlag(FLAG_SOURCE_FEEDBACK))
+ return;
+ setFlag(FLAG_SOURCE_FEEDBACK, false);
+ List editParts = getOperationSet();
+ for (int i = 0; i < editParts.size(); i++) {
+ EditPart editPart = (EditPart) editParts.get(i);
+ editPart.eraseSourceFeedback(getTargetRequest());
+ }
+ }
-/**
- * Asks the edit parts in the {@link AbstractTool#getOperationSet() operation set} to
- * erase their source feedback.
- */
-protected void eraseSourceFeedback() {
- if (!getFlag(FLAG_SOURCE_FEEDBACK))
- return;
- setFlag(FLAG_SOURCE_FEEDBACK, false);
- List editParts = getOperationSet();
- for (int i = 0; i < editParts.size(); i++) {
- EditPart editPart = (EditPart) editParts.get(i);
- editPart.eraseSourceFeedback(getTargetRequest());
+ /**
+ * Asks each edit part in the {@link AbstractTool#getOperationSet() operation set} to
+ * contribute to a {@link CompoundCommand} after first setting the request type to either
+ * {@link RequestConstants#REQ_MOVE} or {@link RequestConstants#REQ_ORPHAN}, depending on
+ * the result of {@link #isMove()}.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#getCommand()
+ */
+ protected Command getCommand() {
+ CompoundCommand command = new CompoundCommand();
+ command.setDebugLabel("Drag Object Tracker"); //$NON-NLS-1$
+
+ Iterator iter = getOperationSet().iterator();
+
+ Request request = getTargetRequest();
+
+ if (isCopy()) {
+ request.setType(REQ_COPY);
+ } else {
+ request.setType(isMove() ? REQ_MOVE : REQ_ORPHAN);
+ }
+ ;
+ while (iter.hasNext()) {
+ EditPart editPart = (EditPart) iter.next();
+ command.add(editPart.getCommand(request));
+ }
+
+ //If reparenting, add all editparts to target editpart.
+ if (!isCopy() && !isMove()) {
+ request.setType(REQ_ADD);
+ if (getTargetEditPart() == null)
+ command.add(UnexecutableCommand.INSTANCE);
+ else
+ command.add(getTargetEditPart().getCommand(getTargetRequest( )));
+ }
+ return command;
}
-}
-/**
- * Asks each edit part in the {@link AbstractTool#getOperationSet() operation set} to
- * contribute to a {@link CompoundCommand} after first setting the request type to either
- * {@link RequestConstants#REQ_MOVE} or {@link RequestConstants#REQ_ORPHAN}, depending on
- * the result of {@link #isMove()}.
- *
- * @see org.eclipse.gef.tools.AbstractTool#getCommand()
- */
-protected Command getCommand() {
- CompoundCommand command = new CompoundCommand();
- command.setDebugLabel("Drag Object Tracker");//$NON-NLS-1$
-
- Iterator iter = getOperationSet().iterator();
-
- Request request = getTargetRequest();
- request.setType(isMove() ? REQ_MOVE : REQ_ORPHAN);
-
- while (iter.hasNext()) {
- EditPart editPart = (EditPart)iter.next();
- command.add(editPart.getCommand(request));
- }
-
- //If reparenting, add all editparts to target editpart.
- if (!isMove()) {
- request.setType(REQ_ADD);
- if (getTargetEditPart() == null)
- command.add(UnexecutableCommand.INSTANCE);
- else
- command.add(getTargetEditPart().getCommand(getTargetRequest( )));
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
+ */
+ protected String getCommandName() {
+ if (getCurrentInput().isControlKeyDown()) {
+ return REQ_COPY;
+ } else {
+ if (isMove())
+ return REQ_MOVE;
+ return REQ_ADD;
+ }
}
- return command;
-}
-/**
- * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
- */
-protected String getCommandName() {
- if (isMove())
- return REQ_MOVE;
- return REQ_ADD;
-}
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
+ */
+ protected String getDebugName() {
+ return "DragEditPartsTracker:" + getCommandName(); //$NON-NLS-1$
+ }
-/**
- * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
- */
-protected String getDebugName() {
- return "DragEditPartsTracker:" + getCommandName();//$NON-NLS-1$
-}
+ /**
+ * Returns a list of all the edit parts in the {@link AbstractTool#getOperationSet()
+ * operation set}, plus the {@link org.eclipse.draw2d.ConnectionLayer}.
+ * @see org.eclipse.gef.tools.TargetingTool#getExclusionSet()
+ */
+ protected Collection getExclusionSet() {
+ if (exclusionSet == null) {
+ List set = getOperationSet();
+ exclusionSet = new ArrayList(set.size() + 1);
+ for (int i = 0; i < set.size(); i++) {
+ GraphicalEditPart editpart = (GraphicalEditPart) set.get(i);
+ exclusionSet.add(editpart.getFigure());
+ }
+ LayerManager layerManager =
+ (LayerManager) getCurrentViewer().getEditPartRegistry().get(
+ LayerManager.ID);
+ exclusionSet.add(
+ layerManager.getLayer(LayerConstants.CONNECTION_LAYER));
+ }
+ return exclusionSet;
+ }
-/**
- * Returns a list of all the edit parts in the {@link AbstractTool#getOperationSet()
- * operation set}, plus the {@link org.eclipse.draw2d.ConnectionLayer}.
- * @see org.eclipse.gef.tools.TargetingTool#getExclusionSet()
- */
-protected Collection getExclusionSet() {
- if (exclusionSet == null) {
- List set = getOperationSet();
- exclusionSet = new ArrayList(set.size() + 1);
- for (int i = 0; i < set.size(); i++) {
- GraphicalEditPart editpart = (GraphicalEditPart)set.get(i);
- exclusionSet.add(editpart.getFigure());
- }
- LayerManager layerManager = (LayerManager)getCurrentViewer().
- getEditPartRegistry().get(LayerManager.ID);
- exclusionSet.add(layerManager.getLayer(LayerConstants.CONNEC TION_LAYER));
+ /**
+ * @see org.eclipse.gef.tools.TargetingTool#handleAutoexpose()
+ */
+ protected void handleAutoexpose() {
+ if (isInDragInProgress()) {
+ if (sourceFigureOffset == null) {
+ Point offset;
+ IFigure figure =
+ ((GraphicalEditPart) getSourceEditPart()).getFigure();
+ sourceFigureOffset = new PrecisionPoint(getStartLocation());
+ figure.translateToRelative(sourceFigureOffset);
+ offset = figure.getBounds().getLocation();
+ sourceFigureOffset.preciseX -= offset.x;
+ sourceFigureOffset.preciseY -= offset.y;
+ }
+ updateTargetRequest();
+ updateTargetUnderMouse();
+ showTargetFeedback();
+ showSourceFeedback();
+ setCurrentCommand(getCommand());
+ }
}
- return exclusionSet;
-}
-/**
- * @see org.eclipse.gef.tools.TargetingTool#handleAutoexpose()
- */
-protected void handleAutoexpose() {
- if (isInDragInProgress()) {
- if (sourceFigureOffset == null) {
- Point offset;
- IFigure figure = ((GraphicalEditPart)getSourceEditPart()).getFigure();
- sourceFigureOffset = new PrecisionPoint(getStartLocation());
- figure.translateToRelative(sourceFigureOffset);
- offset = figure.getBounds().getLocation();
- sourceFigureOffset.preciseX -= offset.x;
- sourceFigureOffset.preciseY -= offset.y;
- }
- updateTargetRequest();
- updateTargetUnderMouse();
- showTargetFeedback();
- showSourceFeedback();
- setCurrentCommand(getCommand());
+ /**
+ * Erases feedback and calls {@link #performDrag()}.
+ * @see org.eclipse.gef.tools.AbstractTool#handleButtonUp(int)
+ */
+ protected boolean handleButtonUp(int button) {
+ if (stateTransition(STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) {
+ eraseSourceFeedback();
+ eraseTargetFeedback();
+ performDrag();
+ return true;
+ }
+ return super.handleButtonUp(button);
}
-}
-/**
- * Erases feedback and calls {@link #performDrag()}.
- * @see org.eclipse.gef.tools.AbstractTool#handleButtonUp(int)
- */
-protected boolean handleButtonUp(int button) {
- if (stateTransition(STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) {
- eraseSourceFeedback();
- eraseTargetFeedback();
- performDrag();
+ /**
+ * Updates the target request and mouse target, asks to show feedback, and sets the
+ * current command.
+ * @see org.eclipse.gef.tools.AbstractTool#handleDragInProgress()
+ */
+ protected boolean handleDragInProgress() {
+ if (isInDragInProgress()) {
+ updateTargetRequest();
+ updateTargetUnderMouse();
+ showTargetFeedback();
+ showSourceFeedback();
+ setCurrentCommand(getCommand());
+ }
return true;
}
- return super.handleButtonUp(button);
-}
-/**
- * Updates the target request and mouse target, asks to show feedback, and sets the
- * current command.
- * @see org.eclipse.gef.tools.AbstractTool#handleDragInProgress()
- */
-protected boolean handleDragInProgress() {
- if (isInDragInProgress()) {
- updateTargetRequest();
- updateTargetUnderMouse();
- showTargetFeedback();
- showSourceFeedback();
- setCurrentCommand(getCommand());
+ /**
+ * Calls {@link TargetingTool#updateAutoexposeHelper()} if a drag is in progress.
+ * @see org.eclipse.gef.tools.TargetingTool#handleHover()
+ */
+ protected boolean handleHover() {
+ if (isInDragInProgress())
+ updateAutoexposeHelper();
+ return true;
}
- return true;
-}
-/**
- * Calls {@link TargetingTool#updateAutoexposeHelper()} if a drag is in progress.
- * @see org.eclipse.gef.tools.TargetingTool#handleHover()
- */
-protected boolean handleHover() {
- if (isInDragInProgress())
- updateAutoexposeHelper();
- return true;
-}
+ /**
+ * Erases source feedback.
+ * @see org.eclipse.gef.tools.TargetingTool#handleInvalidInput()
+ */
+ protected boolean handleInvalidInput() {
+ super.handleInvalidInput();
+ eraseSourceFeedback();
+ return true;
+ }
-/**
- * Erases source feedback.
- * @see org.eclipse.gef.tools.TargetingTool#handleInvalidInput()
- */
-protected boolean handleInvalidInput() {
- super.handleInvalidInput();
- eraseSourceFeedback();
- return true;
-}
+ /**
+ * Processes arrow keys used to move edit parts.
+ * @see org.eclipse.gef.tools.AbstractTool#handleKeyDown(org.eclipse .swt.events.KeyEvent)
+ */
+ protected boolean handleKeyDown(KeyEvent e) {
+ if (acceptArrowKey(e)) {
+ accStepIncrement();
+ if (stateTransition(STATE_INITIAL,
+ STATE_ACCESSIBLE_DRAG_IN_PROGRESS))
+ setStartLocation(getLocation());
+ switch (e.keyCode) {
+ case SWT.ARROW_DOWN :
+ placeMouseInViewer(
+ getLocation().getTranslated(0, accGetStep()));
+ break;
+ case SWT.ARROW_UP :
+ placeMouseInViewer(
+ getLocation().getTranslated(0, -accGetStep()));
+ break;
+ case SWT.ARROW_RIGHT :
+ placeMouseInViewer(
+ getLocation().getTranslated(accGetStep(), 0));
+ break;
+ case SWT.ARROW_LEFT :
+ placeMouseInViewer(
+ getLocation().getTranslated(-accGetStep(), 0));
+ break;
+ }
+ return true;
+ }
+ return false;
+ }
-/**
- * Processes arrow keys used to move edit parts.
- * @see org.eclipse.gef.tools.AbstractTool#handleKeyDown(org.eclipse .swt.events.KeyEvent)
- */
-protected boolean handleKeyDown(KeyEvent e) {
- if (acceptArrowKey(e)) {
- accStepIncrement();
- if (stateTransition(STATE_INITIAL, STATE_ACCESSIBLE_DRAG_IN_PROGRESS))
- setStartLocation(getLocation());
- switch (e.keyCode) {
- case SWT.ARROW_DOWN :
- placeMouseInViewer(getLocation().getTranslated(0, accGetStep()));
- break;
- case SWT.ARROW_UP:
- placeMouseInViewer(getLocation().getTranslated(0, -accGetStep()));
- break;
- case SWT.ARROW_RIGHT:
- placeMouseInViewer(getLocation().getTranslated(accGetStep(), 0));
- break;
- case SWT.ARROW_LEFT:
- placeMouseInViewer(getLocation().getTranslated(-accGetStep() , 0));
- break;
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#handleKeyUp(org.eclipse.s wt.events.KeyEvent)
+ */
+ protected boolean handleKeyUp(KeyEvent e) {
+ if (acceptArrowKey(e)) {
+ accStepReset();
+ return true;
}
- return true;
+ return false;
}
- return false;
-}
-/**
- * @see org.eclipse.gef.tools.AbstractTool#handleKeyUp(org.eclipse.s wt.events.KeyEvent)
- */
-protected boolean handleKeyUp(KeyEvent e) {
- if (acceptArrowKey(e)) {
- accStepReset();
- return true;
+ /**
+ * Returns <code>true</code> if the source edit part is being moved within its parent. If
+ * the source edit part is being moved to another parent, this returns <code>false</code>.
+ * @return <code>true</code> if the source edit part is not being reparented
+ */
+ protected boolean isMove() {
+ return getSourceEditPart().getParent() == getTargetEditPart();
}
- return false;
-}
-/**
- * Returns <code>true</code> if the source edit part is being moved within its parent. If
- * the source edit part is being moved to another parent, this returns <code>false</code>.
- * @return <code>true</code> if the source edit part is not being reparented
- */
-protected boolean isMove() {
- return getSourceEditPart().getParent() == getTargetEditPart();
-}
+ /**
+ * Returns <code>true</code> if the source edit part is being copied. If
+ * the source edit part is being moved, this returns <code>false</code>.
+ * @return <code>true</code> if the source edit part is being copied;
+ */
+ protected boolean isCopy() {
+ return getCurrentInput().isControlKeyDown();
+ }
-/**
- * Calls {@link AbstractTool#executeCurrentCommand()}.
- */
-protected void performDrag() {
- executeCurrentCommand();
-}
+ /**
+ * Calls {@link AbstractTool#executeCurrentCommand()}.
+ */
+ protected void performDrag() {
+ executeCurrentCommand();
+ }
-/**
- * If auto scroll (also called auto expose) is being performed, the start location moves
- * during the scroll. This method updates that location.
- */
-protected void repairStartLocation() {
- if (sourceFigureOffset == null)
- return;
- IFigure figure = ((GraphicalEditPart)getSourceEditPart()).getFigure();
- PrecisionPoint newStart = (PrecisionPoint)sourceFigureOffset.getCopy();
- Point offset = figure.getBounds().getLocation();
- newStart.preciseX += offset.x;
- newStart.preciseY += offset.y;
- figure.translateToAbsolute(newStart);
- setStartLocation(newStart);
-}
+ /**
+ * If auto scroll (also called auto expose) is being performed, the start location moves
+ * during the scroll. This method updates that location.
+ */
+ protected void repairStartLocation() {
+ if (sourceFigureOffset == null)
+ return;
+ IFigure figure = ((GraphicalEditPart) getSourceEditPart()).getFigure();
+ PrecisionPoint newStart = (PrecisionPoint) sourceFigureOffset.getCopy();
+ Point offset = figure.getBounds().getLocation();
+ newStart.preciseX += offset.x;
+ newStart.preciseY += offset.y;
+ figure.translateToAbsolute(newStart);
+ setStartLocation(newStart);
+ }
-/**
- * Asks the edit parts in the {@link AbstractTool#getOperationSet() operation set} to
- * show source feedback.
- */
-protected void showSourceFeedback() {
- List editParts = getOperationSet();
- for (int i = 0; i < editParts.size(); i++) {
- EditPart editPart = (EditPart) editParts.get(i);
- editPart.showSourceFeedback(getTargetRequest());
+ /**
+ * Asks the edit parts in the {@link AbstractTool#getOperationSet() operation set} to
+ * show source feedback.
+ */
+ protected void showSourceFeedback() {
+ List editParts = getOperationSet();
+ for (int i = 0; i < editParts.size(); i++) {
+ EditPart editPart = (EditPart) editParts.get(i);
+ editPart.showSourceFeedback(getTargetRequest());
+ }
+ setFlag(FLAG_SOURCE_FEEDBACK, true);
}
- setFlag(FLAG_SOURCE_FEEDBACK, true);
-}
-/**
- * Calls {@link #repairStartLocation()} in case auto scroll is being performed. Updates
- * the request with the current {@link AbstractTool#getOperationSet() operation set},
- * move delta, location and type.
- * @see org.eclipse.gef.tools.TargetingTool#updateTargetRequest()
- */
-protected void updateTargetRequest() {
- repairStartLocation();
- ChangeBoundsRequest request = (ChangeBoundsRequest)getTargetRequest();
- request.setEditParts(getOperationSet());
- Dimension d = getDragMoveDelta();
- request.setMoveDelta(new Point(d.width, d.height));
- request.setLocation(getLocation());
- request.setType(getCommandName());
-}
+ /**
+ * Calls {@link #repairStartLocation()} in case auto scroll is being performed. Updates
+ * the request with the current {@link AbstractTool#getOperationSet() operation set},
+ * move delta, location and type.
+ * @see org.eclipse.gef.tools.TargetingTool#updateTargetRequest()
+ */
+ protected void updateTargetRequest() {
+ repairStartLocation();
+ ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
+ request.setEditParts(getOperationSet());
+ Dimension d = getDragMoveDelta();
+ request.setMoveDelta(new Point(d.width, d.height));
+ request.setLocation(getLocation());
+ request.setType(getCommandName());
+ }
}
--nextPart18314671.vWY4RKzR4h--
|
|
| |
Re: Copy on drag [message #90996 is a reply to message #90953] |
Fri, 22 August 2003 12:42   |
Eclipse User |
|
|
|
Hi Randy,
you are right, the cursor in not in SWT. I will look into adding it.
About the CTRL key, right now the semantic is that it will be a copy
operation if the user presses CTRL, does the drag and drop, and release the
CTRL. I am not sure what is the recommended behaviour for this.
Randy Hudson wrote:
> You would also want to change the cursor to the native cursor for
> DragCopy. Unfortunately, I'm not sure that SWT exposes such a Cursor
> contant, so you could make something that looks like the native (read
> "windows") Arrow cursor with a + decoration in the bottom right.
>
> Additionally, both the cursor, request type, and command should all be
> updated as a result of either pressing or releasing the CTRL key (i.e.,
> you can't be dependant on a mouse event happening after the key is
> toggled)
>
|
|
|
Re: Copy on drag [message #91011 is a reply to message #90996] |
Fri, 22 August 2003 13:11   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
If you use native Drag-and-Drop as the benchmark, the CTRL key may be
pressed at any time during the drag.
Can you take the default arrow cursor and obtain an ImageData from it, to
which the PLUS could be added? I don't think so, but maybe this would be
useful.
You could use:
org.eclipse.gef.SharedCursors.CURSOR_TREE_ADD
"Alex Cozzi" <cozzi@almaden.ibm.com> wrote in message
news:bi5hbp$ij9$1@eclipse.org...
> Hi Randy,
> you are right, the cursor in not in SWT. I will look into adding it.
> About the CTRL key, right now the semantic is that it will be a copy
> operation if the user presses CTRL, does the drag and drop, and release
the
> CTRL. I am not sure what is the recommended behaviour for this.
>
>
> Randy Hudson wrote:
>
> > You would also want to change the cursor to the native cursor for
> > DragCopy. Unfortunately, I'm not sure that SWT exposes such a Cursor
> > contant, so you could make something that looks like the native (read
> > "windows") Arrow cursor with a + decoration in the bottom right.
> >
> > Additionally, both the cursor, request type, and command should all be
> > updated as a result of either pressing or releasing the CTRL key (i.e.,
> > you can't be dependant on a mouse event happening after the key is
> > toggled)
> >
>
|
|
| |
Re: Copy on drag [message #91041 is a reply to message #91026] |
Sun, 24 August 2003 22:15  |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
"Alex Cozzi" <cozzi@almaden.ibm.com> wrote in message
news:bi621d$4jb$1@eclipse.org...
> Randy Hudson wrote:
>
> > If you use native Drag-and-Drop as the benchmark, the CTRL key may be
> > pressed at any time during the drag.
> >
> You mean that pressing CTRL anytime will switch the drag operation to
copy?
> what if hte user releases the CTRL before the end of the drag?
> I feel the best behaviour would be "if the user has CTRL pressed when
he/she
> releases the button, then it will be a copy, otherwise a normal drag. The
> cursor shold change according to the state of the CTRL key".
When I use the term press, I'm referring to holding down the key, so the
CTRL key would be down when you release the mouse. So, you're right that
the keydown state at the time of mouse release is the most important, but
reactiving to CTRL key Down/Up is important for changing hte cursor,
feedback, and enablement.
> PS: do you think some of the changes will go into GEF? I would like to
know
> whether I should keep a separate branch or just inherit from GEF classes
or
> I can just wait until the changes make into GEF.
> Thanks
These changes could go into GEF as long as the default function remains the
same. So, perhaps a style flag would be used (In DragEditPartsTracker) to
indicate that copying is supported by the object(s) being dragged. *OR*, if
all parts being dragged return true for understandsRequest(req), where req
is a ChangeBoundsRequest with some type identifier like COPY_ON_DRAG. I
would prefer the latter approach. But, you have to then figure out which
EditPolicy(s) would handle copy-on-drag: NonResizableEditPolicy, or
GraphicalLayoutEditPolicy and/or ContainerEditPolicy.
|
|
|
Goto Forum:
Current Time: Wed Jul 23 14:51:37 EDT 2025
Powered by FUDForum. Page generated in 0.05010 seconds
|