Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbateman2007-01-31 02:35:20 +0000
committercbateman2007-01-31 02:35:20 +0000
commit3f93c9e9665810001dfe37243302d3330ebc32a4 (patch)
treebbddf0cba6f2a176f94e2cc48ee0e97b82498ec0
parent94610f4a2c92f25cee81330d583113a30c9cec9b (diff)
downloadwebtools.jsf-20070131.tar.gz
webtools.jsf-20070131.tar.xz
webtools.jsf-20070131.zip
Prototyped basic column selection and drag on dataTablesv20070131
Prototyped basic drop validation and re-wrote DragMoveEditPolicy to make compatible Improved mouse-over and added the idea of a selection tracker that activates before any event other than updating target under mouse in RangeSelectionTool.
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/icons/column_select.gifbin0 -> 858 bytes
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/ColumnElementEdit.java107
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/DataTableElementEdit.java199
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/icons/MoveHandle.pngbin0 -> 183 bytes
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnHelper.java55
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnResizableEditPolicy.java88
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/CornerRelativeHandleLocator.java49
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/DragMoveEditPolicy.java243
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementMenuBar.java17
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementResizableEditPolicy.java35
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/IDropRequestorProvider.java22
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/IEnhancedSelectionEditPolicy.java32
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/ElementEditPart.java54
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NodeEditPart.java47
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NonVisualComponentEditPart.java10
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/TextEditPart.java13
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/requests/PageDesignerRequestConstants.java14
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeDragTracker.java22
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeSelectionTool.java64
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/ActionData.java4
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionRule.java24
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionValidator.java36
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DnDPositionValidator.java10
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/JSFRootContainerPositionRule.java4
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/AbstractDropLocationStrategy.java30
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/DefaultDropLocationStrategy.java143
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/EditPartPositionHelper.java12
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/IDropLocationStrategy.java47
28 files changed, 1141 insertions, 240 deletions
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/icons/column_select.gif b/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/icons/column_select.gif
new file mode 100644
index 000000000..f9dc00611
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/icons/column_select.gif
Binary files differ
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/ColumnElementEdit.java b/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/ColumnElementEdit.java
index 24a59efbd..d4118f5db 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/ColumnElementEdit.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/ColumnElementEdit.java
@@ -11,11 +11,27 @@
*******************************************************************************/
package org.eclipse.jst.pagedesigner.jsf.ui.elementedit.jsfhtml;
+import java.util.Iterator;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.jst.pagedesigner.editpolicies.ColumnHelper;
import org.eclipse.jst.pagedesigner.editpolicies.ColumnResizableEditPolicy;
+import org.eclipse.jst.pagedesigner.editpolicies.DragMoveEditPolicy;
import org.eclipse.jst.pagedesigner.parts.ElementEditPart;
+import org.eclipse.jst.pagedesigner.parts.NodeEditPart;
+import org.eclipse.jst.pagedesigner.validation.caret.IPositionMediator;
+import org.eclipse.jst.pagedesigner.validation.caret.Target;
+import org.eclipse.jst.pagedesigner.viewer.CaretPositionResolver;
+import org.eclipse.jst.pagedesigner.viewer.DefaultDropLocationStrategy;
+import org.eclipse.jst.pagedesigner.viewer.DesignPosition;
+import org.eclipse.jst.pagedesigner.viewer.IDropLocationStrategy;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
/**
* @author mengbo
@@ -23,6 +39,7 @@ import org.w3c.dom.Element;
*/
public class ColumnElementEdit extends DefaultJSFHTMLElementEdit
{
+
/* (non-Javadoc)
* @see org.eclipse.jst.pagedesigner.elementedit.AbstractElementEdit#handleModelChange(org.w3c.dom.Element, org.eclipse.jst.pagedesigner.parts.ElementEditPart)
*/
@@ -43,5 +60,95 @@ public class ColumnElementEdit extends DefaultJSFHTMLElementEdit
public void createEditPolicies(ElementEditPart part)
{
part.installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new ColumnResizableEditPolicy());
+ part.installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new MyDragEditPolicy());
+ }
+
+ private static class MyDragEditPolicy extends DragMoveEditPolicy
+ {
+ public IDropLocationStrategy getDropRequestorLocationStrategy(
+ Request request)
+ {
+ return new MyDropLocationStrategy(getHost());
+ }
+
+ private static class MyDropLocationStrategy extends DefaultDropLocationStrategy
+ {
+ public MyDropLocationStrategy(EditPart host) {
+ super(host);
+ }
+
+ public DesignPosition calculateDesignPosition(EditPart target,
+ Point p, IPositionMediator validator)
+ {
+
+ // get the nearest ancestor part to target that is
+ // editable or target if it is editable
+ target = validator.getEditableContainer(new Target(target));
+
+ // target must be an element part
+ if (target instanceof ElementEditPart)
+ {
+ // can only try to drop a column into a table. If we are
+ // targetting a column, then we can see if its table will take it
+ Node targetNode = ((ElementEditPart)target).getDOMNode();
+
+ if ("dataTable".equals(targetNode.getLocalName()))
+ {
+ // if we're on the table, try to figure out which column we are above
+ for (Iterator it = target.getChildren().iterator(); it.hasNext();)
+ {
+ final NodeEditPart nodeEditPart = (NodeEditPart) it.next();
+ Node childNode = nodeEditPart.getDOMNode();
+ if ("column".equals(childNode.getLocalName()))
+ {
+ final Rectangle columnBounds =
+ ColumnHelper.getAdjustedColumnBoundingRectangle(nodeEditPart);
+ if (columnBounds.contains(p))
+ {
+ target = nodeEditPart;
+ targetNode = ((ElementEditPart)target).getDOMNode();
+ break;
+ }
+ }
+ }
+ }
+
+ // TODO: get proper tag lib resolution
+ if ("column".equals(targetNode.getLocalName()))
+ {
+ DesignPosition position = null;
+ final Rectangle columnBounds =
+ ColumnHelper.getAdjustedColumnBoundingRectangle((GraphicalEditPart) target);
+ if (CaretPositionResolver.toXMiddle(columnBounds, p) < 0)
+ {
+ position = DesignPosition.createPositionBeforePart(target);
+ }
+ else
+ {
+ position = DesignPosition.createPositionAfterPart(target);
+ }
+
+
+ if (validator.isValidPosition(position))
+ {
+ return position;
+ }
+ }
+ }
+
+ // otherwise, no valid position
+ return null;
+ }
+
+ protected Rectangle createCaretBounds(DesignPosition position) {
+ Rectangle bounds = super.createCaretBounds(position);
+ Rectangle containerBounds = ColumnHelper.getAdjustedColumnBoundingRectangle((GraphicalEditPart) getHost());
+ bounds.height = containerBounds.height;
+ bounds.y = containerBounds.y;
+ return bounds;
+ }
+
+
+ }
}
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/DataTableElementEdit.java b/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/DataTableElementEdit.java
index e80095508..c294a7ccb 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/DataTableElementEdit.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner.jsf.ui/src/org/eclipse/jst/pagedesigner/jsf/ui/elementedit/jsfhtml/DataTableElementEdit.java
@@ -11,23 +11,31 @@
*******************************************************************************/
package org.eclipse.jst.pagedesigner.jsf.ui.elementedit.jsfhtml;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
+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.gef.requests.LocationRequest;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
import org.eclipse.jst.pagedesigner.actions.single.SelectEditPartAction;
import org.eclipse.jst.pagedesigner.editors.PageDesignerActionConstants;
+import org.eclipse.jst.pagedesigner.editpolicies.DragMoveEditPolicy;
import org.eclipse.jst.pagedesigner.editpolicies.ElementResizableEditPolicy;
+import org.eclipse.jst.pagedesigner.jsf.core.dom.JSFDOMUtil;
import org.eclipse.jst.pagedesigner.jsf.ui.JSFUIPlugin;
import org.eclipse.jst.pagedesigner.jsf.ui.actions.DeleteHColumnHeaderFooterAction;
import org.eclipse.jst.pagedesigner.jsf.ui.actions.DeleteHeaderFooterAction;
@@ -51,7 +59,18 @@ import org.eclipse.jst.pagedesigner.tableedit.InsertRowColumnAction;
import org.eclipse.jst.pagedesigner.tableedit.TableInsertRequest;
import org.eclipse.jst.pagedesigner.tableedit.TableResizeRequest;
import org.eclipse.jst.pagedesigner.tableedit.TableRowColumnDeleteRequest;
+import org.eclipse.jst.pagedesigner.tools.ObjectModeDragTracker;
+import org.eclipse.jst.pagedesigner.validation.caret.ActionData;
+import org.eclipse.jst.pagedesigner.validation.caret.DefaultPositionRule;
+import org.eclipse.jst.pagedesigner.validation.caret.DnDPositionValidator;
+import org.eclipse.jst.pagedesigner.validation.caret.IPositionMediator;
+import org.eclipse.jst.pagedesigner.validation.caret.Target;
import org.eclipse.jst.pagedesigner.viewer.IHTMLGraphicalViewer;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
/**
* @author mengbo
@@ -203,17 +222,39 @@ public class DataTableElementEdit extends DefaultJSFHTMLElementEdit
public void createEditPolicies(ElementEditPart part)
{
part.installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new DataTableResizePolicy(part));
+ part.installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
+ new MyDragMoveEditPolicy());
}
static class DataTableResizePolicy extends ElementResizableEditPolicy
{
ElementEditPart _part;
+ Cursor _columnSelectCursor;
public DataTableResizePolicy(ElementEditPart part)
{
_part = part;
}
+ public void deactivate() {
+ super.deactivate();
+ if (_columnSelectCursor != null && !_columnSelectCursor.isDisposed())
+ {
+ _columnSelectCursor.dispose();
+ _columnSelectCursor = null;
+ }
+ }
+
+ private Cursor getColumnSelectCursor()
+ {
+ if (_columnSelectCursor == null)
+ {
+ final Image cursorImage = JSFUIPlugin.getDefault().getImage("column_select.gif");
+ _columnSelectCursor = new Cursor(null, cursorImage.getImageData(), 2, 5);
+ }
+
+ return _columnSelectCursor;
+ }
/* (non-Javadoc)
* @see org.eclipse.gef.editpolicies.ResizableEditPolicy#getCommand(org.eclipse.gef.Request)
*/
@@ -271,5 +312,155 @@ public class DataTableElementEdit extends DefaultJSFHTMLElementEdit
}
return super.getCommand(request);
}
+
+ public Cursor getSelectionToolCursor(Point mouseLocation)
+ {
+ if (hitTestColumnSelection(mouseLocation))
+ {
+ return getColumnSelectCursor();
+ }
+
+ return null;
+ }
+
+ protected DragTracker getSelectionTracker(LocationRequest request) {
+ final Point mouseLocator = request.getLocation();
+ if (hitTestColumnSelection(mouseLocator))
+ {
+ ObjectModeDragTracker dragTracker = new ObjectModeDragTracker(getHost())
+ {
+ protected boolean handleButtonDown(int button)
+ {
+ // only customize the case where we are in a column selection mode
+ if (button == 1)
+ {
+ EditPart retarget =
+ getRetargetSelectionEditPart(mouseLocator);
+
+ if (retarget != null)
+ {
+ setSourceEditPart(retarget);
+ }
+ }
+
+ // default
+ return super.handleButtonDown(button);
+ }
+ };
+
+ dragTracker.setDefaultCursor(getSelectionToolCursor(mouseLocator));
+ return dragTracker;
+ }
+ return new ObjectModeDragTracker(getHost());
+ }
+
+ public DragTracker getSelectionDragTracker(LocationRequest request) {
+ return getSelectionTracker(request);
+ }
+
+ public EditPart getRetargetSelectionEditPart(Point mouseLocation) {
+ if (hitTestColumnSelection(mouseLocation))
+ {
+ GraphicalEditPart editPart = (GraphicalEditPart) getHost();
+ List children = editPart.getChildren();
+
+ for (Iterator it = children.iterator(); it.hasNext();)
+ {
+ GraphicalEditPart child = (GraphicalEditPart) it.next();
+
+ if (child instanceof NodeEditPart)
+ {
+ Node childNode = ((NodeEditPart)child).getDOMNode();
+
+ if (JSFDOMUtil.isHColumn(childNode))
+ {
+ Point relativeMousePointer = mouseLocation.getCopy();
+ IFigure hostFigure = child.getFigure();
+ hostFigure.translateToRelative(relativeMousePointer);
+ Rectangle hostBounds = hostFigure.getBounds();
+ if (relativeMousePointer.x >= hostBounds.x
+ && relativeMousePointer.x < hostBounds.x+hostBounds.width)
+ {
+ return child;
+ }
+ }
+ }
+ }
+ }
+
+ // otherwise, don't retarget
+ return null;
+ }
+
+ private boolean hitTestColumnSelection(Point mouseLocation)
+ {
+ final GraphicalEditPart part = (GraphicalEditPart) getHost();
+ final IFigure panelFigure = part.getFigure();
+
+ Point relativeLocation = mouseLocation.getCopy();
+ panelFigure.translateToRelative(relativeLocation);
+
+ final int yoffsetAbs = Math.abs(panelFigure.getBounds().y - relativeLocation.y);
+
+ if (yoffsetAbs <= 4)
+ {
+ return true;
+ }
+
+ return false;
+ }
+ }
+
+ public static class MyDragMoveEditPolicy extends DragMoveEditPolicy
+ {
+ protected IPositionMediator createDropChildValidator(
+ ChangeBoundsRequest r)
+ {
+ DnDPositionValidator validator =
+ new DnDPositionValidator(new ActionData(
+ ActionData.COMPONENT_MOVE, r.getEditParts()));
+ validator.addRule(new OnlyColumnsAndFacetsRule(validator, validator.getActionData()));
+ return validator;
+ }
+
+ private static class OnlyColumnsAndFacetsRule extends DefaultPositionRule
+ {
+ public OnlyColumnsAndFacetsRule(IPositionMediator mediator,
+ ActionData actionData) {
+ super(mediator, actionData);
+ }
+
+ public boolean isEditable(Target target) {
+ // TODO:
+ if ("dataTable".equals(target.getNode().getLocalName()))
+ {
+ return isDataDroppable();
+ }
+
+ return true;
+ }
+
+ private boolean isDataDroppable()
+ {
+ List editParts = (List) _actionData.getData();
+
+ for (Iterator it = editParts.iterator(); it.hasNext();)
+ {
+ EditPart editPart = (EditPart) it.next();
+ if (editPart instanceof NodeEditPart)
+ {
+ Node node = ((NodeEditPart)editPart).getDOMNode();
+ // TODO: need proper lib call that verifies tag lib
+ if (!"facet".equals(node.getLocalName())
+ && !"column".equals(node.getLocalName()))
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+ }
}
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/icons/MoveHandle.png b/jsf/plugins/org.eclipse.jst.pagedesigner/icons/MoveHandle.png
new file mode 100644
index 000000000..679ef9918
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/icons/MoveHandle.png
Binary files differ
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnHelper.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnHelper.java
index c69e687b8..99aa806d7 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnHelper.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnHelper.java
@@ -24,28 +24,43 @@ import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableLayout2;
* @author mengbo
*/
public class ColumnHelper {
+
+ /**
+ * @param editPart
+ * @return a rectangle that bounds the actual visual rectangle of the column represented
+ * by editPart. The editPart's figure normally only maps to the td in the rendered table.
+ *
+ * The rectangle is translated to absolute bounds
+ */
+ public static Rectangle getAdjustedColumnBoundingRectangle(GraphicalEditPart editPart)
+ {
+ Rectangle bounds = editPart.getFigure().getBounds().getCopy();
+
+ if (editPart.getParent() != null) {
+ IFigure figure = ((GraphicalEditPart) editPart.getParent())
+ .getFigure();
+ if (figure instanceof CSSFigure) {
+ CSSFigure cssFigure = (CSSFigure) figure;
+ LayoutManager layoutManager = cssFigure.getLayoutManager();
+ if (layoutManager instanceof CSSTableLayout2) {
+ CSSTableLayout2 tableLayout = (CSSTableLayout2) layoutManager;
+ bounds.y = tableLayout.getHSpacing();
+ bounds.height = figure.getClientArea().height
+ - tableLayout.getHSpacing() * 2;
+ }
+ }
+ }
+ bounds = new PrecisionRectangle(bounds.getResized(-1, -1));
+ editPart.getFigure().translateToAbsolute(bounds);
+
+ return bounds;
+ }
+
public static Rectangle getColumnBounds(GraphicalEditPart editPart,
IFigure target) {
- Insets insets = target.getInsets();
- Rectangle bounds = editPart.getFigure().getBounds().getCopy();
-
- if (editPart.getParent() != null) {
- IFigure figure = ((GraphicalEditPart) editPart.getParent())
- .getFigure();
- if (figure instanceof CSSFigure) {
- CSSFigure cssFigure = (CSSFigure) figure;
- LayoutManager layoutManager = cssFigure.getLayoutManager();
- if (layoutManager instanceof CSSTableLayout2) {
- CSSTableLayout2 tableLayout = (CSSTableLayout2) layoutManager;
- bounds.y = tableLayout.getHSpacing();
- bounds.height = figure.getClientArea().height
- - tableLayout.getHSpacing() * 2;
- }
- }
- }
- bounds = new PrecisionRectangle(bounds.getResized(-1, -1));
- editPart.getFigure().translateToAbsolute(bounds);
- target.translateToRelative(bounds);
+ Rectangle bounds = getAdjustedColumnBoundingRectangle(editPart);
+ target.translateToRelative(bounds);
+ Insets insets = target.getInsets();
bounds.translate(-insets.left, -insets.top);
bounds.resize(insets.getWidth() + 1, insets.getHeight() + 1);
return bounds;
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnResizableEditPolicy.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnResizableEditPolicy.java
index dd11d84d4..7aefa772e 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnResizableEditPolicy.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ColumnResizableEditPolicy.java
@@ -14,10 +14,13 @@ package org.eclipse.jst.pagedesigner.editpolicies;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Locator;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.GraphicalEditPart;
@@ -25,8 +28,13 @@ import org.eclipse.gef.Handle;
import org.eclipse.gef.SharedCursors;
import org.eclipse.gef.handles.MoveHandle;
import org.eclipse.gef.handles.ResizeHandle;
+import org.eclipse.gef.handles.SquareHandle;
+import org.eclipse.gef.tools.DragEditPartsTracker;
import org.eclipse.gef.tools.SelectEditPartTracker;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Image;
import org.w3c.dom.Element;
/**
@@ -44,10 +52,19 @@ public class ColumnResizableEditPolicy extends ElementResizableEditPolicy {
List list = new ArrayList();
GraphicalEditPart part = (GraphicalEditPart) getHost();
- MoveHandle handle = new MoveHandle(part, new ColumnHandleLocator(
- part));
- list.add(handle);
-
+
+ {
+ MoveHandle borderhandle = new MoveHandle(part, new ColumnBorderHandleLocator(
+ part));
+ list.add(borderhandle);
+ }
+
+ {
+ MyMoveHandle cornerHandle = new MyMoveHandle(part, new ColumnHandleLocator(part, getHostFigure(),
+ PositionConstants.NORTH_WEST));
+ list.add(cornerHandle);
+ }
+
SelectEditPartTracker tracker = new SelectEditPartTracker(getHost());
list.add(createHandle(part, PositionConstants.SOUTH_EAST, tracker,
SharedCursors.ARROW));
@@ -72,16 +89,21 @@ public class ColumnResizableEditPolicy extends ElementResizableEditPolicy {
return handle;
}
- private class ColumnHandleLocator implements Locator {
+ private class ColumnHandleLocator extends CornerRelativeHandleLocator {
private GraphicalEditPart editPart;
- public ColumnHandleLocator(GraphicalEditPart editPart) {
+ public ColumnHandleLocator(GraphicalEditPart editPart, IFigure reference, int location) {
+ super(reference, location);
this.editPart = editPart;
}
-
- public void relocate(IFigure target) {
- target.setBounds(ColumnHelper.getColumnBounds(editPart, target));
- }
+
+ protected Dimension getNewTargetSize(IFigure relocateFigure) {
+ return relocateFigure.getPreferredSize();
+ }
+
+ protected Rectangle getCurrentTargetBounds(IFigure relocateFigure) {
+ return ColumnHelper.getColumnBounds(editPart, relocateFigure);
+ }
}
private class ColumnCornerLocator implements Locator {
@@ -144,4 +166,50 @@ public class ColumnResizableEditPolicy extends ElementResizableEditPolicy {
target.setBounds(targetBounds);
}
}
+
+ private class ColumnBorderHandleLocator implements Locator {
+ private GraphicalEditPart editPart;
+
+ public ColumnBorderHandleLocator(GraphicalEditPart editPart) {
+ this.editPart = editPart;
+ }
+
+ public void relocate(IFigure target) {
+ target.setBounds(ColumnHelper.getColumnBounds(editPart, target));
+ }
+ }
+
+ private static class MyMoveHandle extends SquareHandle
+ {
+ public MyMoveHandle(GraphicalEditPart owner, Locator loc) {
+ super(owner, loc);
+ setCursor(SharedCursors.SIZEALL);
+ }
+
+ protected void init() {
+ setPreferredSize(16,16);
+ }
+
+ protected Color getBorderColor() {
+ return ColorConstants.black;
+ }
+
+ protected Color getFillColor() {
+ return ColorConstants.white;
+ }
+
+ protected DragTracker createDragTracker() {
+ DragTracker tracker = new DragEditPartsTracker(getOwner());
+
+ return tracker;
+ }
+
+ public void paintFigure(Graphics graphics) {
+ super.paintFigure(graphics);
+ final Image moveImage = PDPlugin.getDefault().getImage("MoveHandle.png");
+ Point topLeft = getBounds().getTopLeft().getCopy();
+ topLeft.performTranslate(3,3);
+ graphics.drawImage(moveImage, topLeft);
+ }
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/CornerRelativeHandleLocator.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/CornerRelativeHandleLocator.java
index 22fba1aac..43b750b1a 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/CornerRelativeHandleLocator.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/CornerRelativeHandleLocator.java
@@ -52,23 +52,48 @@ class CornerRelativeHandleLocator extends RelativeHandleLocator
}
}
- public void relocate(IFigure target) {
- IFigure reference = getReferenceFigure();
- Rectangle targetBounds = new PrecisionRectangle(getReferenceBox().getResized(-1, -1));
- reference.translateToAbsolute(targetBounds);
- target.translateToRelative(targetBounds);
- //targetBounds.resize(1, 1);
-
- Dimension targetSize = target.getPreferredSize();
-
+ /**
+ * Pass in targetBounds to be updated and newTargetSize. targetBounds will
+ * be applied to the figure that is being relocated immediately after this method
+ * @param targetBounds
+ * @param newTargetSize
+ */
+ protected void relocateBounds(Rectangle targetBounds, Dimension newTargetSize)
+ {
// copied from super.relocate because relativeX/Y are private in super
// changed from super to remove div by 2 that centers target; we want
// it to be corner-to-corner
targetBounds.x
- += (int) ((targetBounds.width+2 * relativeX) + ((targetSize.width+1)*offsetXMultiplier));
+ += (int) (((targetBounds.width+2) * relativeX) + ((newTargetSize.width+1)*offsetXMultiplier));
targetBounds.y
- += (int) (targetBounds.height * relativeY + ((targetSize.height+1)*offsetYMultiplier));
- targetBounds.setSize(targetSize);
+ += (int) (targetBounds.height * relativeY + ((newTargetSize.height+1)*offsetYMultiplier));
+
+ targetBounds.setSize(newTargetSize);
+ }
+
+ /**
+ * @param relocateFigure
+ * @return a modifiable Rectangle that represents the bounds of the figure to be relocated
+ */
+ protected Rectangle getCurrentTargetBounds(IFigure relocateFigure)
+ {
+ IFigure reference = getReferenceFigure();
+ Rectangle targetBounds = new PrecisionRectangle(getReferenceBox().getResized(-1, -1));
+ reference.translateToAbsolute(targetBounds);
+ relocateFigure.translateToRelative(targetBounds);
+ return targetBounds;
+ }
+
+ protected Dimension getNewTargetSize(IFigure relocateFigure)
+ {
+ return relocateFigure.getPreferredSize();
+ }
+
+ public void relocate(IFigure target) {
+ Rectangle targetBounds = getCurrentTargetBounds(target);
+ Dimension targetSize = getNewTargetSize(target);
+ relocateBounds(targetBounds, targetSize);
+
target.setBounds(targetBounds);
}
} \ No newline at end of file
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/DragMoveEditPolicy.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/DragMoveEditPolicy.java
index 732ed045e..3a5a98c0e 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/DragMoveEditPolicy.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/DragMoveEditPolicy.java
@@ -11,15 +11,10 @@
*******************************************************************************/
package org.eclipse.jst.pagedesigner.editpolicies;
-import org.eclipse.draw2d.ColorConstants;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.Label;
-import org.eclipse.draw2d.LineBorder;
-import org.eclipse.draw2d.RectangleFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Insets;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
@@ -31,13 +26,13 @@ import org.eclipse.jst.pagedesigner.commands.MoveNodeCommand;
import org.eclipse.jst.pagedesigner.dom.DOMPositionHelper;
import org.eclipse.jst.pagedesigner.dom.DOMUtil;
import org.eclipse.jst.pagedesigner.dom.IDOMPosition;
-import org.eclipse.jst.pagedesigner.parts.ElementEditPart;
import org.eclipse.jst.pagedesigner.parts.NodeEditPart;
import org.eclipse.jst.pagedesigner.validation.caret.ActionData;
import org.eclipse.jst.pagedesigner.validation.caret.DnDPositionValidator;
import org.eclipse.jst.pagedesigner.validation.caret.IPositionMediator;
+import org.eclipse.jst.pagedesigner.viewer.DefaultDropLocationStrategy;
import org.eclipse.jst.pagedesigner.viewer.DesignPosition;
-import org.eclipse.jst.pagedesigner.viewer.EditPartPositionHelper;
+import org.eclipse.jst.pagedesigner.viewer.IDropLocationStrategy;
import org.eclipse.jst.pagedesigner.viewer.IHTMLGraphicalViewer;
import org.w3c.dom.Node;
@@ -45,19 +40,16 @@ import org.w3c.dom.Node;
* @author mengbo
* @version 1.5
*/
-public class DragMoveEditPolicy extends GraphicalEditPolicy {
- // the amount of vertical offset below the mouse pointer to place
- // the upper left of the drop hint tooltip
- private static final int DROP_HINT_VERTICAL_OFFSET = 20;
- private RectangleFigure _feedbackFigure;
- private Label _dropHintLabel;
+public class DragMoveEditPolicy extends GraphicalEditPolicy implements IDropRequestorProvider
+{
+ private List _feedbackFigures;
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getCommand(org.eclipse.gef.Request)
*/
- public Command getCommand(Request request) {
+ public final Command getCommand(Request request) {
if (!(request instanceof ChangeBoundsRequest)) {
return null;
}
@@ -124,32 +116,108 @@ public class DragMoveEditPolicy extends GraphicalEditPolicy {
return super.getTargetEditPart(request);
}
- DesignPosition findPosition(ChangeBoundsRequest r) {
- IPositionMediator mediator = new DnDPositionValidator(new ActionData(
- ActionData.COMPONENT_MOVE, r.getEditParts()));
- DesignPosition position = EditPartPositionHelper.findEditPartPosition(
- getHost(), r.getLocation(), mediator);
+ protected final DesignPosition findPosition(ChangeBoundsRequest r) {
+ final IPositionMediator mediator = getDropChildValidator(r);
+ final IDropLocationStrategy dropStrategy = createDropLocationStrategy(r);
+ final DesignPosition position =
+ dropStrategy.calculateDesignPosition(getHost(), r.getLocation(), mediator);
+
+ // verify that the drop strategy has honoured it's contract that our
+ // mediator be respected
+ if (position != null)
+ {
+ if (!mediator.isValidPosition(position))
+ {
+ // if our mediator says no go, then veto the requestor
+ // there is no drop location
+ return null;
+ }
+ }
return position;
}
+ /**
+ * @param r
+ * @return the validator to be used to validate the 'request' to drop
+ * the edit parts specified by 'r' into this policy's host edit part
+ * MUST NOT RETURN NULL
+ */
+ protected final IPositionMediator getDropChildValidator(ChangeBoundsRequest r)
+ {
+ IPositionMediator mediator = createDropChildValidator(r);
+
+ if (mediator == null)
+ {
+ mediator = createDefaultDropChildValidator(r);
+ }
+
+ return mediator;
+ }
+
+ /**
+ * @param r
+ * @return a mediator that can validate valid model drops into the
+ * host's edit part
+ */
+ protected IPositionMediator createDropChildValidator(ChangeBoundsRequest r)
+ {
+ // sub-class may override to customize the drop container validator
+ return null;
+ }
+
+ protected final IPositionMediator createDefaultDropChildValidator(ChangeBoundsRequest r)
+ {
+ return new DnDPositionValidator(new ActionData(
+ ActionData.COMPONENT_MOVE, r.getEditParts()));
+ }
+
+ protected final IDropLocationStrategy createDropLocationStrategy(ChangeBoundsRequest r)
+ {
+ List requestingParts = r.getEditParts();
+
+ // TODO: support a composite strategy can collect all requesting parts
+ if (requestingParts.size() == 1)
+ {
+ EditPart requestPart = (EditPart) requestingParts.get(0);
+ IDropRequestorProvider strategyProvider =
+ (IDropRequestorProvider) requestPart.getAdapter(IDropRequestorProvider.class);
+
+ if (strategyProvider != null)
+ {
+ IDropLocationStrategy strategy =
+ strategyProvider.getDropRequestorLocationStrategy(r);
+
+ if (strategy != null)
+ {
+ return strategy;
+ }
+ }
+
+ }
+
+ // by default, return the default strategy
+ return new DefaultDropLocationStrategy(getHost());
+ }
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.editpolicies.AbstractEditPolicy#eraseTargetFeedback(org.eclipse.gef.Request)
*/
- public void eraseTargetFeedback(Request request) {
- if (_feedbackFigure != null)
-// && getFeedbackLayer().getChildren().contains(_feedbackFigure))
+ public final void eraseTargetFeedback(Request request) {
+ if (_feedbackFigures != null)
{
- removeFeedback(_feedbackFigure);
- _feedbackFigure = null;
- }
-
- if (_dropHintLabel != null)
-// && getFeedbackLayer().getChildren().contains(_dropHintLabel))
- {
- removeFeedback(_dropHintLabel);
- _dropHintLabel = null;
+ for (final Iterator it = _feedbackFigures.iterator(); it.hasNext();)
+ {
+ final IFigure figure = (IFigure) it.next();
+
+ if (figure != null)
+ {
+ removeFeedback(figure);
+ }
+ }
+
+ _feedbackFigures.clear();
+ _feedbackFigures = null;
}
}
@@ -158,109 +226,32 @@ public class DragMoveEditPolicy extends GraphicalEditPolicy {
*
* @see org.eclipse.gef.editpolicies.AbstractEditPolicy#showTargetFeedback(org.eclipse.gef.Request)
*/
- public void showTargetFeedback(Request request) {
+ public final void showTargetFeedback(Request request) {
if (request instanceof ChangeBoundsRequest) {
ChangeBoundsRequest r = (ChangeBoundsRequest) request;
-
+
Object type = r.getType();
if (type != REQ_ADD && type != REQ_CLONE
- && type != REQ_MOVE_CHILDREN) {
+ && type != REQ_MOVE_CHILDREN && type != REQ_MOVE) {
return;
}
- //TODO: not used EditPart host = getHost();
- DesignPosition position = findPosition(r);
- if (position != null) {
- Rectangle rect = EditPartPositionHelper
- .convertToAbsoluteCaretRect(position);
- // to avoid enlarge feedback pane.
- rect = rect.intersect(getFeedbackLayer().getBounds());
- showFeedbackRect(rect);
- showDropHintLabel(r.getLocation(), position);
+ DesignPosition position = findPosition(r);
+ if (position != null) {
+ // erase any prior feedback
+ eraseTargetFeedback(request);
+ // add figures to feedback layer and save them in _feedbackFigures
+ // for later.
+ _feedbackFigures = createDropLocationStrategy(r).showTargetFeedback(getHost(), position, r);
}
}
}
- protected RectangleFigure getFeedbackFigure() {
- if (this._feedbackFigure == null) {
- _feedbackFigure = new RectangleFigure();
- _feedbackFigure.setFill(true);
- _feedbackFigure.setOutline(true);
- _feedbackFigure.setLineWidth(1);
- _feedbackFigure.setForegroundColor(ColorConstants.red);
- _feedbackFigure.setBounds(new Rectangle(0, 0, 0, 0));
- _feedbackFigure.setXOR(true);
- addFeedback(_feedbackFigure);
- }
- return _feedbackFigure;
- }
-
- protected void showFeedbackRect(Rectangle rect) {
- RectangleFigure pf = getFeedbackFigure();
- pf.translateToRelative(rect);
- pf.setBounds(rect);
- }
-
- /**
- * Shows a label in a position relative to the drop marker
- * that hints where the new component will be dropped in
- * respect of components already there
- */
- protected void showDropHintLabel(Point mousePosition, DesignPosition position)
+ public IDropLocationStrategy getDropRequestorLocationStrategy(
+ Request request)
{
- if (_dropHintLabel == null){
- _dropHintLabel = new Label();
- _dropHintLabel.setOpaque(true);
- _dropHintLabel.setBackgroundColor(ColorConstants.tooltipBackground);
- _dropHintLabel.setBorder(
- new LineBorder(ColorConstants.black, 1)
- {
- // add an extra pixel of inset to make sure the text
- // isn't pressed against the border
- public Insets getInsets(IFigure figure) {
- return new Insets(getWidth()+1);
- }
- }
- );
- addFeedback(_dropHintLabel);
- }
- final String hintText = getDropHintText(position);
- _dropHintLabel.setText(hintText);
- //TODO: need to handle viewport clipping and adjust label location appropriately
- Dimension hintSize = _dropHintLabel.getPreferredSize();
- Point hintLocation = new Point(mousePosition.x, mousePosition.y+DROP_HINT_VERTICAL_OFFSET);
-
- Rectangle hintRect = new Rectangle(hintLocation, hintSize);
-
- // to avoid enlarge feedback pane.
- //hintRect = hintRect.intersect(getFeedbackLayer().getBounds());
- _dropHintLabel.setBounds(hintRect);
- }
-
- private String getDropHintText(DesignPosition position)
- {
- StringBuffer buffer = new StringBuffer("Place");
-
- EditPart prevPart = position.getSiblingEditPart(false);
- EditPart nextPart = position.getSiblingEditPart(true);
-
- if (nextPart instanceof ElementEditPart)
- {
- buffer.append(" before ");
- buffer.append(((ElementEditPart)nextPart).getTagConvert().getHostElement().getNodeName());
- buffer.append(",");
- }
-
- if (prevPart instanceof ElementEditPart)
- {
- buffer.append(" after ");
- buffer.append(((ElementEditPart)prevPart).getTagConvert().getHostElement().getNodeName());
- buffer.append(",");
- }
-
- buffer.append(" inside ");
- buffer.append(position.getContainerNode().getNodeName());
-
- return buffer.toString();
+ // by default, always return null. Sub-classes should override
+ // to customize their drop request strategy
+ return null;
}
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementMenuBar.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementMenuBar.java
index c6209073e..9471782ad 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementMenuBar.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementMenuBar.java
@@ -71,6 +71,23 @@ public class ElementMenuBar extends Figure implements ISelectionProvider, ISelec
add(editpart.getFigure());
getChildParts().add(editpart);
}
+
+ /**
+ * Removes editpart from the list of non-visual edit parts that this menu
+ * bar is managing the visuals for.
+ * @param editpart
+ * @throws IllegalArgumentException if editpart is not currently managed
+ * by the menu bar
+ */
+ public void removeNonVisualChild(final NonVisualComponentEditPart editpart)
+ {
+ if (!getChildParts().remove(editpart))
+ {
+ throw new IllegalArgumentException("editpart is not a child: "+editpart);
+ }
+
+ remove(editpart.getFigure());
+ }
public boolean hasEditPartFocus()
{
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementResizableEditPolicy.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementResizableEditPolicy.java
index 7cfc6933e..81f098118 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementResizableEditPolicy.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/ElementResizableEditPolicy.java
@@ -25,6 +25,7 @@ import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.LayerConstants;
@@ -46,7 +47,10 @@ import org.eclipse.jst.pagedesigner.dom.EditModelQuery;
import org.eclipse.jst.pagedesigner.parts.ElementEditPart;
import org.eclipse.jst.pagedesigner.parts.NodeEditPart;
import org.eclipse.jst.pagedesigner.requests.LocationModifierRequest;
+import org.eclipse.jst.pagedesigner.tools.ObjectModeDragTracker;
+import org.eclipse.jst.pagedesigner.tools.RangeDragTracker;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Cursor;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -55,7 +59,8 @@ import org.w3c.dom.Node;
* @author mengbo
* @version 1.5
*/
-public class ElementResizableEditPolicy extends ResizableEditPolicy {
+public class ElementResizableEditPolicy extends ResizableEditPolicy implements IEnhancedSelectionEditPolicy
+{
private static final Insets INSETS_1 = new Insets(1, 1, 1, 1);
private static final int THRESHHOLD = 3;
@@ -435,4 +440,32 @@ public class ElementResizableEditPolicy extends ResizableEditPolicy {
feedback.translateToRelative(rect);
feedback.setBounds(rect);
}
+
+ public Cursor getSelectionToolCursor(Point mouseLocation) {
+ // by default return null to indicate system default.
+ // sub-classes should override to customize
+ return null;
+ }
+
+ protected DragTracker getSelectionTracker(LocationRequest request)
+ {
+ // by default, return null
+ // sub-classes should override to customize
+ return null;
+ }
+
+ public DragTracker getSelectionDragTracker(LocationRequest request)
+ {
+ if (org.eclipse.jst.pagedesigner.requests.PageDesignerRequestConstants.REQ_SELECTION_TRACKER.equals(request.getType())){
+ return getSelectionTracker(request);
+ }
+
+ // be default don't specify a selection drag tracker
+ // sub-classes should override to customize
+ if (shouldUseObjectMode(request)) {
+ return new ObjectModeDragTracker(getHost());
+ }
+ return new RangeDragTracker(getHost());
+
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/IDropRequestorProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/IDropRequestorProvider.java
new file mode 100644
index 000000000..144c3753b
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/IDropRequestorProvider.java
@@ -0,0 +1,22 @@
+package org.eclipse.jst.pagedesigner.editpolicies;
+
+import org.eclipse.gef.Request;
+import org.eclipse.jst.pagedesigner.viewer.IDropLocationStrategy;
+
+/**
+ * A type of provider that can provide request information for an edit part
+ * when it is being dropped into an arbitrary location
+ *
+ * @author cbateman
+ *
+ */
+public interface IDropRequestorProvider
+{
+ /**
+ * @param request
+ * @return a drop location strategy that may be used with 'request' that
+ * will help calculate validate drop locations for this policy's host
+ * edit part, or null if no such strategy exists
+ */
+ IDropLocationStrategy getDropRequestorLocationStrategy(Request request);
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/IEnhancedSelectionEditPolicy.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/IEnhancedSelectionEditPolicy.java
new file mode 100644
index 000000000..1115d819c
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editpolicies/IEnhancedSelectionEditPolicy.java
@@ -0,0 +1,32 @@
+package org.eclipse.jst.pagedesigner.editpolicies;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.DragTracker;
+import org.eclipse.gef.requests.LocationRequest;
+import org.eclipse.swt.graphics.Cursor;
+
+/**
+ * Allows a selection edit policy to specify extra capabilities
+ *
+ * @author cbateman
+ */
+public interface IEnhancedSelectionEditPolicy
+{
+ /**
+ * @return the cursor that should be displayed when a selection tool
+ * enters the hit box (mouses over) of an edit part but no selection
+ * or drag operations have occurred yet. Null indicates the caller should
+ * use whatever default it deems appropriate.
+ */
+ Cursor getSelectionToolCursor(Point mouseLocation);
+
+ /**
+ * @param mouseLocator
+ * @return a drag tracker to be used when the mouse moves over a certain
+ * location and mouse state is in initial state or null if the policy
+ * doesn't wish to customize this. This allows an edit part
+ * to customize what drag tracker is used depending on where the mouse is positioned
+ * on its figure.
+ */
+ DragTracker getSelectionDragTracker(LocationRequest request);
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/ElementEditPart.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/ElementEditPart.java
index 3a2f1980c..216d187f5 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/ElementEditPart.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/ElementEditPart.java
@@ -18,11 +18,13 @@ import java.util.List;
import java.util.Map;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
+import org.eclipse.gef.requests.LocationRequest;
import org.eclipse.gef.tools.DragEditPartsTracker;
import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;
import org.eclipse.jst.pagedesigner.PDPlugin;
@@ -37,17 +39,18 @@ import org.eclipse.jst.pagedesigner.css2.style.AbstractStyle;
import org.eclipse.jst.pagedesigner.css2.widget.HiddenProvider;
import org.eclipse.jst.pagedesigner.editpolicies.ElementMenuBar;
import org.eclipse.jst.pagedesigner.editpolicies.ElementResizableEditPolicy;
+import org.eclipse.jst.pagedesigner.editpolicies.IEnhancedSelectionEditPolicy;
import org.eclipse.jst.pagedesigner.elementedit.ElementEditFactoryRegistry;
import org.eclipse.jst.pagedesigner.elementedit.IElementEdit;
import org.eclipse.jst.pagedesigner.figurehandler.FigureFactory;
import org.eclipse.jst.pagedesigner.figurehandler.IFigureHandler;
import org.eclipse.jst.pagedesigner.jsp.core.IJSPCoreConstants;
import org.eclipse.jst.pagedesigner.range.RangeUtil;
-import org.eclipse.jst.pagedesigner.tools.ObjectModeDragTracker;
-import org.eclipse.jst.pagedesigner.tools.RangeDragTracker;
+import org.eclipse.jst.pagedesigner.requests.PageDesignerRequestConstants;
import org.eclipse.jst.pagedesigner.utils.CMUtil;
import org.eclipse.jst.pagedesigner.viewer.DesignRange;
import org.eclipse.jst.pagedesigner.viewer.IHTMLGraphicalViewer;
+import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
@@ -88,16 +91,23 @@ public class ElementEditPart extends SubNodeEditPart {
*
* @see org.eclipse.jst.pagedesigner.parts.NodeEditPart#getDragTracker(org.eclipse.gef.Request)
*/
- public DragTracker getDragTracker(Request request) {
- EditPolicy policy = this
- .getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
- if (policy instanceof ElementResizableEditPolicy) {
- if (((ElementResizableEditPolicy) policy)
- .shouldUseObjectMode(request)) {
- return new ObjectModeDragTracker(this);
- }
- return new RangeDragTracker(this);
- }
+ public DragTracker getDragTracker(Request request)
+ {
+ EditPolicy policy = this
+ .getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
+
+ if (PageDesignerRequestConstants.REQ_SELECTION_TRACKER.equals(request.getType())
+ || org.eclipse.gef.RequestConstants.REQ_SELECTION.equals(request.getType()))
+ {
+ if (policy instanceof IEnhancedSelectionEditPolicy
+ && request instanceof LocationRequest)
+ {
+ return ((IEnhancedSelectionEditPolicy)policy).getSelectionDragTracker((LocationRequest)request);
+ }
+
+ return null;
+ }
+
// should not happen
return new DragEditPartsTracker(this);
}
@@ -510,8 +520,13 @@ public class ElementEditPart extends SubNodeEditPart {
parent.remove(childFigure);
}
+
+ if (childEditPart instanceof NonVisualComponentEditPart)
+ {
+ _nonVisualElementBar.removeNonVisualChild((NonVisualComponentEditPart) childEditPart);
+ }
// this only applies to visual edit parts
- if (! (childEditPart instanceof NonVisualComponentEditPart))
+ else
{
// de-link style
Node childNode = (Node) childEditPart.getModel();
@@ -596,4 +611,17 @@ public class ElementEditPart extends SubNodeEditPart {
_nonVisualElementBar = null;
}
}
+
+ public Cursor getCursor(Point mouseLocation) {
+ // let the selection edit policy dictate
+ EditPolicy editPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
+
+ if (editPolicy instanceof IEnhancedSelectionEditPolicy)
+ {
+ return ((IEnhancedSelectionEditPolicy)editPolicy).getSelectionToolCursor(mouseLocation);
+ }
+ return super.getCursor(mouseLocation);
+ }
+
+
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NodeEditPart.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NodeEditPart.java
index 9b71377f7..e717a15c2 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NodeEditPart.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NodeEditPart.java
@@ -12,6 +12,7 @@
package org.eclipse.jst.pagedesigner.parts;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
@@ -22,9 +23,12 @@ import org.eclipse.gef.requests.LocationRequest;
import org.eclipse.jst.pagedesigner.dnd.LocalDropRequest;
import org.eclipse.jst.pagedesigner.dnd.internal.LocalDropEditPolicy;
import org.eclipse.jst.pagedesigner.editpolicies.DragMoveEditPolicy;
+import org.eclipse.jst.pagedesigner.editpolicies.IDropRequestorProvider;
import org.eclipse.jst.pagedesigner.itemcreation.ItemCreationEditPolicy;
import org.eclipse.jst.pagedesigner.itemcreation.ItemCreationRequest;
import org.eclipse.jst.pagedesigner.tools.RangeDragTracker;
+import org.eclipse.jst.pagedesigner.viewer.IDropLocationStrategy;
+import org.eclipse.swt.graphics.Cursor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
@@ -36,7 +40,7 @@ import org.w3c.dom.Node;
* @author mengbo
*/
public abstract class NodeEditPart extends AbstractGraphicalEditPart implements
- INodeAdapter {
+ INodeAdapter, IDropRequestorProvider {
private IDOMDocument _destDocument;
private boolean _isDragActive;
@@ -134,6 +138,11 @@ public abstract class NodeEditPart extends AbstractGraphicalEditPart implements
.getAdapterFor(IPropertySource.class);
}
}
+ else if (IDropRequestorProvider.class.equals(key))
+ {
+ // I am my own drop requestor
+ return this;
+ }
if (obj instanceof IAdaptable) {
Object ret = ((IAdaptable) obj).getAdapter(key);
@@ -198,4 +207,40 @@ public abstract class NodeEditPart extends AbstractGraphicalEditPart implements
{
_isDragActive = newValue;
}
+
+ /**
+ * @param defaultCursor
+ * @return this edit part's cursor or null if this edit part
+ * does not wish to specify a specific cursor (the default
+ * should be used).
+ * Note that this is only called when no drag tracker is active,
+ * when the mouse enters the edit part with the RangeSelectionTool
+ * and the current state is INITIAL. This allows the editpart to
+ * specify a custom mouse-over tool cursor
+ * TODO: perhaps getCursor is not a specific enough a name
+ */
+ public Cursor getCursor(Point mouseLocation)
+ {
+ return null;
+ }
+
+ /**
+ * @param request
+ * @return a drop location strategy to determine drop locations for this edit part
+ * when it is the part being dropped (drop requestor).
+ */
+ public IDropLocationStrategy getDropRequestorLocationStrategy(Request request)
+ {
+ // by default query the primary drag role policy
+ EditPolicy dragRolePolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+
+ if (dragRolePolicy instanceof IDropRequestorProvider)
+ {
+ return ((IDropRequestorProvider)dragRolePolicy).getDropRequestorLocationStrategy(request);
+ }
+
+ // if our edit policy doesn't support it, return null to indicate
+ // we have no strategy
+ return null;
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NonVisualComponentEditPart.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NonVisualComponentEditPart.java
index 87b4b5bc0..1ab086921 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NonVisualComponentEditPart.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/NonVisualComponentEditPart.java
@@ -45,6 +45,8 @@ public class NonVisualComponentEditPart extends NodeEditPart
super.createEditPolicies();
installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE
, new NonVisualChildGraphicalEditPolicy());
+ installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
+ null);
}
protected ITagConverter getTagConverter()
@@ -65,5 +67,11 @@ public class NonVisualComponentEditPart extends NodeEditPart
public Node getDOMNode() {
return getModelElement();
}
-
+
+// public DragTracker getDragTracker(Request request) {
+// // TODO: need to define drag semantics for these
+// // Also, right now edit part dragging causes bad behaviour
+// // in the non-visual decorator
+// return null;//new ObjectModeDragTracker(this);
+// }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/TextEditPart.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/TextEditPart.java
index b01b6558c..dc4ec9dc4 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/TextEditPart.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/TextEditPart.java
@@ -12,7 +12,9 @@
package org.eclipse.jst.pagedesigner.parts;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
+import org.eclipse.gef.SharedCursors;
import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
import org.eclipse.jst.pagedesigner.css2.layout.CSSTextFigure;
import org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure;
@@ -24,6 +26,7 @@ import org.eclipse.jst.pagedesigner.range.RangeUtil;
import org.eclipse.jst.pagedesigner.utils.HTMLUtil;
import org.eclipse.jst.pagedesigner.viewer.DesignRange;
import org.eclipse.jst.pagedesigner.viewer.IHTMLGraphicalViewer;
+import org.eclipse.swt.graphics.Cursor;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
@@ -171,6 +174,14 @@ public class TextEditPart extends SubNodeEditPart implements ICSSTextProvider {
}
public boolean isSelectable() {
- return false;
+ // controls, amongst other things, whether or not a standard
+ // hit test in SelectionTool for mouse over will find this edit part
+ return true;
}
+
+ public Cursor getCursor(Point mouseLocation) {
+ return SharedCursors.IBEAM;
+ }
+
+
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/requests/PageDesignerRequestConstants.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/requests/PageDesignerRequestConstants.java
new file mode 100644
index 000000000..5747dac9f
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/requests/PageDesignerRequestConstants.java
@@ -0,0 +1,14 @@
+package org.eclipse.jst.pagedesigner.requests;
+
+public final class PageDesignerRequestConstants
+{
+ /**
+ * sent to an edit part to request a selection drag tracker
+ */
+ public final static String REQ_SELECTION_TRACKER = "selection.tracker.request";
+
+ private PageDesignerRequestConstants()
+ {
+ // no instantiation
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeDragTracker.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeDragTracker.java
index 26fceee26..162c499a0 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeDragTracker.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeDragTracker.java
@@ -13,6 +13,7 @@ package org.eclipse.jst.pagedesigner.tools;
import java.util.Collections;
+import org.eclipse.draw2d.Cursors;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.RequestConstants;
@@ -59,10 +60,17 @@ public class RangeDragTracker extends TargetingTool implements DragTracker {
* @see org.eclipse.gef.tools.AbstractTool#calculateCursor()
*/
protected Cursor calculateCursor() {
- if (isInState(STATE_INITIAL | STATE_DRAG | STATE_ACCESSIBLE_DRAG)) {
- return getDefaultCursor();
- }
- return super.calculateCursor();
+ return Cursors.IBEAM;
+// if (isInState(STATE_INITIAL))
+// {
+// return Cursors.IBEAM;
+// }
+// else if (isInState(STATE_DRAG | STATE_ACCESSIBLE_DRAG))
+// {
+// return getDefaultCursor();
+// }
+// return Cursors.IBEAM;
+// return super.calculateCursor();
}
/**
@@ -297,4 +305,10 @@ public class RangeDragTracker extends TargetingTool implements DragTracker {
.updateHorizontalPos();
}
}
+
+ protected boolean handleHover() {
+ boolean retValue = super.handleHover();
+ refreshCursor();
+ return retValue;
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeSelectionTool.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeSelectionTool.java
index 4cb63ed80..c5da84606 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeSelectionTool.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/tools/RangeSelectionTool.java
@@ -11,6 +11,8 @@
*******************************************************************************/
package org.eclipse.jst.pagedesigner.tools;
+import org.eclipse.gef.DragTracker;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.commands.Command;
@@ -38,6 +40,7 @@ import org.eclipse.jst.pagedesigner.viewer.HTMLGraphicalViewer;
import org.eclipse.jst.pagedesigner.viewer.IHTMLGraphicalViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.graphics.Cursor;
/**
* @author mengbo
@@ -181,15 +184,6 @@ public class RangeSelectionTool extends SelectionTool
return false;
}
- /**
- * @param e
- * @return
- */
- protected boolean handleObjectModeKeyDown(KeyEvent e) {
- // TODO Auto-generated method stub
- return false;
- }
-
// /**
// * @param e
// * @return
@@ -297,6 +291,54 @@ public class RangeSelectionTool extends SelectionTool
}
super.showHoverFeedback();
}
-
-
+
+ // TODO : this method is for debug purposes and should
+ // be removed in production
+// protected boolean updateTargetUnderMouse() {
+// EditPart editPart = getTargetEditPart();
+// boolean retValue = super.updateTargetUnderMouse();
+// if (getTargetEditPart() != editPart)
+// {
+// System.out.println("New target editpart: "+getTargetEditPart()+" Old edit part: "+editPart);
+// }
+// return retValue;
+// }
+
+ protected boolean handleMove() {
+ boolean handled = super.handleMove();
+ EditPart targetEditPart = getTargetEditPart();
+
+ if (isInState(STATE_INITIAL)
+ && targetEditPart instanceof NodeEditPart)
+ {
+ LocationRequest request = new LocationRequest(org.eclipse.jst.pagedesigner.requests.PageDesignerRequestConstants.REQ_SELECTION_TRACKER);
+ request.setLocation(getLocation());
+ DragTracker selectionTracker = targetEditPart.getDragTracker(request);
+ setDragTracker(selectionTracker);
+ }
+
+ return handled;
+ }
+
+ protected Cursor calculateCursor() {
+ EditPart targetEditPart = getTargetEditPart();
+ if (isInState(STATE_INITIAL)
+ && targetEditPart instanceof NodeEditPart)
+ {
+ final Cursor nodeCursor =
+ ((NodeEditPart)targetEditPart).getCursor(getLocation());
+
+ // if the edit part specified a custom cursor and there is no
+ // active drag tracker (which would otherwise manage cursor)
+ // then set the custom cursor
+ // if we fall-through, the default behaviour will be used
+ if (nodeCursor != null
+ && getDragTracker() == null)
+ {
+ return nodeCursor;
+ }
+ }
+ // otherwise, use super's defaults
+ return super.calculateCursor();
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/ActionData.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/ActionData.java
index 252c5db00..5a6e93cf5 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/ActionData.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/ActionData.java
@@ -12,9 +12,9 @@
package org.eclipse.jst.pagedesigner.validation.caret;
/**
- * This method represents the an user action, the 'data' could be any related
+ * This method represents a user action, the 'data' could be any related
* data that will be referenced later in the action processing. For example.
- * when user do DnD, the localData will be referenced as _data.
+ * when user does a DnD, the localData will be referenced as _data.
*
* @author mengbo
*/
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionRule.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionRule.java
index 70987e8a5..3e3b02c0a 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionRule.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionRule.java
@@ -31,7 +31,7 @@ public class DefaultPositionRule implements IPositionRule {
public DefaultPositionRule(IPositionMediator mediator, ActionData actionData) {
super();
_mediator = mediator;
- if (_actionData != null) {
+ if (actionData != null) {
_actionData = actionData;
} else {
_actionData = new ActionData(ActionData.UNKNOWN, new Object());
@@ -92,16 +92,16 @@ public class DefaultPositionRule implements IPositionRule {
}
return result;
}
-
- /**
- * @param host
- * @param tagName
- * @return
- */
- public static boolean isWidget(EditPart host) {
- if (host instanceof NodeEditPart) {
- return ((NodeEditPart) host).isWidget();
- }
+
+ /**
+ * @param host
+ * @param tagName
+ * @return
+ */
+ public static boolean isWidget(EditPart host) {
+ if (host instanceof NodeEditPart) {
+ return ((NodeEditPart) host).isWidget();
+ }
return false;
- }
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionValidator.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionValidator.java
index eb1530005..141310dd4 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionValidator.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DefaultPositionValidator.java
@@ -12,6 +12,7 @@
package org.eclipse.jst.pagedesigner.validation.caret;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.gef.EditPart;
@@ -30,7 +31,7 @@ import org.w3c.dom.Node;
public class DefaultPositionValidator implements IPositionMediator {
private List _rules = new ArrayList();
- ActionData _actionData;
+ protected final ActionData _actionData;
/**
* @return Returns the _actionData.
@@ -49,26 +50,18 @@ public class DefaultPositionValidator implements IPositionMediator {
protected void initRules() {
_rules.clear();
- _rules.add(new BasicPositionRule(this, _actionData));
- _rules.add(new IETablePositionRule(this, _actionData));
- _rules.add(new RootContainerPositionRule(this, _actionData));
- _rules.add(new JSFRootContainerPositionRule(this, _actionData));
- _rules.add(new WhitespacePositionMoveRule(this, _actionData));
+ addRule(new BasicPositionRule(this, _actionData));
+ addRule(new IETablePositionRule(this, _actionData));
+ addRule(new RootContainerPositionRule(this, _actionData));
+ addRule(new JSFRootContainerPositionRule(this, _actionData));
+ addRule(new WhitespacePositionMoveRule(this, _actionData));
}
/**
* @return Returns the _rules.
*/
public List getRules() {
- return _rules;
- }
-
- /**
- * @param _rules
- * The _rules to set.
- */
- protected void setRules(List rules) {
- _rules = rules;
+ return Collections.unmodifiableList(_rules);
}
protected void addRule(IValidationRule rule) {
@@ -131,6 +124,7 @@ public class DefaultPositionValidator implements IPositionMediator {
* @see org.eclipse.jst.pagedesigner.caret.IValidator#isValidPosition(org.eclipse.jst.pagedesigner.dom.IDOMPosition)
*/
public boolean isValidPosition(IDOMPosition position) {
+ // if position is really a IDOMRefPosition, convert it to DOMPosition
position = EditHelper.ensureDOMPosition(position);
boolean refLeft = true, refRight = true, result = true;
if (position == null) {
@@ -139,13 +133,23 @@ public class DefaultPositionValidator implements IPositionMediator {
List rules = getRules();
for (int i = 0, n = rules.size(); i < n; i++) {
Object rule = rules.get(i);
+
+ // rule may be an IValidationRule that is not a position rule
+ // so only use those that are actually position rules
if (rule instanceof IPositionRule) {
- // editable?
+ // the IDOMPosition represents a position somewhere in a parent
+ // node based on a node list index. We need to verify that the
+ // parent is editable.
result &= ((IPositionRule) rule).isEditable(new Target(position
.getContainerNode()));
if (result) {
if (!position.isText()) {
+ // TODO C.B: no sure what the point is here. It appears
+ // as though it is validating whether the sibling either
+ // side of this position is a valid location for this
+ // action
+
// ref1?
Node node = EditModelQuery.getInstance().getSibling(
position, true);
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DnDPositionValidator.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DnDPositionValidator.java
index d011d84dd..6fddc522a 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DnDPositionValidator.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/DnDPositionValidator.java
@@ -30,4 +30,14 @@ public class DnDPositionValidator extends DefaultPositionValidator {
public DnDPositionValidator(ActionData actionData) {
super(actionData);
}
+
+ /**
+ * Override to make adding rules public on Dnd validators
+ */
+ public void addRule(IValidationRule rule)
+ {
+ super.addRule(rule);
+ }
+
+
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/JSFRootContainerPositionRule.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/JSFRootContainerPositionRule.java
index 8c957287f..8ae731d4b 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/JSFRootContainerPositionRule.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/validation/caret/JSFRootContainerPositionRule.java
@@ -158,8 +158,12 @@ public class JSFRootContainerPositionRule extends DefaultPositionRule {
public boolean canReference(Target target, boolean atRight) {
Node node = target.getNode();
if (node.getLocalName() != null) {
+ // if the local name of the target is in the list of JSF root
+ // containers
if (Arrays.asList(JSF_ROOT_CONTAINERS).contains(
node.getLocalName().toLowerCase())) {
+
+ // verify that either the target is
return EditModelQuery.isChild(
RootContainerPositionRule.HTML_ROOT_CONTAINERS, node,
false, false)
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/AbstractDropLocationStrategy.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/AbstractDropLocationStrategy.java
new file mode 100644
index 000000000..c0d4cf65a
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/AbstractDropLocationStrategy.java
@@ -0,0 +1,30 @@
+package org.eclipse.jst.pagedesigner.viewer;
+
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.jst.pagedesigner.validation.caret.IPositionMediator;
+
+/**
+ * Abstract parent of all concrete client implmentation of IDropLocationStrategy's
+ * Clients should sub-class instead of implementing {@link IDropLocationStrategy} directly
+ * to avoid future API breakage
+ *
+ * @author cbateman
+ *
+ */
+public abstract class AbstractDropLocationStrategy extends GraphicalEditPolicy implements IDropLocationStrategy
+{
+ public AbstractDropLocationStrategy(EditPart host)
+ {
+ setHost(host);
+ }
+
+ public abstract DesignPosition calculateDesignPosition(EditPart host, Point p,
+ IPositionMediator validator);
+
+ public abstract List showTargetFeedback(EditPart host, DesignPosition position, ChangeBoundsRequest request);
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/DefaultDropLocationStrategy.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/DefaultDropLocationStrategy.java
new file mode 100644
index 000000000..ad924d17f
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/DefaultDropLocationStrategy.java
@@ -0,0 +1,143 @@
+package org.eclipse.jst.pagedesigner.viewer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.LineBorder;
+import org.eclipse.draw2d.RectangleFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Insets;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.jst.pagedesigner.parts.ElementEditPart;
+import org.eclipse.jst.pagedesigner.validation.caret.IPositionMediator;
+
+public class DefaultDropLocationStrategy extends AbstractDropLocationStrategy
+{
+ // the amount of vertical offset below the mouse pointer to place
+ // the upper left of the drop hint tooltip
+ private static final int DROP_HINT_VERTICAL_OFFSET = 20;
+
+ public DefaultDropLocationStrategy(EditPart host) {
+ super(host);
+ }
+
+ public DesignPosition calculateDesignPosition(EditPart host, Point p,
+ IPositionMediator validator) {
+ return EditPartPositionHelper.findEditPartPosition(
+ host, p, validator);
+ }
+
+ public List showTargetFeedback(EditPart host, DesignPosition position, ChangeBoundsRequest request)
+ {
+
+ List feedback = new ArrayList(4);
+ feedback.add(showFeedbackRect(createCaretBounds(position)));
+ feedback.add(showDropHintLabel(request.getLocation(), position));
+
+ return feedback;
+ }
+
+
+
+ protected final RectangleFigure showFeedbackRect(Rectangle rect) {
+ RectangleFigure pf = createFeedbackFigure();
+ pf.translateToRelative(rect);
+ pf.setBounds(rect);
+ return pf;
+ }
+
+ protected Rectangle createCaretBounds(DesignPosition position)
+ {
+ Rectangle rect = EditPartPositionHelper
+ .convertToAbsoluteCaretRect(position);
+
+ // to avoid enlarge feedback pane.
+ rect = rect.intersect(getFeedbackLayer().getBounds());
+
+ return rect;
+ }
+
+ protected RectangleFigure createFeedbackFigure()
+ {
+ RectangleFigure feedbackFigure = new RectangleFigure();
+ feedbackFigure.setFill(true);
+ feedbackFigure.setOutline(true);
+ feedbackFigure.setLineWidth(1);
+ feedbackFigure.setForegroundColor(ColorConstants.red);
+ feedbackFigure.setBounds(new Rectangle(0, 0, 0, 0));
+ feedbackFigure.setXOR(true);
+ addFeedback(feedbackFigure);
+ return feedbackFigure;
+ }
+
+ /**
+ * Shows a label in a position relative to the drop marker
+ * that hints where the new component will be dropped in
+ * respect of components already there
+ */
+ protected final Label showDropHintLabel(Point mousePosition, DesignPosition position)
+ {
+ Label dropHintLabel = new Label();
+ dropHintLabel.setOpaque(true);
+ dropHintLabel.setBackgroundColor(ColorConstants.tooltipBackground);
+ dropHintLabel.setBorder(
+ new LineBorder(ColorConstants.black, 1)
+ {
+ // add an extra pixel of inset to make sure the text
+ // isn't pressed against the border
+ public Insets getInsets(IFigure figure) {
+ return new Insets(getWidth()+1);
+ }
+ }
+ );
+ addFeedback(dropHintLabel);
+
+ final String hintText = getDropHintText(position);
+ dropHintLabel.setText(hintText);
+ //TODO: need to handle viewport clipping and adjust label location appropriately
+ Dimension hintSize = dropHintLabel.getPreferredSize();
+ Point hintLocation = new Point(mousePosition.x, mousePosition.y+DROP_HINT_VERTICAL_OFFSET);
+
+ Rectangle hintRect = new Rectangle(hintLocation, hintSize);
+
+ // to avoid enlarge feedback pane.
+ //hintRect = hintRect.intersect(getFeedbackLayer().getBounds());
+ dropHintLabel.translateToRelative(hintRect);
+ dropHintLabel.setBounds(hintRect);
+
+ return dropHintLabel;
+ }
+
+ protected String getDropHintText(DesignPosition position)
+ {
+ StringBuffer buffer = new StringBuffer("Place");
+
+ EditPart prevPart = position.getSiblingEditPart(false);
+ EditPart nextPart = position.getSiblingEditPart(true);
+
+ if (nextPart instanceof ElementEditPart)
+ {
+ buffer.append(" before ");
+ buffer.append(((ElementEditPart)nextPart).getTagConvert().getHostElement().getNodeName());
+ buffer.append(",");
+ }
+
+ if (prevPart instanceof ElementEditPart)
+ {
+ buffer.append(" after ");
+ buffer.append(((ElementEditPart)prevPart).getTagConvert().getHostElement().getNodeName());
+ buffer.append(",");
+ }
+
+ buffer.append(" inside ");
+ buffer.append(position.getContainerNode().getNodeName());
+
+ return buffer.toString();
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/EditPartPositionHelper.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/EditPartPositionHelper.java
index 2e7101b3d..f2c266083 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/EditPartPositionHelper.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/EditPartPositionHelper.java
@@ -484,12 +484,12 @@ public class EditPartPositionHelper {
* @param box
* @return
*/
- public static Rectangle getBoxBounds(IFigure figure, FlowBox box) {
- Rectangle r = new Rectangle(box._x, box._y, box.getWidth(), box
- .getHeight());
- figure.translateToAbsolute(r);
- return r;
- }
+// public static Rectangle getBoxBounds(IFigure figure, FlowBox box) {
+// Rectangle r = new Rectangle(box._x, box._y, box.getWidth(), box
+// .getHeight());
+// figure.translateToAbsolute(r);
+// return r;
+// }
/**
* @param child
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/IDropLocationStrategy.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/IDropLocationStrategy.java
new file mode 100644
index 000000000..b07eaf58c
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/viewer/IDropLocationStrategy.java
@@ -0,0 +1,47 @@
+package org.eclipse.jst.pagedesigner.viewer;
+
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.jst.pagedesigner.validation.caret.IPositionMediator;
+
+/**
+ * A strategy used to determine the closest validt drop location given
+ * a current position.
+ *
+ * Note: clients should not implement or sub-class this interface. Instead,
+ * sub-class AbstractDropLocationStrategy.
+ * @author cbateman
+ *
+ */
+public interface IDropLocationStrategy
+{
+ /**
+ * @param host
+ * @param p
+ * @param validator
+ * @return the closest valid design positionn to p, starting from host
+ * that is valid based on validator, or null if there is no such position
+ * (drop not valid). validator.isValidPosition must be honoured.
+ */
+ DesignPosition calculateDesignPosition(EditPart host, Point p, IPositionMediator validator);
+
+ /**
+ * May choose to contribute target feedback given a target part host and given
+ * the proposed drops location given by position
+ *
+ * @param position
+ * @return must contain all IFigure objects that were added to the feedback layer by
+ * this call. Once returned, these IFigure's must not be kept as state information
+ * by the strategy because they may be manipulated at any after return by the caller.
+ * This includes erasing them from the feedback layer. List must be modifiable by
+ * the caller.
+ *
+ * Note: most feedback in Draw2D requires that it is added to the feedback layer
+ * before it can be fully initialized, which is why this call adds feedback and then
+ * returns it. The caller is responsible for erasing the figures in the list.
+ */
+ List showTargetFeedback(EditPart host, DesignPosition position, ChangeBoundsRequest request);
+}

Back to the top