Author: dmaliarevich
Date: 2009-04-14 11:32:21 -0400 (Tue, 14 Apr 2009)
New Revision: 14737
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/SeamGraphicImageTemplate.java
Removed:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/ComponentUtil.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/util/Seam.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/templates/vpe-templates-seam.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-4105, s:transformImageSize template was added,
JUnits were updated
Deleted:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/ComponentUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/ComponentUtil.java 2009-04-14
15:32:15 UTC (rev 14736)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/ComponentUtil.java 2009-04-14
15:32:21 UTC (rev 14737)
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * 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.jsf.vpe.seam;
-
-import org.mozilla.interfaces.nsIDOMElement;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-public class ComponentUtil {
-
- /**
- * Copies all attributes from source node to visual node.
- *
- * @param sourceNode
- * @param visualNode
- */
- public static void copyAttributes(Node sourceNode,
- nsIDOMElement visualElement) {
- NamedNodeMap namedNodeMap = sourceNode.getAttributes();
- for (int i = 0; i < namedNodeMap.getLength(); i++) {
- Node attribute = namedNodeMap.item(i);
- visualElement.setAttribute(attribute.getNodeName(), attribute
- .getNodeValue());
- }
- }
-
-}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/SeamGraphicImageTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/SeamGraphicImageTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/SeamGraphicImageTemplate.java 2009-04-14
15:32:21 UTC (rev 14737)
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.seam.template;
+
+import java.util.List;
+
+import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
+import org.jboss.tools.jsf.vpe.seam.template.util.Seam;
+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.VpeStyleUtil;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Class for s:graphicImage template.
+ *
+ * @author dmaliarevich
+ */
+public class SeamGraphicImageTemplate extends VpeAbstractTemplate {
+
+ /*
+ * s:transformImageSize tag name.
+ */
+ private final String TRANSFORM_IMAGE_SIZE_NAME = ":transformImageSize";
//$NON-NLS-1$
+
+ public SeamGraphicImageTemplate() {
+ super();
+ }
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ Element sourceElement = (Element) sourceNode;
+ nsIDOMElement img = visualDocument.createElement(HTML.TAG_IMG);
+
+ /*
+ * Indicates that source node has width or height attributes.
+ */
+ boolean hasWidth = false;
+ boolean hasHeight = false;
+
+ /*
+ * Reading source attributes and setting them to the visual node.
+ */
+ if (sourceElement.hasAttribute(HTML.ATTR_ALT)) {
+ img.setAttribute(HTML.ATTR_ALT, sourceElement.getAttribute(HTML.ATTR_ALT));
+ }
+ if (sourceElement.hasAttribute(HTML.ATTR_DIR)) {
+ img.setAttribute(HTML.ATTR_DIR, sourceElement.getAttribute(HTML.ATTR_DIR));
+ }
+ if (sourceElement.hasAttribute(HTML.ATTR_WIDTH)) {
+ img.setAttribute(HTML.ATTR_WIDTH, sourceElement.getAttribute(HTML.ATTR_WIDTH));
+ hasWidth = true;
+ }
+ if (sourceElement.hasAttribute(HTML.ATTR_HEIGHT)) {
+ img.setAttribute(HTML.ATTR_HEIGHT, sourceElement.getAttribute(HTML.ATTR_HEIGHT));
+ hasHeight = true;
+ }
+ if (sourceElement.hasAttribute(HTML.ATTR_STYLE)) {
+ img.setAttribute(HTML.ATTR_STYLE, sourceElement.getAttribute(HTML.ATTR_STYLE));
+ }
+ if (sourceElement.hasAttribute(Seam.ATTR_STYLE_CLASS)) {
+ img.setAttribute(HTML.ATTR_CLASS,
sourceElement.getAttribute(Seam.ATTR_STYLE_CLASS));
+ }
+ if (sourceElement.hasAttribute(HTML.ATTR_VALUE)) {
+ img.setAttribute(HTML.ATTR_SRC, VpeStyleUtil.addFullPathToImgSrc(
+ sourceElement.getAttribute(HTML.ATTR_VALUE), pageContext,
+ true));
+ } else if (sourceElement.hasAttribute(Seam.ATTR_URL)) {
+ img.setAttribute(HTML.ATTR_SRC, VpeStyleUtil.addFullPathToImgSrc(
+ sourceElement.getAttribute(Seam.ATTR_URL), pageContext,
+ true));
+ }
+
+ /*
+ * Looking for any seam transformation tag to apply the transformation to the image.
+ */
+ List<Node> children = ComponentUtil.getChildren(sourceElement);
+ /*
+ * If s:graphicImage has width and height attributes
+ * skip any size transformation.
+ */
+ if (!(hasHeight || hasWidth)) {
+ for (Node node : children) {
+ if (node.getNodeName().endsWith(TRANSFORM_IMAGE_SIZE_NAME)) {
+ Element transform = (Element) node;
+ if (transform.hasAttribute(HTML.ATTR_WIDTH)) {
+ img.setAttribute(HTML.ATTR_WIDTH, transform
+ .getAttribute(HTML.ATTR_WIDTH));
+ }
+ if (transform.hasAttribute(HTML.ATTR_HEIGHT)) {
+ img.setAttribute(HTML.ATTR_HEIGHT, transform
+ .getAttribute(HTML.ATTR_HEIGHT));
+ }
+ /*
+ * Apply only the first transform element.
+ */
+ break;
+ }
+ }
+ }
+ return new VpeCreationData(img);
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/SeamGraphicImageTemplate.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.seam/src/org/jboss/tools/jsf/vpe/seam/template/util/Seam.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/util/Seam.java 2009-04-14
15:32:15 UTC (rev 14736)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/util/Seam.java 2009-04-14
15:32:21 UTC (rev 14737)
@@ -20,5 +20,6 @@
public static final String ATTR_TEMPLATE = "template"; //$NON-NLS-1$
public static final String ATTR_STYLE_CLASS = "styleClass"; //$NON-NLS-1$
+ public static final String ATTR_URL = "url"; //$NON-NLS-1$
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/templates/vpe-templates-seam.xml
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/templates/vpe-templates-seam.xml 2009-04-14
15:32:15 UTC (rev 14736)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/templates/vpe-templates-seam.xml 2009-04-14
15:32:21 UTC (rev 14737)
@@ -190,29 +190,7 @@
</vpe:tag>
<vpe:tag name="s:graphicImage" case-sensitive="yes">
- <vpe:if test="attrpresent('value')">
- <vpe:template children="no" modify="yes">
- <img src="{src(jsfvalue(@value))}"
width="{@width}"
- height="{@height}" class="{@styleClass}"
style="{@style}"
- title="{tagstring()}"
alt="{jsfvalue(@alt)}"/>
- <vpe:dnd>
- <vpe:drag start-enable="yes" />
- </vpe:dnd>
- <vpe:resize>
- <vpe:width width-attr="style.width" />
- <vpe:height height-attr="style.height" />
- </vpe:resize>
- </vpe:template>
- </vpe:if>
- <vpe:template children="no" modify="yes">
- <img src="{src(jsfvalue(@url))}" width="{@width}"
- height="{@height}" class="{@styleClass}"
style="{@style}"
- title="{tagstring()}" alt="{jsfvalue(@alt)}"/>
- <vpe:resize>
- <vpe:width width-attr="style.width" />
- <vpe:height height-attr="style.height" />
- </vpe:resize>
- </vpe:template>
+ <vpe:template children="no" modify="yes"
class="org.jboss.tools.jsf.vpe.seam.template.SeamGraphicImageTemplate" />
</vpe:tag>
<vpe:tag name="s:label" case-sensitive="yes">