Project

General

Profile

Download (3.21 KB) Statistics
| Branch: | Tag: | Revision:
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.commands.ECommandService;
16
import org.eclipse.e4.core.di.annotations.Optional;
17
import org.eclipse.e4.core.services.events.IEventBroker;
18
import org.eclipse.e4.ui.di.UIEventTopic;
19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.swt.widgets.Shell;
22

    
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
25

    
26
/**
27
 * @author pplitzner
28
 * @since Sep 4, 2017
29
 *
30
 */
31
public class EventUtility {
32

    
33
    private static ITaxonEditor editor;
34

    
35
    private static MPart activePart;
36

    
37
    private static Shell shell;
38

    
39
    @Inject
40
    private static IEventBroker eventBroker;
41

    
42
    @Inject
43
    private static ECommandService commandService;
44

    
45
    @PostConstruct
46
    public void create(){
47
        //nothing
48
    }
49

    
50
    public static void postEvent(String topic, Object data){
51
        eventBroker.post(topic, data);
52
    }
53

    
54
    public static ECommandService getCommandService() {
55
        return commandService;
56
    }
57

    
58
    @Inject
59
    @Optional
60
    private void updateCurrentActiveShell(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell){
61
        EventUtility.shell = shell;
62
    }
63

    
64
    @Inject
65
    @Optional
66
    private void updateCurrentActivePart(@Named(IServiceConstants.ACTIVE_PART)MPart activePart){
67
        if(activePart!=null){
68
            EventUtility.activePart = activePart;
69
        }
70
    }
71

    
72
    @Inject
73
    @Optional
74
    private void updateCurrentTaxon(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
75
        EventUtility.editor = editor;
76
    }
77

    
78
    public static Taxon getCurrentTaxon() {
79
        if(editor!=null){
80
            return editor.getTaxon();
81
        }
82
        return null;
83
    }
84

    
85
    public static ITaxonEditor getTaxonEditor() {
86
        return editor;
87
    }
88

    
89
    public static MPart getActivePart() {
90
        return activePart;
91
    }
92

    
93
    public static Shell getShell() {
94
        return shell;
95
    }
96

    
97
//    private EventHandler testHandler;
98
//
99
//    @Inject
100
//    public EventUtility(IEventBroker eventBroker) {
101
//        testHandler = new EventHandler() {
102
//
103
//            @Override
104
//            public void handleEvent(Event event) {
105
//                Object part = event.getProperty(UIEvents.EventTags.ELEMENT);
106
//                boolean tbr =(Boolean) event.getProperty(UIEvents.EventTags.NEW_VALUE);
107
//                if (part instanceof MPart){
108
//                    System.out.println("Part "+((MPart)part).getElementId()+" is "+(!tbr?"NOT":"")+" visible");
109
//                }
110
//                else if(part instanceof MPlaceholder){
111
//                    System.out.println("Part "+((MPlaceholder)part).getRef().getElementId()+" is "+(!tbr?"NOT":"")+" visible");
112
//                }
113
//            }
114
//        };
115
//        eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, testHandler);
116
//    }
117

    
118
}
(1-1/2)