Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2015-09-06 05:48:29 -0400
committerCarsten Hiesserich2015-09-06 15:10:51 -0400
commit2988515ed72d20fc9d45b823c43dab9690d1d996 (patch)
treeb6b8aa7a3dbef2220b94b1dc244d88521751cc6d
parent0b58700ed80b3699e2e80c2e90b8ebc4be1d7f43 (diff)
downloadorg.eclipse.mylyn.docs.vex-2988515ed72d20fc9d45b823c43dab9690d1d996.tar.gz
org.eclipse.mylyn.docs.vex-2988515ed72d20fc9d45b823c43dab9690d1d996.tar.xz
org.eclipse.mylyn.docs.vex-2988515ed72d20fc9d45b823c43dab9690d1d996.zip
fix error message and missing doctypes in .css file property page
The property page expected all document types to have a public id. As this is not the case for XML-Schemas (Vex uses the namespace name here), a NullPointerException was raised that caused the property dialog to show an error 'The currently displayed page contains illegal values'. Also all document types after the first XML-Schema were not displayed. With this change, the attribute 'publicId' in the <doctypeRef> element of the project xml is renamed to 'doctypeId'. For backward compatibility, the 'publicId' is still recognized when reading the config. Change-Id: Iaa9869c3b81bc9347b62a417e214b6fdc705954f Signed-off-by: Carsten Hiesserich <carsten.hie@gmail.com>
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigLoaderJobTest.java2
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java16
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginProjectTest.java17
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java102
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigItem.java5
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java2
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/Style.java40
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java12
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java10
9 files changed, 173 insertions, 33 deletions
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigLoaderJobTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigLoaderJobTest.java
index 434f526d..c9cb787f 100644
--- a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigLoaderJobTest.java
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigLoaderJobTest.java
@@ -53,6 +53,8 @@ public class ConfigLoaderJobTest {
final List<ConfigSource> allConfigSources = job.getLoadedConfigSources();
assertContainsConfiguration(allConfigSources, name.getMethodName(), pluginProject.getFile("plugintest.dtd"), pluginProject.getFile("plugintest.css"));
assertContainsEachPluginOnlyOnce(allConfigSources);
+
+ pluginProject.delete(true, null);
}
@Test
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
index bf85db74..c84a4590 100644
--- a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
@@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.List;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.vex.ui.internal.config.ConfigEvent;
import org.eclipse.vex.ui.internal.config.ConfigLoaderJob;
import org.eclipse.vex.ui.internal.config.ConfigSource;
@@ -42,12 +43,21 @@ import org.junit.rules.TestName;
public class ConfigurationRegistryTest {
private ConfigurationRegistry registry;
+ private IProject project;
@Rule
public TestName name = new TestName();
@After
public void disposeRegistry() {
+ if (project != null) {
+ try {
+ project.delete(true, null);
+ } catch (final CoreException e) {
+ }
+ }
+ project = null;
+
if (registry != null) {
registry.dispose();
}
@@ -78,7 +88,7 @@ public class ConfigurationRegistryTest {
registry.addConfigListener(configListener);
registry.loadConfigurations();
configListener.reset();
- final IProject project = PluginProjectTest.createVexPluginProject(name.getMethodName());
+ project = PluginProjectTest.createVexPluginProject(name.getMethodName());
assertFalse(configListener.loaded);
assertTrue(configListener.changed);
assertNotNull(registry.getPluginProject(project));
@@ -88,7 +98,7 @@ public class ConfigurationRegistryTest {
public void reloadModifiedPluginProjectAndFireConfigChangedEvent() throws Exception {
registry = new ConfigurationRegistryImpl(new MockConfigurationLoader());
registry.loadConfigurations();
- final IProject project = PluginProjectTest.createVexPluginProject(name.getMethodName());
+ project = PluginProjectTest.createVexPluginProject(name.getMethodName());
final MockConfigListener configListener = new MockConfigListener();
project.getFile("plugintest2.css").create(new ByteArrayInputStream(new byte[0]), true, null);
final String fileContent = PluginProjectTest.createVexPluginFileContent(project, "plugintest.dtd", "plugintest.css", "plugintest2.css");
@@ -104,7 +114,7 @@ public class ConfigurationRegistryTest {
public void removeDeletedPluginProjectAndFireConfigChangedEvent() throws Exception {
registry = new ConfigurationRegistryImpl(new MockConfigurationLoader());
registry.loadConfigurations();
- final IProject project = PluginProjectTest.createVexPluginProject(name.getMethodName());
+ project = PluginProjectTest.createVexPluginProject(name.getMethodName());
final MockConfigListener configListener = new MockConfigListener();
registry.addConfigListener(configListener);
project.getFile("plugintest.css").delete(true, null);
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginProjectTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginProjectTest.java
index 5cab74ce..ff0e63b9 100644
--- a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginProjectTest.java
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginProjectTest.java
@@ -26,6 +26,11 @@ import org.eclipse.vex.ui.internal.config.PluginProjectNature;
*/
public class PluginProjectTest {
+ public static final String CSS_FILE_NAME = "plugintest.css";
+ public static final String CSS_ID = "plugintest";
+ public static final String DTD_FILE_NAME = "plugintest.dtd";
+ public static final String DTD_DOCTYPE_ID = "-//Vex//Plugin Test//EN";
+
public static IProject createVexPluginProject(final String name) throws CoreException {
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
if (project.exists()) {
@@ -33,8 +38,8 @@ public class PluginProjectTest {
}
project.create(null);
project.open(null);
- project.getFile("plugintest.dtd").create(new ByteArrayInputStream(new byte[0]), true, null);
- project.getFile("plugintest.css").create(new ByteArrayInputStream(new byte[0]), true, null);
+ project.getFile(DTD_FILE_NAME).create(new ByteArrayInputStream(new byte[0]), true, null);
+ project.getFile(CSS_FILE_NAME).create(new ByteArrayInputStream(new byte[0]), true, null);
createVexPluginFile(project);
addVexProjectNature(project);
return project;
@@ -46,7 +51,7 @@ public class PluginProjectTest {
}
public static String createVexPluginFileContent(final IProject project) {
- return createVexPluginFileContent(project, "plugintest.dtd", "plugintest.css");
+ return createVexPluginFileContent(project, DTD_FILE_NAME, CSS_FILE_NAME);
}
public static String createVexPluginFileContent(final IProject project, final String dtdFilename, final String... styleFilenames) {
@@ -55,12 +60,12 @@ public class PluginProjectTest {
out.println("<?xml version='1.0'?>"); //$NON-NLS-1$
// HINT: It is important to set the id attribute, because this is used as the unique identifier for the configuration.
out.println("<plugin id=\"" + project.getName() + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
- out.println("<extension id=\"plugintest\" name=\"plugin test doctype\" point=\"org.eclipse.vex.ui.doctypes\">"); //$NON-NLS-1$
- out.println("<doctype systemId=\"" + dtdFilename + "\" dtd=\"" + dtdFilename + "\" publicId=\"-//Vex//Plugin Test//EN\" />"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ out.println("<extension id=\"plugintest\" name=\"" + DTD_FILE_NAME + "\" point=\"org.eclipse.vex.ui.doctypes\">"); //$NON-NLS-1$ //$NON-NLS-2$
+ out.println("<doctype systemId=\"" + dtdFilename + "\" dtd=\"" + dtdFilename + "\" publicId=\"" + DTD_DOCTYPE_ID + "\" />"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
out.println("</extension>"); //$NON-NLS-1$
for (final String styleFilename : styleFilenames) {
out.println("<extension id=\"plugintest\" name=\"plugin test style\" point=\"org.eclipse.vex.ui.styles\">"); //$NON-NLS-1$
- out.println("<style css=\"" + styleFilename + "\"><doctypeRef publicId=\"-//Vex//Plugin Test//EN\" /></style>"); //$NON-NLS-1$ //$NON-NLS-2$
+ out.println("<style css=\"" + styleFilename + "\"><doctypeRef publicId=\"" + DTD_DOCTYPE_ID + "\" /></style>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
out.println("</extension>"); //$NON-NLS-1$
}
out.println("</plugin>"); //$NON-NLS-1$
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java
new file mode 100644
index 00000000..36fdadd3
--- /dev/null
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.config.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.vex.ui.internal.config.ConfigLoaderJob;
+import org.eclipse.vex.ui.internal.config.ConfigurationRegistry;
+import org.eclipse.vex.ui.internal.config.ConfigurationRegistryImpl;
+import org.eclipse.vex.ui.internal.config.DocumentType;
+import org.eclipse.vex.ui.internal.config.Style;
+import org.eclipse.vex.ui.internal.config.StylePropertyPage;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * Tests for the CSS styles definition in a Vex Plugin Project
+ *
+ * @author chi
+ *
+ */
+public class PluginStyleConfigTest {
+
+ private IProject pluginProject;
+
+ @After
+ public void dispose() {
+ if (pluginProject != null) {
+ try {
+ pluginProject.delete(true, null);
+ } catch (final CoreException e) {
+ }
+ }
+ pluginProject = null;
+ }
+
+ /**
+ * Make sure the property page is created without errors.
+ */
+ @Test
+ public void testCssPropertyPage() throws CoreException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ final IProject pluginProject = PluginProjectTest.createVexPluginProject("PropertyPageTest");
+
+ final Display display = Display.getCurrent();
+ final Shell shell = new Shell(display);
+ final StylePropertyPage page = new StylePropertyPage();
+
+ page.setElement(pluginProject.getFile(PluginProjectTest.CSS_FILE_NAME));
+ page.createControl(shell);
+
+ // Make sure the table contains the style declared in the plugin project
+ final Field f = page.getClass().getDeclaredField("doctypesTable");
+ f.setAccessible(true);
+ final Table doctypesTable = (Table) f.get(page);
+ final ArrayList<String> doctypes = new ArrayList<String>();
+ for (final TableItem item : doctypesTable.getItems()) {
+ if (item.getChecked()) {
+ // The item should be selected
+ doctypes.add(item.getText());
+ }
+ }
+ assertTrue("Doctype defined by plugin project should be selected", doctypes.contains(PluginProjectTest.DTD_FILE_NAME));
+
+ page.dispose();
+ }
+
+ @Test
+ public void testDoctypeStyle() throws Exception {
+ final IProject pluginProject = PluginProjectTest.createVexPluginProject("PropertyPageTest");
+
+ final ConfigurationRegistry configurationRegistry = new ConfigurationRegistryImpl(new ConfigLoaderJob());
+ configurationRegistry.loadConfigurations();
+ assertNotNull(configurationRegistry.getPluginProject(pluginProject));
+
+ final DocumentType doctype = configurationRegistry.getDocumentType(PluginProjectTest.DTD_DOCTYPE_ID, null);
+ assertNotNull(doctype);
+ final Style[] styles = configurationRegistry.getStyles(doctype);
+
+ assertEquals(styles[0], configurationRegistry.getStyle("PropertyPageTest." + PluginProjectTest.CSS_ID));
+
+ configurationRegistry.dispose();
+ }
+}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigItem.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigItem.java
index 57b95fa8..9086c771 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigItem.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigItem.java
@@ -140,6 +140,11 @@ public abstract class ConfigItem implements Comparable<ConfigItem> {
this.id = id;
}
+ @Override
+ public String toString() {
+ return getUniqueId();
+ }
+
// ==================================================== PRIVATE
private String id;
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java
index 3f1c4d1a..977b7929 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java
@@ -89,7 +89,7 @@ public class ConfigurationView extends ViewPart {
return VexPlugin.getDefault().getConfigurationRegistry();
}
if (element instanceof Style) {
- return VexPlugin.getDefault().getConfigurationRegistry().getDocumentType(((Style) element).getDocumentTypes().iterator().next(), null);
+ return VexPlugin.getDefault().getConfigurationRegistry().getDocumentType(((Style) element).getDocumentTypeIds().iterator().next(), null);
}
return null;
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/Style.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/Style.java
index 9fac6f01..67898b01 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/Style.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/Style.java
@@ -33,21 +33,33 @@ public class Style extends ConfigItem {
/**
* Adds the public ID of a document type to which the style applies.
*
- * @param publicId
- * public ID of the document type
+ * @param id
+ * the ID of the document type (e.g. the public id or namespace name)
*/
- public void addDocumentType(final String publicId) {
- publicIds.add(publicId);
+ public void addDocumentType(final String id) {
+ if (id != null) {
+ doctypeIds.add(id);
+ }
}
/**
- * Returns true if this style applies to the documents with the given type.
+ * Returns true if this style applies to the documents with the given id.
*
- * @param publicId
- * public ID of the document type being sought
+ * @param id
+ * the ID of the document type (e.g. the public id or namespace name) being sought
+ */
+ public boolean appliesTo(final String id) {
+ return id != null && doctypeIds.contains(id);
+ }
+
+ /**
+ * Returns true if this style applies to the documents with the given id.
+ *
+ * @param id
+ * the ID of the document type (e.g. the public id or namespace name) being sought
*/
- public boolean appliesTo(final String publicId) {
- return publicIds.contains(publicId);
+ public boolean appliesTo(final DocumentType doctype) {
+ return doctype != null && (doctypeIds.contains(doctype.getSimpleId()) || doctypeIds.contains(doctype.getMainId()));
}
/**
@@ -60,8 +72,8 @@ public class Style extends ConfigItem {
/**
* Returns a set of public IDs of all document types supported by this style.
*/
- public Set<String> getDocumentTypes() {
- return Collections.unmodifiableSet(publicIds);
+ public Set<String> getDocumentTypeIds() {
+ return Collections.unmodifiableSet(doctypeIds);
}
/**
@@ -80,7 +92,7 @@ public class Style extends ConfigItem {
* Disassociates this style from all document types.
*/
public void removeAllDocumentTypes() {
- publicIds.clear();
+ doctypeIds.clear();
}
/**
@@ -90,7 +102,7 @@ public class Style extends ConfigItem {
* public ID of the document type
*/
public void removeDocumentType(final String publicId) {
- publicIds.remove(publicId);
+ doctypeIds.remove(publicId);
}
/**
@@ -106,6 +118,6 @@ public class Style extends ConfigItem {
// ===================================================== PRIVATE
private BoxFactory boxFactory;
- private final Set<String> publicIds = new HashSet<String>();
+ private final Set<String> doctypeIds = new HashSet<String>();
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java
index d4e36835..05c44d05 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java
@@ -32,9 +32,9 @@ public class StyleFactory implements IConfigItemFactory {
final Style style = (Style) item;
final ConfigurationElement element = new ConfigurationElement("style"); //$NON-NLS-1$
element.setAttribute("css", style.getResourceUri().toString()); //$NON-NLS-1$
- for (final String publicId : style.getDocumentTypes()) {
+ for (final String doctypeId : style.getDocumentTypeIds()) {
final ConfigurationElement child = new ConfigurationElement("doctypeRef"); //$NON-NLS-1$
- child.setAttribute("publicId", publicId); //$NON-NLS-1$
+ child.setAttribute("doctypeId", doctypeId); //$NON-NLS-1$
element.addChild(child);
}
return new IConfigElement[] { element };
@@ -54,7 +54,13 @@ public class StyleFactory implements IConfigItemFactory {
final IConfigElement[] doctypeRefs = configElement.getChildren();
for (final IConfigElement doctypeRef : doctypeRefs) {
- style.addDocumentType(doctypeRef.getAttribute("publicId")); //$NON-NLS-1$
+ if (doctypeRef.getAttribute("publicId") != null) {
+ // This is for compatibility to older versions
+ style.addDocumentType(doctypeRef.getAttribute("publicId")); //$NON-NLS-1$
+ }
+ if (doctypeRef.getAttribute("doctypeId") != null) {
+ style.addDocumentType(doctypeRef.getAttribute("doctypeId")); //$NON-NLS-1$
+ }
}
return style;
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
index 9380bf87..6089bb37 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 John Krasnay and others.
+ * Copyright (c) 2004, 2015 John Krasnay 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
@@ -8,14 +8,13 @@
* Contributors:
* John Krasnay - initial API and implementation
* Igor Jacy Lino Campista - Java 5 warnings fixed (bug 311325)
+ * Carsten Hiesserich - support for doctypes with no public id
*******************************************************************************/
package org.eclipse.vex.ui.internal.config;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Set;
-import java.util.TreeSet;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
@@ -160,7 +159,6 @@ public class StylePropertyPage extends PropertyPage {
}
private void populateDoctypes() {
- final Set<String> selectedDoctypes = new TreeSet<String>(style.getDocumentTypes());
doctypesTable.removeAll();
final DocumentType[] documentTypes = VexPlugin.getDefault().getConfigurationRegistry().getDocumentTypes();
@@ -168,7 +166,7 @@ public class StylePropertyPage extends PropertyPage {
for (final DocumentType documentType : documentTypes) {
final TableItem item = new TableItem(doctypesTable, SWT.NONE);
item.setText(documentType.getName());
- if (selectedDoctypes.contains(documentType.getPublicId())) {
+ if (style != null && style.appliesTo(documentType)) {
item.setChecked(true);
}
}
@@ -197,7 +195,7 @@ public class StylePropertyPage extends PropertyPage {
Arrays.sort(documentTypes);
for (final DocumentType documentType : documentTypes) {
if (selectedDoctypes.contains(documentType.getName())) {
- style.addDocumentType(documentType.getSimpleId());
+ style.addDocumentType(documentType.getMainId());
}
}

Back to the top