Author: yradtsevich
Date: 2010-04-01 09:30:15 -0400 (Thu, 01 Apr 2010)
New Revision: 21188
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggablePattern.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5042
Enhance DnD support in VPE:
- Now the element being dragged is shown in Drag&Drop session.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggablePattern.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggablePattern.java 2010-04-01
12:50:02 UTC (rev 21187)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggablePattern.java 2010-04-01
13:30:15 UTC (rev 21188)
@@ -17,7 +17,6 @@
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerVpeUtils;
import org.mozilla.interfaces.nsIDOMCSSStyleDeclaration;
import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMElementCSSInlineStyle;
import org.mozilla.interfaces.nsIDOMMouseEvent;
import org.mozilla.interfaces.nsIDOMNode;
@@ -28,22 +27,32 @@
*/
public class DraggablePattern {
private static final String DRAGGING_OPACITY = "0.5"; //$NON-NLS-1$
+ private static final int ICON_HEIGHT = 20;
private static final String DRAG_ICON_ID = "dragIcon"; //$NON-NLS-1$
private static final String DRAG_ICON_FILE = "dragIcon.gif"; //$NON-NLS-1$
- private static final String DEFAULT_DISPLAY = ""; //$NON-NLS-1$
- private static final String NONE_DISPLAY = "none"; //$NON-NLS-1$
private static final String ABSOLUTE_POSITION = "absolute"; //$NON-NLS-1$
private static final String IMPORTANT_PRIORITY = "important"; //$NON-NLS-1$
- private static final String DEFAULT_PRIORITY = ""; //$NON-NLS-1$
- private static final String DRAG_ICON_STYLE
- = "display:none; position: absolute; cursor: move"; //$NON-NLS-1$
+
+ /** @see #getTransparentDiv() */
+ private static final String TRANSPARENT_DIV_ID = "transparentDragDiv";
//$NON-NLS-1$
+ /** @see #getTransparentDiv() */
+ private static final int TRANSPARENT_DIV_SIZE = 360;
+ /** @see #getTransparentDiv() */
+ private static final String TRANSPARENT_DIV_STYLE
+ = "background-color: rgba(255, 0, 0, 0.0);" //$NON-NLS-1$
+ + "height:"+TRANSPARENT_DIV_SIZE+"px;"//$NON-NLS-1$//$NON-NLS-2$
+ + "width:"+TRANSPARENT_DIV_SIZE+"px;" //$NON-NLS-1$//$NON-NLS-2$
+ + "position:absolute;"; //$NON-NLS-1$
+ private static final String DRAG_ICON_STYLE
+ = "display:none;" //$NON-NLS-1$
+ + "position: absolute;" //$NON-NLS-1$
+ + "cursor: move;"; //$NON-NLS-1$
private int offsetX;
private int offsetY;
private boolean sessionStarted;
- private nsIDOMNode nodeCopy;
- private nsIDOMNode node;
- private nsIDOMCSSStyleDeclaration nodeCopyStyle;
+ private nsIDOMElement nodeCopy;
+ private nsIDOMElement node;
private final MozillaEditor mozillaEditor;
public DraggablePattern(MozillaEditor mozillaEditor) {
@@ -51,26 +60,21 @@
this.mozillaEditor = mozillaEditor;
}
- public void showDragIcon(nsIDOMNode node) {
- this.node = node;
- Rectangle bounds = XulRunnerVpeUtils.getElementBounds(node);
- DragIcon dragIcon = getDragIcon();
- dragIcon.setStyleProperty(HTML.STYLE_PARAMETER_DISPLAY,
- DEFAULT_DISPLAY, DEFAULT_PRIORITY);
- dragIcon.setStyleProperty(HTML.STYLE_PARAMETER_LEFT,
- VpeStyleUtil.toPxPosition(bounds.x), DEFAULT_PRIORITY);
- dragIcon.setStyleProperty(HTML.STYLE_PARAMETER_TOP,
- VpeStyleUtil.toPxPosition(bounds.y - 20), DEFAULT_PRIORITY);
+ public void showDragIcon(nsIDOMElement element) {
+ this.node = element;
+ Rectangle bounds = XulRunnerVpeUtils.getElementBounds(element);
+ nsIDOMElement dragIcon = getDragIcon();
+
+ VpeStyleUtil.setElementVisible(dragIcon, true);
+ VpeStyleUtil.moveElementTo(dragIcon, bounds.x, bounds.y - ICON_HEIGHT);
}
public void hideDragIcon() {
this.node = null;
- DragIcon dragIcon = getDragIcon();
- dragIcon.setStyleProperty(HTML.STYLE_PARAMETER_DISPLAY,
- NONE_DISPLAY, DEFAULT_PRIORITY);
+ VpeStyleUtil.setElementVisible(getDragIcon(), false);
}
- public DragIcon getDragIcon() {
+ private nsIDOMElement getDragIcon() {
nsIDOMElement dragIconElement = mozillaEditor.getDomDocument()
.getElementById(DRAG_ICON_ID);
if (dragIconElement == null) {
@@ -84,13 +88,39 @@
VpeStyleUtil.getAbsoluteResourcePathUrl(DRAG_ICON_FILE));
dragIconElement.setAttribute(HTML.ATTR_STYLE, DRAG_ICON_STYLE);
}
- return new DragIcon(dragIconElement);
+ return dragIconElement;
}
+
+
+ /**
+ * This transparent DIV is needed to move the draggable pattern
+ * over empty areas. Without it the dragover event is not fired by
+ * XULRunner.
+ */
+ private nsIDOMElement getTransparentDiv() {
+ nsIDOMElement transparentDiv = mozillaEditor.getDomDocument()
+ .getElementById(TRANSPARENT_DIV_ID);
+ if (transparentDiv == null) {
+ transparentDiv = mozillaEditor.getDomDocument()
+ .createElement(HTML.TAG_DIV);
+ DndUtil.setTemporaryDndElement(transparentDiv, true);
+ mozillaEditor.getDomDocument().getElementsByTagName(HTML.TAG_BODY)
+ .item(0).appendChild(transparentDiv);
+ transparentDiv.setAttribute(HTML.ATTR_ID, TRANSPARENT_DIV_ID);
+ transparentDiv.setAttribute(HTML.ATTR_STYLE, TRANSPARENT_DIV_STYLE);
+ }
+
+ return transparentDiv;
+ }
public boolean isDragIconClicked(nsIDOMMouseEvent mouseEvent) {
- nsIDOMNode targetNode = (nsIDOMNode) mouseEvent.getTarget()
- .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
- return getDragIcon().getElement().equals(targetNode);
+ nsIDOMElement targetElement = (nsIDOMElement) mouseEvent.getTarget()
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ if (targetElement != null) {
+ return DRAG_ICON_ID.equals(targetElement.getAttribute(HTML.ATTR_ID));
+ } else {
+ return false;
+ }
}
public nsIDOMNode getNode() {
@@ -111,90 +141,55 @@
offsetX = nodeBounds.x - mouseStartX;
offsetY = nodeBounds.y - mouseStartY;
- nodeCopy = node.cloneNode(true);
+ nodeCopy = (nsIDOMElement) node.cloneNode(true)
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
if (nodeCopy.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
nsIDOMElement elementCopy = (nsIDOMElement) nodeCopy.queryInterface(
nsIDOMElement.NS_IDOMELEMENT_IID);
DndUtil.setTemporaryDndElement(elementCopy, true);
}
- nodeCopyStyle = ((nsIDOMElementCSSInlineStyle)
- nodeCopy.queryInterface(
- nsIDOMElementCSSInlineStyle
- .NS_IDOMELEMENTCSSINLINESTYLE_IID)).getStyle();
+ nsIDOMCSSStyleDeclaration nodeCopyStyle
+ = VpeStyleUtil.getStyle(nodeCopy);
+
nodeCopyStyle.setProperty(HTML.STYLE_PARAMETER_POSITION,
ABSOLUTE_POSITION, IMPORTANT_PRIORITY);
nodeCopyStyle.setProperty(HTML.STYLE_PARAMETER_OPACITY,
DRAGGING_OPACITY, IMPORTANT_PRIORITY);
+
setVisible(false);
node.getParentNode().appendChild(nodeCopy);
- move(mouseStartX, mouseStartY);
+ moveTo(mouseStartX, mouseStartY);
setVisible(true);
sessionStarted = true;
}
public void closeSession() {
- if (!sessionStarted) {
- new IllegalStateException(
- "Session is already closed."); //$NON-NLS-1$
+ if (sessionStarted) {
+ setVisible(false);
+ nsIDOMNode parent = nodeCopy.getParentNode();
+ if (parent != null) {
+ parent.removeChild(nodeCopy);
+ }
+
+ hideDragIcon();
+ nodeCopy = null;
+ sessionStarted = false;
}
-
- nsIDOMNode parent = nodeCopy.getParentNode();
- if (parent != null) {
- parent.removeChild(nodeCopy);
- }
-
- hideDragIcon();
- nodeCopy = null;
- nodeCopyStyle = null;
- sessionStarted = false;
}
public void setVisible(boolean visible) {
- nodeCopyStyle.setProperty(HTML.STYLE_PARAMETER_DISPLAY,
- visible ? DEFAULT_DISPLAY : NONE_DISPLAY, IMPORTANT_PRIORITY);
- DragIcon dragIcon = getDragIcon();
- dragIcon.setStyleProperty(HTML.STYLE_PARAMETER_DISPLAY,
- visible ? DEFAULT_DISPLAY : NONE_DISPLAY, DEFAULT_PRIORITY);
+ VpeStyleUtil.setElementVisible(nodeCopy, visible);
+ VpeStyleUtil.setElementVisible(getTransparentDiv(), visible);
+ VpeStyleUtil.setElementVisible(getDragIcon(), visible);
}
- public void move(int mouseX, int mouseY) {
- nodeCopyStyle.setProperty(HTML.STYLE_PARAMETER_LEFT,
- VpeStyleUtil.toPxPosition(offsetX + mouseX),
- IMPORTANT_PRIORITY);
- nodeCopyStyle.setProperty(HTML.STYLE_PARAMETER_TOP,
- VpeStyleUtil.toPxPosition(offsetY + mouseY),
- IMPORTANT_PRIORITY);
-
- DragIcon dragIcon = getDragIcon();
- dragIcon.setStyleProperty(HTML.STYLE_PARAMETER_LEFT,
- VpeStyleUtil.toPxPosition(offsetX + mouseX),
- DEFAULT_PRIORITY);
- dragIcon.setStyleProperty(HTML.STYLE_PARAMETER_TOP,
- VpeStyleUtil.toPxPosition(offsetY + mouseY - 20),
- DEFAULT_PRIORITY);
+ public void moveTo(int mouseX, int mouseY) {
+ VpeStyleUtil.moveElementTo(nodeCopy, offsetX + mouseX, offsetY + mouseY);
+ VpeStyleUtil.moveElementTo(getTransparentDiv(),
+ offsetX + mouseX - TRANSPARENT_DIV_SIZE / 2,
+ offsetY + mouseY - TRANSPARENT_DIV_SIZE / 2);
+ VpeStyleUtil.moveElementTo(getDragIcon(),
+ offsetX + mouseX, offsetY + mouseY - ICON_HEIGHT);
}
-
- public class DragIcon {
- private final nsIDOMElement element;
- private final nsIDOMCSSStyleDeclaration style;
-
- public DragIcon(nsIDOMElement element) {
- this.element = element;
- style = VpeStyleUtil.getStyle(element);
- }
-
- public nsIDOMElement getElement() {
- return element;
- }
-
- public nsIDOMCSSStyleDeclaration getStyle() {
- return style;
- }
-
- public void setStyleProperty(String propertyName, String value,
- String priority) {
- style.setProperty(propertyName, value, priority);
- }
- }
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java 2010-04-01
12:50:02 UTC (rev 21187)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java 2010-04-01
13:30:15 UTC (rev 21188)
@@ -50,10 +50,12 @@
import org.jboss.tools.vpe.xulrunner.XPCOM;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
import org.mozilla.interfaces.nsIComponentManager;
+import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMEvent;
import org.mozilla.interfaces.nsIDOMEventTarget;
import org.mozilla.interfaces.nsIDOMMouseEvent;
+import org.mozilla.interfaces.nsIDOMNSDocument;
import org.mozilla.interfaces.nsIDOMNSUIEvent;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
@@ -113,11 +115,20 @@
.getLastSelectedElement();
// start drag sessionvpe-element
if (isDraggable(selectedElement)) {
+ Point mousePosition = getMousePosition(domEvent);
+ draggablePattern.startSession(mousePosition.x, mousePosition.y);
startDragSession(selectedElement);
+ draggablePattern.closeSession();
domEvent.stopPropagation();
domEvent.preventDefault();
}
}
+
+ private Point getMousePosition(nsIDOMEvent domEvent) {
+ nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent)
+ domEvent.queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
+ return new Point(nsuiEvent.getPageX(), nsuiEvent.getPageY());
+ }
/**
* Calls when drag over event ocure
@@ -126,6 +137,10 @@
public void dragOver(nsIDOMEvent event) {
final nsIDOMMouseEvent mouseEvent =
(nsIDOMMouseEvent) event.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
+ if (isInnerDragSession()) {
+ Point mousePosition = getMousePosition(event);
+ draggablePattern.moveTo(mousePosition.x, mousePosition.y);
+ }
final XulRunnerEditor editor = vpeController.getXulRunnerEditor();
new ScrollingSupport(editor).scroll(mouseEvent);
refreshCanDrop(event);
@@ -138,12 +153,13 @@
* @param vpeController
*/
public void dragDrop(nsIDOMEvent domEvent) {
- if(getDragService().getCurrentSession().getSourceDocument()==null) {
+ if(isInnerDragSession()) {
+ // in this case it's is an internal drag
+ draggablePattern.closeSession();
+ innerDrop((nsIDOMMouseEvent)domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID));
+ } else {
//in this case it's is external drag
externalDrop((nsIDOMMouseEvent)domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID),
VpeController.MODEL_FLAVOR, ""); //$NON-NLS-1$
- } else {
- // in this case it's is an internal drag
- innerDrop((nsIDOMMouseEvent)domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID));
}
vpeController.onRefresh();
}
@@ -280,6 +296,10 @@
dropCommand.execute(dropData);
}
+ private boolean isInnerDragSession() {
+ return getDragService().getCurrentSession().getSourceDocument() != null;
+ }
+
private boolean isDraggable(nsIDOMElement element) {
vpeController.onHideTooltip();
@@ -749,8 +769,24 @@
int dropOffset = 0;
int mouseX = nsuiEvent.getPageX();
int mouseY = nsuiEvent.getPageY();
- nsIDOMNode originalNode = vpeController.getVisualBuilder()
- .getOriginalTargetNode(event);
+
+ nsIDOMDocument document = vpeController.getVisualBuilder()
+ .getOriginalTargetNode(event).getOwnerDocument();
+
+ nsIDOMNSDocument nsDocument = (nsIDOMNSDocument) document
+ .queryInterface(nsIDOMNSDocument.NS_IDOMNSDOCUMENT_IID);
+ nsIDOMNode originalNode = DndUtil.getElementFromPoint(nsDocument, mouseX, mouseY);
+// if (originalNode != null) {
+// if (dropableArea == null) {
+// dropableArea = new DropableArea(document);
+// dropableArea.setDropSpots(EnumSet.allOf(DropSpot.class));
+// }
+// dropableArea.setNode(originalNode);
+// dropableArea.setHighlightedSpot(mouseX, mouseY);
+// dropableArea.setVisible(true);
+// dropableArea.redraw();
+// }
+
if (originalNode == null || originalNode.getParentNode() == null ||
originalNode.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
return new VpeVisualInnerDropInfo(null, 0, mouseX, mouseY);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2010-04-01
12:50:02 UTC (rev 21187)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2010-04-01
13:30:15 UTC (rev 21188)
@@ -138,6 +138,7 @@
public static final String VALUE_BLOCK = "block"; //$NON-NLS-1$
public static final String STYLE_PARAMETER_DISPLAY = "display"; //$NON-NLS-1$
+ public static final String STYLE_VALUE_DEFAULT_DISPLAY = ""; //$NON-NLS-1$
public static final String STYLE_VALUE_NONE = "none"; //$NON-NLS-1$
public static final String STYLE_PARAMETER_WIDTH = "width"; //$NON-NLS-1$
public static final String STYLE_PARAMETER_TOP = "top"; //$NON-NLS-1$
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2010-04-01
12:50:02 UTC (rev 21187)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2010-04-01
13:30:15 UTC (rev 21188)
@@ -27,7 +27,6 @@
import org.eclipse.ui.editors.text.ILocationProvider;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.project.IModelNature;
-import org.jboss.tools.common.model.ui.views.navigator.NDeleteAction;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.resref.core.ResourceReference;
import org.jboss.tools.jst.web.project.WebProject;
@@ -40,7 +39,6 @@
import org.mozilla.interfaces.nsIDOMElementCSSInlineStyle;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
-import org.mozilla.interfaces.nsIDebug;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -887,4 +885,29 @@
+ FileUtil.getFile(resolvedValue, file).getLocation()
.toPortableString();
}
-}
\ No newline at end of file
+
+ /**
+ * Applies CSS attributes {@code left:x;top:y;} to the specified
+ * {@code element}.
+ */
+ public static void moveElementTo(nsIDOMElement element, int x, int y) {
+ nsIDOMCSSStyleDeclaration style = VpeStyleUtil.getStyle(element);
+ style.setProperty(HTML.STYLE_PARAMETER_LEFT,
+ VpeStyleUtil.toPxPosition(x), HTML.STYLE_PRIORITY_IMPORTANT);
+ style.setProperty(HTML.STYLE_PARAMETER_TOP,
+ VpeStyleUtil.toPxPosition(y), HTML.STYLE_PRIORITY_IMPORTANT);
+ }
+
+ /**
+ * Applies CSS attribute {@code display} to the specified
+ * {@code element} according to the {@code visible} parameter.
+ */
+ public static void setElementVisible(nsIDOMElement element,
+ boolean visible) {
+ nsIDOMCSSStyleDeclaration style = VpeStyleUtil.getStyle(element);
+ style.setProperty(HTML.STYLE_PARAMETER_DISPLAY,
+ visible ? HTML.STYLE_VALUE_DEFAULT_DISPLAY
+ : HTML.STYLE_VALUE_NONE, HTML.STYLE_PRIORITY_IMPORTANT);
+
+ }
+}