[jbosstools-commits] JBoss Tools SVN: r43252 - in trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf: templates and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Aug 27 09:08:22 EDT 2012


Author: dmaliarevich
Date: 2012-08-27 09:08:22 -0400 (Mon, 27 Aug 2012)
New Revision: 43252

Added:
   trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCommandButton.java
Modified:
   trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JSF.java
   trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
Log:
https://issues.jboss.org/browse/JBIDE-3225 - adding text for h:commandButton

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JSF.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JSF.java	2012-08-27 12:00:59 UTC (rev 43251)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JSF.java	2012-08-27 13:08:22 UTC (rev 43252)
@@ -34,7 +34,9 @@
 	public static final String ATTR_FOR = "for"; //$NON-NLS-1$
 
 	public static final String ATTR_ID = "id";//$NON-NLS-1$
-
+	
+	public static final String ATTR_IMAGE = "image"; //$NON-NLS-1$
+	
 	public static final String ATTR_ITEM_LABEL = "itemLabel"; //$NON-NLS-1$
 	
 	public static final String ATTR_ITEM_VALUE = "itemValue"; //$NON-NLS-1$
@@ -60,6 +62,8 @@
 	public static final String ATTR_LAYOUT = "layout"; //$NON-NLS-1$
 
 	public static final String ATTR_TITLE = "title"; //$NON-NLS-1$
+	
+	public static final String ATTR_TYPE = "type"; //$NON-NLS-1$
 
 	public static final String ATTR_LANG = "lang"; //$NON-NLS-1$
 	
@@ -68,4 +72,9 @@
 	public static final String ATTR_DEFAULT = "default"; //$NON-NLS-1$
 	
 	public static final String CUSTOM_COMPONENT_ATTR_PREFIX="cc.attrs."; //$NON-NLS-1$
+	
+	public static final String ATTR_SRC = "src"; //$NON-NLS-1$
+	
+	public static final String VALUE_BUTTON = "button"; //$NON-NLS-1$
+	
 }

Added: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCommandButton.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCommandButton.java	                        (rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCommandButton.java	2012-08-27 13:08:22 UTC (rev 43252)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.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.jboss.tools.vpe.editor.util.VisualDomUtil;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class JsfCommandButton extends VpeAbstractTemplate {
+
+	@Override
+	public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+			nsIDOMDocument visualDocument) {
+		Element sourceElement = (Element) sourceNode;
+		nsIDOMElement input = visualDocument.createElement(HTML.TAG_INPUT);
+		
+		if (sourceElement.hasAttribute(JSF.ATTR_STYLE)) {
+			input.setAttribute(JSF.ATTR_STYLE, sourceElement.getAttribute(JSF.ATTR_STYLE));
+		}
+		if (sourceElement.hasAttribute(JSF.ATTR_STYLE_CLASS)) {
+			input.setAttribute(HTML.ATTR_CLASS, sourceElement.getAttribute(JSF.ATTR_STYLE_CLASS));
+		}
+		if (sourceElement.hasAttribute(JSF.ATTR_DISABLED)) {
+			String disabled = sourceElement.getAttribute(JSF.ATTR_DISABLED);
+			if ("true".equalsIgnoreCase(disabled)) { //$NON-NLS-1$
+				input.setAttribute(JSF.ATTR_DISABLED, JSF.ATTR_DISABLED);
+			}
+		}
+		if (sourceElement.hasAttribute(JSF.ATTR_DIR)) {
+			input.setAttribute(JSF.ATTR_DIR, sourceElement.getAttribute(JSF.ATTR_DIR));
+		} 
+		if (sourceElement.hasAttribute(JSF.ATTR_IMAGE)) {
+//		1) attr: +image -> type=image
+			input.setAttribute(JSF.ATTR_TYPE,JSF.ATTR_IMAGE);
+			input.setAttribute(JSF.ATTR_SRC, 
+					VpeStyleUtil.addFullPathToImgSrc(
+							sourceElement.getAttribute(JSF.ATTR_IMAGE), pageContext, true));
+		} else if (sourceElement.hasAttribute(JSF.ATTR_TYPE)) { 
+//		2) attr: +type -> type=type
+			input.setAttribute(JSF.ATTR_TYPE, sourceElement.getAttribute(JSF.ATTR_TYPE));
+			if (sourceElement.hasAttribute(JSF.ATTR_VALUE)) {
+				input.setAttribute(JSF.ATTR_VALUE, sourceElement.getAttribute(JSF.ATTR_VALUE));
+			}
+		} else {
+//		3) attr: -type -> type=button
+			input.setAttribute(JSF.ATTR_TYPE, JSF.VALUE_BUTTON);
+			if (sourceElement.hasAttribute(JSF.ATTR_VALUE)) {
+				input.setAttribute(JSF.ATTR_VALUE, sourceElement.getAttribute(JSF.ATTR_VALUE));
+			}
+		}
+
+		/*
+		 * https://issues.jboss.org/browse/JBIDE-3225
+		 * Components should render usual text inside
+		 */
+		VpeCreationData creationData = VisualDomUtil.createTemplateWithTextContainer(
+				sourceElement, input, HTML.TAG_DIV, visualDocument);
+		
+		return creationData;
+	}
+
+}

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	2012-08-27 12:00:59 UTC (rev 43251)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml	2012-08-27 13:08:22 UTC (rev 43252)
@@ -211,105 +211,18 @@
 	</vpe:tag>
 
 	<vpe:tag name="h:commandButton" case-sensitive="yes">
