Project

General

Profile

Download (7.1 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.ReferenceEditorAction;
29
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
30
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
31
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
32
import eu.etaxonomy.vaadin.event.EditorActionType;
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
    protected void initContent() {
72

    
73
        getLayout().setId(NAME);
74

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

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

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

    
90
        newPublicationButton = new Button("New");
91
        newPublicationButton.addClickListener( e -> eventBus.publishEvent(
92
                new ReferenceEditorAction(EditorActionType.ADD, newPublicationButton)
93
                ));
94
        newPublicationButton.setCaption("New");
95
        newPublicationButton.setWidth(ELEMENT_WIDTH);
96

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

    
100
        removeNewPublicationButton = new Button("Delete");
101
        removeNewPublicationButton.setStyleName(ValoTheme.BUTTON_DANGER);
102
        removeNewPublicationButton.setWidth(ELEMENT_WIDTH);
103
        removeNewPublicationButton.addClickListener( e -> eventBus.publishEvent(
104
                new ReferenceEditorAction(EditorActionType.REMOVE, removeNewPublicationButton)
105
                ));
106

    
107
        removeNewPublicationButton.setVisible(false);
108

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

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

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

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

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

    
146
        vlayout.addComponents(publicationLayout, continueButton);
147
        vlayout.setComponentAlignment(publicationLayout, Alignment.TOP_CENTER);
148
        vlayout.setComponentAlignment(continueButton, Alignment.TOP_CENTER);
149

    
150
        addContentComponent(vlayout, 1f);
151
    }
152

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

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

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

    
177
    /**
178
     * {@inheritDoc}
179
     */
180
    @Override
181
    protected String getSubHeaderText() {
182
        return SUBHEADER_DEEFAULT;
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)