Project

General

Profile

Download (3.87 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
public abstract class AbstractEditorAction<V> extends AbstractEntityEvent<EditorActionType> {
34

    
35
    private Button source = null;
36

    
37
    private Field<V> target = null;
38

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

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

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

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

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

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

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

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

    
93
    public Button getSource() {
94
        return source;
95
    }
96

    
97
    public Field<V> getTarget() {
98
        return target;
99
    }
100

    
101
    public boolean hasSource() {
102
        return source != null;
103
    }
104

    
105
    /**
106
     * Which the {@link #context) stack the action can keep track of the chain of editors
107
     * which where opened before and which lead
108
     * to this action.
109
     *
110
     * @return the context
111
     */
112
    public Stack<EditorActionContext> getContext() {
113
        return context;
114
    }
115
}
(1-1/28)