Project

General

Profile

Download (7.05 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

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

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

    
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action;
29
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
30
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
31
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
32
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
33

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

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

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

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

    
50
    private LazyComboBox<Reference> referenceCombobox;
51

    
52
    private Button newPublicationButton;
53

    
54
    private Button removeNewPublicationButton;
55

    
56
    private Label newPublicationLabel;
57

    
58
    private Button continueButton;
59

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

    
62

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

    
67
    /**
68
     * {@inheritDoc}
69
     */
70
    @Override
71
    public boolean allowAnonymousAccess() {
72
        return false;
73
    }
74

    
75
    /**
76
     * {@inheritDoc}
77
     */
78
    @Override
79
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
80
        return null;
81
    }
82

    
83
    /**
84
     * {@inheritDoc}
85
     */
86
    @Override
87
    protected String getHeaderText() {
88
        return "New Registration";
89
    }
90

    
91
    /**
92
     * {@inheritDoc}
93
     */
94
    @Override
95
    protected String getSubHeaderText() {
96
        return SUBHEADER_DEEFAULT;
97
    }
98

    
99
    /**
100
     * {@inheritDoc}
101
     */
102
    @Override
103
    protected void initContent() {
104

    
105
        VerticalLayout vlayout = new VerticalLayout();
106
        vlayout.setSpacing(true);
107
        vlayout.setMargin(true);
108

    
109
        HorizontalLayout publicationLayout = new HorizontalLayout();
110
        publicationLayout.setSpacing(true);
111

    
112
        referenceCombobox = new LazyComboBox<Reference>(Reference.class);
113
        referenceCombobox.setWidth(ELEMENT_WIDTH);
114
        referenceCombobox.setBuffered(false);
115
        referenceCombobox.addValueChangeListener( e -> {
116
            boolean isValueSelected = e.getProperty().getValue() != null;
117
            continueButton.setEnabled(isValueSelected);
118
        });
119

    
120
        newPublicationButton = new Button("New");
121
        newPublicationButton.addClickListener( e -> eventBus.publishEvent(
122
                new ReferenceEditorAction(Action.ADD, newPublicationButton)
123
                ));
124
        newPublicationButton.setCaption("New");
125
        newPublicationButton.setWidth(ELEMENT_WIDTH);
126

    
127
        newPublicationLabel = new Label();
128
        newPublicationLabel.setVisible(false);
129

    
130
        removeNewPublicationButton = new Button("Delete");
131
        removeNewPublicationButton.setStyleName(ValoTheme.BUTTON_DANGER);
132
        removeNewPublicationButton.setWidth(ELEMENT_WIDTH);
133
        removeNewPublicationButton.addClickListener( e -> eventBus.publishEvent(
134
                new ReferenceEditorAction(Action.REMOVE, removeNewPublicationButton)
135
                ));
136

    
137
        removeNewPublicationButton.setVisible(false);
138

    
139
        Label labelLeft = new Label("Choose from existing publications");
140
        Label labelRight = new Label("Create a new publication");
141
        labelLeft.setWidth(ELEMENT_WIDTH);
142
        labelRight.setWidth(ELEMENT_WIDTH);
143

    
144
        CssLayout leftContainer = new CssLayout(labelLeft, referenceCombobox);
145
        CssLayout rightContainer = new CssLayout(labelRight, newPublicationButton, removeNewPublicationButton, newPublicationLabel);
146
        leftContainer.setWidth(ELEMENT_WIDTH);
147
        rightContainer.setWidth(ELEMENT_WIDTH);
148

    
149
        publicationLayout.addComponents(
150
                leftContainer,
151
                rightContainer
152
                );
153
        publicationLayout.setComponentAlignment(leftContainer, Alignment.TOP_RIGHT);
154
        publicationLayout.setComponentAlignment(rightContainer, Alignment.TOP_LEFT);
155

    
156
        continueButton = new Button("Continue");
157
        continueButton.setStyleName(ValoTheme.BUTTON_PRIMARY + " " + ValoTheme.BUTTON_HUGE);
158
        continueButton.setEnabled(false);
159
        continueButton.addClickListener(e -> {
160

    
161
            Integer refId = null;
162
            referenceCombobox.commit();
163
            if(referenceCombobox.getValue() != null){
164
                refId = referenceCombobox.getValue().getId();
165
            }
166
            eventBus.publishEvent(
167
                new RegistrationEditorAction(Action.ADD,
168
                        // passing the refId is hack, bit for some reason the presenter is always referring to the wrong view
169
                        refId,
170
                        continueButton,
171
                        StartRegistrationViewBean.this)
172
                );
173
              }
174
            );
175

    
176
        vlayout.addComponents(publicationLayout, continueButton);
177
        vlayout.setComponentAlignment(publicationLayout, Alignment.TOP_CENTER);
178
        vlayout.setComponentAlignment(continueButton, Alignment.TOP_CENTER);
179

    
180
        getLayout().addComponent(vlayout);
181
    }
182

    
183

    
184

    
185
    /**
186
     * {@inheritDoc}
187
     */
188
    @Override
189
    public void enter(ViewChangeEvent event) {
190
        // TODO Auto-generated method stub
191

    
192
    }
193

    
194
    // ------- StartRegistrationView interface methods ----- //
195

    
196
    /**
197
     * @return the referenceCombobox
198
     */
199
    @Override
200
    public LazyComboBox<Reference> getReferenceCombobox() {
201
        return referenceCombobox;
202
    }
203

    
204
    /**
205
     * @return the newPublicationButton
206
     */
207
    @Override
208
    public Button getNewPublicationButton() {
209
        return newPublicationButton;
210
    }
211

    
212
    /**
213
     * @return the newPublicationButton
214
     */
215
    @Override
216
    public Button getRemoveNewPublicationButton() {
217
        return removeNewPublicationButton;
218
    }
219

    
220
    /**
221
     * @return the newPublicationButton
222
     */
223
    @Override
224
    public Button getContinueButton() {
225
        return continueButton;
226
    }
227

    
228
    /**
229
     * @return the newPublicationLabel
230
     */
231
    @Override
232
    public Label getNewPublicationLabel() {
233
        return newPublicationLabel;
234
    }
235

    
236

    
237

    
238
}
(17-17/19)