Project

General

Profile

Download (3.64 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.Button;
15
import com.vaadin.ui.Field;
16

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

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

    
31
    private Button source = null;
32

    
33
    private Field<V> target = null;
34

    
35
    protected Stack<EditorActionContext> context;
36

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

    
41
    public AbstractEditorAction(EditorActionType action, Button source, Field<V> target, AbstractView sourceView) {
42
        this(action, null, source, target, sourceView);
43
    }
44

    
45
    public AbstractEditorAction(EditorActionType action, UUID entityUuid, Button source, Field<V> target, AbstractView sourceView) {
46
        this(action, entityUuid, source, target, sourceView, null);
47
    }
48

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

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

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

    
80
    public boolean isRemoveAction() {
81
        return type.equals(EditorActionType.REMOVE);
82
    }
83

    
84
    public Button getSource() {
85
        return source;
86
    }
87

    
88
    /**
89
     * @return the target
90
     */
91
    public Field<V> getTarget() {
92
        return target;
93
    }
94

    
95
    public boolean hasSource() {
96
        return source != null;
97
    }
98

    
99
    /**
100
     * @return the context
101
     */
102
    public Stack<EditorActionContext> getContext() {
103
        return context;
104
    }
105

    
106
    public static class EditorActionContext {
107

    
108
        Object parentEntity;
109

    
110
        AbstractView parentView;
111

    
112
        /**
113
         * @param parentEntity
114
         * @param parentView
115
         */
116
        public EditorActionContext(Object parentEntity, AbstractView parentView) {
117
            super();
118
            this.parentEntity = parentEntity;
119
            this.parentView = parentView;
120
        }
121

    
122
        /**
123
         * @return the parentEntity
124
         */
125
        public Object getParentEntity() {
126
            return parentEntity;
127
        }
128

    
129
        /**
130
         * @return the parentView
131
         */
132
        public AbstractView getParentView() {
133
            return parentView;
134
        }
135

    
136

    
137

    
138
    }
139

    
140
}
(1-1/23)