2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.view
.occurrence
;
11 import org
.springframework
.context
.annotation
.Scope
;
13 import com
.vaadin
.spring
.annotation
.SpringComponent
;
14 import com
.vaadin
.ui
.GridLayout
;
15 import com
.vaadin
.ui
.TextField
;
17 import eu
.etaxonomy
.cdm
.api
.util
.RoleProberImpl
;
18 import eu
.etaxonomy
.cdm
.api
.util
.UserHelper
;
19 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
20 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
21 import eu
.etaxonomy
.cdm
.service
.UserHelperAccess
;
22 import eu
.etaxonomy
.cdm
.vaadin
.event
.CollectionEditorAction
;
23 import eu
.etaxonomy
.cdm
.vaadin
.event
.InstitutionEditorAction
;
24 import eu
.etaxonomy
.cdm
.vaadin
.event
.ToOneRelatedEntityButtonUpdater
;
25 import eu
.etaxonomy
.cdm
.vaadin
.ui
.RegistrationUIDefaults
;
26 import eu
.etaxonomy
.cdm
.vaadin
.util
.CdmTitleCacheCaptionGenerator
;
27 import eu
.etaxonomy
.cdm
.vaadin
.util
.CollectionCaptionGenerator
;
28 import eu
.etaxonomy
.vaadin
.component
.ToOneRelatedEntityCombobox
;
29 import eu
.etaxonomy
.vaadin
.event
.EditorActionType
;
30 import eu
.etaxonomy
.vaadin
.mvp
.AbstractCdmPopupEditor
;
33 * @author a.kohlbecker
38 public class CollectionPopupEditor
extends AbstractCdmPopupEditor
<Collection
, CollectionEditorPresenter
> implements CollectionPopupEditorView
{
40 private static final long serialVersionUID
= 2019724189877425882L;
42 private static final int GRID_COLS
= 3;
44 private static final int GRID_ROWS
= 4;
46 private TextField nameField
;
47 private TextField codeField
;
48 private TextField codeStandardField
;
49 private TextField townOrLocationField
;
50 private ToOneRelatedEntityCombobox
<Collection
> superCollectionCombobox
;
51 private ToOneRelatedEntityCombobox
<Institution
> institutionCombobox
;
53 public CollectionPopupEditor() {
54 super(new GridLayout(GRID_COLS
, GRID_ROWS
), Collection
.class);
58 public String
getWindowCaption() {
59 return "Collection editor";
63 public int getWindowWidth() {
68 public void focusFirst() {
73 protected String
getDefaultComponentStyles() {
78 protected void initContent() {
83 townOrLocation : String
84 institute : Institution
85 superCollection : Collection
87 GridLayout grid
= (GridLayout
)getFieldLayout();
89 grid
.setSpacing(true);
90 // grid.setColumnExpandRatio(0, 0.3f);
91 // grid.setColumnExpandRatio(1, 0.3f);
92 // grid.setColumnExpandRatio(2, 0.3f);
93 // grid.setColumnExpandRatio(3, 0.0f);
96 codeField
= addTextField("Code", "code", 0, row
, 0, row
);
97 codeField
.setWidth(100, Unit
.PERCENTAGE
);
99 codeStandardField
= addTextField("Code standard", "codeStandard", 1, row
, 1, row
);
100 codeStandardField
.setWidth(100, Unit
.PERCENTAGE
);
102 townOrLocationField
= addTextField("Town or location", "townOrLocation", 2, row
, 2, row
);
103 townOrLocationField
.setWidth(100, Unit
.PERCENTAGE
);
106 nameField
= addTextField("Name", "name", 0, row
, 2, row
);
107 nameField
.setWidth(100, Unit
.PERCENTAGE
);
110 superCollectionCombobox
= new ToOneRelatedEntityCombobox
<>("In collection", Collection
.class);
112 addField(superCollectionCombobox
, "superCollection", 0, row
, 2, row
);
114 superCollectionCombobox
.getSelect().setCaptionGenerator(
115 new CollectionCaptionGenerator()
117 superCollectionCombobox
.setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater
<Collection
>(superCollectionCombobox
));
119 superCollectionCombobox
.addClickListenerAddEntity( e
-> getViewEventBus().publish(this,
120 new CollectionEditorAction(
121 EditorActionType
.ADD
,
123 superCollectionCombobox
,
126 superCollectionCombobox
.addClickListenerEditEntity(e
-> {
127 if(superCollectionCombobox
.getValue() != null){
128 getViewEventBus().publish(this,
129 new CollectionEditorAction(
130 EditorActionType
.EDIT
,
131 superCollectionCombobox
.getValue().getUuid(),
133 superCollectionCombobox
,
140 UserHelper userHelper
= UserHelperAccess
.userHelper();
141 superCollectionCombobox
.setVisible(RegistrationUIDefaults
.COLLECTION_EDITOR_SUB_COLLECTION_VISIBILITY_RESTRICTION
.stream().anyMatch( role
-> userHelper
.userIs(new RoleProberImpl(role
))));
144 institutionCombobox
= new ToOneRelatedEntityCombobox
<Institution
>("Institute", Institution
.class);
145 addField(institutionCombobox
, "institute", 0, row
, 2, row
);
147 institutionCombobox
.getSelect().setCaptionGenerator(
148 new CdmTitleCacheCaptionGenerator
<Institution
>()
150 institutionCombobox
.setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater
<Institution
>(institutionCombobox
));
152 institutionCombobox
.addClickListenerAddEntity( e
-> getViewEventBus().publish(this,
153 new InstitutionEditorAction(
154 EditorActionType
.ADD
,
159 institutionCombobox
.addClickListenerEditEntity(e
-> {
160 if(institutionCombobox
.getValue() != null){
161 getViewEventBus().publish(this,
162 new InstitutionEditorAction(
163 EditorActionType
.EDIT
,
164 institutionCombobox
.getValue().getUuid(),
174 /* ------------------ View Interface methods -------------------- */
176 public ToOneRelatedEntityCombobox
<Collection
> getSuperCollectionCombobox() {
177 return superCollectionCombobox
;
181 public ToOneRelatedEntityCombobox
<Institution
> getInstitutionCombobox() {
182 return institutionCombobox
;