/** * Adds a CreateAction that removes selection in table, sets a newly created item to editDs * and enables controls for record editing. */ protected void initBrowseCreateAction() { ListComponent table = getTable(); table.addAction(new CreateAction(table) { @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); } }); }
/** * Disables edit controls. */ protected void disableEditControls() { this.editing = false; initEditComponents(false); ((Focusable) getTable()).focus(); }
ListComponent table = getTable(); table.addAction(new EditAction(table) { @Override
/** * Adds AfterRemoveHandler for table's Remove action to reset the record contained in editDs. */ @SuppressWarnings("unchecked") protected void initBrowseRemoveAction() { ListComponent table = getTable(); Datasource editDs = getFieldGroup().getDatasource(); RemoveAction removeAction = (RemoveAction) table.getAction(RemoveAction.ACTION_ID); if (removeAction != null) removeAction.setAfterRemoveHandler(removedItems -> editDs.setItem(null)); }
protected MetaClass getMetaClassForLocking(Entity item) { // lock original metaClass, if any, because by convention all the configuration is based on original entities MetaClass metaClass = AppBeans.get(ExtendedEntities.class).getOriginalMetaClass(item.getMetaClass()); if (metaClass == null) { metaClass = getTable().getDatasource().getMetaClass(); } return metaClass; }
/** * 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(); }
/** * Adds a listener that reloads the selected record with the specified view and sets it to editDs. */ @SuppressWarnings("unchecked") protected void initBrowseItemChangeListener() { CollectionDatasource browseDs = getTable().getDatasource(); Datasource editDs = getFieldGroup().getDatasource(); browseDs.addItemChangeListener(e -> { if (e.getItem() != null) { Entity reloadedItem = getDsContext().getDataSupplier().reload( e.getDs().getItem(), editDs.getView(), null, e.getDs().getLoadDynamicAttributes()); editDs.setItem(reloadedItem); } }); }
/** * Method that is invoked by clicking Cancel button, discards changes and disables controls for editing. */ @SuppressWarnings("unchecked") public void cancel() { CollectionDatasource browseDs = getTable().getDatasource(); Datasource editDs = getFieldGroup().getDatasource(); Entity selectedItem = browseDs.getItem(); if (selectedItem != null) { Entity reloadedItem = getDsContext().getDataSupplier().reload( selectedItem, editDs.getView(), null, editDs.getLoadDynamicAttributes()); browseDs.setItem(reloadedItem); } else { editDs.setItem(null); } releaseLock(); disableEditControls(); } }