Project

General

Profile

Revision b6ea271c

IDb6ea271ce3e275e7831ac0e6d070c15a02e9a30e
Parent ded94939
Child 1103009f

Added by Andreas Kohlbecker about 2 years ago

ref #6169 ToManyRelatedEntitiesComboboxSelect, CdmFilterablePagingProvider and CdmTitleCacheCaptionGenerator implemented

View differences:

src/main/java/eu/etaxonomy/cdm/service/CdmFilterablePagingProvider.java
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.service;
10

  
11
import java.util.Arrays;
12
import java.util.List;
13

  
14
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
15
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
16

  
17
import eu.etaxonomy.cdm.api.service.IIdentifiableEntityService;
18
import eu.etaxonomy.cdm.api.service.pager.Pager;
19
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
20
import eu.etaxonomy.cdm.persistence.query.MatchMode;
21
import eu.etaxonomy.cdm.persistence.query.OrderHint;
22

  
23
/**
24
 * @author a.kohlbecker
25
 * @since Jun 7, 2017
26
 *
27
 */
28
public class CdmFilterablePagingProvider<T extends IdentifiableEntity> implements FilterablePagingProvider<T>, FilterableCountProvider {
29

  
30
    private int pageSize = 20;
31

  
32
    private IIdentifiableEntityService<T> service;
33

  
34
    private MatchMode matchMode = MatchMode.ANYWHERE;
35

  
36
    private List<OrderHint> orderHints = OrderHint.ORDER_BY_TITLE_CACHE.asList();
37

  
38

  
39
    /**
40
     * @return the matchMode
41
     */
42
    protected MatchMode getMatchMode() {
43
        return matchMode;
44
    }
45

  
46
    /**
47
     * @param matchMode the matchMode to set
48
     */
49
    protected void setMatchMode(MatchMode matchMode) {
50
        this.matchMode = matchMode;
51
    }
52

  
53
    /**
54
     * @return the orderHints
55
     */
56
    protected List<OrderHint> getOrderHints() {
57
        return orderHints;
58
    }
59

  
60
    /**
61
     * @param orderHints the orderHints to set
62
     */
63
    protected void setOrderHints(List<OrderHint> orderHints) {
64
        this.orderHints = orderHints;
65
    }
66

  
67
    /**
68
     * @param service
69
     */
70
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service) {
71
        super();
72
        this.service = service;
73
    }
74

  
75
    /**
76
     * @param service
77
     * @param matchMode
78
     * @param orderHints
79
     */
80
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, MatchMode matchMode,
81
            List<OrderHint> orderHints) {
82
        super();
83
        this.service = service;
84
        this.matchMode = matchMode;
85
        this.orderHints = orderHints;
86
    }
87

  
88
    /**
89
     * {@inheritDoc}
90
     */
91
    @Override
92
    public List<T> findEntities(int firstRow, String filter) {
93
        Pager<T> page = service.findByTitle(
94
                null,
95
                filter,
96
                matchMode,
97
                null,
98
                pageSize,
99
                firstRow,
100
                orderHints,
101
                Arrays.asList("$")
102
              );
103
        return page.getRecords();
104
    }
105

  
106
    /**
107
     * {@inheritDoc}
108
     */
109
    @Override
110
    public int size(String filter) {
111
        Pager<T> page = service.findByTitle(
112
                null,
113
                filter,
114
                matchMode,
115
                null,
116
                1,
117
                0,
118
                null,
119
                null
120
              );
121
        return page.getCount().intValue();
122
    }
123

  
124
    /**
125
     * @return the pageSize
126
     */
127
    public int getPageSize() {
128
        return pageSize;
129
    }
130

  
131
    /**
132
     * @param pageSize the pageSize to set
133
     */
134
    public void setPageSize(int pageSize) {
135
        this.pageSize = pageSize;
136
    }
137

  
138
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/SelectFieldFactory.java
125 125
       return selectEditor;
126 126
   }
