- added context menu optio to create a media specimen with an existing media (fixes...
authorPatric Plitzner <p.plitzner@bgbm.org>
Thu, 26 Feb 2015 10:58:30 +0000 (10:58 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Thu, 26 Feb 2015 10:58:30 +0000 (10:58 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/CreateDerivateContextMenu.java

index 2a74174c3c463ecc4d7b39ea2e53241a577082a2..782bd413df3a2f0326e2b4eec294ad38348ec9bb 100644 (file)
@@ -29,6 +29,7 @@ import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.MediaSelectionDialog;
 
 /**
  * Context menu for the creation of derivates in the derivate hierarchy.
@@ -97,10 +98,60 @@ public class CreateDerivateContextMenu extends CompoundContributionItem {
         return contributionItems;
     }
 
-    private void createMenuItem(Menu menu, String menuLabel, TreeNode selectedNode, Class<?> childClass, SpecimenOrObservationType specimenType, DerivationEventType derivationEventType) {
-        MenuItem menuItem = new MenuItem(menu, SWT.NONE);
-        menuItem.setText(menuLabel);
-        menuItem.addSelectionListener(new WidgetSelectionListener(selectedNode, childClass, specimenType, derivationEventType));
+    private void createMenuItem(Menu menu, String menuLabel, final TreeNode selectedNode, Class<?> childClass, final SpecimenOrObservationType specimenType, final DerivationEventType derivationEventType) {
+        if(specimenType.equals(SpecimenOrObservationType.Media)){
+            //media submenu
+            MenuItem mediaItem = new MenuItem(menu, SWT.CASCADE);
+            mediaItem.setText("Media...");
+            Menu mediaMenu = new Menu(menu);
+            mediaItem.setMenu(mediaMenu);
+
+            //media specimen menu
+            MenuItem menuItem = new MenuItem(mediaMenu, SWT.NONE);
+            menuItem.setText(menuLabel);
+            menuItem.addSelectionListener(new WidgetSelectionListener(selectedNode, childClass, specimenType, derivationEventType));
+
+            //existing media menu
+            MenuItem existingMediaItem = new MenuItem(mediaMenu, SWT.NONE);
+            existingMediaItem.setText("Media Specimen with existing media");
+            existingMediaItem.addSelectionListener(new SelectionAdapter() {
+                /* (non-Javadoc)
+                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+                 */
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    //select media
+                    Media media = MediaSelectionDialog.select(AbstractUtility.getShell(), null, null);
+                    //create MediaSpecimen
+                    MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(specimenType);
+                    mediaSpecimen.setMediaSpecimen(media);
+
+                    //attach to parent
+                    if(selectedNode.getValue() instanceof SpecimenOrObservationBase){
+                        SpecimenOrObservationBase<?> specimenOrObservationBase = (SpecimenOrObservationBase<?>)selectedNode.getValue();
+
+                        specimenOrObservationBase.addDerivationEvent(DerivationEvent.NewSimpleInstance(specimenOrObservationBase, mediaSpecimen, derivationEventType));
+                        mediaSpecimen.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
+                        mediaSpecimen.getTitleCache(); //update title cache
+                    }
+
+                    //refresh view
+                    DerivateView derivateView = null;
+                    if(AbstractUtility.getActivePart() instanceof DerivateView){
+                        derivateView = (DerivateView) AbstractUtility.getActivePart();
+                    }
+                    if(derivateView!=null){
+                        derivateView.getConversationHolder().commit();
+                        derivateView.refreshTree(mediaSpecimen);
+                    }
+                }
+            });
+        }
+        else{
+            MenuItem menuItem = new MenuItem(menu, SWT.NONE);
+            menuItem.setText(menuLabel);
+            menuItem.addSelectionListener(new WidgetSelectionListener(selectedNode, childClass, specimenType, derivationEventType));
+        }
     }
 
     private class WidgetSelectionListener extends SelectionAdapter{