Project

General

Profile

Revision 07a39ef5

ID07a39ef5fdeb096d21d81d86118aeb0aa56f7dec
Parent e9c6f795
Child b4127a93

Added by Andreas Kohlbecker over 1 year ago

fix #7382 disabling save button and showing message when type designations are missing

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetPopupEditor.java
50 50
    extends AbstractPopupEditor<SpecimenTypeDesignationWorkingSetDTO, SpecimenTypeDesignationWorkingsetEditorPresenter>
51 51
    implements SpecimenTypeDesignationWorkingsetPopupEditorView, AccessRestrictedView, PerEntityAuthorityGrantingEditor {
52 52
    /**
53
     *
54
     */
55
    private static final String CAN_T_SAVE_AS_LONG_AS_TYPE_DESIGNATIONS_ARE_MISSING = "Can't save as long as type designations are missing.";
56

  
57
    /**
53 58
     * @param layout
54 59
     * @param dtoType
55 60
     */
......
182 187
        typeDesignationsCollectionField.setPropertyHeader("preferredStableUri", "Stable URI");
183 188
        typeDesignationsCollectionField.setPropertyHeader("mediaSpecimenReference", "Image reference");
184 189
        typeDesignationsCollectionField.setPropertyHeader("mediaSpecimenReferenceDetail", "Reference detail");
190
        typeDesignationsCollectionField.addElementAddedListener( e -> updateAllowSave());
191
        typeDesignationsCollectionField.addElementRemovedListener( e -> updateAllowSave());
185 192

  
186 193
        // typeDesignationsCollectionField.getLayout().setMargin(false);
187 194
        // typeDesignationsCollectionField.addStyleName("composite-field-wrapper");
......
280 287
            ((CollectionRowRepresentative)item).updateRowItemsEnabledStates();
281 288
        }
282 289
        updateAllowDelete();
290
        updateAllowSave();
283 291
    }
284 292

  
285 293
    /**
......
296 304
        }
297 305
    }
298 306

  
307
    public void updateAllowSave(){
308
        boolean hasTypeDesignations = getBean().getSpecimenTypeDesignationDTOs().size() > 0;
309
        setSaveButtonEnabled(hasTypeDesignations);
310
        if(!hasTypeDesignations){
311
            addStatusMessage(CAN_T_SAVE_AS_LONG_AS_TYPE_DESIGNATIONS_ARE_MISSING);
312
        } else {
313
            removeStatusMessage(CAN_T_SAVE_AS_LONG_AS_TYPE_DESIGNATIONS_ARE_MISSING);
314
        }
315

  
316
    }
317

  
299 318
    /**
300 319
     * {@inheritDoc}
301 320
     */
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
10 10

  
11 11
import java.util.ArrayList;
12 12
import java.util.Arrays;
13
import java.util.HashSet;
13 14
import java.util.List;
14 15
import java.util.Map;
16
import java.util.Set;
15 17
import java.util.Stack;
16 18

  
17 19
import org.apache.log4j.Logger;
......
42 44
import com.vaadin.ui.GridLayout.OutOfBoundsException;
43 45
import com.vaadin.ui.GridLayout.OverlapsException;
44 46
import com.vaadin.ui.HorizontalLayout;
47
import com.vaadin.ui.Label;
45 48
import com.vaadin.ui.Layout;
46 49
import com.vaadin.ui.Layout.MarginHandler;
47 50
import com.vaadin.ui.Notification;
......
94 97

  
95 98
    private CssLayout toolBarButtonGroup = new CssLayout();
96 99

  
100
    private Label statusMessageLabel = new Label();
101

  
102
    Set<String> statusMessages = new HashSet<>();
103

  
97 104
    private GridLayout _gridLayoutCache;
98 105

  
99 106
    private boolean isBeanLoaded;
......
161 168
        buttonLayout.setComponentAlignment(save, Alignment.TOP_RIGHT);
162 169
        buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT);
163 170

  
164
        mainLayout.addComponents(toolBar, fieldLayout, buttonLayout);
171
        statusMessageLabel.setWidthUndefined();
172

  
173
        mainLayout.addComponents(toolBar, fieldLayout, statusMessageLabel, buttonLayout);
174
        mainLayout.setComponentAlignment(statusMessageLabel, Alignment.BOTTOM_RIGHT);
165 175
        mainLayout.setComponentAlignment(toolBar, Alignment.TOP_RIGHT);
166 176

  
167 177
        updateToolBarVisibility();
......
206 216
        for(Component c : layout){
207 217
            c.setReadOnly(readOnly);
208 218
            if(c instanceof AbstractComponentContainer){
209
                recursiveReadonly(readOnly, layout);
219
                recursiveReadonly(readOnly, (AbstractComponentContainer)c);
210 220
            }
211 221
        }
212 222
    }
......
596 606
        gridLayout().addComponent(component, column1, row1, column2, row2);
597 607
    }
598 608

  
609
    public void setSaveButtonEnabled(boolean enabled){
610
        save.setEnabled(enabled);
611
    }
599 612

  
600 613
    public void withDeleteButton(boolean withDelete){
601 614

  
......
609 622
        delete.setVisible(withDelete);
610 623
    }
611 624

  
625
    public boolean addStatusMessage(String message){
626
        boolean returnVal = statusMessages.add(message);
627
        updateStatusLabel();
628
        return returnVal;
629
    }
630

  
631
    public boolean removeStatusMessage(String message){
632
        boolean returnVal = statusMessages.remove(message);
633
        updateStatusLabel();
634
        return returnVal;
635
    }
636

  
637
    /**
638
     *
639
     */
640
    private void updateStatusLabel() {
641
        String text = "";
642
        for(String s : statusMessages){
643
            text += s + " ";
644
        }
645
        statusMessageLabel.setValue(text);
646
        statusMessageLabel.setVisible(!text.isEmpty());
647
        statusMessageLabel.addStyleName(ValoTheme.LABEL_COLORED);
648
    }
612 649

  
613 650
    // ------------------------ data binding ------------------------ //
614 651

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)