Merge branch 'develop' into remoting-4.0
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 10 Jul 2015 10:42:07 +0000 (12:42 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 10 Jul 2015 10:42:07 +0000 (12:42 +0200)
Conflicts:
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java

13 files changed:
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsContentProvider.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsLabelProvider.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonBaseDetailElement.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/CdmViewerContextMenu.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java

index 6bc3888409bdd444a98f135658dca8d55e41fbf1..8c198fc9bd5805715f409370627356eca4d4f62f 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -25,31 +25,26 @@ import org.eclipse.jface.viewers.Viewer;
  */
 public class ReferencingObjectsContentProvider implements
                IStructuredContentProvider {
-       private static final Logger logger = Logger
+       @SuppressWarnings("unused")
+    private static final Logger logger = Logger
                        .getLogger(ReferencingObjectsContentProvider.class);
 
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
-        */
        /** {@inheritDoc} */
-       public Object[] getElements(Object inputElement) {
+       @Override
+    public Object[] getElements(Object inputElement) {
                if (inputElement instanceof Collection) {
-                       return ((Collection) inputElement).toArray();
+                       return ((Collection<?>) inputElement).toArray();
                }
                return new Object[0];
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.IContentProvider#dispose()
-        */
        /**
         * <p>dispose</p>
         */
-       public void dispose() {}
+       @Override
+    public void dispose() {}
 
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
-        */
        /** {@inheritDoc} */
-       public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+       @Override
+    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
 }
index ec442ba8121e224a2e91bbf51ce2d6614601a522..99bbb847af9933d59eaeec55e21f68ac00915e9f 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -37,24 +37,20 @@ public class ReferencingObjectsLabelProvider extends LabelProvider implements IT
        public ReferencingObjectsLabelProvider() {
        }
 
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
-        */
+
        /** {@inheritDoc} */
-       public Image getColumnImage(Object element, int columnIndex) {
+       @Override
+    public Image getColumnImage(Object element, int columnIndex) {
                return null;
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
-        */
        /** {@inheritDoc} */
-       public String getColumnText(Object element, int columnIndex) {
+       @Override
+    public String getColumnText(Object element, int columnIndex) {
                String text = null;
-               
+
                Object deproxiedElement = HibernateProxyHelper.deproxy(element);
-               
+
                if (columnIndex == 0) {
                        text = DescriptionHelper.getObjectClassname(deproxiedElement);
                }else if (columnIndex == 1) {
@@ -68,8 +64,8 @@ public class ReferencingObjectsLabelProvider extends LabelProvider implements IT
                                text = ((CdmBase) element).getId() + "";
                        }
                }
-               
+
                return text == null ? element.toString() : text;
-               
+
        }
 }
index b613952f6386f4d41a3d175a9b4114dd9973b49c..9f3dbc63aa2fab335b2b1973e3434c209f7da1fa 100644 (file)
@@ -22,10 +22,14 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
@@ -63,7 +67,7 @@ import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
  * @created 08.07.2009
  * @version 1.0
  */
-public class ReferencingObjectsView extends AbstractCdmViewPart{
+public class ReferencingObjectsView extends AbstractCdmViewPart {
        private static final Logger logger = Logger
                        .getLogger(ReferencingObjectsView.class);
 
@@ -88,6 +92,34 @@ public class ReferencingObjectsView extends AbstractCdmViewPart{
                createColumns(viewer);
                viewer.setContentProvider(new ReferencingObjectsContentProvider());
                viewer.setLabelProvider(new ReferencingObjectsLabelProvider());
+               viewer.setCellModifier(new ICellModifier() {
+
+            @Override
+            public void modify(Object element, String property, Object value) {
+                // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public Object getValue(Object element, String property) {
+                ITableLabelProvider tableLabelProvider = null;
+                if(viewer.getLabelProvider() instanceof ITableLabelProvider){
+                    tableLabelProvider = (ITableLabelProvider) viewer.getLabelProvider();
+                }
+                Object[] columnProperties = viewer.getColumnProperties();
+                for (int i=0;i<columnProperties.length;i++) {
+                    if(columnProperties[i].equals(property) && tableLabelProvider!=null){
+                        return tableLabelProvider.getColumnText(element, i);
+                    }
+                }
+                return "";
+            }
+
+            @Override
+            public boolean canModify(Object element, String property) {
+                return true;
+            }
+        });
 //             viewer.setInput(new ArrayList<CdmBase>());
        }
 
@@ -100,8 +132,11 @@ public class ReferencingObjectsView extends AbstractCdmViewPart{
                String[] titles = {"Class", "Description", "UUID", "Object ID" };
                int[] bounds = { 100, 200, 100, 70};
 
+        CellEditor[] editors = new CellEditor[titles.length];
+
                for (int i = 0; i < titles.length; i++) {
                        TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+                       editors[i] = new TextCellEditor(table);
                        column.getColumn().setText(titles[i]);
                        column.getColumn().setWidth(bounds[i]);
                        column.getColumn().setResizable(true);
@@ -109,6 +144,9 @@ public class ReferencingObjectsView extends AbstractCdmViewPart{
                }
                table.setHeaderVisible(true);
                table.setLinesVisible(true);
+
+               viewer.setCellEditors(editors);
+               viewer.setColumnProperties(titles);
        }
 
        /**
index 4d92e047d995a46409f4df9ea2c85a64db9dbd29..796d19aa3a396b98f5f8b01f11b4480755c2f44f 100644 (file)
@@ -13,7 +13,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
-import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.ui.PartInitException;
 
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
@@ -31,11 +30,8 @@ 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, ExecutionEvent event) {
+    public void show(Object input, Class<?> viewerClass) {
         try {
             if(viewerClass.equals(MultiPageTaxonEditor.class)){
                 if(input instanceof TaxonBase){
@@ -54,9 +50,6 @@ public class EditorCdmViewer implements ICdmViewer {
         }
     }
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object)
-     */
     @Override
     public Map<Class<?>, String> getViewerClasses(Object input) {
         Map<Class<?>, String> viewerNameMap = new HashMap<Class<?>, String>();
index 9784c9a7650a34f7702f85e9dbf9af9520494131..8ba357df8781070b8363067366cd67a3c874bd89 100644 (file)
@@ -4,9 +4,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
-import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.PlatformUI;
 
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
@@ -18,26 +17,20 @@ public class NavigationCdmViewer implements ICdmViewer {
     @SuppressWarnings("unused")
     private final Logger logger = Logger.getLogger(NavigationCdmViewer.class);
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
-     */
     @Override
-    public void show(Object input, Class<?> viewerClass, ExecutionEvent event) {
+    public void show(Object input, Class<?> viewerClass) {
         if(viewerClass.equals(NewClassificationWizard.class)){
             if(input instanceof Classification){
                 Classification classification = (Classification)input;
                 NewClassificationWizard classificationWizard = new NewClassificationWizard();
                 classificationWizard.init(null, null);
                 classificationWizard.setEntity(classification);
-                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
+                WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
                 dialog.open();
             }
         }
     }
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object)
-     */
     @Override
     public Map<Class<?>, String> getViewerClasses(Object input) {
         Map<Class<?>, String> viewerNameMap = new HashMap<Class<?>, String>();
index eecb24ba985bc32c311ad1b90fb48be78d63d8ab..e6e8dc6d86422fb25c1e86b66a35a198fbef1aef 100644 (file)
@@ -9,6 +9,14 @@ import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
 
+/**
+ * Opens the (first) currently selected element in a viewer. Opens a list of
+ * possible viewers if more than one are registered for this element.
+ *
+ * @author pplitzner
+ * @date Jul 6, 2015
+ *
+ */
 public class OpenHandler extends AbstractHandler {
 
     @Override
@@ -17,7 +25,7 @@ public class OpenHandler extends AbstractHandler {
         if(currentSelection instanceof IStructuredSelection){
             Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement();
             CdmViewerChooser viewerChooser = new CdmViewerChooser(HandlerUtil.getActiveShell(event));
-            viewerChooser.chooseViewer(firstElement, event);
+            viewerChooser.chooseViewer(firstElement);
         }
         return null;
     }
index ffa008b59897fdad17d2bd6432e52dce5617c85d..fbde0b7e0ed056e51d0b6d809db9aa24e4a535ac 100644 (file)
@@ -14,14 +14,12 @@ import java.io.IOException;
 import java.net.URI;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
 import org.apache.http.HttpException;
 import org.eclipse.swt.events.SelectionListener;
 
 import eu.etaxonomy.cdm.common.media.ImageInfo;
 import eu.etaxonomy.cdm.model.media.ImageFile;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
@@ -31,8 +29,6 @@ import eu.etaxonomy.taxeditor.ui.element.KeyValueViewerElement;
 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
 
 /**
- * <p>ImageFileElement class.</p>
- *
  * @author n.hoffmann
  * @created Mar 26, 2010
  * @version 1.0
@@ -48,21 +44,12 @@ public class ImageFileElement extends MediaRepresentationPartElement<ImageFile>
        private final Runnable postRunnable = new Runnable(){
                @Override
         public void run() {
-                       StoreUtil.reflowDetailsViewer();
-                       StoreUtil.reflowSupplementalViewer();
+                       AbstractUtility.reflowDetailsViewer();
+                       AbstractUtility.reflowSupplementalViewer();
                }
        };
 
 
-       /**
-        * <p>Constructor for ImageFileElement.</p>
-        *
-        * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
-        * @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
-        * @param element a {@link eu.etaxonomy.cdm.model.media.ImageFile} object.
-        * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
-        * @param style a int.
-        */
        public ImageFileElement(CdmFormFactory cdmFormFactory,
                        AbstractFormSection section, ImageFile element,
                        SelectionListener removeListener, int style) {
@@ -125,17 +112,12 @@ public class ImageFileElement extends MediaRepresentationPartElement<ImageFile>
 
        }
 
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent(java.lang.Object)
-        */
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
                if(eventSource == text_uri){
                        try {
-                               String uriString = text_uri.getText();
-                               URI uri = StringUtils.isNotEmpty(uriString) ? new URI(uriString) : null;
+                           URI uri = text_uri.getUri();
                                getEntity().setUri(uri);
 
 
index 6a7b2f2832d701b872558711e02d2e0971b49922..348b472ea9fdbeb3729504a3c753289999e72d5e 100644 (file)
@@ -42,15 +42,6 @@ public class MediaRepresentationElement extends AbstractEntityCollectionElement<
        private TextWithLabelElement text_mimeType;
        private TextWithLabelElement text_suffix;
 
-       /**
-        * <p>Constructor for MediaRepresentationElement.</p>
-        *
-        * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
-        * @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
-        * @param element a {@link eu.etaxonomy.cdm.model.media.MediaRepresentation} object.
-        * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
-        * @param style a int.
-        */
        public MediaRepresentationElement(CdmFormFactory cdmFormFactory,
                        AbstractFormSection section,
                        MediaRepresentation element, SelectionListener removeListener,
@@ -58,9 +49,6 @@ public class MediaRepresentationElement extends AbstractEntityCollectionElement<
                super(cdmFormFactory, section, element, removeListener, null, style);
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.section.AbstractEntityCollectionElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, int)
-        */
        /** {@inheritDoc} */
        @Override
        public void createControls(ICdmFormElement element, int style) {
@@ -79,10 +67,6 @@ public class MediaRepresentationElement extends AbstractEntityCollectionElement<
                text_suffix.setText(element.getSuffix());
        }
 
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent(java.lang.Object)
-        */
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
index 8b032a691c9de592c07b3a67ade48c3960a69fcd..8139ecd577b6f229a6252d482e2ea8b18bd50e3b 100644 (file)
@@ -155,7 +155,7 @@ public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElem
        @Override
        protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
                String title = getEntity().generateTitle();
-               getEntity().setTitleCache(title, true);
+               getEntity().setTitleCache(title);
                super.handleTitleCacheRelevantChange(event);
        }
 
index 3b3909385445adf05e0d0ad3d47bb5aabc711996..6efcc81d0e473e68c40a8168cc60a225bd387092 100644 (file)
@@ -9,17 +9,9 @@
  */
 package eu.etaxonomy.taxeditor.view;
 
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-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;
@@ -36,12 +28,9 @@ import org.eclipse.swt.widgets.Control;
 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
- * which can be opened for a given input in a popup dialog.
+ * This class opens a popup dialog and provides the possibility to choose from a
+ * list of possible viewers which can be opened for a given input.
  *
  * @author pplitzner
  * @date Feb 23, 2015
@@ -51,7 +40,6 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
 
     private Object input;
     private Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap;
-    private ExecutionEvent executionEvent;
 
     public CdmViewerChooser(Shell parentShell) {
         this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...",
@@ -68,38 +56,16 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
     /**
      * Opens a popup dialog with all possible viewers for the given input.
      * @param input the input for which the viewers are listed
-     * @param event the {@link ExecutionEvent} if invoked via command/handler
      */
-    public void chooseViewer(Object input, ExecutionEvent event){
+    public void chooseViewer(Object input){
         this.input = input;
-        this.executionEvent = event;
-        this.nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
-
-        IExtensionRegistry reg = Platform.getExtensionRegistry();
-        IConfigurationElement[] extensions = reg
-                .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
-        for (IConfigurationElement configElement : extensions) {
-            try {
-                Object object = configElement.createExecutableExtension("class");
-                if(object instanceof ICdmViewer){
-                    ICdmViewer cdmViewer = (ICdmViewer)object;
-                    Map<Class<?>, String> viewerClasses = cdmViewer.getViewerClasses(input);
-                    for (Entry<Class<?>, 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);
-            }
-        }
+        this.nameViewerMap = CdmViewerUtil.getNameViewerMap(input);
+
         //if only one editor is available then open it
         if(nameViewerMap.size()==1){
             Entry<Class<?>, String> next = nameViewerMap.keySet().iterator().next();
             ICdmViewer cdmViewer = nameViewerMap.get(next);
-            cdmViewer.show(input, next.getKey(), event);
+            cdmViewer.show(input, next.getKey());
         }
         else{
             if(nameViewerMap.isEmpty()){
@@ -109,9 +75,6 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
         }
     }
 
-    /* (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));
@@ -122,9 +85,6 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
         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();
@@ -133,15 +93,12 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
             if(nameViewerMap.containsKey(firstElement)){
                 Entry<Class<?>, String> entry = (Entry<Class<?>, String>)firstElement;
                 ICdmViewer cdmViewer = nameViewerMap.get(entry);
-                cdmViewer.show(input, entry.getKey(), this.executionEvent);
+                cdmViewer.show(input, entry.getKey());
                 this.close();
             }
         }
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
-     */
     @Override
     public String getText(Object element) {
         String text = null;
@@ -152,45 +109,30 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
         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
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
new file mode 100644 (file)
index 0000000..712bec9
--- /dev/null
@@ -0,0 +1,73 @@
+package eu.etaxonomy.taxeditor.view;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CompoundContributionItem;
+
+/**
+ * Generic context menu for opening elements in the taxeditor.
+ *
+ */
+public class CdmViewerContextMenu extends CompoundContributionItem {
+
+    @Override
+    protected IContributionItem[] getContributionItems() {
+        IContributionItem[] contributionItems = new IContributionItem[] {
+                new ContributionItem() {
+                    @Override
+                    public void fill(Menu menu, int index) {
+                        MenuItem addItem = new MenuItem(menu, SWT.CASCADE);
+                        addItem.setText("Open in...");
+                        Menu addMenu = new Menu(menu);
+                        addItem.setMenu(addMenu);
+                        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+                        final ISelection selection = window.getActivePage().getSelection();
+                        if(selection instanceof IStructuredSelection){
+                            Object firstElement = ((IStructuredSelection) selection).getFirstElement();
+                            Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap = CdmViewerUtil.getNameViewerMap(firstElement);
+                            for(Entry<Entry<Class<?>, String>, ICdmViewer> entry:nameViewerMap.entrySet()){
+                                Entry<Class<?>, String> viewerClass = entry.getKey();
+                                MenuItem menuItem = new MenuItem(addMenu, SWT.NONE);
+                                menuItem.setText(viewerClass.getValue());
+                                menuItem.addSelectionListener(new OpenInViewerListener(entry.getValue(), firstElement, viewerClass.getKey()));
+                            }
+                        }
+                    }
+                }
+        };
+        return contributionItems;
+    }
+
+    private class OpenInViewerListener extends SelectionAdapter {
+
+        private final ICdmViewer cdmViewer;
+        private final Object input;
+        private final Class<?> viewerClass;
+
+        public OpenInViewerListener(ICdmViewer cdmViewer, Object input, Class<?> viewerClass) {
+            super();
+            this.cdmViewer = cdmViewer;
+            this.input = input;
+            this.viewerClass = viewerClass;
+        }
+
+        @Override
+        public void widgetSelected(SelectionEvent e) {
+            cdmViewer.show(input, viewerClass);
+        }
+
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
new file mode 100644 (file)
index 0000000..6f5c6f6
--- /dev/null
@@ -0,0 +1,59 @@
+// $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 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.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+
+/**
+ * @author pplitzner
+ * @date Jul 7, 2015
+ *
+ */
+public class CdmViewerUtil {
+
+    public static  Map<Entry<Class<?>, String>, ICdmViewer> getNameViewerMap(Object input){
+        Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
+    
+        IExtensionRegistry reg = Platform.getExtensionRegistry();
+        IConfigurationElement[] extensions = reg
+                .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
+        for (IConfigurationElement configElement : extensions) {
+            try {
+                Object object = configElement.createExecutableExtension("class");
+                if(object instanceof ICdmViewer){
+                    ICdmViewer cdmViewer = (ICdmViewer)object;
+                    Map<Class<?>, String> viewerClasses = cdmViewer.getViewerClasses(input);
+                    for (Entry<Class<?>, 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);
+            }
+        }
+        return nameViewerMap;
+    }
+
+}
index 877daa81adc69c3c9822ce4873b1f340515ffd3d..92063cfb206272bfb3f7e26aabec2f1ac0a7691c 100644 (file)
@@ -11,8 +11,6 @@ package eu.etaxonomy.taxeditor.view;
 
 import java.util.Map;
 
-import org.eclipse.core.commands.ExecutionEvent;
-
 
 /**
  * Implementors of this interface provide a mapping of input elements to views
@@ -26,8 +24,8 @@ import org.eclipse.core.commands.ExecutionEvent;
 public interface ICdmViewer {
 
     /**
-     * For the given input a map specifying the available viewers classes as
-     * keys and their string representation as values is returned
+     * For the given input a map is returned specifying the available viewer
+     * classes as keys and their string representation as values
      *
      * @param input
      *            the input for which the viewer classes should be returned
@@ -40,8 +38,7 @@ public interface ICdmViewer {
      * 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
-     * @param event the {@link ExecutionEvent} if invoked via command/handler
      */
-    public void show(Object input, Class<?> viewerClass, ExecutionEvent event);
+    public void show(Object input, Class<?> viewerClass);
 
 }