Author: dmaliarevich
Date: 2008-02-22 10:18:18 -0500 (Fri, 22 Feb 2008)
New Revision: 6543
Added:
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/JsfSelectManyCheckbox.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
Log:
http://jira.jboss.com/jira/browse/JBIDE-1719
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java 2008-02-22
15:18:18 UTC (rev 6543)
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 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.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.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * @author dmaliarevich
+ *
+ */
+public class JsfCheckboxSelectItemTemplate extends VpeAbstractTemplate {
+
+ private static final String ITEM_LABEL = "itemLabel";
+ private static final String TYPE_CHECKBOX = "checkbox";
+ private static final String CLASS = "class";
+
+ // style of span
+ private static final String SPAN_STYLE_VALUE = "-moz-user-modify:
read-write;"; //$NON-NLS-1$
+
+ /*h:SelectManyCheckbox attributes*/
+ private static final String DISABLED = "disabled";
+ private static final String ENABLED_CLASS = "enabledClass";
+ private static final String DISABLED_CLASS = "disabledClass";
+
+ private String disabled;
+ private String enabledClass;
+ private String disabledClass;
+
+ /**
+ *
+ */
+ public JsfCheckboxSelectItemTemplate() {
+ }
+
+ /* (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) {
+
+ readAttributes(sourceNode.getParentNode());
+
+ nsIDOMElement input = visualDocument.createElement(HTML.TAG_INPUT);
+ nsIDOMElement label = visualDocument.createElement(HTML.TAG_LABEL);
+ // create span element
+ nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
+
+ VpeCreationData creationData = new VpeCreationData(span);
+
+ // add title attribute to span
+ span.setAttribute(HTML.ATTR_TITLE, getTitle(sourceNode));
+ span.setAttribute(HTML.ATTR_STYLE, SPAN_STYLE_VALUE);
+
+ input.setAttribute(HTML.ATTR_TYPE, TYPE_CHECKBOX);
+
+ if (attrPresents(disabled) && "true".equalsIgnoreCase(disabled)) {
+ label.setAttribute(CLASS, disabledClass);
+ } else if (attrPresents(enabledClass)) {
+ label.setAttribute(CLASS, enabledClass);
+ }
+
+ String itemLabel = getLabel(sourceNode);
+ label.appendChild(visualDocument.createTextNode(itemLabel));
+
+ span.appendChild(input);
+ span.appendChild(label);
+
+ return creationData;
+ }
+
+ /**
+ * Checks is attribute presents.
+ *
+ * @param attr the attribute
+ *
+ * @return true, if successful
+ */
+ private boolean attrPresents(String attr) {
+ return ((null != attr) && (!"".equals(attr)));
+ }
+
+ /**
+ * generate title of element
+ *
+ * @param sourceNode
+ * @return
+ */
+ private String getTitle(Node sourceNode) {
+
+ String tagString = " <" + sourceNode.getNodeName(); //$NON-NLS-1$
+ NamedNodeMap attrs = sourceNode.getAttributes();
+ if (attrs != null) {
+ tagString += attrs.getLength() > 0 ? " " : ""; //$NON-NLS-1$
//$NON-NLS-2$
+ for (int i = 0; i < attrs.getLength(); i++) {
+ Node attr = attrs.item(i);
+ tagString += attr.getNodeName() + "=\"" + attr.getNodeValue()
//$NON-NLS-1$
+ + "\"" + (i < (attrs.getLength() - 1) ? " " :
""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+ tagString += (sourceNode.hasChildNodes() ? "" : "/") + ">
"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ return tagString;
+ }
+
+ /**
+ * 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 "";
+ }
+
+ /**
+ * Read attributes from the source element.
+ *
+ * @param sourceNode the source node
+ */
+ private void readAttributes(Node sourceNode) {
+ if (null == sourceNode) {
+ return;
+ }
+ Element source = (Element) sourceNode;
+ disabled = source.getAttribute(DISABLED);
+ enabledClass = source.getAttribute(ENABLED_CLASS);
+ disabledClass = source.getAttribute(DISABLED_CLASS);
+ }
+
+ @Override
+ public void setSourceAttributeSelection(VpePageContext pageContext,
+ Element sourceElement, int offset, int length, Object data) {
+ VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder();
+ sourceBuilder.setSelection(sourceElement, 0, 0);
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOptionSelectItemTemplate.java 2008-02-22
15:18:18 UTC (rev 6543)
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 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.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.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author dmaliarevich
+ *
+ */
+public class JsfOptionSelectItemTemplate extends VpeAbstractTemplate {
+
+ 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";
+
+ private String disabled;
+ private String enabledClass;
+ private String disabledClass;
+
+ /**
+ *
+ */
+ public JsfOptionSelectItemTemplate() {
+ }
+
+ /* (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) {
+
+ readAttributes(sourceNode.getParentNode());
+
+ nsIDOMElement option = visualDocument.createElement(HTML.TAG_OPTION);
+ VpeCreationData creationData = new VpeCreationData(option);
+
+ if (attrPresents(disabled) && "true".equalsIgnoreCase(disabled)) {
+ option.setAttribute(CLASS, disabledClass);
+ } else if (attrPresents(enabledClass)) {
+ option.setAttribute(CLASS, enabledClass);
+ }
+
+ 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
+ *
+ * @return true, if successful
+ */
+ private boolean attrPresents(String attr) {
+ return ((null != attr) && (!"".equals(attr)));
+ }
+
+ /**
+ * Read attributes from the source element.
+ *
+ * @param sourceNode the source node
+ */
+ private void readAttributes(Node sourceNode) {
+ if (null == sourceNode) {
+ return;
+ }
+ Element source = (Element) sourceNode;
+ disabled = source.getAttribute(DISABLED);
+ enabledClass = source.getAttribute(ENABLED_CLASS);
+ disabledClass = source.getAttribute(DISABLED_CLASS);
+ }
+
+ @Override
+ public void setSourceAttributeSelection(VpePageContext pageContext,
+ Element sourceElement, int offset, int length, Object data) {
+ VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder();
+ sourceBuilder.setSelection(sourceElement, 0, 0);
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOptionSelectItemTemplate.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectManyCheckbox.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectManyCheckbox.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectManyCheckbox.java 2008-02-22
15:18:18 UTC (rev 6543)
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 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 java.util.ArrayList;
+import java.util.List;
+
+import javax.smartcardio.ATR;
+
+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.jboss.tools.vpe.editor.util.VpeStyleUtil;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNamedNodeMap;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author dmaliarevich
+ *
+ */
+public class JsfSelectManyCheckbox extends VpeAbstractTemplate {
+
+ private static final String PAGE_DIRECTION = "pageDirection";
+ private static final String LINE_DIRECTION = "lineDirection";
+
+ /*h:SelectManyCheckbox attributes*/
+ private static final String STYLE = "style";
+ private static final String STYLE_CLASS = "styleClass";
+ private static final String BORDER = "border";
+ private static final String LAYOUT = "layout";
+ private static final String CLASS = "class";
+
+ private String style;
+ private String styleClass;
+ private String border;
+ private String layout;
+
+ /**
+ * 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$
+ }
+
+ /**
+ *
+ */
+ public JsfSelectManyCheckbox() {
+ }
+
+ /*
+ * (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) {
+
+ readAttributes(sourceNode);
+
+ Element sourceElement = (Element) sourceNode;
+ nsIDOMElement table = visualDocument.createElement(HTML.TAG_TABLE);
+ nsIDOMElement tr = null;
+ nsIDOMElement td = null;
+
+ if (attrPresents(style)) {
+ table.setAttribute(STYLE, style);
+ }
+ if (attrPresents(styleClass)) {
+ table.setAttribute(CLASS, styleClass);
+ }
+ if (attrPresents(border)) {
+ table.setAttribute(BORDER, border);
+ }
+
+ VpeCreationData creationData = new VpeCreationData(table);
+
+ NodeList children = sourceNode.getChildNodes();
+
+ if (attrPresents(layout) && PAGE_DIRECTION.equalsIgnoreCase(layout)) {
+ 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())) {
+ tr = visualDocument.createElement(HTML.TAG_TR);
+ td = visualDocument.createElement(HTML.TAG_TD);
+ tr.appendChild(td);
+ table.appendChild(tr);
+ VpeChildrenInfo info = new VpeChildrenInfo(td);
+ info.addSourceChild(child);
+ creationData.addChildrenInfo(info);
+ }
+ }
+ } else {
+ tr = visualDocument.createElement(HTML.TAG_TR);
+ table.appendChild(tr);
+ 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())) {
+ td = visualDocument.createElement(HTML.TAG_TD);
+ tr.appendChild(td);
+ VpeChildrenInfo info = new VpeChildrenInfo(td);
+ info.addSourceChild(child);
+ creationData.addChildrenInfo(info);
+ }
+ }
+ }
+
+ return creationData;
+ }
+
+ /**
+ * Read attributes from the source element.
+ *
+ * @param sourceNode
+ * the source node
+ */
+ private void readAttributes(Node sourceNode) {
+ Element source = (Element) sourceNode;
+ style = source.getAttribute(STYLE);
+ styleClass = source.getAttribute(STYLE_CLASS);
+ border = source.getAttribute(BORDER);
+ layout = source.getAttribute(LAYOUT);
+ }
+
+ /**
+ * Checks is attribute presents.
+ *
+ * @param attr the attribute
+ *
+ * @return true, if successful
+ */
+ private boolean attrPresents(String attr) {
+ return ((null != attr) && (!"".equals(attr)));
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfSelectManyCheckbox.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
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-22
15:13:22 UTC (rev 6542)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2008-02-22
15:18:18 UTC (rev 6543)
@@ -584,9 +584,9 @@
Возможна проблема с нечувствительностью к регистру lineDirection/pageDirection (44 of
4)
-->
<vpe:tag name="h:selectManyCheckbox" case-sensitive="yes">
- <vpe:template children="yes" modify="yes">
- <vpe:grid layout="{@layout}" border="{@border}"
title="{tagstring()}" style="{@style}"
class="{@styleClass}"/>
- <vpe:breaker type="ignore"/>
+ <vpe:template children="yes" modify="yes"
+ class="org.jboss.tools.jsf.vpe.jsf.template.JsfSelectManyCheckbox">
+
<vpe:dnd>
<vpe:drag start-enable="yes"/>
<vpe:drop container="yes">
@@ -807,7 +807,17 @@
</vpe:tag>
<vpe:tag name="f:selectItem" case-sensitive="yes">
- <vpe:if
test="hasinparents('h:selectManyCheckbox')|hasinparents('x:selectManyCheckbox')|hasinparents('t:selectManyCheckbox')">
+ <vpe:if test="hasinparents('h:selectManyCheckbox')">
+ <vpe:template children="no" 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" />
@@ -825,9 +835,7 @@
</vpe:template>
</vpe:if>
<vpe:if test="hasinparents('h:selectOneListbox')|
- hasinparents('h:selectManyListbox')|
hasinparents('h:selectOneMenu')|
- hasinparents('h:selectManyMenu')|
hasinparents('t:selectManyMenu')|
hasinparents('x:selectOneRadio')|
hasinparents('x:selectOneMenu')"> <!-- Gavr --><!--
added x: 8.02.05 -->