- enhanced cdmViewer popup dialog
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 24 Feb 2015 12:01:20 +0000 (12:01 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 24 Feb 2015 12:01:20 +0000 (12:01 +0000)
 - added java doc

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java

index 7a09476fa96fdc91d4fd888faf696d95c1df10e0..4a5b4ea8d189e8b47c7712d0163ceae89559b421 100644 (file)
@@ -31,15 +31,15 @@ public class EditorCdmViewer implements ICdmViewer {
      * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
      */
     @Override
-    public void show(Object input, Class<?> viewerClass) {
+    public void show(Object input, String viewerClass) {
         try {
-            if(viewerClass.equals(MultiPageTaxonEditor.class)){
+            if(viewerClass.equals(MultiPageTaxonEditor.class.toString())){
                 if(input instanceof TaxonBase){
                     TaxonEditorInput editorInput = TaxonEditorInput.NewInstanceFromTaxonBase(((TaxonBase<?>) input).getUuid());
                     EditorUtil.open(editorInput);
                 }
             }
-            else if(viewerClass.equals(DerivateView.class)){
+            else if(viewerClass.equals(DerivateView.class.toString())){
                 if(input instanceof SpecimenOrObservationBase){
                 }
             }
index acf9f735295219e41079c26fa7b2832e7f306ceb..6dd55705d0dc9bf16a47f103fc3c1cec185190df 100644 (file)
@@ -9,38 +9,48 @@
  */
 package eu.etaxonomy.taxeditor.view;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.Collection;
 
+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.Platform;
 import org.eclipse.jface.dialogs.PopupDialog;
 import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
 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.graphics.Image;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+
 /**
+ * This class provides the possibility to choose from a list of possible viewers
+ * which can be opened for a given input in a popup dialog.
+ *
  * @author pplitzner
  * @date Feb 23, 2015
  *
  */
-public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener{
+public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener, ILabelProvider{
 
-    private Map<String, ICdmViewer> viewerNameMap;
     private Object input;
+    private Collection<IConfigurationElement> partConfigurationElements;
 
     public CdmViewerChooser(Shell parentShell) {
-        this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...", "Clicking will open the selected viewer");
+        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,
@@ -50,33 +60,24 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
                 titleText, infoText);
     }
 
+    /**
+     * Opens a popup dialog with all possible viewers for the given input.
+     * @param input the input for which the viewers are listed
+     */
     public void chooseViewer(Object input){
-        viewerNameMap = new HashMap<String, ICdmViewer>();
         this.input = input;
+        partConfigurationElements = new ArrayList<>();
+
         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");
-                }
+                String attribute = inputConfigurationElement.getAttribute("class");
+                    System.out.println("input class: " + attribute);
+                    for (IConfigurationElement partConfigurationElement : inputConfigurationElement.getChildren("part")) {
+                        partConfigurationElements.add(partConfigurationElement);
+                    }
             }
         }
         this.open();
@@ -89,9 +90,9 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
     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.setLabelProvider(this);
         viewer.addSelectionChangedListener(this);
-        viewer.setInput(viewerNameMap.keySet());
+        viewer.setInput(partConfigurationElements);
         return parent;
     }
 
@@ -103,12 +104,84 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
         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();
+            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);
+                }
             }
         }
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+     */
+    @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");
+            }
+        }
+        return text;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
+     */
+    @Override
+    public void addListener(ILabelProviderListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
+     */
+    @Override
+    public void dispose() {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
+     */
+    @Override
+    public boolean isLabelProperty(Object element, String property) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
+     */
+    @Override
+    public void removeListener(ILabelProviderListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
+     */
+    @Override
+    public Image getImage(Object element) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }
index 66cbf87cae9d297eef309f5e6bea02f8c7f95d34..0ef3362a94fb5af58796b3165e27e0c64dd8d438 100644 (file)
@@ -11,12 +11,21 @@ package eu.etaxonomy.taxeditor.view;
 
 
 /**
+ * Implementors of this interface provide a mapping of input elements to views
+ * or editors which can display information or provide editing functionality for
+ * the input elements.
+ *
  * @author pplitzner
  * @date Feb 23, 2015
  *
  */
 public interface ICdmViewer {
 
-    public void show(Object input, Class<?> viewerName);
+    /**
+     * 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);
 
 }