127 127

  
128

  
128 129
    /**
129 130
     * @param termType
130 131
     */
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
21 21
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
22 22
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
23 23
import eu.etaxonomy.vaadin.component.CompositeCustomField;
24
import eu.etaxonomy.vaadin.component.FieldListEditor;
24
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesListSelect;
25 25
import eu.etaxonomy.vaadin.component.SwitchableTextField;
26 26

  
27 27
/**
......
44 44
    // Fields for case when value is a Team
45 45
    private SwitchableTextField titleField = new SwitchableTextField("Team (bibliographic)");
46 46
    private SwitchableTextField nomenclaturalTitleField = new SwitchableTextField("Team (nomenclatural)");
47
    private FieldListEditor<Person, PersonField> personsListEditor = new FieldListEditor<Person, PersonField>(Person.class, PersonField.class, "Teammembers");
47
    private ToManyRelatedEntitiesListSelect<Person, PersonField> personsListEditor = new ToManyRelatedEntitiesListSelect<Person, PersonField>(Person.class, PersonField.class, "Teammembers");
48 48

  
49 49
    private BeanFieldGroup<Team> fieldGroup  = new BeanFieldGroup<>(Team.class);
50 50

  
src/main/java/eu/etaxonomy/cdm/vaadin/event/TaxonNameEditorAction.java
10 10

  
11 11
import com.vaadin.ui.Component;
12 12

  
13
import eu.etaxonomy.vaadin.mvp.AbstractView;
14

  
13 15
/**
14 16
 * @author a.kohlbecker
15 17
 * @since Mar 22, 2017
......
39 41
        super(type, entityId, source);
40 42
    }
41 43

  
44
    /**
45
     * @param action
46
     * @param source
47
     */
48
    public TaxonNameEditorAction(Action action, Component source) {
49
        super(action, source);
50
        // TODO Auto-generated constructor stub
51
    }
52

  
53
    /**
54
     * @param action
55
     * @param entityId
56
     * @param source
57
     * @param sourceView
58
     */
59
    public TaxonNameEditorAction(Action action, Integer entityId, Component source, AbstractView sourceView) {
60
        super(action, entityId, source, sourceView);
61
        // TODO Auto-generated constructor stub
62
    }
63

  
42 64

  
43 65

  
44 66

  
src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmTitleCacheCaptionGenerator.java
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.util;
10

  
11
import org.vaadin.viritin.fields.CaptionGenerator;
12

  
13
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
14

  
15
/**
16
 * @author a.kohlbecker
17
 * @since Jun 7, 2017
18
 *
19
 */
20
public final class CdmTitleCacheCaptionGenerator<T extends IdentifiableEntity> implements CaptionGenerator<T> {
21

  
22
    private static final long serialVersionUID = 3151383366731447990L;
23

  
24
    @Override
25
    public String getCaption(T option) {
26
        return option.getTitleCache();
27
    }
28
}
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/SetToListConverter.java
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.util.converter;
10

  
11
import java.util.ArrayList;
12
import java.util.HashSet;
13
import java.util.List;
14
import java.util.Locale;
15
import java.util.Set;
16

  
17
import com.vaadin.data.util.converter.Converter;
18

  
19
/**
20
 * @author a.kohlbecker
21
 * @since Jun 7, 2017
22
 *
23
 */
