Project

General

Profile

Download (9.08 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 String accessDeniedMessage;
70

    
71
    private static final String ELEMENT_WIDTH = "330px";
72

    
73

    
74
    public StartRegistrationViewBean() {
75
        super();
76
    }
77

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

    
84
        getLayout().setId(NAME);
85

    
86
        VerticalLayout vlayout = new VerticalLayout();
87
        vlayout.setSpacing(true);
88
        vlayout.setMargin(true);
89

    
90
        HorizontalLayout publicationLayout = new HorizontalLayout();
91
        publicationLayout.setSpacing(true);
92

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

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

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

    
114
        searchModeOptions.addItem(MatchMode.BEGINNING);
115
        searchModeOptions.setItemCaption(MatchMode.BEGINNING, "Begins with");
116
        searchModeOptions.addItem(MatchMode.ANYWHERE);
117
        searchModeOptions.setItemCaption(MatchMode.ANYWHERE, "Contains");
118
        searchModeOptions.setValue(MatchMode.BEGINNING);
119
        searchModeOptions.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
120
        searchModeOptions.addStyleName(EditValoTheme.OPTIONGROUP_CAPTION_FIX);
121
        searchModeOptions.addValueChangeListener(e -> getPresenter().updateReferenceSearchMode((MatchMode)e.getProperty().getValue()));
122

    
123
        newPublicationButton = new Button("New");
124
        newPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
125
                new ReferenceEditorAction(EditorActionType.ADD, newPublicationButton, null, this)
126
                ));
127
        newPublicationButton.setCaption("New");
128
        newPublicationButton.setWidth(ELEMENT_WIDTH);
129

    
130
        newPublicationLabel = new Label();
131
        newPublicationLabel.setVisible(false);
132

    
133
        removeNewPublicationButton = new Button("Delete");
134
        removeNewPublicationButton.setStyleName(ValoTheme.BUTTON_DANGER);
135
        removeNewPublicationButton.setWidth(ELEMENT_WIDTH);
136
        removeNewPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
137
                new ReferenceEditorAction(EditorActionType.REMOVE, removeNewPublicationButton, null, this)
138
                ));
139

    
140
        removeNewPublicationButton.setVisible(false);
141

    
142
        Label labelLeft = new Label("Choose from existing publications");
143
        Label labelRight = new Label("Create a new publication");
144
        labelLeft.setWidth(ELEMENT_WIDTH);
145
        labelRight.setWidth(ELEMENT_WIDTH);
146

    
147
        CssLayout leftContainer = new CssLayout(labelLeft, referenceCombobox, searchModeOptions);
148
        CssLayout rightContainer = new CssLayout(labelRight, newPublicationButton, removeNewPublicationButton, newPublicationLabel);
149
        leftContainer.setWidth(ELEMENT_WIDTH);
150
        rightContainer.setWidth(ELEMENT_WIDTH);
151

    
152
        publicationLayout.addComponents(
153
                leftContainer,
154
                rightContainer
155
                );
156
        publicationLayout.setComponentAlignment(leftContainer, Alignment.TOP_RIGHT);
157
        publicationLayout.setComponentAlignment(rightContainer, Alignment.TOP_LEFT);
158

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

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

    
180
        vlayout.addComponents(publicationLayout, continueButton);
181
        vlayout.setComponentAlignment(publicationLayout, Alignment.TOP_CENTER);
182
        vlayout.setComponentAlignment(continueButton, Alignment.TOP_CENTER);
183

    
184
        addContentComponent(vlayout, 1f);
185
    }
186

    
187
    /**
188
     * {@inheritDoc}
189
     */
190
    @Override
191
    public boolean allowAnonymousAccess() {
192
        return false;
193
    }
194

    
195
    /**
196
     * {@inheritDoc}
197
     */
198
    @Override
199
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
200
        return null;
201
    }
202

    
203
    @Override
204
    public String getAccessDeniedMessage() {
205
        return accessDeniedMessage;
206
    }
207

    
208
    @Override
209
    public void setAccessDeniedMessage(String accessDeniedMessage) {
210
        this.accessDeniedMessage = accessDeniedMessage;
211
    }
212

    
213

    
214
    /**
215
     * {@inheritDoc}
216
     */
217
    @Override
218
    protected String getHeaderText() {
219
        return "New Registration";
220
    }
221

    
222
    /**
223
     * {@inheritDoc}
224
     */
225
    @Override
226
    protected String getSubHeaderText() {
227
        return SUBHEADER_DEEFAULT;
228
    }
229

    
230
    /**
231
     * {@inheritDoc}
232
     */
233
    @Override
234
    public void enter(ViewChangeEvent event) {
235

    
236
        getPresenter().handleViewEntered();
237

    
238
    }
239

    
240
    // ------- StartRegistrationView interface methods ----- //
241

    
242
    /**
243
     * @return the referenceCombobox
244
     */
245
    @Override
246
    public LazyComboBox<TypedEntityReference<Reference>> getReferenceCombobox() {
247
        return referenceCombobox;
248
    }
249

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

    
258
    /**
259
     * @return the newPublicationButton
260
     */
261
    @Override
262
    public Button getRemoveNewPublicationButton() {
263
        return removeNewPublicationButton;
264
    }
265

    
266
    /**
267
     * @return the newPublicationButton
268
     */
269
    @Override
270
    public Button getContinueButton() {
271
        return continueButton;
272
    }
273

    
274
    /**
275
     * @return the newPublicationLabel
276
     */
277
    @Override
278
    public Label getNewPublicationLabel() {
279
        return newPublicationLabel;
280
    }
281

    
282

    
283

    
284
}
(18-18/21)