Project

General

Profile

Download (3.43 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.cdm.vaadin.event;
10

    
11
import java.util.Stack;
12
import java.util.UUID;
13

    
14
import com.vaadin.ui.Component;
15

    
16
import eu.etaxonomy.vaadin.event.EditorActionType;
17
import eu.etaxonomy.vaadin.mvp.AbstractView;
18

    
19
/**
20
 * Base implementation for an event which represents the request to start
21
 * an editor to enable the user to perform the <code>action</code> transported
22
 * with this event.
23
 *
24
 * @author a.kohlbecker
25
 * @since Mar 22, 2017
26
 *
27
 */
28
public abstract class AbstractEditorAction extends AbstractEntityEvent<EditorActionType> {
29

    
30
    private Component sourceComponent = null;
31

    
32
    protected Stack<EditorActionContext> context;
33

    
34
    public AbstractEditorAction(EditorActionType action) {
35
        this(action, null, null);
36
    }
37

    
38
    public AbstractEditorAction(EditorActionType action, Component source, AbstractView sourceView) {
39
        this(action, null, source, sourceView);
40
    }
41

    
42
    public AbstractEditorAction(EditorActionType action, UUID entityUuid, Component source, AbstractView sourceView) {
43
        this(action, entityUuid, source, sourceView, null);
44
    }
45

    
46
    /**
47
     *
48
     * @param action
49
     *            the action being requested
50
     * @param entityId
51
     *            the id of the entity to which the action
52
     * @param source
53
     *            The vaadin ui component from which the action was triggered
54
     * @param sourceView
55
     *            The view from which the action is send
56
     * @param context
57
     *            Editor actions can hold a stack of entities to represent the chain of
58
     *            Editor actions from previous views and editors that lead to the point
59
     *            from where this action is spawned.
60
     */
61
    public AbstractEditorAction(EditorActionType action, UUID entityUuid, Component source, AbstractView sourceView,
62
            Stack<EditorActionContext> context) {
63
        super(action, entityUuid, sourceView);
64
        this.sourceComponent = source;
65
        this.context = context;
66
    }
67

    
68
    public boolean isAddAction() {
69
        return type.equals(EditorActionType.ADD);
70
    }
71

    
72
    public boolean isEditAction() {
73
        return type.equals(EditorActionType.EDIT);
74
    }
75

    
76
    public boolean isRemoveAction() {
77
        return type.equals(EditorActionType.REMOVE);
78
    }
79

    
80
    public Component getSourceComponent() {
81
        return sourceComponent;
82
    }
83

    
84
    public boolean hasSource() {
85
        return sourceComponent != null;
86
    }
87

    
88
    /**
89
     * @return the context
90
     */
91
    public Stack<EditorActionContext> getContext() {
92
        return context;
93
    }
94

    
95
    public static class EditorActionContext {
96

    
97
        Object parentEntity;
98

    
99
        AbstractView parentView;
100

    
101
        /**
102
         * @param parentEntity
103
         * @param parentView
104
         */
105
        public EditorActionContext(Object parentEntity, AbstractView parentView) {
106
            super();
107
            this.parentEntity = parentEntity;
108
            this.parentView = parentView;
109
        }
110

    
111
        /**
112
         * @return the parentEntity
113
         */
114
        public Object getParentEntity() {
115
            return parentEntity;
116
        }
117

    
118
        /**
119
         * @return the parentView
120
         */
121
        public AbstractView getParentView() {
122
            return parentView;
123
        }
124

    
125

    
126

    
127
    }
128

    
129
}
(1-1/22)