24
public final class SetToListConverter<V extends Object> implements Converter<List<V>, Set<V>> {
25

  
26
    private static final long serialVersionUID = -4453200532452354378L;
27

  
28
    Class<Set<V>> modelType = (Class<Set<V>>) new HashSet<V>(0).getClass();
29

  
30
    Class<List<V>> presentationType = (Class<List<V>>) new ArrayList<V>(0).getClass();
31

  
32
    @Override
33
    public Set<V> convertToModel(List<V> value, Class<? extends Set<V>> targetType, Locale locale)
34
            throws com.vaadin.data.util.converter.Converter.ConversionException {
35
        if(value != null){
36
            Set<V> set = new HashSet<>(value.size());
37
            set.addAll(value);
38
            return set;
39
        }
40
        return null;
41
    }
42

  
43
    @Override
44
    public List<V> convertToPresentation(Set<V> value, Class<? extends List<V>> targetType, Locale locale)
45
            throws com.vaadin.data.util.converter.Converter.ConversionException {
46
        if(value != null){
47
            List<V> list = new ArrayList<V>(value.size());
48
            list.addAll(value);
49
            return list;
50
        }
51
        return null;
52
    }
53

  
54
    @Override
55
    public Class<Set<V>> getModelType() {
56
        return modelType;
57
    }
58

  
59
    @Override
60
    public Class<List<V>> getPresentationType() {
61
        return presentationType;
62
    }
63
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.name;
10 10

  
11
import java.util.Arrays;
12
import java.util.List;
13

  
14
import org.vaadin.viritin.fields.CaptionGenerator;
15
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
16
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
17

  
18 11
import eu.etaxonomy.cdm.api.service.DeleteResult;
19 12
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
20
import eu.etaxonomy.cdm.api.service.pager.Pager;
21 13
import eu.etaxonomy.cdm.model.name.TaxonName;
22 14
import eu.etaxonomy.cdm.model.reference.Reference;
23
import eu.etaxonomy.cdm.persistence.query.MatchMode;
24
import eu.etaxonomy.cdm.persistence.query.OrderHint;
15
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
16
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
25 17
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
26 18

  
27 19
/**
......
40 32
    public void handleViewEntered() {
41 33
        super.handleViewEntered();
42 34

  
43
        getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CaptionGenerator<Reference>(){
44

  
45
            @Override
46
            public String getCaption(Reference option) {
47
                return option.getTitleCache();
48
            }
35
        getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
36
        CdmFilterablePagingProvider<Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference>(getRepo().getReferenceService());
37
        getView().getNomReferenceCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
49 38

  
50
        });
51
        getView().getNomReferenceCombobox().loadFrom(new FilterablePagingProvider<Reference>(){
52 39

  
53
            @Override
54
            public List<Reference> findEntities(int firstRow, String filter) {
55
                Pager<Reference> page = getRepo().getReferenceService().findByTitle(
56
                        null,
57
                        filter,
58
                        MatchMode.ANYWHERE,
59
                        null,
60
                        20,
61
                        firstRow,
62
                        OrderHint.ORDER_BY_TITLE_CACHE.asList(),
63
                        Arrays.asList("$")
64
                      );
65
                return page.getRecords();
66
            }},
67
            new FilterableCountProvider(){
68
                @Override
69
                public int size(String filter) {
70
                    Pager<Reference> page = getRepo().getReferenceService().findByTitle(
71
                            null,
72
                            filter,
73
                            MatchMode.ANYWHERE,
74
                            null,
75
                            1,
76
                            0,
77
                            null,
78
                            null
79
                          );
80
                    return page.getCount().intValue();
81
                }}
82
            , 20);
40
        getView().getBasionymCombobox().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
41
        CdmFilterablePagingProvider<TaxonName> namePagingProvider = new CdmFilterablePagingProvider<TaxonName>(getRepo().getNameService());
42
        getView().getBasionymCombobox().setPagingProviders(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize());
83 43
    }
84 44

  
85 45

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
13 13
import org.springframework.security.core.GrantedAuthority;
14 14

  
15 15
import com.vaadin.ui.Alignment;
16
import com.vaadin.ui.CheckBox;
16 17
import com.vaadin.ui.GridLayout;
17 18
import com.vaadin.ui.ListSelect;
18 19
import com.vaadin.ui.TextField;
......
25 26
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
26 27
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
27 28
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
29
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
28 30
import eu.etaxonomy.vaadin.component.SwitchableTextField;
31
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
29 32
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
30 33
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
31 34

  
......
40 43

  
41 44
    private final static int GRID_COLS = 4;
42 45

  
43
    private final static int GRID_ROWS = 10;
46
    private final static int GRID_ROWS = 12;
47

  
48
    private static final boolean HAS_BASIONYM_DEFAULT = false;
44 49

  
45 50
    private TextField genusOrUninomialField;
46 51

  
......
58 63

  
59 64
    private TextField nomenclaturalReferenceDetail;
60 65

  
66
    private TeamOrPersonField exBasionymAuthorshipField;
67

  
68
    private TeamOrPersonField basionymAuthorshipField;
69

  
70
    private ToManyRelatedEntitiesComboboxSelect<TaxonName> basionymCombobox;
71

  
72
    private CheckBox basionymToggle;
73

  
74
    private ListSelect rankSelect;
75

  
61 76

  
62 77
    /**
63 78
     * @param layout
......
100 115

  
101 116
        GridLayout grid = (GridLayout)getFieldLayout();
102 117
        grid.setSpacing(true);
118
        grid.setColumnExpandRatio(0, 0.3f);
119
        grid.setColumnExpandRatio(1, 0.3f);
120
        grid.setColumnExpandRatio(2, 0.3f);
121
        grid.setColumnExpandRatio(3, 0.0f);
103 122

  
104 123
        /*
105 124
         - nameType: preset, needs to be set in the presenter for new names
......
153 172
        */
154 173

  
155 174
        int row = 0;
156
        // FIXME add hasBasionymCheckox and toggle the according fields
157
        ListSelect rankSelect = selectFieldFactory.createListSelect("Rank", Rank.class, OrderHint.BY_ORDER_INDEX.asList(), "label");
175

  
176
        rankSelect = selectFieldFactory.createListSelect("Rank", Rank.class, OrderHint.BY_ORDER_INDEX.asList(), "label");
158 177
        rankSelect.setNullSelectionAllowed(false);
159 178
        rankSelect.setRows(1);
179
        rankSelect.setWidth(100, Unit.PERCENTAGE);
160 180
        rankSelect.addValueChangeListener(e -> updateFieldVisibility((Rank)e.getProperty().getValue()));
161
        addField(rankSelect, "rank", 3, row);
181
        addField(rankSelect, "rank", 2, row, 3, row);
162 182
        grid.setComponentAlignment(rankSelect, Alignment.TOP_RIGHT);
163 183
        row++;
164 184
        // fullTitleCache
......
182 202
        combinationAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
183 203
        addField(combinationAuthorshipField, "combinationAuthorship", 0, row, GRID_COLS-1, row);
184 204
        row++;
185
        // FIXME add basionym name field
186
        // FIXME add basionymAuthorship
187 205
        TeamOrPersonField exCombinationAuthorshipField = new TeamOrPersonField("Ex-combination author(s)");
188 206
        exCombinationAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
189 207
        addField(exCombinationAuthorshipField, "exCombinationAuthorship", 0, row, GRID_COLS-1, row);
190
        row++;
191
        TeamOrPersonField exBasionymAuthorshipField = new TeamOrPersonField("Ex-basionym author(s)");
192
        exBasionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
193
        addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
194
        row++;
195 208

  
196 209
        // nomenclaturalReference
210
        row++;
197 211
        nomReferenceCombobox = new ToOneRelatedEntityCombobox<Reference>("Nomenclatural reference", Reference.class);
198
        nomReferenceCombobox.setWidth(100, Unit.PERCENTAGE);
199 212
        nomReferenceCombobox.addClickListenerAddEntity(e -> getEventBus().publishEvent(
200 213
                new ReferenceEditorAction(AbstractEditorAction.Action.ADD, null, nomReferenceCombobox, this)
201 214
                ));
......
210 223
                );
