Reimplementation of DefaultOutlineProvider

The OutlineProvider now supports display of inline elements and element
content.

Change-Id: I479ac9556b6a1335f435493bab2133166802b33a
Signed-off-by: Carsten Hiesserich <carsten.hie@gmail.com>
diff --git a/org.eclipse.vex.ui.tests/.classpath b/org.eclipse.vex.ui.tests/.classpath
index a955886..288a780 100644
--- a/org.eclipse.vex.ui.tests/.classpath
+++ b/org.eclipse.vex.ui.tests/.classpath
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>

-<classpath>

-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>

-	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>

-	<classpathentry kind="src" path="src/"/>

-	<classpathentry kind="output" path="target/classes"/>

-</classpath>

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.vex.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.vex.ui.tests/META-INF/MANIFEST.MF
index 838b08a..afe1639 100644
--- a/org.eclipse.vex.ui.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.vex.ui.tests/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@
  org.eclipse.vex.core.tests;bundle-version="[1.0.0,2.0.0)",
  org.eclipse.vex.ui;bundle-version="[1.0.0,2.0.0)",
  org.junit;bundle-version="3.8.1",
- org.eclipse.jface.text;bundle-version="3.0.0"
+ org.eclipse.jface.text;bundle-version="3.0.0",
+ org.w3c.css.sac;bundle-version="[1.3.0,2.0.0)"
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Export-Package: org.eclipse.vex.ui.internal.config.tests;x-internal:=true,
  org.eclipse.vex.ui.internal.editor.tests;x-internal:=true,
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/outline/tests/OutlineProviderTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/outline/tests/OutlineProviderTest.java
new file mode 100644
index 0000000..9b759b4
--- /dev/null
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/outline/tests/OutlineProviderTest.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Carsten Hiesserich and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ *     Carsten Hiesserich - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.ui.internal.outline.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URL;
+
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.vex.core.internal.css.StyleSheet;
+import org.eclipse.vex.core.internal.css.StyleSheetReader;
+import org.eclipse.vex.core.internal.dom.Document;
+import org.eclipse.vex.core.internal.io.XMLFragment;
+import org.eclipse.vex.core.provisional.dom.IDocument;
+import org.eclipse.vex.core.provisional.dom.IDocumentFragment;
+import org.eclipse.vex.core.provisional.dom.IElement;
+import org.eclipse.vex.ui.internal.outline.DefaultOutlineProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("restriction")
+public class OutlineProviderTest {
+
+	private DefaultOutlineProvider outlineProvider;
+
+	@Before
+	public void setUp() throws Exception {
+		final URL url = this.getClass().getResource("/tests/resources/outlineTest.css");
+		final StyleSheet styleSheet = new StyleSheetReader().read(url);
+		outlineProvider = new DefaultOutlineProvider();
+		outlineProvider.init(styleSheet);
+	}
+
+	@Test
+	public void testContentProvider() throws Exception {
+		final IDocument doc = new Document(new QualifiedName(null, "root"));
+		final IElement parent = doc.insertElement(2, new QualifiedName(null, "parent"));
+		doc.insertElement(parent.getEndOffset(), new QualifiedName(null, "child"));
+		doc.insertElement(parent.getEndOffset(), new QualifiedName(null, "child"));
+
+		final Object[] outlineElements = outlineProvider.getContentProvider().getElements(doc);
+		assertEquals("Count of root elements", 1, outlineElements.length);
+		assertEquals(parent, outlineElements[0]);
+		final Object[] childElements = outlineProvider.getContentProvider().getChildren(parent);
+		assertEquals("Count of child elements", 2, childElements.length);
+	}
+
+	@Test
+	public void testLabelProviderWithoutContent() throws Exception {
+		final IDocument doc = new Document(new QualifiedName(null, "root"));
+		final IDocumentFragment fragment = new XMLFragment("<parent><title>titleText</title></parent>").getDocumentFragment();
+		doc.insertFragment(2, fragment);
+		final Object[] outlineElements = outlineProvider.getContentProvider().getElements(doc);
+		assertEquals("Count of root elements", 1, outlineElements.length);
+
+		outlineProvider.setState(DefaultOutlineProvider.SHOW_ELEMENT_CONTENT, false);
+
+		final IElement parent = (IElement) outlineElements[0];
+		assertEquals("Should return local name", "parent", outlineProvider.getOutlineLabel(parent).getString());
+
+		final IElement title = (IElement) outlineProvider.getContentProvider().getChildren(outlineElements[0])[0];
+		assertEquals("Should return local name", "title", outlineProvider.getOutlineLabel(title).getString());
+	}
+
+	@Test
+	public void testLabelProviderWithContent() throws Exception {
+		final IDocument doc = new Document(new QualifiedName(null, "root"));
+		final IDocumentFragment fragment = new XMLFragment("<parent><title>titleText</title></parent>").getDocumentFragment();
+		doc.insertFragment(2, fragment);
+		final Object[] outlineElements = outlineProvider.getContentProvider().getElements(doc);
+		assertEquals("Count of root elements", 1, outlineElements.length);
+
+		outlineProvider.setState(DefaultOutlineProvider.SHOW_ELEMENT_CONTENT, true);
+
+		final IElement parent = (IElement) outlineElements[0];
+		assertEquals("Should return local name:title content", "parent : titleText", outlineProvider.getOutlineLabel(parent).getString());
+
+		final IElement title = (IElement) outlineProvider.getContentProvider().getChildren(outlineElements[0])[0];
+		assertEquals("Should return local name:content", "title : titleText", outlineProvider.getOutlineLabel(title).getString());
+	}
+}
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java
index 571cb54..97aa94c 100644
--- a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009 Holger Voormann and others.
+ * Copyright (c) 2009, 2013 Holger Voormann and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
  *
  * Contributors:
  *     Holger Voormann - initial API and implementation
+ *     Carsten Hiesserich - added OutlineProvider tests
  *******************************************************************************/
 package org.eclipse.vex.ui.tests;
 
@@ -14,10 +15,11 @@
 import org.eclipse.vex.ui.internal.config.tests.ConfigurationRegistryTest;
 import org.eclipse.vex.ui.internal.editor.tests.FindReplaceTargetTest;
 import org.eclipse.vex.ui.internal.namespace.tests.EditNamespacesControllerTest;
+import org.eclipse.vex.ui.internal.outline.tests.OutlineProviderTest;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
 @RunWith(Suite.class)
-@Suite.SuiteClasses({ ConfigLoaderJobTest.class, ConfigurationRegistryTest.class, EditNamespacesControllerTest.class, FindReplaceTargetTest.class })
+@Suite.SuiteClasses({ ConfigLoaderJobTest.class, ConfigurationRegistryTest.class, EditNamespacesControllerTest.class, FindReplaceTargetTest.class, OutlineProviderTest.class })
 public class VexUiTestSuite {
 }
diff --git a/org.eclipse.vex.ui.tests/src/tests/resources/outlineTest.css b/org.eclipse.vex.ui.tests/src/tests/resources/outlineTest.css
new file mode 100644
index 0000000..66b7460
--- /dev/null
+++ b/org.eclipse.vex.ui.tests/src/tests/resources/outlineTest.css
@@ -0,0 +1,13 @@
+/* Styles for OutlineProvider tests */
+parent {
+  display: block;
+  -vex-outline-content: title;
+}
+
+title {
+  display: inline;
+}
+
+child {
+  display: block;
+}
\ No newline at end of file