[jbosstools-commits] JBoss Tools SVN: r9108 - in trunk: jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util and 1 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Wed Jul 9 12:29:54 EDT 2008
Author: sdzmitrovich
Date: 2008-07-09 12:29:54 -0400 (Wed, 09 Jul 2008)
New Revision: 9108
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/Constants.java
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/util/JSF.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1719
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-07-09 14:29:11 UTC (rev 9107)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOptionSelectItemTemplate.java 2008-07-09 16:29:54 UTC (rev 9108)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.jsf.template;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
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;
@@ -18,6 +19,7 @@
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.Constants;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
@@ -31,19 +33,11 @@
* @author dmaliarevich
*
*/
-public class JsfOptionSelectItemTemplate extends AbstractOutputJsfTemplate /*VpeAbstractTemplate*/ {
+public class JsfOptionSelectItemTemplate extends AbstractOutputJsfTemplate /* VpeAbstractTemplate */{
- public static final String ITEM_DISABLED = "itemDisabled";
+ public static final String EMPTY_STRING = ""; //$NON-NLS-1$
- private static final String CLASS = "class";
- private static final String ITEM_LABEL = "itemLabel";
-
- private static final String DISABLED = "disabled";
- 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;
@@ -59,8 +53,10 @@
/*
* (non-Javadoc)
*
- * @see org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMDocument)
+ * @see
+ * org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools
+ * .vpe.editor.context.VpePageContext, org.w3c.dom.Node,
+ * org.mozilla.interfaces.nsIDOMDocument)
*/
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
@@ -69,69 +65,98 @@
readAttributes(sourceNode);
Element element = (Element) sourceNode;
boolean disabledItem = ComponentUtil.string2boolean(ComponentUtil
- .getAttribute(element, ITEM_DISABLED));
+ .getAttribute(element, JSF.ATTR_ITEM_DISABLED));
nsIDOMElement option = visualDocument.createElement(HTML.TAG_OPTION);
- // nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
- // option.appendChild(span);
+
if (disabledItem)
- option.setAttribute(DISABLED, "true");
+
+ option.setAttribute(HTML.ATTR_DISABLED, Constants.TRUE);
VpeCreationData creationData = new VpeCreationData(option);
- if (attrPresents(disabled) && "true".equalsIgnoreCase(disabled)) {
- option.setAttribute(CLASS, disabledClass);
+ if (attrPresents(disabled) && Constants.TRUE.equalsIgnoreCase(disabled)) {
+ option.setAttribute(HTML.ATTR_CLASS, disabledClass);
} else if (attrPresents(enabledClass)) {
- option.setAttribute(CLASS, enabledClass);
+ option.setAttribute(HTML.ATTR_CLASS, enabledClass);
}
-
- processOutputAttribute(pageContext, visualDocument, element, option, creationData);
-// Attr attr = null;
-// 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
-// String itemLabel = attr.getNodeValue();
-// String bundleValue = ComponentUtil.getBundleValue(pageContext,
-// attr);
-// nsIDOMText text;
-// // if bundleValue differ from value then will be represent
-// // bundleValue, but text will be not edit
-// if (!itemLabel.equals(bundleValue)) {
-// text = visualDocument.createTextNode(bundleValue);
-//
-// } 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(elementData,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);
-// }
-// }
-//
+ processOutputAttribute(pageContext, visualDocument, element, option,
+ creationData);
+
return creationData;
}
+ protected void processOutputAttribute(VpePageContext pageContext,
+ nsIDOMDocument visualDocument, Element sourceElement,
+ nsIDOMElement targetVisualElement, VpeCreationData creationData) {
+
+ VpeElementProxyData elementData = new VpeElementProxyData();
+
+ Attr outputAttr = getOutputAttributeNode(sourceElement);
+
+ if (outputAttr != null) {
+
+ // prepare value
+ String newValue = prepareAttrValue(pageContext, sourceElement,
+ outputAttr);
+
+ // if escape then contents of value (or other attribute) is only
+ // text
+ if (!sourceElement.hasAttribute(JSF.ATTR_ESCAPE)
+ || Constants.TRUE.equalsIgnoreCase(sourceElement //$NON-NLS-1$
+ .getAttribute(JSF.ATTR_ESCAPE))) {
+
+ String value = outputAttr.getNodeValue();
+
+ nsIDOMText text;
+ // if bundleValue differ from value then will be represent
+ // bundleValue, but text will be not edit
+ boolean isEditable = value.equals(newValue);
+
+ text = visualDocument.createTextNode(newValue);
+ // add attribute for ability of editing
+
+ elementData.addNodeData(new AttributeData(outputAttr,
+ targetVisualElement, isEditable));
+
+ targetVisualElement.appendChild(text);
+
+ }
+ // then text can be html code
+ else {
+
+ // create info
+ VpeChildrenInfo targetVisualInfo = new VpeChildrenInfo(
+ targetVisualElement);
+
+ // get atribute's offset
+ int offset = ((IDOMAttr) outputAttr)
+ .getValueRegionStartOffset();
+
+ // reparse attribute's value
+ NodeList list = NodeProxyUtil.reparseAttributeValue(
+ elementData, newValue, offset + 1);
+
+ // add children to info
+ for (int i = 0; i < list.getLength(); i++) {
+
+ Node child = list.item(i);
+
+ // add info to creation data
+ targetVisualInfo.addSourceChild(child);
+ }
+
+ elementData.addNodeData(new AttributeData(outputAttr,
+ targetVisualElement, false));
+
+ creationData.addChildrenInfo(targetVisualInfo);
+
+ }
+
+ }
+
+ creationData.setElementData(elementData);
+ }
+
/**
* Checks is attribute presents.
*
@@ -141,7 +166,7 @@
* @return true, if successful
*/
private boolean attrPresents(String attr) {
- return ((null != attr) && (!"".equals(attr)));
+ return ((null != attr) && (!Constants.EMPTY.equals(attr)));
}
/**
@@ -155,9 +180,9 @@
return;
}
Element source = (Element) sourceNode;
- disabled = source.getAttribute(DISABLED);
- enabledClass = source.getAttribute(ENABLED_CLASS);
- disabledClass = source.getAttribute(DISABLED_CLASS);
+ disabled = source.getAttribute(HTML.ATTR_DISABLED);
+ enabledClass = source.getAttribute(JSF.ATTR_ENABLED_CLASS);
+ disabledClass = source.getAttribute(JSF.ATTR_DISABLED_CLASS);
}
/**
@@ -171,16 +196,9 @@
return;
}
Element source = (Element) sourceNode;
- escape = source.getAttribute(ESCAPE);
+ escape = source.getAttribute(JSF.ATTR_ESCAPE);
}
- /*
- * @Override public void setSourceAttributeSelection(VpePageContext
- * pageContext, Element sourceElement, int offset, int length, Object data) {
- * VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder();
- * sourceBuilder.setSelection(sourceElement, 0, 0); }
- */
-
@Override
protected Attr getOutputAttributeNode(Element element) {
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java 2008-07-09 14:29:11 UTC (rev 9107)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java 2008-07-09 16:29:54 UTC (rev 9108)
@@ -44,5 +44,7 @@
public static final String ATTR_ROWS = "rows"; //$NON-NLS-1$
public static final String ATTR_COLS = "cols"; //$NON-NLS-1$
+
+ public static final String ATTR_ITEM_DISABLED = "itemDisabled"; //$NON-NLS-1$
}
Added: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/Constants.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/Constants.java (rev 0)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/Constants.java 2008-07-09 16:29:54 UTC (rev 9108)
@@ -0,0 +1,9 @@
+package org.jboss.tools.vpe.editor.util;
+
+public class Constants {
+
+ public static final String TRUE = "true"; //$NON-NLS-1$
+ public static final String FALSE = "false"; //$NON-NLS-1$
+ public static final String EMPTY = ""; //$NON-NLS-1$
+
+}
More information about the jbosstools-commits
mailing list