Author: sdzmitrovich
Date: 2008-01-04 06:01:05 -0500 (Fri, 04 Jan 2008)
New Revision: 5504
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/JsfSelectManyListbox.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/JsfSelectOneListbox.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
trunk/vpe/plugins/org.jboss.tools.vpe/templates/vpe-templates-jsf.xml
Log:
http://jira.jboss.com/jira/browse/JBIDE-1501
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/JsfSelectManyListbox.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/JsfSelectManyListbox.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/JsfSelectManyListbox.java 2008-01-04
11:01:05 UTC (rev 5504)
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.template;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+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.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ * template for selectOneListbox select item
+ *
+ */
+public class JsfSelectManyListbox extends VpeAbstractTemplate {
+
+ /**
+ * "size" attribute
+ */
+ private static final String ATTR_SIZE = "size";
+
+ /**
+ * "size" attribute
+ */
+ private static final String ATTR_MULTIPLE_VALUE = "multiple";
+ /**
+ * list of visible children
+ */
+ private static List<String> CHILDREN_LIST = new ArrayList<String>();
+
+ static {
+ CHILDREN_LIST.add("selectItem");
+ CHILDREN_LIST.add("selectItems");
+ }
+
+ /**
+ * list of copied attributes
+ */
+ private static List<String> ATTR_LIST_COPY = new ArrayList<String>();
+
+ static {
+ ATTR_LIST_COPY.add("style");
+ ATTR_LIST_COPY.add("styleClass");
+ }
+
+ /**
+ *
+ */
+ public JsfSelectManyListbox() {
+
+ // 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);
+
+ Element element = (Element) sourceNode;
+
+ // import attributes from source
+ for (String attributeName : ATTR_LIST_COPY) {
+
+ // get attribute
+ String attr = element.getAttribute(attributeName);
+
+ // add attribute to "select"
+ if (attr != null)
+ select.setAttribute(HTML.ATTR_STYLE, attr);
+
+ }
+
+ // set "multiple" attribute
+ select.setAttribute(HTML.ATTR_MULTIPLE, ATTR_MULTIPLE_VALUE);
+
+ // get "size" attribute
+ String size = element.getAttribute(ATTR_SIZE);
+
+ // add "size" attribute to "select"
+ if (size != null)
+ // if source has "size" attribute import it
+ select.setAttribute(HTML.ATTR_SIZE, size);
+ else
+ // count size
+ select.setAttribute(HTML.ATTR_SIZE, String
+ .valueOf(countSize(element)));
+
+ return new VpeCreationData(select);
+ }
+
+ /**
+ * Count size for "select" (size = number of "selectItem" and
"selectItems"
+ * children )
+ *
+ *
+ * @param sourceNode
+ * @return size of select (1 or more)
+ */
+ private int countSize(Node sourceNode) {
+
+ NodeList children = sourceNode.getChildNodes();
+ int size = 0;
+ for (int i = 0; i < children.getLength(); i++) {
+
+ Node child = children.item(i);
+ // if children is one of visible items
+ if (CHILDREN_LIST.contains(child.getLocalName()))
+ size++;
+ }
+ // if 'size' == 0 return 1 else 'size'
+ return size == 0 ? 1 : size;
+
+ }
+
+ /**
+ *
+ */
+ 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);
+ }
+
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/JsfSelectOneListbox.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/JsfSelectOneListbox.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/JsfSelectOneListbox.java 2008-01-04
11:01:05 UTC (rev 5504)
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.template;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+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.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ * template for selectOneListbox select item
+ *
+ */
+public class JsfSelectOneListbox extends VpeAbstractTemplate {
+
+ /**
+ * "size" attribute
+ */
+ private static final String ATTR_SIZE = "size";
+
+ /**
+ * list of visible children
+ */
+ private static List<String> CHILDREN_LIST = new ArrayList<String>();
+
+ static {
+ CHILDREN_LIST.add("selectItem");
+ CHILDREN_LIST.add("selectItems");
+ }
+
+ /**
+ * list of copied attributes
+ */
+ private static List<String> ATTR_LIST_COPY = new ArrayList<String>();
+
+ static {
+ ATTR_LIST_COPY.add("style");
+ ATTR_LIST_COPY.add("styleClass");
+ }
+
+ /**
+ *
+ */
+ public JsfSelectOneListbox() {
+
+ // 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);
+
+ Element element = (Element) sourceNode;
+
+ // import attributes from source
+ for (String attributeName : ATTR_LIST_COPY) {
+
+ // get attribute
+ String attr = element.getAttribute(attributeName);
+
+ // add attribute to "select"
+ if (attr != null)
+ select.setAttribute(HTML.ATTR_STYLE, attr);
+
+ }
+
+ // get "size" attribute
+ String size = element.getAttribute(ATTR_SIZE);
+
+ // add "size" attribute to "select"
+ if (size != null)
+ // if source has "size" attribute import it
+ select.setAttribute(HTML.ATTR_SIZE, size);
+ else
+ // count size
+ select.setAttribute(HTML.ATTR_SIZE, String
+ .valueOf(countSize(element)));
+
+ return new VpeCreationData(select);
+ }
+
+ /**
+ * Count size for "select" (size = number of "selectItem" and
"selectItems"
+ * children )
+ *
+ *
+ * @param sourceNode
+ * @return size of select (1 or more)
+ */
+ private int countSize(Node sourceNode) {
+
+ NodeList children = sourceNode.getChildNodes();
+ int size = 0;
+ for (int i = 0; i < children.getLength(); i++) {
+
+ Node child = children.item(i);
+ // if children is one of visible items
+ if (CHILDREN_LIST.contains(child.getLocalName()))
+ size++;
+ }
+ // if 'size' == 0 return 1 else 'size'
+ return size == 0 ? 1 : size;
+
+ }
+
+ /**
+ *
+ */
+ 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);
+ }
+}
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-01-04
01:55:08 UTC (rev 5503)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2008-01-04
11:01:05 UTC (rev 5504)
@@ -19,43 +19,45 @@
private HTML() {}
- public static final String TAG_HTML = "HTML";
- public static final String TAG_HEAD = "HEAD";
- public static final String TAG_BODY = "BODY";
- public static final String TAG_IMG = "IMG";
- public static final String TAG_LINK = "LINK";
- public static final String TAG_SELECT = "SELECT";
- public static final String TAG_OPTION = "OPTION";
- public static final String TAG_STYLE = "STYLE";
- public static final String TAG_TABLE = "TABLE";
- public static final String TAG_TBODY = "TBODY";
- public static final String TAG_THEAD = "THEAD";
- public static final String TAG_TFOOT = "TFOOT";
- public static final String TAG_TH = "TH";
- public static final String TAG_TR = "TR";
- public static final String TAG_TD = "TD";
- public static final String TAG_COL = "COL";
- public static final String TAG_COLS = "COLS";
- public static final String TAG_COLGROUP = "COLGROUP";
- public static final String TAG_BR = "BR";
- public static final String TAG_LI = "LI";
- public static final String TAG_DIV = "DIV";
- public static final String TAG_SPAN = "SPAN";
- public static final String TAG_P = "P";
- public static final String TAG_TEXTAREA = "TEXTAREA";
- public static final String TAG_INPUT = "INPUT";
- public static final String TAG_BUTTON = "BUTTON";
- public static final String TAG_OL = "OL";
- public static final String TAG_UL = "UL";
+ public static final String TAG_HTML = "HTML";
+ public static final String TAG_HEAD = "HEAD";
+ public static final String TAG_BODY = "BODY";
+ public static final String TAG_IMG = "IMG";
+ public static final String TAG_LINK = "LINK";
+ public static final String TAG_SELECT = "SELECT";
+ public static final String TAG_OPTION = "OPTION";
+ public static final String TAG_STYLE = "STYLE";
+ public static final String TAG_TABLE = "TABLE";
+ public static final String TAG_TBODY = "TBODY";
+ public static final String TAG_THEAD = "THEAD";
+ public static final String TAG_TFOOT = "TFOOT";
+ public static final String TAG_TH = "TH";
+ public static final String TAG_TR = "TR";
+ public static final String TAG_TD = "TD";
+ public static final String TAG_COL = "COL";
+ public static final String TAG_COLS = "COLS";
+ public static final String TAG_COLGROUP = "COLGROUP";
+ public static final String TAG_BR = "BR";
+ public static final String TAG_LI = "LI";
+ public static final String TAG_DIV = "DIV";
+ public static final String TAG_SPAN = "SPAN";
+ public static final String TAG_P = "P";
+ public static final String TAG_TEXTAREA = "TEXTAREA";
+ public static final String TAG_INPUT = "INPUT";
+ public static final String TAG_BUTTON = "BUTTON";
+ public static final String TAG_OL = "OL";
+ public static final String TAG_UL = "UL";
- public static final String ATTR_ID = "ID";
- public static final String ATTR_TYPE ="TYPE";
- public static final String ATTR_TEXT ="TEXT";
- public static final String ATTR_CLASS ="CLASS";
- public static final String ATTR_TITLE ="TITLE";
- public static final String ATTR_NAME ="NAME";
- public static final String ATTR_VALUE ="VALUE";
- public static final String ATTR_STYLE ="STYLE";
+ public static final String ATTR_ID = "ID";
+ public static final String ATTR_TYPE ="TYPE";
+ public static final String ATTR_TEXT ="TEXT";
+ public static final String ATTR_CLASS ="CLASS";
+ public static final String ATTR_TITLE ="TITLE";
+ public static final String ATTR_NAME ="NAME";
+ public static final String ATTR_VALUE ="VALUE";
+ public static final String ATTR_STYLE ="STYLE";
+ public static final String ATTR_SIZE ="SIZE";
+ public static final String ATTR_MULTIPLE = "MULTIPLE";
}
\ No newline at end of file
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/templates/vpe-templates-jsf.xml
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/templates/vpe-templates-jsf.xml 2008-01-04
01:55:08 UTC (rev 5503)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/templates/vpe-templates-jsf.xml 2008-01-04
11:01:05 UTC (rev 5504)
@@ -671,45 +671,9 @@
</vpe:tag>
<vpe:tag name="h:selectOneListbox" case-sensitive="yes">
- <vpe:if test="attrpresent('size')">
- <vpe:template children="yes" modify="yes">
- <select size="{@size}" style="{@style}"
- class="{@styleClass}" title="{tagstring()}" />
- <vpe:dnd>
- <vpe:drag start-enable="yes" />
- <vpe:drop container="yes">
- <vpe:container-child tag-name="selectItem" />
- <vpe:container-child tag-name="selectItems" />
- </vpe:drop>
- </vpe:dnd>
- <vpe:textFormating>
- <vpe:format type="UnderlineFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="BoldFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="ItalicFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="FontNameFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="FontSizeFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="BackgroundColorFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="ForegroundColorFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- </vpe:textFormating>
- </vpe:template>
- </vpe:if>
- <vpe:template children="yes" modify="yes">
- <select size="3" style="{@style}"
class="{@styleClass}"
- title="{tagstring()}" />
+ <vpe:template
+ class="org.jboss.tools.vpe.editor.template.JsfSelectOneListbox"
+ children="yes" modify="yes">
<vpe:dnd>
<vpe:drag start-enable="yes" />
<vpe:drop container="yes">
@@ -740,82 +704,45 @@
<vpe:formatAttribute type="style" />
</vpe:format>
</vpe:textFormating>
- </vpe:template>
- </vpe:tag>
-
- <vpe:tag name="h:selectManyListbox" case-sensitive="yes">
- <vpe:if test="attrpresent('size')">
- <vpe:template children="yes" modify="yes">
- <select size="{@size}" style="{@style}"
- class="{@styleClass}" title="{tagstring()}"
multiple="multiple" />
- <vpe:dnd>
- <vpe:drag start-enable="yes" />
- <vpe:drop container="yes">
- <vpe:container-child tag-name="selectItem" />
- <vpe:container-child tag-name="selectItems" />
- </vpe:drop>
- </vpe:dnd>
- <vpe:textFormating>
- <vpe:format type="UnderlineFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="BoldFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="ItalicFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="FontNameFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="FontSizeFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="BackgroundColorFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="ForegroundColorFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- </vpe:textFormating>
- </vpe:template>
- </vpe:if>
- <vpe:template children="yes" modify="yes">
- <select size="3" style="{@style}"
class="{@styleClass}"
- title="{tagstring()}" multiple="multiple"/>
- <vpe:dnd>
- <vpe:drag start-enable="yes" />
- <vpe:drop container="yes">
- <vpe:container-child tag-name="selectItem" />
- <vpe:container-child tag-name="selectItems" />
- </vpe:drop>
- </vpe:dnd>
- <vpe:textFormating>
- <vpe:format type="UnderlineFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="BoldFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="ItalicFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="FontNameFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="FontSizeFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="BackgroundColorFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- <vpe:format type="ForegroundColorFormat">
- <vpe:formatAttribute type="style" />
- </vpe:format>
- </vpe:textFormating>
- </vpe:template>
- </vpe:tag>
-
+ </vpe:template>
+ </vpe:tag>
+
+ <vpe:tag name="h:selectManyListbox" case-sensitive="yes">
+ <vpe:template children="yes" modify="yes"
+ class="org.jboss.tools.vpe.editor.template.JsfSelectManyListbox">
+ <vpe:dnd>
+ <vpe:drag start-enable="yes" />
+ <vpe:drop container="yes">
+ <vpe:container-child tag-name="selectItem" />
+ <vpe:container-child tag-name="selectItems" />
+ </vpe:drop>
+ </vpe:dnd>
+ <vpe:textFormating>
+ <vpe:format type="UnderlineFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
+ <vpe:format type="BoldFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
+ <vpe:format type="ItalicFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
+ <vpe:format type="FontNameFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
+ <vpe:format type="FontSizeFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
+ <vpe:format type="BackgroundColorFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
+ <vpe:format type="ForegroundColorFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
+ </vpe:textFormating>
+ </vpe:template>
+ </vpe:tag>
+
<vpe:tag name="h:selectOneMenu" case-sensitive="yes">
<vpe:template children="yes" modify="yes">
<select style="{@style}" class="{@styleClass}"
title="{tagstring()}"/>