Author: yradtsevich
Date: 2009-01-08 09:36:16 -0500 (Thu, 08 Jan 2009)
New Revision: 12930
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/3473/
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/3473/JBIDE-3473.html
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE3473Test.java
Modified:
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/util/VisualDomUtil.java
Log:
RESOLVED - issue JBIDE-3473: Something wrong with text processing inside table.
https://jira.jboss.org/jira/browse/JBIDE-3473
JUnit test has been written.
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/3473/JBIDE-3473.html
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/3473/JBIDE-3473.html
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/3473/JBIDE-3473.html 2009-01-08
14:36:16 UTC (rev 12930)
@@ -0,0 +1,32 @@
+<html>
+<head>
+<style type="text/css">
+table {
+ background-color: black;
+}
+td {
+ background-color: yellow;
+}
+</style>
+</head>
+<body>
+<table id="table-id">
+ <tr>
+ <td>
+ 1JSF Testssssssssssssssssssssssssssssss
+ </td>
+ <td>
+ 2JSF Testsssssssssssssssss
+ </td>
+ </tr>
+ <tr>
+ <td>
+ 3JSF Testssssssssssss
+ </td>
+ <td>
+ 4JSF Testssssssss
+ </td>
+ </tr>
+</table>
+</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-01-08
14:08:28 UTC (rev 12929)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java 2009-01-08
14:36:16 UTC (rev 12930)
@@ -47,6 +47,7 @@
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE3376Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE3396Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE3441Test;
+import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE3473Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE3482Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE675Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE788Test;
@@ -78,6 +79,7 @@
// $JUnit-BEGIN$
suite.addTestSuite(JsfComponentTest.class);
suite.addTestSuite(Jsf20ComponentContentTest.class);
+ suite.addTestSuite(JBIDE3473Test.class);
suite.addTestSuite(JBIDE3441Test.class);
suite.addTestSuite(JsfJbide1467Test.class);
suite.addTestSuite(JsfJbide1501Test.class);
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE3473Test.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE3473Test.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE3473Test.java 2009-01-08
14:36:16 UTC (rev 12930)
@@ -0,0 +1,109 @@
+package org.jboss.tools.jsf.vpe.jsf.test.jbide;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
+import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.VisualDomUtil;
+import org.jboss.tools.vpe.ui.test.TestUtil;
+import org.jboss.tools.vpe.ui.test.VpeTest;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Node;
+
+/**
+ * @author yradtsevich
+ *
+ */
+public class JBIDE3473Test extends VpeTest {
+ private static final int INSERTING_POSITION = 179;
+ private static final String TABLE_ID = "table-id"; //$NON-NLS-1$
+ private static final String TEST_PAGE_NAME = "JBIDE/3473/JBIDE-3473.html";
//$NON-NLS-1$
+ private static final String INSERTING_TEXT = " id=\"td-id\"";
//$NON-NLS-1$
+
+ public JBIDE3473Test(String name) {
+ super(name);
+ }
+
+ /**
+ * Adds 'id' attribute to TD tag inside a table and checks if
+ * there are not changes in the VPE view.
+ *
+ * @throws Throwable
+ */
+ public void testNodeUpdate() throws Throwable {
+ TestUtil.waitForJobs();
+ setException(null);
+
+ // get test page path
+ IFile file = (IFile) TestUtil.getComponentPath(TEST_PAGE_NAME,
+ JsfAllTests.IMPORT_PROJECT_NAME);
+ assertNotNull("Could not open specified file " + TEST_PAGE_NAME, file);
//$NON-NLS-1$
+
+ IEditorInput input = new FileEditorInput(file);
+
+ assertNotNull("Editor input is null", input); //$NON-NLS-1$
+
+ // open and get editor
+ JSPMultiPageEditor jspEditor = openEditor(input);
+
+ StyledText styledText = jspEditor.getSourceEditor().getTextViewer()
+ .getTextWidget();
+
+ styledText.setCaretOffset(INSERTING_POSITION);
+ IndexedRegion indexedRegion = ContentAssistUtils.getNodeAt(jspEditor
+ .getSourceEditor().getTextViewer(), INSERTING_POSITION);
+ Node tdTextEditorNode = (Node) indexedRegion;
+ assertNotNull(tdTextEditorNode);
+ assertTrue("Text under cursor is not TD node",
HTML.TAG_TD.equalsIgnoreCase(tdTextEditorNode.getNodeName())); //$NON-NLS-1$
+
+ VpeController vpeController = TestUtil.getVpeController(jspEditor);
+
+ Rectangle boundsBeforeInsert =
getBoundsOfElementById(vpeController.getXulRunnerEditor().getDOMDocument(), TABLE_ID);
+ assertNotNull("boundsBeforeInsert should be not null.", boundsBeforeInsert);
//$NON-NLS-1$
+
+ styledText.insert(INSERTING_TEXT); //$NON-NLS-1$
+ TestUtil.delay(450);
+ TestUtil.waitForJobs();
+
+ Rectangle boundsAfterInsert =
getBoundsOfElementById(vpeController.getXulRunnerEditor().getDOMDocument(), TABLE_ID);
+ assertNotNull("boundsAfterInsert should be not null.", boundsAfterInsert);
//$NON-NLS-1$
+
+ assertEquals("Width of the table has been changed.",
boundsBeforeInsert.width, boundsAfterInsert.width); //$NON-NLS-1$
+ assertEquals("Height of the table has been changed.",
boundsBeforeInsert.height, boundsAfterInsert.height); //$NON-NLS-1$
+
+ if(getException()!=null) {
+ throw getException();
+ }
+ }
+
+ /**
+ * Returns bounds of the element with given {@code id}
+ * from the {@code document}
+ *
+ * @param document the document
+ * @param id ID of the DOM element which bounds is needed
+ * @return bounds of the element with given {@code id}
+ * or {@code null} if the element is not found or not accessible
+ *
+ * @see VisualDomUtil#getBounds(nsIDOMNode)
+ */
+ private Rectangle getBoundsOfElementById(nsIDOMDocument document, String id) {
+ Rectangle bounds = null;
+
+ nsIDOMElement element = document.getElementById(id);
+ if (element != null) {
+ bounds = VisualDomUtil.getBounds(element);
+ }
+
+ return bounds;
+ }
+}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VisualDomUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VisualDomUtil.java 2009-01-08
14:08:28 UTC (rev 12929)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VisualDomUtil.java 2009-01-08
14:36:16 UTC (rev 12930)
@@ -10,9 +10,14 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.util;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
import java.util.List;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.mozilla.interfaces.nsIAccessibilityService;
+import org.mozilla.interfaces.nsIAccessible;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMEvent;
import org.mozilla.interfaces.nsIDOMMouseEvent;
@@ -22,6 +27,7 @@
import org.mozilla.interfaces.nsIDOMNodeList;
import org.mozilla.interfaces.nsIDOMRange;
import org.mozilla.interfaces.nsISelection;
+import org.mozilla.xpcom.Mozilla;
import org.mozilla.xpcom.XPCOMException;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -29,6 +35,8 @@
public class VisualDomUtil {
+ private static final String ACCESSIBILITY_SERVICE_CONTRACT_ID =
"(a)mozilla.org/accessibilityService;1";
+ private static Reference<nsIAccessibilityService> accessibilityServiceCache =
null;
static public nsIDOMNode getAncestorNode(nsIDOMNode visualNode, String tagName){
if (tagName == null) return null;
@@ -207,4 +215,52 @@
}
}
+
+ /**
+ * Returns instance of {@link nsIAccessibilityService}.
+ *
+ * @author yradtsevich
+ */
+ public static nsIAccessibilityService getAccessibilityService() {
+ nsIAccessibilityService accessibilityService = null;
+ if (accessibilityServiceCache != null) {
+ // get accessibilityService from cache
+ accessibilityService = accessibilityServiceCache.get();
+ }
+ if (accessibilityService == null) {
+ accessibilityService = (nsIAccessibilityService) Mozilla.getInstance()
+ .getServiceManager()
+ .getServiceByContractID(ACCESSIBILITY_SERVICE_CONTRACT_ID,
+ nsIAccessibilityService.NS_IACCESSIBILITYSERVICE_IID);
+
+ // cache accessibilityService
+ accessibilityServiceCache = new
SoftReference<nsIAccessibilityService>(accessibilityService);
+ }
+ return accessibilityService;
+ }
+
+ /**
+ * Returns on screen bounds of the {@code node}
+ *
+ * @param node cannot be {@code null}
+ * @return bounds of the {@code node} or {@code null} if it is not accessible
+ *
+ * @author yradtsevich
+ */
+ public static Rectangle getBounds(nsIDOMNode node) {
+ Rectangle bounds = null;
+
+ nsIAccessible accessible = getAccessibilityService().getAccessibleFor(node);
+ if (accessible != null) {
+ int[] xArray = new int[1]; // Left hand corner of the node
+ int[] yArray = new int[1]; // Top corner of the node
+ int[] widthArray = new int[1]; // Width of the node
+ int[] heightArray = new int[1]; // Height of the node
+
+ accessible.getBounds(xArray, yArray, widthArray, heightArray);
+ bounds = new Rectangle(xArray[0], yArray[0], widthArray[0], heightArray[0]);
+ }
+
+ return bounds;
+ }
}