Project

General

Profile

Revision 90e5b45a

ID90e5b45a71c8b48e029fbbbc5d0393022f0f041e
Parent c7936eb4
Child 1faff10b

Added by Andreas Kohlbecker over 1 year ago

fix #7570 implementing intitution editor with basic set of fields

View differences:

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

  
11
import java.util.UUID;
12

  
13
import com.vaadin.ui.Button;
14
import com.vaadin.ui.Field;
15

  
16
import eu.etaxonomy.cdm.model.agent.Institution;
17
import eu.etaxonomy.vaadin.event.EditorActionType;
18
import eu.etaxonomy.vaadin.mvp.AbstractView;
19

  
20
/**
21
 * @author a.kohlbecker
22
 * @since Mar 22, 2017
23
 */
24
public class InstitutionEditorAction extends AbstractEditorAction<Institution> {
25

  
26
    /**
27
     * @param eventType
28
     */
29
    public InstitutionEditorAction(EditorActionType type) {
30
        super(type);
31
    }
32

  
33
    /**
34
     * @param action
35
     * @param source
36
     */
37
    public InstitutionEditorAction(EditorActionType action, Button source, Field<Institution> target, AbstractView sourceView) {
38
        super(action, source, target, sourceView);
39
    }
40

  
41
    /**
42
     * @param action
43
     * @param entityId
44
     * @param source
45
     * @param sourceView
46
     */
47
    public InstitutionEditorAction(EditorActionType action, UUID entityUuid, Button source, Field<Institution> target, AbstractView sourceView) {
48
        super(action, entityUuid, source, target, sourceView);
49
    }
50

  
51
}
src/main/java/eu/etaxonomy/cdm/vaadin/model/common/AgentBaseDTO.java
1
/**
2
* Copyright (C) 2018 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.model.common;
10

  
11
import eu.etaxonomy.cdm.model.agent.AgentBase;
12
import eu.etaxonomy.cdm.vaadin.model.CdmEntityAdapterDTO;
13

  
14
/**
15
 * @author a.kohlbecker
16
 * @since Jul 25, 2018
17
 *
18
 */
19
public class AgentBaseDTO extends CdmEntityAdapterDTO<AgentBase<?>> {
20

  
21
    private static final long serialVersionUID = 8457280951445449327L;
22

  
23
    /**
24
     * @param entity
25
     */
26
    public AgentBaseDTO(AgentBase<?> entity) {
27
        super(entity);
28
        // TODO Auto-generated constructor stub
29
    }
30

  
31
}
src/main/java/eu/etaxonomy/cdm/vaadin/model/common/InstitutionDTO.java
1
/**
2
* Copyright (C) 2018 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.model.common;
10

  
11
import eu.etaxonomy.cdm.model.agent.Institution;
12
import eu.etaxonomy.cdm.vaadin.model.CdmEntityAdapterDTO;
13

  
14
/**
15
 * @author a.kohlbecker
16
 * @since Jul 25, 2018
17
 *
18
 */
