Project

General

Profile

Download (7.22 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.view.registration;
10

    
11
import java.util.Collection;
12
import java.util.UUID;
13

    
14
import org.springframework.security.core.GrantedAuthority;
15
import org.vaadin.viritin.fields.LazyComboBox;
16

    
17
import com.vaadin.navigator.View;
18
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
19
import com.vaadin.spring.annotation.SpringView;
20
import com.vaadin.ui.Alignment;
21
import com.vaadin.ui.Button;
22
import com.vaadin.ui.CssLayout;
23
import com.vaadin.ui.HorizontalLayout;
24
import com.vaadin.ui.Label;
25
import com.vaadin.ui.VerticalLayout;
26
import com.vaadin.ui.themes.ValoTheme;
27

    
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
30
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
31
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
32
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
33
import eu.etaxonomy.vaadin.event.EditorActionType;
34

    
35
/**
36
 * @author a.kohlbecker
37
 * @since Mar 2, 2017
38
 *
39
 */
40
@SpringView(name=StartRegistrationViewBean.NAME)
41
public class StartRegistrationViewBean extends AbstractPageView<StartRegistrationPresenter>
42
    implements StartRegistrationView, AccessRestrictedView, View {
43

    
44
    private static final long serialVersionUID = -9055865292188732909L;
45

    
46
    public static final String NAME = "regStart";
47

    
48
    public static final String SUBHEADER_DEEFAULT = "Any valid nomenclatural act can only be etablished in a publication. "
49
            + "To start a new registration process, please choose an existing one or create a new publication.";
50

    
51
    private LazyComboBox<Reference> referenceCombobox;
52

    
53
    private Button newPublicationButton;
54

    
55
    private Button removeNewPublicationButton;
56

    
57
    private Label newPublicationLabel;
58

    
59
    private Button continueButton;
60

    
61
    private static final String ELEMENT_WIDTH = "330px";
62

    
63

    
64
    public StartRegistrationViewBean() {
65
        super();
66
    }
67

    
68
    /**
69
     * {@inheritDoc}
70
     */
71
    @Override
72
    protected void initContent() {
73

    
74
        getLayout().setId(NAME);
75

    
76
        VerticalLayout vlayout = new VerticalLayout();
77
        vlayout.setSpacing(true);
78
        vlayout.setMargin(true);
79

    
80
        HorizontalLayout publicationLayout = new HorizontalLayout();
81
        publicationLayout.setSpacing(true);
82

    
83
        referenceCombobox = new LazyComboBox<Reference>(Reference.class);
84
        referenceCombobox.setWidth(ELEMENT_WIDTH);
85
        referenceCombobox.setBuffered(false);
86
        referenceCombobox.addValueChangeListener( e -> {
87
            boolean isValueSelected = e.getProperty().getValue() != null;
88
            continueButton.setEnabled(isValueSelected);
89
        });
90

    
91
        newPublicationButton = new Button("New");
92
        newPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
93
                new ReferenceEditorAction(EditorActionType.ADD, newPublicationButton, null, this)
94
                ));
95
        newPublicationButton.setCaption("New");
96
        newPublicationButton.setWidth(ELEMENT_WIDTH);
97

    
98
        newPublicationLabel = new Label();
99
        newPublicationLabel.setVisible(false);
100

    
101
        removeNewPublicationButton = new Button("Delete");
102
        removeNewPublicationButton.setStyleName(ValoTheme.BUTTON_DANGER);
103
        removeNewPublicationButton.setWidth(ELEMENT_WIDTH);
104
        removeNewPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
105
                new ReferenceEditorAction(EditorActionType.REMOVE, removeNewPublicationButton, referenceCombobox, this)
106
                ));
107

    
108
        removeNewPublicationButton.setVisible(false);
109

    
110
        Label labelLeft = new Label("Choose from existing publications");
111
        Label labelRight = new Label("Create a new publication");
112
        labelLeft.setWidth(ELEMENT_WIDTH);
