Add toggle for "link with taxon selection" to context menu of
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 16 Nov 2015 13:41:58 +0000 (14:41 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 16 Nov 2015 15:18:37 +0000 (16:18 +0100)
DerivativeEditor

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/DerivateViewContextMenu.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/ListenToSelectionChangeContextMenu.java [new file with mode: 0644]

index 659ea528365f43205a01c99cfbe3b74ea9371f90..522120d1ba4e6484bde3216b99502f2c20190a6c 100644 (file)
@@ -10,7 +10,8 @@ public class DerivateViewContextMenu extends CompoundContributionItem  {
         IContributionItem[] contributionItems = new IContributionItem[] {
                 new CreateFieldUnitContextMenu(),
                 new CreateDerivateContextMenu(),
-                new SingleReadSequenceContextMenu()
+                new ListenToSelectionChangeContextMenu(),
+                new SingleReadSequenceContextMenu(),
         };
         return contributionItems;
     }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/ListenToSelectionChangeContextMenu.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/ListenToSelectionChangeContextMenu.java
new file mode 100644 (file)
index 0000000..c68c8e5
--- /dev/null
@@ -0,0 +1,62 @@
+package eu.etaxonomy.taxeditor.editor.view.derivate.contextMenu;
+
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+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.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CompoundContributionItem;
+
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+
+/**
+ * Context menu for the SingleReads in the derivate hierarchy.
+ *
+ */
+public class ListenToSelectionChangeContextMenu extends CompoundContributionItem {
+
+    @Override
+    protected IContributionItem[] getContributionItems() {
+        IContributionItem[] contributionItems = new IContributionItem[] {
+                new ContributionItem() {
+                    @Override
+                    public void fill(Menu menu, int index) {
+                        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+                        IWorkbenchPart activePart = window.getActivePage().getActivePart();
+                        if(activePart instanceof DerivateView){
+                            final DerivateView derivateView = (DerivateView) activePart;
+                            MenuItem item = new MenuItem(menu, SWT.NONE);
+                            if(derivateView.isListenToSelectionChange()){
+                                item.setText("Unlink from taxon selection");
+                            }
+                            else{
+                                item.setText("Link with taxon selection");
+                            }
+                            item.addSelectionListener(new SelectionAdapterExtension(derivateView));
+                        }
+                    }
+                }
+        };
+        return contributionItems;
+    }
+
+    private final class SelectionAdapterExtension extends SelectionAdapter {
+
+        private final DerivateView derivateView;
+
+        private SelectionAdapterExtension(DerivateView derivateView) {
+            this.derivateView = derivateView;
+        }
+
+        @Override
+        public void widgetSelected(SelectionEvent e) {
+            derivateView.toggleListenToSelectionChange();
+        }
+    }
+}
+