2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.event
;
11 import java
.util
.Collection
;
13 import javax
.annotation
.PostConstruct
;
14 import javax
.inject
.Inject
;
15 import javax
.inject
.Named
;
17 import org
.eclipse
.e4
.core
.commands
.ECommandService
;
18 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
19 import org
.eclipse
.e4
.core
.services
.events
.IEventBroker
;
20 import org
.eclipse
.e4
.ui
.di
.UIEventTopic
;
21 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
22 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
23 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.taxeditor
.editor
.ITaxonEditor
;
28 import eu
.etaxonomy
.taxeditor
.workbench
.part
.IE4SavablePart
;
35 public class EventUtility
{
37 private static ITaxonEditor editor
;
39 private static MPart activePart
;
41 private static Shell shell
;
44 private static IEventBroker eventBroker
;
47 private static ECommandService commandService
;
54 public static void postEvent(String topic
, Object data
){
55 eventBroker
.post(topic
, data
);
58 public static ECommandService
getCommandService() {
59 return commandService
;
64 private void updateCurrentActiveShell(@Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
){
65 EventUtility
.shell
= shell
;
70 private void updateCurrentActivePart(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
){
72 EventUtility
.activePart
= activePart
;
78 private void updateCurrentTaxon(@UIEventTopic(WorkbenchEventConstants
.CURRENT_ACTIVE_EDITOR
)ITaxonEditor editor
){
79 EventUtility
.editor
= editor
;
82 public static Taxon
getCurrentTaxon() {
84 return editor
.getTaxon();
89 public static ITaxonEditor
getTaxonEditor() {
93 public static MPart
getActivePart() {
97 public static Shell
getShell() {
101 public static MPart
getActiveEditorPart(EPartService partService
){
102 Collection
<MPart
> parts
= partService
.getParts();
103 for (MPart part
: parts
) {
104 if(part
.getObject()!=null && part
.getObject() instanceof IE4SavablePart
105 && part
.isVisible()){
112 // private EventHandler testHandler;
115 // public EventUtility(IEventBroker eventBroker) {
116 // testHandler = new EventHandler() {
119 // public void handleEvent(Event event) {
120 // Object part = event.getProperty(UIEvents.EventTags.ELEMENT);
121 // boolean tbr =(Boolean) event.getProperty(UIEvents.EventTags.NEW_VALUE);
122 // if (part instanceof MPart){
123 // System.out.println("Part "+((MPart)part).getElementId()+" is "+(!tbr?"NOT":"")+" visible");
125 // else if(part instanceof MPlaceholder){
126 // System.out.println("Part "+((MPlaceholder)part).getRef().getElementId()+" is "+(!tbr?"NOT":"")+" visible");
130 // eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, testHandler);