@SuppressWarnings("unchecked") @Override protected void internalOpenEditor(CollectionDatasource datasource, Entity newItem, Datasource parentDs, Map<String, Object> params) { initNewItem(newItem); table.setSelected(Collections.emptyList()); getFieldGroup().getDatasource().setItem(newItem); refreshOptionsForLookupFields(); enableEditControls(true); } });
/** * Method that is invoked by clicking Ok button after editing an existing or creating a new record. */ @SuppressWarnings("unchecked") public void save() { if (!editing) return; FieldGroup fieldGroup = getFieldGroup(); List<Validatable> components = new ArrayList<>(); for (Component component: fieldGroup.getComponents()) { if (component instanceof Validatable) { components.add((Validatable)component); } } if (!validate(components)) { return; } getDsContext().commit(); ListComponent table = getTable(); CollectionDatasource browseDs = table.getDatasource(); Entity editedItem = fieldGroup.getDatasource().getItem(); if (creating) { browseDs.includeItem(editedItem); } else { browseDs.updateItem(editedItem); } table.setSelected(editedItem); releaseLock(); disableEditControls(); }
protected void confirmAndRemove(Set<Entity> selected) { Dialogs dialogs = ComponentsHelper.getScreenContext(target.getFrame()).getDialogs(); dialogs.createOptionDialog() .withCaption(getConfirmationTitle()) .withMessage(getConfirmationMessage()) .withActions( new DialogAction(Type.OK, Status.PRIMARY).withHandler(event -> { try { remove(selected); } finally { if (target instanceof Component.Focusable) { ((Component.Focusable) target).focus(); } Set<Entity> filtered = new HashSet<>(selected); filtered.retainAll(target.getDatasource().getItems()); //noinspection unchecked target.setSelected(filtered); } }), new DialogAction(Type.CANCEL).withHandler(event -> { // move focus to owner if (target instanceof Component.Focusable) { ((Component.Focusable) target).focus(); } })) .show(); }
/** * Method invoked when clicking on the Ok button after editing an existing or creating a new record. */ public void saveChanges() { if (!editing) return; ValidationErrors validationErrors = validateEditorForm(); if (!validationErrors.isEmpty()) { ScreenValidation screenValidation = getBeanLocator().get(ScreenValidation.class); screenValidation.showValidationErrors(this, validationErrors); return; } getScreenData().getDataContext().commit(); T editedItem = getEditContainer().getItem(); if (creating) { getBrowseContainer().getMutableItems().add(0, editedItem); } else { getBrowseContainer().replaceItem(editedItem); } getTable().setSelected(editedItem); releaseLock(); disableEditControls(); }
datasource.includeItem(editedItem); target.setSelected(editedItem); afterCommit(editedItem); if (afterCommitHandler != null) {
refreshOptionsForLookupFields(); enableEditControls(true); table.setSelected(Collections.emptyList()); });