Author: sdzmitrovich
Date: 2008-03-07 14:03:33 -0500 (Fri, 07 Mar 2008)
New Revision: 6789
Added:
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/VpeElementData.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
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateKeyEventHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateNodesManager.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputLabelTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputTextTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/NodeProxyUtil.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/VpeElementMapping.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/VpeAbstractTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreationData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java
Log:
review editing mechanism
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractJsfTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractJsfTemplate.java 2008-03-07
17:06:05 UTC (rev 6788)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractJsfTemplate.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -14,10 +14,19 @@
import java.util.Map;
import java.util.Set;
+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.VpeElementMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.template.EditableTemplateAdapter;
import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMKeyEvent;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsISelection;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
/**
* general class for jsf templates
@@ -72,4 +81,100 @@
}
+ protected boolean handleCharacter(VpePageContext pageContext,
+ nsIDOMKeyEvent keyEvent) {
+
+ // get selection
+ nsISelection selection = getCurrentSelection(pageContext);
+
+ // get visual node which is focused
+ nsIDOMNode visualNode = selection.getFocusNode();
+
+ VpeElementMapping elementMapping = getElmentMapping(pageContext,
+ visualNode);
+ if (elementMapping != null)
+ return super.handleCharacter(pageContext, keyEvent);
+ else
+ return true;
+ }
+
+ protected boolean handleLeftDelete(VpePageContext pageContext,
+ nsIDOMKeyEvent keyEvent) {
+
+ // get selection
+ nsISelection selection = getCurrentSelection(pageContext);
+
+ // get visual node which is focused
+ nsIDOMNode visualNode = selection.getFocusNode();
+
+ VpeElementMapping elementMapping = getElmentMapping(pageContext,
+ visualNode);
+ if (elementMapping != null)
+ return super.handleLeftDelete(pageContext, keyEvent);
+ else
+ return true;
+
+ }
+
+ protected boolean handleRightDelete(VpePageContext pageContext,
+ nsIDOMKeyEvent keyEvent) {
+
+ // get selection
+ nsISelection selection = getCurrentSelection(pageContext);
+
+ // get visual node which is focused
+ nsIDOMNode visualNode = selection.getFocusNode();
+
+ VpeElementMapping elementMapping = getElmentMapping(pageContext,
+ visualNode);
+ if (elementMapping != null)
+ return super.handleRightDelete(pageContext, keyEvent);
+ else
+ return true;
+ }
+
+ @Override
+ public void setSelection(VpePageContext pageContext, nsISelection selection) {
+
+ nsIDOMNode focusedVisualNode = selection.getFocusNode();
+
+ VpeElementMapping elementMapping = pageContext.getDomMapping()
+ .getNearElementMapping(focusedVisualNode);
+
+ if (elementMapping != null)
+ super.setSelection(pageContext, selection);
+ else {
+
+ VpeNodeMapping insertedMapping = pageContext.getDomMapping()
+ .getNearNodeMappingAtVisualNode(focusedVisualNode);
+
+ if (insertedMapping != null) {
+
+ Node insertedNode = insertedMapping.getSourceNode();
+
+ int offset = ((IDOMNode) insertedNode).getStartOffset();
+
+ Node realNode = TemplateManagingUtil.getSourceNodeByPosition(
+ pageContext, offset);
+
+ VpeElementMapping mappingRealNode = pageContext.getDomMapping()
+ .getNearElementMapping(realNode);
+
+ if (mappingRealNode != null) {
+
+ Node focusedNode = getFocusedNode(realNode, mappingRealNode
+ .getElementData(), offset);
+
+ setSourceSelection(pageContext, focusedNode, 0,
+ getLengthNode(focusedNode));
+
+ pageContext.getVisualBuilder().setSelectionRectangle(
+ (nsIDOMElement) mappingRealNode.getVisualElement()
+ .queryInterface(
+ nsIDOMElement.NS_IDOMELEMENT_IID));
+ }
+
+ }
+ }
+ }
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java 2008-03-07
17:06:05 UTC (rev 6788)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -18,7 +18,8 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -41,32 +42,32 @@
/**
* name of "param" tag
*/
- private static final String PARAM_NAME = "param";
+ private static final String PARAM_NAME = "param"; //$NON-NLS-1$
/**
* name of "choice"
*/
- private static final String CHOICE_NAME = "choice";
+ private static final String CHOICE_NAME = "choice"; //$NON-NLS-1$
/**
* message format elements separator
*/
- private static final String MESSAGE_FORMAT_ELEMENTS_SEPARATOR = ",";
+ private static final String MESSAGE_FORMAT_ELEMENTS_SEPARATOR = ",";
//$NON-NLS-1$
/**
* choices separator
*/
- private static final String CHOICES_SEPARATOR = "\\|";
+ private static final String CHOICES_SEPARATOR = "\\|"; //$NON-NLS-1$
/**
* choices separator
*/
- private static final String CHOICE_PAIR_SEPARATOR = "#";
+ private static final String CHOICE_PAIR_SEPARATOR = "#"; //$NON-NLS-1$
/**
* message format elements pattern
*/
- private static final String MESSAGE_FORMAT_ELEMENTS_PATTERN =
"\\{(\\d+)(,.*?){0,2}?\\}";
+ private static final String MESSAGE_FORMAT_ELEMENTS_PATTERN =
"\\{(\\d+)(,.*?){0,2}?\\}"; //$NON-NLS-1$
/*
* (non-Javadoc)
@@ -79,7 +80,7 @@
Element element = (Element) sourceNode;
- List<VpeNodeMapping> attributesMapping = new ArrayList<VpeNodeMapping>();
+ VpeElementData elementData = new VpeElementData();
// create span element
nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
@@ -115,16 +116,13 @@
nsIDOMText text;
// if bundleValue differ from value then will be represent
// bundleValue, but text will be not edit
- if (!value.equals(newValue)) {
+ boolean isEditable = value.equals(newValue);
- text = visualDocument.createTextNode(newValue);
+ text = visualDocument.createTextNode(newValue);
+ // add attribute for ability of editing
+ elementData.addAttributeData(new VpeAttributeData(attr, text,
+ isEditable));
- } else {
-
- text = visualDocument.createTextNode(value);
- // add attribute for ability of editing
- attributesMapping.add(new VpeNodeMapping(attr, text));
- }
span.appendChild(text);
}
// then text can be html code
@@ -144,6 +142,8 @@
spanInfo.addSourceChild(child);
}
+ elementData.addAttributeData(new VpeAttributeData(attr, span,
+ false));
creationData.addChildrenInfo(spanInfo);
@@ -151,7 +151,7 @@
}
- creationData.setData(attributesMapping);
+ creationData.setElementData(elementData);
return creationData;
@@ -229,7 +229,8 @@
// get "choice" as value
String choice = getChoice(parametres[2]);
if (choice != null)
- value = choice.replaceAll("[\\{\\}]", "");;
+ value = choice.replaceAll("[\\{\\}]", "");
//$NON-NLS-1$//$NON-NLS-2$
+ ;
}
}
@@ -239,7 +240,7 @@
// get number of param
String paramNumber = parametres[0].trim();
- paramNumber = paramNumber.replaceAll("[\\{\\}]", "");
+ paramNumber = paramNumber.replaceAll("[\\{\\}]", "");
//$NON-NLS-1$//$NON-NLS-2$
try {
// decode
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputLabelTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputLabelTemplate.java 2008-03-07
17:06:05 UTC (rev 6788)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputLabelTemplate.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -10,12 +10,10 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.jsf.template;
-import java.util.ArrayList;
-import java.util.List;
-
import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -38,7 +36,7 @@
/**
* name of "for" attribute
*/
- protected static final String FOR_ATTR_NAME = "for";
+ protected static final String FOR_ATTR_NAME = "for"; //$NON-NLS-1$
/*
* (non-Javadoc)
@@ -51,7 +49,7 @@
Element element = (Element) sourceNode;
- List<VpeNodeMapping> attributesMapping = new ArrayList<VpeNodeMapping>();
+ VpeElementData elementData = new VpeElementData();
// create label element
nsIDOMElement label = visualDocument.createElement(HTML.TAG_LABEL);
@@ -71,7 +69,7 @@
// if escape then contents of value (or other attribute) is only
// text
if (!element.hasAttribute(ESCAPE_ATTR_NAME)
- || ("true".equalsIgnoreCase(element
+ || ("true".equalsIgnoreCase(element //$NON-NLS-1$
.getAttribute(ESCAPE_ATTR_NAME)))) {
String value = attr.getNodeValue();
@@ -82,23 +80,20 @@
nsIDOMText text;
// if bundleValue differ from value then will be represent
// bundleValue, but text will be not edit
- if (!value.equals(bundleValue)) {
+ boolean isEditable = value.equals(bundleValue);
- text = visualDocument.createTextNode(bundleValue);
+ text = visualDocument.createTextNode(bundleValue);
+ // add attribute for ability of editing
+ elementData.addAttributeData(new VpeAttributeData(attr, text,
+ isEditable));
- } else {
-
- text = visualDocument.createTextNode(value);
- // add attribute for ability of editing
- attributesMapping.add(new VpeNodeMapping(attr, text));
- }
label.appendChild(text);
}
// then text can be html code
else {
// create info
- VpeChildrenInfo spanInfo = new VpeChildrenInfo(label);
+ VpeChildrenInfo labelInfo = new VpeChildrenInfo(label);
// reparse attribute's value
NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
@@ -108,17 +103,20 @@
Node child = list.item(i);
- spanInfo.addSourceChild(child);
+ labelInfo.addSourceChild(child);
}
+ elementData.addAttributeData(new VpeAttributeData(attr, label,
+ false));
+
// add info to creation data
- creationData.addChildrenInfo(spanInfo);
+ creationData.addChildrenInfo(labelInfo);
}
}
- creationData.setData(attributesMapping);
+ creationData.setElementData(elementData);
return creationData;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputTextTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputTextTemplate.java 2008-03-07
17:06:05 UTC (rev 6788)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputTextTemplate.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -10,12 +10,10 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.jsf.template;
-import java.util.ArrayList;
-import java.util.List;
-
import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -46,7 +44,7 @@
Element element = (Element) sourceNode;
- List<VpeNodeMapping> attributesMapping = new ArrayList<VpeNodeMapping>();
+ VpeElementData elementData = new VpeElementData();
// create span element
nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
@@ -64,7 +62,7 @@
// if escape then contents of value (or other attribute) is only
// text
if (!element.hasAttribute(ESCAPE_ATTR_NAME)
- || "true".equalsIgnoreCase(element
+ || "true".equalsIgnoreCase(element //$NON-NLS-1$
.getAttribute(ESCAPE_ATTR_NAME))) {
String value = attr.getNodeValue();
@@ -75,16 +73,13 @@
nsIDOMText text;
// if bundleValue differ from value then will be represent
// bundleValue, but text will be not edit
- if (!value.equals(bundleValue)) {
+ boolean isEditable = value.equals(bundleValue);
- text = visualDocument.createTextNode(bundleValue);
+ text = visualDocument.createTextNode(bundleValue);
+ // add attribute for ability of editing
- } else {
-
- text = visualDocument.createTextNode(value);
- // add attribute for ability of editing
- attributesMapping.add(new VpeNodeMapping(attr, text));
- }
+ elementData.addAttributeData(new VpeAttributeData(attr, text,
+ isEditable));
span.appendChild(text);
}
// then text can be html code
@@ -104,14 +99,15 @@
// add info to creation data
spanInfo.addSourceChild(child);
}
-
+ elementData.addAttributeData(new VpeAttributeData(attr, span,
+ false));
creationData.addChildrenInfo(spanInfo);
}
}
- creationData.setData(attributesMapping);
+ creationData.setElementData(elementData);
return creationData;
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/NodeProxyUtil.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -20,8 +20,8 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
import org.jboss.tools.jsf.vpe.jsf.template.util.model.ElementProxy;
+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.NodeListImpl;
import org.jboss.tools.jsf.vpe.jsf.template.util.model.TextProxy;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -126,6 +126,7 @@
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.VpeAnyData;
import org.jboss.tools.vpe.editor.template.VpeEditAnyDialog;
import org.jboss.tools.vpe.editor.template.VpeHtmlTemplate;
@@ -133,9 +134,9 @@
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.template.VpeTemplateListener;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
-import org.jboss.tools.vpe.editor.template.VpeTemplateNodesManager;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
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.jboss.tools.vpe.editor.util.VpeDndUtil;
@@ -539,12 +540,25 @@
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;
}
+
+ VpeTemplate template = TemplateManagingUtil
+ .getTemplateBySourceSelection(pageContext, focusPosition,
+ anchorPosition);
+
+ if (template instanceof ITemplateSelectionManager) {
+ ((ITemplateSelectionManager) template).setVisualSelectionBySource(
+ pageContext, visualSelectionController, focusPosition,
+ anchorPosition);
+ return;
+ }
+
Node focusNode = getSourceNodeAt(focusPosition);
if (focusNode == null) {
return;
@@ -1369,14 +1383,6 @@
if (elementMapping != null) {
- // if template implements VpeTemplateNodesManager interface
- if (elementMapping.getTemplate() instanceof VpeTemplateNodesManager) {
- Node focusedAttr = ((VpeTemplateNodesManager) elementMapping
- .getTemplate()).getFocusedNode((IDOMNode) node,
- offset, elementMapping.getData());
- if (node != null)
- return focusedAttr;
- }
if (node instanceof IDOMElement) {
IDOMElement element = (IDOMElement) node;
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -21,8 +21,11 @@
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.VpePseudoContentCreator;
+import org.jboss.tools.vpe.editor.template.VpeTemplate;
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.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
@@ -69,6 +72,15 @@
}
public void setSelection(nsISelection selection) {
+
+ VpeTemplate vpeTemplate = TemplateManagingUtil
+ .getTemplateByVisualSelection(visualBuilder.getPageContext());
+ if (vpeTemplate instanceof ITemplateSelectionManager) {
+ ((ITemplateSelectionManager) vpeTemplate).setSelection(
+ visualBuilder.getPageContext(), selection);
+ return;
+ }
+
if (selection.getIsCollapsed()) {
VisualSelectionInfo info = getVisualFocusSelectedInfo(selection);
if (info != null) {
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -35,9 +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.template.VpeTemplateNodesManager;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
@@ -260,9 +260,9 @@
VpeTemplate template = elementMapping.getTemplate();
// if template implements VpeTemplateNodesManager interface
- if (template instanceof VpeTemplateNodesManager) {
- return ((VpeTemplateNodesManager) template).openBundle(
- pageContext, visualNode, elementMapping.getData());
+ if (template instanceof ITemplateNodesManager) {
+ return ((ITemplateNodesManager) template).openBundle(
+ pageContext, visualNode, elementMapping.getElementData());
} else {
template.openBundleEditors(pageContext,
(Element) sourceNode, elementMapping.getData());
@@ -325,29 +325,12 @@
.getNodeMapping(sourceParent);
if (elementMapping != null) {
-
+
VpeTemplate template = elementMapping.getTemplate();
- // if template implements VpeTemplateAttributesManager
- // functions
- if (template instanceof VpeTemplateNodesManager) {
- // get attribute
- Node node = ((VpeTemplateNodesManager) template)
- .getSourceNode(pageContext,
- visualText, elementMapping.getData());
- // set selection
- if (node != null)
- ((VpeTemplateNodesManager) template)
- .setSourceNodeSelection(pageContext,
- node, offset, length);
- else
- setSelection(sourceParent, offset, length);
- } else {
-
- template.setSourceAttributeSelection(pageContext,
- (Element) sourceParent, offset, length,
- elementMapping.getData());
- }
+ template.setSourceAttributeSelection(pageContext,
+ (Element) sourceParent, offset, length,
+ elementMapping.getData());
}
} else if (sourceParent.getNodeType() == Node.COMMENT_NODE) {
// VpeVisualElementInfo info = domMapping.getVisualElementInfo(sourceParent);
@@ -430,7 +413,7 @@
return structuredTextViewer;
}
- Document getSourceDocument() {
+ public Document getSourceDocument() {
return sourceDocument;
}
}
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -57,6 +57,7 @@
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
+import org.jboss.tools.vpe.editor.template.ITemplateNodesManager;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
@@ -64,7 +65,6 @@
import org.jboss.tools.vpe.editor.template.VpeTagDescription;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
-import org.jboss.tools.vpe.editor.template.VpeTemplateNodesManager;
import org.jboss.tools.vpe.editor.template.VpeToggableTemplate;
import org.jboss.tools.vpe.editor.template.dnd.VpeDnd;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -205,6 +205,7 @@
pageContext.installIncludeElements();
addChildren(null, sourceDocument, visualContentArea);
registerNodes(new VpeNodeMapping(sourceDocument, visualContentArea));
+
}
public void rebuildDom(Document sourceDocument) {
@@ -433,12 +434,13 @@
setReadOnlyElement(visualNewElement);
}
if (registerFlag) {
- VpeElementMapping elementMapping = new VpeElementMapping(
- (Element) sourceNode, visualNewElement, border,
- template, ifDependencySet, creationData.getData());
- // elementMapping.setXmlnsMap(xmlnsMap);
- registerNodes(elementMapping);
- }
+ VpeElementMapping elementMapping = new VpeElementMapping(
+ (Element) sourceNode, visualNewElement, border,
+ template, ifDependencySet, creationData.getData(),
+ creationData.getElementData());
+ // elementMapping.setXmlnsMap(xmlnsMap);
+ registerNodes(elementMapping);
+ }
if (template.isChildren()) {
List<?> childrenInfoList = creationData.getChildrenInfoList();
if (childrenInfoList == null) {
@@ -1140,7 +1142,7 @@
return visualContentArea;
}
- void setSelectionRectangle(nsIDOMElement visualElement) {
+ public void setSelectionRectangle(nsIDOMElement visualElement) {
setSelectionRectangle(visualElement, true);
}
@@ -1574,10 +1576,10 @@
VpeTemplate template = ((VpeElementMapping) nodeMapping)
.getTemplate();
// if template implements VpeTemplateAttributesManager
- if (template instanceof VpeTemplateNodesManager)
- return ((VpeTemplateNodesManager) template).isNodeEditable(
+ if (template instanceof ITemplateNodesManager)
+ return ((ITemplateNodesManager) template).isNodeEditable(
pageContext, visualNode,
- ((VpeElementMapping) nodeMapping).getData());
+ ((VpeElementMapping) nodeMapping).getElementData());
}
@@ -1938,16 +1940,10 @@
VpeElementMapping elementMapping = domMapping
.getNearElementMapping(sourceElement);
if (elementMapping != null) {
-
- if (elementMapping.getTemplate() instanceof VpeTemplateNodesManager) {
- return (nsIDOMText) ((VpeTemplateNodesManager) elementMapping
- .getTemplate()).getVisualNode(pageContext, attr,
- elementMapping.getData());
- }
-
- return elementMapping.getTemplate().getOutputTextNode(pageContext,
- sourceElement, elementMapping.getData());
- }
+
+ return elementMapping.getTemplate().getOutputTextNode(pageContext,
+ sourceElement, elementMapping.getData());
+ }
return null;
}
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -42,11 +42,12 @@
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.VpeHtmlTemplate;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
-import org.jboss.tools.vpe.editor.template.VpeTemplateKeyEventHandler;
import org.jboss.tools.vpe.editor.util.FlatIterator;
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.xulrunner.editor.XulRunnerVpeUtils;
import org.mozilla.interfaces.nsIDOMElement;
@@ -168,12 +169,13 @@
boolean shiftKey = keyEvent.getShiftKey();
// get template of selected element
- VpeTemplate template = getCurrentSelectionTemplate();
+ VpeTemplate template = TemplateManagingUtil
+ .getTemplateByVisualSelection(pageContext);
// if template сan handle keyEvent than pass control to him. And if
// template handled event return true
- if ((template instanceof VpeTemplateKeyEventHandler)
- && ((VpeTemplateKeyEventHandler) template).handleKeyPress(
+ if ((template instanceof ITemplateKeyEventHandler)
+ && ((ITemplateKeyEventHandler) template).handleKeyPress(
pageContext, keyEvent)) {
return true;
}
@@ -1825,19 +1827,4 @@
return pageContext.getEditPart().getController().getXulRunnerEditor().getLastSelectedElement();
}
-
- /**
- * get {@link VpeTemplate} from selection
- *
- * @return
- */
- private VpeTemplate getCurrentSelectionTemplate() {
- VpeElementMapping elementMapping = domMapping
- .getNearElementMapping(getSelectedNode());
-
- if (elementMapping != null)
- return elementMapping.getTemplate();
-
- return null;
- }
}
\ No newline at end of file
Added:
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
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeAttributeData.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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;
+
+ 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;
+
+ }
+
+ /**
+ * 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;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementData.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author Sergey Dzmitrovich
+ *
+ * keep information about element
+ */
+public class VpeElementData {
+
+ /**
+ * list of attribute data
+ *
+ * keep information about output attributes
+ */
+ private List<VpeAttributeData> attributesData;
+
+ /**
+ * get attributes data
+ *
+ * @return
+ */
+ public List<VpeAttributeData> getAttributesData() {
+ return attributesData;
+ }
+
+ /**
+ * set attributes data
+ *
+ * @param attributesData
+ */
+ public void setAttributesData(List<VpeAttributeData> attributesData) {
+ this.attributesData = attributesData;
+ }
+
+ /**
+ * add <code>VpeAttributeData</code>
+ * @param attributeData
+ */
+ public void addAttributeData(VpeAttributeData attributeData) {
+
+ if (attributesData == null)
+ attributesData = new ArrayList<VpeAttributeData>();
+
+ attributesData.add(attributeData);
+
+ }
+
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java 2008-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -11,6 +11,7 @@
package org.jboss.tools.vpe.editor.mapping;
import java.util.Set;
+
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.template.expression.VpeExpressionBuilder;
import org.mozilla.interfaces.nsIDOMElement;
@@ -21,19 +22,40 @@
private VpeTemplate template;
private Set ifDependencySet;
// private Map xmlnsMap;
+ /**
+ * @deprecated - You must use elementData. If VpeElementData has not
+ * necessary functionality you must extend its
+ */
private Object data;
+ private VpeElementData elementData;
private nsIDOMElement border;
- public VpeElementMapping(Element sourceElement, nsIDOMElement visualElement,
nsIDOMElement border, VpeTemplate template, Set ifDependencySet, Object data) {
+ public VpeElementMapping(Element sourceElement,
+ nsIDOMElement visualElement, nsIDOMElement border,
+ VpeTemplate template, Set ifDependencySet, Object data, VpeElementData elementData) {
super(sourceElement, visualElement);
this.template = template;
if (ifDependencySet != null && ifDependencySet.size() > 0) {
this.ifDependencySet = ifDependencySet;
}
this.data = data;
+ this.elementData = elementData;
this.border = border;
}
+ public VpeElementMapping(Element sourceElement,
+ nsIDOMElement visualElement, nsIDOMElement border,
+ VpeTemplate template, Set ifDependencySet,
+ VpeElementData elementData) {
+ super(sourceElement, visualElement);
+ this.template = template;
+ if (ifDependencySet != null && ifDependencySet.size() > 0) {
+ this.ifDependencySet = ifDependencySet;
+ }
+ this.elementData = elementData;
+ this.border = border;
+ }
+
public nsIDOMElement getVisualElement() {
return (nsIDOMElement) getVisualNode();
}
@@ -50,6 +72,10 @@
// this.xmlnsMap = xmlnsMap;
// }
+ /**
+ * @deprecated - You must use elementData. If VpeElementData has not
+ * necessary functionality you must extend its
+ */
public Object getData() {
return data;
}
@@ -84,4 +110,20 @@
}
return false;
}
+
+ /**
+ * get element data
+ * @return
+ */
+ public VpeElementData getElementData() {
+ return elementData;
+ }
+
+ /**
+ * get element data
+ * @param elementData
+ */
+ public void setElementData(VpeElementData elementData) {
+ this.elementData = elementData;
+ }
}
Modified:
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -15,32 +15,37 @@
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
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.VpeAttributeData;
+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.selection.VpeSelectionController;
+import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
import org.jboss.tools.vpe.editor.util.TextUtil;
+import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMKeyEvent;
import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsIDOMText;
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 {@link VpeTemplateKeyEventHandler}. In result of
- * work handleKeyPress() call one from handle* methods.
+ * 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 {@link VpeTemplateNodesManager}.
+ * Default implementation of ITemplateNodesManager.
*
* @author Sergey Dzmitrovich
*
*/
public abstract class EditableTemplateAdapter extends VpeAbstractTemplate
- implements VpeTemplateKeyEventHandler, VpeTemplateNodesManager {
+ implements ITemplateKeyEventHandler, ITemplateNodesManager,
+ ITemplateSelectionManager {
/**
* name of "view" tag
@@ -141,8 +146,7 @@
nsIDOMKeyEvent keyEvent) {
// get selection
- nsISelection selection = pageContext.getEditPart().getController()
- .getXulRunnerEditor().getSelection();
+ nsISelection selection = getCurrentSelection(pageContext);
// get visual node which is focused
nsIDOMNode visualNode = selection.getFocusNode();
@@ -150,17 +154,17 @@
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
- if (elementMapping == null || elementMapping.getData() == null) {
+ if (elementMapping == null || elementMapping.getElementData() == null) {
return false;
}
- Object data = elementMapping.getData();
+ VpeElementData elementData = elementMapping.getElementData();
// if node editable
- if (isNodeEditable(pageContext, visualNode, data)) {
+ if (isNodeEditable(pageContext, visualNode, elementData)) {
// get source node
- Node node = getSourceNode(pageContext, visualNode, data);
+ Node node = getSourceNode(pageContext, visualNode, elementData);
if (node == null)
return false;
@@ -201,7 +205,7 @@
node.setNodeValue(newValue);
// set selection
- setSourceNodeSelection(pageContext, node, startOffset + 1, 0);
+ setSourceSelection(pageContext, node, startOffset + 1, 0);
}
return true;
@@ -237,8 +241,7 @@
protected boolean handleRightDelete(VpePageContext pageContext,
nsIDOMKeyEvent keyEvent) {
// get selection
- nsISelection selection = pageContext.getEditPart().getController()
- .getXulRunnerEditor().getSelection();
+ nsISelection selection = getCurrentSelection(pageContext);
// get visual node which is focused
nsIDOMNode visualNode = selection.getFocusNode();
@@ -246,17 +249,17 @@
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
- if (elementMapping == null || elementMapping.getData() == null) {
+ if (elementMapping == null || elementMapping.getElementData() == null) {
return false;
}
- Object data = elementMapping.getData();
+ VpeElementData elementData = elementMapping.getElementData();
// if node editable
- if (isNodeEditable(pageContext, visualNode, data)) {
+ if (isNodeEditable(pageContext, visualNode, elementData)) {
// get source node
- Node node = getSourceNode(pageContext, visualNode, data);
+ Node node = getSourceNode(pageContext, visualNode, elementData);
if (node == null)
return false;
@@ -301,7 +304,7 @@
node.setNodeValue(newValue);
// set new selection
- setSourceNodeSelection(pageContext, node, startOffset, 0);
+ setSourceSelection(pageContext, node, startOffset, 0);
}
@@ -323,8 +326,7 @@
nsIDOMKeyEvent keyEvent) {
// get selection
- nsISelection selection = pageContext.getEditPart().getController()
- .getXulRunnerEditor().getSelection();
+ nsISelection selection = getCurrentSelection(pageContext);
// get visual node which is focused
nsIDOMNode visualNode = selection.getFocusNode();
@@ -333,17 +335,17 @@
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
- if (elementMapping == null || elementMapping.getData() == null) {
+ if (elementMapping == null || elementMapping.getElementData() == null) {
return false;
}
- Object data = elementMapping.getData();
+ VpeElementData elementData = elementMapping.getElementData();
// if node editable
- if (isNodeEditable(pageContext, visualNode, data)) {
+ if (isNodeEditable(pageContext, visualNode, elementData)) {
// get source node
- Node node = getSourceNode(pageContext, visualNode, data);
+ Node node = getSourceNode(pageContext, visualNode, elementData);
if (node == null)
return false;
@@ -386,7 +388,7 @@
node.setNodeValue(newValue);
// set new selection
- setSourceNodeSelection(pageContext, node, startOffset, 0);
+ setSourceSelection(pageContext, node, startOffset, 0);
}
@@ -456,8 +458,7 @@
nsIDOMKeyEvent keyEvent) {
// get selection
- nsISelection selection = pageContext.getEditPart().getController()
- .getXulRunnerEditor().getSelection();
+ nsISelection selection = getCurrentSelection(pageContext);
// get visual node which is focused
nsIDOMNode visualNode = selection.getFocusNode();
@@ -465,27 +466,28 @@
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
- if (elementMapping == null || elementMapping.getData() == null) {
+ if (elementMapping == null || elementMapping.getElementData() == null) {
return false;
}
- Object data = elementMapping.getData();
+ VpeElementData elementData = elementMapping.getElementData();
- // if node editable
- if (isNodeEditable(pageContext, visualNode, data)) {
+ // get source node
+ Node node = getSourceNode(pageContext, visualNode, elementData);
- // get source node
- Node node = getSourceNode(pageContext, visualNode, data);
+ if (node == null)
+ return false;
- if (node == null)
- return false;
+ // get focus and anchor offsets
+ int focusOffset = selection.getFocusOffset();
- // get focus and anchor offsets
- int focusOffset = selection.getFocusOffset();
+ // if node editable
+ if (isNodeEditable(pageContext, visualNode, elementData)) {
if (focusOffset != node.getNodeValue().length()) {
- setSourceNodeSelection(pageContext, node, focusOffset + 1, 0);
- }
+ setSourceSelection(pageContext, node, focusOffset + 1, 0);
+ } else
+ setSourceSelection(pageContext, node, focusOffset, 0);
}
return true;
@@ -522,8 +524,7 @@
nsIDOMKeyEvent keyEvent) {
// get selection
- nsISelection selection = pageContext.getEditPart().getController()
- .getXulRunnerEditor().getSelection();
+ nsISelection selection = getCurrentSelection(pageContext);
// get visual node which is focused
nsIDOMNode visualNode = selection.getFocusNode();
@@ -531,17 +532,17 @@
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
- if (elementMapping == null || elementMapping.getData() == null) {
+ if (elementMapping == null || elementMapping.getElementData() == null) {
return false;
}
- Object data = elementMapping.getData();
+ VpeElementData elementData = elementMapping.getElementData();
// if node editable
- if (isNodeEditable(pageContext, visualNode, data)) {
+ if (isNodeEditable(pageContext, visualNode, elementData)) {
// get source node
- Node node = getSourceNode(pageContext, visualNode, data);
+ Node node = getSourceNode(pageContext, visualNode, elementData);
if (node == null)
return false;
@@ -550,7 +551,7 @@
int focusOffset = selection.getFocusOffset();
if (focusOffset != 0) {
- setSourceNodeSelection(pageContext, node, focusOffset - 1, 0);
+ setSourceSelection(pageContext, node, focusOffset - 1, 0);
}
}
return true;
@@ -569,7 +570,7 @@
*/
protected boolean handleEnter(VpePageContext pageContext,
nsIDOMKeyEvent keyEvent) {
- return false;
+ return true;
}
/*
@@ -577,63 +578,98 @@
*
* @see
org.jboss.tools.vpe.editor.template.VpeTemplateNodesManager#getSourceNode(org.jboss.tools.vpe.editor.context.VpePageContext,
* org.mozilla.interfaces.nsIDOMNode)
- */public Node getSourceNode(VpePageContext pageContext,
- nsIDOMNode visualNode, Object data) {
+ */
+ public Node getSourceNode(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementData elementData) {
- if ((data != null) && (data instanceof List)) {
+ if ((elementData != null) && (elementData.getAttributesData() != null)) {
- List<VpeNodeMapping> attributesMapping = (List<VpeNodeMapping>) data;
+ List<VpeAttributeData> attributesMapping = elementData
+ .getAttributesData();
- for (VpeNodeMapping mapping : attributesMapping) {
+ for (VpeAttributeData attributeData : attributesMapping) {
- if (mapping.getVisualNode().equals(visualNode))
- return mapping.getSourceNode();
-
+ if (attributeData.getVisualAttr().equals(visualNode))
+ return attributeData.getSourceAttr();
}
-
}
return null;
}
+ /**
+ *
+ * @param pageContext
+ * @param node
+ * @param elementData
+ * @return
+ */
public nsIDOMNode getVisualNode(VpePageContext pageContext, Node node,
- Object data) {
- if ((data != null) && (data instanceof List)) {
+ VpeElementData elementData) {
- List<VpeNodeMapping> attributesMapping = (List<VpeNodeMapping>) data;
- for (VpeNodeMapping mapping : attributesMapping) {
- if (mapping.getSourceNode().equals(node))
- return (nsIDOMText) mapping.getVisualNode();
+ if ((elementData != null) && (elementData.getAttributesData() != null)) {
+
+ List<VpeAttributeData> attributesMapping = elementData
+ .getAttributesData();
+
+ for (VpeAttributeData attributeData : attributesMapping) {
+ if (attributeData.getSourceAttr().equals(node))
+ return attributeData.getVisualAttr();
}
}
return null;
}
+ /**
+ *
+ * @param pageContext
+ * @param visualNode
+ * @param elementData
+ * @return
+ */
public boolean isNodeEditable(VpePageContext pageContext,
- nsIDOMNode visualNode, Object data) {
+ nsIDOMNode visualNode, VpeElementData elementData) {
- if ((data != null) && (data instanceof List)) {
+ if ((elementData != null) && (elementData.getAttributesData() != null)) {
- List<VpeNodeMapping> attributesMapping = (List<VpeNodeMapping>) data;
+ List<VpeAttributeData> attributesMapping = elementData
+ .getAttributesData();
- for (VpeNodeMapping mapping : attributesMapping) {
+ for (VpeAttributeData attributeData : attributesMapping) {
- if (mapping.getVisualNode().equals(visualNode))
- return true;
+ if (attributeData.getVisualAttr().equals(visualNode))
+ return attributeData.isEditable();
}
}
return false;
}
- /*
- * (non-Javadoc)
+ public boolean isNodeEditable(VpePageContext pageContext, Node node,
+ VpeElementData elementData) {
+ if ((elementData != null) && (elementData.getAttributesData() != null)) {
+
+ List<VpeAttributeData> attributesMapping = elementData
+ .getAttributesData();
+
+ for (VpeAttributeData attributeData : attributesMapping) {
+
+ if (attributeData.getSourceAttr().equals(node))
+ return attributeData.isEditable();
+ }
+ }
+ return false;
+ }
+
+ /**
*
- * @see
org.jboss.tools.vpe.editor.template.VpeTemplateNodesManager#setSourceNodeSelection(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.w3c.dom.Node, int, int)
+ * @param pageContext
+ * @param node
+ * @param offset
+ * @param length
*/
- public void setSourceNodeSelection(VpePageContext pageContext, Node node,
+ protected void setSourceSelection(VpePageContext pageContext, Node node,
int offset, int length) {
- int start = getStartOffsetNode(node) + 1;
+ int start = getStartOffsetNode(node) ;
pageContext.getSourceBuilder().getStructuredTextViewer()
.setSelectedRange(start + offset, length);
@@ -645,20 +681,122 @@
/*
* (non-Javadoc)
*
+ * @see
org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setSelection(org.jboss.tools.vpe.editor.context.VpePageContext,
+ * org.mozilla.interfaces.nsISelection)
+ */
+ public void setSelection(VpePageContext pageContext, nsISelection selection) {
+
+ nsIDOMNode focusedVisualNode = selection.getFocusNode();
+
+ VpeElementMapping elementMapping = pageContext.getDomMapping()
+ .getNearElementMapping(focusedVisualNode);
+
+ int focusOffset = selection.getFocusOffset();
+ int anchorOffset = selection.getAnchorOffset();
+
+ boolean isEditable = isNodeEditable(pageContext, focusedVisualNode,
+ elementMapping.getElementData());
+
+ Node focusedSourceNode = getSourceNode(pageContext, focusedVisualNode,
+ elementMapping.getElementData());
+
+ if (focusedSourceNode == null)
+ focusedSourceNode = elementMapping.getSourceNode();
+ if (isEditable)
+ setSourceSelection(pageContext, focusedSourceNode, focusOffset,
+ anchorOffset - focusOffset);
+ else
+ setSourceSelection(pageContext, focusedSourceNode, 0,
+ getLengthNode(focusedSourceNode));
+
+ if (focusedVisualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE)
+ focusedVisualNode = focusedVisualNode.getParentNode();
+
+ pageContext.getVisualBuilder().setSelectionRectangle(
+ (nsIDOMElement) focusedVisualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setVisualSelectionBySource(org.jboss.tools.vpe.editor.context.VpePageContext,
+ * int, int)
+ */
+ public void setVisualSelectionBySource(VpePageContext pageContext,
+ VpeSelectionController selectionController, int focus, int anchor) {
+
+ // get source node
+ Node sourceNode = TemplateManagingUtil.getSourceNodeByPosition(
+ pageContext, focus);
+
+ // get element mapping
+ VpeElementMapping elementMapping = pageContext.getDomMapping()
+ .getNearElementMapping(sourceNode);
+
+ // get focused attribute
+ Node focusNode = getFocusedNode(sourceNode, elementMapping
+ .getElementData(), focus);
+
+ Node anchorNode = getFocusedNode(sourceNode, elementMapping
+ .getElementData(), anchor);
+
+ int visualFocus = 0;
+ int visualAnchor = 0;
+ nsIDOMNode visualNode = null;
+ nsIDOMNode visualParent = null;
+ if (focusNode == anchorNode) {
+
+ visualNode = getVisualNode(pageContext, focusNode, elementMapping
+ .getElementData());
+ if (visualNode != null) {
+ visualParent = (nsIDOMNode) visualNode.getParentNode()
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ String text = focusNode.getNodeValue();
+ int start = getStartOffsetNode(focusNode);
+ focus = focus - start;
+ anchor = anchor - start;
+ visualFocus = TextUtil.visualInnerPosition(text, focus);
+ visualAnchor = TextUtil.visualInnerPosition(text, anchor);
+ }
+
+ }
+
+ if (visualNode == null) {
+ visualParent = visualNode = elementMapping.getVisualNode();
+
+ }
+ nsISelection selection = selectionController
+ .getSelection(nsISelectionController.SELECTION_NORMAL);
+
+ selection.collapse(visualNode, visualFocus);
+
+ // selection.extend(visualNode, visualAnchor - visualFocus);
+ pageContext.getVisualBuilder().setSelectionRectangle(
+ (nsIDOMElement) visualParent);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see
org.jboss.tools.vpe.editor.template.VpeTemplateNodesManager#getFocusedNode(org.w3c.dom.Node,
* int)
*/
- public Node getFocusedNode(Node sourceNode, int offset, Object data) {
+ public Node getFocusedNode(Node sourceNode, VpeElementData elementData,
+ int offset) {
- if ((data != null) && (data instanceof List)) {
+ if ((elementData != null) && (elementData.getAttributesData() != null)) {
- List<VpeNodeMapping> attributesMapping = (List<VpeNodeMapping>) data;
+ List<VpeAttributeData> attributesMapping = elementData
+ .getAttributesData();
- for (VpeNodeMapping mapping : attributesMapping) {
+ for (VpeAttributeData attributeData : attributesMapping) {
- if ((offset > (getStartOffsetNode(mapping.getSourceNode()) + 1))
- && (offset < (getEndOffsetNode(mapping.getSourceNode()) - 1)))
- return mapping.getSourceNode();
+ if ((offset > (getStartOffsetNode(attributeData.getSourceAttr())))
+ && (offset < (getEndOffsetNode(attributeData
+ .getSourceAttr()))))
+ return attributeData.getSourceAttr();
}
}
@@ -671,10 +809,10 @@
* @param node
* @return
*/
- private int getStartOffsetNode(Node node) {
+ protected int getStartOffsetNode(Node node) {
if (node instanceof IDOMAttr) {
- return ((IDOMAttr) node).getValueRegionStartOffset();
+ return ((IDOMAttr) node).getValueRegionStartOffset()+1;
} else if (node instanceof IndexedRegion) {
return ((IndexedRegion) node).getStartOffset();
}
@@ -682,12 +820,28 @@
}
/**
+ *
+ * @param node
+ * @return
+ */
+ protected int getLengthNode(Node node) {
+
+ if (node instanceof IDOMAttr) {
+ return ((IDOMAttr) node).getValueSource().length();
+ } else if (node instanceof IndexedRegion) {
+ return ((IndexedRegion) node).getStartOffset()
+ - ((IndexedRegion) node).getEndOffset();
+ }
+ return 0;
+ }
+
+ /**
* get end offset of node
*
* @param node
* @return
*/
- private int getEndOffsetNode(Node node) {
+ protected int getEndOffsetNode(Node node) {
if (node instanceof IndexedRegion) {
return ((IndexedRegion) node).getEndOffset();
@@ -695,10 +849,13 @@
return 0;
}
+ /**
+ *
+ */
public boolean openBundle(VpePageContext pageContext,
- nsIDOMNode visualNode, Object data) {
+ nsIDOMNode visualNode, VpeElementData elementData) {
- Node node = getSourceNode(pageContext, visualNode, data);
+ Node node = getSourceNode(pageContext, visualNode, elementData);
// so as nsIDOMMouseEvent doesn't give simple selected nsIDOMText as
// target, but nsiSelection can give simple "text"
@@ -712,7 +869,7 @@
// get visual node which is focused
nsIDOMNode tempNode = selection.getFocusNode();
- node = getSourceNode(pageContext, tempNode, data);
+ node = getSourceNode(pageContext, tempNode, elementData);
}
@@ -750,10 +907,21 @@
}
- private VpeElementMapping getElmentMapping(VpePageContext pageContext,
+ /**
+ *
+ * @param pageContext
+ * @param node
+ * @return
+ */
+ protected VpeElementMapping getElmentMapping(VpePageContext pageContext,
nsIDOMNode node) {
return pageContext.getDomMapping().getNearElementMapping(node);
}
+
+ protected nsISelection getCurrentSelection(VpePageContext pageContext) {
+ return pageContext.getEditPart().getController().getXulRunnerEditor()
+ .getSelection();
+ }
}
Added:
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
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateKeyEventHandler.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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);
+
+}
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java
(from rev 6668,
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateNodesManager.java)
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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.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(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementData elementData);
+
+ /**
+ *
+ * @param pageContext
+ * @param node
+ * @param elementData
+ * @return
+ */
+ public boolean isNodeEditable(VpePageContext pageContext, Node node,
+ VpeElementData elementData);
+
+ /**
+ * get visual element of attribute from source element
+ *
+ * @param pageContext
+ * @param attr
+ * @param data
+ * @return
+ */
+ public nsIDOMNode getVisualNode(VpePageContext pageContext, Node node,
+ VpeElementData elementData);
+
+ /**
+ * get source element of attribute from visual element
+ *
+ * @param pageContext
+ * @param visualNode
+ * @param data
+ * @return
+ */
+ public Node getSourceNode(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementData elementData);
+
+ /**
+ * get sourceNode by offset
+ *
+ * @param sourceNode
+ * @param offset
+ * @return
+ */
+ public Node getFocusedNode(Node sourceNode, VpeElementData elementData,
+ int offset);
+
+ /**
+ * open bundle
+ *
+ * @param pageContext
+ * @param visualNod
+ * @return
+ */
+ boolean openBundle(VpePageContext pageContext, nsIDOMNode visualNode,
+ VpeElementData elementData);
+}
Added:
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
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.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 setVisualSelectionBySource(VpePageContext pageContext,
+ VpeSelectionController selectionController, int focus, int anchor);
+
+}
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -738,10 +738,14 @@
return children;
}
- boolean isModify() {
+ public boolean isModify() {
return modify;
}
+ public void setModify(boolean modify) {
+ this.modify = modify;
+ }
+
/**
* @return <code>true</code> if the element is case sensitive
*/
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreationData.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreationData.java 2008-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreationData.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -14,6 +14,7 @@
import java.util.List;
import org.jboss.tools.common.model.util.XMLUtil;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.util.VpeDebugUtil;
import org.jboss.tools.vpe.editor.util.XmlUtil;
import org.mozilla.interfaces.nsIDOMNode;
@@ -23,7 +24,13 @@
private nsIDOMNode node;
private List<VpeChildrenInfo> childrenInfoList;
private List<Node> illegalChildren;
+
+ /**
+ * @deprecated - You must use elementData. If VpeElementData has not
+ * necessary functionality you must extend its
+ */
private Object data;
+ private VpeElementData elementData;
public VpeCreationData(nsIDOMNode node) {
this.node = node;
@@ -55,15 +62,41 @@
return illegalChildren;
}
+ /**
+ * @deprecated - You must use elementData. If VpeElementData has not
+ * necessary functionality you must extend its
+ * @param data
+ */
public void setData(Object data) {
this.data = data;
}
-
+
+ /**
+ * @deprecated - You must use elementData. If VpeElementData has not
+ * necessary functionality you must extend its
+ * @return
+ */
public Object getData() {
return data;
}
/**
+ * get element data
+ * @return
+ */
+ public VpeElementData getElementData() {
+ return elementData;
+ }
+
+ /**
+ * set element data
+ * @param elementData
+ */
+ public void setElementData(VpeElementData elementData) {
+ this.elementData = elementData;
+ }
+
+ /**
* Added method for creation copy which will
* placed in cash to improve perfomance of VPE
* Added by Max Areshkau JBIDE-675.
@@ -90,6 +123,8 @@
}
data.illegalChildren =this.illegalChildren;
data.data = this.data;
+ data.elementData = this.elementData;
return data;
}
+
}
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-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -464,4 +464,9 @@
nsIDOMNode visualContainer, nsIDOMDocument visualDocument);
boolean containsText();
+
+ public boolean isModify();
+
+ public void setModify(boolean modify);
+
}
\ No newline at end of file
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateKeyEventHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateKeyEventHandler.java 2008-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateKeyEventHandler.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -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 VpeTemplateKeyEventHandler {
-
- /**
- * 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/VpeTemplateNodesManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateNodesManager.java 2008-03-07
17:06:05 UTC (rev 6788)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateNodesManager.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -1,91 +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.nsIDOMNode;
-import org.w3c.dom.Node;
-
-/**
- * Interface for editing of attributes of a template
- *
- * @author Sergey Dzmitrovich
- *
- */
-public interface VpeTemplateNodesManager {
-
- /**
- * @param pageContext -
- * context of vpe
- * @param visualNode -
- * selected visual node
- *
- * @return true if selected attribute is editable
- */
- public boolean isNodeEditable(VpePageContext pageContext,
- nsIDOMNode visualNode, Object data);
-
- /**
- * set attribute in sourceEditor
- *
- * @param pageContext -
- * context of vpe
- * @param attr -
- * attribute
- * @param focusOffset -
- * focus offset
- * @param length -
- * length of selection
- *
- */
- public void setSourceNodeSelection(VpePageContext pageContext, Node node,
- int focusOffset, int length);
-
- /**
- * get visual element of attribute from source element
- *
- * @param pageContext
- * @param attr
- * @param data
- * @return
- */
- public nsIDOMNode getVisualNode(VpePageContext pageContext, Node node,
- Object data);
-
- /**
- * get source element of attribute from visual element
- *
- * @param pageContext
- * @param visualNode
- * @param data
- * @return
- */
- public Node getSourceNode(VpePageContext pageContext,
- nsIDOMNode visualNode, Object data);
-
- /**
- * get sourceNode by offset
- *
- * @param sourceNode
- * @param offset
- * @return
- */
- public Node getFocusedNode(Node sourceNode, int offset, Object data);
-
- /**
- * open bundle
- *
- * @param pageContext
- * @param visualNod
- * @return
- */
- boolean openBundle(VpePageContext pageContext, nsIDOMNode visualNode, Object data);
-}
Added:
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
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java 2008-03-07
19:03:33 UTC (rev 6789)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * 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.util;
+
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+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.VpeElementMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.template.VpeTemplate;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Node;
+
+public class TemplateManagingUtil {
+
+ /**
+ * get template of selected element
+ *
+ * @param pageContext
+ * @return
+ */
+ public static VpeTemplate getTemplateByVisualSelection(
+ VpePageContext pageContext) {
+ // get element mapping
+ VpeElementMapping elementMapping = pageContext.getDomMapping()
+ .getNearElementMapping(getVisualSelectedNode(pageContext));
+
+ if (elementMapping != null)
+ return elementMapping.getTemplate();
+
+ // next code is necessary for get template some jsf elements (which have
+ // escape="false" attribute). It's necessary for the current
+ // implementation of escape="false" attribute's process.
+ // When or if the implementation of escape="false" attribute's process
+ // will changed, you will must review next code
+ VpeNodeMapping nodeMapping = pageContext.getDomMapping()
+ .getNearNodeMapping(getVisualSelectedNode(pageContext));
+
+ if (nodeMapping != null) {
+
+ // get node. This node is not ascribe (may be) to DOM model of page,
+ // because "value" attribute is parsed (if escape ="false")
+ // separately and is built in vpe. But it has correct offset
+ // information
+ IDOMNode mappingNode = (IDOMNode) nodeMapping.getSourceNode();
+
+ // get source node by ofsset
+ Node sourceNode = getSourceNodeByPosition(pageContext, mappingNode
+ .getStartOffset());
+ // find elementMapping by source node
+ if (sourceNode != null) {
+ VpeElementMapping mapping = pageContext.getDomMapping()
+ .getNearElementMapping(sourceNode);
+ if (mapping != null)
+ return mapping.getTemplate();
+ }
+
+ }
+
+ return null;
+ }
+
+ /**
+ *
+ * @param pageContext
+ * @param focus
+ * @param anchor
+ * @return
+ */
+ public static VpeTemplate getTemplateBySourceSelection(
+ VpePageContext pageContext, int focus, int anchor) {
+
+ // get source node by ofsset
+ Node focusNode = getSourceNodeByPosition(pageContext, focus);
+ // if focus node also contain anchor point (selected only 1 element)
+ if ((anchor <= ((IDOMNode) focusNode).getEndOffset())
+ && (anchor >= ((IDOMNode) focusNode).getStartOffset())) {
+
+ VpeElementMapping elementMapping = pageContext.getDomMapping()
+ .getNearElementMapping(focusNode);
+
+ if (elementMapping != null)
+ return elementMapping.getTemplate();
+
+ }
+ return null;
+
+ }
+
+ /**
+ * get source node by position
+ *
+ * @param pageContext
+ * @param position
+ * @return
+ */
+ public static Node getSourceNodeByPosition(VpePageContext pageContext,
+ int position) {
+
+ // get document
+ IDOMDocument document = (IDOMDocument) pageContext.getSourceBuilder()
+ .getSourceDocument();
+
+ // get source node by position
+ return (Node) document.getModel().getIndexedRegion(position);
+
+ }
+
+ /**
+ * get selected element
+ *
+ * @param pageContext
+ * @return
+ */
+ private static nsIDOMElement getVisualSelectedNode(
+ VpePageContext pageContext) {
+
+ return pageContext.getEditPart().getController().getXulRunnerEditor()
+ .getLastSelectedElement();
+ }
+
+}