Project

General

Profile

Download (3.41 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

    
13
import com.vaadin.ui.Component;
14

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

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

    
29
    private Component sourceComponent = null;
30

    
31
    protected Stack<EditorActionContext> context;
32

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

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

    
41
    public AbstractEditorAction(EditorActionType action, Integer entityId, Component source, AbstractView sourceView) {
42
        this(action, entityId, source, sourceView, null);
43
    }
44

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

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

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

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

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

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

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

    
94
    public static class EditorActionContext {
95

    
96
        Object parentEntity;
97

    
98
        AbstractView parentView;
99

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

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

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

    
124

    
125

    
126
    }
127

    
128
}
(1-1/22)