211 224
            }
212 225
            });
213
        addField(nomReferenceCombobox, "nomenclaturalReference", 0, row, 3, row);
226
        nomReferenceCombobox.setWidth(300, Unit.PIXELS);
227
        addField(nomReferenceCombobox, "nomenclaturalReference", 0, row, 2, row);
228
        nomenclaturalReferenceDetail = addTextField("Reference detail", "nomenclaturalMicroReference", 3, row, 3, row);
229
        nomenclaturalReferenceDetail.setWidth(100, Unit.PIXELS);
230

  
231
        // Basionym
232
        row++;
233
        basionymToggle = new CheckBox("With basionym");
234
        basionymToggle.setValue(HAS_BASIONYM_DEFAULT);
235
        basionymToggle.addValueChangeListener(e -> {
236
                boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue();
237
                enableBasionymFields(enable);
238
            });
239
        basionymToggle.setStyleName(getDefaultComponentStyles());
240
        grid.addComponent(basionymToggle, 0, row);
241
        grid.setComponentAlignment(basionymToggle, Alignment.BOTTOM_LEFT);
242

  
243
        row++;
244
        basionymCombobox = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Basionym");
245
        /**
246
        basionymCombobox.newAdd(e -> getEventBus().publishEvent(
247
                new TaxonNameEditorAction(AbstractEditorAction.Action.ADD, null, basionymCombobox, this)
248
                ));
249
        basionymCombobox.addClickListenerEditEntity(e -> {
250
            if(basionymCombobox.getValue() != null){
251
                getEventBus().publishEvent(
252
                    new TaxonNameEditorAction(
253
                            AbstractEditorAction.Action.EDIT,
254
                            basionymCombobox.getValue().getId(),
255
                            basionymCombobox,
256
                            this)
257
                );
258
            }
259
            });
260
         **/
