Author: scabanovich
Date: 2010-12-09 09:43:42 -0500 (Thu, 09 Dec 2010)
New Revision: 27281
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/testJSFProject/WebContent/pages/hello2.jsp
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/TestPalette.java
Log:
JBIDE-5661
https://issues.jboss.org/browse/JBIDE-5661
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/testJSFProject/WebContent/pages/hello2.jsp
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/testJSFProject/WebContent/pages/hello2.jsp
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/testJSFProject/WebContent/pages/hello2.jsp 2010-12-09
14:43:42 UTC (rev 27281)
@@ -0,0 +1,21 @@
+<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib
uri="http://java.sun.com/jsp/jstl/functions"
prefix="fn2"%>
+
+<f:loadBundle var="Message" basename="demo.Messages" />
+
+<html>
+ <head>
+ <title>Hello!</title>
+ </head>
+
+ <body>
+ <f:view>
+ <h3>
+ <h:outputText value="#{Message.hello_message}" />,
+ <h:outputText value="#{user.name}" />!
+ </h3>
+ </f:view>
+ </body>
+
+</html>
\ No newline at end of file
Property changes on:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/testJSFProject/WebContent/pages/hello2.jsp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/TestPalette.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/TestPalette.java 2010-12-09
14:41:47 UTC (rev 27280)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/TestPalette.java 2010-12-09
14:43:42 UTC (rev 27281)
@@ -12,7 +12,10 @@
package org.jboss.tools.jsf.ui.test;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Properties;
+import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -25,6 +28,10 @@
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
import org.eclipse.gef.ui.views.palette.PalettePage;
import org.eclipse.gef.ui.views.palette.PaletteView;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewPart;
@@ -32,10 +39,16 @@
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.IPage;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.ui.views.palette.IPaletteAdapter;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.jsf.ui.JsfUiPlugin;
import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
import org.jboss.tools.jst.jsp.jspeditor.PalettePageImpl;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.JSPPaletteInsertHelper;
+import org.jboss.tools.jst.web.tld.model.helpers.TLDToPaletteHelper;
import org.jboss.tools.jst.web.ui.WebDevelopmentPerspectiveFactory;
import org.jboss.tools.test.util.ProjectImportTestSetup;
import org.jboss.tools.vpe.ui.palette.PaletteAdapter;
@@ -130,4 +143,69 @@
}
+ public void testTLDTagImport() throws Exception {
+ XModel model = EclipseResourceUtil.getModelNature(jsfProject).getModel();
+
+ XModelObject tld = model.getByPath("/META-INF/fmt.tld");
+ assertNotNull("Taglib /META-INF/fmt.tld is not found.", tld);
+ XModelObject g = new TLDToPaletteHelper().createGroupByTLD(tld, model);
+ assertNotNull(g);
+ XModelObject m = g.getChildByPath("timeZone");
+ assertNotNull("Macros timeZone was not created.", m);
+ assertEquals("Text of macros timeZone is not correct.", "<timeZone
value=\"|\">", m.getAttributeValue("start text"));
+ }
+
+ public void testTLDFunctionImport() throws Exception {
+ XModel model = EclipseResourceUtil.getModelNature(jsfProject).getModel();
+
+ XModelObject tld = model.getByPath("/META-INF/fn.tld");
+ assertNotNull("Taglib /META-INF/fn.tld is not found.", tld);
+ XModelObject g = new TLDToPaletteHelper().createGroupByTLD(tld, model);
+ assertNotNull(g);
+ assertEquals("Library uri is not set correctly to the palette group.",
"http://java.sun.com/jsp/jstl/functions", g.getAttributeValue("library
uri"));
+ System.out.println(g.getAttributeValue("library uri"));
+ XModelObject m = g.getChildByPath("containsIgnoreCase");
+ assertNotNull("Macros containsIgnoreCase was not created.", m);
+ assertEquals("Text of macros containsIgnoreCase is not correct.",
"${containsIgnoreCase('', '')}", m.getAttributeValue("start
text"));
+ }
+
+ public void testPaletteInsertHelper() throws Exception {
+ IWorkbench w = JsfUiPlugin.getDefault().getWorkbench();
+ IWorkbenchWindow window = w.getActiveWorkbenchWindow();
+
+ //open Web Development perspective
+ w.showPerspective(WebDevelopmentPerspectiveFactory.PERSPECTIVE_ID, window);
+
+ //open file
+ IFile f = jsfProject.getFile(new Path("WebContent/pages/hello2.jsp"));
+ assertNotNull(f);
+ IEditorPart editor = IDE.openEditor(window.getActivePage(), f);
+ assertNotNull(editor);
+ assertTrue(editor instanceof JSPMultiPageEditor);
+ JSPMultiPageEditor jspEditor = (JSPMultiPageEditor)editor;
+
+ //Test applying prefix
+ String[] text = {"${containsIgnoreCase('', '')}"};
+ JSPPaletteInsertHelper.applyPrefix(text, jspEditor.getSourceEditor(),
"containsIgnoreCase", "http://java.sun.com/jsp/jstl/functions",
"fn");
+ assertEquals("Prefix is not substituted correctly.",
"${fn2:containsIgnoreCase('', '')}", text[0]);
+
+ //Set selection in text editor.
+ int offset = 306;
+ ISelectionProvider selProvider = jspEditor.getSourceEditor().getSelectionProvider();
+ selProvider.setSelection(new TextSelection(offset, 0));
+
+ //Prepare parameters
+ ISourceViewer v =
(ISourceViewer)jspEditor.getSourceEditor().getAdapter(ISourceViewer.class);
+ assertNotNull(v);
+ Properties p = new Properties();
+ p.setProperty(PaletteInsertHelper.PROPOPERTY_TAG_NAME,
"containsIgnoreCase");
+ p.setProperty(PaletteInsertHelper.PROPOPERTY_START_TEXT,
"${containsIgnoreCase('', '')}");
+ p.setProperty(JSPPaletteInsertHelper.PROPOPERTY_TAGLIBRARY_URI,
"http://java.sun.com/jsp/jstl/functions");
+
+ //Execute insert into editor.
+ JSPPaletteInsertHelper.getInstance().insertIntoEditor(v, p);
+ IDocument doc =
jspEditor.getSourceEditor().getDocumentProvider().getDocument(editor.getEditorInput());
+ assertTrue(doc.get().indexOf("${fn2:containsIgnoreCase('',
'')}") >= 0);
+ }
+
}