Author: izhukov
Date: 2009-02-09 08:10:30 -0500 (Mon, 09 Feb 2009)
New Revision: 13543
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFLogTemplate.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/log.xhtml.xml
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/log.xhtml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/src/org/jboss/tools/jsf/vpe/ajax4jsf/test/Ajax4JsfComponentContentTest.java
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/VpeStyleUtil.java
Log:
JBIDE-3707 fixed
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFLogTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFLogTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFLogTemplate.java 2009-02-09
13:10:30 UTC (rev 13543)
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * 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.ajax4jsf.template;
+
+
+import java.util.List;
+
+import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces;
+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.Constants;
+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;
+
+/**
+ * Template for the <a4j:log> component.
+ *
+ * @author Igor Zhukov
+ */
+public class Ajax4JSFLogTemplate extends VpeAbstractTemplate {
+
+ /** DEFAULT_DIV_SIZE */
+ private final static String DEFAULT_WIDTH = "800px"; //$NON-NLS-1$
+ private final static String DEFAULT_HEIGHT = "600px"; //$NON-NLS-1$
+ private final static String DEFAULT_OVERFLOW = "auto"; //$NON-NLS-1$
+
+ private final static String CLEAR_BUTTON = "Clear"; //$NON-NLS-1$
+
+ /**
+ * The Constructor.
+ */
+ public Ajax4JSFLogTemplate() {
+ super();
+ }
+
+ /**
+ * Creates a node of the visual tree on the node of the source tree.
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceNode
+ * The current node of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @return The information on the created node of the visual tree.
+ */
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
+ // cast to Element
+ Element sourceElement = (Element) sourceNode;
+
+ nsIDOMElement divElement = visualDocument.createElement(HTML.TAG_DIV);
+
+ String style = sourceElement.getAttribute(HTML.ATTR_STYLE);
+ // set STYLE attributes
+ // check 'overflow' attribute
+ String parameterValue = VpeStyleUtil.getParameterFromStyleAttribute(style,
HTML.STYLE_PARAMETER_OVERFLOW);
+ if (parameterValue == null || parameterValue.equals(Constants.EMPTY)) {
+ parameterValue = ComponentUtil.getAttribute(sourceElement,
HTML.STYLE_PARAMETER_OVERFLOW, DEFAULT_OVERFLOW);
+ style = VpeStyleUtil.setParameterInStyle(style, HTML.STYLE_PARAMETER_OVERFLOW,
parameterValue);
+ }
+ // check 'width' attribute
+ parameterValue = VpeStyleUtil.getParameterFromStyleAttribute(style, HTML.ATTR_WIDTH);
+ if (parameterValue == null || parameterValue.equals(Constants.EMPTY)) {
+ parameterValue = ComponentUtil.getAttribute(sourceElement, HTML.ATTR_WIDTH,
DEFAULT_WIDTH);
+ style = VpeStyleUtil.setParameterInStyle(style, HTML.ATTR_WIDTH, parameterValue);
+ }
+ // check 'height' attribute
+ parameterValue = VpeStyleUtil.getParameterFromStyleAttribute(style, HTML.ATTR_HEIGHT);
+ if (parameterValue == null || parameterValue.equals(Constants.EMPTY)) {
+ parameterValue = ComponentUtil.getAttribute(sourceElement, HTML.ATTR_HEIGHT,
DEFAULT_HEIGHT);
+ style = VpeStyleUtil.setParameterInStyle(style, HTML.ATTR_HEIGHT, parameterValue);
+ }
+ divElement.setAttribute(HTML.ATTR_STYLE, style);
+
+ // set CLASS attribute
+ String styleClass = ComponentUtil.getAttribute(sourceElement,
RichFaces.ATTR_STYLE_CLASS);
+ if (!Constants.EMPTY.equals(styleClass)) {
+ divElement.setAttribute(HTML.ATTR_CLASS, styleClass);
+ }
+
+ // create 'Clear' button
+ nsIDOMElement clearButton = visualDocument.createElement(HTML.TAG_BUTTON);
+ clearButton.appendChild(visualDocument.createTextNode(CLEAR_BUTTON));
+ clearButton.setAttribute(HTML.ATTR_TYPE, HTML.VALUE_TYPE_BUTTON);
+
+ divElement.appendChild(clearButton);
+
+ //
================================================================================
+ // Check if template component has children elements
+ // ================================================================================
+ List<Node> list = ComponentUtil.getChildren(sourceElement, true);
+ VpeCreationData creationData = null;
+ if (list != null && list.size() > 0) {
+ nsIDOMElement rootDiv = visualDocument.createElement(HTML.TAG_DIV);
+
+ // this element is used to contains template children
+ nsIDOMElement childDiv = visualDocument.createElement(HTML.TAG_DIV);
+
+ rootDiv.appendChild(childDiv);
+ rootDiv.appendChild(divElement);
+
+ // Create return variable contains template
+ creationData = new VpeCreationData(rootDiv);
+ VpeChildrenInfo divInfo = new VpeChildrenInfo(childDiv);
+ creationData.addChildrenInfo(divInfo);
+ for (Node child : list) {
+ divInfo.addSourceChild(child);
+ }
+ } else {
+ creationData = new VpeCreationData(divElement);
+ }
+
+ return creationData;
+ }
+}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml 2009-02-09
13:04:32 UTC (rev 13542)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml 2009-02-09
13:10:30 UTC (rev 13543)
@@ -225,8 +225,10 @@
</vpe:template>
</vpe:tag>
- <vpe:tag name="a4j:log" case-sensitive="yes">
- <vpe:template children="no" modify="no" >
+ <vpe:tag name="a4j:log" case-sensitive="yes">
+ <vpe:template children="yes" modify="no"
+
class="org.jboss.tools.jsf.vpe.ajax4jsf.template.Ajax4JSFLogTemplate">
+ <vpe:pseudoContent defaultText="no" />
</vpe:template>
</vpe:tag>
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/log.xhtml
===================================================================
(Binary files differ)
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/log.xhtml.xml
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/log.xhtml.xml
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/log.xhtml.xml 2009-02-09
13:10:30 UTC (rev 13543)
@@ -0,0 +1,43 @@
+<tests>
+ <test id="log">
+ <DIV STYLE="overflow: auto; width: 800px; height: 600px;">
+ <BUTTON TYPE="button">Clear</BUTTON>
+ </DIV>
+ </test>
+ <test id="compliteLog">
+ <DIV>
+ <DIV>
+ <SPAN STYLE="-moz-user-modify: read-write;">
+ <SPAN CLASS="vpe-text">
+ f:verbatim
+ </SPAN>
+ </SPAN>
+ <SPAN CLASS="vpe-text">
+ Over Text For loadStyle
+ </SPAN>
+ </DIV>
+ <DIV STYLE="overflow: auto; color: red; background-color: red; width:
400px; height: 100px;"
+ CLASS="myClass">
+ <BUTTON TYPE="button">Clear</BUTTON>
+ </DIV>
+ </DIV>
+ </test>
+ <test id="compliteLog2">
+ <DIV>
+ <DIV>
+ <SPAN STYLE="-moz-user-modify: read-write;">
+ <SPAN CLASS="vpe-text">
+ f:verbatim
+ </SPAN>
+ </SPAN>
+ <SPAN CLASS="vpe-text">
+ Over Text For loadStyle
+ </SPAN>
+ </DIV>
+ <DIV STYLE="overflow: auto; color: red; background-color: red; width:
350px; height: 250px;"
+ CLASS="myClass">
+ <BUTTON TYPE="button">Clear</BUTTON>
+ </DIV>
+ </DIV>
+ </test>
+</tests>
\ No newline at end of file
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/src/org/jboss/tools/jsf/vpe/ajax4jsf/test/Ajax4JsfComponentContentTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/src/org/jboss/tools/jsf/vpe/ajax4jsf/test/Ajax4JsfComponentContentTest.java 2009-02-09
13:04:32 UTC (rev 13542)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/src/org/jboss/tools/jsf/vpe/ajax4jsf/test/Ajax4JsfComponentContentTest.java 2009-02-09
13:10:30 UTC (rev 13543)
@@ -70,7 +70,7 @@
}
public void testLog() throws Throwable {
- performInvisibleTagTest("components/log.xhtml", "log");
//$NON-NLS-1$ //$NON-NLS-2$
+ performContentTest("components/log.xhtml"); //$NON-NLS-1$
}
public void testMediaOutput() throws Throwable {
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 2009-02-09
13:04:32 UTC (rev 13542)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2009-02-09
13:10:30 UTC (rev 13543)
@@ -141,6 +141,7 @@
public static final String STYLE_PARAMETER_MAX_HEIGHT = "max-height";
//$NON-NLS-1$
public static final String STYLE_PARAMETER_ZINDEX = "z-index"; //$NON-NLS-1$
public static final String STYLE_PARAMETER_CLEAR = "clear"; //$NON-NLS-1$
+ public static final String STYLE_PARAMETER_OVERFLOW = "overflow";
//$NON-NLS-1$
public static final String STYLE_PARAMETER_TABLE_LAYOUT = "table-layout";
//$NON-NLS-1$
public static final String STYLE_VALUE_FIXED = "fixed"; //$NON-NLS-1$
public static final String STYLE_VALUE_MIDDLE = "middle"; //$NON-NLS-1$
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2009-02-09
13:04:32 UTC (rev 13542)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2009-02-09
13:10:30 UTC (rev 13543)
@@ -189,6 +189,41 @@
return null;
}
+ /**
+ * This method is used to get parameter value from <code>style</code>
attribute.
+ * For instance, in case of style="width:65px; color:red" for parameter
<code>color</code>
+ * method should return <code>red</code> string value.
+ *
+ * @param styleAttr the style attribute value
+ * @param parameter the name of parameter of style attribute
+ * @return the parameter value
+ */
+ public static String getParameterFromStyleAttribute(String style, String parameter)
{
+ if (style == null || EMPTY_STRING.equals(style)) {
+ return null;
+ }
+ int parameterPosition = style.indexOf(parameter);
+ if (parameterPosition >= 0) {
+ int valuePosition = style.indexOf(COLON_STRING, parameterPosition);
+ if (valuePosition >= 0) {
+ int endPosition = style.indexOf(SEMICOLON_STRING, valuePosition);
+ if (endPosition >= 0) {
+ style = style.substring(valuePosition + 1, endPosition).trim();
+ endPosition = style.indexOf(PX_STRING, valuePosition);
+ if (endPosition >= 0) {
+ return style.substring(valuePosition + 1, endPosition).trim();
+ }
+ return style;
+ } else {
+ // last parameter ends without closing semicolon symbol
+ return style.substring(valuePosition + 1).trim();
+ }
+ }
+ }
+
+ return null;
+ }
+
// sets value of parameter described in sizeAttribute, for example
// "style.width"
public static void setSizeInStyle(Element sourceElement,