protected StandardEditor() { addInitListener(this::initActions); addBeforeShowListener(this::beforeShow); addBeforeCloseListener(this::beforeClose); addAfterShowListener(this::afterShow); }
/** * Tries to validate and commit data. If data committed successfully then closes the screen with * {@link #WINDOW_COMMIT_AND_CLOSE} action. May show validation errors or open an additional dialog before closing * the screen. * * @return result of close request */ public OperationResult closeWithCommit() { return commitChanges() .compose(() -> close(WINDOW_COMMIT_AND_CLOSE_ACTION)); }
protected void commitAndClose(@SuppressWarnings("unused") Action.ActionPerformedEvent event) { closeWithCommit(); }
protected void setupEntityToEdit() { if (getScreenData().getDataContext() == null) { throw new IllegalStateException("No DataContext defined. Make sure the editor screen XML descriptor has <data> element"); DynamicAttributesGuiTools tools = getBeanLocator().get(DynamicAttributesGuiTools.NAME); String screenId = getScreenContext().getWindowInfo().getId(); InstanceContainer<T> editedEntityContainer = getEditedEntityContainer(); if (editedEntityContainer instanceof HasLoader) { if (((HasLoader) editedEntityContainer).getLoader() instanceof InstanceLoader) { instanceLoader = getEditedEntityLoader(); if (tools.screenContainsDynamicAttributes(editedEntityContainer.getView(), screenId)) { instanceLoader.setLoadDynamicAttributes(true); if (getEntityStates().isNew(entityToEdit) || doNotReloadEditedEntity()) { T mergedEntity = getScreenData().getDataContext().merge(entityToEdit); && getEntityStates().isNew(entityToEdit) && mergedEntity instanceof BaseGenericIdEntity) { tools.initDefaultAttributeValues((BaseGenericIdEntity) mergedEntity, mergedEntity.getMetaClass()); fireEvent(InitEntityEvent.class, new InitEntityEvent<>(this, mergedEntity)); InstanceContainer<T> container = getEditedEntityContainer(); container.setItem(mergedEntity); } else { InstanceLoader loader = getEditedEntityLoader(); loader.setEntityId(entityToEdit.getId());
protected void setupLock() { InstanceContainer<T> container = getEditedEntityContainer(); Security security = getBeanLocator().get(Security.class); if (!getEntityStates().isNew(entityToEdit) && security.isEntityOpPermitted(container.getEntityMetaClass(), EntityOp.UPDATE)) { this.readOnly = false; LockService lockService = getBeanLocator().get(LockService.class); LockInfo lockInfo = lockService.lock(getLockName(), entityToEdit.getId().toString()); if (lockInfo == null) { this.justLocked = true; addAfterDetachListener(afterDetachEvent -> releaseLock() ); } else if (!(lockInfo instanceof LockNotSupported)) { Messages messages = getBeanLocator().get(Messages.class); DatatypeFormatter datatypeFormatter = getBeanLocator().get(DatatypeFormatter.class); getScreenContext().getNotifications().create(NotificationType.HUMANIZED) .withCaption(messages.getMainMessage("entityLocked.msg")) .withDescription( Action commitAction = getWindow().getAction(WINDOW_COMMIT); if (commitAction != null) { commitAction.setEnabled(false); Action commitCloseAction = getWindow().getAction(WINDOW_COMMIT_AND_CLOSE);
protected void preventUnsavedChanges(BeforeCloseEvent event) { CloseAction action = event.getCloseAction(); if (action instanceof ChangeTrackerCloseAction && ((ChangeTrackerCloseAction) action).isCheckForUnsavedChanges() && hasUnsavedChanges()) { Configuration configuration = getBeanLocator().get(Configuration.NAME); ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); ScreenValidation screenValidation = getBeanLocator().get(ScreenValidation.NAME); UnknownOperationResult result = new UnknownOperationResult(); if (clientConfig.getUseSaveConfirmation()) { screenValidation.showSaveConfirmationDialog(this, action) .onCommit(() -> result.resolveWith(closeWithCommit())) .onDiscard(() -> result.resolveWith(closeWithDiscard())) .onCancel(result::fail); } else { screenValidation.showUnsavedChangesDialog(this, action) .onDiscard(() -> result.resolveWith(closeWithDiscard())) .onCancel(result::fail); } event.preventWindowClose(result); } }
/** * Ignores the unsaved changes and closes the screen with {@link #WINDOW_DISCARD_AND_CLOSE_ACTION} action. * * @return result of close request */ public OperationResult closeWithDiscard() { return close(WINDOW_DISCARD_AND_CLOSE_ACTION); }
protected void commit(@SuppressWarnings("unused") Action.ActionPerformedEvent event) { commitChanges() .then(() -> commitActionPerformed = true); }
protected void cancel(@SuppressWarnings("unused") Action.ActionPerformedEvent event) { close(commitActionPerformed ? WINDOW_COMMIT_AND_CLOSE_ACTION : WINDOW_CLOSE_ACTION); }