Project

General

Profile

Revision 87bbccd4

ID87bbccd430886b5a2b9c744e0dc018e7d6235920
Parent fd071f70
Child b7f9be76

Added by Andreas Kohlbecker over 2 years ago

fix #7535 TeamOrPersonField and PersonField without OK button

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/common/PersonField.java
54 54

  
55 55
    private LazyComboBox<Person> personSelect = new LazyComboBox<Person>(Person.class);
56 56

  
57
    private Button personSelectConfirmButton = new Button("OK");
58 57
    private Button newPersonButton = new Button("New");
59 58

  
60 59
    private BeanFieldGroup<Person> fieldGroup = new BeanFieldGroup<>(Person.class);
......
85 84
    private TextField suffixField = new TextFieldNFix();
86 85
    private SwitchButton unlockSwitch = new SwitchButton();
87 86

  
88
    private boolean onCommit = false;
89

  
90

  
91 87

  
92 88
    /**
93 89
     * @param caption
......
106 102
        root.setPrimaryStyleName(PRIMARY_STYLE);
107 103

  
108 104
        // select existing or create new person
109
        addStyledComponents(personSelect, personSelectConfirmButton, newPersonButton);
105
        addStyledComponents(personSelect, newPersonButton);
110 106
        personSelect.addValueChangeListener(e -> {
111 107
            if(personSelect.getValue() != null){
112
                personSelectConfirmButton.setEnabled(true);
108
                setValue(personSelect.getValue());
109
                personSelect.clear();
113 110
            }
114 111
        });
115
        personSelectConfirmButton.setEnabled(false);
116
        personSelectConfirmButton.addClickListener(e -> {
117
            setValue(personSelect.getValue());
118
            personSelect.clear();
119
        });
120
        selectOrNewContainer.addComponents(personSelect, personSelectConfirmButton, newPersonButton);
112

  
113
        selectOrNewContainer.addComponents(personSelect, newPersonButton);
121 114
        newPersonButton.addClickListener(e -> createNewPerson());
122 115

  
123 116
        // edit person
......
391 384
        if(bean == null){
392 385
            return null;
393 386
        }
394
       // boolean isUnsaved = bean.getId() == 0;
395
//        if(isUnsaved && hasNullContent() && !allowNewEmptyEntity) {
396
//            return null;
397
//        }
398 387
        return bean;
399 388
    }
400 389

  
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
62 62

  
63 63
    private ReloadableLazyComboBox<TeamOrPersonBase> teamOrPersonSelect = new ReloadableLazyComboBox<TeamOrPersonBase>(TeamOrPersonBase.class);
64 64

  
65
    private Button selectConfirmButton = new Button("OK");
66 65
    private Button removeButton = new Button(FontAwesome.REMOVE);
67 66
    private Button personButton = new Button(FontAwesome.USER);
68 67
    private Button teamButton = new Button(FontAwesome.USERS);
......
96 95
        addStyledComponent(titleField);
97 96
        addStyledComponent(nomenclaturalTitleField);
98 97
        addStyledComponent(personsListEditor);
99
        addStyledComponents(selectConfirmButton, removeButton, personButton, teamButton);
98
        addStyledComponents(removeButton, personButton, teamButton);
100 99

  
101 100

  
102 101
        addSizedComponent(root);
......
118 117
    protected Component initContent() {
119 118

  
120 119
        teamOrPersonSelect.addValueChangeListener(e -> {
121
            selectConfirmButton.setEnabled(teamOrPersonSelect.getValue() != null);
122
            selectConfirmButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
123
        });
124
        teamOrPersonSelect.setWidthUndefined();
125

  
126
        selectConfirmButton.setEnabled(teamOrPersonSelect.getValue() != null);
127
        selectConfirmButton.addClickListener(e -> {
128
            // new entitiy being set, reset the readonly state
129
//            resetReadOnlyComponents();
130
//            getPropertyDataSource().setReadOnly(false);
131 120
            setValue(teamOrPersonSelect.getValue(), false, true);
132
            teamOrPersonSelect.clear();
133 121
            updateToolBarButtonStates();
134 122
        });
123
        teamOrPersonSelect.setWidthUndefined();
124

  
135 125
        removeButton.addClickListener(e -> {
136
//            resetReadOnlyComponents();
137
//            getPropertyDataSource().setReadOnly(false);
138 126
            setValue(null, false, true);
139 127
            updateToolBarButtonStates();
140 128
        });
141 129
        removeButton.setDescription("Remove");
142 130

  
143 131
        personButton.addClickListener(e -> {
144
            setValue(Person.NewInstance(), false, true); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
132
            setValue(Person.NewInstance(), false, true);
145 133

  
146 134
        });
147 135
        personButton.setDescription("Add person");
148 136
        teamButton.addClickListener(e -> {
149
            setValue(Team.NewInstance(), false, true); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
137
            setValue(Team.NewInstance(), false, true);
150 138
        });
151 139
        teamButton.setDescription("Add team");
152 140

  
153 141
        toolBar.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP + " toolbar");
154
        toolBar.addComponents(teamOrPersonSelect, selectConfirmButton,  removeButton, personButton, teamButton);
142
        toolBar.addComponents(teamOrPersonSelect,  removeButton, personButton, teamButton);
155 143

  
156 144
        compositeWrapper.setStyleName("margin-wrapper");
157 145
        compositeWrapper.addComponent(toolBar);
......
174 162
        boolean userCanCreate = UserHelper.fromSession().userHasPermission(Person.class, "CREATE");
175 163

  
176 164
        teamOrPersonSelect.setVisible(val == null);
177
        selectConfirmButton.setVisible(val == null);
165
        if(teamOrPersonSelect.getValue() != val){
166
            teamOrPersonSelect.clear();
167
        }
178 168
        removeButton.setVisible(val != null);
179 169
        personButton.setEnabled(userCanCreate && val == null);
180 170
        teamButton.setEnabled(userCanCreate && val == null);
......
256 246
        }
257 247
    }
258 248

  
259
//    private void checkUserPermissions(TeamOrPersonBase<?> newValue) {
260
//        boolean userCanEdit = UserHelper.fromSession().userHasPermission(newValue, "DELETE", "UPDATE");
261
//        setEnabled(userCanEdit);
262
//        personsListEditor.setEnabled(userCanEdit);
263
//    }
264 249

  
265 250
    /**
266 251
     * {@inheritDoc}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListPresenter.java
303 303
     */
304 304
    private void setSelectValue(AbstractSelect select, Set<?> itemsToChoose) {
305 305

  
306
        for(Object item : select.getContainerDataSource().getItemIds()){
307
            if(item != null){
308
                if(itemsToChoose.contains(item)){
309
                    select.select(item);
306
        if(itemsToChoose != null){
307
            for(Object item : select.getContainerDataSource().getItemIds()){
308
                if(item != null){
309
                    if(itemsToChoose.contains(item)){
310
                        select.select(item);
311
                    }
310 312
                }
311 313
            }
312 314
        }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)