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
|
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 popupeditors!!!
|
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
|
*
|
61
|
* @param action
|
62
|
* the action being requested
|
63
|
* @param entityId
|
64
|
* the id of the entity to which the action
|
65
|
* @param source
|
66
|
* The vaadin ui component from which the action was triggered
|
67
|
* @param sourceView
|
68
|
* The view from which the action is send
|
69
|
* @param context
|
70
|
* Editor actions can hold a stack of entities to represent the chain of
|
71
|
* Editor actions from previous views and editors that lead to the point
|
72
|
* from where this action is spawned.
|
73
|
*/
|
74
|
public AbstractEditorAction(EditorActionType action, UUID entityUuid, Button source, Field<V> target, AbstractView sourceView,
|
75
|
Stack<EditorActionContext> context) {
|
76
|
super(action, entityUuid, sourceView);
|
77
|
this.source = source;
|
78
|
this.target = target;
|
79
|
this.context = context;
|
80
|
}
|
81
|
|
82
|
public boolean isAddAction() {
|
83
|
return type.equals(EditorActionType.ADD);
|
84
|
}
|
85
|
|
86
|
public boolean isEditAction() {
|
87
|
return type.equals(EditorActionType.EDIT);
|
88
|
}
|
89
|
|
90
|
public boolean isRemoveAction() {
|
91
|
return type.equals(EditorActionType.REMOVE);
|
92
|
}
|
93
|
|
94
|
public Button getSource() {
|
95
|
return source;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* @return the target
|
100
|
*/
|
101
|
public Field<V> getTarget() {
|
102
|
return target;
|
103
|
}
|
104
|
|
105
|
public boolean hasSource() {
|
106
|
return source != null;
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Which the {@link #context) stack the action can keep track of the chain of editors
|
111
|
* which where opened before and which lead
|
112
|
* to this action.
|
113
|
*
|
114
|
* @return the context
|
115
|
*/
|
116
|
public Stack<EditorActionContext> getContext() {
|
117
|
return context;
|
118
|
}
|
119
|
|
120
|
}
|