Author: yradtsevich
Date: 2009-12-15 07:42:13 -0500 (Tue, 15 Dec 2009)
New Revision: 19274
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputScriptTemplate.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5382/
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5382/OpenOnJsf20.xhtml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/OpenOnJsf20Test_JBIDE5382.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/util/SeamUtil.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java
Log:
issue JBIDE-5382: add openOn action for name param for h:outputStylesheet, h:outputScript
jsf 2.0 tags.
https://jira.jboss.org/jira/browse/JBIDE-5382
- added support of openOn for source nodes
- added support of openOn for visual nodes
- created JUnit tests for this functionality
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml 2009-12-15 11:37:27 UTC (rev
19273)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml 2009-12-15 12:42:13 UTC (rev
19274)
@@ -407,9 +407,17 @@
class="org.jboss.tools.jsf.text.ext.hyperlink.JSFJSPLinkHyperlinkPartitioner">
<contentType id="org.eclipse.jst.jsp.core.jspsource">
<partitionType id="org.jboss.tools.common.text.ext.jsp.JSP_LINK"
/>
+ <partitionType
id="org.jboss.tools.common.text.ext.xml.XML_ATTRIBUTE_VALUE">
+ <axis
path="*/[http://java.sun.com/jsf/html]:outputStylesheet/name/" />
+ <axis
path="*/[http://java.sun.com/jsf/html]:outputScript/name/"
/>
+ </partitionType>
</contentType>
<contentType id="org.eclipse.wst.html.core.htmlsource">
<partitionType id="org.jboss.tools.common.text.ext.jsp.JSP_LINK"
/>
+ <partitionType
id="org.jboss.tools.common.text.ext.xml.XML_ATTRIBUTE_VALUE">
+ <axis
path="*/[http://java.sun.com/jsf/html]:outputStylesheet/name/" />
+ <axis
path="*/[http://java.sun.com/jsf/html]:outputScript/name/"
/>
+ </partitionType>
</contentType>
</hyperlinkPartitioner>
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputScriptTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputScriptTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputScriptTemplate.java 2009-12-15
12:42:13 UTC (rev 19274)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.jsf.template;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
+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.NodesManagingUtil;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Node;
+
+/**
+ * Template for h:outputScript .
+ *
+ * @author yradtsevich
+ */
+public class JsfOutputScriptTemplate extends VpeAbstractTemplate {
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ // invisible tag
+ return new VpeCreationData(null);
+ }
+
+ @Override
+ public IRegion getSourceRegionForOpenOn(VpePageContext pageContext,
+ Node sourceNode, nsIDOMNode domNode) {
+ IRegion region = null;
+ Node node = sourceNode.getAttributes().getNamedItem(JSF.ATTR_NAME);
+ if (node != null) {
+ region = new Region(NodesManagingUtil.getStartOffsetNode(node),
+ NodesManagingUtil.getNodeLength(node));
+ }
+ return region;
+ }
+}
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 2009-12-15
11:37:27 UTC (rev 19273)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2009-12-15
12:42:13 UTC (rev 19274)
@@ -901,19 +901,23 @@
becouse it's not specified correctly in jsf lib, mareshkau -->
<!-- <vpe:if test="tld_version('min=2.0')"> -->
- <vpe:template children="no" modify="no"/>
+ <vpe:template children="no" modify="no"
+ class="org.jboss.tools.jsf.vpe.jsf.template.JsfOutputScriptTemplate"/>
<!-- </vpe:if> -->
</vpe:tag>
<!--
Tag h:outputStylesheet can have any of next attributes: name, library, target.
Value of target could be either 'head' or 'body'.
- Mojarra 2.0 EDR1 implementation of JSF 2.0 links a stylesheet as follows:
+ Mojarra 2.0 EDR1 implementation of JSF 2.0 links a stylesheet as follows:
<link type="text/css" rel="stylesheet"
href="{facesContext.getApplication().getResourceHandler().createResource(name,
library).getRequestPath()}"/>
+
+ NOTE: See VpeHtmlTemplate.getSourceRegionForOpenOn(...)
+ for OpenOn implementation.
-->
<vpe:tag name="h:outputStylesheet" case-sensitive="yes">
- <!-- Checks for min tld version has been comented,
+ <!-- Checks for min tld version has been comented,
becouse it's not specified correctly in jsf lib, mareshkau -->
<!-- <vpe:if test="tld_version('min=2.0')"> -->
<vpe:template children="no" modify="no">
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/util/SeamUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/util/SeamUtil.java 2009-12-15
11:37:27 UTC (rev 19273)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.seam/src/org/jboss/tools/jsf/vpe/seam/template/util/SeamUtil.java 2009-12-15
12:42:13 UTC (rev 19274)
@@ -55,29 +55,11 @@
Node sourceNode, String parentName) {
Node parentNode = sourceNode.getParentNode();
+ VpeTemplateManager templateManager = VpeTemplateManager.getInstance();
while (parentNode != null) {
- String parentSourcePrefix = parentNode.getPrefix();
- if (parentSourcePrefix == null) {
- parentSourcePrefix = ""; //$NON-NLS-1$
- }
- List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(parentNode,
- pageContext);
- TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(
- parentSourcePrefix, taglibs);
-
- String parentNodeName = parentNode.getNodeName();
- if (sourceNodeTaglib != null) {
- String sourceNodeUri = sourceNodeTaglib.getUri();
- String templateTaglibPrefix = VpeTemplateManager.getInstance()
- .getTemplateTaglibPrefix(sourceNodeUri);
-
- if (templateTaglibPrefix != null) {
- parentNodeName = templateTaglibPrefix
- + ":" + parentNode.getLocalName(); //$NON-NLS-1$
- }
- }
- if (parentNodeName.equals(parentName)) {
+ if (parentName.equals(
+ templateManager.getTemplateName(pageContext, parentNode))) {
return parentNode;
}
parentNode = parentNode.getParentNode();
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5382/OpenOnJsf20.xhtml
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5382/OpenOnJsf20.xhtml
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5382/OpenOnJsf20.xhtml 2009-12-15
12:42:13 UTC (rev 19274)
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html">
+<h:head />
+<h:body>
+ <h:outputScript name="/resources/scripts/f1.js"
id="outputScript1"/>
+ <h:outputStylesheet name="/resources/css/stylesRed.css"
id="outputStylesheet1"/>
+ <h:outputStylesheet name="/resources/css/stylesBlue.css"
id="outputStylesheetBlue"/>
+ <span>Blue text</span>
+</h:body>
+</html>
\ No newline at end of file
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java 2009-12-15
11:37:27 UTC (rev 19273)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java 2009-12-15
12:42:13 UTC (rev 19274)
@@ -67,6 +67,7 @@
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE4509Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE4510Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE4534Test;
+import org.jboss.tools.jsf.vpe.jsf.test.jbide.OpenOnJsf20Test_JBIDE5382;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.TestFViewLocaleAttribute_JBIDE5218;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE675Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE788Test;
@@ -110,6 +111,7 @@
// $JUnit-BEGIN$
suite.addTestSuite(TestForUsingComponentsLibrariesWithDefaultNamespace.class);
suite.addTestSuite(EditingSPecialSymbolsVPE_JBIDE3810.class);
+ suite.addTestSuite(OpenOnJsf20Test_JBIDE5382.class);
suite.addTestSuite(MozDirtyTest_JBIDE5105.class);
suite.addTestSuite(VpeI18nTest_JBIDE4887.class);
suite.addTestSuite(JsfComponentTest.class);
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/OpenOnJsf20Test_JBIDE5382.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/OpenOnJsf20Test_JBIDE5382.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/OpenOnJsf20Test_JBIDE5382.java 2009-12-15
12:42:13 UTC (rev 19274)
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * 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.jsf.test.jbide;
+
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
+import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
+import org.jboss.tools.vpe.ui.test.OpenOnUtil;
+import org.jboss.tools.vpe.ui.test.TestUtil;
+import org.jboss.tools.vpe.ui.test.VpeTest;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Tests for the OpenOn actions in JSF 2.0 projects.
+ *
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class OpenOnJsf20Test_JBIDE5382 extends VpeTest {
+ private static final String OUTPUT_STYLESHEET_ELEMENT_ID
+ = "outputStylesheet1"; //$NON-NLS-1$
+ private static final String OUTPUT_SCRIPT_ELEMENT_ID
+ = "outputScript1"; //$NON-NLS-1$
+ private static final String SCRIPT_FILE_NAME = "f1.js"; //$NON-NLS-1$
+ private static final String STYLESHEET_FILE_NAME
+ = "stylesRed.css"; //$NON-NLS-1$
+ private static final String TEST_FILE_PATH
+ = "JBIDE/5382/OpenOnJsf20.xhtml"; //$NON-NLS-1$
+ private VpeController vpeController;
+ private Document sourceDocument;
+
+ public OpenOnJsf20Test_JBIDE5382(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ vpeController = openInVpe(JsfAllTests.IMPORT_JSF_20_PROJECT_NAME,
+ TEST_FILE_PATH);
+ sourceDocument = getSourceDocument(vpeController);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // JUNIT TESTING METHODS
+
+ public void testSourceOpenOnOutputStylesheet() throws Throwable {
+ openOnSourceNode(getOutputStylesheetNode()
+ .getAttributeNode(JSF.ATTR_NAME));
+ assertActiveEditorInputNameEquals(STYLESHEET_FILE_NAME);
+ }
+
+ public void testSourceOpenOnOutputScript() throws Throwable {
+ openOnSourceNode(getOutputScriptNode().getAttributeNode(JSF.ATTR_NAME));
+ assertActiveEditorInputNameEquals(SCRIPT_FILE_NAME);
+ }
+
+ public void testVisualOpenOnOutputStylesheet() {
+ showInvisibleTags();
+ openOnCorrespondingVisualNode(getOutputStylesheetNode());
+ assertActiveEditorInputNameEquals(STYLESHEET_FILE_NAME);
+ }
+
+ public void testVisualOpenOnOutputScript() {
+ showInvisibleTags();
+ openOnCorrespondingVisualNode(getOutputScriptNode());
+ assertActiveEditorInputNameEquals(SCRIPT_FILE_NAME);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // PRIVATE METHODS
+
+ private Element getOutputScriptNode() {
+ return sourceDocument.getElementById(OUTPUT_SCRIPT_ELEMENT_ID);
+ }
+
+ private Element getOutputStylesheetNode() {
+ return sourceDocument.getElementById(OUTPUT_STYLESHEET_ELEMENT_ID);
+ }
+
+ private void openOnSourceNode(Node sourceNode) throws Throwable {
+ int offset = NodesManagingUtil.getStartOffsetNode(sourceNode);
+ OpenOnUtil.performOpenOnAction(vpeController.getSourceEditor(), offset);
+ }
+
+ private void openOnCorrespondingVisualNode(Node sourceNode) {
+ nsIDOMNode visualNode = vpeController.getDomMapping()
+ .getNearVisualNode(sourceNode);
+ vpeController.getSourceBuilder().openOn(visualNode);
+ }
+
+ private void showInvisibleTags() {
+ vpeController.getVisualBuilder().setShowInvisibleTags(true);
+ vpeController.visualRefresh();
+ TestUtil.waitForIdle();
+ }
+
+ private void assertActiveEditorInputNameEquals(String expectedName) {
+ IEditorPart activeEditorPart = (IEditorPart) PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().getActivePart();
+ String actualName = activeEditorPart.getEditorInput().getName();
+
+ assertEquals("No file is opened or a wrong file " //$NON-NLS-1$
+ + "is opened on the OpenOn action .", //$NON-NLS-1$
+ expectedName, actualName);
+ }
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java 2009-12-15
11:37:27 UTC (rev 19273)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java 2009-12-15
12:42:13 UTC (rev 19274)
@@ -554,16 +554,23 @@
public IRegion getSourceRegionForOpenOn(VpePageContext pageContext,
Node sourceNode, nsIDOMNode domNode) {
if(sourceNode != null && sourceNode instanceof Element) {
+ Element sourceElement = (Element) sourceNode;
+ String templateName = VpeTemplateManager.getInstance()
+ .getTemplateName(pageContext, sourceElement);
+
Attr file = null;
- if ("jsp:directive.include".equals(sourceNode.getNodeName())) {
//$NON-NLS-1$
- file = ((Element)sourceNode).getAttributeNode("file"); //$NON-NLS-1$
- } else if ("jsp:include".equals(sourceNode.getNodeName())) {
//$NON-NLS-1$
- file = ((Element)sourceNode).getAttributeNode("page"); //$NON-NLS-1$
- } else if(HTML.TAG_A.equalsIgnoreCase(sourceNode.getNodeName())) {
- file = ((Element)sourceNode).getAttributeNode(HTML.ATTR_HREF);
+ if ("jsp:directive.include".equals(templateName)) { //$NON-NLS-1$
+ file = sourceElement.getAttributeNode("file"); //$NON-NLS-1$
+ } else if ("jsp:include".equals(templateName)) { //$NON-NLS-1$
+ file = sourceElement.getAttributeNode("page"); //$NON-NLS-1$
+ } else if (HTML.TAG_A.equalsIgnoreCase(templateName)) {
+ file = sourceElement.getAttributeNode(HTML.ATTR_HREF);
+ } else if ("h:outputStylesheet".equals(templateName)) { //$NON-NLS-1$
+ file = sourceElement.getAttributeNode("name"); //$NON-NLS-1$
}
- if(file!=null) {
- return new Region(NodesManagingUtil.getStartOffsetNode(file),0);
+
+ if(file != null) {
+ return new Region(NodesManagingUtil.getStartOffsetNode(file), 0);
}
}
return null;