Author: sdzmitrovich
Date: 2008-06-26 04:19:17 -0400 (Thu, 26 Jun 2008)
New Revision: 8951
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/VpeElementProxyData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/AttributeData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/NodeData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/IKeyEventHandler.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/KeyEventManager.java
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/util/NodesManagingUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeAttributeData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateKeyEventHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOptionSelectItemTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfVerbatim.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/NodeProxyUtil.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/AttributeProxy.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/NamedNodeMapImpl.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/NodeProxy.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/AbstractEditableRichFacesTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/InputNumberSliderTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesComboBoxTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSpinnerTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java
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/VpeSelectionBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.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/mapping/VpeElementData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TextUtil.java
Log:
selection's mechanism and editing's mechanism were changed, concerned with
http://jira.jboss.com/jira/browse/JBIDE-2362 and
http://jira.jboss.com/jira/browse/JBIDE-1719 ... the 2nd attempt
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -14,7 +14,7 @@
import java.util.Map;
import java.util.Set;
-import org.jboss.tools.vpe.editor.template.EditableTemplateAdapter;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMElement;
import org.w3c.dom.Element;
@@ -25,8 +25,7 @@
* @author Sergey Dzmitrovich
*
*/
-public abstract class AbstractEditableJsfTemplate extends
- EditableTemplateAdapter {
+public abstract class AbstractEditableJsfTemplate extends VpeAbstractTemplate {
// general jsf attributes
static private Map<String, String> attributes = new HashMap<String,
String>();
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -4,15 +4,18 @@
import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
+import org.jboss.tools.jsf.vpe.jsf.template.util.model.VpeElementProxyData;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.AttributeData;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
+import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
@@ -66,7 +69,7 @@
nsIDOMDocument visualDocument, Element sourceElement,
nsIDOMElement targetVisualElement, VpeCreationData creationData) {
- VpeElementData elementData = new VpeElementData();
+ VpeElementProxyData elementData = new VpeElementProxyData();
Attr outputAttr = getOutputAttributeNode(sourceElement);
@@ -92,8 +95,8 @@
text = visualDocument.createTextNode(newValue);
// add attribute for ability of editing
- elementData.addAttributeData(new VpeAttributeData(outputAttr,
- text, isEditable));
+ elementData.addNodeData(new AttributeData(outputAttr, text,
+ isEditable));
targetVisualElement.appendChild(text);
@@ -110,8 +113,8 @@
.getValueRegionStartOffset();
// reparse attribute's value
- NodeList list = NodeProxyUtil.reparseAttributeValue(newValue,
- offset);
+ NodeList list = NodeProxyUtil.reparseAttributeValue(
+ elementData, newValue, offset + 1);
// add children to info
for (int i = 0; i < list.getLength(); i++) {
@@ -122,7 +125,7 @@
targetVisualInfo.addSourceChild(child);
}
- elementData.addAttributeData(new VpeAttributeData(outputAttr,
+ elementData.addNodeData(new AttributeData(outputAttr,
targetVisualElement, false));
creationData.addChildrenInfo(targetVisualInfo);
@@ -140,114 +143,79 @@
return ComponentUtil.getBundleValue(pageContext, attr);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#setPseudoContent
+ * (org.jboss.tools.vpe.editor.context.VpePageContext, org.w3c.dom.Node,
+ * org.mozilla.interfaces.nsIDOMNode, org.mozilla.interfaces.nsIDOMDocument)
+ */
@Override
- public Node getTargetSourceNodeByVisualNode(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementMapping elementMapping) {
+ public void setPseudoContent(VpePageContext pageContext,
+ Node sourceContainer, nsIDOMNode visualContainer,
+ nsIDOMDocument visualDocument) {
+ // Empty
+ }
- // try get mapping
- VpeNodeMapping tempMapping = pageContext.getDomMapping()
- .getNearElementMapping(visualNode);
+ @Override
+ public NodeData getNodeData(nsIDOMNode node, VpeElementData elementData,
+ VpeDomMapping domMapping) {
+ // TODO Auto-generated method stub
+ NodeData nodeData = super.getNodeData(node, elementData, domMapping);
+ if (nodeData == null) {
- // if mapping is not null
- if (tempMapping != null) {
+ VpeNodeMapping nodeMapping = domMapping.getNodeMapping(node);
- return super.getTargetSourceNodeByVisualNode(pageContext,
- visualNode, elementMapping);
- }
- // can be only for escape=false
- else {
-
- tempMapping = pageContext.getDomMapping()
- .getNearNodeMappingAtVisualNode(visualNode);
-
- if (tempMapping != null) {
-
- Node insertedNode = tempMapping.getSourceNode();
-
- return getTargetSourceNodeBySourcePosition(pageContext,
- TemplateManagingUtil.getStartOffsetNode(insertedNode),
- TemplateManagingUtil.getEndOffsetNode(insertedNode));
-
+ if (nodeMapping != null) {
+ if (nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+ nodeData = super.getNodeData(node,
+ ((VpeElementMapping) nodeMapping).getElementData(),
+ domMapping);
+ } else if (nodeMapping.getType() == VpeNodeMapping.TEXT_MAPPING) {
+ nodeData = new NodeData(nodeMapping.getSourceNode(), node,
+ true);
+ }
}
}
-
- return elementMapping.getSourceNode();
-
+ return nodeData;
}
@Override
- public nsIDOMNode getTargetVisualNodeByVisualNode(
- VpePageContext pageContext, nsIDOMNode visualNode,
- VpeElementMapping elementMapping) {
- // try get mapping
- VpeNodeMapping tempMapping = pageContext.getDomMapping()
- .getNearElementMapping(visualNode);
+ public nsIDOMNode getVisualNodeByBySourcePosition(
+ VpeElementMapping elementMapping, int focusPosition,
+ int anchorPosition, VpeDomMapping domMapping) {
+ nsIDOMNode node = null;
- // if mapping is not null
- if (tempMapping != null) {
+ if ((elementMapping.getElementData() instanceof VpeElementProxyData)
+ && (((VpeElementProxyData) elementMapping.getElementData())
+ .getNodelist() != null)) {
- return super.getTargetVisualNodeByVisualNode(pageContext,
- visualNode, elementMapping);
- }
- // can be only for escape=false
- else {
+ VpeElementProxyData elementProxyData = (VpeElementProxyData) elementMapping
+ .getElementData();
- tempMapping = pageContext.getDomMapping()
- .getNearNodeMappingAtVisualNode(visualNode);
+ Node sourceNode = NodeProxyUtil.findNodeByPosition(elementProxyData
+ .getNodelist(), focusPosition, anchorPosition);
- if (tempMapping != null) {
+ VpeNodeMapping nodeMapping = NodesManagingUtil.getNodeMapping(
+ domMapping, sourceNode);
- Node insertedNode = tempMapping.getSourceNode();
+ if (nodeMapping != null) {
- Node sourceNode = getTargetSourceNodeBySourcePosition(
- pageContext, TemplateManagingUtil
- .getStartOffsetNode(insertedNode),
- TemplateManagingUtil.getEndOffsetNode(insertedNode));
- return getTargetVisualNodeBySourceNode(sourceNode,
- elementMapping);
-
+ if (nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+ node = super.getVisualNodeByBySourcePosition(
+ (VpeElementMapping) nodeMapping, focusPosition,
+ anchorPosition, domMapping);
+ } else {
+ node = nodeMapping.getVisualNode();
+ }
}
}
- return elementMapping.getVisualNode();
- }
-
- @Override
- protected VpeElementMapping getElmentMapping(VpePageContext pageContext,
- nsIDOMNode node) {
- // TODO Auto-generated method stub
- VpeElementMapping elementMapping = super.getElmentMapping(pageContext,
- node);
-
- if (elementMapping == null) {
- VpeNodeMapping insertedMapping = pageContext.getDomMapping()
- .getNearNodeMappingAtVisualNode(node);
- if (insertedMapping != null) {
- Node insertedNode = insertedMapping.getSourceNode();
-
- int offset = TemplateManagingUtil
- .getStartOffsetNode(insertedNode);
- elementMapping = TemplateManagingUtil
- .getElementMappingBySourceSelection(pageContext,
- offset, offset);
-
- }
+ if (node == null) {
+ node = super.getVisualNodeByBySourcePosition(elementMapping,
+ focusPosition, anchorPosition, domMapping);
}
-
- return elementMapping;
+ return node;
}
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#setPseudoContent(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMNode,
- * org.mozilla.interfaces.nsIDOMDocument)
- */
- @Override
- public void setPseudoContent(VpePageContext pageContext,
- Node sourceContainer, nsIDOMNode visualContainer,
- nsIDOMDocument visualDocument) {
- // Empty
- }
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -2,7 +2,7 @@
import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.AttributeData;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -42,12 +42,12 @@
Attr attr = sourceElement.getAttributeNode(JSF.ATTR_VALUE);
text = visualDocument.createTextNode(sourceElement
.getAttribute(JSF.ATTR_VALUE));
- elementData.addAttributeData(new VpeAttributeData(attr, textArea,
+ elementData.addNodeData(new AttributeData(attr, textArea,
true));
} else {
text = visualDocument.createTextNode(""); //$NON-NLS-1$
- elementData.addAttributeData(new VpeAttributeData(JSF.ATTR_VALUE,
+ elementData.addNodeData(new AttributeData(JSF.ATTR_VALUE,
textArea, true));
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -2,7 +2,8 @@
import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.AttributeData;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -34,11 +35,11 @@
Attr attr = sourceElement.getAttributeNode(JSF.ATTR_VALUE);
elementData
- .addAttributeData(new VpeAttributeData(attr, input, true));
+ .addNodeData(new AttributeData(attr, input, true));
} else {
- elementData.addAttributeData(new VpeAttributeData(JSF.ATTR_VALUE,
+ elementData.addNodeData(new AttributeData(JSF.ATTR_VALUE,
input, true));
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOptionSelectItemTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOptionSelectItemTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOptionSelectItemTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -12,9 +12,9 @@
import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
-import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
+import org.jboss.tools.jsf.vpe.jsf.template.util.model.VpeElementProxyData;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.mapping.AttributeData;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -30,7 +30,7 @@
* @author dmaliarevich
*
*/
-public class JsfOptionSelectItemTemplate extends VpeAbstractTemplate {
+public class JsfOptionSelectItemTemplate extends AbstractOutputJsfTemplate
/*VpeAbstractTemplate*/ {
public static final String ITEM_DISABLED = "itemDisabled";
@@ -86,7 +86,9 @@
if (element.hasAttribute(ITEM_LABEL)) {
attr = element.getAttributeNode(ITEM_LABEL);
}
-
+
+ VpeElementProxyData elementData = new VpeElementProxyData();
+
if (null != attr) {
if (null == escape || "true".equalsIgnoreCase(escape)) {
// show text as is
@@ -101,13 +103,19 @@
} else {
text = visualDocument.createTextNode(itemLabel);
+
+ elementData.addNodeData(new AttributeData(attr,
+ option, true));
+ creationData.setElementData(elementData);
}
+
+
option.appendChild(text);
} else {
// show formatted text
VpeChildrenInfo spanInfo = new VpeChildrenInfo(option);
// re-parse attribute's value
- NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
+ NodeList list = NodeProxyUtil.reparseAttributeValue(elementData,attr);
// add children to info
for (int i = 0; i < list.getLength(); i++) {
Node child = list.item(i);
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfVerbatim.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfVerbatim.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfVerbatim.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -14,7 +14,7 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.template.EditableTemplateAdapter;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -29,7 +29,7 @@
* @author Sergey Dzmitrovich
*
*/
-public class JsfVerbatim extends EditableTemplateAdapter {
+public class JsfVerbatim extends VpeAbstractTemplate {
/*
* (non-Javadoc)
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/NodeProxyUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/NodeProxyUtil.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/NodeProxyUtil.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -23,35 +23,45 @@
import org.jboss.tools.jsf.vpe.jsf.template.util.model.NodeListImpl;
import org.jboss.tools.jsf.vpe.jsf.template.util.model.NodeProxy;
import org.jboss.tools.jsf.vpe.jsf.template.util.model.TextProxy;
+import org.jboss.tools.jsf.vpe.jsf.template.util.model.VpeElementProxyData;
+import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class NodeProxyUtil {
- static public NodeList reparseAttributeValue(String attrString, int offset) {
+ static public NodeList reparseAttributeValue(VpeElementProxyData data,
+ String attrString, int offset) {
IStructuredDocument newStructuredDocument = StructuredDocumentFactory
.getNewStructuredDocumentInstance(new JSPSourceParser());
newStructuredDocument.set(attrString);
IDOMModel modelForJSP = new DOMModelForJSP();
+
modelForJSP.setStructuredDocument(newStructuredDocument);
+ // data.setModel(modelForJSP);
+ // data.setOffset(offset);
+
IDOMDocument document = modelForJSP.getDocument();
NodeList list = document.getChildNodes();
NodeList adaptersList = getNodeAdapterList(list, offset);
+ data.setNodelist(adaptersList);
+
return adaptersList;
}
- static public NodeList reparseAttributeValue(Attr attr) {
+ static public NodeList reparseAttributeValue(VpeElementProxyData data,
+ Attr attr) {
- return reparseAttributeValue(attr.getValue(), ((IDOMAttr) attr)
- .getValueRegionStartOffset());
+ return reparseAttributeValue(data, attr.getValue(), ((IDOMAttr) attr)
+ .getValueRegionStartOffset() + 1);
}
@@ -84,4 +94,44 @@
}
+ /**
+ *
+ * @param nodeList
+ * @param focusPosition
+ * @param anchorPosition
+ * @return
+ */
+ static public Node findNodeByPosition(NodeList nodeList, int focusPosition,
+ int anchorPosition) {
+
+ if (anchorPosition < focusPosition) {
+ focusPosition = anchorPosition;
+ anchorPosition = focusPosition;
+ }
+
+ for (int i = 0; i < nodeList.getLength(); i++) {
+
+ Node child = nodeList.item(i);
+
+ Node result = null;
+ if (child.hasChildNodes()) {
+
+ result = findNodeByPosition(child.getChildNodes(),
+ focusPosition, anchorPosition);
+ }
+
+ if (result != null)
+ return result;
+
+ if ((focusPosition >= (NodesManagingUtil.getStartOffsetNode(child)))
+ && (anchorPosition <= (NodesManagingUtil
+ .getEndOffsetNode(child))))
+
+ return child;
+ }
+
+ return null;
+
+ }
+
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/AttributeProxy.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/AttributeProxy.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/AttributeProxy.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -12,7 +12,6 @@
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
-import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.TypeInfo;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/NamedNodeMapImpl.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/NamedNodeMapImpl.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/NamedNodeMapImpl.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -13,10 +13,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.wst.xml.core.internal.document.AttrImpl;
-import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
-import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/NodeProxy.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/NodeProxy.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/NodeProxy.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -24,11 +24,9 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.w3c.dom.TypeInfo;
import org.w3c.dom.UserDataHandler;
public class NodeProxy implements IDOMNode {
@@ -314,7 +312,7 @@
}
public int getStartOffset() {
- return ((IDOMNode) basicNode).getStartOffset()+ basicOffset;
+ return ((IDOMNode) basicNode).getStartOffset() + basicOffset;
}
public void addAdapter(INodeAdapter adapter) {
Copied:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/VpeElementProxyData.java
(from rev 8946,
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/VpeElementProxyData.java)
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/VpeElementProxyData.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/model/VpeElementProxyData.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,38 @@
+package org.jboss.tools.jsf.vpe.jsf.template.util.model;
+
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.w3c.dom.NodeList;
+
+public class VpeElementProxyData extends VpeElementData {
+
+ // private IStructuredModel model;
+
+ // private int offset;
+ //
+ // public void setModel(IStructuredModel model) {
+ // this.model = model;
+ // }
+ //
+ // public IStructuredModel getModel() {
+ // return model;
+ // }
+ //
+ // public int getOffset() {
+ // return offset;
+ // }
+ //
+ // public void setOffset(int offset) {
+ // this.offset = offset;
+ // }
+
+ private NodeList nodelist;
+
+ public NodeList getNodelist() {
+ return nodelist;
+ }
+
+ public void setNodelist(NodeList nodelist) {
+ this.nodelist = nodelist;
+ }
+
+}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/AbstractEditableRichFacesTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/AbstractEditableRichFacesTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/AbstractEditableRichFacesTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -10,11 +10,11 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.richfaces.template;
-import org.jboss.tools.vpe.editor.template.EditableTemplateAdapter;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.w3c.dom.Element;
public abstract class AbstractEditableRichFacesTemplate extends
- EditableTemplateAdapter {
+ VpeAbstractTemplate {
public String getAttribute(Element sourceElement, String attributeName) {
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/InputNumberSliderTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/InputNumberSliderTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/InputNumberSliderTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -17,7 +17,8 @@
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.AttributeData;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
@@ -281,24 +282,24 @@
.getBackgoundImgStyle(INPUT_BACKGROUND_IMAGE_PATH)
+ getAttribute(sourceElement, RichFaces.ATTR_INPUT_STYLE));
- VpeAttributeData attributeData;
+ NodeData attributeData;
if (sourceElement.hasAttribute(RichFaces.ATTR_VALUE)) {
inputField.setAttribute(HTML.ATTR_VALUE, sourceElement
.getAttribute(RichFaces.ATTR_VALUE));
- attributeData = new VpeAttributeData(sourceElement
+ attributeData = new NodeData(sourceElement
.getAttributeNode(RichFaces.ATTR_VALUE), inputField);
} else {
inputField.setAttribute(HTML.ATTR_VALUE, ""); //$NON-NLS-1$
- attributeData = new VpeAttributeData(RichFaces.ATTR_VALUE,
+ attributeData = new AttributeData(RichFaces.ATTR_VALUE,
inputField);
}
- elementData.addAttributeData(attributeData);
+ elementData.addNodeData(attributeData);
// get class attribute
String inputClass = null;
@@ -418,14 +419,14 @@
if (isShowBoundaryValues(sourceElement)) {
nsIDOMText minValueText;
- VpeAttributeData minValueData;
+ NodeData minValueData;
if (sourceElement.hasAttribute(MIN_VALUE_ATTR)) {
// create minValue text
minValueText = visualDocument.createTextNode(sourceElement
.getAttribute(MIN_VALUE_ATTR));
- minValueData = new VpeAttributeData(sourceElement
+ minValueData = new NodeData(sourceElement
.getAttributeNode(MIN_VALUE_ATTR), minValueText);
} else {
@@ -433,23 +434,23 @@
// create minValue text
minValueText = visualDocument.createTextNode(MIN_VALUE_DEFAULT);
- minValueData = new VpeAttributeData(MIN_VALUE_ATTR,
+ minValueData = new AttributeData(MIN_VALUE_ATTR,
minValueText);
}
// add text to td
minValueTd.appendChild(minValueText);
- elementData.addAttributeData(minValueData);
+ elementData.addNodeData(minValueData);
nsIDOMText maxValueText;
- VpeAttributeData maxValueData;
+ NodeData maxValueData;
if (sourceElement.hasAttribute(MAX_VALUE_ATTR)) {
// create minValue text
maxValueText = visualDocument.createTextNode(sourceElement
.getAttribute(MAX_VALUE_ATTR));
- maxValueData = new VpeAttributeData(sourceElement
+ maxValueData = new NodeData(sourceElement
.getAttributeNode(MAX_VALUE_ATTR), maxValueText);
} else {
@@ -457,13 +458,13 @@
// create minValue text
maxValueText = visualDocument.createTextNode(MAX_VALUE_DEFAULT);
- maxValueData = new VpeAttributeData(MAX_VALUE_ATTR,
+ maxValueData = new AttributeData(MAX_VALUE_ATTR,
maxValueText);
}
// add text to td
maxValueTd.appendChild(maxValueText);
- elementData.addAttributeData(maxValueData);
+ elementData.addNodeData(maxValueData);
}
valuesBlock.appendChild(minValueTd);
@@ -580,30 +581,4 @@
return true;
}
- /**
- *
- */
- public Node getTargetSourceNodeByVisualNode(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementMapping elementMapping) {
-
- // if element is not null
- if (elementMapping != null) {
-
- // get attributeData
- VpeAttributeData attributeData = getAttributeData(visualNode,
- elementMapping.getElementData());
-
- // attributeData is found
- if ((attributeData != null)
- && (attributeData.getSourceAttr() != null)) {
- return attributeData.getSourceAttr();
- } else
- return elementMapping.getSourceNode();
-
- }
-
- return null;
-
- }
-
}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesComboBoxTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesComboBoxTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesComboBoxTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -20,7 +20,8 @@
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.AttributeData;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -252,9 +253,9 @@
inputElement.setAttribute(HTML.ATTR_VALUE, getInputValue(sourceElement));
if ((sourceElement).hasAttribute(RichFaces.ATTR_VALUE)) {
- elementData.addAttributeData(new
VpeAttributeData(sourceElement.getAttributeNode(RichFaces.ATTR_VALUE), inputElement,
true));
+ elementData.addNodeData(new
AttributeData(sourceElement.getAttributeNode(RichFaces.ATTR_VALUE), inputElement, true));
} else {
- elementData.addAttributeData(new VpeAttributeData(RichFaces.ATTR_VALUE,
inputElement, true));
+ elementData.addNodeData(new AttributeData(RichFaces.ATTR_VALUE, inputElement,
true));
}
return inputElement;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSpinnerTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSpinnerTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSpinnerTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -14,7 +14,8 @@
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.AttributeData;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -187,10 +188,10 @@
.setAttribute(HTML.ATTR_VALUE, getInputValue(sourceElement));
if ((sourceElement).hasAttribute(RichFaces.ATTR_VALUE)) {
- elementData.addAttributeData(new VpeAttributeData(sourceElement
+ elementData.addNodeData(new NodeData(sourceElement
.getAttributeNode(RichFaces.ATTR_VALUE), inputElement, true));
} else {
- elementData.addAttributeData(new VpeAttributeData(
+ elementData.addNodeData(new AttributeData(
RichFaces.ATTR_VALUE, inputElement, true));
}
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 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -127,7 +127,10 @@
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
import org.jboss.tools.vpe.editor.selection.VpeSelectionHelper;
-import org.jboss.tools.vpe.editor.template.ITemplateSelectionManager;
+import org.jboss.tools.vpe.editor.template.IKeyEventHandler;
+import org.jboss.tools.vpe.editor.template.ISelectionManager;
+import org.jboss.tools.vpe.editor.template.KeyEventManager;
+import org.jboss.tools.vpe.editor.template.SelectionManager;
import org.jboss.tools.vpe.editor.template.VpeAnyData;
import org.jboss.tools.vpe.editor.template.VpeEditAnyDialog;
import org.jboss.tools.vpe.editor.template.VpeHtmlTemplate;
@@ -137,8 +140,7 @@
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
import org.jboss.tools.vpe.editor.util.DocTypeUtil;
-import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
-import org.jboss.tools.vpe.editor.util.TextUtil;
+import org.jboss.tools.vpe.editor.util.SelectionUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.jboss.tools.vpe.editor.util.VpeDndUtil;
import org.jboss.tools.vpe.messages.VpeUIMessages;
@@ -165,355 +167,391 @@
import org.w3c.dom.Text;
public class VpeController implements INodeAdapter, IModelLifecycleListener,
- INodeSelectionListener, ITextSelectionListener, SelectionListener,
- EditorDomEventListener, VpeTemplateListener, XModelTreeListener,
- ResourceReferenceListListener, ISelectionChangedListener,
- IVisualController {
+ INodeSelectionListener, ITextSelectionListener, SelectionListener,
+ EditorDomEventListener, VpeTemplateListener, XModelTreeListener,
+ ResourceReferenceListListener, ISelectionChangedListener,
+ IVisualController {
private boolean visualEditorVisible = true;
- private boolean synced = true;
- StructuredTextEditor sourceEditor;
- private MozillaEditor visualEditor;
- // MozillaBrowser browser;
- XulRunnerEditor xulRunnerEditor;
- // TODO Sergey Vasilyev figure out with nsIPressShell
- // private nsIPresShell presShell;
- // TODO Max Areshkau figure out with nsISelectionController
- private VpeSelectionController visualSelectionController;
- VpeDomMapping domMapping;
- private VpeTemplateManager templateManager;
- private VpeSourceDomBuilder sourceBuilder;
- private VpeVisualDomBuilder visualBuilder;
- private VpeSelectionBuilder selectionBuilder;
- private VpeVisualKeyHandler visualKeyHandler;
- private ActiveEditorSwitcher switcher = new ActiveEditorSwitcher();
- private Attr lastRemovedAttr;
- private String lastRemovedAttrName;
- private boolean mouseUpSelectionReasonFlag;
- private boolean mouseDownSelectionFlag;
- private boolean sourceChangeFlag;
- private VpePageContext pageContext;
- private BundleMap bundle;
- private VpeEditorPart editPart;
- private static final int AROUND_MENU = 1;
- private static final int BEFORE_MENU = 2;
- private static final int AFTER_MENU = 3;
+ private boolean synced = true;
+ StructuredTextEditor sourceEditor;
+ private MozillaEditor visualEditor;
+ // MozillaBrowser browser;
+ XulRunnerEditor xulRunnerEditor;
+ // TODO Sergey Vasilyev figure out with nsIPressShell
+ // private nsIPresShell presShell;
+ // TODO Max Areshkau figure out with nsISelectionController
+ private VpeSelectionController visualSelectionController;
+ VpeDomMapping domMapping;
+ private VpeTemplateManager templateManager;
+ private VpeSourceDomBuilder sourceBuilder;
+ private VpeVisualDomBuilder visualBuilder;
+ /**
+ * @deprecated
+ */
+ private VpeSelectionBuilder selectionBuilder;
+ // private VpeVisualKeyHandler visualKeyHandler;
+ private ActiveEditorSwitcher switcher = new ActiveEditorSwitcher();
+ private Attr lastRemovedAttr;
+ private String lastRemovedAttrName;
+ private boolean mouseUpSelectionReasonFlag;
+ private boolean mouseDownSelectionFlag;
+ private boolean sourceChangeFlag;
+ private VpePageContext pageContext;
+ private BundleMap bundle;
+ private VpeEditorPart editPart;
+ private static final int AROUND_MENU = 1;
+ private static final int BEFORE_MENU = 2;
+ private static final int AFTER_MENU = 3;
- private CSSReferenceList cssReferenceListListener;
- private TaglibReferenceList taglibReferenceListListener;
- private AbsoluteFolderReferenceList absoluteFolderReferenceListListener;
- private RelativeFolderReferenceList relativeFolderReferenceListListener;
- private VpeIncludeList includeList = new VpeIncludeList();
- private VpeVisualInnerDragInfo innerDragInfo = null;
- private FormatControllerManager toolbarFormatControllerManager = null;
- private SelectionBar selectionBar = null;
- private XModelTreeListenerSWTSync optionsListener;
- // Added by Max Areshkau Fix for JBIDE-1479
- private UIJob job = null;
- private IProgressMonitor progressMonitor;
+ private CSSReferenceList cssReferenceListListener;
+ private TaglibReferenceList taglibReferenceListListener;
+ private AbsoluteFolderReferenceList absoluteFolderReferenceListListener;
+ private RelativeFolderReferenceList relativeFolderReferenceListListener;
+ private VpeIncludeList includeList = new VpeIncludeList();
+ private VpeVisualInnerDragInfo innerDragInfo = null;
+ private FormatControllerManager toolbarFormatControllerManager = null;
+ private SelectionBar selectionBar = null;
+ private XModelTreeListenerSWTSync optionsListener;
+ // Added by Max Areshkau Fix for JBIDE-1479
+ private UIJob job = null;
+ private IProgressMonitor progressMonitor;
private UIJob uiJob;
- //JBIDE-675, visual refresh job
+ // JBIDE-675, visual refresh job
private UIJob visualRefresfJob;
-
+
/**
- * Added by Max Areshkau
- * JBIDE-675, stores information about modification events
+ * Added by Max Areshkau JBIDE-675, stores information about modification
+ * events
*/
private LinkedList<VpeEventBean> changeEvents;
-
- Shell tip;
- public final static String MODEL_FLAVOR = ModelTransfer.MODEL;
+ Shell tip;
- public VpeController(VpeEditorPart editPart) {
+ /**
+ * selectionManager is used for management of selection
+ */
+ private ISelectionManager selectionManager;
- this.editPart = editPart;
- dropWindow = new VpeDropWindow(editPart.getSite().getShell());
- }
+ /**
+ * keyEventHandler is used for management of key events
+ */
+ private IKeyEventHandler keyEventHandler;
- void init(StructuredTextEditor sourceEditor, MozillaEditor visualEditor)
- throws Exception {
- this.sourceEditor = sourceEditor;
- if (sourceEditor instanceof IJSPTextEditor) {
- ((IJSPTextEditor) sourceEditor).setVPEController(this);
- dropWindow.setEditor((IJSPTextEditor) sourceEditor);
+ public final static String MODEL_FLAVOR = ModelTransfer.MODEL;
+
+ public VpeController(VpeEditorPart editPart) {
+
+ this.editPart = editPart;
+ dropWindow = new VpeDropWindow(editPart.getSite().getShell());
}
- this.visualEditor = visualEditor;
- visualEditor.setController(this);
- templateManager = VpeTemplateManager.getInstance();
- bundle = new BundleMap();
- bundle.init(sourceEditor);
- pageContext = new VpePageContext(templateManager, bundle, editPart);
- domMapping = new VpeDomMapping(pageContext);
- sourceBuilder = new VpeSourceDomBuilder(domMapping, this,
- templateManager, sourceEditor, pageContext);
- visualBuilder = new VpeVisualDomBuilder(domMapping, this,
- templateManager, visualEditor, pageContext);
- pageContext.setSourceDomBuilder(sourceBuilder);
- pageContext.setVisualDomBuilder(visualBuilder);
- IDOMModel sourceModel = (IDOMModel) getModel();
- if (sourceModel == null) {
- return;
- }
- sourceModel.addModelLifecycleListener(this);
- IDOMDocument sourceDocument = sourceModel.getDocument();
- visualBuilder.refreshExternalLinks();
- visualBuilder.buildDom(sourceDocument);
- templateManager.addTemplateListener(this);
+ void init(StructuredTextEditor sourceEditor, MozillaEditor visualEditor)
+ throws Exception {
+ this.sourceEditor = sourceEditor;
+ if (sourceEditor instanceof IJSPTextEditor) {
+ ((IJSPTextEditor) sourceEditor).setVPEController(this);
+ dropWindow.setEditor((IJSPTextEditor) sourceEditor);
+ }
+ this.visualEditor = visualEditor;
+ visualEditor.setController(this);
+ templateManager = VpeTemplateManager.getInstance();
+ bundle = new BundleMap();
+ bundle.init(sourceEditor);
+ pageContext = new VpePageContext(templateManager, bundle, editPart);
+ domMapping = new VpeDomMapping(pageContext);
+ sourceBuilder = new VpeSourceDomBuilder(domMapping, this,
+ templateManager, sourceEditor, pageContext);
+ visualBuilder = new VpeVisualDomBuilder(domMapping, this,
+ templateManager, visualEditor, pageContext);
+ pageContext.setSourceDomBuilder(sourceBuilder);
+ pageContext.setVisualDomBuilder(visualBuilder);
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ if (sourceModel == null) {
+ return;
+ }
+ sourceModel.addModelLifecycleListener(this);
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ visualBuilder.refreshExternalLinks();
+ visualBuilder.buildDom(sourceDocument);
- xulRunnerEditor = visualEditor.getXulRunnerEditor();
- // TODO Sergey Vasilyev figure out with nsIPressShell
- // presShell = browser.getPresShell();
- visualSelectionController = new VpeSelectionController(xulRunnerEditor
- .getSelection());
- selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
- visualBuilder, visualSelectionController);
- visualKeyHandler = new VpeVisualKeyHandler(sourceEditor, domMapping,
- pageContext) {
- public void doSave(IProgressMonitor monitor) {
- editPart.doSave(monitor);
- }
- };
+ templateManager.addTemplateListener(this);
- // glory
- ISelectionProvider provider = sourceEditor.getSelectionProvider();
- // Max Areshkau JBIDE-1105 If selection event received after selection
- // in
- // visual part we lost focus of selection, so we should process
- // selection event
- // in time of selection
- // if (provider instanceof IPostSelectionProvider)
- // ((IPostSelectionProvider)
- // provider).addPostSelectionChangedListener(this);
- // else
- provider.addSelectionChangedListener(this);
+ xulRunnerEditor = visualEditor.getXulRunnerEditor();
+ // TODO Sergey Vasilyev figure out with nsIPressShell
+ // presShell = browser.getPresShell();
+ visualSelectionController = new VpeSelectionController(xulRunnerEditor
+ .getSelection());
- // ViewerSelectionManager selectionManager =
- // sourceEditor.getViewerSelectionManager();
- // selectionManager.addNodeSelectionListener(this);
- // selectionManager.addTextSelectionListener(this);
- StyledText textWidget = VpeSelectionHelper
- .getSourceTextWidget(sourceEditor);
- if (textWidget != null) {
- textWidget.addSelectionListener(this);
- }
+ selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
+ visualBuilder, visualSelectionController);
- visualEditor.setEditorDomEventListener(this);
- switcher.initActiveEditor();
+ selectionManager = new SelectionManager(pageContext,
+ sourceEditor, visualSelectionController);
- if (optionsListener == null) {
- XModelObject optionsObject = ModelUtilities.getPreferenceModel()
- .getByPath(VpePreference.EDITOR_PATH);
- optionsListener = new XModelTreeListenerSWTSync(this);
- optionsObject.getModel().addModelTreeListener(optionsListener);
- }
+ keyEventHandler = new KeyEventManager(sourceEditor, domMapping,
+ pageContext);
- cssReferenceListListener = CSSReferenceList.getInstance();
- cssReferenceListListener.addChangeListener(this);
+ // visualKeyHandler = new VpeVisualKeyHandler(sourceEditor, domMapping,
+ // pageContext) {
+ // public void doSave(IProgressMonitor monitor) {
+ // editPart.doSave(monitor);
+ // }
+ // };
- taglibReferenceListListener = TaglibReferenceList.getInstance();
- taglibReferenceListListener.addChangeListener(this);
+ // glory
+ ISelectionProvider provider = sourceEditor.getSelectionProvider();
+ // Max Areshkau JBIDE-1105 If selection event received after selection
+ // in
+ // visual part we lost focus of selection, so we should process
+ // selection event
+ // in time of selection
+ // if (provider instanceof IPostSelectionProvider)
+ // ((IPostSelectionProvider)
+ // provider).addPostSelectionChangedListener(this);
+ // else
+ provider.addSelectionChangedListener(this);
- absoluteFolderReferenceListListener = AbsoluteFolderReferenceList
- .getInstance();
- absoluteFolderReferenceListListener.addChangeListener(this);
+ // ViewerSelectionManager selectionManager =
+ // sourceEditor.getViewerSelectionManager();
+ // selectionManager.addNodeSelectionListener(this);
+ // selectionManager.addTextSelectionListener(this);
+ StyledText textWidget = VpeSelectionHelper
+ .getSourceTextWidget(sourceEditor);
+ if (textWidget != null) {
+ textWidget.addSelectionListener(this);
+ }
- relativeFolderReferenceListListener = RelativeFolderReferenceList
- .getInstance();
- relativeFolderReferenceListListener.addChangeListener(this);
+ visualEditor.setEditorDomEventListener(this);
+ switcher.initActiveEditor();
- // pageContext.fireTaglibsChanged();
- }
+ if (optionsListener == null) {
+ XModelObject optionsObject = ModelUtilities.getPreferenceModel()
+ .getByPath(VpePreference.EDITOR_PATH);
+ optionsListener = new XModelTreeListenerSWTSync(this);
+ optionsObject.getModel().addModelTreeListener(optionsListener);
+ }
- public void dispose() {
-
- if (job != null) {
+ cssReferenceListListener = CSSReferenceList.getInstance();
+ cssReferenceListListener.addChangeListener(this);
+
+ taglibReferenceListListener = TaglibReferenceList.getInstance();
+ taglibReferenceListListener.addChangeListener(this);
+
+ absoluteFolderReferenceListListener = AbsoluteFolderReferenceList
+ .getInstance();
+ absoluteFolderReferenceListListener.addChangeListener(this);
+
+ relativeFolderReferenceListListener = RelativeFolderReferenceList
+ .getInstance();
+ relativeFolderReferenceListListener.addChangeListener(this);
+
+ // pageContext.fireTaglibsChanged();
+ }
+
+ public void dispose() {
+
+ if (job != null) {
job.cancel();
job = null;
}
-
- if(uiJob!=null) {
- uiJob.cancel();
- getChangeEvents().clear();
- uiJob=null;
- }
-
- if(visualRefresfJob!=null) {
- visualRefresfJob.cancel();
- visualRefresfJob=null;
- }
-
- if (optionsListener != null) {
- XModelObject optionsObject = ModelUtilities.getPreferenceModel()
- .getByPath(VpePreference.EDITOR_PATH);
- optionsObject.getModel().removeModelTreeListener(optionsListener);
- optionsListener.dispose();
- optionsListener = null;
- }
- IDOMModel sourceModel = (IDOMModel) getModel();
- if (sourceModel != null) {
- sourceModel.removeModelLifecycleListener(this);
- }
- switcher.destroyActiveEditor();
- switcher = null;
- if (templateManager != null) {
- templateManager.removeTemplateListener(this);
- templateManager = null;
- }
- if (visualBuilder != null) {
- visualBuilder.dispose();
- visualBuilder = null;
- }
- sourceBuilder = null;
- if (sourceEditor != null) {
- // glory
- ISelectionProvider provider = sourceEditor.getSelectionProvider();
- provider.removeSelectionChangedListener(this);
- // ViewerSelectionManager selectionManager =
- // sourceEditor.getViewerSelectionManager();
- // selectionManager.removeNodeSelectionListener(this);
- // selectionManager.removeTextSelectionListener(this);
- StyledText textWidget = VpeSelectionHelper
- .getSourceTextWidget(sourceEditor);
- if (textWidget != null) {
- textWidget.removeSelectionListener(this);
- }
- ((IJSPTextEditor) sourceEditor).setVPEController(null);
+ if (uiJob != null) {
+ uiJob.cancel();
+ getChangeEvents().clear();
+ uiJob = null;
+ }
+ if (visualRefresfJob != null) {
+ visualRefresfJob.cancel();
+ visualRefresfJob = null;
+ }
+
+ if (optionsListener != null) {
+ XModelObject optionsObject = ModelUtilities.getPreferenceModel()
+ .getByPath(VpePreference.EDITOR_PATH);
+ optionsObject.getModel().removeModelTreeListener(optionsListener);
+ optionsListener.dispose();
+ optionsListener = null;
+ }
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ if (sourceModel != null) {
+ sourceModel.removeModelLifecycleListener(this);
+ }
+ switcher.destroyActiveEditor();
+ switcher = null;
+
+ if (templateManager != null) {
+ templateManager.removeTemplateListener(this);
+ templateManager = null;
+ }
+ if (visualBuilder != null) {
+ visualBuilder.dispose();
+ visualBuilder = null;
+ }
+ sourceBuilder = null;
+ if (sourceEditor != null) {
+ // glory
+ ISelectionProvider provider = sourceEditor.getSelectionProvider();
+ provider.removeSelectionChangedListener(this);
+ // ViewerSelectionManager selectionManager =
+ // sourceEditor.getViewerSelectionManager();
+ // selectionManager.removeNodeSelectionListener(this);
+ // selectionManager.removeTextSelectionListener(this);
+ StyledText textWidget = VpeSelectionHelper
+ .getSourceTextWidget(sourceEditor);
+ if (textWidget != null) {
+ textWidget.removeSelectionListener(this);
+ }
+ ((IJSPTextEditor) sourceEditor).setVPEController(null);
+
+ }
+ if (dropWindow != null) {
+ dropWindow.setEditor(null);
+ }
+ if (visualEditor != null) {
+ visualEditor.setEditorDomEventListener(null);
+ if (visualSelectionController != null) {
+ // visualSelectionController.Release();
+ visualSelectionController = null;
+ }
+ // TODO Sergey Vasilyev figure out with Press Shell
+ // if (presShell != null) {
+ // presShell.Release();
+ // presShell = null;
+ // }
+ visualEditor = null;
+ }
+
+ if (cssReferenceListListener != null) {
+ cssReferenceListListener.removeChangeListener(this);
+ }
+ if (taglibReferenceListListener != null) {
+ taglibReferenceListListener.removeChangeListener(this);
+ }
+ if (absoluteFolderReferenceListListener != null) {
+ absoluteFolderReferenceListListener.removeChangeListener(this);
+ }
+ if (relativeFolderReferenceListListener != null) {
+ relativeFolderReferenceListListener.removeChangeListener(this);
+ }
+ toolbarFormatControllerManager = null;
}
- if (dropWindow != null) {
- dropWindow.setEditor(null);
- }
- if (visualEditor != null) {
- visualEditor.setEditorDomEventListener(null);
- if (visualSelectionController != null) {
- // visualSelectionController.Release();
- visualSelectionController = null;
- }
- // TODO Sergey Vasilyev figure out with Press Shell
- // if (presShell != null) {
- // presShell.Release();
- // presShell = null;
- // }
- visualEditor = null;
- }
- if (cssReferenceListListener != null) {
- cssReferenceListListener.removeChangeListener(this);
+ // INodeAdapter implementation
+ public boolean isAdapterForType(Object type) {
+ return type == this;
}
- if (taglibReferenceListListener != null) {
- taglibReferenceListListener.removeChangeListener(this);
- }
- if (absoluteFolderReferenceListListener != null) {
- absoluteFolderReferenceListListener.removeChangeListener(this);
- }
- if (relativeFolderReferenceListListener != null) {
- relativeFolderReferenceListListener.removeChangeListener(this);
- }
- toolbarFormatControllerManager = null;
- }
- // INodeAdapter implementation
- public boolean isAdapterForType(Object type) {
- return type == this;
- }
- // FIX Fox JBIDE-1479 added by Max Areshkau
- public void notifyChanged(final INodeNotifier notifier,
- final int eventType, final Object feature, final Object oldValue,
- final Object newValue, final int pos) {
+ // FIX Fox JBIDE-1479 added by Max Areshkau
+ public void notifyChanged(final INodeNotifier notifier,
+ final int eventType, final Object feature, final Object oldValue,
+ final Object newValue, final int pos) {
- if (!visualEditorVisible) {
- synced = false;
- return;
- }
+ if (!visualEditorVisible) {
+ synced = false;
+ return;
+ }
- // start job when we modify file in ui thread, without this code
- // changes will be applied with 1 second delay
- Display display = null;
- if (PlatformUI.isWorkbenchRunning())
- display = PlatformUI.getWorkbench().getDisplay();
+ // start job when we modify file in ui thread, without this code
+ // changes will be applied with 1 second delay
+ Display display = null;
+ if (PlatformUI.isWorkbenchRunning())
+ display = PlatformUI.getWorkbench().getDisplay();
- if (display != null && (Thread.currentThread() == display.getThread())) {
+ if (display != null && (Thread.currentThread() == display.getThread())) {
- getChangeEvents().addLast(new VpeEventBean(notifier, eventType, feature,
oldValue,newValue, pos));
- if(uiJob==null) {
- uiJob = new UIJob(VpeUIMessages.VPE_UPDATE_JOB_TITLE){
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
+ getChangeEvents().addLast(
+ new VpeEventBean(notifier, eventType, feature, oldValue,
+ newValue, pos));
+ if (uiJob == null) {
+ uiJob = new UIJob(VpeUIMessages.VPE_UPDATE_JOB_TITLE) {
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
- monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE, 100);
- while(getChangeEvents().size()>0) {
+ monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE,
+ 100);
+ while (getChangeEvents().size() > 0) {
- monitor.worked((int)(100/getChangeEvents().size()));
- VpeEventBean eventBean = getChangeEvents().getFirst();
- if (monitor.isCanceled()) {
- getChangeEvents().clear();
- return Status.CANCEL_STATUS;
- }
- try {
- notifyChangedInUiThread(eventBean.getNotifier(), eventBean.getEventType(),
- eventBean.getFeature(), eventBean.getOldValue(), eventBean.getNewValue(),
- eventBean.getPos());
- } catch (VpeDisposeException ex) {
- //JBIDE-675 we will get this exception if user close editor,
- //when update visual editor job is running, we shoud ignore this
- //exception
- break;
- } catch (NullPointerException ex) {
-
- if(switcher!=null ) {
- throw ex;
- } else {
- //class was disposed and exception result of that we can't stop
- //refresh job in time, so we just ignore this exception
+ monitor.worked((int) (100 / getChangeEvents()
+ .size()));
+ VpeEventBean eventBean = getChangeEvents()
+ .getFirst();
+ if (monitor.isCanceled()) {
+ getChangeEvents().clear();
+ return Status.CANCEL_STATUS;
+ }
+ try {
+ notifyChangedInUiThread(
+ eventBean.getNotifier(), eventBean
+ .getEventType(), eventBean
+ .getFeature(), eventBean
+ .getOldValue(), eventBean
+ .getNewValue(), eventBean
+ .getPos());
+ } catch (VpeDisposeException ex) {
+ // JBIDE-675 we will get this exception if user
+ // close editor,
+ // when update visual editor job is running, we
+ // shoud ignore this
+ // exception
+ break;
+ } catch (NullPointerException ex) {
+
+ if (switcher != null) {
+ throw ex;
+ } else {
+ // class was disposed and exception result
+ // of that we can't stop
+ // refresh job in time, so we just ignore
+ // this exception
+ }
+ }
+ getChangeEvents().remove(eventBean);
}
- }
- getChangeEvents().remove(eventBean);
- }
- monitor.done();
-
- return Status.OK_STATUS;
- }
-
- };
- }
- if(uiJob.getState()!=Job.RUNNING) {
-
- uiJob.setPriority(Job.LONG);
- //Fix of JBIDE-1900
- uiJob.cancel();
- uiJob.schedule(400L);
- }
-
- return;
- }
- // start job when we modify file in non ui thread
- if (job != null) {
- job.cancel();
- }
+ sourceSelectionChanged();
+ monitor.done();
- job = new UIJob("NotifyChangedJob") {
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- // we checks is job was canceled and if is it true we cancel job
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- } else {
- notifyChangedInUiThread(notifier, eventType, feature,
- oldValue, newValue, pos);
- }
- return Status.OK_STATUS;
- }
- };
- job.setPriority(Job.LONG);
- job.schedule(1000L);
- }
+ return Status.OK_STATUS;
+ }
-
- public void notifyChangedInUiThread(INodeNotifier notifier, int eventType,
+ };
+ }
+
+ if (uiJob.getState() != Job.RUNNING) {
+
+ uiJob.setPriority(Job.LONG);
+ // Fix of JBIDE-1900
+ uiJob.cancel();
+ uiJob.schedule(400L);
+ }
+
+ return;
+ }
+ // start job when we modify file in non ui thread
+ if (job != null) {
+ job.cancel();
+ }
+
+ job = new UIJob("NotifyChangedJob") {
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ // we checks is job was canceled and if is it true we cancel job
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ } else {
+ notifyChangedInUiThread(notifier, eventType, feature,
+ oldValue, newValue, pos);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setPriority(Job.LONG);
+ job.schedule(1000L);
+ }
+
+ public void notifyChangedInUiThread(INodeNotifier notifier, int eventType,
Object feature, Object oldValue, Object newValue, int pos) {
if (switcher == null
|| !switcher
@@ -603,22 +641,21 @@
}
break;
}
- }
- finally {
- //fix for jbide-675, swithcer is null when vpecontroller is disposed
-
- if(switcher!=null) {
-
+ } finally {
+ // fix for jbide-675, swithcer is null when vpecontroller is
+ // disposed
+
+ if (switcher != null) {
switcher.stopActiveEditor();
} else {
-
+
throw new VpeDisposeException("VpeController already disposed");
}
}
}
- // INodeSelectionListener implementation
- public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
+ // INodeSelectionListener implementation
+ public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
@@ -642,9 +679,9 @@
}
}
- // ITextSelectionListener implementation
- // TODO Max Areshau looks like this method don't used
- public void textSelectionChanged(TextSelectionChangedEvent event) {
+ // ITextSelectionListener implementation
+ // TODO Max Areshau looks like this method don't used
+ public void textSelectionChanged(TextSelectionChangedEvent event) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
@@ -664,8 +701,8 @@
}
}
- // SelectionListener implementation
- public void widgetSelected(SelectionEvent event) {
+ // SelectionListener implementation
+ public void widgetSelected(SelectionEvent event) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
@@ -684,109 +721,117 @@
}
}
- public void widgetDefaultSelected(SelectionEvent event) {
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>>
widgetDefaultSelected"); //$NON-NLS-1$
+ public void widgetDefaultSelected(SelectionEvent event) {
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>>
widgetDefaultSelected"); //$NON-NLS-1$
+ }
}
- }
- public void sourceSelectionChanged() {
- sourceSelectionChanged(false);
- }
+ public void sourceSelectionChanged() {
+ sourceSelectionChanged(false);
+ }
- public void sourceSelectionChanged(boolean showCaret) {
-
- //we should processed if we have correct view in visual editor,
- //otherwise we shouldn't process this event
- if(getChangeEvents().size()>0) {
-
- return;
- }
-
- Point range = sourceEditor.getTextViewer().getSelectedRange();
- int anchorPosition = range.x;
- int focusPosition = range.x + range.y;
+ public void sourceSelectionChanged(boolean showCaret) {
- boolean extendFlag = range.y != 0;
- boolean reversionFlag = extendFlag
- && anchorPosition == VpeSelectionHelper
- .getCaretOffset(sourceEditor);
- if (reversionFlag) {
- anchorPosition = focusPosition;
- focusPosition = range.x;
- }
+ // we should processed if we have correct view in visual editor,
+ // otherwise we shouldn't process this event
+ if (getChangeEvents().size() > 0) {
- VpeTemplate template = TemplateManagingUtil
- .getTemplateBySourceSelection(pageContext, focusPosition,
- anchorPosition);
+ return;
+ }
- if (template instanceof ITemplateSelectionManager) {
- ((ITemplateSelectionManager) template).setSelectionBySource(
- pageContext, visualSelectionController, focusPosition,
- anchorPosition);
- return;
- }
+// Point range = sourceEditor.getTextViewer().getSelectedRange();
+// int anchorPosition = range.x;
+// int focusPosition = range.x + range.y;
+//
+// boolean extendFlag = range.y != 0;
+// boolean reversionFlag = extendFlag
+// && anchorPosition == VpeSelectionHelper
+// .getCaretOffset(sourceEditor);
+// if (reversionFlag) {
+// anchorPosition = focusPosition;
+// focusPosition = range.x;
+// }
- Node focusNode = getSourceNodeAt(focusPosition);
- if (focusNode == null) {
- return;
- }
- int focusOffset = getSourceNodeOffset(focusNode, focusPosition,
- extendFlag && !reversionFlag);
- Node anchorNode = null;
- int anchorOffset = 0;
- if (extendFlag) {
- anchorNode = getSourceNodeAt(anchorPosition);
- anchorOffset = getSourceNodeOffset(anchorNode, anchorPosition,
- reversionFlag);
- } else {
- anchorNode = focusNode;
- anchorOffset = focusOffset;
- }
+ try {
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println("sourceSelectionChanged"); //$NON-NLS-1$
- System.out
- .println(" anchorNode: " + anchorNode.getNodeName() +
" anchorOffset: " + anchorOffset); //$NON-NLS-1$ //$NON-NLS-2$
- System.out
- .println(" focusNode: " + focusNode.getNodeName() + "
focusOffset: " + focusOffset + " focusPosition: " + focusPosition);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- try {
- if (anchorNode.getNodeType() == Node.TEXT_NODE
- || anchorNode.getNodeType() == Node.ATTRIBUTE_NODE) {
- String text;
- if (anchorNode.getNodeType() == Node.TEXT_NODE) {
- IndexedRegion region = (IndexedRegion) anchorNode;
- text = sourceEditor.getTextViewer().getDocument().get(
- region.getStartOffset(),
- region.getEndOffset() - region.getStartOffset());
- } else {
- text = ((AttrImpl) anchorNode).getValueRegionText();
+ selectionManager.refreshVisualSelection();
+
+ } catch (Exception ex) {
+ VpePlugin.reportProblem(ex);
}
- anchorOffset = TextUtil.visualPosition(text, anchorOffset);
- }
- if (focusNode.getNodeType() == Node.TEXT_NODE
- || focusNode.getNodeType() == Node.ATTRIBUTE_NODE) {
- IndexedRegion region = (IndexedRegion) focusNode;
- String text;
- if (focusNode.getNodeType() == Node.TEXT_NODE) {
- text = sourceEditor.getTextViewer().getDocument().get(
- region.getStartOffset(),
- region.getEndOffset() - region.getStartOffset());
- } else {
- text = ((AttrImpl) focusNode).getValueRegionText();
- }
- focusOffset = TextUtil.visualPosition(text, focusOffset);
- }
- } catch (Exception ex) {
- VpePlugin.reportProblem(ex);
+
+ // VpeTemplate template = TemplateManagingUtil
+ // .getTemplateBySourceSelection(pageContext, focusPosition,
+ // anchorPosition);
+ //
+ // if (template instanceof ITemplateSelectionManager) {
+ // ((ITemplateSelectionManager) template).setSelectionBySource(
+ // pageContext, visualSelectionController, focusPosition,
+ // anchorPosition);
+ // return;
+ // }
+ //
+ // Node focusNode = getSourceNodeAt(focusPosition);
+ // if (focusNode == null) {
+ // return;
+ // }
+ // int focusOffset = getSourceNodeOffset(focusNode, focusPosition,
+ // extendFlag && !reversionFlag);
+ // Node anchorNode = null;
+ // int anchorOffset = 0;
+ // if (extendFlag) {
+ // anchorNode = getSourceNodeAt(anchorPosition);
+ // anchorOffset = getSourceNodeOffset(anchorNode, anchorPosition,
+ // reversionFlag);
+ // } else {
+ // anchorNode = focusNode;
+ // anchorOffset = focusOffset;
+ // }
+ //
+ // if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ // System.out.println("sourceSelectionChanged"); //$NON-NLS-1$
+ // System.out
+ // .println(" anchorNode: " + anchorNode.getNodeName() +
" anchorOffset: " + anchorOffset); //$NON-NLS-1$ //$NON-NLS-2$
+ // System.out
+ // .println(" focusNode: " + focusNode.getNodeName() +
" focusOffset: " + focusOffset + " focusPosition: " +
focusPosition); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ // }
+ // try {
+ // if (anchorNode.getNodeType() == Node.TEXT_NODE
+ // || anchorNode.getNodeType() == Node.ATTRIBUTE_NODE) {
+ // String text;
+ // if (anchorNode.getNodeType() == Node.TEXT_NODE) {
+ // IndexedRegion region = (IndexedRegion) anchorNode;
+ // text = sourceEditor.getTextViewer().getDocument().get(
+ // region.getStartOffset(),
+ // region.getEndOffset() - region.getStartOffset());
+ // } else {
+ // text = ((AttrImpl) anchorNode).getValueRegionText();
+ // }
+ // anchorOffset = TextUtil.visualPosition(text, anchorOffset);
+ // }
+ // if (focusNode.getNodeType() == Node.TEXT_NODE
+ // || focusNode.getNodeType() == Node.ATTRIBUTE_NODE) {
+ // IndexedRegion region = (IndexedRegion) focusNode;
+ // String text;
+ // if (focusNode.getNodeType() == Node.TEXT_NODE) {
+ // text = sourceEditor.getTextViewer().getDocument().get(
+ // region.getStartOffset(),
+ // region.getEndOffset() - region.getStartOffset());
+ // } else {
+ // text = ((AttrImpl) focusNode).getValueRegionText();
+ // }
+ // focusOffset = TextUtil.visualPosition(text, focusOffset);
+ // }
+ // } catch (Exception ex) {
+ // VpePlugin.reportProblem(ex);
+ // }
+ //
+ // selectionBuilder.setVisualSelection(anchorNode, anchorOffset,
+ // focusNode, focusOffset, reversionFlag, showCaret);
}
- selectionBuilder.setVisualSelection(anchorNode, anchorOffset,
- focusNode, focusOffset, reversionFlag, showCaret);
- }
-
- public void sourceSelectionToVisualSelection(boolean showCaret) {
+ public void sourceSelectionToVisualSelection(boolean showCaret) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
@@ -800,11 +845,11 @@
}
}
- // IModelLifecycleListener implementation
- public void processPreModelEvent(ModelLifecycleEvent event) {
- }
+ // IModelLifecycleListener implementation
+ public void processPreModelEvent(ModelLifecycleEvent event) {
+ }
- public void processPostModelEvent(ModelLifecycleEvent event) {
+ public void processPostModelEvent(ModelLifecycleEvent event) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
@@ -846,8 +891,8 @@
}
}
- // EditorDomEventListener implementation
- public void subtreeModified(nsIDOMMutationEvent mutationEvent) {
+ // EditorDomEventListener implementation
+ public void subtreeModified(nsIDOMMutationEvent mutationEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
@@ -863,7 +908,7 @@
}
}
- public void nodeInserted(nsIDOMMutationEvent mutationEvent) {
+ public void nodeInserted(nsIDOMMutationEvent mutationEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
@@ -884,7 +929,7 @@
}
}
- public void nodeRemoved(nsIDOMMutationEvent mutationEvent) {
+ public void nodeRemoved(nsIDOMMutationEvent mutationEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
@@ -906,7 +951,7 @@
}
}
- public void nodeRemovedFromDocument(nsIDOMMutationEvent mutationEvent) {
+ public void nodeRemovedFromDocument(nsIDOMMutationEvent mutationEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
@@ -922,7 +967,7 @@
}
}
- public void nodeInsertedIntoDocument(nsIDOMMutationEvent mutationEvent) {
+ public void nodeInsertedIntoDocument(nsIDOMMutationEvent mutationEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
@@ -938,42 +983,42 @@
}
}
- public void attrModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher
- .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- } finally {
- switcher.stopActiveEditor();
- }
- }
+ public void attrModified(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher
+ .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
- public void characterDataModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher
- .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
- sourceBuilder.setText(targetNode);
- visualBuilder.resetPseudoElement(targetNode);
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- } finally {
- switcher.stopActiveEditor();
- }
- }
+ public void characterDataModified(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher
+ .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
+ sourceBuilder.setText(targetNode);
+ visualBuilder.resetPseudoElement(targetNode);
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
- public void notifySelectionChanged(nsIDOMDocument doc,
+ public void notifySelectionChanged(nsIDOMDocument doc,
nsISelection selection, short reason) {
if (switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
@@ -981,14 +1026,24 @@
mouseUpSelectionReasonFlag = (reason & nsISelectionListener.MOUSEUP_REASON) >
0;
if (mouseUpSelectionReasonFlag
|| reason == nsISelectionListener.NO_REASON
- || reason == nsISelectionListener.KEYPRESS_REASON
+// || reason == nsISelectionListener.KEYPRESS_REASON
|| reason == nsISelectionListener.SELECTALL_REASON
|| (reason & nsISelectionListener.MOUSEDOWN_REASON) > 0) {
+
if (VpeDebug.PRINT_VISUAL_SELECTION_EVENT) {
System.out
.println("<<< notifySelectionChanged: " + reason);
//$NON-NLS-1$
+
}
- selectionBuilder.setSelection(selection);
+
+ nsIDOMNode node = SelectionUtil.getSelectedNode(selection);
+ if (node != null
+ && node.getNodeType() == nsIDOMNode.TEXT_NODE) {
+
+ // selectionBuilder.setSelection(selection);
+
+ selectionManager.setSelection(selection);
+ }
}
} catch (Exception e) {
VpePlugin.reportProblem(e);
@@ -998,65 +1053,82 @@
}
}
- public void mouseDown(nsIDOMMouseEvent mouseEvent) {
+ public void mouseDown(nsIDOMMouseEvent mouseEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
- mouseDownSelectionFlag = false;
- VpeTemplate template = TemplateManagingUtil
- .getTemplateByVisualSelection(pageContext, VisualDomUtil
- .getTargetNode(mouseEvent));
- if (template instanceof ITemplateSelectionManager) {
- ((ITemplateSelectionManager) template).setSelectionByMouse(
- pageContext, visualSelectionController, mouseEvent);
- mouseDownSelectionFlag = true;
- } else {
- nsIDOMElement visualDragElement = selectionBuilder
- .getDragElement(mouseEvent);
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- nsIDOMNode visualNode = VisualDomUtil
- .getTargetNode(mouseEvent);
- System.out
- .println("<<< mouseDown targetNode: " +
visualNode.getNodeName() + " (" + visualNode + ") selectedElement: "
+ (visualDragElement != null ? visualDragElement.getNodeName() + " (" +
visualDragElement + ")" : null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$ //$NON-NLS-5$
- }
+ // mouseDownSelectionFlag = false;
+ // VpeTemplate template = TemplateManagingUtil
+ // .getTemplateByVisualSelection(pageContext, VisualDomUtil
+ // .getTargetNode(mouseEvent));
+ // if (template instanceof ITemplateSelectionManager) {
+ // ((ITemplateSelectionManager) template).setSelectionByMouse(
+ // pageContext, visualSelectionController, mouseEvent);
+ // mouseDownSelectionFlag = true;
+ // } else {
+ // nsIDOMElement visualDragElement = selectionBuilder
+ // .getDragElement(mouseEvent);
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ System.out.println("<<< mouseDown targetNode: " /*
+ * +visualNode.
+ * getNodeName()
+ * + " (" +
+ * visualNode +
+ * ") selectedElement: "
+ * +(
+ * visualDragElement
+ * != null ?
+ * visualDragElement
+ * .
+ * getNodeName()
+ * + " (" +
+ * visualDragElement
+ * + ")" : null)
+ */); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
//$NON-NLS-5$
+ }
+ //
+ // if (visualDragElement != null) {
+ //
+ // // we shouldn't change selection when we click on <input
+ // // type="text" /> element,
+ // // because if we change after resizing the input element
+ // // lost
+ // // selection
+ // // if(!(HTML.TAG_INPUT.equalsIgnoreCase(visualDragElement.
+ // // getNodeName())&&
+ // // HTML.ATTR_TEXT.equalsIgnoreCase(visualDragElement.
+ // // getAttribute(HTML.ATTR_TYPE))
+ // // &&visualDragElement.getAttribute(HTML.ATTR_TYPE)!=null))
+ // // {
+ //
+ // selectionBuilder
+ // .setVisualElementSelection(visualDragElement);
+ // mouseDownSelectionFlag = true;
+ // // }
+ // } else {
+ // selectionBuilder.setCaretAtMouse(mouseEvent);
+ // }
+ // }
- if (visualDragElement != null) {
- // we shouldn't change selection when we click on <input
- // type="text" /> element,
- // because if we change after resizing the input element
- // lost
- // selection
- // if(!(HTML.TAG_INPUT.equalsIgnoreCase(visualDragElement.
- // getNodeName())&&
- // HTML.ATTR_TEXT.equalsIgnoreCase(visualDragElement.
- // getAttribute(HTML.ATTR_TYPE))
- // &&visualDragElement.getAttribute(HTML.ATTR_TYPE)!=null))
- // {
+ selectionManager.setSelection(mouseEvent);
+ } catch (Exception e) {
- selectionBuilder
- .setVisualElementSelection(visualDragElement);
- mouseDownSelectionFlag = true;
- // }
- } else {
- selectionBuilder.setCaretAtMouse(mouseEvent);
- }
- }
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
} finally {
switcher.stopActiveEditor();
}
}
- public void mouseUp(nsIDOMMouseEvent mouseEvent) {
+ public void mouseUp(nsIDOMMouseEvent mouseEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
+
if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
System.out.println("<<< mouseUp"); //$NON-NLS-1$
}
@@ -1072,39 +1144,39 @@
}
}
- public void mouseClick(nsIDOMMouseEvent mouseEvent) {
- if (!switcher
- .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- if (visualNode != null) {
- if (!mouseUpSelectionReasonFlag) {
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out
- .println("<<< mouseClick visualNode: " +
visualNode.getNodeName() + " (" + visualNode + ")"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- }
- if (visualBuilder.isContentArea(visualNode)) {
- selectionBuilder.setClickContentAreaSelection();
- }
- } else {
- mouseUpSelectionReasonFlag = false;
- }
+ public void mouseClick(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher
+ .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ if (visualNode != null) {
+ if (!mouseUpSelectionReasonFlag) {
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ System.out
+ .println("<<< mouseClick visualNode: " +
visualNode.getNodeName() + " (" + visualNode + ")"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ }
+ if (visualBuilder.isContentArea(visualNode)) {
+ // selectionBuilder.setClickContentAreaSelection();
+ }
+ } else {
+ mouseUpSelectionReasonFlag = false;
+ }
- if (visualBuilder.doToggle(VisualDomUtil
- .getTargetNode(mouseEvent))) {
- selectionBuilder.setClickContentAreaSelection();
- }
- }
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- } finally {
- switcher.stopActiveEditor();
- }
- }
+ if (visualBuilder.doToggle(VisualDomUtil
+ .getTargetNode(mouseEvent))) {
+ // selectionBuilder.setClickContentAreaSelection();
+ }
+ }
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
- public void mouseDblClick(nsIDOMMouseEvent mouseEvent) {
+ public void mouseDblClick(nsIDOMMouseEvent mouseEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
@@ -1119,6 +1191,7 @@
System.out
.println("<<< mouseDblClick visualNode: " +
visualNode.getNodeName() + " (" + visualNode + ")"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
}
+
}
} catch (Exception e) {
VpePlugin.reportProblem(e);
@@ -1127,7 +1200,7 @@
}
}
- public void mouseMove(nsIDOMMouseEvent mouseEvent) {
+ public void mouseMove(nsIDOMMouseEvent mouseEvent) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
@@ -1135,11 +1208,11 @@
try {
nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
if (visualNode != null) {
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< mouseMove visualNode: "
- + visualNode.getNodeName() + " (" + visualNode
- + ")");
- }
+ // if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ // System.out.println("<<< mouseMove visualNode: "
+ // + visualNode.getNodeName() + " (" + visualNode
+ // + ")");
+ // }
visualBuilder.setMoveCursor(mouseEvent);
}
} catch (Exception e) {
@@ -1149,7 +1222,7 @@
}
}
- public void keyPress(nsIDOMKeyEvent keyEvent) {
+ public void keyPress(nsIDOMKeyEvent keyEvent) {
if (VpeDebug.PRINT_VISUAL_KEY_EVENT) {
System.out
.println("<<< keyPress type: " + keyEvent.getType() + "
Ctrl: " + keyEvent.getCtrlKey() + " Shift: " + keyEvent.getShiftKey() +
" CharCode: " + keyEvent.getCharCode() + " KeyCode: " +
keyEvent.getKeyCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
//$NON-NLS-5$
@@ -1168,7 +1241,8 @@
}
try {
- if (visualKeyHandler.keyPressHandler(keyEvent)) {
+ if (/* visualKeyHandler.keyPressHandler(keyEvent) */keyEventHandler
+ .handleKeyPress(keyEvent)) {
switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
try {
@@ -1182,7 +1256,7 @@
}
} else {
// adding calls of core event handlers, for example' CTR+H' or
- //' CTRL+M' event handler dialog
+ // ' CTRL+M' event handler dialog
Event keyboardEvent = new Event();
// widget where event occur
keyboardEvent.widget = xulRunnerEditor.getBrowser();
@@ -1243,357 +1317,357 @@
}
}
- public void elementResized(nsIDOMElement element, int resizerConstrains,
- int top, int left, int width, int height) {
- if (!switcher
- .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- visualEditor.hideResizer();
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- } finally {
- switcher.stopActiveEditor();
- }
- visualBuilder.resize(element, resizerConstrains, top, left, width, height);
- sourceSelectionChanged();
- }
+ public void elementResized(nsIDOMElement element, int resizerConstrains,
+ int top, int left, int width, int height) {
+ if (!switcher
+ .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ visualEditor.hideResizer();
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ visualBuilder.resize(element, resizerConstrains, top, left, width,
+ height);
+ sourceSelectionChanged();
+ }
- public void dragGesture(nsIDOMEvent domEvent) {
+ public void dragGesture(nsIDOMEvent domEvent) {
- nsIDOMMouseEvent mouseEvent = (nsIDOMMouseEvent) domEvent
- .queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
- boolean canDragFlag = canInnerDrag(mouseEvent);
- // start drag sessionvpe-element
- if (canDragFlag) {
- startDragSession(domEvent);
+ nsIDOMMouseEvent mouseEvent = (nsIDOMMouseEvent) domEvent
+ .queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
+ boolean canDragFlag = canInnerDrag(mouseEvent);
+ // start drag sessionvpe-element
+ if (canDragFlag) {
+ startDragSession(domEvent);
+ }
}
- }
- private void createMenuForNode(Node node, MenuManager manager) {
- createMenuForNode(node, manager, false);
- }
+ private void createMenuForNode(Node node, MenuManager manager) {
+ createMenuForNode(node, manager, false);
+ }
- private void createMenuForNode(Node node, MenuManager manager,
- boolean topLevelFlag) {
- NodeActionManager.setTextNodeSplitter(null);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(node);
- if (elementMapping != null && elementMapping.getTemplate() != null) {
- manager.add(new VpeAction(
- "<" + node.getNodeName() + "> Attributes", node) {
//$NON-NLS-1$ //$NON-NLS-2$
- public void run() {
- showProperties(actionNode);
- }
- });
+ private void createMenuForNode(Node node, MenuManager manager,
+ boolean topLevelFlag) {
+ NodeActionManager.setTextNodeSplitter(null);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ VpeElementMapping elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(node);
+ if (elementMapping != null && elementMapping.getTemplate() != null) {
+ manager.add(new VpeAction(
+ "<" + node.getNodeName() + "> Attributes", node) {
//$NON-NLS-1$ //$NON-NLS-2$
+ public void run() {
+ showProperties(actionNode);
+ }
+ });
- if (!topLevelFlag) {
- manager.add(new VpeAction("Select This Tag", node) { //$NON-NLS-1$
- public void run() {
- selectionBuilder.setVisualSelection(
- actionNode, 0, actionNode, 0,
- false, true);
+ if (!topLevelFlag) {
+ manager.add(new VpeAction("Select This Tag", node) { //$NON-NLS-1$
+ public void run() {
+ selectionBuilder.setVisualSelection(
+ actionNode, 0, actionNode, 0,
+ false, true);
+ }
+ });
}
- });
+ Node parent = node.getParentNode();
+ if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
+ MenuManager menuManager = new MenuManager("Parent Tag"); //$NON-NLS-1$
+ menuManager.setParent(manager);
+ manager.add(menuManager);
+ createMenuForNode(parent, menuManager);
+ }
+
+ manager.add(new Separator());
+ }
}
- Node parent = node.getParentNode();
- if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
- MenuManager menuManager = new MenuManager("Parent Tag"); //$NON-NLS-1$
- menuManager.setParent(manager);
- manager.add(menuManager);
- createMenuForNode(parent, menuManager);
+ NodeActionManager actionManager = new NodeActionManager(getModel(),
+ null);
+
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ Point range = sourceEditor.getTextViewer().getSelectedRange();
+ TextNodeSplitterImpl splitter = new TextNodeSplitterImpl(range,
+ (Text) node);
+ NodeActionManager.setTextNodeSplitter(splitter);
}
- manager.add(new Separator());
- }
- }
- NodeActionManager actionManager = new NodeActionManager(getModel(),
- null);
+ if (actionManager != null) {
+ StructuredSelection structuredSelection = new StructuredSelection(
+ node);
+ actionManager.fillContextMenuForVpe(manager, structuredSelection);
- if (node.getNodeType() == Node.TEXT_NODE) {
- Point range = sourceEditor.getTextViewer().getSelectedRange();
- TextNodeSplitterImpl splitter = new TextNodeSplitterImpl(range,
- (Text) node);
- NodeActionManager.setTextNodeSplitter(splitter);
- }
-
- if (actionManager != null) {
- StructuredSelection structuredSelection = new StructuredSelection(
- node);
- actionManager.fillContextMenuForVpe(manager, structuredSelection);
-
- }
-
- IContributionItem[] items = manager.getItems();
-
- for (int i = 0; i < items.length; i++) {
- if (items[i] instanceof MenuManager) {
- MenuManager mm = (MenuManager) items[i];
- if (NodeActionManager.INSERT_AROUND_MENU.equals(mm
- .getMenuText())) {
- listenContextMenu(mm, (IndexedRegion) node, AROUND_MENU);
- } else if (NodeActionManager.INSERT_BEFORE_MENU.equals(mm
- .getMenuText())) {
- listenContextMenu(mm, (IndexedRegion) node, BEFORE_MENU);
- } else if (NodeActionManager.INSERT_AFTER_MENU.equals(mm
- .getMenuText())) {
- listenContextMenu(mm, (IndexedRegion) node, AFTER_MENU);
}
- }
- }
- manager.add(new Separator());
+ IContributionItem[] items = manager.getItems();
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(node);
- if (elementMapping != null
- && elementMapping.getTemplate() != null
- && elementMapping.getTemplate().getType() == VpeHtmlTemplate.TYPE_ANY) {
- final VpeTemplate selectedTemplate = elementMapping
- .getTemplate();
- manager.add(new VpeAction("Template", node) { //$NON-NLS-1$
- public void run() {
- boolean isCorrectNS = pageContext
- .isCorrectNS(actionNode);
- VpeAnyData data = null;
- if (isCorrectNS) {
- data = selectedTemplate.getAnyData();
- data.setUri(pageContext
- .getSourceTaglibUri(actionNode));
- data.setName(actionNode.getNodeName());
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] instanceof MenuManager) {
+ MenuManager mm = (MenuManager) items[i];
+ if (NodeActionManager.INSERT_AROUND_MENU.equals(mm
+ .getMenuText())) {
+ listenContextMenu(mm, (IndexedRegion) node, AROUND_MENU);
+ } else if (NodeActionManager.INSERT_BEFORE_MENU.equals(mm
+ .getMenuText())) {
+ listenContextMenu(mm, (IndexedRegion) node, BEFORE_MENU);
+ } else if (NodeActionManager.INSERT_AFTER_MENU.equals(mm
+ .getMenuText())) {
+ listenContextMenu(mm, (IndexedRegion) node, AFTER_MENU);
}
- data = editAnyData(sourceEditor, isCorrectNS,
- data);
- if (data != null && data.isChanged())
- templateManager.setAnyTemplate(data);
- }
- });
+ }
+ }
manager.add(new Separator());
- }
- manager.add(new VpeTextOperationAction(
- "Cut", ActionFactory.CUT.getId(), (IndexedRegion) node)); //$NON-NLS-1$
- manager.add(new VpeTextOperationAction(
- "Copy", ActionFactory.COPY.getId(), (IndexedRegion) node));
//$NON-NLS-1$
- manager
- .add(new VpeTextOperationAction(
- "Paste", ActionFactory.PASTE.getId(), (IndexedRegion) node));
//$NON-NLS-1$
- } else if (node.getNodeType() == Node.TEXT_NODE) {
- manager.add(new Action("Cut") { //$NON-NLS-1$
- public void run() {
- sourceEditor.getAction(ActionFactory.CUT.getId())
- .run();
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ VpeElementMapping elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(node);
+ if (elementMapping != null
+ && elementMapping.getTemplate() != null
+ && elementMapping.getTemplate().getType() == VpeHtmlTemplate.TYPE_ANY) {
+ final VpeTemplate selectedTemplate = elementMapping
+ .getTemplate();
+ manager.add(new VpeAction("Template", node) { //$NON-NLS-1$
+ public void run() {
+ boolean isCorrectNS = pageContext
+ .isCorrectNS(actionNode);
+ VpeAnyData data = null;
+ if (isCorrectNS) {
+ data = selectedTemplate.getAnyData();
+ data.setUri(pageContext
+ .getSourceTaglibUri(actionNode));
+ data.setName(actionNode.getNodeName());
+ }
+ data = editAnyData(sourceEditor, isCorrectNS,
+ data);
+ if (data != null && data.isChanged())
+ templateManager.setAnyTemplate(data);
+ }
+ });
+
+ manager.add(new Separator());
}
- });
- manager.add(new Action("Copy") { //$NON-NLS-1$
- public void run() {
- sourceEditor.getAction(ActionFactory.COPY.getId())
- .run();
- }
- });
- manager.add(new Action("Paste") { //$NON-NLS-1$
- public void run() {
- sourceEditor.getAction(ActionFactory.PASTE.getId())
- .run();
- }
- });
- }
- manager.add(new Separator());
- if (actionManager != null) {
- StructuredSelection structuredSelection = node.getNodeType() == Node.ELEMENT_NODE ?
new StructuredSelection(
- node)
- : null;
- actionManager.addContextMenuForVpe(manager, structuredSelection);
- }
+ manager.add(new VpeTextOperationAction(
+ "Cut", ActionFactory.CUT.getId(), (IndexedRegion) node)); //$NON-NLS-1$
+ manager.add(new VpeTextOperationAction(
+ "Copy", ActionFactory.COPY.getId(), (IndexedRegion) node)); //$NON-NLS-1$
+ manager
+ .add(new VpeTextOperationAction(
+ "Paste", ActionFactory.PASTE.getId(), (IndexedRegion) node));
//$NON-NLS-1$
+ } else if (node.getNodeType() == Node.TEXT_NODE) {
+ manager.add(new Action("Cut") { //$NON-NLS-1$
+ public void run() {
+ sourceEditor.getAction(ActionFactory.CUT.getId())
+ .run();
+ }
+ });
+ manager.add(new Action("Copy") { //$NON-NLS-1$
+ public void run() {
+ sourceEditor.getAction(ActionFactory.COPY.getId())
+ .run();
+ }
+ });
+ manager.add(new Action("Paste") { //$NON-NLS-1$
+ public void run() {
+ sourceEditor.getAction(ActionFactory.PASTE.getId())
+ .run();
+ }
+ });
+ }
+ manager.add(new Separator());
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- boolean stripEnable = false;
- NodeImpl impl = (NodeImpl) node;
- if (impl.isContainer()) {
- NodeList list = impl.getChildNodes();
- if (list.getLength() > 0) {
- if (list.getLength() == 1) {
- Node child = list.item(0);
- if (child.getNodeType() == Node.TEXT_NODE) {
- if ("".equals(child.getNodeValue().trim()))stripEnable = false;
//$NON-NLS-1$
- else
- stripEnable = true;
- } else
- stripEnable = true;
- } else
- stripEnable = true;
+ if (actionManager != null) {
+ StructuredSelection structuredSelection = node.getNodeType() == Node.ELEMENT_NODE ?
new StructuredSelection(
+ node)
+ : null;
+ actionManager.addContextMenuForVpe(manager, structuredSelection);
}
- }
- if (stripEnable)
- manager.add(new VpeAction("Strip Tag", node) { //$NON-NLS-1$
- public void run() {
- Node parent = actionNode.getParentNode();
- if (parent != null) {
- int index = ((NodeImpl) actionNode)
- .getIndex();
- parent.removeChild(actionNode);
- NodeList children = actionNode
- .getChildNodes();
- int lengh = children.getLength();
- Node child;
- for (int i = 0; i < lengh; i++) {
- child = children.item(0);
- actionNode.removeChild(child);
- insertNode(parent, child, index++);
- }
+
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ boolean stripEnable = false;
+ NodeImpl impl = (NodeImpl) node;
+ if (impl.isContainer()) {
+ NodeList list = impl.getChildNodes();
+ if (list.getLength() > 0) {
+ if (list.getLength() == 1) {
+ Node child = list.item(0);
+ if (child.getNodeType() == Node.TEXT_NODE) {
+ if ("".equals(child.getNodeValue().trim()))stripEnable = false;
//$NON-NLS-1$
+ else
+ stripEnable = true;
+ } else
+ stripEnable = true;
+ } else
+ stripEnable = true;
}
- }
+ }
+ if (stripEnable)
+ manager.add(new VpeAction("Strip Tag", node) { //$NON-NLS-1$
+ public void run() {
+ Node parent = actionNode.getParentNode();
+ if (parent != null) {
+ int index = ((NodeImpl) actionNode)
+ .getIndex();
+ parent.removeChild(actionNode);
+ NodeList children = actionNode
+ .getChildNodes();
+ int lengh = children.getLength();
+ Node child;
+ for (int i = 0; i < lengh; i++) {
+ child = children.item(0);
+ actionNode.removeChild(child);
+ insertNode(parent, child, index++);
+ }
+ }
+ }
- private void insertNode(Node parent, Node node,
- int index) {
- Node oldNode = null;
- int childSize = parent.getChildNodes()
- .getLength();
+ private void insertNode(Node parent, Node node,
+ int index) {
+ Node oldNode = null;
+ int childSize = parent.getChildNodes()
+ .getLength();
- if (index <= (childSize - 1))
- oldNode = parent.getChildNodes()
- .item(index);
- if (oldNode != null)
- parent.insertBefore(node, oldNode);
- else
- parent.appendChild(node);
- }
- });
- }
- if (node.getNodeType() == Node.TEXT_NODE) {
- manager.add(new Action("Delete") { //$NON-NLS-1$
- public void run() {
- sourceEditor
- .getAction(ActionFactory.DELETE.getId())
- .run();
- }
- });
- }
+ if (index <= (childSize - 1))
+ oldNode = parent.getChildNodes()
+ .item(index);
+ if (oldNode != null)
+ parent.insertBefore(node, oldNode);
+ else
+ parent.appendChild(node);
+ }
+ });
+ }
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ manager.add(new Action("Delete") { //$NON-NLS-1$
+ public void run() {
+ sourceEditor
+ .getAction(ActionFactory.DELETE.getId())
+ .run();
+ }
+ });
+ }
- if (VpeDebug.VISUAL_CONTEXTMENU_DUMP_SOURCE) {
- manager.add(new Action("Dump Source") { //$NON-NLS-1$
- public void run() {
- DOMTreeDumper dumper = new DOMTreeDumper(
- VpeDebug.VISUAL_DUMP_PRINT_HASH);
- dumper.dumpToStream(System.out, visualEditor
- .getDomDocument());
- }
- });
- }
+ if (VpeDebug.VISUAL_CONTEXTMENU_DUMP_SOURCE) {
+ manager.add(new Action("Dump Source") { //$NON-NLS-1$
+ public void run() {
+ DOMTreeDumper dumper = new DOMTreeDumper(
+ VpeDebug.VISUAL_DUMP_PRINT_HASH);
+ dumper.dumpToStream(System.out, visualEditor
+ .getDomDocument());
+ }
+ });
+ }
- if (VpeDebug.VISUAL_CONTEXTMENU_DUMP_MAPPING) {
- manager.add(new Action("Dump Mapping") { //$NON-NLS-1$
- public void run() {
- printMapping();
- }
- });
- }
+ if (VpeDebug.VISUAL_CONTEXTMENU_DUMP_MAPPING) {
+ manager.add(new Action("Dump Mapping") { //$NON-NLS-1$
+ public void run() {
+ printMapping();
+ }
+ });
+ }
- if (VpeDebug.VISUAL_CONTEXTMENU_TEST) {
- manager.add(new VpeAction("Test", node) { //$NON-NLS-1$
- public void run() {
- test(actionNode);
- }
- });
+ if (VpeDebug.VISUAL_CONTEXTMENU_TEST) {
+ manager.add(new VpeAction("Test", node) { //$NON-NLS-1$
+ public void run() {
+ test(actionNode);
+ }
+ });
+ }
}
- }
- /**
- * Calls when on when browser receive context menu event.
- *
- * @param contextFlags
- * -not used in this function, just for becouse this parametr
- * exist in nsIContextMenuListener
- * @param event
- * event from browser used here
- * @param node
- * where this event are occur
- */
- public void onShowContextMenu(long contextFlags, nsIDOMEvent event,
- nsIDOMNode node) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
+ /**
+ * Calls when on when browser receive context menu event.
+ *
+ * @param contextFlags
+ * -not used in this function, just for becouse this parametr
+ * exist in nsIContextMenuListener
+ * @param event
+ * event from browser used here
+ * @param node
+ * where this event are occur
+ */
+ public void onShowContextMenu(long contextFlags, nsIDOMEvent event,
+ nsIDOMNode node) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
- if (visualNode != null) {
- Node selectedSourceNode = null;
- selectedSourceNode = selectionBuilder
- .setContextMenuSelection(visualNode);
- if (selectedSourceNode != null) {
+ if (visualNode != null) {
+ Node selectedSourceNode = null;
+ selectedSourceNode = selectionBuilder
+ .setContextMenuSelection(visualNode);
+ if (selectedSourceNode != null) {
- MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
- final Menu contextMenu = menuManager
- .createContextMenu(visualEditor.getControl());
- contextMenu.addMenuListener(new MenuListener() {
- Menu menu = contextMenu;
+ MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
+ final Menu contextMenu = menuManager
+ .createContextMenu(visualEditor.getControl());
+ contextMenu.addMenuListener(new MenuListener() {
+ Menu menu = contextMenu;
- public void menuHidden(MenuEvent e) {
- Display.getCurrent().asyncExec(new Runnable() {
- public void run() {
- menu.dispose();
- }
- });
- }
+ public void menuHidden(MenuEvent e) {
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ menu.dispose();
+ }
+ });
+ }
- public void menuShown(MenuEvent e) {
- }
- });
- createMenuForNode(selectedSourceNode, menuManager, true);
+ public void menuShown(MenuEvent e) {
+ }
+ });
+ createMenuForNode(selectedSourceNode, menuManager, true);
- contextMenu.setVisible(true);
+ contextMenu.setVisible(true);
- }
+ }
+ }
}
- }
- private VpeAnyData editAnyData(StructuredTextEditor sourceEditor,
- boolean isCorrectNS, VpeAnyData data) {
- Shell shell = sourceEditor.getEditorPart().getSite().getShell();
- if (isCorrectNS) {
- VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data);
- editDialog.open();
- } else {
- MessageBox message = new MessageBox(shell, SWT.ICON_WARNING
- | SWT.OK);
- message.setMessage(VpeUIMessages.NAMESPACE_NOT_DEFINED);
- message.open();
+ private VpeAnyData editAnyData(StructuredTextEditor sourceEditor,
+ boolean isCorrectNS, VpeAnyData data) {
+ Shell shell = sourceEditor.getEditorPart().getSite().getShell();
+ if (isCorrectNS) {
+ VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data);
+ editDialog.open();
+ } else {
+ MessageBox message = new MessageBox(shell, SWT.ICON_WARNING
+ | SWT.OK);
+ message.setMessage(VpeUIMessages.NAMESPACE_NOT_DEFINED);
+ message.open();
+ }
+ return data;
}
- return data;
- }
- // VpeTemplateListener implementation
- public void templateReloaded() {
- visualRefresh();
- }
+ // VpeTemplateListener implementation
+ public void templateReloaded() {
+ visualRefresh();
+ }
- public void visualRefresh() {
-
- if(visualRefresfJob==null || visualRefresfJob.getState()==Job.NONE) {
-
- visualRefresfJob =new UIJob(VpeUIMessages.VPE_VISUAL_REFRESH_JOB){
+ public void visualRefresh() {
+ if (visualRefresfJob == null || visualRefresfJob.getState() == Job.NONE) {
+
+ visualRefresfJob = new UIJob(VpeUIMessages.VPE_VISUAL_REFRESH_JOB) {
+
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
-
- if(monitor.isCanceled()) {
-
+
+ if (monitor.isCanceled()) {
+
return Status.CANCEL_STATUS;
}
-
- if(uiJob!=null &&
- uiJob.getState()==Job.RUNNING) {
+
+ if (uiJob != null && uiJob.getState() == Job.RUNNING) {
uiJob.cancel();
getChangeEvents().clear();
- //wait while ui job is finished
+ // wait while ui job is finished
schedule(500);
} else {
-
- if(uiJob!=null) {
-
+
+ if (uiJob != null) {
+
uiJob.cancel();
getChangeEvents().clear();
}
@@ -1602,36 +1676,41 @@
return Status.CANCEL_STATUS;
}
try {
- monitor.beginTask(VpeUIMessages.VPE_VISUAL_REFRESH_JOB,
IProgressMonitor.UNKNOWN);
+ monitor.beginTask(
+ VpeUIMessages.VPE_VISUAL_REFRESH_JOB,
+ IProgressMonitor.UNKNOWN);
visualRefreshImpl();
monitor.done();
} catch (VpeDisposeException exc) {
- //just ignore this exception
+ // just ignore this exception
} catch (NullPointerException ex) {
-
- if(switcher!=null ) {
+
+ if (switcher != null) {
throw ex;
} else {
- //class was disposed and exception result of that we can't stop
- //refresh job in time, so we just ignore this exception
+ // class was disposed and exception result of
+ // that we can't stop
+ // refresh job in time, so we just ignore this
+ // exception
}
} finally {
-
- if(switcher!=null) {
-
+
+ if (switcher != null) {
+
switcher.stopActiveEditor();
}
}
}
return Status.OK_STATUS;
- }};
-
- visualRefresfJob.setPriority(Job.SHORT);
- visualRefresfJob.schedule();
- }
+ }
+ };
+
+ visualRefresfJob.setPriority(Job.SHORT);
+ visualRefresfJob.schedule();
+ }
}
- void visualRefreshImpl() {
+ void visualRefreshImpl() {
visualEditor.hideResizer();
@@ -1641,9 +1720,9 @@
if (!visualEditor.getDoctype().equals(currentDoctype)) {
visualEditor.reload();
-
- }else {
-
+
+ } else {
+
visualBuilder.setSelectionRectangle(null);
IDOMModel sourceModel = (IDOMModel) getModel();
if (sourceModel != null) {
@@ -1655,132 +1734,132 @@
}
}
- public void preLongOperation() {
+ public void preLongOperation() {
switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
}
- public void postLongOperation() {
+ public void postLongOperation() {
switcher.stopActiveEditor();
visualRefresh();
}
- // for debug
- private void printSourceEvent(INodeNotifier notifier, int eventType,
- Object feature, Object oldValue, Object newValue, int pos) {
- System.out
- .println(">>> eventType: " +
INodeNotifier.EVENT_TYPE_STRINGS[eventType] + " pos: " + pos + "
notifier: " + ((Node) notifier).getNodeName() + " hashCode: " +
notifier.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- if (feature != null) {
- if (feature instanceof Node) {
+ // for debug
+ private void printSourceEvent(INodeNotifier notifier, int eventType,
+ Object feature, Object oldValue, Object newValue, int pos) {
System.out
- .println(" feature: " + ((Node) feature).getNodeType() + " "
+ ((Node) feature).getNodeName() + " hashCode: " + feature.hashCode());
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- } else {
- System.out.println(" feature: " + feature); //$NON-NLS-1$
- }
+ .println(">>> eventType: " +
INodeNotifier.EVENT_TYPE_STRINGS[eventType] + " pos: " + pos + "
notifier: " + ((Node) notifier).getNodeName() + " hashCode: " +
notifier.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ if (feature != null) {
+ if (feature instanceof Node) {
+ System.out
+ .println(" feature: " + ((Node) feature).getNodeType() + "
" + ((Node) feature).getNodeName() + " hashCode: " + feature.hashCode());
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } else {
+ System.out.println(" feature: " + feature); //$NON-NLS-1$
+ }
+ }
+ if (oldValue != null) {
+ if (oldValue instanceof Node) {
+ System.out
+ .println(" oldValue: " + ((Node) oldValue).getNodeName() + "
hashCode: " + oldValue.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ System.out.println(" oldValue: " + oldValue); //$NON-NLS-1$
+ }
+ }
+ if (newValue != null) {
+ if (newValue instanceof Node) {
+ System.out
+ .println(" newValue: " + ((Node) newValue).getNodeName() + "
hashCode: " + newValue.hashCode() + " " + ((Node)
newValue).getNodeType()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } else {
+ System.out.println(" newValue: " + newValue); //$NON-NLS-1$
+ }
+ }
}
- if (oldValue != null) {
- if (oldValue instanceof Node) {
- System.out
- .println(" oldValue: " + ((Node) oldValue).getNodeName() + "
hashCode: " + oldValue.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- System.out.println(" oldValue: " + oldValue); //$NON-NLS-1$
- }
- }
- if (newValue != null) {
- if (newValue instanceof Node) {
- System.out
- .println(" newValue: " + ((Node) newValue).getNodeName() + "
hashCode: " + newValue.hashCode() + " " + ((Node)
newValue).getNodeType()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- } else {
- System.out.println(" newValue: " + newValue); //$NON-NLS-1$
- }
- }
- }
- private void printVisualEvent(nsIDOMEvent event) {
- System.out.print("<<< " + event.getType()); //$NON-NLS-1$
+ private void printVisualEvent(nsIDOMEvent event) {
+ System.out.print("<<< " + event.getType()); //$NON-NLS-1$
- if (event instanceof nsIDOMMutationEvent) {
- nsIDOMMutationEvent mutationEvent = (nsIDOMMutationEvent) event;
+ if (event instanceof nsIDOMMutationEvent) {
+ nsIDOMMutationEvent mutationEvent = (nsIDOMMutationEvent) event;
- System.out.print(" EventPhase: " + mutationEvent.getEventPhase());
//$NON-NLS-1$
+ System.out.print(" EventPhase: " + mutationEvent.getEventPhase());
//$NON-NLS-1$
- nsIDOMNode relatedNode = mutationEvent.getRelatedNode();
- System.out
- .print(" RelatedNode: " + (relatedNode == null ? null :
relatedNode.getNodeName())); //$NON-NLS-1$
+ nsIDOMNode relatedNode = mutationEvent.getRelatedNode();
+ System.out
+ .print(" RelatedNode: " + (relatedNode == null ? null :
relatedNode.getNodeName())); //$NON-NLS-1$
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
- String name = targetNode != null ? targetNode.getNodeName() : null;
- System.out.print(" TargetNode: " + name + " (" + targetNode +
")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
+ String name = targetNode != null ? targetNode.getNodeName() : null;
+ System.out.print(" TargetNode: " + name + " (" + targetNode +
")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- System.out
- .print(" PrevValue: " + mutationEvent.getPrevValue().trim());
//$NON-NLS-1$
- System.out
- .print(" NewValue: " + mutationEvent.getNewValue().trim());
//$NON-NLS-1$
+ System.out
+ .print(" PrevValue: " + mutationEvent.getPrevValue().trim());
//$NON-NLS-1$
+ System.out
+ .print(" NewValue: " + mutationEvent.getNewValue().trim());
//$NON-NLS-1$
+ }
+ System.out.println();
}
- System.out.println();
- }
- private void printMapping() {
- domMapping.printMapping();
- }
+ private void printMapping() {
+ domMapping.printMapping();
+ }
- private class ActiveEditorSwitcher {
- private static final int ACTIVE_EDITOR_CANNOT = 0;
- private static final int ACTIVE_EDITOR_NONE = 1;
- private static final int ACTIVE_EDITOR_SOURCE = 2;
- private static final int ACTIVE_EDITOR_VISUAL = 3;
+ private class ActiveEditorSwitcher {
+ private static final int ACTIVE_EDITOR_CANNOT = 0;
+ private static final int ACTIVE_EDITOR_NONE = 1;
+ private static final int ACTIVE_EDITOR_SOURCE = 2;
+ private static final int ACTIVE_EDITOR_VISUAL = 3;
- private int type = ACTIVE_EDITOR_CANNOT;
+ private int type = ACTIVE_EDITOR_CANNOT;
- private void initActiveEditor() {
- type = ACTIVE_EDITOR_NONE;
- }
+ private void initActiveEditor() {
+ type = ACTIVE_EDITOR_NONE;
+ }
- private void destroyActiveEditor() {
- type = ACTIVE_EDITOR_CANNOT;
- }
+ private void destroyActiveEditor() {
+ type = ACTIVE_EDITOR_CANNOT;
+ }
- private boolean startActiveEditor(int newType) {
- if (type == ACTIVE_EDITOR_NONE) {
- if (newType == ACTIVE_EDITOR_SOURCE
- && editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
- return false;
+ private boolean startActiveEditor(int newType) {
+ if (type == ACTIVE_EDITOR_NONE) {
+ if (newType == ACTIVE_EDITOR_SOURCE
+ && editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
+ return false;
+ }
+ type = newType;
+ return true;
+ } else {
+ return false;
+ }
}
- type = newType;
- return true;
- } else {
- return false;
- }
+
+ private void stopActiveEditor() {
+ onRefresh();
+ type = ACTIVE_EDITOR_NONE;
+ }
}
- private void stopActiveEditor() {
- onRefresh();
- type = ACTIVE_EDITOR_NONE;
+ private void showProperties(Node node) {
+ ExtendedProperties p = createExtendedProperties(node);
+ if (p != null)
+ ExtendedPropertiesWizard.run(p);
}
- }
- private void showProperties(Node node) {
- ExtendedProperties p = createExtendedProperties(node);
- if (p != null)
- ExtendedPropertiesWizard.run(p);
- }
+ ExtendedProperties createExtendedProperties(Node node) {
+ try {
+ Class c = ModelFeatureFactory.getInstance().getFeatureClass(
+ "org.jboss.tools.jst.jsp.outline.VpeProperties"); //$NON-NLS-1$
+ return (ExtendedProperties) c.getDeclaredConstructor(
+ new Class[] { Node.class }).newInstance(
+ new Object[] { node });
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ return null;
+ }
+ }
- ExtendedProperties createExtendedProperties(Node node) {
- try {
- Class c = ModelFeatureFactory.getInstance().getFeatureClass(
- "org.jboss.tools.jst.jsp.outline.VpeProperties"); //$NON-NLS-1$
- return (ExtendedProperties) c.getDeclaredConstructor(
- new Class[] { Node.class }).newInstance(
- new Object[] { node });
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- return null;
+ private void test(Node node) {
}
- }
- private void test(Node node) {
- }
-
- void refreshBundleValues() {
+ void refreshBundleValues() {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
@@ -1799,7 +1878,7 @@
}
}
- void refreshTemplates() {
+ void refreshTemplates() {
if (includeList.includesRefresh()) {
visualRefresh();
}
@@ -1824,493 +1903,493 @@
}
}
- // implements XModelTreeListener
- public void nodeChanged(XModelTreeEvent event) {
- visualRefresh();
- }
+ // implements XModelTreeListener
+ public void nodeChanged(XModelTreeEvent event) {
+ visualRefresh();
+ }
- public void structureChanged(XModelTreeEvent event) {
- }
+ public void structureChanged(XModelTreeEvent event) {
+ }
- private Node getSourceNodeAt(int offset) {
- if (sourceEditor != null && getModel() != null) {
- IndexedRegion node = getModel().getIndexedRegion(offset);
- if (node instanceof IDOMNode) {
+ private Node getSourceNodeAt(int offset) {
+ if (sourceEditor != null && getModel() != null) {
+ IndexedRegion node = getModel().getIndexedRegion(offset);
+ if (node instanceof IDOMNode) {
- VpeElementMapping elementMapping = domMapping
- .getNearElementMapping((IDOMNode) node);
+ VpeElementMapping elementMapping = domMapping
+ .getNearElementMapping((IDOMNode) node);
- if (elementMapping != null) {
+ if (elementMapping != null) {
- if (node instanceof IDOMElement) {
- IDOMElement element = (IDOMElement) node;
+ if (node instanceof IDOMElement) {
+ IDOMElement element = (IDOMElement) node;
- if (offset < element.getEndStartOffset()) {
- NamedNodeMap attrs = element.getAttributes();
- if (attrs != null) {
- for (int i = 0; i < attrs.getLength(); i++) {
- if (attrs.item(i) instanceof AttrImpl) {
- AttrImpl attr = (AttrImpl) attrs
- .item(i);
- if (getSourceAttributeOffset(attr,
- offset) != -1) {
+ if (offset < element.getEndStartOffset()) {
+ NamedNodeMap attrs = element.getAttributes();
+ if (attrs != null) {
+ for (int i = 0; i < attrs.getLength(); i++) {
+ if (attrs.item(i) instanceof AttrImpl) {
+ AttrImpl attr = (AttrImpl) attrs
+ .item(i);
+ if (getSourceAttributeOffset(attr,
+ offset) != -1) {
- String[] atributeNames = elementMapping
- .getTemplate()
- .getOutputAtributeNames();
- if (atributeNames != null
- && atributeNames.length > 0
- && attr
- .getName()
- .equalsIgnoreCase(
- atributeNames[0])) {
- return attr;
- }
+ String[] atributeNames = elementMapping
+ .getTemplate()
+ .getOutputAtributeNames();
+ if (atributeNames != null
+ && atributeNames.length > 0
+ && attr
+ .getName()
+ .equalsIgnoreCase(
+ atributeNames[0])) {
+ return attr;
+ }
+ }
+ }
+ }
+ }
+ }
}
- }
}
- }
}
- }
+ if (node == null) {
+ node = getModel().getIndexedRegion(offset - 1);
+ }
+ if (node instanceof Node) {
+ return (Node) node;
+ }
}
- }
- if (node == null) {
- node = getModel().getIndexedRegion(offset - 1);
- }
- if (node instanceof Node) {
- return (Node) node;
- }
+ return null;
}
- return null;
- }
- private int getSourceNodeOffset(Node node, int pos, boolean endFlag) {
- if (node == null)
- return 0;
- int start = ((IndexedRegion) node).getStartOffset();
- int end = ((IndexedRegion) node).getEndOffset();
+ private int getSourceNodeOffset(Node node, int pos, boolean endFlag) {
+ if (node == null)
+ return 0;
+ int start = ((IndexedRegion) node).getStartOffset();
+ int end = ((IndexedRegion) node).getEndOffset();
- switch (node.getNodeType()) {
- case Node.ATTRIBUTE_NODE:
- if (node instanceof AttrImpl) {
- return getSourceAttributeOffset((AttrImpl) node, pos);
- }
- case Node.TEXT_NODE:
- if (pos < start) {
- return 0;
- } else if (pos > end) {
- return end - start;
- } else {
- return pos - start;
- }
- case Node.COMMENT_NODE:
- if (pos > end) {
- pos = end;
- }
- int offset = pos - start - 4;
- return offset < 0 ? 0 : offset;
- case Node.ELEMENT_NODE:
- ElementImpl element = (ElementImpl) node;
- if (element.isContainer()) {
- if (pos < element.getStartEndOffset()) {
- return 0;
- } else {
- return 1;
+ switch (node.getNodeType()) {
+ case Node.ATTRIBUTE_NODE:
+ if (node instanceof AttrImpl) {
+ return getSourceAttributeOffset((AttrImpl) node, pos);
+ }
+ case Node.TEXT_NODE:
+ if (pos < start) {
+ return 0;
+ } else if (pos > end) {
+ return end - start;
+ } else {
+ return pos - start;
+ }
+ case Node.COMMENT_NODE:
+ if (pos > end) {
+ pos = end;
+ }
+ int offset = pos - start - 4;
+ return offset < 0 ? 0 : offset;
+ case Node.ELEMENT_NODE:
+ ElementImpl element = (ElementImpl) node;
+ if (element.isContainer()) {
+ if (pos < element.getStartEndOffset()) {
+ return 0;
+ } else {
+ return 1;
+ }
+ } else {
+ return endFlag ? 1 : 0;
+ }
+ default:
+ return endFlag ? 1 : 0;
}
- } else {
- return endFlag ? 1 : 0;
- }
- default:
- return endFlag ? 1 : 0;
}
- }
- private int getSourceAttributeOffset(AttrImpl attr, int pos) {
- if (attr.getValueRegion() != null) {
- int start = attr.getValueRegionStartOffset();
- String value = attr.getValueRegionText();
- int len = value.length();
- if (pos >= start && pos <= start + len) {
- int offset = pos - start;
- if (len > 1 && value.charAt(0) == '"'
- && value.charAt(len - 1) == '"') {
- if (offset <= 0 || offset >= len) {
- return -1;
- }
- offset--;
+ private int getSourceAttributeOffset(AttrImpl attr, int pos) {
+ if (attr.getValueRegion() != null) {
+ int start = attr.getValueRegionStartOffset();
+ String value = attr.getValueRegionText();
+ int len = value.length();
+ if (pos >= start && pos <= start + len) {
+ int offset = pos - start;
+ if (len > 1 && value.charAt(0) == '"'
+ && value.charAt(len - 1) == '"') {
+ if (offset <= 0 || offset >= len) {
+ return -1;
+ }
+ offset--;
+ }
+ return offset;
+ }
}
- return offset;
- }
+ return -1;
}
- return -1;
- }
- private int getSourceNodeOffset1(Node node, int pos, boolean endFlag) {
- if (node == null)
- return 0;
- int start = ((IndexedRegion) node).getStartOffset();
- int end = ((IndexedRegion) node).getEndOffset();
+ private int getSourceNodeOffset1(Node node, int pos, boolean endFlag) {
+ if (node == null)
+ return 0;
+ int start = ((IndexedRegion) node).getStartOffset();
+ int end = ((IndexedRegion) node).getEndOffset();
- switch (node.getNodeType()) {
- case Node.ATTRIBUTE_NODE:
- if (node instanceof AttrImpl) {
- AttrImpl attr = (AttrImpl) node;
- start = attr.getValueRegionStartOffset();
- end = start + attr.getValueRegion().getLength();
- int ret = 0;
- if (pos > end) {
- ret = end - start;
- } else {
- ret = pos - start;
+ switch (node.getNodeType()) {
+ case Node.ATTRIBUTE_NODE:
+ if (node instanceof AttrImpl) {
+ AttrImpl attr = (AttrImpl) node;
+ start = attr.getValueRegionStartOffset();
+ end = start + attr.getValueRegion().getLength();
+ int ret = 0;
+ if (pos > end) {
+ ret = end - start;
+ } else {
+ ret = pos - start;
+ }
+ if (ret > 0 && attr.getValueRegionText().charAt(0) == '"') {
+ ret--;
+ }
+ return ret;
+ }
+ case Node.TEXT_NODE:
+ if (pos < start) {
+ return 0;
+ } else if (pos > end) {
+ return end - start;
+ } else {
+ return pos - start;
+ }
+ case Node.COMMENT_NODE:
+ if (pos > end) {
+ pos = end;
+ }
+ int offset = pos - start - 4;
+ return offset < 0 ? 0 : offset;
+ case Node.ELEMENT_NODE:
+ ElementImpl element = (ElementImpl) node;
+ if (element.isContainer()) {
+ if (pos < element.getStartEndOffset()) {
+ return 0;
+ } else if (pos < element.getStartEndOffset()) {
+ return 1;
+ } else if (pos == element.getStartEndOffset()) {
+ return 2;
+ }
+ } else {
+ return endFlag ? 1 : 0;
+ }
+ default:
+ return endFlag ? 1 : 0;
}
- if (ret > 0 && attr.getValueRegionText().charAt(0) == '"') {
- ret--;
+ }
+
+ private void listenContextMenu(MenuManager manager, IndexedRegion region,
+ int type) {
+ MenuManager mm = new MyMenuManager("From Palette", true); //$NON-NLS-1$
+ manager.add(mm);
+ manager.addMenuListener(new VpeMenuListener(mm, region, type));
+ }
+
+ class VpeMenuListener implements IMenuListener {
+ private MenuManager manager;
+ private IndexedRegion region;
+ private int type;
+ private boolean loaded = false;
+
+ public VpeMenuListener(MenuManager manager, IndexedRegion region,
+ int type) {
+ this.manager = manager;
+ this.region = region;
+ this.type = type;
}
- return ret;
- }
- case Node.TEXT_NODE:
- if (pos < start) {
- return 0;
- } else if (pos > end) {
- return end - start;
- } else {
- return pos - start;
- }
- case Node.COMMENT_NODE:
- if (pos > end) {
- pos = end;
- }
- int offset = pos - start - 4;
- return offset < 0 ? 0 : offset;
- case Node.ELEMENT_NODE:
- ElementImpl element = (ElementImpl) node;
- if (element.isContainer()) {
- if (pos < element.getStartEndOffset()) {
- return 0;
- } else if (pos < element.getStartEndOffset()) {
- return 1;
- } else if (pos == element.getStartEndOffset()) {
- return 2;
+
+ public void menuAboutToShow(IMenuManager m) {
+ if (loaded)
+ return;
+ loaded = true;
+ fillContextMenuFromPalette(manager, region, type);
+ manager.getParent().update(true);
}
- } else {
- return endFlag ? 1 : 0;
- }
- default:
- return endFlag ? 1 : 0;
}
- }
- private void listenContextMenu(MenuManager manager, IndexedRegion region,
- int type) {
- MenuManager mm = new MyMenuManager("From Palette", true); //$NON-NLS-1$
- manager.add(mm);
- manager.addMenuListener(new VpeMenuListener(mm, region, type));
- }
+ private MenuManager fillContextMenuFromPalette(MenuManager manager,
+ IndexedRegion region, int type) {
+ XModelObject model = ModelUtilities.getPreferenceModel().getByPath(
+ "%Palette%"); //$NON-NLS-1$
- class VpeMenuListener implements IMenuListener {
- private MenuManager manager;
- private IndexedRegion region;
- private int type;
- private boolean loaded = false;
-
- public VpeMenuListener(MenuManager manager, IndexedRegion region,
- int type) {
- this.manager = manager;
- this.region = region;
- this.type = type;
+ XModelObject[] folders = model.getChildren();
+ for (int i = 0; i < folders.length; i++) {
+ if ("yes".equals(folders[i].getAttributeValue("hidden")))continue;
//$NON-NLS-1$ //$NON-NLS-2$
+ MenuManager mm = new MenuManager(folders[i]
+ .getAttributeValue("name")); //$NON-NLS-1$
+ manager.add(mm);
+ fillPaletteFolder(mm, region, folders[i], type);
+ }
+ return manager;
}
- public void menuAboutToShow(IMenuManager m) {
- if (loaded)
- return;
- loaded = true;
- fillContextMenuFromPalette(manager, region, type);
- manager.getParent().update(true);
+ private void fillPaletteFolder(MenuManager menu, IndexedRegion region,
+ XModelObject folder, int type) {
+ XModelObject[] groups = folder.getChildren();
+ for (int i = 0; i < groups.length; i++) {
+ if ("yes".equals(groups[i].getAttributeValue("hidden")))continue;
//$NON-NLS-1$ //$NON-NLS-2$
+ MenuManager mm = new MenuManager(groups[i]
+ .getAttributeValue("name")); //$NON-NLS-1$
+ menu.add(mm);
+ fillPaletteGroup(mm, region, groups[i], type);
+ }
}
- }
- private MenuManager fillContextMenuFromPalette(MenuManager manager,
- IndexedRegion region, int type) {
- XModelObject model = ModelUtilities.getPreferenceModel().getByPath(
- "%Palette%"); //$NON-NLS-1$
+ private void fillPaletteGroup(MenuManager menu, IndexedRegion region,
+ XModelObject group, int type) {
+ XModelObject[] items = group.getChildren();
+ String endText;
- XModelObject[] folders = model.getChildren();
- for (int i = 0; i < folders.length; i++) {
- if
("yes".equals(folders[i].getAttributeValue("hidden")))continue;
//$NON-NLS-1$ //$NON-NLS-2$
- MenuManager mm = new MenuManager(folders[i]
- .getAttributeValue("name")); //$NON-NLS-1$
- manager.add(mm);
- fillPaletteFolder(mm, region, folders[i], type);
- }
- return manager;
- }
+ for (int i = 0; i < items.length; i++) {
+ if ("yes".equals(items[i].getAttributeValue("hidden")))continue;
//$NON-NLS-1$ //$NON-NLS-2$
+ endText = items[i].getAttributeValue("end text"); //$NON-NLS-1$
- private void fillPaletteFolder(MenuManager menu, IndexedRegion region,
- XModelObject folder, int type) {
- XModelObject[] groups = folder.getChildren();
- for (int i = 0; i < groups.length; i++) {
- if
("yes".equals(groups[i].getAttributeValue("hidden")))continue;
//$NON-NLS-1$ //$NON-NLS-2$
- MenuManager mm = new MenuManager(groups[i]
- .getAttributeValue("name")); //$NON-NLS-1$
- menu.add(mm);
- fillPaletteGroup(mm, region, groups[i], type);
+ if (type == AROUND_MENU && (endText == null ||
"".equals(endText)))continue; //$NON-NLS-1$
+ createInsertAction(menu, region, items[i], type);
+ }
}
- }
- private void fillPaletteGroup(MenuManager menu, IndexedRegion region,
- XModelObject group, int type) {
- XModelObject[] items = group.getChildren();
- String endText;
+ private void createInsertAction(MenuManager menu, IndexedRegion region,
+ XModelObject item, int type) {
- for (int i = 0; i < items.length; i++) {
- if ("yes".equals(items[i].getAttributeValue("hidden")))continue;
//$NON-NLS-1$ //$NON-NLS-2$
- endText = items[i].getAttributeValue("end text"); //$NON-NLS-1$
+ XModelObject parent = item.getParent();
+ String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+ String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
+ String[] texts = new String[] { "<" + tagName + ">" };
//$NON-NLS-1$ //$NON-NLS-2$
+ if (tagName.indexOf("taglib") < 0) //$NON-NLS-1$
+ PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagName, uri,
+ defaultPrefix);
+ tagName = texts[0];
- if (type == AROUND_MENU && (endText == null ||
"".equals(endText)))continue; //$NON-NLS-1$
- createInsertAction(menu, region, items[i], type);
+ menu.add(new InsertAction(tagName, region, item, type));
}
- }
- private void createInsertAction(MenuManager menu, IndexedRegion region,
- XModelObject item, int type) {
+ class InsertAction extends Action {
+ private XModelObject item;
+ private int type;
+ private IndexedRegion region;
- XModelObject parent = item.getParent();
- String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
- String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
- String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
- String[] texts = new String[] { "<" + tagName + ">" };
//$NON-NLS-1$ //$NON-NLS-2$
- if (tagName.indexOf("taglib") < 0) //$NON-NLS-1$
- PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagName, uri,
- defaultPrefix);
- tagName = texts[0];
+ public InsertAction(String title, IndexedRegion region,
+ XModelObject item, int type) {
+ super(title);
+ this.item = item;
+ this.type = type;
+ this.region = region;
+ }
- menu.add(new InsertAction(tagName, region, item, type));
- }
+ public void run() {
+ try {
+ String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
- class InsertAction extends Action {
- private XModelObject item;
- private int type;
- private IndexedRegion region;
+ XModelObject parent = item.getParent();
+ String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String libraryVersion = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_VERSION); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+ VpeSelectionProvider selProvider = new VpeSelectionProvider(
+ region);
- public InsertAction(String title, IndexedRegion region,
- XModelObject item, int type) {
- super(title);
- this.item = item;
- this.type = type;
- this.region = region;
- }
+ String startText = "" + item.getAttributeValue("start text");
//$NON-NLS-1$ //$NON-NLS-2$
+ String endText = "" + item.getAttributeValue("end text");
//$NON-NLS-1$ //$NON-NLS-2$
+ if (type == AROUND_MENU) {
+ } else if (type == BEFORE_MENU) {
+ selProvider = new VpeSelectionProvider(region
+ .getStartOffset());
+ } else if (type == AFTER_MENU) {
+ selProvider = new VpeSelectionProvider(region
+ .getEndOffset());
+ }
- public void run() {
- try {
- String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
+ Properties p = new Properties();
+ p.setProperty("tag name", tagName); //$NON-NLS-1$
+ p.setProperty("start text", startText); //$NON-NLS-1$
+ p.setProperty("end text", endText); //$NON-NLS-1$
+ p
+ .setProperty(
+ "automatically reformat tag body", "" +
item.getAttributeValue("automatically reformat tag body")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ p.setProperty(URIConstants.LIBRARY_URI, uri);
+ p.setProperty(URIConstants.LIBRARY_VERSION, libraryVersion);
+ String addTaglib = item.getParent().getAttributeValue(
+ TLDToPaletteHelper.ADD_TAGLIB);
+ p.setProperty(URIConstants.DEFAULT_PREFIX, defaultPrefix);
+ p.setProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB,
+ addTaglib);
+ /*
+ * Added by Dzmitry Sakovich Fix for JBIDE-1626
+ */
+ // if(((Node)region).getNodeType() == Node.ELEMENT_NODE)
+ p.put("selectionProvider", selProvider); //$NON-NLS-1$
+ PaletteInsertHelper.insertIntoEditor(sourceEditor
+ .getTextViewer(), p);
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ }
- XModelObject parent = item.getParent();
- String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
- String libraryVersion = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_VERSION); //$NON-NLS-1$
- String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
- VpeSelectionProvider selProvider = new VpeSelectionProvider(
- region);
-
- String startText = "" + item.getAttributeValue("start text");
//$NON-NLS-1$ //$NON-NLS-2$
- String endText = "" + item.getAttributeValue("end text");
//$NON-NLS-1$ //$NON-NLS-2$
- if (type == AROUND_MENU) {
- } else if (type == BEFORE_MENU) {
- selProvider = new VpeSelectionProvider(region
- .getStartOffset());
- } else if (type == AFTER_MENU) {
- selProvider = new VpeSelectionProvider(region
- .getEndOffset());
}
- Properties p = new Properties();
- p.setProperty("tag name", tagName); //$NON-NLS-1$
- p.setProperty("start text", startText); //$NON-NLS-1$
- p.setProperty("end text", endText); //$NON-NLS-1$
- p
- .setProperty(
- "automatically reformat tag body", "" +
item.getAttributeValue("automatically reformat tag body")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- p.setProperty(URIConstants.LIBRARY_URI, uri);
- p.setProperty(URIConstants.LIBRARY_VERSION, libraryVersion);
- String addTaglib = item.getParent().getAttributeValue(
- TLDToPaletteHelper.ADD_TAGLIB);
- p.setProperty(URIConstants.DEFAULT_PREFIX, defaultPrefix);
- p.setProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB,
- addTaglib);
- /*
- * Added by Dzmitry Sakovich Fix for JBIDE-1626
- */
- // if(((Node)region).getNodeType() == Node.ELEMENT_NODE)
- p.put("selectionProvider", selProvider); //$NON-NLS-1$
- PaletteInsertHelper.insertIntoEditor(sourceEditor
- .getTextViewer(), p);
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- }
-
}
- }
+ class VpeSelectionProvider implements ISelectionProvider {
+ VpeSelection selection;
- class VpeSelectionProvider implements ISelectionProvider {
- VpeSelection selection;
+ public VpeSelectionProvider(IndexedRegion region) {
+ selection = new VpeSelection(region);
+ }
- public VpeSelectionProvider(IndexedRegion region) {
- selection = new VpeSelection(region);
- }
+ public VpeSelectionProvider(int position) {
+ selection = new VpeSelection(position);
+ }
- public VpeSelectionProvider(int position) {
- selection = new VpeSelection(position);
- }
+ public VpeSelectionProvider(int offset, int length) {
+ selection = new VpeSelection(offset, length);
+ }
- public VpeSelectionProvider(int offset, int length) {
- selection = new VpeSelection(offset, length);
- }
+ public void addSelectionChangedListener(
+ ISelectionChangedListener listener) {
+ }
- public void addSelectionChangedListener(
- ISelectionChangedListener listener) {
- }
+ public ISelection getSelection() {
+ return selection;
+ }
- public ISelection getSelection() {
- return selection;
- }
+ public void removeSelectionChangedListener(
+ ISelectionChangedListener listener) {
- public void removeSelectionChangedListener(
- ISelectionChangedListener listener) {
+ }
+ public void setSelection(ISelection selection) {
+ }
}
- public void setSelection(ISelection selection) {
- }
- }
+ class VpeSelection implements ITextSelection {
+ String text = ""; //$NON-NLS-1$
+ int offset, length;
- class VpeSelection implements ITextSelection {
- String text = ""; //$NON-NLS-1$
- int offset, length;
+ public VpeSelection(int position) {
+ offset = position;
+ length = 0;
+ }
- public VpeSelection(int position) {
- offset = position;
- length = 0;
- }
+ public VpeSelection(int offset, int length) {
+ this.offset = offset;
+ this.length = length;
+ if (length > 0) {
+ try {
+ text = sourceEditor.getTextViewer().getDocument().get(
+ offset, length);
+ } catch (Exception ex) {
+ VpePlugin.reportProblem(ex);
+ }
+ }
+ }
- public VpeSelection(int offset, int length) {
- this.offset = offset;
- this.length = length;
- if (length > 0) {
- try {
- text = sourceEditor.getTextViewer().getDocument().get(
- offset, length);
- } catch (Exception ex) {
- VpePlugin.reportProblem(ex);
+ public VpeSelection(IndexedRegion region) {
+ offset = region.getStartOffset();
+ length = region.getEndOffset() - offset;
+ try {
+ text = sourceEditor.getTextViewer().getDocument().get(offset,
+ length);
+ } catch (Exception ex) {
+ VpePlugin.reportProblem(ex);
+ }
}
- }
- }
- public VpeSelection(IndexedRegion region) {
- offset = region.getStartOffset();
- length = region.getEndOffset() - offset;
- try {
- text = sourceEditor.getTextViewer().getDocument().get(offset,
- length);
- } catch (Exception ex) {
- VpePlugin.reportProblem(ex);
- }
- }
+ public int getEndLine() {
+ return 0;
+ }
- public int getEndLine() {
- return 0;
- }
+ public int getLength() {
+ return length;
+ }
- public int getLength() {
- return length;
- }
+ public int getOffset() {
+ return offset;
+ }
- public int getOffset() {
- return offset;
- }
+ public int getStartLine() {
+ return 0;
+ }
- public int getStartLine() {
- return 0;
- }
+ public String getText() {
+ return text;
+ }
- public String getText() {
- return text;
+ public boolean isEmpty() {
+ return false;
+ }
}
- public boolean isEmpty() {
- return false;
+ class VpeAction extends Action {
+ public Node actionNode;
+
+ public VpeAction(String name, Node node) {
+ super(name);
+ this.actionNode = node;
+ }
}
- }
- class VpeAction extends Action {
- public Node actionNode;
+ class VpeTextOperationAction extends Action {
+ private String id;
+ private IndexedRegion region;
- public VpeAction(String name, Node node) {
- super(name);
- this.actionNode = node;
+ public VpeTextOperationAction(String name, String id,
+ IndexedRegion region) {
+ super(name);
+ this.id = id;
+ this.region = region;
+ }
+
+ public void run() {
+ sourceEditor.getSelectionProvider().setSelection(
+ new VpeSelection(region));
+ sourceEditor.getAction(id).run();
+ }
}
- }
- class VpeTextOperationAction extends Action {
- private String id;
- private IndexedRegion region;
-
- public VpeTextOperationAction(String name, String id,
- IndexedRegion region) {
- super(name);
- this.id = id;
- this.region = region;
+ public void refreshExternalLinks() {
+ pageContext.getVisualBuilder().refreshExternalLinks();
}
- public void run() {
- sourceEditor.getSelectionProvider().setSelection(
- new VpeSelection(region));
- sourceEditor.getAction(id).run();
+ public IPath getPath() {
+ if (editPart != null) {
+ IEditorInput input = editPart.getEditorInput();
+ if (input != null && input instanceof IFileEditorInput) {
+ return ((IFileEditorInput) input).getFile().getFullPath();
+ }
+ }
+ return null;
}
- }
- public void refreshExternalLinks() {
- pageContext.getVisualBuilder().refreshExternalLinks();
- }
-
- public IPath getPath() {
- if (editPart != null) {
- IEditorInput input = editPart.getEditorInput();
- if (input != null && input instanceof IFileEditorInput) {
- return ((IFileEditorInput) input).getFile().getFullPath();
- }
+ public void changed(Object source) {
+ if (cssReferenceListListener == source) {
+ pageContext.getVisualBuilder().refreshExternalLinks();
+ } else if (absoluteFolderReferenceListListener == source
+ || relativeFolderReferenceListListener == source
+ || taglibReferenceListListener == source) {
+ visualRefresh();
+ }
}
- return null;
- }
- public void changed(Object source) {
- if (cssReferenceListListener == source) {
- pageContext.getVisualBuilder().refreshExternalLinks();
- } else if (absoluteFolderReferenceListListener == source
- || relativeFolderReferenceListListener == source
- || taglibReferenceListListener == source) {
- visualRefresh();
+ public void dragEnter(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<<<<<<<<<<<<<<<<<<<
DragEnter"); //$NON-NLS-1$
+ }
}
- }
- public void dragEnter(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
-
System.out.println("<<<<<<<<<<<<<<<<<<<<
DragEnter"); //$NON-NLS-1$
+ public void dragExit(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<<<<<<<<<<<<<<<<<<<
dragExit"); //$NON-NLS-1$
+ }
+ // TODO Sergey Vasilyev figure out with drag caret
+ // xulRunnerEditor.hideDragCaret();
}
- }
- public void dragExit(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
-
System.out.println("<<<<<<<<<<<<<<<<<<<<
dragExit"); //$NON-NLS-1$
+ public void dragOver(nsIDOMEvent event) {
+ visualBuilder.getDnd().dragOver(event, this);
}
- // TODO Sergey Vasilyev figure out with drag caret
- // xulRunnerEditor.hideDragCaret();
- }
- public void dragOver(nsIDOMEvent event) {
- visualBuilder.getDnd().dragOver(event, this);
- }
-
- public void _dragOver(nsIDOMEvent event) {
+ public void _dragOver(nsIDOMEvent event) {
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
@@ -2351,564 +2430,565 @@
}
}
- public void drop(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<< outerDrop"); //$NON-NLS-1$
+ public void drop(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<< outerDrop"); //$NON-NLS-1$
+ }
+ event.preventDefault();
}
- event.preventDefault();
- }
- public boolean canInnerDrag(nsIDOMMouseEvent event) {
- onHideTooltip();
+ public boolean canInnerDrag(nsIDOMMouseEvent event) {
+ onHideTooltip();
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< canInnerDrag"); //$NON-NLS-1$
- }
- if (innerDragInfo != null) {
- innerDragInfo.Release();
- innerDragInfo = null;
- }
- boolean canDrag = false;
- VpeVisualInnerDragInfo dragInfo = selectionBuilder
- .getInnerDragInfo(event);
- if (dragInfo != null) {
- nsIDOMNode dragNode = dragInfo.getNode();
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .print(" dragNode: " + dragNode.getNodeName() + "(" + dragNode +
")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- switch (dragNode.getNodeType()) {
- case nsIDOMNode.ELEMENT_NODE:
- canDrag = visualBuilder.canInnerDrag((nsIDOMElement) dragNode);
- case nsIDOMNode.TEXT_NODE:
- canDrag = visualBuilder.isTextEditable(dragNode);
- }
- if (canDrag) {
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
- .getSourceInnerDragInfo(dragInfo);
- if (sourceInnerDragInfo.getNode() != null) {
- innerDragInfo = dragInfo;
- InnerDragBuffer.object = sourceInnerDragInfo.getNode();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- InnerDragBuffer.object = null;
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print("<<<<<< canInnerDrag"); //$NON-NLS-1$
+ }
+ if (innerDragInfo != null) {
+ innerDragInfo.Release();
+ innerDragInfo = null;
+ }
+ boolean canDrag = false;
+ VpeVisualInnerDragInfo dragInfo = selectionBuilder
+ .getInnerDragInfo(event);
+ if (dragInfo != null) {
+ nsIDOMNode dragNode = dragInfo.getNode();
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .print(" dragNode: " + dragNode.getNodeName() + "(" + dragNode
+ ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- });
- } else {
- canDrag = false;
+ switch (dragNode.getNodeType()) {
+ case nsIDOMNode.ELEMENT_NODE:
+ canDrag = visualBuilder.canInnerDrag((nsIDOMElement) dragNode);
+ case nsIDOMNode.TEXT_NODE:
+ canDrag = visualBuilder.isTextEditable(dragNode);
+ }
+ if (canDrag) {
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
+ .getSourceInnerDragInfo(dragInfo);
+ if (sourceInnerDragInfo.getNode() != null) {
+ innerDragInfo = dragInfo;
+ InnerDragBuffer.object = sourceInnerDragInfo.getNode();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ InnerDragBuffer.object = null;
+ }
+ });
+ } else {
+ canDrag = false;
+ }
+ }
+ if (!canDrag) {
+ dragInfo.Release();
+ }
}
- }
- if (!canDrag) {
- dragInfo.Release();
- }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" canDrag: " + canDrag); //$NON-NLS-1$
+ }
+ return canDrag;
}
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrag: " + canDrag); //$NON-NLS-1$
- }
- return canDrag;
- }
- VpeDropWindow dropWindow = null;
+ VpeDropWindow dropWindow = null;
- public MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
- onHideTooltip();
+ public MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
+ onHideTooltip();
- if (dropWindow.active) {
- if (!event.getAltKey()) {
- dropWindow.close();
- } else {
- return null;
- }
- }
- if (event.getAltKey()) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
- Node sourceNode = domMapping.getNearSourceNode(visualNode);
- if (sourceNode != null) {
- dropWindow.active = true;
- dropWindow.setEventPosition(event.getScreenX(), event
- .getScreenY());
- dropWindow.setInitialTargetNode(sourceNode);
- dropWindow.open();
- event.stopPropagation();
- event.preventDefault();
- return null;
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< canInnerDrop"); //$NON-NLS-1$
- }
- boolean canDrop = false;
- ;
- nsIDOMNode caretParent = null;
- long caretOffset = 0;
- if (innerDragInfo != null) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(event);
- if (visualDropInfo.getDropContainer() != null) {
+ if (dropWindow.active) {
+ if (!event.getAltKey()) {
+ dropWindow.close();
+ } else {
+ return null;
+ }
+ }
+ if (event.getAltKey()) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
+ Node sourceNode = domMapping.getNearSourceNode(visualNode);
+ if (sourceNode != null) {
+ dropWindow.active = true;
+ dropWindow.setEventPosition(event.getScreenX(), event
+ .getScreenY());
+ dropWindow.setInitialTargetNode(sourceNode);
+ dropWindow.open();
+ event.stopPropagation();
+ event.preventDefault();
+ return null;
+ }
+ }
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .print(" x: " + visualDropInfo.getMouseX() + " y: " +
visualDropInfo.getMouseY() + //$NON-NLS-1$ //$NON-NLS-2$
- " container: "
- + visualDropInfo.getDropContainer()
- .getNodeName()
- + //$NON-NLS-1$
- "("
- + visualDropInfo.getDropContainer()
- + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " parent: "
- + visualDropInfo.getDropContainer()
- .getParentNode().getNodeName()
- + //$NON-NLS-1$
- "("
- + visualDropInfo.getDropContainer()
- .getParentNode() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " offset: "
- + visualDropInfo.getDropOffset()); //$NON-NLS-1$
+ System.out.print("<<<<<< canInnerDrop"); //$NON-NLS-1$
}
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
- .getSourceInnerDragInfo(innerDragInfo);
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
- .getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
- visualDropInfo, true);
- canDrop = sourceDropInfo.canDrop();
- if (canDrop) {
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
- .getInnerDropInfo(sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(
- newVisualDropInfo, visualDropInfo);
- caretParent = newVisualDropInfo.getDropContainer();
- caretOffset = newVisualDropInfo.getDropOffset();
- }
+ boolean canDrop = false;
+ ;
+ nsIDOMNode caretParent = null;
+ long caretOffset = 0;
+ if (innerDragInfo != null) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(event);
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .print(" x: " + visualDropInfo.getMouseX() + " y: " +
visualDropInfo.getMouseY() + //$NON-NLS-1$ //$NON-NLS-2$
+ " container: "
+ + visualDropInfo.getDropContainer()
+ .getNodeName()
+ + //$NON-NLS-1$
+ "("
+ + visualDropInfo.getDropContainer()
+ + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " parent: "
+ + visualDropInfo.getDropContainer()
+ .getParentNode().getNodeName()
+ + //$NON-NLS-1$
+ "("
+ + visualDropInfo.getDropContainer()
+ .getParentNode() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " offset: "
+ + visualDropInfo.getDropOffset()); //$NON-NLS-1$
+ }
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
+ .getSourceInnerDragInfo(innerDragInfo);
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
+ .getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
+ visualDropInfo, true);
+ canDrop = sourceDropInfo.canDrop();
+ if (canDrop) {
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
+ .getInnerDropInfo(sourceDropInfo.getContainer(),
+ sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(
+ newVisualDropInfo, visualDropInfo);
+ caretParent = newVisualDropInfo.getDropContainer();
+ caretOffset = newVisualDropInfo.getDropOffset();
+ }
+ }
+ }
+ visualDropInfo.Release();
}
- }
- visualDropInfo.Release();
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" canDrop: " + canDrop); //$NON-NLS-1$
+ }
+ return new MozillaDropInfo(canDrop, caretParent, caretOffset);
}
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrop: " + canDrop); //$NON-NLS-1$
- }
- return new MozillaDropInfo(canDrop, caretParent, caretOffset);
- }
- public void innerDrop(nsIDOMMouseEvent event) {
- onHideTooltip();
+ public void innerDrop(nsIDOMMouseEvent event) {
+ onHideTooltip();
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
- }
- if (innerDragInfo != null) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(event);
- if (visualDropInfo.getDropContainer() != null) {
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .print(" container: " + visualDropInfo.getDropContainer().getNodeName()
+ //$NON-NLS-1$
- "(" + visualDropInfo.getDropContainer()
- + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " offset: "
- + visualDropInfo.getDropOffset()); //$NON-NLS-1$
+ System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
}
+ if (innerDragInfo != null) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(event);
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .print(" container: " + visualDropInfo.getDropContainer().getNodeName()
+ //$NON-NLS-1$
+ "(" + visualDropInfo.getDropContainer()
+ + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " offset: "
+ + visualDropInfo.getDropOffset()); //$NON-NLS-1$
+ }
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
- .getSourceInnerDragInfo(innerDragInfo);
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
- .getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
- visualDropInfo, true);
- if (sourceDropInfo.canDrop()) {
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
- .getInnerDropInfo(sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(
- newVisualDropInfo, visualDropInfo);
- sourceDropInfo.setTop(visualDropInfo.getMouseY());
- sourceDropInfo.setLeft(visualDropInfo.getMouseX());
- visualBuilder.innerDrop(sourceInnerDragInfo,
- sourceDropInfo);
- if (innerDragInfo != null) {
- innerDragInfo.Release();
- innerDragInfo = null;
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
+ .getSourceInnerDragInfo(innerDragInfo);
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
+ .getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
+ visualDropInfo, true);
+ if (sourceDropInfo.canDrop()) {
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
+ .getInnerDropInfo(sourceDropInfo.getContainer(),
+ sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(
+ newVisualDropInfo, visualDropInfo);
+ sourceDropInfo.setTop(visualDropInfo.getMouseY());
+ sourceDropInfo.setLeft(visualDropInfo.getMouseX());
+ visualBuilder.innerDrop(sourceInnerDragInfo,
+ sourceDropInfo);
+ if (innerDragInfo != null) {
+ innerDragInfo.Release();
+ innerDragInfo = null;
+ }
+ }
+ }
}
- }
}
- }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println();
+ }
}
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println();
- }
- }
- public MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent,
- String flavor, String data) {
- InnerDragBuffer.object = null;
- onHideTooltip();
+ public MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent,
+ String flavor, String data) {
+ InnerDragBuffer.object = null;
+ onHideTooltip();
- if (dropWindow.active) {
- if (!mouseEvent.getAltKey()) {
- dropWindow.close();
- } else {
- return new MozillaDropInfo(false, null, 0);
- }
- }
- if (mouseEvent.getAltKey()) {
- nsIDOMEvent event = (nsIDOMEvent) mouseEvent
- .queryInterface(nsIDOMEvent.NS_IDOMEVENT_IID);
- nsIDOMNode visualNode = (nsIDOMNode) event.getTarget()
- .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
- Node sourceNode = domMapping.getNearSourceNode(visualNode);
- if (sourceNode != null) {
- if (ModelTransfer.MODEL.equals(flavor)) { //$NON-NLS-1$
- // XModelObject object =
- // PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
- // InnerDragBuffer.object = object;
- } else {
- dropWindow.flavor = flavor;
+ if (dropWindow.active) {
+ if (!mouseEvent.getAltKey()) {
+ dropWindow.close();
+ } else {
+ return new MozillaDropInfo(false, null, 0);
+ }
}
- dropWindow.active = true;
- dropWindow.setEventPosition(mouseEvent.getScreenX(), mouseEvent
- .getScreenY());
- dropWindow.setInitialTargetNode(sourceNode);
- dropWindow.open();
- mouseEvent.stopPropagation();
- mouseEvent.preventDefault();
- return new MozillaDropInfo(false, null, 0);
- }
- }
- boolean canDrop = false;
- nsIDOMNode caretParent = null;
- long caretOffset = 0;
+ if (mouseEvent.getAltKey()) {
+ nsIDOMEvent event = (nsIDOMEvent) mouseEvent
+ .queryInterface(nsIDOMEvent.NS_IDOMEVENT_IID);
+ nsIDOMNode visualNode = (nsIDOMNode) event.getTarget()
+ .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+ Node sourceNode = domMapping.getNearSourceNode(visualNode);
+ if (sourceNode != null) {
+ if (ModelTransfer.MODEL.equals(flavor)) { //$NON-NLS-1$
+ // XModelObject object =
+ // PreferenceModelUtilities.getPreferenceModel().
+ // getModelBuffer().source();
+ // InnerDragBuffer.object = object;
+ } else {
+ dropWindow.flavor = flavor;
+ }
+ dropWindow.active = true;
+ dropWindow.setEventPosition(mouseEvent.getScreenX(), mouseEvent
+ .getScreenY());
+ dropWindow.setInitialTargetNode(sourceNode);
+ dropWindow.open();
+ mouseEvent.stopPropagation();
+ mouseEvent.preventDefault();
+ return new MozillaDropInfo(false, null, 0);
+ }
+ }
+ boolean canDrop = false;
+ nsIDOMNode caretParent = null;
+ long caretOffset = 0;
- if (MODEL_FLAVOR.equals(flavor)) {
- XModelObject object = PreferenceModelUtilities.getPreferenceModel()
- .getModelBuffer().source();
- if (object.getFileType() == XModelObject.FILE
- && !TLDUtil.isTaglib(object)) {
- IFile f = (IFile) EclipseResourceUtil.getResource(object);
- canDrop = f != null;
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- caretParent = visualDropInfo.getDropContainer();
- caretOffset = visualDropInfo.getDropOffset();
- } else {
- String tagname = getTagName(object);
- if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document) getModel().getAdapter(
- Document.class)).createElement(tagname);
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- if (visualDropInfo.getDropContainer() != null) {
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
- .getSourceInnerDropInfo(sourceDragNode,
- visualDropInfo, true);
- canDrop = sourceDropInfo.canDrop();
- if (canDrop) {
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
- .getInnerDropInfo(
- sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(
- newVisualDropInfo, visualDropInfo);
- caretParent = newVisualDropInfo.getDropContainer();
- caretOffset = newVisualDropInfo.getDropOffset();
+ if (MODEL_FLAVOR.equals(flavor)) {
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel()
+ .getModelBuffer().source();
+ if (object.getFileType() == XModelObject.FILE
+ && !TLDUtil.isTaglib(object)) {
+ IFile f = (IFile) EclipseResourceUtil.getResource(object);
+ canDrop = f != null;
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ caretParent = visualDropInfo.getDropContainer();
+ caretOffset = visualDropInfo.getDropOffset();
+ } else {
+ String tagname = getTagName(object);
+ if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
+ Node sourceDragNode = ((Document) getModel().getAdapter(
+ Document.class)).createElement(tagname);
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ if (visualDropInfo.getDropContainer() != null) {
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
+ .getSourceInnerDropInfo(sourceDragNode,
+ visualDropInfo, true);
+ canDrop = sourceDropInfo.canDrop();
+ if (canDrop) {
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
+ .getInnerDropInfo(
+ sourceDropInfo.getContainer(),
+ sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(
+ newVisualDropInfo, visualDropInfo);
+ caretParent = newVisualDropInfo.getDropContainer();
+ caretOffset = newVisualDropInfo.getDropOffset();
+ }
+ }
+ }
+ visualDropInfo.Release();
}
- }
+ } else if (XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor)
+ || XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ caretParent = visualDropInfo.getDropContainer();
+ caretOffset = visualDropInfo.getDropOffset();
+ try {
+ canDrop = true;
+ } catch (Exception ex) {
+ VpePlugin.reportProblem(ex);
+ }
}
- visualDropInfo.Release();
- }
- } else if (XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor)
- || XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- caretParent = visualDropInfo.getDropContainer();
- caretOffset = visualDropInfo.getDropOffset();
- try {
- canDrop = true;
- } catch (Exception ex) {
- VpePlugin.reportProblem(ex);
- }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .println(" canDrop: " + canDrop + (canDrop ? " container: " +
caretParent.getNodeName() + " offset: " + caretOffset : ""));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+ return new MozillaDropInfo(canDrop, caretParent, caretOffset);
+
}
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .println(" canDrop: " + canDrop + (canDrop ? " container: " +
caretParent.getNodeName() + " offset: " + caretOffset : ""));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ public VpeSourceInnerDropInfo canExternalDropMacro(XModelObject object,
+ Node parentNode, int offset) {
+ String tagname = getTagName(object);
+ Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
+ .createElement(tagname);
+ return visualBuilder.getSourceInnerDropInfo(sourceDragNode, parentNode,
+ offset, false);
}
- return new MozillaDropInfo(canDrop, caretParent, caretOffset);
- }
+ public void externalDropAny(final String flavor, final String data,
+ final Point range, Node container) {
+ if (flavor == null || flavor.length() == 0)
+ return;
+ IDropCommand dropCommand = DropCommandFactory.getInstance()
+ .getDropCommand(flavor, JSPTagProposalFactory.getInstance());
- public VpeSourceInnerDropInfo canExternalDropMacro(XModelObject object,
- Node parentNode, int offset) {
- String tagname = getTagName(object);
- Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
- .createElement(tagname);
- return visualBuilder.getSourceInnerDropInfo(sourceDragNode, parentNode,
- offset, false);
- }
+ boolean promptAttributes = "yes"
+ .equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
+ dropCommand.getDefaultModel().setPromptForTagAttributesRequired(
+ promptAttributes);
- public void externalDropAny(final String flavor, final String data,
- final Point range, Node container) {
- if (flavor == null || flavor.length() == 0)
- return;
- IDropCommand dropCommand = DropCommandFactory.getInstance()
- .getDropCommand(flavor, JSPTagProposalFactory.getInstance());
+ dropCommand.execute(new DropData(flavor, data, sourceEditor
+ .getEditorInput(), (ISourceViewer) sourceEditor
+ .getAdapter(ISourceViewer.class), new VpeSelectionProvider(
+ range.x, range.y), container));
+ }
- boolean promptAttributes = "yes"
- .equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
- dropCommand.getDefaultModel().setPromptForTagAttributesRequired(
- promptAttributes);
+ private String getTagName(XModelObject object) {
+ String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
- dropCommand.execute(new DropData(flavor, data, sourceEditor
- .getEditorInput(), (ISourceViewer) sourceEditor
- .getAdapter(ISourceViewer.class), new VpeSelectionProvider(
- range.x, range.y), container));
- }
+ XModelObject parent = object.getParent();
+ String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
- private String getTagName(XModelObject object) {
- String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
+ String[] texts = new String[] { "<" + tagname + ">" };
//$NON-NLS-1$ //$NON-NLS-2$
+ PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagname, uri,
+ defaultPrefix);
+ tagname = texts[0].substring(1, texts[0].length() - 1);
- XModelObject parent = object.getParent();
- String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
- String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+ return tagname;
+ }
- String[] texts = new String[] { "<" + tagname + ">" };
//$NON-NLS-1$ //$NON-NLS-2$
- PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagname, uri,
- defaultPrefix);
- tagname = texts[0].substring(1, texts[0].length() - 1);
+ public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor,
+ String data) {
+ onHideTooltip();
- return tagname;
- }
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(
+ visualDropInfo.getDropContainer(), (int) visualDropInfo
+ .getDropOffset());
+ VpeSourceInnerDropInfo sourceDropInfo = null;
- public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor,
- String data) {
- onHideTooltip();
+ if (MODEL_FLAVOR.equals(flavor)) {
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel()
+ .getModelBuffer().source();
+ if (object.getFileType() == XModelObject.FILE
+ && !TLDUtil.isTaglib(object)) {
+ flavor = "application/x-moz-file"; //$NON-NLS-1$
+ IFile f = (IFile) EclipseResourceUtil.getResource(object);
+ try {
+ data = f.getLocation().toFile().toURL().toString();
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
+ } else {
+ String tagname = getTagName(object);
+ if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
+ Node sourceDragNode = ((Document) getModel().getAdapter(
+ Document.class)).createElement(tagname);
+ if (visualDropInfo.getDropContainer() != null) {
+ sourceDropInfo = visualBuilder.getSourceInnerDropInfo(
+ sourceDragNode, visualDropInfo, true);
+ range = selectionBuilder.getSourceSelectionRange(
+ sourceDropInfo.getContainer(), sourceDropInfo
+ .getOffset());
+ }
+ }
+ }
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(
- visualDropInfo.getDropContainer(), (int) visualDropInfo
- .getDropOffset());
- VpeSourceInnerDropInfo sourceDropInfo = null;
-
- if (MODEL_FLAVOR.equals(flavor)) {
- XModelObject object = PreferenceModelUtilities.getPreferenceModel()
- .getModelBuffer().source();
- if (object.getFileType() == XModelObject.FILE
- && !TLDUtil.isTaglib(object)) {
- flavor = "application/x-moz-file"; //$NON-NLS-1$
- IFile f = (IFile) EclipseResourceUtil.getResource(object);
- try {
- data = f.getLocation().toFile().toURL().toString();
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
- }
- } else {
- String tagname = getTagName(object);
- if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document) getModel().getAdapter(
- Document.class)).createElement(tagname);
if (visualDropInfo.getDropContainer() != null) {
- sourceDropInfo = visualBuilder.getSourceInnerDropInfo(
- sourceDragNode, visualDropInfo, true);
- range = selectionBuilder.getSourceSelectionRange(
- sourceDropInfo.getContainer(), sourceDropInfo
- .getOffset());
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .println(" drop! container: " +
visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
+ }
+ externalDropAny(flavor, data, range, sourceDropInfo == null ? null
+ : sourceDropInfo.getContainer());
}
- }
}
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .println(" drop! container: " +
visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
- }
- externalDropAny(flavor, data, range, sourceDropInfo == null ? null
- : sourceDropInfo.getContainer());
- }
- }
+ public void onShowTooltip(int x, int y, final String text) {
- public void onShowTooltip(int x, int y, final String text) {
+ if (tip != null && !tip.isDisposed())
+ tip.dispose();
- if (tip != null && !tip.isDisposed())
- tip.dispose();
+ Display display = visualEditor.getControl().getDisplay();
+ Shell parent = visualEditor.getControl().getShell();
- Display display = visualEditor.getControl().getDisplay();
- Shell parent = visualEditor.getControl().getShell();
+ tip = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP);
+ Color bckgColor = new Color(tip.getDisplay(), 255, 250, 236);
+ tip.setBackground(bckgColor);
- tip = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP);
- Color bckgColor = new Color(tip.getDisplay(), 255, 250, 236);
- tip.setBackground(bckgColor);
+ Composite composite = tip;
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.verticalSpacing = 0;
+ layout.horizontalSpacing = 0;
+ composite.setLayout(layout);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ composite.setLayoutData(gd);
- Composite composite = tip;
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.verticalSpacing = 0;
- layout.horizontalSpacing = 0;
- composite.setLayout(layout);
- GridData gd = new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(gd);
+ final StyledText tipControlHeaderText = new StyledText(composite,
+ SWT.MULTI | SWT.READ_ONLY);
- final StyledText tipControlHeaderText = new StyledText(composite,
- SWT.MULTI | SWT.READ_ONLY);
+ tipControlHeaderText.setForeground(bckgColor);
+ tipControlHeaderText.setBackground(bckgColor);
- tipControlHeaderText.setForeground(bckgColor);
- tipControlHeaderText.setBackground(bckgColor);
+ String formatText = text.trim();
- String formatText = text.trim();
+ /**
+ * attributeString string containing the pairs attribute and it's value
+ * as one string
+ */
+ String[] attributeString = formatText.split("\n"); //$NON-NLS-1$
+ /**
+ * buffer string containing the attribute and the value in the different
+ * succeding string
+ */
+ String[] buffer = attributeString[0].split(" "); //$NON-NLS-1$
- /**
- * attributeString string containing the pairs attribute and it's value
- * as one string
- */
- String[] attributeString = formatText.split("\n"); //$NON-NLS-1$
- /**
- * buffer string containing the attribute and the value in the different
- * succeding string
- */
- String[] buffer = attributeString[0].split(" "); //$NON-NLS-1$
+ tipControlHeaderText.setText(buffer[0].toString());
- tipControlHeaderText.setText(buffer[0].toString());
+ tipControlHeaderText.addLineStyleListener(new LineStyleListener() {
+ public void lineGetStyle(LineStyleEvent event) {
+ Color color = new Color(tipControlHeaderText.getDisplay(), 201,
+ 51, 40);
+ if (event.lineOffset == 0) {
+ StyleRange st = new StyleRange();
+ st.fontStyle = SWT.BOLD;
+ st.foreground = color;
+ event.styles = new StyleRange[] { st };
+ st.start = event.lineOffset;
+ st.length = event.lineText.length();
+ }
+ }
+ });
- tipControlHeaderText.addLineStyleListener(new LineStyleListener() {
- public void lineGetStyle(LineStyleEvent event) {
- Color color = new Color(tipControlHeaderText.getDisplay(), 201,
- 51, 40);
- if (event.lineOffset == 0) {
- StyleRange st = new StyleRange();
- st.fontStyle = SWT.BOLD;
- st.foreground = color;
- event.styles = new StyleRange[] { st };
- st.start = event.lineOffset;
- st.length = event.lineText.length();
- }
- }
- });
+ GridData gridData = new GridData(GridData.BEGINNING
+ | GridData.FILL_BOTH);
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.horizontalSpan = 2;
+ tipControlHeaderText.setLayoutData(gridData);
- GridData gridData = new GridData(GridData.BEGINNING
- | GridData.FILL_BOTH);
- gridData.horizontalAlignment = GridData.FILL;
- gridData.horizontalSpan = 2;
- tipControlHeaderText.setLayoutData(gridData);
+ StringBuffer tempAttr = new StringBuffer();
+ StringBuffer tempValue = new StringBuffer();
- StringBuffer tempAttr = new StringBuffer();
- StringBuffer tempValue = new StringBuffer();
+ if (attributeString.length >= 2) {
+ for (int i = 1; i < attributeString.length; i++) {
+ buffer = attributeString[i].split(" ", 2); //$NON-NLS-1$
+ if (i == 1) {
+ tempAttr.append(buffer[0] + " "); //$NON-NLS-1$
+ tempValue
+ .append((buffer.length >= 2 ? buffer[1] : "") + " ");
//$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ tempAttr.append("\n" + buffer[0] + " "); //$NON-NLS-1$
//$NON-NLS-2$
+ tempValue
+ .append(" \n" + (buffer.length >= 2 ? buffer[1] : "") +
" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
- if (attributeString.length >= 2) {
- for (int i = 1; i < attributeString.length; i++) {
- buffer = attributeString[i].split(" ", 2); //$NON-NLS-1$
- if (i == 1) {
- tempAttr.append(buffer[0] + " "); //$NON-NLS-1$
- tempValue
- .append((buffer.length >= 2 ? buffer[1] : "") + " ");
//$NON-NLS-1$ //$NON-NLS-2$
- } else {
- tempAttr.append("\n" + buffer[0] + " "); //$NON-NLS-1$
//$NON-NLS-2$
- tempValue
- .append(" \n" + (buffer.length >= 2 ? buffer[1] : "") +
" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
+ final StyledText tipControlAttributeText = new StyledText(
+ composite, SWT.MULTI | SWT.READ_ONLY);
- final StyledText tipControlAttributeText = new StyledText(
- composite, SWT.MULTI | SWT.READ_ONLY);
+ tipControlAttributeText.setForeground(bckgColor);
+ tipControlAttributeText.setBackground(bckgColor);
- tipControlAttributeText.setForeground(bckgColor);
- tipControlAttributeText.setBackground(bckgColor);
+ tipControlAttributeText.setText(tempAttr.toString());
+ tipControlAttributeText
+ .addLineStyleListener(new LineStyleListener() {
+ public void lineGetStyle(LineStyleEvent event) {
+ Color color = new Color(tipControlHeaderText
+ .getDisplay(), 42, 148, 0);
+ StyleRange st = new StyleRange();
+ st.start = event.lineOffset;
+ st.length = event.lineText.length();
+ st.foreground = color;
+ st.fontStyle = SWT.NORMAL;
+ event.styles = new StyleRange[] { st };
+ }
+ });
+ GridData gridData1 = new GridData(GridData.BEGINNING
+ | GridData.FILL_BOTH);
+ gridData1.horizontalAlignment = GridData.FILL;
+ tipControlAttributeText.setLayoutData(gridData1);
- tipControlAttributeText.setText(tempAttr.toString());
- tipControlAttributeText
- .addLineStyleListener(new LineStyleListener() {
- public void lineGetStyle(LineStyleEvent event) {
- Color color = new Color(tipControlHeaderText
- .getDisplay(), 42, 148, 0);
- StyleRange st = new StyleRange();
- st.start = event.lineOffset;
- st.length = event.lineText.length();
- st.foreground = color;
- st.fontStyle = SWT.NORMAL;
- event.styles = new StyleRange[] { st };
- }
- });
- GridData gridData1 = new GridData(GridData.BEGINNING
- | GridData.FILL_BOTH);
- gridData1.horizontalAlignment = GridData.FILL;
- tipControlAttributeText.setLayoutData(gridData1);
+ final StyledText tipControlValueText = new StyledText(composite,
+ SWT.MULTI | SWT.READ_ONLY);
- final StyledText tipControlValueText = new StyledText(composite,
- SWT.MULTI | SWT.READ_ONLY);
+ tipControlValueText.setBackground(bckgColor);
- tipControlValueText.setBackground(bckgColor);
+ tipControlValueText.setText(tempValue.toString());
- tipControlValueText.setText(tempValue.toString());
+ GridData gridData2 = new GridData(GridData.BEGINNING
+ | GridData.FILL_BOTH);
+ gridData2.horizontalAlignment = GridData.FILL;
+ tipControlValueText.setLayoutData(gridData2);
+ }
+ /*
+ * Bug in Mozilla embedded API. Tooltip coordinates are wrong for
+ * elements inside an inline frame (IFrame tag). The workaround is to
+ * position the tooltip based on the mouse cursor location.
+ */
+ Point point = display.getCursorLocation();
+ /*
+ * Assuming cursor is 21x21 because this is the size of the arrow cursor
+ * on Windows
+ */
+ point.y += 21;
+ tip.setLocation(point);
+ tip.pack();
+ tip.setVisible(true);
+ }
- GridData gridData2 = new GridData(GridData.BEGINNING
- | GridData.FILL_BOTH);
- gridData2.horizontalAlignment = GridData.FILL;
- tipControlValueText.setLayoutData(gridData2);
+ public void onHideTooltip() {
+ if (tip != null && !tip.isDisposed())
+ tip.dispose();
+ tip = null;
}
- /*
- * Bug in Mozilla embedded API. Tooltip coordinates are wrong for
- * elements inside an inline frame (IFrame tag). The workaround is to
- * position the tooltip based on the mouse cursor location.
- */
- Point point = display.getCursorLocation();
- /*
- * Assuming cursor is 21x21 because this is the size of the arrow cursor
- * on Windows
- */
- point.y += 21;
- tip.setLocation(point);
- tip.pack();
- tip.setVisible(true);
- }
- public void onHideTooltip() {
- if (tip != null && !tip.isDisposed())
- tip.dispose();
- tip = null;
- }
+ public VpePageContext getPageContext() {
- public VpePageContext getPageContext() {
+ return pageContext;
+ }
- return pageContext;
- }
+ public StructuredTextEditor getSourceEditor() {
+ return sourceEditor;
+ }
- public StructuredTextEditor getSourceEditor() {
- return sourceEditor;
- }
+ public FormatControllerManager getToolbarFormatControllerManager() {
+ return toolbarFormatControllerManager;
+ }
- public FormatControllerManager getToolbarFormatControllerManager() {
- return toolbarFormatControllerManager;
- }
+ public void setToolbarFormatControllerManager(
+ FormatControllerManager formatControllerManager) {
+ toolbarFormatControllerManager = formatControllerManager;
+ }
- public void setToolbarFormatControllerManager(
- FormatControllerManager formatControllerManager) {
- toolbarFormatControllerManager = formatControllerManager;
- }
+ public void setSelectionBarController(SelectionBar selectionBar) {
+ this.selectionBar = selectionBar;
+ }
- public void setSelectionBarController(SelectionBar selectionBar) {
- this.selectionBar = selectionBar;
- }
+ public IStructuredModel getModel() {
+ return sourceEditor.getModel();
+ }
- public IStructuredModel getModel() {
- return sourceEditor.getModel();
- }
+ public VpeDomMapping getDomMapping() {
+ return domMapping;
+ }
- public VpeDomMapping getDomMapping() {
- return domMapping;
- }
-
- public VpeIncludeList getIncludeList() {
- try {
- if (includeList == null)
- throw new Exception("includeList - NULL!!!"); //$NON-NLS-1$
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
+ public VpeIncludeList getIncludeList() {
+ try {
+ if (includeList == null)
+ throw new Exception("includeList - NULL!!!"); //$NON-NLS-1$
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
+ return includeList;
}
- return includeList;
- }
- public void selectionChanged(SelectionChangedEvent event) {
+ public void selectionChanged(SelectionChangedEvent event) {
// FIX for JBIDE-2114
if (!isVisualEditorVisible()) {
// selection event doesn't changes a content
@@ -2941,128 +3021,128 @@
}
}
- // nsIClipboardDragDropHooks implementation
- public void onPasteOrDrop(nsIDOMMouseEvent mouseEvent, String flavor,
- String data) {
- onHideTooltip();
+ // nsIClipboardDragDropHooks implementation
+ public void onPasteOrDrop(nsIDOMMouseEvent mouseEvent, String flavor,
+ String data) {
+ onHideTooltip();
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(
- visualDropInfo.getDropContainer(), (int) visualDropInfo
- .getDropOffset());
- VpeSourceInnerDropInfo sourceDropInfo = null;
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(
+ visualDropInfo.getDropContainer(), (int) visualDropInfo
+ .getDropOffset());
+ VpeSourceInnerDropInfo sourceDropInfo = null;
- XModelObject object = PreferenceModelUtilities.getPreferenceModel()
- .getModelBuffer().source();
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel()
+ .getModelBuffer().source();
- String tagname = getTagName(object);
- if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
- .createElement(tagname);
- if (visualDropInfo.getDropContainer() != null) {
- sourceDropInfo = visualBuilder.getSourceInnerDropInfo(
- sourceDragNode, visualDropInfo, true);
- range = selectionBuilder.getSourceSelectionRange(sourceDropInfo
- .getContainer(), sourceDropInfo.getOffset());
- }
+ String tagname = getTagName(object);
+ if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
+ Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
+ .createElement(tagname);
+ if (visualDropInfo.getDropContainer() != null) {
+ sourceDropInfo = visualBuilder.getSourceInnerDropInfo(
+ sourceDragNode, visualDropInfo, true);
+ range = selectionBuilder.getSourceSelectionRange(sourceDropInfo
+ .getContainer(), sourceDropInfo.getOffset());
+ }
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .println(" drop! container: " +
visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
- }
- final String finalFlavor = flavor;
- final String finalData = data;
- final Point finalRange = range;
- final Node finalDropContainer = sourceDropInfo == null ? null
- : sourceDropInfo.getContainer();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- externalDropAny(finalFlavor, finalData, finalRange,
- finalDropContainer);
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .println(" drop! container: " +
visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
+ }
+ final String finalFlavor = flavor;
+ final String finalData = data;
+ final Point finalRange = range;
+ final Node finalDropContainer = sourceDropInfo == null ? null
+ : sourceDropInfo.getContainer();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ externalDropAny(finalFlavor, finalData, finalRange,
+ finalDropContainer);
+ }
+ });
}
- });
}
- }
- public void drop(Node node, Node parentNode, int offset) {
- visualBuilder.innerDrop(node, parentNode, offset);
- }
+ public void drop(Node node, Node parentNode, int offset) {
+ visualBuilder.innerDrop(node, parentNode, offset);
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.mozilla.interfaces.nsISupports#queryInterface(java.lang.String)
- */
- public nsISupports queryInterface(String arg0) {
- return Mozilla.getInstance().queryInterface(this, arg0);
- }
-
- /**
- * Calls when editor content should be refreshed
- */
- public void onRefresh() {
- // when we using separate thread to display selection rectangle
- // it's working better than without
/*
- * HACK We need wait some time while standart event will be handled and
- * in process event handles some components are repainted(like buttons)
- * and flasher are not repainted, so we should paint flasher
+ * (non-Javadoc)
+ *
+ * @see org.mozilla.interfaces.nsISupports#queryInterface(java.lang.String)
*/
+ public nsISupports queryInterface(String arg0) {
+ return Mozilla.getInstance().queryInterface(this, arg0);
+ }
- Display.getDefault().asyncExec(new Thread() {
- public void run() {
+ /**
+ * Calls when editor content should be refreshed
+ */
+ public void onRefresh() {
+ // when we using separate thread to display selection rectangle
+ // it's working better than without
+ /*
+ * HACK We need wait some time while standart event will be handled and
+ * in process event handles some components are repainted(like buttons)
+ * and flasher are not repainted, so we should paint flasher
+ */
- getXulRunnerEditor().showSelectionRectangle();
- }
- });
+ Display.getDefault().asyncExec(new Thread() {
+ public void run() {
- }
+ getXulRunnerEditor().showSelectionRectangle();
+ }
+ });
- /**
- * @return the xulRunnerEditor
- */
- public XulRunnerEditor getXulRunnerEditor() {
- return xulRunnerEditor;
- }
+ }
- /**
- * @param xulRunnerEditor
- * the xulRunnerEditor to set
- */
- public void setXulRunnerEditor(XulRunnerEditor xulRunnerEditor) {
- this.xulRunnerEditor = xulRunnerEditor;
- }
+ /**
+ * @return the xulRunnerEditor
+ */
+ public XulRunnerEditor getXulRunnerEditor() {
+ return xulRunnerEditor;
+ }
- /**
- * Start drag session
- */
- public void startDragSession(nsIDOMEvent domEvent) {
+ /**
+ * @param xulRunnerEditor
+ * the xulRunnerEditor to set
+ */
+ public void setXulRunnerEditor(XulRunnerEditor xulRunnerEditor) {
+ this.xulRunnerEditor = xulRunnerEditor;
+ }
- visualBuilder.getDnd().startDragSession(domEvent);
- }
+ /**
+ * Start drag session
+ */
+ public void startDragSession(nsIDOMEvent domEvent) {
- public void dragDrop(nsIDOMEvent domEvent) {
+ visualBuilder.getDnd().startDragSession(domEvent);
+ }
- visualBuilder.getDnd().dragDrop(domEvent, this);
- }
+ public void dragDrop(nsIDOMEvent domEvent) {
- /**
- * @return the selectionBuilder
- */
- public VpeSelectionBuilder getSelectionBuilder() {
- return selectionBuilder;
- }
+ visualBuilder.getDnd().dragDrop(domEvent, this);
+ }
- /**
- * @param selectionBuilder
- * the selectionBuilder to set
- */
- public void setSelectionBuilder(VpeSelectionBuilder selectionBuilder) {
- this.selectionBuilder = selectionBuilder;
- }
+ /**
+ * @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;
}
@@ -3092,39 +3172,40 @@
synced = true;
}
- /**
- * @return the progressMonitor
- */
- private IProgressMonitor getProgressMonitor() {
-
- if(progressMonitor==null) {
-
- progressMonitor = Job.getJobManager().createProgressGroup();
- }
-
- return progressMonitor;
- }
+ /**
+ * @return the progressMonitor
+ */
+ private IProgressMonitor getProgressMonitor() {
+ if (progressMonitor == null) {
+
+ progressMonitor = Job.getJobManager().createProgressGroup();
+ }
+
+ return progressMonitor;
+ }
+
/**
- * @param progressMonitor the progressMonitor to set
- */
- private void setProgressMonitor(IProgressMonitor progressMonitor) {
-
- this.progressMonitor = progressMonitor;
- }
+ * @param progressMonitor
+ * the progressMonitor to set
+ */
+ private void setProgressMonitor(IProgressMonitor progressMonitor) {
+ this.progressMonitor = progressMonitor;
+ }
+
/**
* @return the changeEvents
*/
public LinkedList<VpeEventBean> getChangeEvents() {
-
- if(changeEvents==null) {
-
- changeEvents = new LinkedList<VpeEventBean>();
- }
+
+ if (changeEvents == null) {
+
+ changeEvents = new LinkedList<VpeEventBean>();
+ }
return changeEvents;
}
-
+
public void reinit() {
visualBuilder.setSelectionRectangle(null);
@@ -3137,8 +3218,7 @@
visualBuilder.rebuildDom(null);
}
- visualSelectionController.setSelection(xulRunnerEditor
- .getSelection());
+ visualSelectionController.setSelection(xulRunnerEditor.getSelection());
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -21,7 +21,7 @@
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
-import org.jboss.tools.vpe.editor.template.ITemplateSelectionManager;
+import org.jboss.tools.vpe.editor.template.ISelectionManager;
import org.jboss.tools.vpe.editor.template.VpePseudoContentCreator;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -47,6 +47,11 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+/**
+ *
+ * @deprecated
+ *
+ */
public class VpeSelectionBuilder {
private static int HUGE_DISTANCE = 999999;
private VpeDomMapping domMapping;
@@ -76,11 +81,11 @@
VpeTemplate vpeTemplate = TemplateManagingUtil
.getTemplateByVisualSelection(visualBuilder.getPageContext(),
TemplateManagingUtil.getSelectedNode(selection));
- if (vpeTemplate instanceof ITemplateSelectionManager) {
- ((ITemplateSelectionManager) vpeTemplate).setSelection(
- visualBuilder.getPageContext(), selection);
- return;
- }
+// if (vpeTemplate instanceof ITemplateSelectionManager) {
+// ((ITemplateSelectionManager) vpeTemplate).setSelection(
+// visualBuilder.getPageContext(), selection);
+// return;
+// }
if (selection.getIsCollapsed()) {
VisualSelectionInfo info = getVisualFocusSelectedInfo(selection);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -35,10 +35,9 @@
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.selection.VpeSelectionHelper;
-import org.jboss.tools.vpe.editor.template.ITemplateNodesManager;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
-import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
+import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
@@ -252,21 +251,20 @@
}
boolean openBundleEditors(nsIDOMNode visualNode) {
- VpeElementMapping elementMapping = TemplateManagingUtil
- .getElementMappingByVisualSelection(pageContext, visualNode);
- if (elementMapping != null) {
+ VpeNodeMapping nodeMapping = NodesManagingUtil.getNodeMapping(
+ domMapping, visualNode);
+ if (nodeMapping != null
+ && nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+
+ VpeElementMapping elementMapping = (VpeElementMapping) nodeMapping;
+
VpeTemplate template = elementMapping.getTemplate();
- // if template implements VpeTemplateNodesManager interface
- if (template instanceof ITemplateNodesManager) {
- return ((ITemplateNodesManager) template).openBundle(
- pageContext, visualNode, elementMapping);
- } else {
+ if (!template.openBundle(pageContext, visualNode, elementMapping))
template.openBundleEditors(pageContext,
(Element) elementMapping.getSourceNode(),
elementMapping.getData());
- }
}
return false;
}
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 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -1254,11 +1254,11 @@
return visualEditor.getContentArea();
}
- public void setSelectionRectangle(nsIDOMElement visualElement) {
+ public void setSelectionRectangle(/*nsIDOMElement*/ nsIDOMNode visualElement) {
setSelectionRectangle(visualElement, true);
}
- void setSelectionRectangle(nsIDOMElement visualElement, boolean scroll) {
+ void setSelectionRectangle(/*nsIDOMElement*/ nsIDOMNode visualElement, boolean
scroll) {
int resizerConstrains = getResizerConstrains(visualElement);
visualEditor.setSelectionRectangle(visualElement, resizerConstrains,
scroll);
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 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -42,7 +42,7 @@
import org.jboss.tools.vpe.editor.selection.VpeSelectedNodeInfo;
import org.jboss.tools.vpe.editor.selection.VpeSourceSelection;
import org.jboss.tools.vpe.editor.selection.VpeSourceSelectionBuilder;
-import org.jboss.tools.vpe.editor.template.ITemplateKeyEventHandler;
+import org.jboss.tools.vpe.editor.template.IKeyEventHandler;
import org.jboss.tools.vpe.editor.template.VpeHtmlTemplate;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.util.FlatIterator;
@@ -174,11 +174,11 @@
// if template сan handle keyEvent than pass control to him. And if
// template handled event return true
- if ((template instanceof ITemplateKeyEventHandler)
- && ((ITemplateKeyEventHandler) template).handleKeyPress(
- pageContext, keyEvent)) {
- return true;
- }
+// if ((template instanceof ITemplateKeyEventHandler)
+// && ((ITemplateKeyEventHandler) template).handleKeyPress(
+// pageContext, keyEvent)) {
+// return true;
+// }
if (keyCode == VK_ENTER) {
return split();
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/AttributeData.java
(from rev 8946,
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/AttributeData.java)
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/AttributeData.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/AttributeData.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,57 @@
+package org.jboss.tools.vpe.editor.mapping;
+
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Attr;
+
+/**
+ *
+ * @author Sergey Dzmitrovich
+ *
+ * Keep information about output Attribute. Set up a correspondence
+ * source node and visual node
+ *
+ */
+public class AttributeData extends NodeData {
+
+ /**
+ * some attributes can have a visual representation but have not a source
+ * representation
+ */
+ private String attributeName;
+
+ public AttributeData(Attr attr, nsIDOMNode visualNode, boolean editable) {
+ super(attr, visualNode, editable);
+ }
+
+ public AttributeData(String attributeName, nsIDOMNode visualNode,
+ boolean editable) {
+
+ super(null, visualNode, editable);
+
+ // initialize attributeName field
+ this.attributeName = attributeName;
+
+ }
+
+ public AttributeData(String attributeName, nsIDOMNode visualNode) {
+
+ super(null, visualNode, true);
+
+ // initialize attributeName field
+ this.attributeName = attributeName;
+
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ public void setAttributeName(String attributeName) {
+ this.attributeName = attributeName;
+ }
+
+ @Override
+ public int getType() {
+ return ATTRIBUTE;
+ }
+}
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/NodeData.java
(from rev 8946,
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/NodeData.java)
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/NodeData.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/NodeData.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.mapping;
+
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @author Sergey Dzmitrovich
+ *
+ * Keep information about output Node. Set up a correspondence source
+ * node and visual node
+ *
+ *
+ */
+public class NodeData {
+
+ public static int NODE = 0;
+
+ public static int ATTRIBUTE = 1;
+
+ /**
+ * source presentation of attribute
+ */
+ protected Node sourceNode;
+
+ /**
+ * visual presentation of attribute
+ */
+ protected nsIDOMNode visualNode;
+
+ /**
+ * mark if editable
+ */
+ protected boolean isEditable;
+
+ public NodeData(Node sourceNode, nsIDOMNode visualNode, boolean isEditable) {
+ this.sourceNode = sourceNode;
+ this.visualNode = visualNode;
+ this.isEditable = isEditable;
+
+ }
+
+ public NodeData(Node sourceNode, nsIDOMNode visualNode) {
+ this.sourceNode = sourceNode;
+ this.visualNode = visualNode;
+ this.isEditable = true;
+
+ }
+
+ public NodeData() {
+ this.visualNode = null;
+ this.sourceNode = null;
+ this.isEditable = true;
+
+ }
+
+ public Node getSourceNode() {
+ return sourceNode;
+ }
+
+ public void setSourceNode(Node sourceNode) {
+ this.sourceNode = sourceNode;
+ }
+
+ public nsIDOMNode getVisualNode() {
+ return visualNode;
+ }
+
+ public void setVisualNode(nsIDOMNode visualNode) {
+ this.visualNode = visualNode;
+ }
+
+ public boolean isEditable() {
+ return isEditable;
+ }
+
+ public void setEditable(boolean isEditable) {
+ this.isEditable = isEditable;
+ }
+
+ public int getType() {
+ return NODE;
+ }
+
+}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeAttributeData.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeAttributeData.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeAttributeData.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -1,140 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.editor.mapping;
-
-import org.mozilla.interfaces.nsIDOMNode;
-import org.w3c.dom.Attr;
-
-/**
- *
- * @author Sergey Dzmitrovich
- *
- * Keep information about output attribute. Set up a correspondence source node
- * and visual node
- *
- *
- */
-public class VpeAttributeData {
-
- /**
- * source presentation of attribute
- */
- private Attr sourceAttr;
-
- /**
- * visual presentation of attribute
- */
- private nsIDOMNode visualAttr;
-
- /**
- * mark if editable
- */
- private boolean isEditable;
-
- /**
- * name of attribute. add for cases when attribute has default value and
- * attribute has not source presentation but has visual presentation
- */
- private String attributeName;
-
- public VpeAttributeData(Attr sourceAttr, nsIDOMNode visualAttr,
- boolean isEditable) {
- this.sourceAttr = sourceAttr;
- this.visualAttr = visualAttr;
- this.isEditable = isEditable;
-
- }
-
- public VpeAttributeData(Attr sourceAttr, nsIDOMNode visualAttr) {
- this.sourceAttr = sourceAttr;
- this.visualAttr = visualAttr;
- this.isEditable = true;
-
- }
-
- public VpeAttributeData(String attributeName, nsIDOMNode visualAttr,
- boolean isEditable) {
- this.attributeName = attributeName;
- this.visualAttr = visualAttr;
- this.isEditable = isEditable;
-
- }
-
- public VpeAttributeData(String attributeName, nsIDOMNode visualAttr) {
- this.attributeName = attributeName;
- this.visualAttr = visualAttr;
- this.isEditable = true;
-
- }
-
- /**
- * get source
- *
- * @return
- */
- public Attr getSourceAttr() {
- return sourceAttr;
- }
-
- /**
- * set source
- *
- * @param sourceAttr
- */
- public void setSourceAttr(Attr sourceAttr) {
- this.sourceAttr = sourceAttr;
- }
-
- /**
- * get visual
- *
- * @return
- */
- public nsIDOMNode getVisualAttr() {
- return visualAttr;
- }
-
- /**
- * set visual
- *
- * @param visualAttr
- */
- public void setVisualAttr(nsIDOMNode visualAttr) {
- this.visualAttr = visualAttr;
- }
-
- /**
- * is editable
- *
- * @return
- */
- public boolean isEditable() {
- return isEditable;
- }
-
- /**
- * set editable
- *
- * @param isEditable
- */
- public void setEditable(boolean isEditable) {
- this.isEditable = isEditable;
- }
-
- public String getAttributeName() {
- return attributeName;
- }
-
- public void setAttributeName(String attributeName) {
- this.attributeName = attributeName;
- }
-
-}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementData.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementData.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementData.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -17,45 +17,47 @@
*
* @author Sergey Dzmitrovich
*
- * keep information about element
+ * keep information about element
*/
public class VpeElementData {
/**
- * list of attribute data
+ * list of node data
*
- * keep information about output attributes
+ * keep information about output nodes ( one element can contain some nodes
+ * )
*/
- private List<VpeAttributeData> attributesData;
+ private List<NodeData> nodesData;
/**
- * get attributes data
+ * get nodes data
*
* @return
*/
- public List<VpeAttributeData> getAttributesData() {
- return attributesData;
+ public List<NodeData> getNodesData() {
+ return nodesData;
}
/**
- * set attributes data
+ * set nodes data
*
- * @param attributesData
+ * @param nodesData
*/
- public void setAttributesData(List<VpeAttributeData> attributesData) {
- this.attributesData = attributesData;
+ public void setNodesData(List<NodeData> nodesData) {
+ this.nodesData = nodesData;
}
/**
* add <code>VpeAttributeData</code>
+ *
* @param attributeData
*/
- public void addAttributeData(VpeAttributeData attributeData) {
+ public void addNodeData(NodeData nodeData) {
- if (attributesData == null)
- attributesData = new ArrayList<VpeAttributeData>();
+ if (nodesData == null)
+ nodesData = new ArrayList<NodeData>();
- attributesData.add(attributeData);
+ nodesData.add(nodeData);
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -553,9 +553,9 @@
}
}
- public void setSelectionRectangle(nsIDOMElement element, int resizerConstrains, boolean
scroll) {
+ public void setSelectionRectangle(/*nsIDOMElement*/nsIDOMNode element, int
resizerConstrains, boolean scroll) {
if (getContentAreaEventListener() != null) {
- xulRunnerEditor.setSelectionRectangle((nsIDOMElement)element, resizerConstrains,
scroll);
+ xulRunnerEditor.setSelectionRectangle(element, resizerConstrains, scroll);
}
}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -1,1217 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.editor.template;
-
-import java.util.List;
-
-import org.eclipse.swt.graphics.Point;
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
-import org.jboss.tools.vpe.editor.mapping.VpeElementData;
-import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
-import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
-import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
-import org.jboss.tools.vpe.editor.util.TextUtil;
-import org.jboss.tools.vpe.editor.util.VisualDomUtil;
-import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMKeyEvent;
-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;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * Abstract class to handle keyEvent.
- *
- * Default implementation of ITemplateKeyEventHandler. In result of work
- * handleKeyPress() call one from handle* methods.
- *
- * You must override some handle* methods if you want change work of your
- * handler *
- *
- * Default implementation of ITemplateNodesManager.
- *
- * @author Sergey Dzmitrovich
- *
- */
-public abstract class EditableTemplateAdapter extends VpeAbstractTemplate
- implements ITemplateKeyEventHandler, ITemplateNodesManager,
- ITemplateSelectionManager {
-
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.VpeTemplateKeyEventHandler#handleKeyPress(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.mozilla.interfaces.nsIDOMKeyEvent)
- */
- final public boolean handleKeyPress(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- long keyCode = keyEvent.getKeyCode();
-
- if (keyCode == nsIDOMKeyEvent.DOM_VK_ENTER) {
- return handleEnter(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_LEFT)
- && (!keyEvent.getShiftKey())) {
- return handleLeft(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_UP)
- && (!keyEvent.getShiftKey())) {
- return handleUp(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_RIGHT)
- && (!keyEvent.getShiftKey())) {
- return handleRight(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_DOWN)
- && (!keyEvent.getShiftKey())) {
- return handleDown(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_HOME)
- && (!keyEvent.getShiftKey())) {
- return handleHome(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_END)
- && (!keyEvent.getShiftKey())) {
- return handleEnd(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_BACK_SPACE)
- && (!keyEvent.getShiftKey())) {
- return handleLeftDelete(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_DELETE)
- && (!keyEvent.getShiftKey())) {
- return handleRightDelete(pageContext, keyEvent);
-
- } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_PAGE_UP)
- && (!keyEvent.getShiftKey())) {
- return handlePageUp(pageContext, keyEvent);
-
- } else if (keyEvent.getCharCode() != 0) {
- return handleCharacter(pageContext, keyEvent);
-
- } else if ((keyEvent.getKeyCode() == nsIDOMKeyEvent.DOM_VK_INSERT)
- && keyEvent.getShiftKey()) {
- return handleInsert(pageContext, keyEvent);
- }
-
- return false;
- }
-
- /**
- * Default handling of a pressing the "insert" event - always return false.
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleInsert(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
- return false;
- }
-
- /**
- * Default handling of a pressing a character event
- *
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleCharacter(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get visual node which is focused
- nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
- if (elementMapping == null || elementMapping.getElementData() == null) {
- return false;
- }
-
- VpeElementData elementData = elementMapping.getElementData();
-
- // if node editable
- if (isNodeEditable(visualNode, elementData)) {
-
- VpeAttributeData attributeData = getAttributeData(visualNode,
- elementMapping.getElementData());
-
- Node node;
- Point selectedRange;
- // get source node
- if ((attributeData.getSourceAttr() == null)
- && (attributeData.getAttributeName() != null)) {
-
- node = createAttribute(
- (Element) elementMapping.getSourceNode(), attributeData
- .getAttributeName(), EMPTY_STRING);
- selectedRange = new Point(0, 0);
- } else {
-
- node = getTargetSourceNodeByVisualNode(pageContext, visualNode,
- elementMapping);
- selectedRange = getSelectionRange(TemplateManagingUtil
- .getCurrentSelection(pageContext));
- }
-
- if (node == null || selectedRange == null)
- return false;
-
- // get focus and anchor offsets
- int focusOffset = selectedRange.x;
- int anchorOffset = selectedRange.x + selectedRange.y;
-
- // initialization offset and length selected string
- int startOffset = 0;
- int length = 0;
-
- // set start offset and length selected string
- if (focusOffset < anchorOffset) {
- startOffset = focusOffset;
- length = anchorOffset - focusOffset;
- } else {
- startOffset = anchorOffset;
- length = focusOffset - anchorOffset;
- }
-
- // get inserted string
- long charCode = keyEvent.getCharCode();
- char[] s = new char[1];
- s[0] = (char) charCode;
- String str = new String(s);
- if (TextUtil.containsKey(s[0])) {
- str = TextUtil.getValue(s[0]);
- }
-
- // get value
- String oldValue = node.getNodeValue();
-
- // create new value
- String newValue = oldValue.substring(0, startOffset) + str
- + oldValue.substring(startOffset + length);
-
- node.setNodeValue(newValue);
-
- // set selection
- TemplateManagingUtil.setSourceSelection(pageContext, node,
- startOffset + 1, 0);
-
- }
- return true;
- }
-
- /**
- * Default handling of a pressing the "page up" event - always return false.
- *
- * Override this method for a handling of a pressing the "page up" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handlePageUp(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
- return false;
- }
-
- /**
- * Default implementation of a handling of a pressing the "delete" event
- *
- * Override this method for a handling of a pressing the "delete" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleRightDelete(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get visual node which is focused
- nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
- if (elementMapping == null || elementMapping.getElementData() == null) {
- return false;
- }
-
- VpeElementData elementData = elementMapping.getElementData();
-
- // if node editable
- if (isNodeEditable(visualNode, elementData)) {
-
- VpeAttributeData attributeData = getAttributeData(visualNode,
- elementMapping.getElementData());
-
- Node node;
- Point selectedRange;
- // get source node
- if ((attributeData.getSourceAttr() == null)
- && (attributeData.getAttributeName() != null)) {
-
- node = createAttribute(
- (Element) elementMapping.getSourceNode(), attributeData
- .getAttributeName(), EMPTY_STRING);
- selectedRange = new Point(0, 0);
- } else {
-
- node = getTargetSourceNodeByVisualNode(pageContext, visualNode,
- elementMapping);
- selectedRange = getSelectionRange(TemplateManagingUtil
- .getCurrentSelection(pageContext));
- }
-
- if (node == null || selectedRange == null)
- return false;
-
- // get focus and anchor offsets
-
- int focusOffset = selectedRange.x;
- int anchorOffset = selectedRange.x + selectedRange.y;
-
- // initialization offset and length selected string
- int startOffset = 0;
- int length = 0;
-
- // set start offset and length selected string
- // if text was not selected then will be deleted next character
- if (focusOffset == anchorOffset) {
-
- // if offset is end of text will do nothing
- if (focusOffset == node.getNodeValue().length()) {
- TemplateManagingUtil.setSourceSelection(pageContext, node,
- focusOffset, 0);
- return true;
- }
-
- startOffset = focusOffset;
- length = 1;
- }
- // if some text was selected
- else if (focusOffset < anchorOffset) {
- startOffset = focusOffset;
- length = anchorOffset - focusOffset;
- } else {
- startOffset = anchorOffset;
- length = focusOffset - anchorOffset;
- }
-
- // get old value
- String oldValue = node.getNodeValue();
-
- // create new value
- String newValue = oldValue.substring(0, startOffset)
- + oldValue.substring(startOffset + length);
-
- // set new value
- node.setNodeValue(newValue);
-
- // set new selection
- TemplateManagingUtil.setSourceSelection(pageContext, node,
- startOffset, 0);
-
- }
-
- return true;
- }
-
- /**
- * Default handling of a pressing the "backspace" event
- *
- * Override this method to handle the "backspace" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleLeftDelete(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get visual node which is focused
- nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
- if (elementMapping == null || elementMapping.getElementData() == null) {
- return false;
- }
-
- VpeElementData elementData = elementMapping.getElementData();
-
- // if node editable
- if (isNodeEditable(visualNode, elementData)) {
-
- VpeAttributeData attributeData = getAttributeData(visualNode,
- elementMapping.getElementData());
-
- Node node;
- Point selectedRange;
- // get source node
- if ((attributeData.getSourceAttr() == null)
- && (attributeData.getAttributeName() != null)) {
-
- node = createAttribute(
- (Element) elementMapping.getSourceNode(), attributeData
- .getAttributeName(), EMPTY_STRING);
- selectedRange = new Point(0, 0);
- } else {
-
- node = getTargetSourceNodeByVisualNode(pageContext, visualNode,
- elementMapping);
- selectedRange = getSelectionRange(TemplateManagingUtil
- .getCurrentSelection(pageContext));
- }
- if (node == null || selectedRange == null)
- return false;
-
- // get focus and anchor offsets
-
- int focusOffset = selectedRange.x;
- int anchorOffset = selectedRange.x + selectedRange.y;
-
- // initialization offset and length selected string
- int startOffset = 0;
- int length = 0;
-
- // set start offset and length selected string
- // if text was not selected then will be deleted previous character
- if (focusOffset == anchorOffset) {
- // if offset is start of text then will do nothing
- if (focusOffset == 0) {
-
- TemplateManagingUtil.setSourceSelection(pageContext, node,
- 0, 0);
- return true;
- }
- // set start offset to previous character
- startOffset = focusOffset - 1;
- length = 1;
- }
- // if some text was selected
- else if (focusOffset < anchorOffset) {
- startOffset = focusOffset;
- length = anchorOffset - focusOffset;
- } else {
- startOffset = anchorOffset;
- length = focusOffset - anchorOffset;
- }
-
- // get old value
- String oldValue = node.getNodeValue();
-
- // create new value
- String newValue = oldValue.substring(0, startOffset)
- + oldValue.substring(startOffset + length);
-
- // set new value
- node.setNodeValue(newValue);
-
- // set new selection
- TemplateManagingUtil.setSourceSelection(pageContext, node,
- startOffset, 0);
-
- }
-
- return true;
- }
-
- /**
- * Default handling of a pressing the "end" event - always return false.
- *
- * Override this method to handle of a pressing the "end" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleEnd(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
- return false;
- }
-
- /**
- * Default handling of a pressing the "home" event - always return false.
- *
- * Override this method to handle of a pressing the "home" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleHome(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
- return false;
- }
-
- /**
- * Default handling of a pressing the "down" event - always return false.
- *
- * Override this method to handle of a pressing the "down" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleDown(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
- return false;
- }
-
- /**
- * Default handling of a pressing the "right" event - always return false.
- *
- * Override this method to handle of a pressing the "right" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleRight(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get visual node which is focused
- nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
- if (elementMapping == null || elementMapping.getElementData() == null) {
- return false;
- }
-
- VpeElementData elementData = elementMapping.getElementData();
-
- // get source node
- Node node = getTargetSourceNodeByVisualNode(pageContext, visualNode,
- elementMapping);
-
- // get focus and anchor offsets
- Point selectedRange = getSelectionRange(TemplateManagingUtil
- .getCurrentSelection(pageContext));
-
- if (node == null || selectedRange == null)
- return false;
-
- int focusOffset = selectedRange.x;
-
- // if node editable
- if (isNodeEditable(visualNode, elementData)) {
-
- if (focusOffset != node.getNodeValue().length()) {
- TemplateManagingUtil.setSourceSelection(pageContext, node,
- focusOffset + 1, 0);
- } else
- TemplateManagingUtil.setSourceSelection(pageContext, node,
- focusOffset, 0);
- }
- return true;
-
- }
-
- /**
- * Default handling of a pressing the "up" event - always return false.
- *
- * Override this method to handle of a pressing the "up" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleUp(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
- return false;
- }
-
- /**
- * Default handling of a pressing the "left" event - always return false.
- *
- * Override this method to handle of a pressing the "left" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleLeft(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get visual node which is focused
- nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
- if (elementMapping == null || elementMapping.getElementData() == null) {
- return false;
- }
-
- VpeElementData elementData = elementMapping.getElementData();
-
- // if node editable
- if (isNodeEditable(visualNode, elementData)) {
-
- // get source node
- Node node = getTargetSourceNodeByVisualNode(pageContext,
- visualNode, elementMapping);
-
- // get focus and anchor offsets
- Point selectedRange = getSelectionRange(TemplateManagingUtil
- .getCurrentSelection(pageContext));
-
- if (node == null || selectedRange == null)
- return false;
-
- int focusOffset = selectedRange.x;
-
- if (focusOffset != 0) {
- TemplateManagingUtil.setSourceSelection(pageContext, node,
- focusOffset - 1, 0);
- } else {
- TemplateManagingUtil
- .setSourceSelection(pageContext, node, 0, 0);
- }
- }
- return true;
- }
-
- /**
- * Default handling of a pressing the "enter" event - always return false.
- *
- * Override to handling of a pressing the "enter" event
- *
- * @param pageContext -
- * context of vpe
- * @param keyEvent -
- * event
- * @return whether handled event
- */
- protected boolean handleEnter(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
- return true;
- }
-
- /**
- *
- * @param pageContext
- * @param visualNode
- * @param elementData
- * @return
- */
- public boolean isNodeEditable(nsIDOMNode visualNode,
- VpeElementData elementData) {
-
- VpeAttributeData attributeData = getAttributeData(visualNode,
- elementData);
-
- if (attributeData != null)
- return attributeData.isEditable();
-
- return false;
- }
-
- /**
- *
- */
- public boolean isNodeEditable(Node node, VpeElementData elementData) {
-
- VpeAttributeData attributeData = getAttributeData(node, elementData);
-
- if (attributeData != null) {
- return attributeData.isEditable();
- }
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setSelection(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.mozilla.interfaces.nsISelection)
- */
- final public void setSelection(VpePageContext pageContext,
- nsISelection selection) {
-
- nsIDOMNode selectedVisualNode = TemplateManagingUtil
- .getSelectedNode(selection);
-
- if (selectedVisualNode == null)
- return;
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- selectedVisualNode);
-
- // get target visual node
- nsIDOMNode targetVisualNode = getTargetVisualNodeByVisualNode(
- pageContext, selectedVisualNode, elementMapping);
-
- // get target souce node
- Node targetSourceNode = getTargetSourceNodeByVisualNode(pageContext,
- selectedVisualNode, elementMapping);
-
- int focusOffset;
- int length;
-
- if (isNodeEditable(targetVisualNode, elementMapping.getElementData())) {
-
- Point range = getSelectionRange(selection);
-
- focusOffset = range.x;
- length = range.y;
-
- } else {
-
- focusOffset = 0;
- length = TemplateManagingUtil.getLengthNode(targetSourceNode);
-
- }
-
- // set source selection
- TemplateManagingUtil.setSourceSelection(pageContext, targetSourceNode,
- focusOffset, length);
-
- if ((HTML.TAG_INPUT.equalsIgnoreCase(targetVisualNode.getLocalName()))
- || (HTML.TAG_TEXTAREA.equalsIgnoreCase(targetVisualNode
- .getLocalName()))) {
-
- TemplateManagingUtil.setSelectionRangeInInputElement(
- targetVisualNode, new Point(focusOffset, length));
-
- selection.collapse(targetVisualNode.getParentNode(),
- (int) VisualDomUtil.getOffset(targetVisualNode));
-
- selection.extend(targetVisualNode.getParentNode(),
- (int) VisualDomUtil.getOffset(targetVisualNode) + 1);
- }
-
- // setSelectionRange(selection,
- // targetVisualNode, new Point(focusOffset, length));
-
- // check for text node
- if (targetVisualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE)
- targetVisualNode = targetVisualNode.getParentNode();
-
- // paint visual selection
- pageContext.getVisualBuilder().setSelectionRectangle(
- (nsIDOMElement) targetVisualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setSelectionBySource(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.jboss.tools.vpe.editor.selection.VpeSelectionController, int,
- * int)
- */
- final public void setSelectionBySource(VpePageContext pageContext,
- VpeSelectionController selectionController, int focus, int anchor) {
-
- // get element mapping
- VpeElementMapping elementMapping = TemplateManagingUtil
- .getElementMappingBySourceSelection(pageContext, focus, anchor);
-
- // get focused attribute
- Node focusNode = getTargetSourceNodeBySourcePosition(pageContext,
- focus, anchor);
-
- int visualFocus = 0;
- int visualAnchor = 0;
-
- if (isNodeEditable(focusNode, elementMapping.getElementData())) {
-
- String text = focusNode.getNodeValue();
- int start = TemplateManagingUtil.getStartOffsetNode(focusNode);
- focus = focus - start;
- anchor = anchor - start;
- visualFocus = TextUtil.visualInnerPosition(text, focus);
- visualAnchor = TextUtil.visualInnerPosition(text, anchor);
-
- }
-
- nsIDOMNode visualNode = getTargetVisualNodeBySourceNode(focusNode,
- elementMapping);
-
- if (visualNode == null)
- return;
-
- setSelectionRange(selectionController
- .getSelection(nsISelectionController.SELECTION_NORMAL),
- visualNode, new Point(visualFocus, visualAnchor - visualFocus));
-
- // check for text node
- if (visualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE) {
- visualNode = visualNode.getParentNode();
- }
-
- pageContext.getVisualBuilder().setSelectionRectangle(
- (nsIDOMElement) visualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setSelectionByMouse(org.mozilla.interfaces.nsIDOMMouseEvent)
- */
- final public void setSelectionByMouse(VpePageContext pageContext,
- VpeSelectionController selectionController,
- nsIDOMMouseEvent mouseEvent) {
-
- // get visual node by event
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
-
- // get element mapping
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
- if (elementMapping == null)
- return;
-
- Node targetSourceNode = getTargetSourceNodeByVisualNode(pageContext,
- visualNode, elementMapping);
-
- nsIDOMNode targetVisualNode = getTargetVisualNodeByVisualNode(
- pageContext, visualNode, elementMapping);
-
- // get nsIDOMNSUIEvent event
- nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent) mouseEvent
- .queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
-
- int selectionOffset;
- int selectionLength;
-
- if (isNodeEditable(targetVisualNode, elementMapping.getElementData())) {
- selectionOffset = nsuiEvent.getRangeOffset();
- selectionLength = 0;
- } else {
-
- selectionOffset = 0;
- selectionLength = TemplateManagingUtil
- .getLengthNode(targetSourceNode);
-
- }
-
- TemplateManagingUtil.setSourceSelection(pageContext, targetSourceNode,
- selectionOffset, selectionLength);
-
- // setSelectionRange(selectionController
- // .getSelection(nsISelectionController.SELECTION_NORMAL),
- // targetVisualNode, new Point(selectionOffset, selectionLength));
-
- if ((HTML.TAG_INPUT.equalsIgnoreCase(targetVisualNode.getLocalName()))
- || (HTML.TAG_TEXTAREA.equalsIgnoreCase(targetVisualNode
- .getLocalName()))) {
-
- TemplateManagingUtil.setSelectionRangeInInputElement(
- targetVisualNode, new Point(selectionOffset,
- selectionLength));
-
-
(selectionController.getSelection(nsISelectionController.SELECTION_NORMAL)).collapse(targetVisualNode.getParentNode(),(int)
- VisualDomUtil.getOffset(targetVisualNode));
-
- (selectionController
- .getSelection(nsISelectionController.SELECTION_NORMAL))
- .extend(targetVisualNode.getParentNode(),
- (int) VisualDomUtil.getOffset(targetVisualNode) + 1);
- }
-
- // check for text node
- if (targetVisualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE) {
- targetVisualNode = targetVisualNode.getParentNode();
- }
-
- // paint selection rectangle
- pageContext.getVisualBuilder().setSelectionRectangle(
- (nsIDOMElement) targetVisualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
-
- }
-
- /**
- *
- */
- public boolean openBundle(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementMapping elementMapping) {
-
- VpeAttributeData attributeData = getAttributeData(
- getTargetVisualNodeByVisualNode(pageContext, visualNode,
- elementMapping), elementMapping.getElementData());
-
- // so as nsIDOMMouseEvent doesn't give simple selected nsIDOMText as
- // target, but nsiSelection can give simple "text"
- // TODO may be, there is a better way to get selected simple nsIDOMText
- if (attributeData == null) {
-
- // get visual node which is focused
- nsIDOMNode tempNode = getCurrentSelectedVisualNode(pageContext);
- attributeData = getAttributeData(getTargetVisualNodeByVisualNode(
- pageContext, tempNode, elementMapping), elementMapping
- .getElementData());
-
- }
-
- if ((attributeData == null) || (attributeData.getSourceAttr() == null))
- return false;
-
- return pageContext.getBundle().openBundle(
- attributeData.getSourceAttr().getNodeValue(),
- TemplateManagingUtil.getPageLocale(pageContext, attributeData
- .getSourceAttr()));
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.ITemplateNodesManager#getTargetSourceNodeBySourcePosition(org.jboss.tools.vpe.editor.context.VpePageContext,
- * int, int)
- */
- public Node getTargetSourceNodeBySourcePosition(VpePageContext pageContext,
- int focusPosition, int anchorPosition) {
-
- // get element mapping by position
- VpeElementMapping elementMapping = TemplateManagingUtil
- .getElementMappingBySourceSelection(pageContext, focusPosition,
- anchorPosition);
-
- // find focus attribute by position
- Node focusAttribute = findElementAttributeByPosition(elementMapping
- .getElementData(), focusPosition);
-
- // fond anchor attribute by position
- Node anchorAttribute = findElementAttributeByPosition(elementMapping
- .getElementData(), anchorPosition);
-
- // if anchor and focus attributes are equal return focused attribute
- if (focusAttribute == anchorAttribute)
- return focusAttribute;
-
- // else return all element
- return elementMapping.getSourceNode();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.ITemplateNodesManager#getTargetVisualNodeBySourceNode(org.w3c.dom.Node,
- * org.jboss.tools.vpe.editor.mapping.VpeElementMapping)
- */
- public nsIDOMNode getTargetVisualNodeBySourceNode(Node sourceNode,
- VpeElementMapping elementMapping) {
-
- // if element is not null
- if (elementMapping != null) {
-
- // get attributeData
- VpeAttributeData attributeData = getAttributeData(sourceNode,
- elementMapping.getElementData());
-
- // attributeData is found
- if (attributeData != null)
- return attributeData.getVisualAttr();
- else
- return elementMapping.getVisualNode();
-
- }
-
- return null;
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.ITemplateNodesManager#getTargetVisualNodeByVisualNode(org.mozilla.interfaces.nsIDOMNode,
- * org.jboss.tools.vpe.editor.mapping.VpeElementMapping)
- */
- public nsIDOMNode getTargetVisualNodeByVisualNode(
- VpePageContext pageContext, nsIDOMNode visualNode,
- VpeElementMapping elementMapping) {
-
- // if element is not null
- if (elementMapping != null) {
-
- // get attributeData
- VpeAttributeData attributeData = getAttributeData(visualNode,
- elementMapping.getElementData());
-
- // attributeData is found
- if (attributeData != null)
- return attributeData.getVisualAttr();
- else
- return elementMapping.getVisualNode();
-
- }
-
- return null;
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.ITemplateNodesManager#getTargetSourceNodeByVisualNode(org.mozilla.interfaces.nsIDOMNode,
- * org.jboss.tools.vpe.editor.mapping.VpeElementMapping)
- */
- public Node getTargetSourceNodeByVisualNode(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementMapping elementMapping) {
-
- // if element is not null
- if (elementMapping != null) {
-
- // get attributeData
- VpeAttributeData attributeData = getAttributeData(visualNode,
- elementMapping.getElementData());
-
- // attributeData is found
- if ((attributeData != null)
- && (attributeData.getSourceAttr() != null))
- return attributeData.getSourceAttr();
- else
- return elementMapping.getSourceNode();
-
- }
-
- return null;
-
- }
-
- /**
- *
- * @param elementData
- * @param offset
- * @return
- */
- private Node findElementAttributeByPosition(VpeElementData elementData,
- int position) {
-
- // if data are correct
- if ((elementData != null) && (elementData.getAttributesData() != null)) {
-
- List<VpeAttributeData> attributesMapping = elementData
- .getAttributesData();
-
- // for each defined attribute
- for (VpeAttributeData attributeData : attributesMapping) {
-
- // if position is in attribute's bound
- if ((position >= (TemplateManagingUtil
- .getStartOffsetNode(attributeData.getSourceAttr())))
- && (position <= (TemplateManagingUtil
- .getEndOffsetNode(attributeData.getSourceAttr()))))
- return attributeData.getSourceAttr();
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param pageContext
- * @param visualNode
- * @param elementData
- * @return
- */
- protected VpeAttributeData getAttributeData(nsIDOMNode visualNode,
- VpeElementData elementData) {
-
- // if input data is correct
- if ((visualNode != null) && (elementData != null)
- && (elementData.getAttributesData() != null)) {
-
- List<VpeAttributeData> attributesMapping = elementData
- .getAttributesData();
-
- for (VpeAttributeData attributeData : attributesMapping) {
-
- // if visual nodes equals
- if (visualNode.equals(attributeData.getVisualAttr()))
- return attributeData;
- }
- }
-
- return null;
-
- }
-
- /**
- *
- * @param pageContext
- * @param node
- * @param elementData
- * @return
- */
- protected VpeAttributeData getAttributeData(Node node,
- VpeElementData elementData) {
-
- // if input data is correct
- if ((node != null) && (elementData != null)
- && (elementData.getAttributesData() != null)) {
-
- List<VpeAttributeData> attributesMapping = elementData
- .getAttributesData();
-
- for (VpeAttributeData attributeData : attributesMapping) {
-
- // if source nodes equals
- if (node.equals(attributeData.getSourceAttr()))
- return attributeData;
- }
- }
- return null;
-
- }
-
- /**
- *
- * @param pageContext
- * @param node
- * @return
- */
- protected VpeElementMapping getElmentMapping(VpePageContext pageContext,
- nsIDOMNode node) {
-
- return pageContext.getDomMapping().getNearElementMapping(node);
-
- }
-
- /**
- *
- * @param pageContext
- * @return
- */
- protected nsIDOMNode getCurrentSelectedVisualNode(VpePageContext pageContext) {
-
- nsISelection selection = TemplateManagingUtil
- .getCurrentSelection(pageContext);
-
- if (selection.getFocusNode() != null)
- return TemplateManagingUtil.getSelectedNode(selection);
- else
- return TemplateManagingUtil.getLastSelectedVisualNode(pageContext);
-
- }
-
- /**
- *
- * @param pageContext
- * @return
- */
- protected Point getSelectionRange(nsISelection selection) {
-
- nsIDOMNode focusedNode = TemplateManagingUtil
- .getSelectedNode(selection);
-
- Point range = null;
-
- if (focusedNode != null) {
-
- range = new Point(0,0);
- if ((HTML.TAG_INPUT.equalsIgnoreCase(focusedNode.getLocalName()))
- || (HTML.TAG_TEXTAREA.equalsIgnoreCase(focusedNode
- .getLocalName()))) {
-
- range = TemplateManagingUtil
- .getSelectionRangeFromInputElement(focusedNode);
-
- } else {
-
- ;
- range.x = selection.getFocusOffset();
- range.y = selection.getAnchorOffset()
- - selection.getFocusOffset();
-
- }
- }
- return range;
- }
-
- /**
- *
- * @param selection
- * @param node
- * @param range
- */
- protected void setSelectionRange(nsISelection selection, nsIDOMNode node,
- Point range) {
-
- if (node.getNodeType() == nsIDOMNode.TEXT_NODE) {
- selection.collapse(node, range.x);
-
- // if(visualFocus!=visualAnchor)
- // selection.extend(visualNode, visualAnchor );
- } else {
-
- if ((HTML.TAG_INPUT.equalsIgnoreCase(node.getLocalName()))
- || (HTML.TAG_TEXTAREA.equalsIgnoreCase(node.getLocalName()))) {
- TemplateManagingUtil.setSelectionRangeInInputElement(node,
- range);
-
- }
- selection.collapse(node, 0);
- }
-
- }
-
- /**
- *
- * @param sourceElement
- * @param attributeName
- * @param value
- */
- protected Node createAttribute(Element sourceElement, String attributeName,
- String value) {
-
- if ((sourceElement != null) && (attributeName != null)) {
- sourceElement.setAttribute(attributeName, value != null ? value
- : ""); //$NON-NLS-1$
-
- return sourceElement.getAttributeNode(attributeName);
- }
- return null;
-
- }
-}
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/IKeyEventHandler.java
(from rev 8946,
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/IKeyEventHandler.java)
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/IKeyEventHandler.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/IKeyEventHandler.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.template;
+
+import org.mozilla.interfaces.nsIDOMKeyEvent;
+
+/**
+ * interface for handling of keyEvent by himself template
+ *
+ * @author Sergey Dzmitrovich
+ *
+ */
+public interface IKeyEventHandler {
+
+ /**
+ * handle keyEvent
+ *
+ * @param pageContext
+ * @param keyEvent -
+ * happens when element of current template is selected and
+ * is pressed key
+ * @return
+ */
+ boolean handleKeyPress(nsIDOMKeyEvent keyEvent);
+
+}
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java
(from rev 8946,
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
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.template;
+
+import org.mozilla.interfaces.nsIDOMMouseEvent;
+import org.mozilla.interfaces.nsISelection;
+
+/**
+ *
+ * interface for template selection
+ *
+ * @author Sergey Dzmitrovich
+ */
+public interface ISelectionManager {
+
+ /**
+ * set selection
+ *
+ * @param selection
+ */
+ public void setSelection(nsISelection selection);
+
+ /**
+ * set selection by mouse
+ *
+ * @param mouseEvent
+ */
+ public void setSelection(nsIDOMMouseEvent mouseEvent);
+
+ /**
+ * to bring in correspondence visual selection and source selection
+ */
+ public void refreshVisualSelection();
+
+}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateKeyEventHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateKeyEventHandler.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateKeyEventHandler.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.editor.template;
-
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.mozilla.interfaces.nsIDOMKeyEvent;
-
-/**
- * interface for handling of keyEvent by himself template
- *
- * @author Sergey Dzmitrovich
- *
- */
-public interface ITemplateKeyEventHandler {
-
- /**
- * handle keyEvent
- *
- * @param pageContext
- * @param keyEvent -
- * happens when element of current template is selected and
- * is pressed key
- * @return
- */
- boolean handleKeyPress(VpePageContext pageContext, nsIDOMKeyEvent keyEvent);
-
-}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.editor.template;
-
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeElementData;
-import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.w3c.dom.Node;
-
-/**
- * Interface for editing of attributes of a template
- *
- * @author Sergey Dzmitrovich
- *
- */
-public interface ITemplateNodesManager {
-
- /**
- * @param pageContext -
- * context of vpe
- * @param visualNode -
- * selected visual node
- *
- * @return true if selected attribute is editable
- */
- public boolean isNodeEditable(nsIDOMNode visualNode,
- VpeElementData elementData);
-
- /**
- *
- * @param pageContext
- * @param node
- * @param elementData
- * @return
- */
- public boolean isNodeEditable(Node node, VpeElementData elementData);
-
- public nsIDOMNode getTargetVisualNodeBySourceNode(Node sourceNode,
- VpeElementMapping elementMapping);
-
- public nsIDOMNode getTargetVisualNodeByVisualNode(
- VpePageContext pageContext, nsIDOMNode visualNode,
- VpeElementMapping elementMapping);
-
- public Node getTargetSourceNodeByVisualNode(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementMapping elementMapping);
-
- public Node getTargetSourceNodeBySourcePosition(VpePageContext pageContext,
- int focusOffset, int anchorOffset);
-
- /**
- * open bundle
- *
- * @param pageContext
- * @param visualNod
- * @return
- */
- boolean openBundle(VpePageContext pageContext, nsIDOMNode visualNode,
- VpeElementMapping elementMapping);
-}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.editor.template;
-
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
-import org.mozilla.interfaces.nsIDOMMouseEvent;
-import org.mozilla.interfaces.nsISelection;
-
-/**
- *
- * interface for template selection
- *
- * @author Sergey Dzmitrovich
- */
-public interface ITemplateSelectionManager {
-
- /**
- * selection
- *
- * @param pageContext
- * @param selection
- */
- public void setSelection(VpePageContext pageContext, nsISelection selection);
-
- /**
- * select visual element by source selection
- *
- * @param pageContext
- * @return true if visual element was selected
- */
- public void setSelectionBySource(VpePageContext pageContext,
- VpeSelectionController selectionController, int focus, int anchor);
-
- /**
- * set selection by mouse
- *
- * @param visualSelectionController
- *
- * @param mouseEvent
- */
- public void setSelectionByMouse(VpePageContext pageContext,
- VpeSelectionController selectionController,
- nsIDOMMouseEvent mouseEvent);
-
-}
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/KeyEventManager.java
(from rev 8946,
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/KeyEventManager.java)
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/KeyEventManager.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/KeyEventManager.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,482 @@
+package org.jboss.tools.vpe.editor.template;
+
+import org.eclipse.swt.custom.ST;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.AttributeData;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.util.SelectionUtil;
+import org.jboss.tools.vpe.editor.util.TextUtil;
+import org.mozilla.interfaces.nsIDOMKeyEvent;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @author S.Dzmitrovich
+ *
+ */
+public class KeyEventManager implements IKeyEventHandler {
+
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ /**
+ * source editor
+ */
+ private StructuredTextEditor sourceEditor;
+
+ /**
+ * mapping
+ */
+ private VpeDomMapping domMapping;
+
+ /**
+ * page context
+ */
+ private VpePageContext pageContext;
+
+ public KeyEventManager(StructuredTextEditor sourceEditor,
+ VpeDomMapping domMapping, VpePageContext pageContext) {
+ this.sourceEditor = sourceEditor;
+ this.domMapping = domMapping;
+ this.pageContext = pageContext;
+ }
+
+ final public boolean handleKeyPress(nsIDOMKeyEvent keyEvent) {
+
+ long keyCode = keyEvent.getKeyCode();
+
+ if (keyCode == nsIDOMKeyEvent.DOM_VK_ENTER) {
+ return handleEnter(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_LEFT)
+ && (!keyEvent.getShiftKey())) {
+ return handleLeft(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_UP)
+ && (!keyEvent.getShiftKey())) {
+ return handleUp(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_RIGHT)
+ && (!keyEvent.getShiftKey())) {
+ return handleRight(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_DOWN)
+ && (!keyEvent.getShiftKey())) {
+ return handleDown(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_HOME)
+ && (!keyEvent.getShiftKey())) {
+ return handleHome(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_END)
+ && (!keyEvent.getShiftKey())) {
+ return handleEnd(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_BACK_SPACE)
+ && (!keyEvent.getShiftKey())) {
+ return handleLeftDelete(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_DELETE)
+ && (!keyEvent.getShiftKey())) {
+ return handleRightDelete(keyEvent);
+
+ } else if ((keyCode == nsIDOMKeyEvent.DOM_VK_PAGE_UP)
+ && (!keyEvent.getShiftKey())) {
+ return handlePageUp(keyEvent);
+
+ } else if (keyEvent.getCharCode() != 0) {
+ return handleCharacter(keyEvent);
+
+ } else if ((keyEvent.getKeyCode() == nsIDOMKeyEvent.DOM_VK_INSERT)
+ && keyEvent.getShiftKey()) {
+ return handleInsert(keyEvent);
+ }
+
+ return false;
+ }
+
+ /**
+ * Default handling of a pressing a character event
+ *
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleCharacter(nsIDOMKeyEvent keyEvent) {
+
+ VpeNodeMapping selectedNodeMapping = SelectionUtil
+ .getNodeMappingBySourceSelection(getSourceEditor(),
+ getDomMapping());
+
+ if (selectedNodeMapping == null)
+ return false;
+
+ boolean editable = false;
+
+ String enteredChar = TextUtil.getChar(keyEvent);
+
+ // if selected node is element
+ if (selectedNodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+
+ VpeElementMapping elementMapping = (VpeElementMapping) selectedNodeMapping;
+
+ VpeElementData elementData = elementMapping.getElementData();
+
+ VpeTemplate template = elementMapping.getTemplate();
+
+ nsIDOMNode visualNode = SelectionUtil
+ .getLastSelectedNode(getPageContext());
+
+ NodeData nodeData = template.getNodeData(visualNode, elementData,
+ domMapping);
+
+ if (nodeData != null) {
+
+ editable = nodeData.isEditable();
+
+ if (editable && nodeData.getType() == NodeData.ATTRIBUTE
+ && nodeData.getSourceNode() == null) {
+
+ Node newNode = createAttribute(
+ (Element) selectedNodeMapping.getSourceNode(),
+ ((AttributeData) nodeData).getAttributeName(),
+ enteredChar);
+ nodeData.setSourceNode(newNode);
+
+ SelectionUtil.setSourceSelection(pageContext, newNode,
+ enteredChar.length());
+ return true;
+
+ }
+
+ }
+ // if template can't give necessary information
+ else {
+
+ editable = false;
+
+ }
+ }
+ // if node is simple text
+ else {
+ editable = true;
+ }
+
+ if (editable) {
+
+ Point range = getSourceEditor().getTextViewer().getSelectedRange();
+
+ getSourceEditor().getTextViewer().getTextWidget().replaceTextRange(
+ range.x, range.y, enteredChar);
+
+ getSourceEditor().getTextViewer().getTextWidget().setSelection(
+ range.x + enteredChar.length());
+
+ }
+
+ return true;
+ }
+
+ /**
+ * Default implementation of a handling of a pressing the "delete" event
+ *
+ * Override this method for a handling of a pressing the "delete" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleRightDelete(nsIDOMKeyEvent keyEvent) {
+
+ VpeNodeMapping selectedNodeMapping = SelectionUtil
+ .getNodeMappingBySourceSelection(getSourceEditor(),
+ getDomMapping());
+
+ if (selectedNodeMapping == null)
+ return false;
+
+ boolean editable = false;
+
+ // if selected node is element
+ if (selectedNodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+
+ VpeElementMapping elementMapping = (VpeElementMapping) selectedNodeMapping;
+
+ VpeElementData elementData = elementMapping.getElementData();
+
+ VpeTemplate template = elementMapping.getTemplate();
+
+ nsIDOMNode visualNode = SelectionUtil
+ .getLastSelectedNode(getPageContext());
+
+ NodeData nodeData = template.getNodeData(visualNode, elementData,
+ domMapping);
+
+ if (nodeData != null) {
+ editable = nodeData.isEditable();
+
+ if (editable && nodeData.getType() == NodeData.ATTRIBUTE
+ && nodeData.getSourceNode() == null) {
+
+ Node newNode = createAttribute(
+ (Element) selectedNodeMapping.getSourceNode(),
+ ((AttributeData) nodeData).getAttributeName(),
+ EMPTY_STRING);
+
+ nodeData.setSourceNode(newNode);
+
+ SelectionUtil.setSourceSelection(pageContext, newNode, 0);
+
+ return true;
+
+ }
+
+ }
+ // if template can't give necessary information
+ else {
+
+ editable = false;
+
+ }
+ }
+ // if node is simple text
+ else {
+ editable = true;
+ }
+
+ if (editable) {
+
+ sourceEditor.getTextViewer().getTextWidget().invokeAction(
+ ST.DELETE_NEXT);
+
+ }
+
+ return true;
+
+ }
+
+ /**
+ * Default handling of a pressing the "backspace" event
+ *
+ * Override this method to handle the "backspace" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleLeftDelete(nsIDOMKeyEvent keyEvent) {
+ VpeNodeMapping selectedNodeMapping = SelectionUtil
+ .getNodeMappingBySourceSelection(getSourceEditor(),
+ getDomMapping());
+
+ if (selectedNodeMapping == null)
+ return false;
+
+ boolean editable = false;
+
+ // if selected node is element
+ if (selectedNodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+
+ VpeElementMapping elementMapping = (VpeElementMapping) selectedNodeMapping;
+
+ VpeElementData elementData = elementMapping.getElementData();
+
+ VpeTemplate template = elementMapping.getTemplate();
+
+ nsIDOMNode visualNode = SelectionUtil
+ .getLastSelectedNode(getPageContext());
+
+ NodeData nodeData = template.getNodeData(visualNode, elementData,
+ domMapping);
+
+ if (nodeData != null) {
+ editable = nodeData.isEditable();
+
+ if (editable && nodeData.getType() == NodeData.ATTRIBUTE
+ && nodeData.getSourceNode() == null) {
+
+ Node newNode = createAttribute(
+ (Element) selectedNodeMapping.getSourceNode(),
+ ((AttributeData) nodeData).getAttributeName(),
+ EMPTY_STRING);
+
+ nodeData.setSourceNode(newNode);
+
+ SelectionUtil.setSourceSelection(pageContext, newNode, 0);
+
+ return true;
+
+ }
+
+ }
+ // if template can't give necessary information
+ else {
+
+ editable = false;
+
+ }
+ }
+ // if node is simple text
+ else {
+ editable = true;
+ }
+
+ if (editable) {
+
+ sourceEditor.getTextViewer().getTextWidget().invokeAction(
+ ST.DELETE_PREVIOUS);
+
+ }
+
+ return true;
+
+ }
+
+ /**
+ * Default handling of a pressing the "end" event - always return false.
+ *
+ * Override this method to handle of a pressing the "end" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleEnd(nsIDOMKeyEvent keyEvent) {
+ return false;
+ }
+
+ /**
+ * Default handling of a pressing the "home" event - always return false.
+ *
+ * Override this method to handle of a pressing the "home" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleHome(nsIDOMKeyEvent keyEvent) {
+ return false;
+ }
+
+ /**
+ * Default handling of a pressing the "down" event - always return false.
+ *
+ * Override this method to handle of a pressing the "down" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleDown(nsIDOMKeyEvent keyEvent) {
+ return false;
+ }
+
+ /**
+ * Default handling of a pressing the "right" event - always return false.
+ *
+ * Override this method to handle of a pressing the "right" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleRight(nsIDOMKeyEvent keyEvent) {
+ return false;
+
+ }
+
+ /**
+ * Default handling of a pressing the "up" event - always return false.
+ *
+ * Override this method to handle of a pressing the "up" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleUp(nsIDOMKeyEvent keyEvent) {
+ return false;
+ }
+
+ /**
+ * Default handling of a pressing the "left" event - always return false.
+ *
+ * Override this method to handle of a pressing the "left" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleLeft(nsIDOMKeyEvent keyEvent) {
+ return false;
+
+ }
+
+ /**
+ * Default handling of a pressing the "enter" event - always return false.
+ *
+ * Override to handling of a pressing the "enter" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handleEnter(nsIDOMKeyEvent keyEvent) {
+ return true;
+ }
+
+ /**
+ *
+ * @param keyEvent
+ * @return
+ */
+ protected boolean handleInsert(nsIDOMKeyEvent keyEvent) {
+ return false;
+ }
+
+ /**
+ * Default handling of a pressing the "page up" event - always return false.
+ *
+ * Override this method for a handling of a pressing the "page up" event
+ *
+ * @param keyEvent
+ * - event
+ * @return whether handled event
+ */
+ protected boolean handlePageUp(nsIDOMKeyEvent keyEvent) {
+ return false;
+ }
+
+ protected StructuredTextEditor getSourceEditor() {
+ return sourceEditor;
+ }
+
+ protected VpeDomMapping getDomMapping() {
+ return domMapping;
+ }
+
+ protected VpePageContext getPageContext() {
+ return pageContext;
+ }
+
+ protected Node createAttribute(Element sourceElement, String attributeName,
+ String value) {
+
+ if ((sourceElement != null) && (attributeName != null)) {
+ sourceElement.setAttribute(attributeName, value != null ? value
+ : ""); //$NON-NLS-1$
+
+ return sourceElement.getAttributeNode(attributeName);
+ }
+ return null;
+
+ }
+}
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java
(from rev 8946,
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
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,279 @@
+package org.jboss.tools.vpe.editor.template;
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
+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.selection.VpeSelectionController;
+import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
+import org.jboss.tools.vpe.editor.util.SelectionUtil;
+import org.jboss.tools.vpe.editor.util.VisualDomUtil;
+import org.mozilla.interfaces.nsIDOMMouseEvent;
+import org.mozilla.interfaces.nsIDOMNSUIEvent;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsISelection;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @author S. Dzmitrovich
+ *
+ */
+public class SelectionManager implements ISelectionManager {
+
+ /**
+ * pageContext keeps information about page
+ */
+ private VpePageContext pageContext;
+
+ /**
+ * source editor
+ */
+ private StructuredTextEditor sourceEditor;
+
+ /**
+ * selection
+ */
+ private VpeSelectionController selectionController;
+
+ public SelectionManager(VpePageContext pageContext,
+ StructuredTextEditor sourceEditor,
+ VpeSelectionController selectionController) {
+ this.pageContext = pageContext;
+ this.sourceEditor = sourceEditor;
+ this.selectionController = selectionController;
+ }
+
+ final public void setSelection(nsISelection selection) {
+
+ nsIDOMNode selectedVisualNode = SelectionUtil
+ .getSelectedNode(selection);
+
+ if (selectedVisualNode == null)
+ return;
+
+ VpeNodeMapping nodeMapping = NodesManagingUtil.getNodeMapping(
+ getDomMapping(), selectedVisualNode);
+
+ if (nodeMapping == 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.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+
+ 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 {
+
+ targetSourceNode = elementMapping.getSourceNode();
+
+ }
+
+ targetVisualNode = nodeData.getVisualNode();
+ } else {
+
+ targetVisualNode = elementMapping.getVisualNode();
+ targetSourceNode = elementMapping.getSourceNode();
+ isNodeEditable = false;
+ }
+
+ } else {
+
+ targetVisualNode = nodeMapping.getVisualNode();
+ targetSourceNode = nodeMapping.getSourceNode();
+ isNodeEditable = true;
+
+ }
+
+ int focusOffset;
+ int length;
+
+ if (isNodeEditable) {
+
+ Point range = SelectionUtil.getSelectionRange(selection);
+
+ focusOffset = range.x;
+ length = range.y;
+
+ } else {
+
+ focusOffset = 0;
+ length = NodesManagingUtil.getNodeLength(targetSourceNode);
+
+ }
+
+ // set source selection
+ SelectionUtil.setSourceSelection(getPageContext(), targetSourceNode,
+ focusOffset, length);
+
+ // paint visual selection
+ getPageContext().getVisualBuilder().setSelectionRectangle(
+ targetVisualNode);
+
+ }
+
+ final public void setSelection(nsIDOMMouseEvent mouseEvent) {
+
+ // get visual node by event
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+
+ // get element mapping
+ VpeNodeMapping nodeMapping = NodesManagingUtil.getNodeMapping(
+ getDomMapping(), visualNode);
+
+ if (nodeMapping == 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.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+
+ VpeElementMapping elementMapping = (VpeElementMapping) nodeMapping;
+
+ VpeTemplate template = elementMapping.getTemplate();
+
+ NodeData nodeData = template.getNodeData(visualNode, 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 {
+
+ targetVisualNode = nodeMapping.getVisualNode();
+ targetSourceNode = nodeMapping.getSourceNode();
+ isNodeEditable = true;
+
+ }
+
+ // get nsIDOMNSUIEvent event
+ nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent) mouseEvent
+ .queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
+
+ int selectionOffset;
+ int selectionLength;
+
+ if (isNodeEditable) {
+ selectionOffset = nsuiEvent.getRangeOffset();
+ selectionLength = 0;
+ } else {
+
+ selectionOffset = 0;
+ selectionLength = NodesManagingUtil.getNodeLength(targetSourceNode);
+
+ }
+
+ SelectionUtil.setSourceSelection(getPageContext(), targetSourceNode,
+ selectionOffset, selectionLength);
+
+ // paint selection rectangle
+ getPageContext().getVisualBuilder().setSelectionRectangle(
+ targetVisualNode);
+
+ }
+
+ final public void refreshVisualSelection() {
+
+ Point range = SelectionUtil.getSourceSelection(getSourceEditor());
+
+ int focus = range.x;
+
+ int anchor = focus + range.y;
+
+ // get element mapping
+ VpeNodeMapping nodeMapping = SelectionUtil
+ .getNodeMappingBySourceSelection(NodesManagingUtil
+ .getStructuredModel(getSourceEditor()),
+ getDomMapping(), focus, anchor);
+
+ if (nodeMapping == null)
+ return;
+
+ // visual node which will be selected
+ nsIDOMNode targetVisualNode;
+
+ // if mapping is elementMapping
+ if (nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+
+ VpeElementMapping elementMapping = (VpeElementMapping) nodeMapping;
+
+ VpeTemplate template = elementMapping.getTemplate();
+
+ targetVisualNode = template.getVisualNodeByBySourcePosition(
+ elementMapping, focus, anchor, getDomMapping());
+
+ } else {
+
+ targetVisualNode = nodeMapping.getVisualNode();
+
+ }
+
+ getPageContext().getVisualBuilder().setSelectionRectangle(
+ targetVisualNode);
+
+ }
+
+ protected VpePageContext getPageContext() {
+ return pageContext;
+ }
+
+ protected VpeDomMapping getDomMapping() {
+ return pageContext.getDomMapping();
+ }
+
+ protected StructuredTextEditor getSourceEditor() {
+ return sourceEditor;
+ }
+
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -7,11 +7,12 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.template;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
@@ -24,10 +25,16 @@
import org.jboss.tools.vpe.editor.VpeSourceInnerDragInfo;
import org.jboss.tools.vpe.editor.VpeSourceInnerDropInfo;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.selection.VpeSourceSelection;
import org.jboss.tools.vpe.editor.template.dnd.VpeDnd;
import org.jboss.tools.vpe.editor.template.resize.VpeResizer;
import org.jboss.tools.vpe.editor.template.textformating.TextFormatingData;
+import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
+import org.jboss.tools.vpe.editor.util.SelectionUtil;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
@@ -39,26 +46,27 @@
import org.w3c.dom.Text;
/**
- * Class which response for configuration template element from
- * configuration file.
- *
+ * Class which response for configuration template element from configuration
+ * file.
+ *
*/
public abstract class VpeAbstractTemplate implements VpeTemplate {
protected boolean caseSensitive;
protected boolean children;
- protected boolean modify;
-
+ protected boolean modify;
+
protected boolean hasImaginaryBorder;
-
+
/** a resizer instance */
private VpeResizer resizer;
-
+
// TODO Max Areshkau add DnD support
private VpeDnd dragger;
private TextFormatingData textFormatingData;
private VpePseudoContentCreator pseudoContentCreator;
- private static final String TAG_BREAKER = VpeTemplateManager.VPE_PREFIX +
"breaker"; //$NON-NLS-1$
+ private static final String TAG_BREAKER = VpeTemplateManager.VPE_PREFIX
+ + "breaker"; //$NON-NLS-1$
private static final String ATTR_BREAKER_TYPE = "type"; //$NON-NLS-1$
private static final String ATTR_BREAKER_TYPE_IGNORE = "ignore";
//$NON-NLS-1$
private static final String ATTR_BREAKER_TYPE_SELECTITEM = "selectItem";
//$NON-NLS-1$
@@ -66,14 +74,15 @@
private static final int BREAKER_TYPE_IGNORE = 1;
private static final int BREAKER_TYPE_SELECTITEM = 2;
- private static final String TAG_PSEUDOCONTENT = VpeTemplateManager.VPE_PREFIX +
"pseudoContent"; //$NON-NLS-1$
+ private static final String TAG_PSEUDOCONTENT = VpeTemplateManager.VPE_PREFIX
+ + "pseudoContent"; //$NON-NLS-1$
private static final String ATTR_PSEUDOCONTENT_DEFAULTTEXT = "defaultText";
//$NON-NLS-1$
private static final String ATTR_PSEUDOCONTENT_ATTRNAME = "attrName";
//$NON-NLS-1$
private int breakerType = BREAKER_TYPE_NONE;
static private HashSet<String> inlineTags = new HashSet<String>();
- static{
+ static {
inlineTags.add("b"); //$NON-NLS-1$
inlineTags.add("i"); //$NON-NLS-1$
inlineTags.add("u"); //$NON-NLS-1$
@@ -90,22 +99,39 @@
inlineTags.add("label"); //$NON-NLS-1$
}
static private HashMap<String, Integer> tagResizeConstrans = new
HashMap<String, Integer>();
- static{
- tagResizeConstrans.put("table",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_ALL)); //$NON-NLS-1$
- tagResizeConstrans.put("tr",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_ALL)); //$NON-NLS-1$
- tagResizeConstrans.put("br",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
- tagResizeConstrans.put("b",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
- tagResizeConstrans.put("i",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
- tagResizeConstrans.put("u",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
- tagResizeConstrans.put("sub",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
- tagResizeConstrans.put("sup",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
- tagResizeConstrans.put("strike",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
- tagResizeConstrans.put("font",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
- tagResizeConstrans.put("a",
Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+ static {
+ tagResizeConstrans
+ .put(
+ "table", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_ALL));
//$NON-NLS-1$
+ tagResizeConstrans.put(
+ "tr", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_ALL));
//$NON-NLS-1$
+ tagResizeConstrans
+ .put(
+ "br", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
+ tagResizeConstrans.put(
+ "b", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
+ tagResizeConstrans.put(
+ "i", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
+ tagResizeConstrans.put(
+ "u", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
+ tagResizeConstrans
+ .put(
+ "sub", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
+ tagResizeConstrans
+ .put(
+ "sup", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
+ tagResizeConstrans
+ .put(
+ "strike", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
+ tagResizeConstrans
+ .put(
+ "font", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
+ tagResizeConstrans.put(
+ "a", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
//$NON-NLS-1$
}
-
+
static private HashSet<String> breakWithParagraphTags = new
HashSet<String>();
- static{
+ static {
breakWithParagraphTags.add("b"); //$NON-NLS-1$
breakWithParagraphTags.add("a"); //$NON-NLS-1$
breakWithParagraphTags.add("abbr"); //$NON-NLS-1$
@@ -135,7 +161,7 @@
breakWithParagraphTags.add("var"); //$NON-NLS-1$
}
static private HashSet<String> breakWithoutParagraphTags = new
HashSet<String>();
- static{
+ static {
breakWithoutParagraphTags.add("p"); //$NON-NLS-1$
breakWithoutParagraphTags.add("address"); //$NON-NLS-1$
breakWithoutParagraphTags.add("blockquote"); //$NON-NLS-1$
@@ -150,11 +176,15 @@
breakWithoutParagraphTags.add("p"); //$NON-NLS-1$
breakWithoutParagraphTags.add("pre"); //$NON-NLS-1$
}
-
+
/**
* Initiates template after its creating
- * @param templateElement <code>Element</code> with a name
"vpe:template" from the template file
- * @param caseSensitive The case sensitive of an element of a source file
+ *
+ * @param templateElement
+ * <code>Element</code> with a name "vpe:template" from
the
+ * template file
+ * @param caseSensitive
+ * The case sensitive of an element of a source file
*/
public void init(Element templateElement, boolean caseSensitive) {
this.caseSensitive = caseSensitive;
@@ -173,17 +203,15 @@
init(templateElement);
}
-
+
protected void init(Element templateElement) {
initTemplateSections(templateElement, true, true, true, true, true);
}
-
+
protected void initTemplateSections(Element templateElement,
- boolean resizeHandler,
- boolean dndHandler,
- boolean textFormatingHandler,
- boolean breakHandler,
- boolean pseudoContentHandler) {
+ boolean resizeHandler, boolean dndHandler,
+ boolean textFormatingHandler, boolean breakHandler,
+ boolean pseudoContentHandler) {
NodeList children = templateElement.getChildNodes();
if (children != null) {
int len = children.getLength();
@@ -191,62 +219,71 @@
Node section = children.item(i);
if (section.getNodeType() == Node.ELEMENT_NODE) {
String sectionName = section.getNodeName();
- if (resizeHandler && VpeTemplateManager.TAG_RESIZE.equals(sectionName)) {
- initResizeHandler((Element)section);
- } else if (dndHandler && VpeTemplateManager.TAG_DND.equals(sectionName)) {
- initDndHandler((Element)section);
- } else if (textFormatingHandler &&
VpeTemplateManager.TAG_TEXT_FORMATING.equals(sectionName)) {
- initTextFormatingHandler((Element)section);
+ if (resizeHandler
+ && VpeTemplateManager.TAG_RESIZE
+ .equals(sectionName)) {
+ initResizeHandler((Element) section);
+ } else if (dndHandler
+ && VpeTemplateManager.TAG_DND.equals(sectionName)) {
+ initDndHandler((Element) section);
+ } else if (textFormatingHandler
+ && VpeTemplateManager.TAG_TEXT_FORMATING
+ .equals(sectionName)) {
+ initTextFormatingHandler((Element) section);
} else if (breakHandler && TAG_BREAKER.equals(sectionName)) {
- initBreakHandler((Element)section);
- } else if (pseudoContentHandler && TAG_PSEUDOCONTENT.equals(sectionName)) {
- initPseudoContentHandler((Element)section);
+ initBreakHandler((Element) section);
+ } else if (pseudoContentHandler
+ && TAG_PSEUDOCONTENT.equals(sectionName)) {
+ initPseudoContentHandler((Element) section);
} else {
- initTemplateSection((Element)section);
+ initTemplateSection((Element) section);
}
}
}
}
}
-
+
private void initResizeHandler(Element templateSection) {
if (resizer == null) {
resizer = new VpeResizer();
resizer.setResizeData(templateSection);
}
}
-
+
private void initDndHandler(Element templateSection) {
if (getDragger() == null) {
setDragger(new VpeDnd());
getDragger().setDndData(templateSection);
- }
+ }
}
-
+
private void initTextFormatingHandler(Element templateSection) {
if (textFormatingData == null) {
textFormatingData = new TextFormatingData(templateSection);
}
}
-
+
private void initBreakHandler(Element templateSection) {
if (breakerType == BREAKER_TYPE_NONE) {
String typeValue = templateSection.getAttribute(ATTR_BREAKER_TYPE);
if (typeValue != null) {
if (ATTR_BREAKER_TYPE_IGNORE.equalsIgnoreCase(typeValue)) {
breakerType = BREAKER_TYPE_IGNORE;
- } else if (ATTR_BREAKER_TYPE_SELECTITEM.equalsIgnoreCase(typeValue)) {
+ } else if (ATTR_BREAKER_TYPE_SELECTITEM
+ .equalsIgnoreCase(typeValue)) {
breakerType = BREAKER_TYPE_SELECTITEM;
}
}
}
}
-
+
private void initPseudoContentHandler(Element templateSection) {
if (pseudoContentCreator == null) {
if
("yes".equalsIgnoreCase(templateSection.getAttribute(ATTR_PSEUDOCONTENT_DEFAULTTEXT)))
{ //$NON-NLS-1$
- pseudoContentCreator = new VpeTextPseudoContentCreator(null,
templateSection.getAttribute(ATTR_PSEUDOCONTENT_ATTRNAME));
+ pseudoContentCreator = new VpeTextPseudoContentCreator(null,
+ templateSection
+ .getAttribute(ATTR_PSEUDOCONTENT_ATTRNAME));
} else {
NodeList children = templateSection.getChildNodes();
if (children != null) {
@@ -254,7 +291,8 @@
for (int i = 0; i < len; i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
- pseudoContentCreator = new VpeHtmlPseudoContentCreator((Element)child);
+ pseudoContentCreator = new VpeHtmlPseudoContentCreator(
+ (Element) child);
return;
}
}
@@ -263,64 +301,83 @@
if (child.getNodeType() == Node.TEXT_NODE) {
String text = child.getNodeValue().trim();
if (text.length() > 0) {
- pseudoContentCreator = new VpeTextPseudoContentCreator(text, null);
+ pseudoContentCreator = new VpeTextPseudoContentCreator(
+ text, null);
return;
}
}
}
}
- pseudoContentCreator = VpeEmptyPseudoContentCreator.getInstance();
+ pseudoContentCreator = VpeEmptyPseudoContentCreator
+ .getInstance();
}
}
}
-
+
protected void initTemplateSection(Element templateSection) {
}
/**
- * Is invoked after construction of all child nodes of the current visual node.
- * @param pageContext Contains the information on edited page.
- * @param sourceNode The current node of the source tree.
- * @param visualDocument The document of the visual tree.
- * @param data Object <code>VpeCreationData</code>, built by a method
<code>create</code>
+ * Is invoked after construction of all child nodes of the current visual
+ * node.
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceNode
+ * The current node of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @param data
+ * Object <code>VpeCreationData</code>, built by a method
+ * <code>create</code>
*/
- public void validate(VpePageContext pageContext, Node sourceNode, nsIDOMDocument
visualDocument, VpeCreationData data) {
+ public void validate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData data) {
}
IRegion fCurrentRegionToFormat = null;
+
private IRegion getRegionToFormat() {
return fCurrentRegionToFormat;
}
+
private void clearRegionToFormat() {
fCurrentRegionToFormat = null;
}
+
private void updateRegionToFormat(Node node) {
if (node instanceof IndexedRegion) {
- IndexedRegion region = (IndexedRegion)node;
+ IndexedRegion region = (IndexedRegion) node;
int start = region.getStartOffset();
int end = region.getEndOffset();
-
+
if (fCurrentRegionToFormat == null) {
fCurrentRegionToFormat = new Region(start, end - start);
} else {
int cStart = fCurrentRegionToFormat.getOffset();
- int cEnd = fCurrentRegionToFormat.getOffset() + fCurrentRegionToFormat.getLength();
-
- if (start < cStart) cStart = start;
- if (end > cEnd) cEnd = end;
-
+ int cEnd = fCurrentRegionToFormat.getOffset()
+ + fCurrentRegionToFormat.getLength();
+
+ if (start < cStart)
+ cStart = start;
+ if (end > cEnd)
+ cEnd = end;
+
fCurrentRegionToFormat = new Region(cStart, cEnd - cStart);
}
}
}
+
private void reformatCallback(VpePageContext pageContext) {
try {
- StructuredTextEditor editor = pageContext.getEditPart().getSourceEditor();
+ StructuredTextEditor editor = pageContext.getEditPart()
+ .getSourceEditor();
StructuredTextViewer viewer = editor.getTextViewer();
- if (getRegionToFormat() != null){
+ if (getRegionToFormat() != null) {
if (editor instanceof ITextFormatter) {
- ((ITextFormatter)editor).formatTextRegion(viewer.getDocument(),
getRegionToFormat());
- }
+ ((ITextFormatter) editor).formatTextRegion(viewer
+ .getDocument(), getRegionToFormat());
+ }
}
} catch (Exception e) {
VpePlugin.reportProblem(e);
@@ -328,31 +385,49 @@
clearRegionToFormat();
}
}
-
+
/**
* Processes keyboard input (without the pressed key Ctrl)
- * @param pageContext Contains the information on edited page.
- * @param sourceDocument The document of the source tree.
- * @param sourceNode The current node of the source tree.
- * @param visualNode The current node of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
- * @param charCode Code of the pressed key
- * @param selection The current selection
- * @param formatter Interface for formatting the source text
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceDocument
+ * The document of the source tree.
+ * @param sourceNode
+ * The current node of the source tree.
+ * @param visualNode
+ * The current node of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
+ * @param charCode
+ * Code of the pressed key
+ * @param selection
+ * The current selection
+ * @param formatter
+ * Interface for formatting the source text
* @return <code>true</code> if the key is processed
*/
- public boolean nonctrlKeyPressHandler(VpePageContext pageContext, Document
sourceDocument, Node sourceNode, nsIDOMNode visualNode, Object data, long charCode,
VpeSourceSelection selection, ITextFormatter formatter) {
+ public boolean nonctrlKeyPressHandler(VpePageContext pageContext,
+ Document sourceDocument, Node sourceNode, nsIDOMNode visualNode,
+ Object data, long charCode, VpeSourceSelection selection,
+ ITextFormatter formatter) {
switch (breakerType) {
case BREAKER_TYPE_IGNORE:
return true;
case BREAKER_TYPE_SELECTITEM:
- return VpeBreackerHelper.selectItem(pageContext, sourceDocument, sourceNode,
visualNode, data, charCode, selection);
+ return VpeBreackerHelper.selectItem(pageContext, sourceDocument,
+ sourceNode, visualNode, data, charCode, selection);
default:
- return nonctrlKeyPressHandlerImpl(pageContext, sourceDocument, sourceNode,
visualNode, data, charCode, selection, formatter);
+ return nonctrlKeyPressHandlerImpl(pageContext, sourceDocument,
+ sourceNode, visualNode, data, charCode, selection,
+ formatter);
}
}
-
- private boolean nonctrlKeyPressHandlerImpl(VpePageContext pageContext, Document
sourceDocument, Node sourceNode, nsIDOMNode visualNode, Object data, long charCode,
VpeSourceSelection selection, ITextFormatter formatter) {
+
+ private boolean nonctrlKeyPressHandlerImpl(VpePageContext pageContext,
+ Document sourceDocument, Node sourceNode, nsIDOMNode visualNode,
+ Object data, long charCode, VpeSourceSelection selection,
+ ITextFormatter formatter) {
clearRegionToFormat();
Node focusNode = selection.getFocusNode();
int focusNodeType = focusNode.getNodeType();
@@ -366,15 +441,17 @@
Node newLi = sourceNode.cloneNode(false);
newLi = sourceNode.getParentNode().insertBefore(newLi, where);
- if (focusNodeType == Node.TEXT_NODE ||
- (focusNodeType == Node.ELEMENT_NODE && sourceNode != focusNode)) {
+ if (focusNodeType == Node.TEXT_NODE
+ || (focusNodeType == Node.ELEMENT_NODE && sourceNode != focusNode)) {
Node parent = focusNode.getParentNode();
Node newText = focusNode.cloneNode(false);
Node node1 = newText;
if (focusNodeType == Node.TEXT_NODE) {
- String value1 = focusNode.getNodeValue().substring(0, selection.getFocusOffset());
- String value2 = node1.getNodeValue().substring(selection.getFocusOffset());
+ String value1 = focusNode.getNodeValue().substring(0,
+ selection.getFocusOffset());
+ String value2 = node1.getNodeValue().substring(
+ selection.getFocusOffset());
if (where != sourceNode) {
focusNode.setNodeValue(value1);
node1.setNodeValue(value2);
@@ -411,21 +488,28 @@
updateRegionToFormat(newLi);
reformatCallback(pageContext);
return true;
- } else if (focusNodeType == Node.ELEMENT_NODE &&
focusNode.getNodeName().equalsIgnoreCase("br")) { //$NON-NLS-1$
- Node newNode =
focusNode.getParentNode().insertBefore(focusNode.getOwnerDocument().createElement("br"),
focusNode); //$NON-NLS-1$
+ } else if (focusNodeType == Node.ELEMENT_NODE
+ && focusNode.getNodeName().equalsIgnoreCase("br")) { //$NON-NLS-1$
+ Node newNode = focusNode
+ .getParentNode()
+ .insertBefore(
+ focusNode.getOwnerDocument().createElement("br"), focusNode);
//$NON-NLS-1$
updateRegionToFormat(focusNode);
updateRegionToFormat(newNode);
reformatCallback(pageContext);
return true;
- } else if (focusNodeType == Node.ELEMENT_NODE &&
focusNode.getNodeName().equalsIgnoreCase("p")) { //$NON-NLS-1$
+ } else if (focusNodeType == Node.ELEMENT_NODE
+ && focusNode.getNodeName().equalsIgnoreCase("p")) { //$NON-NLS-1$
Node nextElement = focusNode.getNextSibling();
Node parent = focusNode.getParentNode();
if (parent != null) {
Node newP = null;
if (nextElement != null) {
- newP = focusNode.getParentNode().insertBefore(focusNode.cloneNode(false),
nextElement);
+ newP = focusNode.getParentNode().insertBefore(
+ focusNode.cloneNode(false), nextElement);
} else {
- newP = focusNode.getParentNode().appendChild(focusNode.cloneNode(false));
+ newP = focusNode.getParentNode().appendChild(
+ focusNode.cloneNode(false));
}
setCursor(pageContext, newP);
updateRegionToFormat(newP);
@@ -433,16 +517,22 @@
updateRegionToFormat(focusNode);
reformatCallback(pageContext);
return true;
- } else if (focusNodeType == Node.TEXT_NODE &&
focusNode.getParentNode().getNodeName().equalsIgnoreCase("td")) { //$NON-NLS-1$
- Text newNode = ((Text)focusNode).splitText(selection.getFocusOffset());
+ } else if (focusNodeType == Node.TEXT_NODE
+ && focusNode.getParentNode().getNodeName().equalsIgnoreCase(
+ "td")) { //$NON-NLS-1$
+ Text newNode = ((Text) focusNode).splitText(selection
+ .getFocusOffset());
setCursor(pageContext, newNode);
updateRegionToFormat(focusNode);
updateRegionToFormat(newNode);
reformatCallback(pageContext);
return true;
- } else if (sourceNode.getNodeType() == Node.ELEMENT_NODE &&
sourceNode.getNodeName().equalsIgnoreCase("tr")) { //$NON-NLS-1$
+ } else if (sourceNode.getNodeType() == Node.ELEMENT_NODE
+ && sourceNode.getNodeName().equalsIgnoreCase("tr")) {
//$NON-NLS-1$
return true;
- } else if (focusNodeType == Node.TEXT_NODE &&
!focusNode.getParentNode().getNodeName().equalsIgnoreCase("body")) {
//$NON-NLS-1$
+ } else if (focusNodeType == Node.TEXT_NODE
+ && !focusNode.getParentNode().getNodeName().equalsIgnoreCase(
+ "body")) { //$NON-NLS-1$
Node parent = focusNode.getParentNode();
if (parent != null) {
String parentName = parent.getNodeName();
@@ -452,12 +542,14 @@
if (parentParent != null) {
if (!parentParent.getNodeName().equalsIgnoreCase("p")) { //$NON-NLS-1$
if (parentParent.getNodeType() != Node.DOCUMENT_NODE) {
- p1 = parentParent.getOwnerDocument().createElement("p"); //$NON-NLS-1$
+ p1 = parentParent.getOwnerDocument()
+ .createElement("p"); //$NON-NLS-1$
parentParent.insertBefore(p1, parent);
parent = parentParent.removeChild(parent);
p1.appendChild(parent);
} else {
- p1 = ((Document)parentParent).createElement("p"); //$NON-NLS-1$
+ p1 = ((Document) parentParent)
+ .createElement("p"); //$NON-NLS-1$
parentParent.insertBefore(p1, parent);
parent = parentParent.removeChild(parent);
p1.appendChild(parent);
@@ -466,12 +558,16 @@
p1 = parentParent;
}
if (p1 != null) {
- Text newNode = ((Text)focusNode).splitText(selection.getFocusOffset());
- p2 = p1.getParentNode().insertBefore(p1.cloneNode(false), p1.getNextSibling());
- Node newParent = p2.appendChild(parent.cloneNode(false));
+ Text newNode = ((Text) focusNode)
+ .splitText(selection.getFocusOffset());
+ p2 = p1.getParentNode().insertBefore(
+ p1.cloneNode(false), p1.getNextSibling());
+ Node newParent = p2.appendChild(parent
+ .cloneNode(false));
Node currentNode = newNode;
while (currentNode != null) {
- Node currentNode1 = currentNode.getNextSibling();
+ Node currentNode1 = currentNode
+ .getNextSibling();
currentNode = parent.removeChild(currentNode);
newParent.appendChild(currentNode);
currentNode = currentNode1;
@@ -485,11 +581,14 @@
}
}
} else if (breakWithoutParagraphTags.contains(parentName)) {
- Text newNode = ((Text)focusNode).splitText(selection.getFocusOffset());
+ Text newNode = ((Text) focusNode).splitText(selection
+ .getFocusOffset());
Node parentParent = parent.getParentNode();
if (parentParent != null) {
boolean clone = newNode.getNodeValue().trim().length() > 0;
- Node newParent = parentParent.insertBefore(makeNewParent(parent, clone),
parent.getNextSibling());
+ Node newParent = parentParent.insertBefore(
+ makeNewParent(parent, clone), parent
+ .getNextSibling());
Node currentNode = newNode;
while (currentNode != null) {
Node currentNode1 = currentNode.getNextSibling();
@@ -506,7 +605,8 @@
}
}
}
- } else if (focusNodeType == Node.ELEMENT_NODE && selection.getFocusOffset() ==
2) {
+ } else if (focusNodeType == Node.ELEMENT_NODE
+ && selection.getFocusOffset() == 2) {
Node parent = focusNode;
if (parent != null) {
String parentName = parent.getNodeName();
@@ -516,12 +616,14 @@
if (parentParent != null) {
if (!parentParent.getNodeName().equalsIgnoreCase("p")) {
if (parentParent.getNodeType() != Node.DOCUMENT_NODE) {
- p1 = parentParent.getOwnerDocument().createElement("p");
+ p1 = parentParent.getOwnerDocument()
+ .createElement("p");
parentParent.insertBefore(p1, parent);
parent = parentParent.removeChild(parent);
p1.appendChild(parent);
} else {
- p1 = ((Document)parentParent).createElement("p");
+ p1 = ((Document) parentParent)
+ .createElement("p");
parentParent.insertBefore(p1, parent);
parent = parentParent.removeChild(parent);
p1.appendChild(parent);
@@ -530,10 +632,12 @@
p1 = parentParent;
}
if (p1 != null) {
- p2 = p1.getParentNode().insertBefore(p1.cloneNode(false), p1.getNextSibling());
- Node newParent = p2.appendChild(parent.cloneNode(false));
+ p2 = p1.getParentNode().insertBefore(
+ p1.cloneNode(false), p1.getNextSibling());
+ Node newParent = p2.appendChild(parent
+ .cloneNode(false));
setCursor(pageContext, newParent);
-
+
updateRegionToFormat(p1);
updateRegionToFormat(p2);
updateRegionToFormat(newParent);
@@ -544,7 +648,9 @@
} else if (breakWithoutParagraphTags.contains(parentName)) {
Node parentParent = parent.getParentNode();
if (parentParent != null) {
- Node newParent = parentParent.insertBefore(makeNewParent(parent, false),
parent.getNextSibling());
+ Node newParent = parentParent.insertBefore(
+ makeNewParent(parent, false), parent
+ .getNextSibling());
setCursor(pageContext, newParent);
updateRegionToFormat(newParent);
@@ -554,14 +660,17 @@
}
}
}
- } else if (focusNodeType == Node.TEXT_NODE &&
focusNode.getParentNode().getNodeName().equalsIgnoreCase("body")) {
//$NON-NLS-1$
+ } else if (focusNodeType == Node.TEXT_NODE
+ && focusNode.getParentNode().getNodeName().equalsIgnoreCase(
+ "body")) { //$NON-NLS-1$
Node p1 = focusNode.getOwnerDocument().createElement("p"); //$NON-NLS-1$
Node p2 = focusNode.getOwnerDocument().createElement("p"); //$NON-NLS-1$
- Text newNode = ((Text)focusNode).splitText(selection.getFocusOffset());
+ Text newNode = ((Text) focusNode).splitText(selection
+ .getFocusOffset());
focusNode.getParentNode().insertBefore(p1, focusNode);
focusNode.getParentNode().insertBefore(p2, newNode);
focusNode = focusNode.getParentNode().removeChild(focusNode);
- newNode = (Text)newNode.getParentNode().removeChild(newNode);
+ newNode = (Text) newNode.getParentNode().removeChild(newNode);
p1.appendChild(focusNode);
p2.appendChild(newNode);
setCursor(pageContext, newNode);
@@ -572,8 +681,12 @@
reformatCallback(pageContext);
return true;
- } else if (focusNodeType == Node.ELEMENT_NODE && selection.getFocusOffset() ==
0) {
- Node newNode =
focusNode.getParentNode().insertBefore(focusNode.getOwnerDocument().createElement("br"),
focusNode); //$NON-NLS-1$
+ } else if (focusNodeType == Node.ELEMENT_NODE
+ && selection.getFocusOffset() == 0) {
+ Node newNode = focusNode
+ .getParentNode()
+ .insertBefore(
+ focusNode.getOwnerDocument().createElement("br"), focusNode);
//$NON-NLS-1$
updateRegionToFormat(focusNode);
updateRegionToFormat(newNode);
reformatCallback(pageContext);
@@ -599,79 +712,117 @@
}
private void setCursor(VpePageContext pageContext, Node node) {
- int nodeOffset = ((IndexedRegion)node).getStartOffset();
+ int nodeOffset = ((IndexedRegion) node).getStartOffset();
if (node.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl)node;
+ ElementImpl element = (ElementImpl) node;
nodeOffset = element.getStartEndOffset();
}
- pageContext.getSourceBuilder().getStructuredTextViewer().setSelectedRange(nodeOffset,
0);
- pageContext.getSourceBuilder().getStructuredTextViewer().revealRange(nodeOffset, 0);
+ pageContext.getSourceBuilder().getStructuredTextViewer()
+ .setSelectedRange(nodeOffset, 0);
+ pageContext.getSourceBuilder().getStructuredTextViewer().revealRange(
+ nodeOffset, 0);
}
/**
* Is invoked before removal of the visiblis node from the tree
- * @param pageContext Contains the information on edited page.
- * @param sourceNode The current node of the source tree.
- * @param visualNode The current node of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceNode
+ * The current node of the source tree.
+ * @param visualNode
+ * The current node of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
*/
- public void beforeRemove(VpePageContext pageContext, Node sourceNode, nsIDOMNode
visualNode, Object data) {
+ public void beforeRemove(VpePageContext pageContext, Node sourceNode,
+ nsIDOMNode visualNode, Object data) {
}
/**
- * At a modification of the node of an source tree, the method update
- * for this node is invoked. Template can indicate other node for update
- * @param pageContext Contains the information on edited page.
- * @param sourceNode The current node of the source tree.
- * @param visualNode The current node of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
- * @return For this node of an source tree the method update is invoked.
- * If null, that is invoked update for current source node
+ * At a modification of the node of an source tree, the method update for
+ * this node is invoked. Template can indicate other node for update
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceNode
+ * The current node of the source tree.
+ * @param visualNode
+ * The current node of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
+ * @return For this node of an source tree the method update is invoked. If
+ * null, that is invoked update for current source node
*/
- public Node getNodeForUptate(VpePageContext pageContext, Node sourceNode, nsIDOMNode
visualNode, Object data) {
+ public Node getNodeForUptate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMNode visualNode, Object data) {
return null;
}
/**
* Is invoked at resize of an element visual tree
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param visualDocument The document of the visual tree.
- * @param visualElement The current element of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
- * @param resizerConstrains Code of resizer:<br>
- * top-left: 1<br>
- * top: 2<br>
- * top-right: 4<br>
- * left: 8<br>
- * right: 16<br>
- * bottomleft: 32<br>
- * bottom: 64<br>
- * bottom-right: 128<br>
- * @param top Element top
- * @param left Element left
- * @param width Element width
- * @param height Element height
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @param visualElement
+ * The current element of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
+ * @param resizerConstrains
+ * Code of resizer:<br>
+ * top-left: 1<br>
+ * top: 2<br>
+ * top-right: 4<br>
+ * left: 8<br>
+ * right: 16<br>
+ * bottomleft: 32<br>
+ * bottom: 64<br>
+ * bottom-right: 128<br>
+ * @param top
+ * Element top
+ * @param left
+ * Element left
+ * @param width
+ * Element width
+ * @param height
+ * Element height
*/
- public void resize(VpePageContext pageContext, Element sourceElement, nsIDOMDocument
visualDocument, nsIDOMElement visualElement, Object data, int resizerConstrains, int top,
int left, int width, int height) {
+ public void resize(VpePageContext pageContext, Element sourceElement,
+ nsIDOMDocument visualDocument, nsIDOMElement visualElement,
+ Object data, int resizerConstrains, int top, int left, int width,
+ int height) {
if (resizer != null) {
- resizer.resize(pageContext, sourceElement, visualDocument, visualElement, data,
resizerConstrains, top, left, width, height);
+ resizer.resize(pageContext, sourceElement, visualDocument,
+ visualElement, data, resizerConstrains, top, left, width,
+ height);
}
}
/**
- * Checks a capability of drag of visual element
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param visualDocument The document of the visual tree.
- * @param visualElement The current element of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
+ * Checks a capability of drag of visual element
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @param visualElement
+ * The current element of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
* @return <code>true</code> The element can be dragged
*/
- public boolean canInnerDrag(VpePageContext pageContext, Element sourceElement,
nsIDOMDocument visualDocument, nsIDOMElement visualElement, Object data) {
+ public boolean canInnerDrag(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualElement, Object data) {
// TODO Max Areshkau add DnD support
if (getDragger() != null) {
-
+
return getDragger().isDragEnabled();
} else {
return true;
@@ -680,15 +831,21 @@
/**
* Checks a capability to drop an element in the container
- * @param pageContext Contains the information on edited page.
- * @param container Element-Container
- * @param sourceDragNode Node for drop
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param container
+ * Element-Container
+ * @param sourceDragNode
+ * Node for drop
* @return <code>true</code> The node can be dropped
*/
- public boolean canInnerDrop(VpePageContext pageContext, Node container, Node
sourceDragNode) {
+ public boolean canInnerDrop(VpePageContext pageContext, Node container,
+ Node sourceDragNode) {
if (dragger != null) {
- return dragger.isDropEnabled(pageContext, container, sourceDragNode);
+ return dragger
+ .isDropEnabled(pageContext, container, sourceDragNode);
} else {
return false;
}
@@ -696,44 +853,62 @@
/**
* Is invoked at drop of an element visual tree
- * @param pageContext Contains the information on edited page.
- * @param dragInfo The information on the dragged element
- * @param dropInfo The information on the drop container
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param dragInfo
+ * The information on the dragged element
+ * @param dropInfo
+ * The information on the drop container
*/
- public void innerDrop(VpePageContext pageContext, VpeSourceInnerDragInfo dragInfo,
VpeSourceInnerDropInfo dropInfo) {
+ public void innerDrop(VpePageContext pageContext,
+ VpeSourceInnerDragInfo dragInfo, VpeSourceInnerDropInfo dropInfo) {
// TODO Max Areshkau add DnD support
-// if (dragger != null) {
-// dragger.drop(pageContext, dragInfo, dropInfo);
-// }
+ // if (dragger != null) {
+ // dragger.drop(pageContext, dragInfo, dropInfo);
+ // }
}
-
- protected String deleteFromString(String data, String begin, String end){
+
+ protected String deleteFromString(String data, String begin, String end) {
int startPosition = data.indexOf(begin);
-
- if(startPosition < 0) return data;
-
+
+ if (startPosition < 0)
+ return data;
+
int endPosition = data.indexOf(end, startPosition);
-
+
String result = data.substring(0, startPosition).trim();
- if(endPosition > 0){
- result += data.substring(endPosition+1, data.length()).trim();
+ if (endPosition > 0) {
+ result += data.substring(endPosition + 1, data.length()).trim();
}
-
+
return result;
}
/**
- * Checks, whether it is necessary to re-create an element at change of attribute
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param visualDocument The document of the visual tree.
- * @param visualNode The current node of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
- * @param name Atrribute name
- * @param value Attribute value
- * @return <code>true</code> if it is required to re-create an element at a
modification of attribute, <code>false</code> otherwise.
+ * Checks, whether it is necessary to re-create an element at change of
+ * attribute
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @param visualNode
+ * The current node of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
+ * @param name
+ * Atrribute name
+ * @param value
+ * Attribute value
+ * @return <code>true</code> if it is required to re-create an element at a
+ * modification of attribute, <code>false</code> otherwise.
*/
- public boolean isRecreateAtAttrChange(VpePageContext pageContext, Element sourceElement,
nsIDOMDocument visualDocument, nsIDOMElement visualNode, Object data, String name, String
value) {
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
return false;
}
@@ -743,15 +918,15 @@
public boolean isChildren() {
return children;
}
-
+
public boolean isModify() {
return modify;
}
-
+
public void setModify(boolean modify) {
this.modify = modify;
}
-
+
/**
* @return <code>true</code> if the element is case sensitive
*/
@@ -761,28 +936,38 @@
/**
* Returns the data for formatting an element of source tree
+ *
* @return <code>TextFormatingData</code>
*/
public TextFormatingData getTextFormatingData() {
return textFormatingData;
}
-
+
/**
* Returns <code>VpeTagDescription</code>
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param visualDocument The document of the visual tree.
- * @param visualElement The current element of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @param visualElement
+ * The current element of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
* @return <code>VpeTagDescription</code>
*/
- public VpeTagDescription getTagDescription(VpePageContext pageContext, Element
sourceElement, nsIDOMDocument visualDocument, nsIDOMElement visualElement, Object data){
+ public VpeTagDescription getTagDescription(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualElement, Object data) {
VpeTagDescription tagDescription = new VpeTagDescription();
if (inlineTags.contains(visualElement.getNodeName().toLowerCase())) {
- tagDescription.setDisplayType(VpeTagDescription.DISPLAY_TYPE_INLINE);
+ tagDescription
+ .setDisplayType(VpeTagDescription.DISPLAY_TYPE_INLINE);
}
-
+
if (resizer != null) {
resizer.modifyTagDescription(tagDescription);
}
@@ -790,34 +975,54 @@
}
/**
- * Sets value of attribute of the current visual element.
- * Is invoked at change of attribute of an source element.
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param visualDocument The document of the visual tree.
- * @param visualNode The current node of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
- * @param name Attribute name.
- * @param value Attribute value.
+ * Sets value of attribute of the current visual element. Is invoked at
+ * change of attribute of an source element.
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @param visualNode
+ * The current node of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
+ * @param name
+ * Attribute name.
+ * @param value
+ * Attribute value.
*/
- public void setAttribute(VpePageContext pageContext, Element sourceElement,
nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data, String name, String
value) {
+ public void setAttribute(VpePageContext pageContext, Element sourceElement,
+ nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data,
+ String name, String value) {
}
/**
* Informs on remove of attribute of the current source element.
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param visualDocument The document of the visual tree.
- * @param visualNode The current node of the visual tree.
- * @param data The arbitrary data, built by a method <code>create</code>
- * @param name Attribute name.
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @param visualNode
+ * The current node of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
+ * @param name
+ * Attribute name.
*/
- public void removeAttribute(VpePageContext pageContext, Element sourceElement,
nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data, String name) {
+ public void removeAttribute(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMNode visualNode, Object data, String name) {
}
/**
- * Returns a list of attributes of an element of the source tree,
- * the values which one are mapped in the visiblis editor
+ * Returns a list of attributes of an element of the source tree, the values
+ * which one are mapped in the visiblis editor
+ *
* @return attrubute name array
*/
public String[] getOutputAtributeNames() {
@@ -825,15 +1030,20 @@
}
/**
- * If the value of attribute of an element of an source tree
- * is mapped by the way of text node of a visual treer,
- * this method returns the text node, otherwise - null
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param data The arbitrary data, built by a method <code>create</code>
+ * If the value of attribute of an element of an source tree is mapped by
+ * the way of text node of a visual treer, this method returns the text
+ * node, otherwise - null
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
* @return Text node or null
*/
- public nsIDOMText getOutputTextNode(VpePageContext pageContext, Element sourceElement,
Object data) {
+ public nsIDOMText getOutputTextNode(VpePageContext pageContext,
+ Element sourceElement, Object data) {
return null;
}
@@ -862,73 +1072,104 @@
/**
* @deprecated
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
* @param offset
* @param length
* @param data
*/
- public void setSourceAttributeSelection(VpePageContext pageContext, Element
sourceElement, int offset, int length, Object data) {
+ public void setSourceAttributeSelection(VpePageContext pageContext,
+ Element sourceElement, int offset, int length, Object data) {
}
/**
* @deprecated
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param data The arbitrary data, built by a method <code>create</code>
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
*/
- public void setSourceAttributeValue(VpePageContext pageContext, Element sourceElement,
Object data) {
+ public void setSourceAttributeValue(VpePageContext pageContext,
+ Element sourceElement, Object data) {
}
/**
* Is invoked at a change of bundle values
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param data The arbitrary data, built by a method <code>create</code>
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
*/
- public void refreshBundleValues(VpePageContext pageContext, Element sourceElement,
Object data) {
+ public void refreshBundleValues(VpePageContext pageContext,
+ Element sourceElement, Object data) {
}
/**
- * Opens proprties editor for bundle value
- * Is invoked at double mouse click on visual element
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param data The arbitrary data, built by a method <code>create</code>
+ * Opens proprties editor for bundle value Is invoked at double mouse click
+ * on visual element
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
*/
- public void openBundleEditors(VpePageContext pageContext, Element sourceElement, Object
data) {
+ public void openBundleEditors(VpePageContext pageContext,
+ Element sourceElement, Object data) {
}
/**
* Opens editor of source file for include-element
- * @param pageContext Contains the information on edited page.
- * @param sourceElement The current element of the source tree.
- * @param data The arbitrary data, built by a method <code>create</code>
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
*/
- public void openIncludeEditor(VpePageContext pageContext, Element sourceElement, Object
data) {
+ public void openIncludeEditor(VpePageContext pageContext,
+ Element sourceElement, Object data) {
}
/**
- * The unfilled element of an source tree can be mapped
- * in the visiblis editor with the default contents
- * This method fills default contents
- * @param pageContext Contains the information on edited page.
- * @param sourceContainer The current element of the source tree.
- * @param visualContainer The current element of the visual tree.
- * @param visualDocument The document of the visual tree.
+ * The unfilled element of an source tree can be mapped in the visiblis
+ * editor with the default contents This method fills default contents
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceContainer
+ * The current element of the source tree.
+ * @param visualContainer
+ * The current element of the visual tree.
+ * @param visualDocument
+ * The document of the visual tree.
*/
- public void setPseudoContent(VpePageContext pageContext, Node sourceContainer,
nsIDOMNode visualContainer, nsIDOMDocument visualDocument) {
+ public void setPseudoContent(VpePageContext pageContext,
+ Node sourceContainer, nsIDOMNode visualContainer,
+ nsIDOMDocument visualDocument) {
if (pseudoContentCreator != null) {
- pseudoContentCreator.setPseudoContent(pageContext, sourceContainer, visualContainer,
visualDocument);
+ pseudoContentCreator.setPseudoContent(pageContext, sourceContainer,
+ visualContainer, visualDocument);
} else {
- VpeDefaultPseudoContentCreator.getInstance().setPseudoContent(pageContext,
sourceContainer, visualContainer, visualDocument);
+ VpeDefaultPseudoContentCreator.getInstance().setPseudoContent(
+ pageContext, sourceContainer, visualContainer,
+ visualDocument);
}
}
public boolean containsText() {
return true;
}
-
+
public boolean hasImaginaryBorder() {
return hasImaginaryBorder;
}
@@ -937,14 +1178,126 @@
* @return the dragger
*/
public VpeDnd getDragger() {
-
+
return dragger;
}
/**
- * @param dragger the dragger to set
+ * @param dragger
+ * the dragger to set
*/
public void setDragger(VpeDnd dragger) {
this.dragger = dragger;
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.vpe.editor.template.VpeTemplate#getNodeData(org.mozilla
+ * .interfaces.nsIDOMNode,
+ * org.jboss.tools.vpe.editor.mapping.VpeElementData,
+ * org.jboss.tools.vpe.editor.mapping.VpeDomMapping)
+ */
+ public NodeData getNodeData(nsIDOMNode node, VpeElementData elementData,
+ VpeDomMapping domMapping) {
+
+ // if input data is correct
+ if ((node != null) && (elementData != null)
+ && (elementData.getNodesData() != null)) {
+
+ List<NodeData> nodesData = elementData.getNodesData();
+
+ for (NodeData nodeData : nodesData) {
+
+ // if source nodes equals
+ if (node.equals(nodeData.getVisualNode()))
+ return nodeData;
+ }
+ }
+ return null;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.jboss.tools.vpe.editor.template.ITemplateNodesManager#
+ * getTargetVisualNodeByBySourcePosition
+ * (org.jboss.tools.vpe.editor.mapping.VpeElementMapping, int, int,
+ * org.jboss.tools.vpe.editor.mapping.VpeDomMapping)
+ */
+ public nsIDOMNode getVisualNodeByBySourcePosition(
+ VpeElementMapping elementMapping, int focusPosition,
+ int anchorPosition, VpeDomMapping domMapping) {
+
+ // find focus attribute by position
+ nsIDOMNode focusNode = findNodeByPosition(elementMapping
+ .getElementData(), focusPosition);
+
+ // fond anchor attribute by position
+ nsIDOMNode anchorNode = findNodeByPosition(elementMapping
+ .getElementData(), anchorPosition);
+
+ // if anchor and focus attributes are equal return focused attribute
+ if ((focusNode != null) && (focusNode == anchorNode))
+ return focusNode;
+
+ // else return all element
+ return elementMapping.getVisualNode();
+
+ }
+
+ private nsIDOMNode findNodeByPosition(VpeElementData elementData,
+ int position) {
+
+ // if data are correct
+ if ((elementData != null) && (elementData.getNodesData() != null)) {
+
+ List<NodeData> attributesMapping = elementData.getNodesData();
+
+ // for each defined attribute
+ for (NodeData attributeData : attributesMapping) {
+
+ // if position is in attribute's bound
+ if ((position >= (NodesManagingUtil
+ .getStartOffsetNode(attributeData.getSourceNode())))
+ && (position <= (NodesManagingUtil
+ .getEndOffsetNode(attributeData.getSourceNode()))))
+ return attributeData.getVisualNode();
+ }
+ }
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.vpe.editor.template.VpeTemplate#openBundle(org.jboss.
+ * tools.vpe.editor.context.VpePageContext,
+ * org.mozilla.interfaces.nsIDOMNode,
+ * org.jboss.tools.vpe.editor.mapping.VpeElementMapping)
+ */
+ public boolean openBundle(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementMapping elementMapping) {
+
+ nsIDOMNode lastSelectedNode = SelectionUtil
+ .getLastSelectedNode(pageContext);
+
+ if (elementMapping == null)
+ return false;
+
+ NodeData nodeData = getNodeData(lastSelectedNode, elementMapping
+ .getElementData(), pageContext.getDomMapping());
+
+ if (nodeData != null && nodeData.getSourceNode() != null)
+ return pageContext.getBundle().openBundle(
+ nodeData.getSourceNode().getNodeValue(),
+ NodesManagingUtil.getPageLocale(pageContext, nodeData
+ .getSourceNode()));
+
+ return false;
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -14,6 +14,10 @@
import org.jboss.tools.vpe.editor.VpeSourceInnerDragInfo;
import org.jboss.tools.vpe.editor.VpeSourceInnerDropInfo;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.NodeData;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.selection.VpeSourceSelection;
import org.jboss.tools.vpe.editor.template.textformating.TextFormatingData;
import org.mozilla.interfaces.nsIDOMDocument;
@@ -322,7 +326,7 @@
/**
* Returns a list of attributes of an element of the source tree, the values
* which one are mapped in the visiblis editor
- *
+ * @deprecated
* @return attrubute name array
*/
String[] getOutputAtributeNames();
@@ -341,6 +345,7 @@
Object data);
/**
+ * @deprecated
* Opens proprties editor for bundle value Is invoked at double mouse click
* on visual element
*
@@ -383,7 +388,7 @@
* If the value of attribute of an element of an source tree is mapped by
* the way of text node of a visual tree, this method returns the text
* node, otherwise - null
- *
+ * @deprecated
* @param pageContext
* Contains the information on edited page.
* @param sourceElement
@@ -447,4 +452,36 @@
public void setModify(boolean modify);
+ /**
+ * open bundle
+ *
+ * @param pageContext
+ * @param visualNod
+ * @return
+ */
+ public boolean openBundle(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementMapping elementMapping);
+
+ /**
+ *
+ * @param node
+ * @param elementData
+ * @param domMapping
+ * @return
+ */
+ public NodeData getNodeData(nsIDOMNode node, VpeElementData elementData,
+ VpeDomMapping domMapping);
+
+ /**
+ *
+ * @param elementMapping
+ * @param focusPosition
+ * @param anchorPosition
+ * @param domMapping
+ * @return
+ */
+ public nsIDOMNode getVisualNodeByBySourcePosition(
+ VpeElementMapping elementMapping, int focusPosition,
+ int anchorPosition, VpeDomMapping domMapping);
+
}
\ No newline at end of file
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/NodesManagingUtil.java
(from rev 8946,
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/NodesManagingUtil.java)
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/NodesManagingUtil.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/NodesManagingUtil.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,146 @@
+package org.jboss.tools.vpe.editor.util;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @author S.Dzmitrovich
+ *
+ */
+public class NodesManagingUtil {
+
+ /**
+ * name of "view" tag
+ */
+ private static final String VIEW_TAGNAME = "view"; //$NON-NLS-1$
+
+ /**
+ * name of "locale" attribute
+ */
+ private static final String LOCALE_ATTRNAME = "locale"; //$NON-NLS-1$
+
+ /**
+ *
+ * @param domMapping
+ * @param node
+ * @return
+ */
+ public static VpeNodeMapping getNodeMapping(VpeDomMapping domMapping,
+ Node node) {
+
+ return domMapping.getNearNodeMappingAtSourceNode(node);
+
+ }
+
+ /**
+ *
+ * @param domMapping
+ * @param node
+ * @return
+ */
+ public static VpeNodeMapping getNodeMapping(VpeDomMapping domMapping,
+ nsIDOMNode node) {
+
+ return domMapping.getNearNodeMappingAtVisualNode(node);
+
+ }
+
+ /**
+ *
+ * @param sourceEditor
+ * @return
+ */
+ public static IStructuredModel getStructuredModel(
+ StructuredTextEditor sourceEditor) {
+
+ IDocument document = sourceEditor.getTextViewer().getDocument();
+
+ return StructuredModelManager.getModelManager()
+ .getExistingModelForEdit(document);
+ }
+
+ /**
+ *
+ * @param node
+ * @return
+ */
+ public static int getNodeLength(Node node) {
+
+ if (node instanceof IDOMAttr) {
+ return ((IDOMAttr) node).getValueSource().length();
+ } else if (node instanceof IndexedRegion) {
+ return ((IndexedRegion) node).getEndOffset()
+ - ((IndexedRegion) node).getStartOffset();
+ }
+ return 0;
+ }
+
+ /**
+ * get start offset of node
+ *
+ * @param node
+ * @return
+ */
+ public static int getStartOffsetNode(Node node) {
+
+ if (node instanceof IDOMAttr) {
+ return ((IDOMAttr) node).getValueRegionStartOffset() + 1;
+ } else if (node instanceof IndexedRegion) {
+ return ((IndexedRegion) node).getStartOffset();
+ }
+ return 0;
+ }
+
+ /**
+ * get end offset of node
+ *
+ * @param node
+ * @return
+ */
+ public static int getEndOffsetNode(Node node) {
+
+ if (node instanceof IndexedRegion) {
+ return ((IndexedRegion) node).getEndOffset();
+ }
+ return 0;
+ }
+
+ /**
+ *
+ * @param pageContext
+ * @param sourceElement
+ * @return
+ */
+ public static String getPageLocale(VpePageContext pageContext,
+ Node sourceNode) {
+
+ while (sourceNode != null) {
+
+ if (VIEW_TAGNAME.equals(sourceNode.getLocalName())) {
+ break;
+ }
+ sourceNode = sourceNode.getParentNode();
+ }
+
+ if ((sourceNode == null) || !(sourceNode instanceof Element)
+ || !(((Element) sourceNode).hasAttribute(LOCALE_ATTRNAME)))
+ return null;
+
+ String locale = ((Element) sourceNode).getAttribute(LOCALE_ATTRNAME);
+
+ return locale;
+
+ }
+
+}
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java
(from rev 8946,
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
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -0,0 +1,215 @@
+package org.jboss.tools.vpe.editor.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMRange;
+import org.mozilla.interfaces.nsISelection;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @author S.Dzmitrovich
+ *
+ */
+public class SelectionUtil {
+
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ private static List<String> NO_INPUT_TYPES;
+
+ static {
+ NO_INPUT_TYPES = new ArrayList<String>();
+
+ NO_INPUT_TYPES.add(HTML.VALUE_TEXT_TYPE);
+ NO_INPUT_TYPES.add(HTML.VALUE_PASSWORD_TYPE);
+ NO_INPUT_TYPES.add(EMPTY_STRING);
+ }
+
+ /**
+ * get selected visual node from nsiDelection
+ *
+ * @param selection
+ * @return
+ */
+ public static nsIDOMNode getSelectedNode(nsISelection selection) {
+
+ if (selection.getAnchorNode() == selection.getFocusNode()) {
+ if (selection.getFocusNode() != null) {
+ if ((selection.getFocusNode().getNodeType() != nsIDOMNode.TEXT_NODE)
+ && (selection.getFocusOffset() != 0)) {
+
+ return selection.getFocusNode().getChildNodes().item(
+ selection.getFocusOffset() - 1);
+ } else
+ return selection.getFocusNode();
+
+ }
+ } else {
+ nsIDOMRange range = selection.getRangeAt(0);
+ nsIDOMNode visualAncestor = range.getCommonAncestorContainer();
+ return visualAncestor;
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param pageContext
+ * @param node
+ * @param offset
+ * @param length
+ */
+ public static void setSourceSelection(VpePageContext pageContext,
+ Node node, int offset, int length) {
+
+ int start = NodesManagingUtil.getStartOffsetNode(node);
+
+ pageContext.getSourceBuilder().getStructuredTextViewer()
+ .setSelectedRange(start + offset, length);
+ pageContext.getSourceBuilder().getStructuredTextViewer().revealRange(
+ start + offset, length);
+
+ }
+
+ public static void setSourceSelection(VpePageContext pageContext,
+ Node node, int offset) {
+
+ int start = NodesManagingUtil.getStartOffsetNode(node);
+
+ pageContext.getSourceBuilder().getStructuredTextViewer()
+ .getTextWidget().setSelection(start + offset);
+
+ }
+
+ public static VpeNodeMapping getNodeMappingBySourceSelection(
+ IStructuredModel model, VpeDomMapping domMapping, int focus,
+ int anchor) {
+
+ /*
+ * implementation of IDOMModel's method getIndexedRegion(...) has one
+ * feature : if cursor is situated at the border of elements then this
+ * method return next element. For example ... <h:inputText
+ * ../><h:outputText/>... - if cursor will be situated at the right
+ * border of "h:inputText" element then getIndexedRegion() return
+ * "h:outputText" element. So for focus position we choose smaller value
+ */
+
+ if (anchor < focus) {
+ focus = anchor;
+ anchor = focus;
+ }
+
+ // get source node by offset
+ Node focusNode = getSourceNodeByPosition(model, focus);
+
+ // if focus node also contain anchor point (selected only 1 element)
+ if ((focusNode != null) && isNodeContainsPosition(focusNode, anchor)) {
+
+ return NodesManagingUtil.getNodeMapping(domMapping, focusNode);
+
+ }
+ return null;
+
+ }
+
+ /**
+ * if position belong to node return true
+ *
+ * @param node
+ * @param position
+ * @return
+ */
+ private static boolean isNodeContainsPosition(Node node, int position) {
+
+ if ((((IDOMNode) node).getStartOffset() <= position)
+ && (((IDOMNode) node).getEndOffset() >= position))
+ return true;
+
+ return false;
+ }
+
+ public static Node getSourceNodeByPosition(IStructuredModel model,
+ int position) {
+
+ // get source node by position
+ Node node = (Node) model.getIndexedRegion(position);
+
+ return node;
+ }
+
+ public static Point getSelectionRange(nsISelection selection) {
+ nsIDOMNode focusedNode = getSelectedNode(selection);
+
+ Point range = new Point(0, 0);
+
+ if (focusedNode != null) {
+
+ range.x = selection.getFocusOffset();
+ range.y = selection.getAnchorOffset() - selection.getFocusOffset();
+
+ }
+ return range;
+ }
+
+ public static VpeNodeMapping getNodeMappingBySourceSelection(
+ StructuredTextEditor sourceEditor, VpeDomMapping domMapping) {
+
+ Point range = sourceEditor.getTextViewer().getSelectedRange();
+
+ IDocument document = sourceEditor.getTextViewer().getDocument();
+
+ IStructuredModel model = StructuredModelManager.getModelManager()
+ .getExistingModelForEdit(document);
+
+ 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 then this
+ * method return next element. For example ... <h:inputText
+ * ../><h:outputText/>... - if cursor will be situated at the right
+ * border of "h:inputText" element then getIndexedRegion() return
+ * "h:outputText" element. So for focus position we choose smaller value
+ */
+
+ if (anchor < focus) {
+ focus = anchor;
+ anchor = focus;
+ }
+
+ // get source node by offset
+ Node focusNode = getSourceNodeByPosition(model, focus);
+
+ // if focus node also contain anchor point (selected only 1 element)
+ if ((focusNode != null) && isNodeContainsPosition(focusNode, anchor)) {
+
+ return NodesManagingUtil.getNodeMapping(domMapping, focusNode);
+
+ }
+ return null;
+
+ }
+
+ public static nsIDOMNode getLastSelectedNode(VpePageContext pageContext) {
+
+ return pageContext.getVisualBuilder().getXulRunnerEditor()
+ .getLastSelectedNode();
+
+ }
+
+ static public Point getSourceSelection(StructuredTextEditor sourceEditor) {
+ return sourceEditor.getTextViewer().getSelectedRange();
+ }
+
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -20,6 +20,7 @@
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMHTMLInputElement;
import org.mozilla.interfaces.nsIDOMNSHTMLInputElement;
import org.mozilla.interfaces.nsIDOMNSHTMLTextAreaElement;
import org.mozilla.interfaces.nsIDOMNode;
@@ -28,6 +29,11 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+/**
+ * @deprecated
+ * @author S. Dzmitrovich
+ *
+ */
public class TemplateManagingUtil {
/**
@@ -428,9 +434,13 @@
if ((node != null) && (range != null))
if (HTML.TAG_INPUT.equalsIgnoreCase(node.getLocalName())) {
- nsIDOMNSHTMLInputElement inputElement = (nsIDOMNSHTMLInputElement) node
- .queryInterface(nsIDOMNSHTMLInputElement.NS_IDOMNSHTMLINPUTELEMENT_IID);
- inputElement.setSelectionRange(range.x, range.x + range.y);
+
+ nsIDOMHTMLInputElement inputElement = (nsIDOMHTMLInputElement) node
+ .queryInterface(nsIDOMHTMLInputElement.NS_IDOMHTMLINPUTELEMENT_IID);
+ System.out.print("\ninput:"+inputElement.getType());
+// nsIDOMNSHTMLInputElement inputElement = (nsIDOMNSHTMLInputElement) node
+// .queryInterface(nsIDOMNSHTMLInputElement.NS_IDOMNSHTMLINPUTELEMENT_IID);
+// inputElement.setSelectionRange(range.x, range.x + range.y);
} else if (HTML.TAG_TEXTAREA.equalsIgnoreCase(node.getLocalName())) {
nsIDOMNSHTMLTextAreaElement textAreaElement = (nsIDOMNSHTMLTextAreaElement) node
.queryInterface(nsIDOMNSHTMLTextAreaElement.NS_IDOMNSHTMLTEXTAREAELEMENT_IID);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TextUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TextUtil.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TextUtil.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -13,6 +13,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.mozilla.interfaces.nsIDOMKeyEvent;
+
public class TextUtil {
private final static String SOURCE_BREAK = "\r\n";
private final static String VISUAL_BREAK = "\n";
@@ -352,4 +354,17 @@
}
return true;
}
+
+ public static String getChar(nsIDOMKeyEvent keyEvent) {
+ // get inserted string
+ long charCode = keyEvent.getCharCode();
+ char[] s = new char[1];
+ s[0] = (char) charCode;
+ String str = new String(s);
+ if (TextUtil.containsKey(s[0])) {
+ str = TextUtil.getValue(s[0]);
+ }
+
+ return str;
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java 2008-06-26
05:28:13 UTC (rev 8950)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java 2008-06-26
08:19:17 UTC (rev 8951)
@@ -50,6 +50,8 @@
import org.mozilla.xpcom.Mozilla;
import org.mozilla.xpcom.XPCOMException;
+import com.sun.org.apache.bcel.internal.generic.RETURN;
+
/**
* @author Sergey Vasilyev (svasilyev(a)exadel.com)
*
@@ -100,7 +102,8 @@
*/
private static final String STYLE_ATTR="style";
- private nsIDOMElement lastSelectedElement;
+// private nsIDOMElement lastSelectedElement;
+ private nsIDOMNode lastSelectedNode;
private int lastResizerConstrains;
/**
* Scroll selection into view flag
@@ -290,30 +293,42 @@
*/
public nsIDOMElement getLastSelectedElement() {
- return lastSelectedElement;
+ return getElement(lastSelectedNode);
}
- /**
- * Function created to restore functionality of MozillaBrowser
- * @return
- */
- private void setLastSelectedElement(nsIDOMElement lastSelectedElement) {
- this.lastSelectedElement = lastSelectedElement;
+
+ public nsIDOMNode getLastSelectedNode() {
+ return lastSelectedNode;
}
+ // /**
+ // * Function created to restore functionality of MozillaBrowser
+ // * @return
+ // */
+ // private void setLastSelectedElement(nsIDOMElement lastSelectedElement) {
+ // this.lastSelectedElement = lastSelectedElement;
+ // }
+
+ private void setLastSelectedNode(nsIDOMNode lastSelectedNode) {
+ this.lastSelectedNode = lastSelectedNode;
+ }
+
/**
* Draws rectangle around the element.
* @param element
* @param resizerConstrains
* @param scroll
*/
- public void setSelectionRectangle(nsIDOMElement element, int resizerConstrains, boolean
scroll) {
+ public void setSelectionRectangle(nsIDOMNode node, int resizerConstrains, boolean
scroll) {
if (getIFlasher() == null) {
return;
}
+
+ nsIDOMElement element = getElement(node);
+
if (getLastSelectedElement() != null) {
- scrollRegtangleFlag = scroll && element != null;
+ scrollRegtangleFlag = scroll && node != null;
if(checkVisability(getLastSelectedElement())){
@@ -385,7 +400,8 @@
}
}
- setLastSelectedElement(element);
+// setLastSelectedElement(element);
+ setLastSelectedNode(node);
lastResizerConstrains = resizerConstrains;
}
@@ -490,8 +506,8 @@
*
*/
public void showResizer() {
- if (xulRunnerVpeResizer != null && lastSelectedElement != null &&
lastResizerConstrains != 0) {
- xulRunnerVpeResizer.show(lastSelectedElement, lastResizerConstrains);
+ if (xulRunnerVpeResizer != null && getLastSelectedElement() != null &&
lastResizerConstrains != 0) {
+ xulRunnerVpeResizer.show(getLastSelectedElement(), lastResizerConstrains);
}
}
@@ -564,6 +580,37 @@
this.selectionListener = selectionListener;
}
+ /**
+ * get nsIDomElement from nsIDomNode
+ *
+ * if node is nsIDomElement - return it
+ *
+ * if node is text node - return it's
+ *
+ * parent else return null
+ *
+ * @param node
+ * @return
+ */
+ private nsIDOMElement getElement(nsIDOMNode node) {
+
+ if (node != null) {
+
+ if (node.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
+ return (nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ } else if (node.getNodeType() == nsIDOMNode.TEXT_NODE) {
+
+ return (nsIDOMElement) node.getParentNode().queryInterface(
+ nsIDOMElement.NS_IDOMELEMENT_IID);
+
+ }
+
+ }
+
+ return null;
+ }
+
}