Author: yradtsevich
Date: 2010-10-15 15:11:45 -0400 (Fri, 15 Oct 2010)
New Revision: 25887
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java
Log:
https://jira.jboss.org/browse/JBIDE-7258 :
DnD in VPE does not work with rich:calendar
- problem fixing
- code refactoring
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2010-10-15
18:55:11 UTC (rev 25886)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2010-10-15
19:11:45 UTC (rev 25887)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.vpe.editor;
+import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
+
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.LinkedList;
@@ -95,6 +97,7 @@
import org.jboss.tools.vpe.dnd.VpeDnD;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.menu.VpeMenuCreator;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
@@ -122,6 +125,7 @@
import org.jboss.tools.vpe.editor.util.DocTypeUtil;
import org.jboss.tools.vpe.editor.util.SelectionUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
+import org.jboss.tools.vpe.editor.util.VpeNodesManagingUtil;
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.resref.core.AbsoluteFolderReferenceList;
import org.jboss.tools.vpe.resref.core.CSSReferenceList;
@@ -134,8 +138,10 @@
import org.mozilla.interfaces.nsIDOMKeyEvent;
import org.mozilla.interfaces.nsIDOMMouseEvent;
import org.mozilla.interfaces.nsIDOMMutationEvent;
+import org.mozilla.interfaces.nsIDOMNSUIEvent;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsISelection;
+import org.mozilla.interfaces.nsISelectionDisplay;
import org.mozilla.interfaces.nsISelectionListener;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
@@ -164,8 +170,6 @@
private VpeSourceDomBuilder sourceBuilder;
private VpeVisualDomBuilder visualBuilder;
private VpeDnD vpeDnD;
- /** @deprecated */
- private VpeSelectionBuilder selectionBuilder;
// private VpeVisualKeyHandler visualKeyHandler;
private ActiveEditorSwitcher switcher = new ActiveEditorSwitcher();
private Attr lastRemovedAttr;
@@ -286,10 +290,8 @@
// initialization visual selection controller
visualSelectionController = new VpeSelectionController(visualEditor
.getEditor().getSelectionController());
+ visualSelectionController.setSelectionFlags(nsISelectionDisplay.DISPLAY_ALL);
- selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
- visualBuilder, visualSelectionController);
-
selectionManager = new SelectionManager(pageContext, sourceEditor,
visualSelectionController);
@@ -1203,7 +1205,9 @@
if (vpeDnD.isDragIconClicked(mouseEvent)) {
vpeDnD.dragStart(mouseEvent);
} else {
- selectionManager.setSelection(mouseEvent);
+ selectionManager.setSelection(
+ VisualDomUtil.getTargetNode(mouseEvent),
+ queryInterface(mouseEvent, nsIDOMNSUIEvent.class).getRangeOffset());
}
}
} finally {
@@ -1247,9 +1251,13 @@
mouseUpSelectionReasonFlag = false;
}
- if (visualBuilder.doToggle(VisualDomUtil
- .getTargetNode(mouseEvent))) {
- // selectionBuilder.setClickContentAreaSelection();
+ Element toggledElement = visualBuilder.doToggle(visualNode);
+ if (toggledElement != null) {
+ VpeNodeMapping toggledMapping
+ = getDomMapping().getNearNodeMapping(toggledElement);
+ if (toggledMapping != null && toggledMapping.getVisualNode() != null) {
+ selectionManager.setSelection(toggledMapping.getVisualNode(), 0);
+ }
}
}
} finally {
@@ -2353,21 +2361,6 @@
this.xulRunnerEditor = xulRunnerEditor;
}
- /**
- * @return the selectionBuilder
- */
- public VpeSelectionBuilder getSelectionBuilder() {
- return selectionBuilder;
- }
-
- /**
- * @param selectionBuilder
- * the selectionBuilder to set
- */
- public void setSelectionBuilder(VpeSelectionBuilder selectionBuilder) {
- this.selectionBuilder = selectionBuilder;
- }
-
public boolean isVisualEditorVisible() {
return visualEditorVisible;
}
@@ -2438,8 +2431,7 @@
visualSelectionController = new VpeSelectionController(visualEditor
.getEditor().getSelectionController());
- selectionBuilder = new VpeSelectionBuilder(domMapping,
- sourceBuilder, visualBuilder, visualSelectionController);
+ visualSelectionController.setSelectionFlags(nsISelectionDisplay.DISPLAY_ALL);
selectionManager = new SelectionManager(pageContext, sourceEditor,
visualSelectionController);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2010-10-15
18:55:11 UTC (rev 25886)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2010-10-15
19:11:45 UTC (rev 25887)
@@ -940,9 +940,9 @@
}
}
- public boolean doToggle(nsIDOMNode visualNode) {
+ public Element doToggle(nsIDOMNode visualNode) {
if (visualNode == null) {
- return false;
+ return null;
}
nsIDOMElement visualElement = null;
try {
@@ -951,18 +951,18 @@
visualElement = queryInterface(visualNode.getParentNode(), nsIDOMElement.class);
}
if (visualElement == null) {
- return false;
+ return null;
}
nsIDOMAttr toggleIdAttr = visualElement
.getAttributeNode(VPE_USER_TOGGLE_ID);
if (toggleIdAttr == null) {
- return false;
+ return null;
}
String toggleId = toggleIdAttr.getNodeValue();
if (toggleId == null) {
- return false;
+ return null;
}
boolean toggleLookup = false;
@@ -975,7 +975,7 @@
nsIDOMElement selectedElem = getLastSelectedElement();
// Fixes JBIDE-1823 author dmaliarevich
if (null == selectedElem) {
- return false;
+ return null;
}
VpeElementMapping elementMapping = null;
VpeNodeMapping nodeMapping = domMapping.getNodeMapping(selectedElem);
@@ -997,7 +997,7 @@
}
Node sourceNode = domMapping.getSourceNode(selectedElem);
if (sourceNode == null) {
- return false;
+ return null;
}
Element sourceElement = (Element) (sourceNode instanceof Element ? sourceNode
@@ -1039,10 +1039,10 @@
((VpeToggableTemplate) template).toggle(this, sourceElement,
toggleId);
updateElement(sourceElement);
- return true;
+ return sourceElement;
}
}
- return false;
+ return null;
}
public void removeAttribute(Element sourceElement, String name) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java 2010-10-15
18:55:11 UTC (rev 25886)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java 2010-10-15
19:11:45 UTC (rev 25887)
@@ -1758,15 +1758,7 @@
return nearestElement;
}
-
-
- private VpeSelectionBuilder getSelectionBuilder() {
-
- return pageContext.getEditPart().getController().getSelectionBuilder();
- }
-
private nsIDOMElement getSelectedNode() {
-
return pageContext.getEditPart().getController().getXulRunnerEditor().getLastSelectedElement();
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java 2010-10-15
18:55:11 UTC (rev 25886)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java 2010-10-15
19:11:45 UTC (rev 25887)
@@ -10,7 +10,7 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.template;
-import org.mozilla.interfaces.nsIDOMMouseEvent;
+import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsISelection;
/**
@@ -33,7 +33,7 @@
*
* @param mouseEvent
*/
- public void setSelection(nsIDOMMouseEvent mouseEvent);
+ public void setSelection(nsIDOMNode visualNode, int rangeOffset);
/**
* to bring in correspondence visual selection and source selection
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java 2010-10-15
18:55:11 UTC (rev 25886)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java 2010-10-15
19:11:45 UTC (rev 25887)
@@ -11,8 +11,6 @@
package org.jboss.tools.vpe.editor.template;
-import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
-
import org.eclipse.swt.graphics.Point;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.xml.core.internal.document.NodeImpl;
@@ -25,10 +23,7 @@
import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
import org.jboss.tools.vpe.editor.util.SelectionUtil;
import org.jboss.tools.vpe.editor.util.TextUtil;
-import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.jboss.tools.vpe.editor.util.VpeNodesManagingUtil;
-import org.mozilla.interfaces.nsIDOMMouseEvent;
-import org.mozilla.interfaces.nsIDOMNSUIEvent;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsISelection;
import org.mozilla.interfaces.nsISelectionController;
@@ -64,185 +59,108 @@
this.selectionController = selectionController;
}
+ /* TODO: merge this method with setSelection(nsIDOMNode visualNode, int rangeOffset) */
public final void setSelection(nsISelection selection) {
-
- nsIDOMNode selectedVisualNode = SelectionUtil
- .getSelectedNode(selection);
-
- if (selectedVisualNode == null)
+ nsIDOMNode visualNode = SelectionUtil.getSelectedNode(selection);
+ if (visualNode == null) {
return;
+ }
- VpeNodeMapping nodeMapping = VpeNodesManagingUtil.getNodeMapping(
- getDomMapping(), selectedVisualNode);
-
- if (nodeMapping == null)
+ SelectionData selectionData = getSelectionData(visualNode);
+ if (selectionData == null) {
return;
-
- // visual node which will be selected
- nsIDOMNode targetVisualNode;
- // source node which will be selected
- Node targetSourceNode;
-
- boolean isNodeEditable;
-
- // if mapping is elementMapping
- if (nodeMapping instanceof VpeElementMapping) {
-
- VpeElementMapping elementMapping = (VpeElementMapping) nodeMapping;
-
- VpeTemplate template = elementMapping.getTemplate();
-
- NodeData nodeData = template.getNodeData(selectedVisualNode,
- elementMapping.getElementData(), getDomMapping());
-
- if (nodeData != null) {
-
- isNodeEditable = nodeData.isEditable();
- if (nodeData.getSourceNode() != null) {
- targetSourceNode = nodeData.getSourceNode();
-
- } else {
-
- isNodeEditable = false;
- targetSourceNode = elementMapping.getSourceNode();
-
- }
-
- targetVisualNode = nodeData.getVisualNode();
- } else {
-
- targetVisualNode = elementMapping.getVisualNode();
- targetSourceNode = elementMapping.getSourceNode();
- isNodeEditable = false;
- }
-
- } else {
- // here we processed text node
- targetVisualNode = nodeMapping.getVisualNode();
- targetSourceNode = nodeMapping.getSourceNode();
- isNodeEditable = true;
-
}
- if (targetVisualNode.getNodeType() != nsIDOMNode.TEXT_NODE
- && SelectionUtil.getLastSelectedNode(getPageContext()) == targetVisualNode)
+ if (selectionData.getVisualNode().getNodeType() != nsIDOMNode.TEXT_NODE
+ && SelectionUtil.getLastSelectedNode(getPageContext())
+ == selectionData.getVisualNode()) {
return;
-
- int focusOffset;
- int length;
-
- if (isNodeEditable) {
-
+ }
+ /*************** Calculate selection range ****************************/
+ int selectionOffset;
+ int selectionLength;
+ if (selectionData.isNodeEditable()) {
Point sourceSelectionRange = SelectionUtil.getSourceSelectionRange(
- selection, targetSourceNode);
-
- focusOffset = sourceSelectionRange.x;
- length = sourceSelectionRange.y;
-
+ selection, selectionData.getSourceNode());
+ selectionOffset = sourceSelectionRange.x;
+ selectionLength = sourceSelectionRange.y;
} else {
-
- focusOffset = 0;
- length = NodesManagingUtil.getNodeLength(targetSourceNode);
-
+ selectionOffset = 0;
+ selectionLength = NodesManagingUtil.getNodeLength(selectionData.getSourceNode());
}
-
+ /*************** Apply selection to views *****************************/
// set source selection
- SelectionUtil.setSourceSelection(getPageContext(), targetSourceNode,
- focusOffset, length);
-
+ SelectionUtil.setSourceSelection(getPageContext(), selectionData.getSourceNode(),
+ selectionOffset, selectionLength);
// paint visual selection
getPageContext().getVisualBuilder().setSelectionRectangle(
- targetVisualNode);
+ selectionData.getVisualNode());
+ }
+ final public void setSelection(nsIDOMNode visualNode, int rangeOffset) {
+ SelectionData selectionData = getSelectionData(visualNode);
+ if (selectionData == null) {
+ return;
+ }
+ /*************** Calculate selection range ****************************/
+ int selectionOffset;
+ int selectionLength;
+ if (selectionData.isNodeEditable()) {
+ selectionOffset = rangeOffset;
+ selectionLength = 0;
+ } else {
+ selectionOffset = 0;
+ selectionLength = NodesManagingUtil.getNodeLength(selectionData.getSourceNode());
+ }
+ /*************** Apply selection to views *****************************/
+ SelectionUtil.clearSelection(selectionController);
+ SelectionUtil.setSourceSelection(getPageContext(),
+ selectionData.getSourceNode(),
+ selectionOffset, selectionLength);
+ // paint selection rectangle
+ getPageContext().getVisualBuilder().setSelectionRectangle(
+ selectionData.getVisualNode());
}
- final public void setSelection(nsIDOMMouseEvent mouseEvent) {
-
- // get visual node by event
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
-
+ private SelectionData getSelectionData(nsIDOMNode visualNode) {
// get element mapping
VpeNodeMapping nodeMapping = VpeNodesManagingUtil.getNodeMapping(
getDomMapping(), visualNode);
- if (nodeMapping == null)
- return;
-
- // visual node which will be selected
- nsIDOMNode targetVisualNode;
- // source node which will be selected
- Node targetSourceNode;
-
+ if (nodeMapping == null) {
+ return null;
+ }
+
+ nsIDOMNode targetVisualNode; // visual node which will be selected
+ Node targetSourceNode; // source node which will be selected
boolean isNodeEditable;
-
- // if mapping is elementMapping
if (nodeMapping instanceof VpeElementMapping) {
-
VpeElementMapping elementMapping = (VpeElementMapping) nodeMapping;
+ NodeData nodeData = elementMapping.getTemplate().getNodeData(
+ visualNode, elementMapping.getElementData(), getDomMapping());
- VpeTemplate template = elementMapping.getTemplate();
-
- NodeData nodeData = template.getNodeData(visualNode, elementMapping
- .getElementData(), getDomMapping());
-
if (nodeData != null) {
-
- isNodeEditable = nodeData.isEditable();
-
+ targetVisualNode = nodeData.getVisualNode();
if (nodeData.getSourceNode() != null) {
-
targetSourceNode = nodeData.getSourceNode();
-
+ isNodeEditable = nodeData.isEditable();
} else {
-
- isNodeEditable = false;
targetSourceNode = elementMapping.getSourceNode();
-
+ isNodeEditable = false;
}
-
- targetVisualNode = nodeData.getVisualNode();
-
} else {
-
targetVisualNode = elementMapping.getVisualNode();
- targetSourceNode = elementMapping.getSourceNode();
+ targetSourceNode = elementMapping.getSourceNode();
isNodeEditable = false;
-
}
-
- }
-
- else {
-
+ } else {
targetVisualNode = nodeMapping.getVisualNode();
targetSourceNode = nodeMapping.getSourceNode();
isNodeEditable = true;
-
}
-
- // get nsIDOMNSUIEvent event
- nsIDOMNSUIEvent nsuiEvent = queryInterface(mouseEvent, nsIDOMNSUIEvent.class);
-
- int selectionOffset;
- int selectionLength;
-
- if (isNodeEditable) {
- selectionOffset = nsuiEvent.getRangeOffset();
- selectionLength = 0;
- } else {
-
- selectionOffset = 0;
- selectionLength = NodesManagingUtil.getNodeLength(targetSourceNode);
-
- }
-
- SelectionUtil.clearSelection(selectionController);
- SelectionUtil.setSourceSelection(getPageContext(), targetSourceNode,
- selectionOffset, selectionLength);
- // paint selection rectangle
- getPageContext().getVisualBuilder().setSelectionRectangle(
- targetVisualNode);
-
+ SelectionData selectionData = new SelectionData(
+ targetVisualNode, targetSourceNode, isNodeEditable);
+ return selectionData;
}
/**
@@ -391,3 +309,36 @@
}
}
+
+class SelectionData {
+ private nsIDOMNode visualNode;
+ private Node sourceNode;
+ private boolean isNodeEditable;
+
+ public SelectionData(nsIDOMNode visualNode, Node sourceNode,
+ boolean isNodeEditable) {
+ super();
+ this.visualNode = visualNode;
+ this.sourceNode = sourceNode;
+ this.isNodeEditable = isNodeEditable;
+ }
+
+ public nsIDOMNode getVisualNode() {
+ return visualNode;
+ }
+ public void setVisualNode(nsIDOMNode visualNode) {
+ this.visualNode = visualNode;
+ }
+ public Node getSourceNode() {
+ return sourceNode;
+ }
+ public void setSourceNode(Node sourceNode) {
+ this.sourceNode = sourceNode;
+ }
+ public boolean isNodeEditable() {
+ return isNodeEditable;
+ }
+ public void setNodeEditable(boolean isNodeEditable) {
+ this.isNodeEditable = isNodeEditable;
+ }
+}