- implemented framework which links an input element to viewers/editors which are...
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 24 Feb 2015 10:04:18 +0000 (10:04 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 24 Feb 2015 10:04:18 +0000 (10:04 +0000)
  - added ICdmViewer interface
  - added extension point to register ICdmViewer
  - registered EditorCdmViewer for the taxeditor.editor plugin

.gitattributes
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java [new file with mode: 0644]

index 7530a1c505e2022fd76862d4629bdd9933ce0168..cc539fac25226a638ca93a8749ffc34333514825 100644 (file)
@@ -371,6 +371,7 @@ eu.etaxonomy.taxeditor.editor/plugin.xml -text
 eu.etaxonomy.taxeditor.editor/pom.xml -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorStateManager.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/IDropTargetable.java -text
@@ -1207,6 +1208,7 @@ eu.etaxonomy.taxeditor.store/icons/web.gif -text
 eu.etaxonomy.taxeditor.store/p2.inf -text
 eu.etaxonomy.taxeditor.store/plugin.xml -text
 eu.etaxonomy.taxeditor.store/pom.xml -text
+eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceCredentialsWizardPage.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceH2WizardPage.java -text
@@ -1764,6 +1766,8 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractC
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmViewPart.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractSplitableViewPart.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceContentProvider.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceLabelProvider.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceViewPart.java -text
index 08d4850cf04b2478280b9f5f7e2eb069c7f4336d..b2dc9bfa68955694681b624893deb79574441ea5 100644 (file)
          </description>
       </wizard>
    </extension>
+    <extension
+          point="eu.etaxonomy.taxeditor.store.cdmViewer">
+       <cdmViewer
+             class="eu.etaxonomy.taxeditor.editor.EditorCdmViewer">
+          <input
+                class="eu.etaxonomy.cdm.model.taxon.TaxonBase">
+             <part
+                   class="eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor"
+                   name="Taxon Editor">
+             </part>
+          </input>
+       </cdmViewer>
+    </extension>
 </plugin>
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
new file mode 100644 (file)
index 0000000..7a09476
--- /dev/null
@@ -0,0 +1,53 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor;
+
+import org.apache.log4j.Logger;
+import org.eclipse.ui.PartInitException;
+
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.view.ICdmViewer;
+
+/**
+ * @author pplitzner
+ * @date Feb 23, 2015
+ *
+ */
+public class EditorCdmViewer implements ICdmViewer {
+
+    private final Logger logger = Logger.getLogger(EditorCdmViewer.class);
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
+     */
+    @Override
+    public void show(Object input, Class<?> viewerClass) {
+        try {
+            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)){
+                if(input instanceof SpecimenOrObservationBase){
+                }
+            }
+        } catch (PartInitException e) {
+            String errorMessage = "Could not open editor";
+            logger.error(errorMessage, e);
+            MessagingUtils.error(EditorCdmViewer.class, errorMessage, e);
+        }
+    }
+
+}
index 9a68e2ec1c858bbedad3833bbcfaa01e1dbe75da..95573ca219a15b86831d400deb29e099142f6e4c 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.2"?>
 <plugin>