261
        basionymCombobox.setConverter(new SetToListConverter<TaxonName>());
262
        addField(basionymCombobox, "basionyms", 0, row, 3, row);
263
        basionymCombobox.setWidth(100, Unit.PERCENTAGE);
264
        grid.setComponentAlignment(basionymCombobox, Alignment.TOP_RIGHT);
265
        row++;
266
        basionymAuthorshipField = new TeamOrPersonField("Basionym author(s)");
267
        basionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
268
        addField(basionymAuthorshipField, "basionymAuthorship", 0, row, GRID_COLS-1, row);
214 269
        row++;
215
        nomenclaturalReferenceDetail = addTextField("Reference detail", "nomenclaturalMicroReference", 0, row, 1, row);
270
        exBasionymAuthorshipField = new TeamOrPersonField("Ex-basionym author(s)");
271
        exBasionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
272
        addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
273

  
274

  
216 275

  
217 276
        setAdvancedModeEnabled(true);
277
        enableBasionymFields(HAS_BASIONYM_DEFAULT);
218 278
        registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
279
        registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
280
        registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
281
        registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
282
        registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
219 283
        setAdvancedMode(false);
220 284

  
221 285
    }
222 286

  
223 287
    /**
288
     * @param value
289
     * @return
290
     */
291
    private void enableBasionymFields(boolean enable) {
292
        basionymAuthorshipField.setVisible(enable);
293
        exBasionymAuthorshipField.setVisible(enable);
294
        basionymCombobox.setVisible(enable);
295
    }
296

  
297
    /**
224 298
     * @param rank
225 299
     * @return
226 300
     */
......
257 331
        return nomReferenceCombobox;
258 332
    }
259 333

  
334
    /**
335
     * {@inheritDoc}
336
     */
337
    @Override
338
    public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymCombobox() {
339
        return basionymCombobox;
340
    }
341

  
260 342

  
261 343
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditorView.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.name;
10 10

  
11
import eu.etaxonomy.cdm.model.name.TaxonName;
11 12
import eu.etaxonomy.cdm.model.reference.Reference;
13
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
12 14
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
13 15
import eu.etaxonomy.vaadin.mvp.ApplicationView;
14 16

  
......
24 26
     */
25 27
    public ToOneRelatedEntityCombobox<Reference> getNomReferenceCombobox();
26 28

  
29
    /**
30
     * @return
31
     */
32
    public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymCombobox();
33

  
27 34
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowPresenter.java
190 190
            }
191 191
        } else
