1
|
/**
|
2
|
* Copyright (C) 2019 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.reference;
|
10
|
|
11
|
import java.util.EnumSet;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
14
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
15
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
|
16
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
17
|
import eu.etaxonomy.vaadin.mvp.EditorFormConfigurator;
|
18
|
|
19
|
/**
|
20
|
* @author a.kohlbecker
|
21
|
* @since Mar 22, 2019
|
22
|
*
|
23
|
*/
|
24
|
public class RegistrationUiReferenceEditorFormConfigurator implements EditorFormConfigurator<ReferencePopupEditor> {
|
25
|
|
26
|
boolean limitToSectionEditing;
|
27
|
|
28
|
boolean typeSelectReadonly;
|
29
|
|
30
|
EnumSet<ReferenceType> sectionTypes = EnumSet.of(ReferenceType.Section, ReferenceType.BookSection);
|
31
|
|
32
|
public static RegistrationUiReferenceEditorFormConfigurator create(boolean limitToSectionEditing) {
|
33
|
return new RegistrationUiReferenceEditorFormConfigurator(limitToSectionEditing);
|
34
|
}
|
35
|
|
36
|
public RegistrationUiReferenceEditorFormConfigurator configure(ReferencePopupEditor referenceEditorPopup, BeanInstantiator<Reference> beanInstantiator) {
|
37
|
referenceEditorPopup.setEditorComponentsConfigurator(this);
|
38
|
if(beanInstantiator != null) {
|
39
|
referenceEditorPopup.setBeanInstantiator(beanInstantiator);
|
40
|
}
|
41
|
return this;
|
42
|
}
|
43
|
|
44
|
private RegistrationUiReferenceEditorFormConfigurator(boolean limitToSectionEditing){
|
45
|
this.limitToSectionEditing = limitToSectionEditing;
|
46
|
}
|
47
|
|
48
|
public RegistrationUiReferenceEditorFormConfigurator typeSelectReadonly(boolean typeSelectReadonly) {
|
49
|
this.typeSelectReadonly = typeSelectReadonly;
|
50
|
return this;
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public void updateComponentStates(AbstractPopupEditor<?, ?> popupEditor) {
|
55
|
ReferencePopupEditor refEditor = (ReferencePopupEditor)popupEditor;
|
56
|
if(limitToSectionEditing){
|
57
|
boolean isSection = sectionTypes.contains(refEditor.getBean().getType());
|
58
|
// editing of the inRefernce should be allowed if the reference in the editor is not a section
|
59
|
refEditor.getInReferenceCombobox().setAddButtonEnabled(!isSection);
|
60
|
refEditor.getInReferenceCombobox().getSelect().setEnabled(!isSection);
|
61
|
// the user should be able to edit the inRefernce of a section from here
|
62
|
refEditor.getInReferenceCombobox().setEditButtonEnabled(true);
|
63
|
refEditor.getTypeSelect().setEnabled(false);
|
64
|
}
|
65
|
if(typeSelectReadonly) {
|
66
|
refEditor.getTypeSelect().setEnabled(false);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
}
|