protected void setupModifiedTracking() { DataContext dataContext = getScreenData().getDataContext(); if (dataContext != null) { dataContext.addChangeListener(this::editedEntityModified); dataContext.addPostCommitListener(this::editedEntityCommitted); } }
protected boolean isEntityModifiedInParentContext() { boolean result = false; DataContext parentDc = getScreenData().getDataContext().getParent(); while (!result && parentDc != null) { result = isEntityModifiedRecursive(entityToEdit, parentDc, new HashSet<>()); parentDc = parentDc.getParent(); } return result; }
protected InstanceContainer<T> getEditedEntityContainer() { EditedEntityContainer annotation = getClass().getAnnotation(EditedEntityContainer.class); if (annotation == null || Strings.isNullOrEmpty(annotation.value())) { throw new IllegalStateException( String.format("StandardEditor %s does not declare @EditedEntityContainer", getClass()) ); } String[] parts = annotation.value().split("\\."); ScreenData screenData; if (parts.length == 1) { screenData = getScreenData(); } else { Frame frame = getWindow(); for (int i = 0; i < parts.length - 1; i++) { String part = parts[i]; Component component = frame.getComponent(part); if (!(component instanceof Frame)) { throw new IllegalStateException("Path to EditedEntityContainer must include frames only"); } frame = (Frame) component; } screenData = UiControllerUtils.getScreenData(frame.getFrameOwner()); } return screenData.getContainer(parts[parts.length - 1]); }
@Override public boolean hasUnsavedChanges() { if (isReadOnly()) { return false; } return isEntityModified() && getScreenData().getDataContext().hasChanges(); }
/** * Validates screen and commits data context. * * @return operation result */ protected OperationResult commitChanges() { ValidationErrors validationErrors = validateScreen(); if (!validationErrors.isEmpty()) { ScreenValidation screenValidation = getBeanLocator().get(ScreenValidation.class); screenValidation.showValidationErrors(this, validationErrors); return OperationResult.fail(); } getScreenData().getDataContext().commit(); return OperationResult.success(); }
protected void setupEntityToEdit() { if (getScreenData().getDataContext() == null) { throw new IllegalStateException("No DataContext defined. Make sure the editor screen XML descriptor has <data> element"); T mergedEntity = getScreenData().getDataContext().merge(entityToEdit);