[jbosstools-commits] JBoss Tools SVN: r17707 - in trunk: jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/4713 and 4 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Sep 23 15:12:30 EDT 2009


Author: yradtsevich
Date: 2009-09-23 15:12:29 -0400 (Wed, 23 Sep 2009)
New Revision: 17707

Added:
   trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/4713/
   trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/4713/SelectWholeElement_JBIDE4713.html
   trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/SelectWholeElement_JBIDE4713.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/template/SelectionManager.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java
Log:
RESOLVED - issue JBIDE-4713: Visual selection isn't correct from selection bar.
https://jira.jboss.org/jira/browse/JBIDE-4713
 - fixed
 - added JUnit test

Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/4713/SelectWholeElement_JBIDE4713.html
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/4713/SelectWholeElement_JBIDE4713.html	                        (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/4713/SelectWholeElement_JBIDE4713.html	2009-09-23 19:12:29 UTC (rev 17707)
@@ -0,0 +1,9 @@
+<html>
+	<body>
+		<form>
+			BEFORE
+			<h1 id="selected-element">H1</h1>
+			AFTER
+		</form>
+	</body>
+</html>

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-09-23 16:09:52 UTC (rev 17706)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java	2009-09-23 19:12:29 UTC (rev 17707)
@@ -77,6 +77,7 @@
 import org.jboss.tools.jsf.vpe.jsf.test.jbide.JsfJbide2362Test;
 import org.jboss.tools.jsf.vpe.jsf.test.jbide.OpenOnCssClassTest_JBIDE4775;
 import org.jboss.tools.jsf.vpe.jsf.test.jbide.SelectAllAndCut_JBIDE4853;
+import org.jboss.tools.jsf.vpe.jsf.test.jbide.SelectWholeElement_JBIDE4713;
 import org.jboss.tools.jsf.vpe.jsf.test.jbide.VPERefreshTest;
 import org.jboss.tools.tests.ImportBean;
 import org.jboss.tools.vpe.ui.test.VpeTestSetup;
@@ -104,6 +105,7 @@
 		suite.addTestSuite(JBIDE3519Test.class);
 		suite.addTestSuite(ContextMenuDoubleInsertionTest_JBIDE3888.class);
 		suite.addTestSuite(SelectAllAndCut_JBIDE4853.class);
+		suite.addTestSuite(SelectWholeElement_JBIDE4713.class);
 		suite.addTestSuite(JBIDE4037Test.class);
 		suite.addTestSuite(JBIDE3734Test.class);
 		suite.addTestSuite(JBIDE3617Test.class);

Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/SelectWholeElement_JBIDE4713.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/SelectWholeElement_JBIDE4713.java	                        (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/SelectWholeElement_JBIDE4713.java	2009-09-23 19:12:29 UTC (rev 17707)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
+import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.SelectionUtil;
+import org.jboss.tools.vpe.ui.test.TestUtil;
+import org.jboss.tools.vpe.ui.test.VpeTest;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+
+/**
+ * Tests for JIRA issue JBIDE-4713:
+ * Visual selection isn't correct from selection bar.
+ * (https://jira.jboss.org/jira/browse/JBIDE-4713 )
+ * 
+ * @author yradtsevich
+ */
+public class SelectWholeElement_JBIDE4713 extends VpeTest {
+	private static final String TEST_PAGE_NAME
+			= "JBIDE/4713/SelectWholeElement_JBIDE4713.html"; //$NON-NLS-1$
+	private static final Point SELECTION_START = new Point(5, 13);
+	private static final Point SELECTION_END = new Point(5, 46);
+	private static final String SELECTED_ELEMENT_ID
+			= "selected-element"; //$NON-NLS-1$
+
+	public SelectWholeElement_JBIDE4713(String name) {
+		super(name);
+	}
+
+	public void testSelectWholeElement() throws Throwable {
+		VpeController vpeController = openInVpe(JsfAllTests.IMPORT_PROJECT_NAME,
+				TEST_PAGE_NAME);
+
+		StructuredTextViewer textViewer = vpeController.getSourceEditor()
+				.getTextViewer();
+		StyledText textWidget = textViewer.getTextWidget();
+
+		int selectionStartOffset = TestUtil.getLinePositionOffcet(
+				textViewer, SELECTION_START.x, SELECTION_START.y);
+		int selectionEndOffset = TestUtil.getLinePositionOffcet(
+				textViewer, SELECTION_END.x, SELECTION_END.y);
+
+		textViewer.setSelectedRange(selectionStartOffset,
+				selectionEndOffset - selectionStartOffset);
+		TestUtil.waitForIdle();
+
+		nsIDOMNode selectedNode = SelectionUtil.getLastSelectedNode(
+				vpeController.getPageContext()); 
+
+		assertTrue(selectedNode.getNodeType() == nsIDOMNode.ELEMENT_NODE);
+		nsIDOMElement element = (nsIDOMElement)
+				selectedNode.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+
+		assertEquals(SELECTED_ELEMENT_ID, element.getAttribute(HTML.ATTR_ID));
+	}
+}

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java	2009-09-23 16:09:52 UTC (rev 17706)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java	2009-09-23 19:12:29 UTC (rev 17707)
@@ -11,10 +11,7 @@
 
 package org.jboss.tools.vpe.editor.template;
 
-import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.swt.graphics.Point;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
 import org.eclipse.wst.sse.ui.StructuredTextEditor;
 import org.eclipse.wst.xml.core.internal.document.NodeImpl;
 import org.jboss.tools.vpe.editor.context.VpePageContext;
@@ -252,91 +249,72 @@
 	 */
 	final public void refreshVisualSelection() {
 
-		IStructuredModel model = null;
-		try {
-			// checks for null, for case when we close editor and background
-			// update job is running
-			if (getSourceEditor().getTextViewer() == null) {
+		// checks for null, for case when we close editor and background
+		// update job is running
+		if (getSourceEditor().getTextViewer() == null) {
 
-				return;
-			}
-			// gets source model for read, model should be released see
-			// JBIDE-2219
-			model = StructuredModelManager.getModelManager()
-					.getExistingModelForRead(
-							getSourceEditor().getTextViewer().getDocument());
-			
-			//fix for JBIDE-3805, mareshkau			
-			if(model==null) {
-				return;
-			}
-			
-			Point range = SelectionUtil
-					.getSourceSelectionRange(getSourceEditor());
+			return;
+		}
 
-			if (range == null)
-				return;
+		Point range = SelectionUtil
+				.getSourceSelectionRange(getSourceEditor());
 
-			int focusOffcetInSourceDocument = range.x;
+		if (range == null)
+			return;
 
-			int anchorOffcetInSourceDocument = focusOffcetInSourceDocument
-					+ range.y;
+		int focusOffcetInSourceDocument = range.x;
 
-			// get element mapping
-			VpeNodeMapping nodeMapping = SelectionUtil
-					.getNodeMappingBySourceSelection(model, getDomMapping(),
-							focusOffcetInSourceDocument,
-							anchorOffcetInSourceDocument);
+		int anchorOffcetInSourceDocument = focusOffcetInSourceDocument
+				+ range.y;
+		VpeNodeMapping nodeMapping = SelectionUtil
+				.getNodeMappingBySourceSelection(getSourceEditor(),
+						getDomMapping());
 
-			if (nodeMapping == null)
-				return;
+		if (nodeMapping == null) {
+			return;
+		}
 
-			// visual node which will be selected
-			nsIDOMNode targetVisualNode;
+		// visual node which will be selected
+		nsIDOMNode targetVisualNode;
 
-			// int visualNodeOffcet =
-			// TextUtil.visualPosition(((Node)targetSourceNode
-			// ).getNodeValue(),offcetReferenceToSourceNode);
+		// int visualNodeOffcet =
+		// TextUtil.visualPosition(((Node)targetSourceNode
+		// ).getNodeValue(),offcetReferenceToSourceNode);
 
-			// if mapping is elementMapping
-			
-			SelectionUtil.clearSelection(selectionController); 
-			
-			if (nodeMapping instanceof VpeElementMapping) {
+		// if mapping is elementMapping
+		
+		SelectionUtil.clearSelection(selectionController); 
+		
+		if (nodeMapping instanceof VpeElementMapping) {
 
-				VpeElementMapping elementMapping = (VpeElementMapping) nodeMapping;
+			VpeElementMapping elementMapping = (VpeElementMapping) nodeMapping;
 
-				VpeTemplate template = elementMapping.getTemplate();
+			VpeTemplate template = elementMapping.getTemplate();
 
-				targetVisualNode = template.getVisualNodeBySourcePosition(
-						elementMapping, focusOffcetInSourceDocument,
-						anchorOffcetInSourceDocument, getDomMapping());
+			targetVisualNode = template.getVisualNodeBySourcePosition(
+					elementMapping, focusOffcetInSourceDocument,
+					anchorOffcetInSourceDocument, getDomMapping());
 
-				NodeData nodeData = template.getNodeData(targetVisualNode,
-						elementMapping.getElementData(), getDomMapping());
-				// we can restore cursor position only if we have nodeData and
-				// range.y==0
-				if (nodeData != null) {
-					// restore cursor position in source document
-					restoreVisualCursorPosition(template, nodeData,
-							focusOffcetInSourceDocument,
-							anchorOffcetInSourceDocument);
-				}
-			} else {
+			NodeData nodeData = template.getNodeData(targetVisualNode,
+					elementMapping.getElementData(), getDomMapping());
+			// we can restore cursor position only if we have nodeData and
+			// range.y==0
+			if (nodeData != null) {
+				// restore cursor position in source document
+				restoreVisualCursorPosition(template, nodeData,
+						focusOffcetInSourceDocument,
+						anchorOffcetInSourceDocument);
+			}
+		} else {
 
-				targetVisualNode = nodeMapping.getVisualNode();
-				// restore cursor position for source node
+			targetVisualNode = nodeMapping.getVisualNode();
+			// restore cursor position for source node
 //				restoreVisualCursorPositionForTextNode(targetVisualNode,
 //						focusOffcetInSourceDocument, model);
-			}
-			// here we restore only highlight
-			getPageContext().getVisualBuilder().setSelectionRectangle(
-					targetVisualNode);
-		} finally {
-			if (model != null) {
-				model.releaseFromRead();
-			}
 		}
+		// here we restore only highlight
+		getPageContext().getVisualBuilder().setSelectionRectangle(
+				targetVisualNode);
 	}
 
 	/**

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java	2009-09-23 16:09:52 UTC (rev 17706)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java	2009-09-23 19:12:29 UTC (rev 17707)
@@ -119,6 +119,11 @@
 				offset, length);
 	}
 
+	/**
+	 * @deprecated This method causes JBIDE-4713. Use
+	 * {@link #getNodeMappingBySourceSelection(StructuredTextEditor, VpeDomMapping)}
+	 * instead.
+	 */
 	public static VpeNodeMapping getNodeMappingBySourceSelection(
 			IStructuredModel model, VpeDomMapping domMapping, int focus,
 			int anchor) {
@@ -228,8 +233,15 @@
 
 		IStructuredModel model = null;
 		try {
+			// gets source model for read, model should be released see
+			// JBIDE-2219
 			model = StructuredModelManager.getModelManager()
 					.getExistingModelForRead(document);
+			
+			//fix for JBIDE-3805, mareshkau			
+			if(model == null) {
+				return null;
+			}
 
 			int anchor = range.x;
 			int focus = range.x + range.y;



More information about the jbosstools-commits mailing list