Listen to selection changes in DerivateEditor
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 26 Oct 2015 10:22:07 +0000 (11:22 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 26 Oct 2015 11:55:30 +0000 (12:55 +0100)
eu.etaxonomy.taxeditor.editor/icons/synced.gif [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenDerivateViewHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.store/plugin.xml

diff --git a/eu.etaxonomy.taxeditor.editor/icons/synced.gif b/eu.etaxonomy.taxeditor.editor/icons/synced.gif
new file mode 100644 (file)
index 0000000..870934b
Binary files /dev/null and b/eu.etaxonomy.taxeditor.editor/icons/synced.gif differ
index d1d818b56a18c809bb31a5614d1ba253e0980524..1d1c2e147da5e220184f06b28fb2a1b059270a22 100644 (file)
             id="eu.etaxonomy.taxeditor.editor.group.authority"
             name="%editor.name.4">
       </editor>
             id="eu.etaxonomy.taxeditor.editor.group.authority"
             name="%editor.name.4">
       </editor>
-      <editor
-            class="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"
-            default="false"
-            icon="icons/derivate_view-16x16-32.png"
-            id="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"
-            name="%editor.name.5">
-      </editor>
       <editor
             class="eu.etaxonomy.taxeditor.editor.view.dataimport.SpecimenImportEditor"
             default="false"
       <editor
             class="eu.etaxonomy.taxeditor.editor.view.dataimport.SpecimenImportEditor"
             default="false"
                id="eu.etaxonomy.taxeditor.editor.view.validation.problems"
                name="%view.name.6">
          </view>
                id="eu.etaxonomy.taxeditor.editor.view.validation.problems"
                name="%view.name.6">
          </view>
+         <view
+               class="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"
+               icon="icons/derivate_view-16x16-32.png"
+               id="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"
+               name="Derivative Editor"
+               restorable="true">
+         </view>
       </extension>
       
        <!-- VALIDATION RELATED STUFF -->
       </extension>
       
        <!-- VALIDATION RELATED STUFF -->
                </and>
             </visibleWhen>
          </command>
                </and>
             </visibleWhen>
          </command>
-      </menuContribution>
-      <menuContribution
-            allPopups="false"
-            locationURI="menu:eu.etaxonomy.taxeditor.menu.showView?before=org.eclipse.ui.views.showView.occurenceView">
          <separator
                name="eu.etaxonomy.taxeditor.store.separator_derivative_start"
                visible="true">
          <separator
                name="eu.etaxonomy.taxeditor.store.separator_derivative_start"
                visible="true">
                </reference>
             </visibleWhen>
          </command>
                </reference>
             </visibleWhen>
          </command>
+         <separator
+               name="eu.etaxonomy.taxeditor.editor.separator1">
+         </separator>
       </menuContribution>
       <menuContribution
             locationURI="menu:eu.etaxonomy.taxeditor.menu.showView?after=org.eclipse.ui.views.showView.supplemental">
       </menuContribution>
       <menuContribution
             locationURI="menu:eu.etaxonomy.taxeditor.menu.showView?after=org.eclipse.ui.views.showView.supplemental">
             locationURI="toolbar:eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView">
          <command
                commandId="eu.etaxonomy.taxeditor.editor.derivative.listenToSelectionChange"
             locationURI="toolbar:eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView">
          <command
                commandId="eu.etaxonomy.taxeditor.editor.derivative.listenToSelectionChange"
+               icon="icons/synced.gif"
                label="Link with Editor"
                label="Link with Editor"
-               style="push">
+               style="toggle">
          </command>
       </menuContribution>
    </extension>
          </command>
       </menuContribution>
    </extension>
index 9a6effa169dc31927a7390d5e12e85d0aa0caeef..04307863d72e1f37b23bd45899aae9e0089015d5 100644 (file)
@@ -1,64 +1,17 @@
 package eu.etaxonomy.taxeditor.editor.handler;
 
 package eu.etaxonomy.taxeditor.editor.handler;
 
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.UUID;
-
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.handlers.HandlerUtil;
 
 
-import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 
 public class OpenDerivateViewHandler extends AbstractHandler {
 
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
 
 public class OpenDerivateViewHandler extends AbstractHandler {
 
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
-        Object parameter = null;
-        //check if parameter is set
-        if(event.getParameter("eu.etaxonomy.taxeditor.specimenUuidParameter")!=null){
-            parameter = event.getObjectParameterForExecution("eu.etaxonomy.taxeditor.specimenUuidParameter");
-        }
-        if(parameter instanceof UUID){
-            selectedElementUUIDs.add((UUID) parameter);
-        }
-        else{
-            //if not, try with current selection
-            ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
-            if(currentSelection instanceof IStructuredSelection){
-                Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
-                while(selectionIterator.hasNext()){
-                    Object object = selectionIterator.next();
-                    if(object instanceof SpecimenOrObservationBase<?>){
-                        selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
-                    }
-                    else if(object instanceof IndividualsAssociation){
-                        SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
-                        if(specimen!=null){
-                            selectedElementUUIDs.add(specimen.getUuid());
-                        }
-                    }
-                }
-            }
-        }
-        DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
-        try {
-            EditorUtil.open(input);
-        } catch (PartInitException e) {
-            MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
-        } catch (NullPointerException npe){
-            MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
-        }
+        AbstractUtility.showView(DerivateView.ID);
         return null;
     }
 
         return null;
     }
 
index db52330ee77a1afe6eebf328b051c634be78d00b..f8eeb6fb46db96559b522004d6a16e247d53fdf7 100644 (file)
@@ -16,9 +16,7 @@ import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.util.LocalSelectionTransfer;
 import org.eclipse.jface.viewers.AbstractTreeViewer;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.util.LocalSelectionTransfer;
 import org.eclipse.jface.viewers.AbstractTreeViewer;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.jface.viewers.TreeSelection;
@@ -53,9 +51,7 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
@@ -66,9 +62,7 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
  *
  */
 public class DerivateView extends AbstractCdmViewPart implements IPartContentHasFactualData, ISaveablePart2,
  *
  */
 public class DerivateView extends AbstractCdmViewPart implements IPartContentHasFactualData, ISaveablePart2,
-        IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
-
-        ISelectionChangedListener, IPostOperationEnabled, ICdmEntitySessionEnabled{
+        IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia {
     public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
 
     public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE;
     public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
 
     public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE;
@@ -171,8 +165,10 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas
         viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
         // Propagate selection from viewer
         getSite().setSelectionProvider(viewer);
         viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
         // Propagate selection from viewer
         getSite().setSelectionProvider(viewer);
+
         //listen to selection changes
         //listen to selection changes
-        viewer.addSelectionChangedListener(this);
+        selectionService = getSite().getWorkbenchWindow().getSelectionService();
+        selectionService.addSelectionListener(this);
 
         //create context menu
         MenuManager menuManager = new MenuManager();
 
         //create context menu
         MenuManager menuManager = new MenuManager();
@@ -181,10 +177,6 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas
         Menu menu = menuManager.createContextMenu(control);
         control.setMenu(menu);
 
         Menu menu = menuManager.createContextMenu(control);
         control.setMenu(menu);
 
-        //single read multi links
-        generateMultiLinkSingleReads();
-        labelProvider.setMultiLinkSingleReads(multiLinkSingleReads);
-
         //init tree
         updateRootEntities();
 
         //init tree
         updateRootEntities();
 
@@ -199,30 +191,35 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas
     }
 
     public void updateRootEntities(Collection<UUID> derivativeUuids) {
     }
 
     public void updateRootEntities(Collection<UUID> derivativeUuids) {
-        if(derivativeUuids!=null){
-            this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
-            this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
-            for (UUID uuid : derivativeUuids) {
-                SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
-                if(derivate instanceof FieldUnit){
-                    derivateToRootEntityMap.put(derivate, derivate);
-                }
-                else {
-                    SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
-                    if(topMostDerivate!=null){
-                        derivateToRootEntityMap.put(derivate, topMostDerivate);
-                    }
-                    else{
+        if(conversation!=null){
+            if (!conversation.isBound()) {
+                conversation.bind();
+            }
+            if(derivativeUuids!=null){
+                this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
+                this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
+                for (UUID uuid : derivativeUuids) {
+                    SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
+                    if(derivate instanceof FieldUnit){
                         derivateToRootEntityMap.put(derivate, derivate);
                     }
                         derivateToRootEntityMap.put(derivate, derivate);
                     }
+                    else {
+                        SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
+                        if(topMostDerivate!=null){
+                            derivateToRootEntityMap.put(derivate, topMostDerivate);
+                        }
+                        else{
+                            derivateToRootEntityMap.put(derivate, derivate);
+                        }
+                    }
+                }
+                for (SpecimenOrObservationBase<?> specimen : derivateToRootEntityMap.values()) {
+                    rootElements.add(specimen);
                 }
             }
                 }
             }
-            for (SpecimenOrObservationBase<?> specimen : derivateToRootEntityMap.values()) {
-                rootElements.add(specimen);
-            }
+            viewer.setInput(rootElements);
+            refreshTree();
         }
         }
-        viewer.setInput(rootElements);
-        refreshTree();
     }
 
     @Override
     }
 
     @Override
@@ -238,7 +235,7 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas
         conversation.commit(true);
 
         if(CdmStore.getCurrentSessionManager().isRemoting()) {
         conversation.commit(true);
 
         if(CdmStore.getCurrentSessionManager().isRemoting()) {
-            CdmStore.getService(IOccurrenceService.class).merge(new ArrayList(getRootEntities()), true);
+            CdmStore.getService(IOccurrenceService.class).merge(new ArrayList<SpecimenOrObservationBase>(rootElements), true);
         }
         monitor.worked(1);
 
         }
         monitor.worked(1);
 
@@ -384,11 +381,6 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas
         return this.multiLinkSingleReads;
     }
 
         return this.multiLinkSingleReads;
     }
 
