From: Patric Plitzner
Date: Wed, 25 Feb 2015 06:31:03 +0000 (+0000)
Subject: - refactored cdmViewer extension point to be more generic
X-Git-Tag: 3.6.0~204
X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/b93817a3cdf6ce5a5984476c25cb089871044f56
- refactored cdmViewer extension point to be more generic
---
diff --git a/eu.etaxonomy.taxeditor.editor/plugin.xml b/eu.etaxonomy.taxeditor.editor/plugin.xml
index b2dc9bfa6..53080cc47 100644
--- a/eu.etaxonomy.taxeditor.editor/plugin.xml
+++ b/eu.etaxonomy.taxeditor.editor/plugin.xml
@@ -1617,13 +1617,6 @@
point="eu.etaxonomy.taxeditor.store.cdmViewer">
-
-
-
-
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
index 4a5b4ea8d..877ed28f4 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
@@ -9,6 +9,9 @@
*/
package eu.etaxonomy.taxeditor.editor;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.log4j.Logger;
import org.eclipse.ui.PartInitException;
@@ -31,15 +34,15 @@ public class EditorCdmViewer implements ICdmViewer {
* @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
*/
@Override
- public void show(Object input, String viewerClass) {
+ public void show(Object input, Class> viewerClass) {
try {
- if(viewerClass.equals(MultiPageTaxonEditor.class.toString())){
+ if(viewerClass.equals(MultiPageTaxonEditor.class)){
if(input instanceof TaxonBase){
TaxonEditorInput editorInput = TaxonEditorInput.NewInstanceFromTaxonBase(((TaxonBase>) input).getUuid());
EditorUtil.open(editorInput);
}
}
- else if(viewerClass.equals(DerivateView.class.toString())){
+ else if(viewerClass.equals(DerivateView.class)){
if(input instanceof SpecimenOrObservationBase){
}
}
@@ -50,4 +53,16 @@ public class EditorCdmViewer implements ICdmViewer {
}
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object)
+ */
+ @Override
+ public Map, String> getViewerClasses(Object input) {
+ Map, String> viewerNameMap = new HashMap, String>();
+ if(input instanceof TaxonBase){
+ viewerNameMap.put(MultiPageTaxonEditor.class, "Taxon Editor");
+ }
+ return viewerNameMap;
+ }
+
}
diff --git a/eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd b/eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd
index b7f2964c8..d885f0288 100644
--- a/eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd
+++ b/eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd
@@ -15,10 +15,13 @@
+
+ Extensions must provide and ICdmViewer which maps input elements to viewers which are able to display information for them.
+
-
-
+
+
@@ -55,7 +58,6 @@
-
@@ -70,56 +72,6 @@
-
-
-
- The input element which can be shown by the cdmViewer.
-
-
-
-
-
-
-
-
-
- The class of the input element.
-
-
-
-
-
-
-
-
-
-
-
-
- The part which can be opened for the given input.
-
-
-
-
-
-
- The class of the part.
-
-
-
-
-
-
-
-
-
- The name of the part.
-
-
-
-
-
-
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
index 0129f7f78..a862b6946 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
@@ -9,14 +9,16 @@
*/
package eu.etaxonomy.taxeditor.view;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -34,6 +36,7 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
/**
* This class provides the possibility to choose from a list of possible viewers
@@ -46,7 +49,7 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener, ILabelProvider{
private Object input;
- private Collection partConfigurationElements;
+ private Map, String>, ICdmViewer> nameViewerMap;
public CdmViewerChooser(Shell parentShell) {
this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...",
@@ -66,23 +69,40 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
*/
public void chooseViewer(Object input){
this.input = input;
- partConfigurationElements = new ArrayList<>();
+ this.nameViewerMap = new HashMap, String>, ICdmViewer>();
IExtensionRegistry reg = Platform.getExtensionRegistry();
IConfigurationElement[] extensions = reg
.getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
- for (IConfigurationElement e : extensions) {
- for (IConfigurationElement inputConfigurationElement : e.getChildren("input")) {
- String inputClass = inputConfigurationElement.getAttribute("class");
- if(inputClass.equals(input.getClass().toString())){
- System.out.println("input class: " + inputClass);
- for (IConfigurationElement partConfigurationElement : inputConfigurationElement.getChildren("part")) {
- partConfigurationElements.add(partConfigurationElement);
+ for (IConfigurationElement configElement : extensions) {
+ try {
+ Object object = configElement.createExecutableExtension("class");
+ if(object instanceof ICdmViewer){
+ ICdmViewer cdmViewer = (ICdmViewer)object;
+ Map, String> viewerClasses = cdmViewer.getViewerClasses(input);
+ for (Entry, String> entry : viewerClasses.entrySet()) {
+ nameViewerMap.put(entry, cdmViewer);
}
}
+ else{
+ MessagingUtils.error(CdmViewerChooser.class, new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Could not load cdmViewer extension"));
+ }
+ } catch (CoreException e) {
+ MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
+ }
+ }
+ //if only one editor is available then open it
+ if(nameViewerMap.size()==1){
+ Entry, String> next = nameViewerMap.keySet().iterator().next();
+ ICdmViewer cdmViewer = nameViewerMap.get(next);
+ cdmViewer.show(input, next.getKey());
+ }
+ else{
+ if(nameViewerMap.isEmpty()){
+ this.setInfoText("No viewers registered for this input");
}
+ this.open();
}
- this.open();
}
/* (non-Javadoc)
@@ -94,7 +114,7 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(this);
viewer.addSelectionChangedListener(this);
- viewer.setInput(partConfigurationElements);
+ viewer.setInput(nameViewerMap.keySet());
return parent;
}
@@ -106,21 +126,11 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
ISelection selection = event.getSelection();
if(selection instanceof IStructuredSelection){
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
- if(firstElement instanceof IConfigurationElement){
- IConfigurationElement configElement = (IConfigurationElement)firstElement;
- String viewerClass = configElement.getAttribute("class");
- try {
- //get the grand parent (this is the cdmViewer)
- Object o = ((IConfigurationElement)((IConfigurationElement)configElement.getParent()).getParent()).createExecutableExtension("class");
- if(o instanceof ICdmViewer){
- ((ICdmViewer) o).show(input, viewerClass);
- this.close();
- }
- } catch (InvalidRegistryObjectException e) {
- MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
- } catch (CoreException e) {
- MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
- }
+ if(nameViewerMap.containsKey(firstElement)){
+ Entry, String> entry = (Entry, String>)firstElement;
+ ICdmViewer cdmViewer = nameViewerMap.get(entry);
+ cdmViewer.show(input, entry.getKey());
+ this.close();
}
}
}
@@ -131,12 +141,9 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
@Override
public String getText(Object element) {
String text = null;
- if(element instanceof IConfigurationElement){
- IConfigurationElement configElement = (IConfigurationElement)element;
- text = configElement.getAttribute("name");
- if(text==null){
- text = configElement.getAttribute("class");
- }
+ if(nameViewerMap.containsKey(element)){
+ Entry, String> entry = (Entry, String>) element;
+ text = entry.getValue();
}
return text;
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java
index 0ef3362a9..0dd9e9b44 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java
@@ -9,6 +9,8 @@
*/
package eu.etaxonomy.taxeditor.view;
+import java.util.Map;
+
/**
* Implementors of this interface provide a mapping of input elements to views
@@ -21,11 +23,22 @@ package eu.etaxonomy.taxeditor.view;
*/
public interface ICdmViewer {
+ /**
+ * For the given input a map specifying the available viewers classes as
+ * keys and their string representation as values is returned
+ *
+ * @param input
+ * the input for which the viewer classes should be returned
+ * @return a map holding the viewer classes as keys and their string
+ * representations as values
+ */
+ public Map, String> getViewerClasses(Object input);
+
/**
* Opens the viewer defined by the given viewerClass for the given input.
* @param input the input for which a viewer should be opened
* @param viewerClass the qualified class name of the viewer
*/
- public void show(Object input, String viewerClass);
+ public void show(Object input, Class> viewerClass);
}