ref #6595, #6925 Use EventBroker to keep track of active taxon editor
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 4 Sep 2017 08:25:06 +0000 (10:25 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 4 Sep 2017 08:25:18 +0000 (10:25 +0200)
eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.store/fragment.e4xmi
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/EventUtility.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/WorkbenchEventConstants.java [new file with mode: 0644]

index bf8ceaaff03b2ac60f6583b3cd3efb7635eea0fa..49f263c1f9c15e52fcb3e8d26de7b661fd3e36fd 100644 (file)
@@ -35,7 +35,8 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.e4.core.di,
  org.eclipse.e4.ui.model.workbench,
  org.eclipse.e4.ui.di,
- org.eclipse.e4.core.commands
+ org.eclipse.e4.core.commands,
+ org.eclipse.e4.core.services
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
index 9d314eec749ee2bbdaf69224d14a15116fa095ac..d4373e0410164e2e6d235405424040e47ef9e16c 100644 (file)
@@ -23,6 +23,7 @@ import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.commands.operations.UndoContext;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.e4.core.services.events.IEventBroker;
 import org.eclipse.e4.ui.di.Focus;
 import org.eclipse.e4.ui.di.Persist;
 import org.eclipse.e4.ui.model.application.ui.MDirtyable;
@@ -56,6 +57,7 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.editor.ISecuredEditor;
+import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
 import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupE4;
@@ -65,6 +67,7 @@ import eu.etaxonomy.taxeditor.editor.name.e4.container.AcceptedNameContainerE4;
 import eu.etaxonomy.taxeditor.editor.name.e4.container.ContainerFactoryE4;
 import eu.etaxonomy.taxeditor.editor.name.e4.container.HomotypicalSynonymGroupE4;
 import eu.etaxonomy.taxeditor.editor.name.e4.container.MisappliedGroupE4;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.model.IPartChangeListener;
@@ -87,7 +90,7 @@ import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
  */
 public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable, IPartContentHasDetails,
         IPartContentHasSupplementalData, IPartContentHasMedia, IPartContentHasFactualData, IPartChangeListener,
-        ISelectionListener, ISecuredEditor, IPostOperationEnabled, IE4SavablePart {
+        ISelectionListener, ISecuredEditor, IPostOperationEnabled, IE4SavablePart, ITaxonEditor {
 
        private Taxon taxon;
 
@@ -124,6 +127,9 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
 
     private UndoContext undoContext;
 
+    @Inject
+    private IEventBroker eventBroker;
+
        @Inject
        public TaxonNameEditorE4() {
            undoContext = new UndoContext();
@@ -204,7 +210,8 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
                managedForm.refresh();
        }
 
-       public Taxon getTaxon() {
+       @Override
+    public Taxon getTaxon() {
                return HibernateProxyHelper.deproxy(taxon);
        }
 
@@ -230,6 +237,7 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
                boolean doEnable = permissionsSatisfied();
                managedForm.getForm().setEnabled(doEnable);
            }
+        eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, this);
        }
 
        @Override
index d67198ce18dc20f6b64cf531f5c1a1eb95098f40..35cda018b658b7f91f1f1d834a4002ad3c365174 100644 (file)
@@ -14,6 +14,7 @@ Export-Package: eu.etaxonomy.cdm,
  eu.etaxonomy.taxeditor.editor,
  eu.etaxonomy.taxeditor.editor.definedterm,
  eu.etaxonomy.taxeditor.editor.definedterm.input,
+ eu.etaxonomy.taxeditor.event,
  eu.etaxonomy.taxeditor.featuretree,
  eu.etaxonomy.taxeditor.featuretree.e4,
  eu.etaxonomy.taxeditor.handler,
index f47dfaedd6eddbb0f2e9d53eb8fb8c41a211ad59..7d96a1d267087c9b7e747442b4f1057f7ae49f7f 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ASCII"?>
-<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/descriptor/basic" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmlns:ui="http://www.eclipse.org/ui/2010/UIModel/application/ui" xmi:id="_OhwnQCTfEeeiN5lBIuqN3g">
+<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/descriptor/basic" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmlns:ui="http://www.eclipse.org/ui/2010/UIModel/application/ui" xmi:id="_OhwnQCTfEeeiN5lBIuqN3g">
   <imports xsi:type="commands:Command" xmi:id="_bnVKsCZxEeeQLpuomSmVoQ" elementId="eu.etaxonomy.taxeditor.command.openPart"/>
   <imports xsi:type="commands:Command" xmi:id="_LlbAMEq2EeeN-dEYnw7m3g" elementId="org.eclipse.ui.file.save"/>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_xVa1wCXXEeex9MwMOgUeWw" featurename="descriptors" parentElementId="xpath:/">
       </children>
     </elements>
   </fragments>
+  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_pVVyEJFJEeeDJpjGQES7gw" featurename="addons" parentElementId="org.eclipse.e4.legacy.ide.application">
+    <elements xsi:type="application:Addon" xmi:id="_q4JBkJFJEeeDJpjGQES7gw" elementId="eu.etaxonomy.taxeditor.event.EventUtility" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.event.EventUtility"/>
+  </fragments>
 </fragment:ModelFragments>
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/EventUtility.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/EventUtility.java
new file mode 100644 (file)
index 0000000..b96f8b2
--- /dev/null
@@ -0,0 +1,51 @@
+/**
+* Copyright (C) 2017 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.event;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.di.UIEventTopic;
+
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
+
+/**
+ * @author pplitzner
+ * @since Sep 4, 2017
+ *
+ */
+public class EventUtility {
+
+    private static ITaxonEditor editor;
+
+    @PostConstruct
+    public void create(){
+        //nothing
+    }
+
+    @Inject
+    @Optional
+    private void updateCurrentTaxon(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
+        EventUtility.editor = editor;
+    }
+
+    public static Taxon getCurrentTaxon() {
+        if(editor!=null){
+            return editor.getTaxon();
+        }
+        return null;
+    }
+
+    public static ITaxonEditor getEditor() {
+        return editor;
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/WorkbenchEventConstants.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/WorkbenchEventConstants.java
new file mode 100644 (file)
index 0000000..edf9fd0
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+* Copyright (C) 2017 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.event;
+
+/**
+ * @author pplitzner
+ * @since Sep 4, 2017
+ *
+ */
+public interface WorkbenchEventConstants {
+
+    public static final String CURRENT_ACTIVE_EDITOR = "CURRENT/ACTIVE_EDITOR";
+
+}