-		<!--
-			This is a very big if-statement. Its goal is to add support of
-			'disabled property' DO NOT FORGET TO EDIT 'ELSE' PART IN FUTURE
-			MODIFICATIONS
-		-->
-		<vpe:if test="(@disabled='true')">
-			<vpe:if test="not(attrpresent('image'))">
-				<vpe:if test="(@type='')">
-					<vpe:template children="no" modify="no">
-						<input type="button" value="{iif(@value='',' ',jsfvalue(@value))}"
-							class="{@styleClass}" style="{@style}" title="{tagstring()}" dir="{@dir}"
-							disabled='disabled' />
-						<vpe:resize>
+		<vpe:template children="yes" modify="no" 
+			class="org.jboss.tools.jsf.vpe.jsf.template.JsfCommandButton">
+			<vpe:resize>
 							<vpe:width width-attr="style.width" />
 							<vpe:height height-attr="style.height" />
-						</vpe:resize>
-						<vpe:dnd>
-							<vpe:drag start-enable="yes" />
-						</vpe:dnd>
-						<vpe:textFormatting use-default-formats="yes">
-						</vpe:textFormatting>
-					</vpe:template>
-				</vpe:if>
-				<vpe:if test="not(@type='')">
-					<vpe:template children="no" modify="no">
-						<input type="{@type}" value="{iif(@value='',' ',jsfvalue(@value))}"
-							class="{@styleClass}" style="{@style}" title="{tagstring()}" dir="{@dir}"
-							disabled='disabled' />
-						<vpe:resize>
-							<vpe:width width-attr="style.width" />
-							<vpe:height height-attr="style.height" />
-						</vpe:resize>
-						<vpe:dnd>
-							<vpe:drag start-enable="yes" />
-						</vpe:dnd>
-						<vpe:textFormatting use-default-formats="yes">
-						</vpe:textFormatting>
-					</vpe:template>
-				</vpe:if>
-			</vpe:if>
-			<vpe:if test="attrpresent('image')">
-				<vpe:template children="no" modify="no">
-					<input type="image" src="{src(@image)}" class="{@styleClass}"
-						style="{@style}" title="{tagstring()}" disabled='disabled' />
-					<vpe:resize>
-						<vpe:width width-attr="style.width" />
-						<vpe:height height-attr="style.height" />
-					</vpe:resize>
-					<vpe:textFormatting use-default-formats="yes">
-					</vpe:textFormatting>
-				</vpe:template>
-			</vpe:if>
-		</vpe:if>
-		<!--else-->
-		<vpe:if test="not(attrpresent('image'))">
-			<vpe:if test="(@type='')">
-				<vpe:template children="no" modify="no">
-					<input type="button" value="{iif(@value='',' ',jsfvalue(@value))}"
-						class="{@styleClass}" style="{@style}" title="{tagstring()}" dir="{@dir}" />
-					<vpe:resize>
-						<vpe:width width-attr="style.width" />
-						<vpe:height height-attr="style.height" />
-					</vpe:resize>
-					<vpe:dnd>
+			</vpe:resize>
+			<vpe:dnd>
 						<vpe:drag start-enable="yes" />
-					</vpe:dnd>
-					<vpe:textFormatting use-default-formats="yes">
-					</vpe:textFormatting>
-				</vpe:template>
-			</vpe:if>
-			<vpe:if test="not(@type='')">
-				<vpe:template children="no" modify="no">
-					<input type="{@type}" value="{iif(@value='',' ',jsfvalue(@value))}"
-						class="{@styleClass}" style="{@style}" title="{tagstring()}" dir="{@dir}" />
-					<vpe:resize>
-						<vpe:width width-attr="style.width" />
-						<vpe:height height-attr="style.height" />
-					</vpe:resize>
-					<vpe:dnd>
-						<vpe:drag start-enable="yes" />
-					</vpe:dnd>
-					<vpe:textFormatting use-default-formats="yes">
-					</vpe:textFormatting>
-				</vpe:template>
-			</vpe:if>
-		</vpe:if>
-		<vpe:if test="attrpresent('image')">
-			<vpe:template children="no" modify="no">
-				<input type="image" src="{src(@image)}" class="{@styleClass}"
-					style="{@style}" title="{tagstring()}" />
-				<vpe:resize>
-					<vpe:width width-attr="style.width" />
-					<vpe:height height-attr="style.height" />
-				</vpe:resize>
-				<vpe:textFormatting use-default-formats="yes">
-				</vpe:textFormatting>
-			</vpe:template>
-		</vpe:if>
-		<!--end-of-else-->
+			</vpe:dnd>
+			<vpe:textFormatting use-default-formats="yes">
+			</vpe:textFormatting>
+		</vpe:template>
 	</vpe:tag>
 
 	<!-- Проблема с вложенным параметром (31 of 4) -->



More information about the jbosstools-commits mailing list