Project

General

Profile

Download (8.61 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.AbstractSelect;
21
import com.vaadin.ui.Alignment;
22
import com.vaadin.ui.Button;
23
import com.vaadin.ui.ComboBox;
24
import com.vaadin.ui.CssLayout;
25
import com.vaadin.ui.HorizontalLayout;
26
import com.vaadin.ui.Label;
27
import com.vaadin.ui.OptionGroup;
28
import com.vaadin.ui.VerticalLayout;
29
import com.vaadin.ui.themes.ValoTheme;
30

    
31
import eu.etaxonomy.cdm.model.reference.Reference;
32
import eu.etaxonomy.cdm.persistence.query.MatchMode;
33
import eu.etaxonomy.cdm.ref.TypedEntityReference;
34
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
35
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
36
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
37
import eu.etaxonomy.cdm.vaadin.theme.EditValoTheme;
38
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
39
import eu.etaxonomy.vaadin.event.EditorActionType;
40

    
41
/**
42
 * @author a.kohlbecker
43
 * @since Mar 2, 2017
44
 *
45
 */
46
@SpringView(name=StartRegistrationViewBean.NAME)
47
public class StartRegistrationViewBean extends AbstractPageView<StartRegistrationPresenter>
48
    implements StartRegistrationView, AccessRestrictedView, View {
49

    
50
    private static final long serialVersionUID = -9055865292188732909L;
51

    
52
    public static final String NAME = "regStart";
53

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

    
57
    private LazyComboBox<TypedEntityReference<Reference>> referenceCombobox;
58

    
59
    private OptionGroup searchModeOptions = new OptionGroup("Search mode");
60

    
61
    private Button newPublicationButton;
62

    
63
    private Button removeNewPublicationButton;
64

    
65
    private Label newPublicationLabel;
66

    
67
    private Button continueButton;
68

    
69
    private static final String ELEMENT_WIDTH = "330px";
70

    
71

    
72
    public StartRegistrationViewBean() {
73
        super();
74
    }
75

    
76
    /**
77
     * {@inheritDoc}
78
     */
79
    @Override
80
    protected void initContent() {
81

    
82
        getLayout().setId(NAME);
83

    
84
        VerticalLayout vlayout = new VerticalLayout();
85
        vlayout.setSpacing(true);
86
        vlayout.setMargin(true);
87

    
88
        HorizontalLayout publicationLayout = new HorizontalLayout();
89
        publicationLayout.setSpacing(true);
90

    
91
        Class<TypedEntityReference<Reference>> type = (Class<TypedEntityReference<Reference>>) new TypedEntityReference<Reference>(Reference.class, null).getClass();
92
        referenceCombobox = new LazyComboBox<TypedEntityReference<Reference>>(type) {
93

    
94
            @Override
95
            protected void setSelectInstance(AbstractSelect select) {
96
                if(select instanceof ComboBox){
97
                    ComboBox combobox = (ComboBox)select;
98
                    // uncomment the below line to set a defined width for the ComboBox popup
99
                    // combobox.setPopupWidth("200%");
100
                }
101
                super.setSelectInstance(select);
102
            }
103

    
104
        };
105
        referenceCombobox.setWidth(ELEMENT_WIDTH);
106
        referenceCombobox.setBuffered(false);
107
        referenceCombobox.addValueChangeListener( e -> {
108
            boolean isValueSelected = e.getProperty().getValue() != null;
109
            continueButton.setEnabled(isValueSelected);
110
        });
111

    
112
        searchModeOptions.addItems(MatchMode.BEGINNING, MatchMode.ANYWHERE);
113
        searchModeOptions.setValue(MatchMode.BEGINNING);
114
        searchModeOptions.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
115
        searchModeOptions.addStyleName(EditValoTheme.OPTIONGROUP_CAPTION_FIX);
116
        searchModeOptions.addValueChangeListener(e -> getPresenter().updateReferenceSearchMode((MatchMode)e.getProperty().getValue()));
117

    
118
        newPublicationButton = new Button("New");
119
        newPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
120
                new ReferenceEditorAction(EditorActionType.ADD, newPublicationButton, null, this)
121
                ));
122
        newPublicationButton.setCaption("New");
123
        newPublicationButton.setWidth(ELEMENT_WIDTH);
124

    
125
        newPublicationLabel = new Label();
126
        newPublicationLabel.setVisible(false);
127

    
128
        removeNewPublicationButton = new Button("Delete");
129
        removeNewPublicationButton.setStyleName(ValoTheme.BUTTON_DANGER);
130
        removeNewPublicationButton.setWidth(ELEMENT_WIDTH);
131
        removeNewPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
132
                new ReferenceEditorAction(EditorActionType.REMOVE, removeNewPublicationButton, null, this)
133
                ));
134

    
135
        removeNewPublicationButton.setVisible(false);
136

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

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

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

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

    
159
            UUID refUuid = null;
160
            referenceCombobox.commit();
161
            if(referenceCombobox.getValue() != null){
162
                refUuid = referenceCombobox.getValue().getUuid();
163
            }
164
            getViewEventBus().publish(this,
165
                new RegistrationEditorAction(EditorActionType.ADD,
166
                        // passing the refId is hack, bit for some reason the presenter is always referring to the wrong view
167
                        refUuid,
168
                        continueButton,
169
                        null,
170
                        StartRegistrationViewBean.this)
171
                );
172
              }
173
            );
174

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

    
179
        addContentComponent(vlayout, 1f);
180
    }
181

    
182
    /**
183
     * {@inheritDoc}
184
     */
185
    @Override
186
    public boolean allowAnonymousAccess() {
187
        return false;
188
    }
189

    
190
    /**
191
     * {@inheritDoc}
192
     */
193
    @Override
194
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
195
        return null;
196
    }
197

    
198
    /**
199
     * {@inheritDoc}
200
     */
201
    @Override
202
    protected String getHeaderText() {
203
        return "New Registration";
204
    }
205

    
206
    /**
207
     * {@inheritDoc}
208
     */
209
    @Override
210
    protected String getSubHeaderText() {
211
        return SUBHEADER_DEEFAULT;
212
    }
213

    
214
    /**
215
     * {@inheritDoc}
216
     */
217
    @Override
218
    public void enter(ViewChangeEvent event) {
219

    
220
        getPresenter().handleViewEntered();
221

    
222
    }
223

    
224
    // ------- StartRegistrationView interface methods ----- //
225

    
226
    /**
227
     * @return the referenceCombobox
228
     */
229
    @Override
230
    public LazyComboBox<TypedEntityReference<Reference>> getReferenceCombobox() {
231
        return referenceCombobox;
232
    }
233

    
234
    /**
235
     * @return the newPublicationButton
236
     */
237
    @Override
238
    public Button getNewPublicationButton() {
239
        return newPublicationButton;
240
    }
241

    
242
    /**
243
     * @return the newPublicationButton
244
     */
245
    @Override
246
    public Button getRemoveNewPublicationButton() {
247
        return removeNewPublicationButton;
248
    }
249

    
250
    /**
251
     * @return the newPublicationButton
252
     */
253
    @Override
254
    public Button getContinueButton() {
255
        return continueButton;
256
    }
257

    
258
    /**
259
     * @return the newPublicationLabel
260
     */
261
    @Override
262
    public Label getNewPublicationLabel() {
263
        return newPublicationLabel;
264
    }
265

    
266

    
267

    
268
}
(18-18/21)