@Override protected void loadEditable(Component component, Element element) { FieldGroup fieldGroup = (FieldGroup) component; if (fieldGroup.getDatasource() != null) { MetaClass metaClass = fieldGroup.getDatasource().getMetaClass(); boolean editableByPermission = (getSecurity().isEntityOpPermitted(metaClass, EntityOp.CREATE) || getSecurity().isEntityOpPermitted(metaClass, EntityOp.UPDATE)); if (!editableByPermission) { fieldGroup.setEditable(false); return; } } String editable = element.attributeValue("editable"); if (StringUtils.isNotEmpty(editable)) { fieldGroup.setEditable(Boolean.parseBoolean(editable)); } }
protected MetaClass getMetaClass(FieldGroup resultComponent, FieldGroup.FieldConfig field) { if (field.isCustom()) { return null; } Datasource datasource; if (field.getDatasource() != null) { datasource = field.getDatasource(); } else if (resultComponent.getDatasource() != null) { datasource = resultComponent.getDatasource(); } else { throw new GuiDevelopmentException(String.format("Unable to get datasource for field '%s'", field.getId()), context.getFullFrameId()); } return datasource.getMetaClass(); }
@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); } });
/** * 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)); }
/** * Release pessimistic lock if it was applied. */ protected void releaseLock() { if (justLocked) { Datasource ds = getFieldGroup().getDatasource(); Entity entity = ds.getItem(); if (entity != null) { MetaClass metaClass = getMetaClassForLocking(entity); AppBeans.get(LockService.class).unlock(metaClass.getName(), entity.getId().toString()); } } }
Datasource ds; if (field.getDatasource() == null) { ds = resultComponent.getDatasource(); } else { ds = field.getDatasource();
/** * 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(); } }