192 192
        if(TaxonName.class.isAssignableFrom(event.getEntityType())){
193
            if(workingset.getRegistrationDTOs().stream().anyMatch(reg -> reg.getTypifiedName().getId() == event.getEntityId())){
194
                refreshView();
193
            if(workingset.getRegistrationDTOs().stream().anyMatch(reg ->
194
                reg.getTypifiedName() != null
195
                && reg.getTypifiedName().getId() == event.getEntityId())){
196
                    refreshView();
195 197
            }
196 198
        } else
197 199
        if(TypeDesignationBase.class.isAssignableFrom(event.getEntityType())){
src/main/java/eu/etaxonomy/vaadin/component/SwitchableTextField.java
112 112
        return null;
113 113
    }
114 114

  
115
    /**
116
     * {@inheritDoc}
117
     */
118
    @Override
119
    public void setVisible(boolean visible) {
120
        super.setVisible(visible);
121
        // the unlockSwitch needs to be handled explicitly, for the textField this is not needed.
122
        unlockSwitch.setVisible(visible);
123
    }
124

  
125

  
126

  
127

  
115 128
}
src/main/java/eu/etaxonomy/vaadin/component/ToManyRelatedEntitiesComboboxSelect.java
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.vaadin.component;
10

  
11
import org.vaadin.viritin.fields.CaptionGenerator;
12
import org.vaadin.viritin.fields.LazyComboBox;
13
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
14
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
15

  
16
import com.vaadin.ui.Button.ClickListener;
17

  
18
/**
19
 * @author a.kohlbecker
20
 * @since Jun 7, 2017
21
 *
22
 */
23
public class ToManyRelatedEntitiesComboboxSelect<V extends Object> extends ToManyRelatedEntitiesListSelect<V, LazyComboBox<V>> {
24

  
25
    private static final long serialVersionUID = -4496067980953939548L;
26

  
27
    private FilterablePagingProvider<V> filterablePagingProvider = null;
28
    private FilterableCountProvider filterableCountProvider = null;
29
    private Integer pageLength = null;
30

  
31
    private CaptionGenerator<V> captionGenerator;
32

  
33
    /**
34
     * @param itemType
35
     * @param fieldType
36
     * @param caption
37
     */
38
    public ToManyRelatedEntitiesComboboxSelect(Class<V> itemType, String caption) {
39
        super(itemType, null, caption);
40
        // TODO this.fieldTyp = LazyComboBox.class does not work
41
        LazyComboBox<V> field = new LazyComboBox<V>(itemType);
42
        this.fieldType = (Class<LazyComboBox<V>>) field.getClass();
43

  
44

  
45
    }
46

  
47
    /**
48
     * {@inheritDoc}
49
     */
50
    @Override
51
    protected LazyComboBox<V> newFieldInstance(V val) throws InstantiationException, IllegalAccessException {
52
        LazyComboBox<V> field = new LazyComboBox<V>(itemType);
53

  
54
        if(filterablePagingProvider == null || filterableCountProvider == null ||  pageLength == null) {
55
            throw new RuntimeException("The filterablePagingProvider, filterableCountProvider and pageLength must be set, use setPagingProviders().");
56
        }
57
        field.loadFrom(filterablePagingProvider, filterableCountProvider, pageLength);
58
        if(captionGenerator != null){
59
            field.setCaptionGenerator(captionGenerator);
60
        }
61
        return field;
62
    }
63

  
64
    public void setPagingProviders(FilterablePagingProvider<V> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength){
65
        this.filterablePagingProvider = filterablePagingProvider;
66
        this.filterableCountProvider = filterableCountProvider;
67
        this.pageLength = pageLength;
68
    }
69

  
70
    /**
71
     * @param cdmTitleCacheCaptionGenerator
72
     */
73
    public void setCaptionGenerator(CaptionGenerator<V> captionGenerator) {
74
        this.captionGenerator = captionGenerator;
75
    }
76

  
77
    /**
78
     * {@inheritDoc}
79
     */
80
    @Override
81
    protected ClickListener newEditButtonClicklistener(LazyComboBox<V> field) {
82
        // TODO Auto-generated method stub
83
        return super.newEditButtonClicklistener(field);
84
    }
85

  
86
    /**
87
     * {@inheritDoc}
88
     */
89
    @Override
90
    protected ClickListener newAddButtonClicklistener(LazyComboBox<V> field) {
91
        // TODO Auto-generated method stub
92
        return super.newAddButtonClicklistener(field);
93
    }
94

  
95
    /**
96
     * {@inheritDoc}
97
     */
98
    @Override
99
    protected ClickListener newRemoveButtonClicklistener(LazyComboBox<V> field) {
100
        // TODO Auto-generated method stub
101
        return super.newRemoveButtonClicklistener(field);
102
    }
103

  
104

  
105

  
106
}
src/main/java/eu/etaxonomy/vaadin/component/ToManyRelatedEntitiesListSelect.java
15 15
import com.vaadin.server.FontAwesome;
16 16
import com.vaadin.ui.AbstractField;
17 17
import com.vaadin.ui.Button;
18
import com.vaadin.ui.Button.ClickListener;
18 19
import com.vaadin.ui.Component;
19 20
import com.vaadin.ui.CssLayout;
20 21
import com.vaadin.ui.GridLayout;
......
25 26
 * @since May 11, 2017
