Author: yradtsevich
Date: 2011-02-24 07:25:40 -0500 (Thu, 24 Feb 2011)
New Revision: 29309
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/mapping/VpeDomMapping.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-8115 : Support for multiple selection in visual
part
- created SelectionUtil.getNodeMappingsBySourceSelection and
getFocusNodesBySourceSelection to support one-to-many linking between source selection and
visual nodes.
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 2011-02-24
12:03:57 UTC (rev 29308)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2011-02-24
12:25:40 UTC (rev 29309)
@@ -1466,22 +1466,6 @@
node.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
}
- public nsIDOMNode getOriginalTargetNode(nsIDOMEvent event) {
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(event);
- if (HTML.TAG_INPUT.equalsIgnoreCase(targetNode.getNodeName())) {
- return targetNode;
- }
- nsIDOMNSEvent nsEvent = queryInterface(event, nsIDOMNSEvent.class);
- // TODO Sergey Vasilyev figure out with TmpRealOriginalTarget
-// nsIDOMEventTarget target = nsEvent.getTmpRealOriginalTarget();
- nsIDOMEventTarget target = nsEvent.getOriginalTarget();
- nsIDOMNode originalNode = queryInterface(target, nsIDOMNode.class);
- if (VpeVisualDomBuilder.isAnonElement(originalNode)) {
- originalNode = getLastSelectedElement();
- }
- return originalNode;
- }
-
public nsIDOMText getOutputTextNode(Attr attr) {
Element sourceElement = attr.getOwnerElement();
VpeElementMapping elementMapping = domMapping
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java 2011-02-24
12:03:57 UTC (rev 29308)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java 2011-02-24
12:25:40 UTC (rev 29309)
@@ -19,6 +19,7 @@
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -125,20 +126,12 @@
public VpeNodeMapping getNearNodeMappingAtSourceNode(Node sourceNode) {
VpeNodeMapping nodeMapping = getNodeMappingAtSourceNode(sourceNode);
- if(nodeMapping!=null){
-
- if(sourceNode!=null && nodeMapping != null) {
-
- nsIDOMNode nearVisualNode = nodeMapping.getVisualNode();
- if(nearVisualNode instanceof nsIDOMElement){
-
- nsIDOMElement visualElement = (nsIDOMElement) nearVisualNode;
- visualElement.removeAttribute(XulRunnerEditor.VPE_INVISIBLE_ELEMENT);
- }
+ while (sourceNode != null && nodeMapping == null) {
+ if (sourceNode instanceof Attr) {
+ sourceNode = ((Attr) sourceNode).getOwnerElement();
+ } else {
+ sourceNode = sourceNode.getParentNode();
}
- }
- while (sourceNode != null && nodeMapping == null) {
- sourceNode = sourceNode.getParentNode();
nodeMapping = getNodeMappingAtSourceNode(sourceNode);
if(sourceNode!=null && nodeMapping != null) {
@@ -150,6 +143,15 @@
}
}
}
+
+ if(sourceNode!=null && nodeMapping != null) {
+ nsIDOMNode nearVisualNode = nodeMapping.getVisualNode();
+ if(nearVisualNode instanceof nsIDOMElement){
+ nsIDOMElement visualElement = (nsIDOMElement) nearVisualNode;
+ visualElement.removeAttribute(XulRunnerEditor.VPE_INVISIBLE_ELEMENT);
+ }
+ }
+
return nodeMapping;
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java 2011-02-24
12:03:57 UTC (rev 29308)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java 2011-02-24
12:25:40 UTC (rev 29309)
@@ -11,8 +11,15 @@
package org.jboss.tools.vpe.editor.util;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.graphics.Point;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
@@ -225,12 +232,37 @@
return sourceRange;
}
+
public static VpeNodeMapping getNodeMappingBySourceSelection(
StructuredTextEditor sourceEditor, VpeDomMapping domMapping) {
+ List<VpeNodeMapping> mappings
+ = getNodeMappingsBySourceSelection(sourceEditor, domMapping);
+ if (!mappings.isEmpty()) {
+ return mappings.get(0);
+ } else {
+ return null;
+ }
+ }
+ public static List<VpeNodeMapping> getNodeMappingsBySourceSelection(
+ StructuredTextEditor sourceEditor, VpeDomMapping domMapping) {
+ List<VpeNodeMapping> nodeMappings = new ArrayList<VpeNodeMapping>();
+ for (Node node : getFocusNodesBySourceSelection(sourceEditor, domMapping)) {
+ VpeNodeMapping nodeMapping = VpeNodesManagingUtil.getNodeMapping(domMapping, node);
+ if (nodeMapping != null) {
+ nodeMappings.add(nodeMapping);
+ }
+ }
+
+ return nodeMappings;
+ }
+
+ private static List<Node> getFocusNodesBySourceSelection(
+ StructuredTextEditor sourceEditor, VpeDomMapping domMapping) {
Point range = sourceEditor.getTextViewer().getSelectedRange();
IDocument document = sourceEditor.getTextViewer().getDocument();
+ List<Node> focusNodes = new ArrayList<Node>();
IStructuredModel model = null;
try {
// gets source model for read, model should be released see
@@ -240,12 +272,9 @@
//fix for JBIDE-3805, mareshkau
if(model == null) {
- return null;
+ return Collections.emptyList();
}
- int anchor = range.x;
- int focus = range.x + range.y;
-
/*
* implementation of IDOMModel's method getIndexedRegion(...) has
* one feature : if cursor is situated at the border of elements
@@ -255,39 +284,34 @@
* getIndexedRegion() return "h:outputText" element. So for focus
* position we choose smaller value
*/
- Node focusNode = null;
- if (anchor < focus) {
- int tmp = focus;
- focus = anchor;
- anchor = tmp;
- }
- if (anchor == focus) {
- // get source node by offset
- // see JBIDE-3163
- focusNode = getSourceNodeByPosition(model, focus);
+ int selectionStart = Math.min(range.x, range.x + range.y);
+ if (range.y == 0) {
+ /* if selection length is 0 (text cursor only), than use
+ * custom implementation to determine node. See JBIDE-3163. */
+ Node focusNode = getSourceNodeByPosition(model, selectionStart);
+ if (focusNode != null) {
+ focusNodes.add(focusNode);
+ }
} else {
// fixed JBIDE-3388: Incorrect selection after Copy/Cut actions
- IndexedRegion node = model.getIndexedRegion(focus);
- if (node != null) {
- focusNode = (Node) node;
+ ISelection selection = sourceEditor.getSelectionProvider().getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Iterator iterator = ((IStructuredSelection) selection).iterator();
+ while (iterator.hasNext()) {
+ Object selectionElement = iterator.next();
+ if (selectionElement instanceof Node) {
+ focusNodes.add((Node) selectionElement);
+ }
+ }
}
}
-
- // if focus node also contains anchor point (selected only 1
- // element)
- if (focusNode != null) {
- // if (NodesManagingUtil.isNodeContainsPosition(focusNode,
- // anchor)) {
- return VpeNodesManagingUtil.getNodeMapping(domMapping, focusNode);
- // }
- }
} finally {
if (model != null) {
model.releaseFromRead();
}
}
- return null;
+ return focusNodes;
}
public static Node getNodeBySourcePosition(