+   <extension-point id="eu.etaxonomy.taxeditor.store.cdmViewer" name="Cdm Viewer" schema="schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd"/>
    <extension
          point="org.eclipse.ui.preferencePages">
       <page
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
new file mode 100644 (file)
index 0000000..b7f2964
--- /dev/null
@@ -0,0 +1,160 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="eu.etaxonomy.taxeditor.store" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appInfo>
+         <meta.schema plugin="eu.etaxonomy.taxeditor.store" id="eu.etaxonomy.taxeditor.store.cdmViewer" name="Cdm Viewer"/>
+      </appInfo>
+      <documentation>
+         [Enter description of this extension point.]
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appInfo>
+            <meta.element />
+         </appInfo>
+      </annotation>
+      <complexType>
+         <sequence minOccurs="1" maxOccurs="unbounded">
+            <element ref="cdmViewer"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="att" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="java"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="cdmViewer">
+      <annotation>
+         <documentation>
+            A Cdm Viewer knows what viewer or editor can show which input.
+         </documentation>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="input"/>
+         </sequence>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  The class of the viewer.
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="java" basedOn=":eu.etaxonomy.taxeditor.view.ICdmViewer"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="input">
+      <annotation>
+         <documentation>
+            The input element which can be shown by the cdmViewer.
+         </documentation>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="part"/>
+         </sequence>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  The class of the input element.
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="java"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="part">
+      <annotation>
+         <documentation>
+            The part which can be opened for the given input.
+         </documentation>
+      </annotation>
+      <complexType>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  The class of the part.
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="java"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  The name of the part.
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="since"/>
+      </appInfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="examples"/>
+      </appInfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="apiinfo"/>
+      </appInfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="implementation"/>
+      </appInfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+
+</schema>
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
new file mode 100644 (file)
index 0000000..acf9f73
--- /dev/null
@@ -0,0 +1,114 @@
+// $Id$
+/**
+ * Copyright (C) 2015 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
+package eu.etaxonomy.taxeditor.view;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.PopupDialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+
+/**
+ * @author pplitzner
+ * @date Feb 23, 2015
+ *
+ */
+public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener{
+
+    private Map<String, ICdmViewer> viewerNameMap;
+    private Object input;
+
+    public CdmViewerChooser(Shell parentShell) {
+        this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...", "Clicking will open the selected viewer");
+    }
+
+    public CdmViewerChooser(Shell parent, int shellStyle, boolean takeFocusOnOpen, boolean persistSize,
+            boolean persistLocation, boolean showDialogMenu, boolean showPersistActions, String titleText,
+            String infoText) {
+        super(parent, shellStyle, takeFocusOnOpen, persistSize, persistLocation, showDialogMenu, showPersistActions,
+                titleText, infoText);
+    }
+
+    public void chooseViewer(Object input){
+        viewerNameMap = new HashMap<String, ICdmViewer>();
+        this.input = input;
+        IExtensionRegistry reg = Platform.getExtensionRegistry();
+        IConfigurationElement[] extensions = reg
+                .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
+        for (IConfigurationElement e : extensions) {
+            Object o;
+//            try {
+//                o = e.createExecutableExtension("class");
+//                if (o instanceof ICdmViewer) {
+//                    ICdmViewer cdmViewer = (ICdmViewer) o;
+//                    Collection<String> viewerNames = cdmViewer.getViewerNames(input);
+//                    if(viewerNames!=null){
+//                        for (String string : viewerNames) {
+//                            viewerNameMap.put(string, cdmViewer);
+//                        }
+//                    }
+//                }
+//            } catch (CoreException e1) {
+//                MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e1);
+//            }
+            for (IConfigurationElement inputConfigurationElement : e.getChildren("input")) {
+                System.out.println("input");
+                for (IConfigurationElement partConfigurationElement : inputConfigurationElement.getChildren("part")) {
+                    System.out.println("part");
+                }
+            }
+        }
+        this.open();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        TableViewer viewer = new TableViewer(new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
+        viewer.setContentProvider(new ArrayContentProvider());
+        viewer.setLabelProvider(new ColumnLabelProvider());
+        viewer.addSelectionChangedListener(this);
+        viewer.setInput(viewerNameMap.keySet());
+        return parent;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+     */
+    @Override
+    public void selectionChanged(SelectionChangedEvent event) {
+        ISelection selection = event.getSelection();
+        if(selection instanceof IStructuredSelection){
+            Object firstElement = ((IStructuredSelection) selection).getFirstElement();
+            ICdmViewer cdmViewer = viewerNameMap.get(firstElement);
+            if(cdmViewer!=null){
+                cdmViewer.show(input, null);
+                this.close();
+            }
+        }
+    }
+
+}
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
new file mode 100644 (file)
index 0000000..66cbf87
--- /dev/null
@@ -0,0 +1,22 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view;
+
+
+/**
+ * @author pplitzner
+ * @date Feb 23, 2015
+ *
+ */
+public interface ICdmViewer {
+
+    public void show(Object input, Class<?> viewerName);
+
+}