19
public class InstitutionDTO extends CdmEntityAdapterDTO<Institution> {
20

  
21
    private static final long serialVersionUID = 8457280951445449327L;
22

  
23
    /**
24
     * @param entity
25
     */
26
    public InstitutionDTO(Institution entity) {
27
        super(entity);
28
    }
29

  
30
    public void setCode(String code){
31
        entity.setCode(code);
32
    }
33

  
34
    public String getCode(){
35
        return entity.getCode();
36
    }
37

  
38
    /**
39
     * Returns the full name, as distinct from a code, an acronym or initials,
40
     * by which this institution is generally known.
41
     */
42
    public String getName(){
43
        return entity.getName();
44
    }
45
    /**
46
     * @see    #getName()
47
     */
48
    public void setName(String name){
49
        entity.setName(name);
50
    }
51

  
52
    /**
53
     * Returns the parent institution of this institution.
54
     * This is for instance the case when this institution is a herbarium
55
     * belonging to a parent institution such as a museum.
56
     */
57
    public Institution getIsPartOf(){
58
        return entity.getIsPartOf();
59
    }
60

  
61
    /**
62
     * Assigns a parent institution to which this institution belongs.
63
     *
64
     * @param  isPartOf  the parent institution
65
     * @see    #getIsPartOf()
66
     */
67
    public void setIsPartOf(Institution parentInstitution){
68
        entity.setIsPartOf(parentInstitution);
69
    }
70

  
71

  
72
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/common/InstitutionEditorPresenter.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.view.common;
10

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

  
15
import org.springframework.context.annotation.Scope;
16
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
17

  
18
import com.vaadin.spring.annotation.SpringComponent;
19

  
20
import eu.etaxonomy.cdm.api.service.IService;
21
import eu.etaxonomy.cdm.model.agent.AgentBase;
22
import eu.etaxonomy.cdm.model.agent.Institution;
23
import eu.etaxonomy.cdm.model.occurrence.Collection;
24
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
25
import eu.etaxonomy.cdm.service.UserHelperAccess;
26
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
27
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
28
import eu.etaxonomy.cdm.vaadin.event.InstitutionEditorAction;
29
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
30
import eu.etaxonomy.cdm.vaadin.model.common.InstitutionDTO;
31
import eu.etaxonomy.vaadin.mvp.AbstractCdmDTOEditorPresenter;
32
import eu.etaxonomy.vaadin.mvp.BoundField;
33
import eu.etaxonomy.vaadin.ui.view.PopupView;
34

  
35
/**
36
 * @author a.kohlbecker
37
 * @since Dec 21, 2017
38
 *
39
 */
40
@SpringComponent
41
@Scope("prototype")
42
public class InstitutionEditorPresenter extends AbstractCdmDTOEditorPresenter<InstitutionDTO, Institution, InstitutionPopupEditorView> {
43

  
44
    private static final long serialVersionUID = -1996365248431425021L;
45

  
46

  
47
    /**
48
     * {@inheritDoc}
49
     */
50
    @Override
51
    protected Institution loadCdmEntity(UUID identifier) {
52

  
53
        List<String> initStrategy = Arrays.asList(new String []{
54

  
55
                "$",
56
                "contact.$",
57
                "isPartOf.$",
58
                }
59
        );
60

  
61
        Institution bean;
62
        if(identifier != null){
63
            bean = (Institution) getRepo().getAgentService().load(identifier, initStrategy);
64
        } else {
65
            bean = Institution.NewInstance();
66
        }
67
        return bean;
68
    }
69

  
70
    /**
71
     * {@inheritDoc}
72
     */
73
    @Override
74
    protected void guaranteePerEntityCRUDPermissions(UUID identifier) {
75
        if(crud != null){
76
            newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(Collection.class, identifier, crud, null);
77
        }
78

  
79
    }
80

  
81
    /**
82
     * {@inheritDoc}
83
     */
84
    @Override
85
    protected void guaranteePerEntityCRUDPermissions(Institution bean) {
86
        if(crud != null){
87
            newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, crud, null);
88
        }
89

  
90
    }
91

  
92
    /**
93
     * {@inheritDoc}
94
     */
95
    @Override
96
    protected IService<Institution> getService() {
97
        // TODO Auto-generated method stub
98
        return null;
99
    }
100

  
101
    /**
102
     * {@inheritDoc}
103
     */
104
    @Override
105
    public void handleViewEntered() {
106
        super.handleViewEntered();
107

  
108
        CdmFilterablePagingProvider<AgentBase, Institution> collectionPagingProvider = new CdmFilterablePagingProvider<AgentBase, Institution>(getRepo().getAgentService(), Institution.class);
109
        getView().getPartOfCombobox().getSelect().loadFrom(collectionPagingProvider, collectionPagingProvider, collectionPagingProvider.getPageSize());
110
        getView().getPartOfCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Institution>(getView().getPartOfCombobox(), this));
111

  
112
    }