-    @Override
-    public void selectionChanged(SelectionChangedEvent event) {
-        this.selection  = event.getSelection();
-    }
-
     public ISelection getSelection() {
         return selection;
     }
     public ISelection getSelection() {
         return selection;
     }
index a19528f9bf10ed2cb2c507eb74a2888920b6d161..f25258f8a3b68dcb7d8d12c8accdbbc153d065b2 100644 (file)
          <menu
                id="eu.etaxonomy.taxeditor.menu.showView"
                label="%menu.label">
          <menu
                id="eu.etaxonomy.taxeditor.menu.showView"
                label="%menu.label">
-            <separator
-                  name="eu.etaxonomy.taxeditor.store.showViewMenu.details"
-                  visible="true">
-            </separator>
-            <command
-                  commandId="org.eclipse.ui.views.showView"
-                  id="org.eclipse.ui.views.showView.occurenceView"
-                  label="Derivative Editor (taxon-based)"
-                  style="push">
-               <parameter
-                     name="org.eclipse.ui.views.showView.viewId"
-                     value="eu.etaxonomy.taxeditor.view.derivative.OccurrenceView">
-               </parameter>
-               <visibleWhen
-                     checkEnabled="true">
-                  <reference
-                        definitionId="isCdmStoreConnected">
-                  </reference>
-               </visibleWhen>
-            </command>
-            <separator
-                  name="eu.etaxonomy.taxeditor.store.separator_derivative_end"
-                  visible="true">
-            </separator>
             <command
                   commandId="org.eclipse.ui.views.showView"
             <command
                   commandId="org.eclipse.ui.views.showView"
+                  id="eu.etaxonomy.taxeditor.store.showViewMenu.details"
                   label="%command.label.0"
                   style="push">
                <parameter
                   label="%command.label.0"
                   style="push">
                <parameter