@Override public void init(Map<String, Object> params) { super.init(params); add.setWindowId("dashboard$WidgetTemplate.browse"); } }
@Override protected void postInit() { super.postInit(); initProcTaskActionsFrame(); }
protected boolean commitInternal(boolean close) { if (!preCommit()) return false; boolean committed; DsContext context = getDsContext(); if (context != null) { committed = context.commit(); } else { DataSupplier supplier = getDataService(); supplier.commit(getItem()); committed = true; } return postCommit(committed, close); }
/** * 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() { if (validateAll()) { boolean committed = commitInternal(true); if (committed) { return close(WINDOW_COMMIT_AND_CLOSE_ACTION); } } return OperationResult.fail(); }
/** * Called by the framework to set an edited entity after creation of all components and datasources, and after * {@link #init(java.util.Map)}. * <p>Don't override this method in subclasses, use hooks {@link #initNewItem(com.haulmont.cuba.core.entity.Entity)} * and {@link #postInit()} instead.</p> * @param item entity instance */ @SuppressWarnings("unchecked") @Override public void setItem(Entity item) { if (PersistenceHelper.isNew(item)) { DatasourceImplementation parentDs = (DatasourceImplementation) getParentDs(); if (parentDs == null || !parentDs.getItemsToCreate().contains(item)) { initNewItem((T) item); } } setItemInternal(item); postInit(); }
/** * Hook to be implemented in subclasses. Called by the framework after committing datasources. * The default implementation notifies about commit and calls {@link #postInit()} if the window is not closing. * * @param committed whether any data were actually changed and committed * @param close whether the window is going to be closed * @return true to continue, false to abort */ protected boolean postCommit(boolean committed, boolean close) { if (committed && !close) { if (showSaveNotification) { Entity entity = getItem(); MetadataTools metadataTools = getBeanLocator().get(MetadataTools.class); showNotification( messages.formatMainMessage("info.EntitySave", messages.getTools().getEntityCaption(entity.getMetaClass()), metadataTools.getInstanceName(entity)), NotificationType.TRAY); } postInit(); afterWindowApplyPostInit(); } return true; }
public void editAttribute() { Set<ManagedBeanAttribute> selected = attributesTable.getSelected(); if (selected.isEmpty()) { return; } ManagedBeanAttribute mba = selected.iterator().next(); if (!mba.getWriteable()) { return; } AbstractEditor w = openEditor("jmxConsoleEditAttribute", mba, OpenType.DIALOG); w.addCloseListener(actionId -> { if (Window.COMMIT_ACTION_ID.equals(actionId)) { Object item = w.getItem(); reloadAttribute((ManagedBeanAttribute) item); } }); }
protected void initCommitActions(@SuppressWarnings("unused") InitEvent event) { Component commitAndCloseButton = ComponentsHelper.findComponent(getFrame(), WINDOW_COMMIT_AND_CLOSE); Configuration configuration = getBeanLocator().get(Configuration.NAME); commitAndCloseButtonExists = true; getFrame().addAction( new BaseAction(WINDOW_COMMIT_AND_CLOSE) .withCaption(messages.getMainMessage("actions.OkClose")) .withPrimary(true) .withShortcut(commitShortcut) .withHandler(e -> commitAndClose())); .withHandler(e -> { if (!finalCommitAndCloseButtonExists) { commitAndClose(); } else { if (commit()) { commitActionPerformed = true; getFrame().addAction(commitAction); close(commitActionPerformed ? Window.COMMIT_ACTION_ID : getId()) ); getFrame().addAction(closeAction);
@Override public void setEntityToEdit(T entity) { setItem(entity); }
@Override protected boolean preCommit() { if (localizedFrame != null) { category.setLocaleNames(localizedFrame.getValue()); } return super.preCommit(); } }
@Override protected boolean postCommit(boolean committed, boolean close) { if (committed && needSave) { saveFile(); } return super.postCommit(committed, close); }
@Override public T getEditedEntity() { return getItem(); }
public void validateAdditionalRules(ValidationErrors errors) { // all previous validations return no errors if (crossFieldValidate && errors.isEmpty()) { BeanValidation beanValidation = getBeanLocator().get(BeanValidation.NAME); Validator validator = beanValidation.getValidator(); Set<ConstraintViolation<Entity>> violations = validator.validate(getItem(), UiCrossFieldChecks.class); violations.stream() .filter(violation -> { Path propertyPath = violation.getPropertyPath(); Path.Node lastNode = Iterables.getLast(propertyPath); return lastNode.getKind() == ElementKind.BEAN; }) .forEach(violation -> errors.add(violation.getMessage())); } }
@Override protected void postValidate(ValidationErrors errors) { super.postValidate(errors); //remove errors from widget frames errors.getAll().removeIf(error -> !"dashboard$dashboardEditFieldGroup1".equals(error.component.getParent().getId())); List<Widget> dashboardWidgets = dashboardDs.getItem().getWidgets(); Map<String, Long> widgetsCount = dashboardWidgets.stream() .collect(Collectors.groupingBy(Widget::getWidgetId, Collectors.counting())); List<String> nonUniqueIds = widgetsCount.entrySet().stream() .filter(es -> es.getValue() > 1) .map(Map.Entry::getKey) .collect(toList()); if (nonUniqueIds.size() > 0) { errors.add(null, formatMessage("uniqueWidgetId", String.join(",", nonUniqueIds))); } }
/** * Called by the framework to validate and commit changes. * <p>Don't override this method in subclasses, use hooks {@link #postValidate(ValidationErrors)}, {@link #preCommit()} * and {@link #postCommit(boolean, boolean)} instead.</p> * * @return true if commit was successful */ @Override public boolean commit() { return commit(true); }
public void close() { super.close(Window.CLOSE_ACTION_ID, true); } }
AbstractEditor editor = openEditor("sec$User.edit", newUser, OpenType.THIS_TAB, ParamsMap.of("initCopy", true)); editor.addCloseListener(actionId -> { if (Window.COMMIT_ACTION_ID.equals(actionId)) { usersDs.refresh();
window.addCloseListener(actionId -> { Entity editedItem = window.getItem(); if (editedItem != null) { if (parentDs == null) { window.addCloseListener(editorCloseListener);
@Override public void setItem(Entity item) { super.setItem(item); if (StringUtils.isNotEmpty(getItem().getMethodName())) { setInitialMethodNameValue(getItem()); } }
@Override protected boolean preCommit() { if (reportRegionPropertiesTableDs.getItems().isEmpty()) { showNotification(getMessage("selectAtLeastOneProp"), NotificationType.TRAY); return false; } return super.preCommit(); }