113

  
114
    @EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
115
    public void onInstitutionEditorActionAdd(InstitutionEditorAction event) {
116

  
117
        if(!checkFromOwnView(event)){
118
            return;
119
        }
120

  
121
        InstitutionPopupEditor intitutionPopuEditor = openPopupEditor(InstitutionPopupEditor.class, event);
122

  
123
        intitutionPopuEditor.grantToCurrentUser(this.crud);
124
        intitutionPopuEditor.withDeleteButton(true);
125
        intitutionPopuEditor.loadInEditor(null);
126
    }
127

  
128
    @EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
129
    public void onCollectionEditorActionEdit(InstitutionEditorAction event) {
130

  
131
        if(!checkFromOwnView(event)){
132
            return;
133
        }
134

  
135
        InstitutionPopupEditor intitutionPopuEditor = openPopupEditor(InstitutionPopupEditor.class, event);
136

  
137
        intitutionPopuEditor.grantToCurrentUser(this.crud);
138
        intitutionPopuEditor.withDeleteButton(true);
139
        intitutionPopuEditor.loadInEditor(event.getEntityUuid());
140
    }
141

  
142
    @EventBusListenerMethod()
143
    public void onEntityChangeEvent(EntityChangeEvent<?> event){
144

  
145
        BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView());
146

  
147
        if(boundTargetField != null){
148
            if(boundTargetField.matchesPropertyIdPath("isPartOf")){
149
                if(event.isCreateOrModifiedType()){
150

  
151
                    Institution newInstitution = (Institution) event.getEntity();
152
                    getCache().load(newInstitution);
153
                    if(event.isCreatedType()){
154
                        getView().getPartOfCombobox().setValue(newInstitution);
155
                    } else {
156
                        getView().getPartOfCombobox().reload();
157
                    }
158
                }
159

  
160
            }
161
        }
162
    }
163

  
164
    /**
165
     * {@inheritDoc}
166
     */
167
    @Override
168
    protected InstitutionDTO createDTODecorator(Institution cdmEntitiy) {
169
        return new InstitutionDTO(cdmEntitiy);
170
    }
171

  
172

  
173

  
174
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/common/InstitutionPopupEditor.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.view.common;
10

  
11
import org.springframework.context.annotation.Scope;
12
import org.springframework.security.core.GrantedAuthority;
13

  
14
import com.vaadin.spring.annotation.SpringComponent;
15
import com.vaadin.ui.GridLayout;
16
import com.vaadin.ui.TextField;
17

  
18
import eu.etaxonomy.cdm.model.agent.Institution;
19
import eu.etaxonomy.cdm.vaadin.event.InstitutionEditorAction;
20
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
21
import eu.etaxonomy.cdm.vaadin.model.common.InstitutionDTO;
22
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
23
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
24
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
25
import eu.etaxonomy.vaadin.event.EditorActionType;
26
import eu.etaxonomy.vaadin.mvp.AbstractCdmDTOPopupEditor;
27

  
28
/**
29
 * @author a.kohlbecker
30
 * @since Dec 21, 2017
31
 *
32
 */