26 27
 *
27 28
 */
28
public class FieldListEditor<V extends Object, F extends AbstractField<V>>  extends CompositeCustomField<List<V>> {
29
public class ToManyRelatedEntitiesListSelect<V extends Object, F extends AbstractField<V>>  extends CompositeCustomField<List<V>> {
29 30

  
30 31
    private static final long serialVersionUID = 4670707714503199599L;
31 32

  
32
    private Class<F> fieldType;
33
    protected Class<F> fieldType;
33 34

  
34
    private Class<V> itemType;
35
    protected Class<V> itemType;
35 36

  
36 37
    private FieldGroup parentFieldGroup = null;
37 38

  
39
    protected boolean isOrderedCollection = false;
40

  
41
    private boolean withEditButton = false;
42

  
38 43
    //NOTE: Managing the item
39 44
    //      IDs makes BeanContainer more complex to use, but it is necessary in some cases where the
40 45
    //      equals() or hashCode() methods have been reimplemented in the bean.
......
47 52

  
48 53
    private GridLayout grid = new GridLayout(GRID_COLS,1);
49 54

  
50
    public  FieldListEditor(Class<V> itemType, Class<F> fieldType, String caption){
55
    public  ToManyRelatedEntitiesListSelect(Class<V> itemType, Class<F> fieldType, String caption){
51 56
        this.fieldType = fieldType;
52 57
        this.itemType = itemType;
53 58
        setCaption(caption);
54 59
        beans = new BeanItemContainer<V>(itemType);
55 60
    }
56 61

  
57
    private Component buttonGroup(){
62
    private Component buttonGroup(F field){
63

  
64
        CssLayout buttonGroup = new CssLayout();
58 65
        Button add = new Button(FontAwesome.PLUS);
66
        ClickListener addclickListerner = newRemoveButtonClicklistener(field);
67
        if(addclickListerner != null){
68
            add.addClickListener(addclickListerner);
69
        }
70

  
71
        if(withEditButton){
72
            Button edit = new Button(FontAwesome.EDIT);
73
            ClickListener editClickListerner = newEditButtonClicklistener(field);
74
            if(editClickListerner != null){
75
                edit.addClickListener(editClickListerner);
76
            }
77
            buttonGroup.addComponent(edit);
78
            addStyledComponents(edit);
79
        }
80

  
59 81
        Button remove = new Button(FontAwesome.MINUS);
60
        Button moveUp = new Button(FontAwesome.ARROW_UP);
61
        Button moveDown = new Button(FontAwesome.ARROW_DOWN);
62
        CssLayout buttonGroup = new CssLayout(add, remove, moveUp, moveDown);
63
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
82
        ClickListener removeclickListerner = newRemoveButtonClicklistener(field);
83
        if(removeclickListerner != null){
84
            remove.addClickListener(removeclickListerner);
85
        }
64 86

  
65
        addStyledComponents(add, remove, moveUp, moveDown);
87
        buttonGroup.addComponent(add);
88
        buttonGroup.addComponent(remove);
89
        addStyledComponents(add, remove);
90
        if(isOrderedCollection){
91
            Button moveUp = new Button(FontAwesome.ARROW_UP);
92
            Button moveDown = new Button(FontAwesome.ARROW_DOWN);
93
            buttonGroup.addComponents(moveUp, moveDown);
94
            addStyledComponents(moveUp, moveDown);
95
        }
96
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
66 97

  
67 98
        return buttonGroup;
68 99
    }
69 100

  
70 101
    /**
102
     * @param field
103
     * @return
104
     */
105
    protected ClickListener newEditButtonClicklistener(F field) {
106
        return null;
107
    }
108

  
109
    /**
110
     * @return
111
     */
112
    protected ClickListener newAddButtonClicklistener(F field) {
113
        return null;
114
    }
115

  
116
    /**
117
     * @return
118
     */
119
    protected ClickListener newRemoveButtonClicklistener(F field) {
120
        return null;
121
    }
122

  
123
    /**
71 124
     * {@inheritDoc}
72 125
     */
73 126
    @Override
......
91 144
    protected void setInternalValue(List<V> newValue) {
92 145
        super.setInternalValue(newValue);
93 146

  
147
        // newValue is already converted, need to use the original value from the dataasource
148
        isOrderedCollection = List.class.isAssignableFrom(getPropertyDataSource().getValue().getClass());
149

  
94 150
        beans.addAll(newValue);
95 151

  
96 152
        grid.setRows(newValue.size());
......
107 163
     */
108 164
    protected int addNewRow(int row, V val) {
109 165
        try {
110
            F field = fieldType.newInstance();
166
            F field = newFieldInstance(val);
111 167
            addStyledComponent(field);
112
            field.setWidth(100, Unit.PERCENTAGE);
113
            field.setValue(val);
114 168
            grid.addComponent(field, 0, row);
115
            grid.addComponent(buttonGroup(), 1, row);
169
            grid.addComponent(buttonGroup(field), 1, row);
116 170
            nestFieldGroup(field);
117 171
            row++;
118 172
        } catch (InstantiationException e) {
......
126 180
    }
127 181

  
128 182
    /**
183
     * @param val
184
     * @return
185
     * @throws InstantiationException
186
     * @throws IllegalAccessException
187
     */
188
    protected F newFieldInstance(V val) throws InstantiationException, IllegalAccessException {
189
        F field = fieldType.newInstance();
190
        field.setWidth(100, Unit.PERCENTAGE);
191
        field.setValue(val);
192
        return field;
193
    }
194

  
195
    /**
129 196
     * @param field
130 197
     */
131 198
    protected void nestFieldGroup(F field) {
......
176 243
        parentFieldGroup = parent;
177 244
    }
178 245

  
246
    public void withEditButton(boolean withEditButton){
247
        this.withEditButton = withEditButton;
248
    }
249

  
179 250

  
180 251

  
181 252

  
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
554 554
     * {@link FieldGroup#configureField(Field<?> field)} method will be called.
555 555
     * In this method all fields are set to default states defined for the fieldGroup.
556 556
     * <p>
557
     * You can now implement this method if you need to configure the enable state of fields
558
     * individually.
557
     * You can now implement this method if you need to modify the state or value of individual fields.
559 558
     */
560 559
    protected void afterItemDataSourceSet() {
561

  
562 560
    }
563 561

  
564 562
    // ------------------------ issue related temporary solutions --------------------- //
......
570 568
     *
571 569
     * @return
572 570
     * @deprecated marked deprecated to emphasize on the special character of this method
573
     *    which should only be used interlally see #6673
571
     *    which should only be used internally see #6673
574 572
     */
575 573
    @Deprecated
576 574
    public P presenter() {
src/main/webapp/VAADIN/themes/edit-valo/edit-valo.scss
1 1
// Global variable overrides. Must be declared before importing Valo.
2 2

  
3 3
// Defines the plaintext font size, weight and family. Font size affects general component sizing.
4
//$v-font-size: 16px;
4
$v-font-size: 14px; // default in valo is 16px
5 5
//$v-font-weight: 300;
6 6
$v-font-family: "Open Sans", sans-serif;
7 7

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)