113
        labelRight.setWidth(ELEMENT_WIDTH);
114

    
115
        CssLayout leftContainer = new CssLayout(labelLeft, referenceCombobox);
116
        CssLayout rightContainer = new CssLayout(labelRight, newPublicationButton, removeNewPublicationButton, newPublicationLabel);
117
        leftContainer.setWidth(ELEMENT_WIDTH);
118
        rightContainer.setWidth(ELEMENT_WIDTH);
119

    
120
        publicationLayout.addComponents(
121
                leftContainer,
122
                rightContainer
123
                );
124
        publicationLayout.setComponentAlignment(leftContainer, Alignment.TOP_RIGHT);
125
        publicationLayout.setComponentAlignment(rightContainer, Alignment.TOP_LEFT);
126

    
127
        continueButton = new Button("Continue");
128
        continueButton.setStyleName(ValoTheme.BUTTON_PRIMARY + " " + ValoTheme.BUTTON_HUGE);
129
        continueButton.setEnabled(false);
130
        continueButton.addClickListener(e -> {
131

    
132
            UUID refUuid = null;
133
            referenceCombobox.commit();
134
            if(referenceCombobox.getValue() != null){
135
                refUuid = referenceCombobox.getValue().getUuid();
136
            }
137
            getViewEventBus().publish(this,
138
                new RegistrationEditorAction(EditorActionType.ADD,
139
                        // passing the refId is hack, bit for some reason the presenter is always referring to the wrong view
140
                        refUuid,
141
                        continueButton,
142
                        null,
143
                        StartRegistrationViewBean.this)
144
                );
145
              }
146
            );
147

    
148
        vlayout.addComponents(publicationLayout, continueButton);
149
        vlayout.setComponentAlignment(publicationLayout, Alignment.TOP_CENTER);
150
        vlayout.setComponentAlignment(continueButton, Alignment.TOP_CENTER);
151

    
152
        addContentComponent(vlayout, 1f);
153
    }
154

    
155
    /**
156
     * {@inheritDoc}
157
     */
158
    @Override
159
    public boolean allowAnonymousAccess() {
160
        return false;
161
    }
162

    
163
    /**
164
     * {@inheritDoc}
165
     */
166
    @Override
167
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
168
        return null;
169
    }
170

    
171
    /**
172
     * {@inheritDoc}
173
     */
174
    @Override
175
    protected String getHeaderText() {
176
        return "New Registration";
177
    }
178

    
179
    /**
180
     * {@inheritDoc}
181
     */
182
    @Override
183
    protected String getSubHeaderText() {
184
        return SUBHEADER_DEEFAULT;
185
    }
186

    
187
    /**
188
     * {@inheritDoc}
189
     */
190
    @Override
191
    public void enter(ViewChangeEvent event) {
192

    
193
        getPresenter().handleViewEntered();
194

    
195
    }
196

    
197
    // ------- StartRegistrationView interface methods ----- //
198

    
199
    /**
200
     * @return the referenceCombobox
201
     */
202
    @Override
203
    public LazyComboBox<Reference> getReferenceCombobox() {
204
        return referenceCombobox;
205
    }
206

    
207
    /**
208
     * @return the newPublicationButton
209
     */
210
    @Override
211
    public Button getNewPublicationButton() {
212
        return newPublicationButton;
213
    }
214

    
215
    /**
216
     * @return the newPublicationButton
217
     */
218
    @Override
219
    public Button getRemoveNewPublicationButton() {
220
        return removeNewPublicationButton;
221
    }
222

    
223
    /**
224
     * @return the newPublicationButton
225
     */
226
    @Override
227
    public Button getContinueButton() {
228
        return continueButton;
229
    }
230

    
231
    /**
232
     * @return the newPublicationLabel
233
     */
234
    @Override
235
    public Label getNewPublicationLabel() {
236
        return newPublicationLabel;
237
    }
238

    
239

    
240

    
241
}
(18-18/20)