ref #6925 Migrate getShell utility method
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / event / EventUtility.java
1 /**
2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.event;
10
11 import javax.annotation.PostConstruct;
12 import javax.inject.Inject;
13 import javax.inject.Named;
14
15 import org.eclipse.e4.core.di.annotations.Optional;
16 import org.eclipse.e4.ui.di.UIEventTopic;
17 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18 import org.eclipse.e4.ui.services.IServiceConstants;
19 import org.eclipse.swt.widgets.Shell;
20
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
23
24 /**
25 * @author pplitzner
26 * @since Sep 4, 2017
27 *
28 */
29 public class EventUtility {
30
31 private static ITaxonEditor editor;
32
33 private static MPart activePart;
34
35 private static Shell shell;
36
37 @PostConstruct
38 public void create(){
39 //nothing
40 }
41
42 @Inject
43 @Optional
44 private void updateCurrentActiveShell(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell){
45 EventUtility.shell = shell;
46 }
47
48 @Inject
49 @Optional
50 private void updateCurrentActivePart(@Named(IServiceConstants.ACTIVE_PART)MPart activePart){
51 if(activePart!=null){
52 EventUtility.activePart = activePart;
53 }
54 }
55
56 @Inject
57 @Optional
58 private void updateCurrentTaxon(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
59 EventUtility.editor = editor;
60 }
61
62 public static Taxon getCurrentTaxon() {
63 if(editor!=null){
64 return editor.getTaxon();
65 }
66 return null;
67 }
68
69 public static ITaxonEditor getTaxonEditor() {
70 return editor;
71 }
72
73 public static MPart getActivePart() {
74 return activePart;
75 }
76
77 public static Shell getShell() {
78 return shell;
79 }
80
81 }