Project

General

Profile

Download (3.92 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
 * <p>
25
 * Which the {@link #context) stack the action can keep track of the chain of editors which where opened before and which lead
26
 * to this action. This is important information when working with popup editors for which EntitySave events etc
27
 * need to be also handled by the base view (e.g. see {@link eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkingsetPresenter}
28
 * from which the the first popup editor of the chain has been opened. So the {@link #context) stack is just like a breadcrumbs information.
29
 *
30
 * @author a.kohlbecker
31
 * @since Mar 22, 2017
32
 *
33
 */
34
public abstract class AbstractEditorAction<V> extends AbstractEntityEvent<EditorActionType> {
35

    
36
    private Button source = null;
37

    
38
    private Field<V> target = null;
39

    
40
    // DO NOT initialize here, the context should always be set by the view in which the Action object is created
41
    protected Stack<EditorActionContext> context;
42

    
43
    public AbstractEditorAction(EditorActionType action) {
44
        this(action, null, null, null);
45
    }
46

    
47
    public AbstractEditorAction(EditorActionType action, Button source, Field<V> target, AbstractView sourceView) {
48
        this(action, null, source, target, sourceView);
49
    }
50

    
51
    /**
52
     *
53
     * @deprecated Consider using the constructor with Stack<EditorActionContext> context, so that the context is set for all popupeditors!!!
54
     */
55
    @Deprecated
56
    public AbstractEditorAction(EditorActionType action, UUID entityUuid, Button source, Field<V> target, AbstractView sourceView) {
57
        this(action, entityUuid, source, target, sourceView, null);
58
    }
59

    
60
    /**
61
     *
62
     * @param action
63
     *            the action being requested
64
     * @param entityId
65
     *            the id of the entity to which the action
66
     * @param source
67
     *            The vaadin ui component from which the action was triggered
68
     * @param sourceView
69
     *            The view from which the action is send
70
     * @param context
71
     *            Editor actions can hold a stack of entities to represent the chain of
72
     *            Editor actions from previous views and editors that lead to the point
73
     *            from where this action is spawned.
74
     */
75
    public AbstractEditorAction(EditorActionType action, UUID entityUuid, Button source, Field<V> target, AbstractView sourceView,
76
            Stack<EditorActionContext> context) {
77
        super(action, entityUuid, sourceView);
78
        this.source = source;
79
        this.target = target;
80
        this.context = context;
81
    }
82

    
83
    public boolean isAddAction() {
84
        return type.equals(EditorActionType.ADD);
85
    }
86

    
87
    public boolean isEditAction() {
88
        return type.equals(EditorActionType.EDIT);
89
    }
90

    
91
    public boolean isRemoveAction() {
92
        return type.equals(EditorActionType.REMOVE);
93
    }
94

    
95
    public Button getSource() {
96
        return source;
97
    }
98

    
99
    /**
100
     * @return the target
101
     */
102
    public Field<V> getTarget() {
103
        return target;
104
    }
105

    
106
    public boolean hasSource() {
107
        return source != null;
108
    }
109

    
110
    /**
111
     * Which the {@link #context) stack the action can keep track of the chain of editors
112
     * which where opened before and which lead
113
     * to this action.
114
     *
115
     * @return the context
116
     */
117
    public Stack<EditorActionContext> getContext() {
118
        return context;
119
    }
120

    
121
}
(1-1/29)