33
@SpringComponent
34
@Scope("prototype")
35
public class InstitutionPopupEditor extends AbstractCdmDTOPopupEditor<InstitutionDTO, Institution, InstitutionEditorPresenter> implements InstitutionPopupEditorView, AccessRestrictedView {
36

  
37
    private static final long serialVersionUID = 2019724189877425882L;
38

  
39
    private static final int GRID_COLS = 3;
40

  
41
    private static final int GRID_ROWS = 3;
42

  
43
    TextField codeField;
44
    TextField codeStandardField;
45
    TextField townOrLocationField;
46
    ToOneRelatedEntityCombobox<Institution> partOfCombobox;
47

  
48

  
49
    /**
50
     * @param layout
51
     * @param dtoType
52
     */
53
    public InstitutionPopupEditor() {
54
        super(new GridLayout(GRID_COLS, GRID_ROWS), InstitutionDTO.class);
55
    }
56

  
57
    /**
58
     * {@inheritDoc}
59
     */
60
    @Override
61
    public String getWindowCaption() {
62
        return "Institution editor";
63
    }
64

  
65
    /**
66
     * {@inheritDoc}
67
     */
68
    @Override
69
    public int getWindowWidth() {
70
        return 500;
71
    }
72

  
73
    /**
74
     * {@inheritDoc}
75
     */
76
    @Override
77
    public void focusFirst() {
78
        codeField.focus();
79
    }
80

  
81
    /**
82
     * {@inheritDoc}
83
     */
84
    @Override
85
    public boolean allowAnonymousAccess() {
86
        return false;
87
    }
88

  
89
    /**
90
     * {@inheritDoc}
91
     */
92
    @Override
93
    public java.util.Collection<java.util.Collection<GrantedAuthority>> allowedGrantedAuthorities() {
94
        return null;
95
    }
96

  
97
    /**
98
     * {@inheritDoc}
99
     */
100
    @Override
101
    protected String getDefaultComponentStyles() {
102
        return "tiny";
103
    }
104

  
105
    /**
106
     * {@inheritDoc}
107
     */
108
    @Override
109
    protected void initContent() {
110

  
111
        GridLayout grid = (GridLayout)getFieldLayout();
112
        grid.setSizeFull();
113
        grid.setSpacing(true);
114

  
115
        int row = 0;
116
        codeField = addTextField("Code", "code", 0, row, 0, row);
117
        codeField.setWidth(100, Unit.PIXELS);
118

  
119
        townOrLocationField = addTextField("Name", "name", 1, row, 2, row);
120
        townOrLocationField.setWidth(200, Unit.PIXELS);
121

  
122
        row++;
123

  
124
        partOfCombobox = new ToOneRelatedEntityCombobox<Institution>("Part of", Institution.class);
125

  
126

  
127
        partOfCombobox.setWidth(300, Unit.PIXELS);
128
        addField(partOfCombobox, "isPartOf", 0, row, 1, row);
129

  
130
        partOfCombobox.getSelect().setCaptionGenerator(
131
                new CdmTitleCacheCaptionGenerator<Institution>()
132
                );
133
        partOfCombobox.getSelect().addValueChangeListener(
134
                new ToOneRelatedEntityButtonUpdater<Institution>(partOfCombobox)
135
                );
136

  
137

  
138
        partOfCombobox.addClickListenerAddEntity( e -> getViewEventBus().publish(this,
139
                new InstitutionEditorAction(
140
                        EditorActionType.ADD,
141
                        null,
142
                        partOfCombobox,
143
                        this)
144
                ));
145
        partOfCombobox.addClickListenerEditEntity(e -> {
146
                if(partOfCombobox.getValue() != null){
147
                    getViewEventBus().publish(this,
148
                            new InstitutionEditorAction(
149
                                EditorActionType.EDIT,
150
                                partOfCombobox.getValue().getUuid(),
151
                                e.getButton(),
152
                                partOfCombobox,
153
                                this
154
                            )
155
                    );
156
                }
157
            });
158

  
159
    }
160

  
161
    /* ------------------ View Interface methods -------------------- */
162

  
163
    @Override
164
    public ToOneRelatedEntityCombobox<Institution> getPartOfCombobox(){
165
        return partOfCombobox;
166
    }
167
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/common/InstitutionPopupEditorView.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.view.common;
10

  
11
import eu.etaxonomy.cdm.model.agent.Institution;
12
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
13
import eu.etaxonomy.vaadin.mvp.ApplicationView;
14

  
15
/**
16
 * @author a.kohlbecker
17
 * @since Dec 21, 2017
18
 *
19
 */
20
public interface InstitutionPopupEditorView extends ApplicationView<InstitutionEditorPresenter> {
21

  
22
    ToOneRelatedEntityCombobox<Institution> getPartOfCombobox();
23

  
24
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)