Author: dsakovich
Date: 2008-02-27 05:43:07 -0500 (Wed, 27 Feb 2008)
New Revision: 6591
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneMenuTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneRadioTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/ComponentUtil.java
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/JsfSelectOneListbox.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1720
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-27
07:06:46 UTC (rev 6590)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfRadioSelectItemTemplate.java 2008-02-27
10:43:07 UTC (rev 6591)
@@ -59,7 +59,7 @@
nsIDOMDocument visualDocument) {
// create span element
- nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
+ nsIDOMElement span = visualDocument.createElement(HTML.TAG_TABLE);
// add title attribute to span
span.setAttribute(HTML.ATTR_TITLE, getTitle(sourceNode));
span.setAttribute(HTML.ATTR_STYLE, SPAN_STYLE_VALUE);
@@ -84,8 +84,10 @@
// label exist
if (null != label) {
// add label to span
+ nsIDOMElement labelElement = visualDocument.createElement(HTML.TAG_LABEL);
nsIDOMText text = visualDocument.createTextNode(label);
- span.appendChild(text);
+ span.appendChild(labelElement);
+ labelElement.appendChild(text);
}
return new VpeCreationData(span);
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneListbox.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneListbox.java 2008-02-27
07:06:46 UTC (rev 6590)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneListbox.java 2008-02-27
10:43:07 UTC (rev 6591)
@@ -1,18 +1,22 @@
/*******************************************************************************
-* 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
-******************************************************************************/
+ * 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.jsf.vpe.jsf.template;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
@@ -20,6 +24,8 @@
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
+import org.mozilla.xpcom.XPCOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -37,6 +43,9 @@
*/
private static final String ATTR_SIZE = "size"; //$NON-NLS-1$
+ private static final String ATTR_DISABLED_CLASS = "disabledClass";
+ private static final String ATTR_ENABLED_CLASS = "enabledClass";
+
/**
* list of visible children
*/
@@ -50,11 +59,13 @@
/**
* list of copied attributes
*/
- private static List<String> ATTR_LIST_COPY = new ArrayList<String>();
+ private static Map<String, String> ATTR_LIST_COPY = new HashMap<String,
String>();
static {
- ATTR_LIST_COPY.add("style"); //$NON-NLS-1$
- ATTR_LIST_COPY.add("styleClass"); //$NON-NLS-1$
+ ATTR_LIST_COPY.put("style", "style"); //$NON-NLS-1$
+ ATTR_LIST_COPY.put("styleClass", "class"); //$NON-NLS-1$
+ ATTR_LIST_COPY.put("disabled", "disabled"); //$NON-NLS-1$
+ ATTR_LIST_COPY.put("dir", "dir"); //$NON-NLS-1$
}
/**
@@ -80,14 +91,24 @@
Element element = (Element) sourceNode;
// import attributes from source
- for (String attributeName : ATTR_LIST_COPY) {
+ Set<String> jsfAttributes = ATTR_LIST_COPY.keySet();
+ for (String attributeName : jsfAttributes) {
+
// get attribute
String attr = element.getAttribute(attributeName);
// add attribute to "select"
- if (attr != null)
- select.setAttribute(HTML.ATTR_STYLE, attr);
+ if (attr != null) {
+ if (attributeName.equalsIgnoreCase(HTML.ATTR_DISABLED)) {
+ if (attr.equalsIgnoreCase("true")) {
+ select.setAttribute(ATTR_LIST_COPY.get(attributeName),
+ "disabled");
+ }
+ continue;
+ }
+ select.setAttribute(ATTR_LIST_COPY.get(attributeName), attr);
+ }
}
@@ -144,4 +165,35 @@
// remove attribute
select.removeAttribute(name);
}
+
+ @Override
+ public void validate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData data) {
+ if (data.getNode() != null) {
+ applyChildAttributes((Element) sourceNode, data.getNode());
+ }
+ }
+
+ private void applyChildAttributes(Element sourceElement, nsIDOMNode node) {
+ boolean disabled = false;
+ try {
+ nsIDOMNodeList list = node.getChildNodes();
+ nsIDOMElement element = (nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ disabled = ComponentUtil.string2boolean(ComponentUtil.getAttribute(
+ sourceElement, HTML.ATTR_DISABLED));
+ if (node.getNodeName().equalsIgnoreCase(HTML.TAG_OPTION)) {
+ element.setAttribute(HTML.ATTR_CLASS, disabled ? ComponentUtil
+ .getAttribute(sourceElement, ATTR_DISABLED_CLASS)
+ : ComponentUtil.getAttribute(sourceElement,
+ ATTR_ENABLED_CLASS));
+ }
+ for (int i = 0; i < list.getLength(); i++) {
+ applyChildAttributes(sourceElement, list.item(i));
+ }
+ } catch (XPCOMException e) {
+ // Ignore
+ return;
+ }
+ }
}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneMenuTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneMenuTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneMenuTemplate.java 2008-02-27
10:43:07 UTC (rev 6591)
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * 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.jsf.vpe.jsf.template;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+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.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
+import org.mozilla.xpcom.XPCOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author Dzmitry Sakovich (dsakovich(a)exadel.com)
+ *
+ * template for selectOneMenu select item
+ *
+ */
+public class JsfSelectOneMenuTemplate extends VpeAbstractTemplate {
+
+ /**
+ * "size" attribute
+ */
+
+ private static final String ATTR_DISABLED_CLASS = "disabledClass";
+ private static final String ATTR_ENABLED_CLASS = "enabledClass";
+
+ /**
+ * list of visible children
+ */
+ private static List<String> CHILDREN_LIST = new ArrayList<String>();
+
+ static {
+ CHILDREN_LIST.add("selectItem"); //$NON-NLS-1$
+ CHILDREN_LIST.add("selectItems"); //$NON-NLS-1$
+ }
+
+ /**
+ * list of copied attributes
+ */
+ private static Map<String, String> ATTR_LIST_COPY = new HashMap<String,
String>();
+
+ static {
+ ATTR_LIST_COPY.put("style", "style"); //$NON-NLS-1$
+ ATTR_LIST_COPY.put("styleClass", "class"); //$NON-NLS-1$
+ ATTR_LIST_COPY.put("disabled", "disabled"); //$NON-NLS-1$
+ ATTR_LIST_COPY.put("dir", "dir"); //$NON-NLS-1$
+
+ }
+
+ /**
+ *
+ */
+ public JsfSelectOneMenuTemplate() {
+
+ // TODO Auto-generated constructor stub
+ }
+
+ /*
+ * (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)
+ */
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+
+ // create select element
+ nsIDOMElement select = visualDocument.createElement(HTML.TAG_SELECT);
+ select.setAttribute(HTML.ATTR_SIZE, "1");
+ Element element = (Element) sourceNode;
+
+ // import attributes from source
+ Set<String> jsfAttributes = ATTR_LIST_COPY.keySet();
+
+ for (String attributeName : jsfAttributes) {
+
+ // get attribute
+ String attr = element.getAttribute(attributeName);
+
+ // add attribute to "select"
+ if (attr != null) {
+ if (attributeName.equalsIgnoreCase(HTML.ATTR_DISABLED)) {
+ if (attr.equalsIgnoreCase("true")) {
+ select.setAttribute(ATTR_LIST_COPY.get(attributeName),
+ "disabled");
+
+ }
+ continue;
+ }
+ select.setAttribute(ATTR_LIST_COPY.get(attributeName), attr);
+ }
+
+ }
+
+ return new VpeCreationData(select);
+ }
+
+ /**
+ *
+ */
+ public void removeAttribute(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMNode visualNode, Object data, String name) {
+
+ // get DOMElement(root element is select)
+ nsIDOMElement select = (nsIDOMElement) visualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+
+ // remove attribute
+ select.removeAttribute(name);
+ }
+
+ @Override
+ public void validate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData data) {
+ if (data.getNode() != null) {
+ applyChildAttributes((Element) sourceNode, data.getNode());
+ }
+ }
+
+ private void applyChildAttributes(Element sourceElement, nsIDOMNode node) {
+ boolean disabled = false;
+ try {
+ nsIDOMNodeList list = node.getChildNodes();
+ nsIDOMElement element = (nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ disabled = ComponentUtil.string2boolean(ComponentUtil.getAttribute(
+ sourceElement, HTML.ATTR_DISABLED));
+ if (node.getNodeName().equalsIgnoreCase(HTML.TAG_OPTION)) {
+ element.setAttribute(HTML.ATTR_CLASS, disabled ? ComponentUtil
+ .getAttribute(sourceElement, ATTR_DISABLED_CLASS)
+ : ComponentUtil.getAttribute(sourceElement,
+ ATTR_ENABLED_CLASS));
+ }
+ for (int i = 0; i < list.getLength(); i++) {
+ applyChildAttributes(sourceElement, list.item(i));
+ }
+ } catch (XPCOMException e) {
+ // Ignore
+ return;
+ }
+ }
+}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneRadioTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneRadioTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectOneRadioTemplate.java 2008-02-27
10:43:07 UTC (rev 6591)
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.jsf.template;
+
+import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
+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.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
+import org.mozilla.xpcom.XPCOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Class for creating selectOneRadio template
+ *
+ * @author Dzmitry Sakovich (dsakovich(a)exadel.com)
+ *
+ */
+
+public class JsfSelectOneRadioTemplate extends VpeAbstractTemplate {
+
+ private static final String VAL_PAGE_DIRECTION = "pageDirection";
+ private static final String ATTR_LAYOUT = "layout";
+ private static final String ATTR_BORDER = "border";
+ private static final String ATTR_DISABLED_CLASS = "disabledClass";
+ private static final String ATTR_ENABLED_CLASS = "enabledClass";
+ private static final String ATTR_STYLE_CLASS = "styleClass";
+
+ private static final String ATTR_DIR_RIGHT_TO_LEFT = "rtl";
+ private static final String ATTR_DIR_LEFT_TO_RIGHT = "ltr";
+ private static final String ATTR_DISABLED_VALUE = "disabled";
+
+ public JsfSelectOneRadioTemplate() {
+ super();
+
+ }
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+
+ Element sourceElement = (Element) sourceNode;
+
+ boolean layoutHorizontal = true;
+
+ String layout = sourceElement.getAttribute(ATTR_LAYOUT);
+
+ layoutHorizontal = !VAL_PAGE_DIRECTION.equalsIgnoreCase(layout);
+
+ nsIDOMElement visualTable = visualDocument
+ .createElement(HTML.TAG_TABLE);
+ VpeCreationData creatorInfo = new VpeCreationData(visualTable);
+
+ visualTable.setAttribute(HTML.ATTR_CLASS, ComponentUtil.getAttribute(
+ sourceElement, ATTR_STYLE_CLASS));
+ visualTable.setAttribute(HTML.ATTR_STYLE, ComponentUtil.getAttribute(
+ sourceElement, HTML.ATTR_STYLE));
+ String border = sourceElement.getAttribute(ATTR_BORDER);
+ if (border != null)
+ visualTable.setAttribute(ATTR_BORDER, border);
+
+ NodeList children = sourceNode.getChildNodes();
+ int count = children != null ? children.getLength() : 0;
+ if (count > 0) {
+ Node[] sourceChildren = new Node[count];
+ int childrenCount = 0;
+ for (int i = 0; i < count; i++) {
+ Node node = children.item(i);
+ int type = node.getNodeType();
+ if (type == Node.ELEMENT_NODE || type == Node.TEXT_NODE
+ && node.getNodeValue().trim().length() > 0) {
+ sourceChildren[childrenCount] = node;
+ childrenCount++;
+ }
+ }
+ if (childrenCount > 0) {
+ int rowCount;
+ int rowLength;
+ int tableSize = childrenCount;
+ if (layoutHorizontal) {
+ rowCount = (childrenCount + tableSize - 1) / tableSize;
+ rowLength = tableSize;
+ } else {
+ rowCount = tableSize;
+ rowLength = (childrenCount + tableSize - 1) / tableSize;
+ }
+ for (int i = 0; i < rowCount; i++) {
+ nsIDOMElement visualRow = visualDocument
+ .createElement(HTML.TAG_TR);
+ for (int j = 0; j < rowLength; j++) {
+ nsIDOMElement visualCell = visualDocument
+ .createElement(HTML.TAG_TD);
+ visualRow.appendChild(visualCell);
+ int sourceIndex = layoutHorizontal ? rowLength * i + j
+ : rowCount * j + i;
+ if (sourceIndex < childrenCount) {
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(
+ visualCell);
+ childrenInfo
+ .addSourceChild(sourceChildren[sourceIndex]);
+ creatorInfo.addChildrenInfo(childrenInfo);
+ }
+ }
+ visualTable.appendChild(visualRow);
+ }
+ }
+ }
+ return creatorInfo;
+ }
+
+ @Override
+ public void validate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData data) {
+ if (data.getNode() != null) {
+ applyChildAttributes((Element) sourceNode, data.getNode());
+ }
+ }
+
+ private void applyChildAttributes(Element sourceElement, nsIDOMNode node) {
+ boolean disabled = false;
+ try {
+ nsIDOMNodeList list = node.getChildNodes();
+ nsIDOMElement element = (nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ disabled = ComponentUtil.string2boolean(ComponentUtil.getAttribute(
+ sourceElement, HTML.ATTR_DISABLED));
+ if (node.getNodeName().equalsIgnoreCase(HTML.TAG_INPUT)) {
+ element
+ .setAttribute(
+ HTML.ATTR_DIR,
+ (ComponentUtil.getAttribute(sourceElement,
+ HTML.ATTR_DIR) == ATTR_DIR_LEFT_TO_RIGHT) ? ATTR_DIR_LEFT_TO_RIGHT
+ : ATTR_DIR_RIGHT_TO_LEFT);
+ element.setAttribute(HTML.ATTR_SIZE, ComponentUtil
+ .getAttribute(sourceElement, HTML.ATTR_SIZE));
+ if (disabled)
+ element.setAttribute(HTML.ATTR_DISABLED,
+ ATTR_DISABLED_VALUE);
+
+ }
+ if (node.getNodeName().equalsIgnoreCase(HTML.TAG_LABEL)) {
+ element.setAttribute(HTML.ATTR_CLASS, disabled ? ComponentUtil
+ .getAttribute(sourceElement, ATTR_DISABLED_CLASS)
+ : ComponentUtil.getAttribute(sourceElement,
+ ATTR_ENABLED_CLASS));
+ }
+
+ if (node.getNodeName().equalsIgnoreCase(HTML.TAG_TABLE)) {
+ element.setAttribute(HTML.ATTR_STYLE, ComponentUtil
+ .getAttribute(sourceElement, HTML.ATTR_STYLE));
+ }
+
+ for (int i = 0; i < list.getLength(); i++) {
+ applyChildAttributes(sourceElement, list.item(i));
+ }
+ } catch (XPCOMException e) {
+ // Ignore
+ return;
+ }
+ }
+
+}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/ComponentUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/ComponentUtil.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/ComponentUtil.java 2008-02-27
10:43:07 UTC (rev 6591)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.jsf.template.util;
+
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Element;
+
+/**
+ * Utilities for jsf templates
+ *
+ * @author Dzmitry Sakovich (dsakovich(a)exadel.com)
+ *
+ */
+public class ComponentUtil {
+
+ /**
+ * Returns value of attribute.
+ *
+ * @param sourceElement
+ * @param attributeName
+ * @return
+ */
+ public static String getAttribute(Element sourceElement,
+ String attributeName) {
+ String attribute = sourceElement.getAttribute(attributeName);
+ if (attribute == null) {
+ attribute = "";
+ }
+ return attribute;
+ }
+
+ /**
+ * Returns value of attribute.
+ *
+ * @param sourceElement
+ * @param attributeName
+ * @return
+ */
+ public static String getAttribute(nsIDOMElement sourceElement,
+ String attributeName) {
+ String attribute = sourceElement.getAttribute(attributeName);
+ if (attribute == null) {
+ attribute = "";
+ }
+ return attribute;
+ }
+
+ /**
+ * Parses string value retrieved from sourceElement.getAttribure(..) method
+ * to its boolean value.
+ * <p>
+ * <code>false</code> is returned only if it specified explicitly,
+ * otherwise <code>true</code> is returned.
+ *
+ * @param str
+ * the string to parse
+ * @return boolean value from string
+ */
+ public static boolean string2boolean(String str) {
+ if ((str == null) || ("".equals(str))) {
+ return false;
+ } else if (("true".equalsIgnoreCase(str))
+ || ("false".equalsIgnoreCase(str))) {
+ return new Boolean(str).booleanValue();
+ }
+ return false;
+ }
+}
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-27
07:06:46 UTC (rev 6590)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2008-02-27
10:43:07 UTC (rev 6591)
@@ -561,9 +561,7 @@
</vpe:tag>
<vpe:tag name="h:selectOneRadio" case-sensitive="yes">
- <vpe:template children="yes" modify="yes">
- <vpe:grid layout="{@layout}" border="{@border}"
title="{tagstring()}"/>
- <vpe:breaker type="ignore"/>
+ <vpe:template children="yes" modify="yes"
class="org.jboss.tools.jsf.vpe.jsf.template.JsfSelectOneRadioTemplate">
<vpe:dnd>
<vpe:drag start-enable="yes"/>
<vpe:drop container="yes">
@@ -671,8 +669,8 @@
</vpe:tag>
<vpe:tag name="h:selectOneMenu" case-sensitive="yes">
- <vpe:template children="yes" modify="yes">
- <select style="{@style}" class="{@styleClass}"
title="{tagstring()}"/>
+ <vpe:template
class="org.jboss.tools.jsf.vpe.jsf.template.JsfSelectOneMenuTemplate"
+ children="yes" modify="yes">
<vpe:resize>
<vpe:width width-attr="style.width" />
<vpe:height height-attr="style.height" />
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2008-02-27
07:06:46 UTC (rev 6590)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2008-02-27
10:43:07 UTC (rev 6591)
@@ -61,12 +61,12 @@
public static final String ATTR_ID = "ID"; //$NON-NLS-1$
public static final String ATTR_TYPE = "TYPE"; //$NON-NLS-1$
public static final String ATTR_TEXT = "TEXT"; //$NON-NLS-1$
- public static final String ATTR_CLASS = "CLASS"; //$NON-NLS-1$
+ public static final String ATTR_CLASS = "class"; //$NON-NLS-1$
public static final String ATTR_TITLE = "TITLE"; //$NON-NLS-1$
public static final String ATTR_NAME = "NAME"; //$NON-NLS-1$
public static final String ATTR_VALUE = "VALUE"; //$NON-NLS-1$
- public static final String ATTR_STYLE = "STYLE"; //$NON-NLS-1$
- public static final String ATTR_SIZE = "SIZE"; //$NON-NLS-1$
+ public static final String ATTR_STYLE = "style"; //$NON-NLS-1$
+ public static final String ATTR_SIZE = "size"; //$NON-NLS-1$
public static final String ATTR_MULTIPLE = "MULTIPLE"; //$NON-NLS-1$
public static final String ATTR_COLSPAN = "colspan"; //$NON-NLS-1$
public static final String ATTR_CELLSPACING = "cellspacing"; //$NON-NLS-1$
@@ -75,6 +75,7 @@
public static final String ATTR_HEIGHT = "HEIGHT"; //$NON-NLS-1$
public static final String ATTR_BORDER = "BORDER"; //$NON-NLS-1$
public static final String ATTR_FOR = "FOR";
- public static final String ATTR_DIR = "DIR";
+ public static final String ATTR_DIR = "dir";
+ public static final String ATTR_DISABLED = "disabled";
}
\ No newline at end of file