Author: dmaliarevich
Date: 2008-02-28 07:22:22 -0500 (Thu, 28 Feb 2008)
New Revision: 6637
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.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/JsfRadioSelectItemTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
Log:
http://jira.jboss.com/jira/browse/JBIDE-1719, <f:selectItem> Attribute
"escape" doesn't work
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java 2008-02-28
12:02:59 UTC (rev 6636)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java 2008-02-28
12:22:22 UTC (rev 6637)
@@ -10,16 +10,22 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.jsf.template;
+import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
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;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMText;
+import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* @author dmaliarevich
@@ -39,6 +45,11 @@
private static final String ENABLED_CLASS = "enabledClass";
private static final String DISABLED_CLASS = "disabledClass";
+
+ /* "escape" attribute of f:selectItem */
+ private static final String ESCAPE = "escape";
+
+ private String escape;
private String disabled;
private String enabledClass;
private String disabledClass;
@@ -54,13 +65,17 @@
*/
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
-
- readAttributes(sourceNode.getParentNode());
-
+
+ readParentAttributes(sourceNode.getParentNode());
+ readAttributes(sourceNode);
+
+ Element element = (Element) sourceNode;
+
nsIDOMElement input = visualDocument.createElement(HTML.TAG_INPUT);
nsIDOMElement label = visualDocument.createElement(HTML.TAG_LABEL);
// create span element
nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
+ nsIDOMElement labelSpan = visualDocument.createElement(HTML.TAG_SPAN);
VpeCreationData creationData = new VpeCreationData(span);
@@ -76,12 +91,35 @@
label.setAttribute(CLASS, enabledClass);
}
- String itemLabel = getLabel(sourceNode);
- label.appendChild(visualDocument.createTextNode(itemLabel));
-
+ label.appendChild(labelSpan);
span.appendChild(input);
span.appendChild(label);
+
+ Attr attr = null;
+ if (element.hasAttribute(ITEM_LABEL)) {
+ attr = element.getAttributeNode(ITEM_LABEL);
+ }
+ if (null != attr) {
+ if (null == escape || "true".equalsIgnoreCase(escape)) {
+ // show text as is
+ String itemLabel = attr.getNodeValue();
+ labelSpan.appendChild(visualDocument.createTextNode(itemLabel));
+ } else {
+ // show formatted text
+ VpeChildrenInfo labelSpanInfo = new VpeChildrenInfo(labelSpan);
+ // re-parse attribute's value
+ NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
+ // add children to info
+ for (int i = 0; i < list.getLength(); i++) {
+ Node child = list.item(i);
+ // add info to creation data
+ labelSpanInfo.addSourceChild(child);
+ }
+ creationData.addChildrenInfo(labelSpanInfo);
+ }
+ }
+
return creationData;
}
@@ -120,19 +158,18 @@
}
/**
- * get Label of element
+ * Read attributes from the h:SelectManyCheckbox element.
*
- * @param sourceNode
- * @return
+ * @param sourceNode the source node
*/
- private String getLabel(Node sourceNode) {
- // get value of "itemLabeL" from jsf tag
- Node attrNode = sourceNode.getAttributes().getNamedItem(ITEM_LABEL);
- // if attribute exist return value
- if (attrNode != null) {
- return attrNode.getNodeValue();
+ private void readParentAttributes(Node sourceNode) {
+ if (null == sourceNode) {
+ return;
}
- return "";
+ Element source = (Element) sourceNode;
+ disabled = source.getAttribute(DISABLED);
+ enabledClass = source.getAttribute(ENABLED_CLASS);
+ disabledClass = source.getAttribute(DISABLED_CLASS);
}
/**
@@ -145,9 +182,7 @@
return;
}
Element source = (Element) sourceNode;
- disabled = source.getAttribute(DISABLED);
- enabledClass = source.getAttribute(ENABLED_CLASS);
- disabledClass = source.getAttribute(DISABLED_CLASS);
+ escape = source.getAttribute(ESCAPE);
}
@Override
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-02-28
12:02:59 UTC (rev 6636)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOptionSelectItemTemplate.java 2008-02-28
12:22:22 UTC (rev 6637)
@@ -10,15 +10,19 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.jsf.template;
+import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
import org.jboss.tools.vpe.editor.context.VpePageContext;
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;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* @author dmaliarevich
@@ -33,6 +37,10 @@
private static final String ENABLED_CLASS = "enabledClass";
private static final String DISABLED_CLASS = "disabledClass";
+ /* "escape" attribute of f:selectItem */
+ private static final String ESCAPE = "escape";
+
+ private String escape;
private String disabled;
private String enabledClass;
private String disabledClass;
@@ -49,9 +57,14 @@
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
- readAttributes(sourceNode.getParentNode());
-
+ readParentAttributes(sourceNode.getParentNode());
+ readAttributes(sourceNode);
+ Element element = (Element) sourceNode;
+
nsIDOMElement option = visualDocument.createElement(HTML.TAG_OPTION);
+ nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
+ option.appendChild(span);
+
VpeCreationData creationData = new VpeCreationData(option);
if (attrPresents(disabled) && "true".equalsIgnoreCase(disabled)) {
@@ -59,30 +72,36 @@
} else if (attrPresents(enabledClass)) {
option.setAttribute(CLASS, enabledClass);
}
+
+ Attr attr = null;
+ if (element.hasAttribute(ITEM_LABEL)) {
+ attr = element.getAttributeNode(ITEM_LABEL);
+ }
+
+ if (null != attr) {
+ if (null == escape || "true".equalsIgnoreCase(escape)) {
+ // show text as is
+ String itemLabel = attr.getNodeValue();
+ span.appendChild(visualDocument.createTextNode(itemLabel));
+ } else {
+ // show formatted text
+ VpeChildrenInfo spanInfo = new VpeChildrenInfo(span);
+ // re-parse attribute's value
+ NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
+ // add children to info
+ for (int i = 0; i < list.getLength(); i++) {
+ Node child = list.item(i);
+ // add info to creation data
+ spanInfo.addSourceChild(child);
+ }
+ creationData.addChildrenInfo(spanInfo);
+ }
+ }
- String itemLabel = getLabel(sourceNode);
- option.appendChild(visualDocument.createTextNode(itemLabel));
-
return creationData;
}
/**
- * get Label of element
- *
- * @param sourceNode
- * @return
- */
- private String getLabel(Node sourceNode) {
- // get value of "itemLabeL" from jsf tag
- Node attrNode = sourceNode.getAttributes().getNamedItem(ITEM_LABEL);
- // if attribute exist return value
- if (attrNode != null) {
- return attrNode.getNodeValue();
- }
- return "";
- }
-
- /**
* Checks is attribute presents.
*
* @param attr the attribute
@@ -94,11 +113,11 @@
}
/**
- * Read attributes from the source element.
+ * Read attributes from the h:SelectManyCheckbox element.
*
* @param sourceNode the source node
*/
- private void readAttributes(Node sourceNode) {
+ private void readParentAttributes(Node sourceNode) {
if (null == sourceNode) {
return;
}
@@ -108,6 +127,19 @@
disabledClass = source.getAttribute(DISABLED_CLASS);
}
+ /**
+ * Read attributes from the source element.
+ *
+ * @param sourceNode the source node
+ */
+ private void readAttributes(Node sourceNode) {
+ if (null == sourceNode) {
+ return;
+ }
+ Element source = (Element) sourceNode;
+ escape = source.getAttribute(ESCAPE);
+ }
+
@Override
public void setSourceAttributeSelection(VpePageContext pageContext,
Element sourceElement, int offset, int length, Object data) {
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfRadioSelectItemTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfRadioSelectItemTemplate.java 2008-02-28
12:02:59 UTC (rev 6636)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfRadioSelectItemTemplate.java 2008-02-28
12:22:22 UTC (rev 6637)
@@ -11,15 +11,20 @@
package org.jboss.tools.jsf.vpe.jsf.template;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
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;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMText;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* @author sdzmitrovich
@@ -41,6 +46,14 @@
// style of span
private static final String SPAN_STYLE_VALUE = "-moz-user-modify:
read-write;"; //$NON-NLS-1$
+ /* "itemLabel" attribute of f:selectItem */
+ private static final String ITEM_LABEL = "itemLabel";
+
+ /* "escape" attribute of f:selectItem */
+ private static final String ESCAPE = "escape";
+
+ private String escape;
+
/**
*
*/
@@ -58,39 +71,55 @@
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
+ Element element = (Element) sourceNode;
+
// create span element
nsIDOMElement span = visualDocument.createElement(HTML.TAG_TABLE);
// add title attribute to span
span.setAttribute(HTML.ATTR_TITLE, getTitle(sourceNode));
+ nsIDOMElement radio = visualDocument.createElement(HTML.TAG_INPUT);
+ nsIDOMElement labelSpan = visualDocument.createElement(HTML.TAG_SPAN);
+ span.appendChild(radio);
+ span.appendChild(labelSpan);
+
+ VpeCreationData creationData = new VpeCreationData(span);
+
+ // set attributes
span.setAttribute(HTML.ATTR_STYLE, SPAN_STYLE_VALUE);
-
- // create radio element
- nsIDOMElement radio = visualDocument.createElement(HTML.TAG_INPUT);
radio.setAttribute(HTML.ATTR_TYPE, ATTR_TYPE_VALUE);
-
- // set title
radio.setAttribute(HTML.ATTR_TITLE, getTitle(sourceNode));
-
- // set name
radio.setAttribute(HTML.ATTR_NAME, ATTR_NAME_VALUE
+ getNameSuffix(sourceNode));
- // add radio to span
- span.appendChild(radio);
+ Attr attr = null;
+ if (element.hasAttribute(ITEM_LABEL)) {
+ attr = element.getAttributeNode(ITEM_LABEL);
+ }
- // get label for element
- String label = getLabel(sourceNode);
+ if (null != element) {
+ escape = element.getAttribute(ESCAPE);
+ }
- // label exist
- if (null != label) {
- // add label to span
- nsIDOMElement labelElement = visualDocument.createElement(HTML.TAG_LABEL);
- nsIDOMText text = visualDocument.createTextNode(label);
- span.appendChild(labelElement);
- labelElement.appendChild(text);
+ if (null != attr) {
+ if (null == escape || "true".equalsIgnoreCase(escape)) {
+ // show text as is
+ String itemLabel = attr.getNodeValue();
+ labelSpan.appendChild(visualDocument.createTextNode(itemLabel));
+ } else {
+ // show formatted text
+ VpeChildrenInfo labelSpanInfo = new VpeChildrenInfo(labelSpan);
+ // re-parse attribute's value
+ NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
+ // add children to info
+ for (int i = 0; i < list.getLength(); i++) {
+ Node child = list.item(i);
+ // add info to creation data
+ labelSpanInfo.addSourceChild(child);
+ }
+ creationData.addChildrenInfo(labelSpanInfo);
+ }
}
-
- return new VpeCreationData(span);
+ return creationData;
}
/**
@@ -160,5 +189,16 @@
return name_suffix;
}
+
+ /**
+ * Checks is attribute presents.
+ *
+ * @param attr the attribute
+ *
+ * @return true, if successful
+ */
+ private boolean attrPresents(String attr) {
+ return ((null != attr) && (!"".equals(attr)));
+ }
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2008-02-28
12:02:59 UTC (rev 6636)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2008-02-28
12:22:22 UTC (rev 6637)
@@ -745,44 +745,49 @@
</vpe:tag>
<vpe:tag name="f:selectItem" case-sensitive="yes">
- <vpe:if test="hasinparents('h:selectManyCheckbox')">
- <vpe:template children="no" modify="yes"
+ <vpe:if test="hasinparents('h:selectManyCheckbox')">
+ <vpe:template children="yes" modify="yes"
class="org.jboss.tools.jsf.vpe.jsf.template.JsfCheckboxSelectItemTemplate">
- </vpe:template>
- </vpe:if>
- <vpe:if
test="hasinparents('h:selectManyListbox')|hasinparents('h:selectManyMenu')">
- <vpe:template children="no" modify="yes"
-
class="org.jboss.tools.jsf.vpe.jsf.template.JsfOptionSelectItemTemplate">
- </vpe:template>
- </vpe:if>
- <vpe:if
test="hasinparents('x:selectManyCheckbox')|hasinparents('t:selectManyCheckbox')">
- <vpe:template children="no" modify="yes">
- <span title="{tagstring()}">
- <input type="checkbox" />
- <vpe:value expr="{jsfvalue(@itemLabel)}"/>
- </span>
- <vpe:dnd>
- <vpe:drag start-enable="yes"/>
- </vpe:dnd>
- <vpe:breaker type="selectItem"/>
- </vpe:template>
- </vpe:if>
- <vpe:if
test="hasinparents('h:selectOneRadio')|hasinparents('x:selectOneRadio')">
- <vpe:template children="no" modify="yes"
class="org.jboss.tools.jsf.vpe.jsf.template.JsfRadioSelectItemTemplate">
-
- </vpe:template>
- </vpe:if>
- <vpe:if test="hasinparents('h:selectOneListbox')|
+ </vpe:template>
+ </vpe:if>
+ <vpe:if
+
test="hasinparents('h:selectManyListbox')|hasinparents('h:selectManyMenu')">
+ <vpe:template children="yes" modify="yes"
+
class="org.jboss.tools.jsf.vpe.jsf.template.JsfOptionSelectItemTemplate">
+ </vpe:template>
+ </vpe:if>
+ <vpe:if
+
test="hasinparents('h:selectOneRadio')|hasinparents('x:selectOneRadio')">
+ <vpe:template children="yes" modify="yes"
+
class="org.jboss.tools.jsf.vpe.jsf.template.JsfRadioSelectItemTemplate">
+ </vpe:template>
+ </vpe:if>
+ <vpe:if
+
test="hasinparents('x:selectManyCheckbox')|hasinparents('t:selectManyCheckbox')">
+ <vpe:template children="no" modify="yes">
+ <span title="{tagstring()}">
+ <input type="checkbox" />
+ <vpe:value expr="{jsfvalue(@itemLabel)}" />
+ </span>
+ <vpe:dnd>
+ <vpe:drag start-enable="yes" />
+ </vpe:dnd>
+ <vpe:breaker type="selectItem" />
+ </vpe:template>
+ </vpe:if>
+ <vpe:if
+ test="hasinparents('h:selectOneListbox')|
hasinparents('h:selectOneMenu')|
hasinparents('t:selectManyMenu')|
hasinparents('x:selectOneRadio')|
- hasinparents('x:selectOneMenu')"> <!-- Gavr --><!--
added x: 8.02.05 -->
- <vpe:template children="no" modify="yes">
- <option value="{@itemValue}" title="{tagstring()}">
- <vpe:value expr="{jsfvalue(@itemLabel)}"/>
- </option>
- </vpe:template>
- </vpe:if>
+ hasinparents('x:selectOneMenu')">
+<!-- Gavr --><!-- added x: 8.02.05 -->
+ <vpe:template children="no" modify="yes">
+ <option value="{@itemValue}" title="{tagstring()}">
+ <vpe:value expr="{jsfvalue(@itemLabel)}" />
+ </option>
+ </vpe:template>
+ </vpe:if>
</vpe:tag>
<vpe:tag name="f:selectItems" case-sensitive="yes">