Search in sources :

Example 11 with Messages

use of io.jmix.core.Messages in project jmix by jmix-framework.

the class PropertyOperationEditor method createComponent.

@Override
protected Component createComponent() {
    OpManager opManager = AppBeans.get(OpManager.class);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    componentsFactory = AppBeans.get(ComponentsFactory.class);
    popupButton = componentsFactory.createComponent(PopupButton.class);
    MetaClass metaClass = condition.getEntityMetaClass();
    MetaPropertyPath propertyPath = metaClass.getPropertyPath(condition.getName());
    if (propertyPath == null) {
        throw new IllegalStateException(String.format("Unable to find property '%s' in entity %s", condition.getName(), metaClass));
    }
    MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
    for (Op op : opManager.availableOps(propertyMetaClass, propertyPath.getMetaProperty())) {
        OperatorChangeAction operatorChangeAction = new OperatorChangeAction(op);
        popupButton.addAction(operatorChangeAction);
    }
    Messages messages = AppBeans.get(Messages.class);
    popupButton.setCaption(messages.getMessage(Op.class, "Op." + condition.getOperator().name()));
    popupButton.setStyleName("condition-operation-button");
    return popupButton;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Op(com.haulmont.cuba.core.global.filter.Op) MetadataTools(io.jmix.core.MetadataTools) Messages(io.jmix.core.Messages) PopupButton(io.jmix.ui.component.PopupButton) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) OpManager(com.haulmont.cuba.core.global.filter.OpManager)

Example 12 with Messages

use of io.jmix.core.Messages in project jmix by jmix-framework.

the class WebAbstractField method validate.

@Override
public void validate() throws ValidationException {
    if (hasValidationError()) {
        setValidationError(null);
    }
    if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
        return;
    }
    V value = getValue();
    if (isEmpty(value) && isRequired()) {
        String requiredMessage = getRequiredMessage();
        if (requiredMessage == null) {
            Messages messages = applicationContext.getBean(Messages.class);
            requiredMessage = messages.getMessage("validationFail.defaultRequiredMessage");
        }
        throw new RequiredValueMissingException(requiredMessage, this);
    }
    if (validators != null) {
        try {
            for (Validator<V> validator : validators) {
                validator.accept(value);
            }
        } catch (ValidationException e) {
            setValidationError(e.getDetailsMessage());
            throw new ValidationFailedException(e.getDetailsMessage(), this, e);
        }
    }
}
Also used : Messages(io.jmix.core.Messages)

Example 13 with Messages

use of io.jmix.core.Messages in project jmix by jmix-framework.

the class MultipleResourcePolicyModelCreateScreen method initScreenActions.

protected void initScreenActions() {
    Window window = getWindow();
    Messages messages = getApplicationContext().getBean(Messages.class);
    Icons icons = getApplicationContext().getBean(Icons.class);
    String commitShortcut = getApplicationContext().getBean(UiScreenProperties.class).getCommitShortcut();
    Action commitAndCloseAction = new BaseAction(COMMIT_ACTION_ID).withCaption(messages.getMessage("actions.Ok")).withIcon(icons.get(JmixIcon.EDITOR_OK)).withPrimary(true).withShortcut(commitShortcut).withHandler(actionPerformedEvent -> {
        ValidationErrors validationErrors = validateScreen();
        if (!validationErrors.isEmpty()) {
            screenValidation.showValidationErrors(this, validationErrors);
        } else {
            close(new StandardCloseAction(COMMIT_ACTION_ID));
        }
    });
    window.addAction(commitAndCloseAction);
    Action closeAction = new BaseAction(CANCEL_ACTION_ID).withIcon(icons.get(JmixIcon.EDITOR_CANCEL)).withCaption(messages.getMessage("actions.Cancel")).withHandler(actionPerformedEvent -> close(new StandardCloseAction(CANCEL_ACTION_ID)));
    window.addAction(closeAction);
}
Also used : Window(io.jmix.ui.component.Window) StandardCloseAction(io.jmix.ui.screen.StandardCloseAction) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) Messages(io.jmix.core.Messages) UiScreenProperties(io.jmix.ui.UiScreenProperties) StandardCloseAction(io.jmix.ui.screen.StandardCloseAction) ValidationErrors(io.jmix.ui.component.ValidationErrors) Icons(io.jmix.ui.icon.Icons) BaseAction(io.jmix.ui.action.BaseAction)

Example 14 with Messages

use of io.jmix.core.Messages in project jmix by jmix-framework.

the class App method logout.

/**
 * Try to perform logout. If there are unsaved changes in opened windows then logout will not be performed and
 * unsaved changes dialog will appear.
 *
 * @return operation result object
 */
public OperationResult logout() {
    AppUI ui = AppUI.getCurrent();
    try {
        RootWindow topLevelWindow = ui != null ? ui.getTopLevelWindow() : null;
        if (topLevelWindow != null) {
            Screens screens = ui.getScreens();
            if (!screens.hasUnsavedChanges()) {
                performStandardLogout(ui);
                return OperationResult.success();
            }
            UnknownOperationResult result = new UnknownOperationResult();
            Messages messages = applicationContext.getBean(Messages.class);
            Icons icons = applicationContext.getBean(Icons.class);
            Dialogs dialogs = ui.getDialogs();
            dialogs.createOptionDialog().withCaption(messages.getMessage("closeUnsaved.caption")).withMessage(messages.getMessage("discardChangesOnClose")).withActions(new BaseAction("closeApplication").withCaption(messages.getMessage("closeApplication")).withIcon(icons.get(JmixIcon.DIALOG_OK)).withHandler(event -> {
                performStandardLogout(ui);
                result.success();
            }), new DialogAction(DialogAction.Type.CANCEL, Action.Status.PRIMARY).withHandler(event -> result.fail())).show();
            return OperationResult.fail();
        } else {
            performForceLogout();
            return OperationResult.success();
        }
    } catch (Exception e) {
        log.error("Error on logout", e);
        String url = ControllerUtils.getLocationWithoutParams() + "?restartApp";
        if (ui != null) {
            ui.getPage().open(url, "_self");
        }
        return new UnknownOperationResult();
    }
}
Also used : Messages(io.jmix.core.Messages) DialogAction(io.jmix.ui.action.DialogAction) UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult) Icons(io.jmix.ui.icon.Icons) BaseAction(io.jmix.ui.action.BaseAction) RootWindow(io.jmix.ui.component.RootWindow) IllegalConcurrentAccessException(io.jmix.ui.executor.IllegalConcurrentAccessException)

Example 15 with Messages

use of io.jmix.core.Messages in project jmix by jmix-framework.

the class DateFieldImpl method validate.

@Override
public void validate() throws ValidationException {
    if (hasValidationError()) {
        setValidationError(null);
    }
    if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
        return;
    }
    Messages messages = applicationContext.getBean(Messages.class);
    V value = constructModelValue();
    if (!checkRange(value, false)) {
        LoggerFactory.getLogger(DateFieldImpl.class).trace("DateField value is out of range");
        String dateOutOfRangeMessage = messages.getMessage("datePicker.dateOutOfRangeMessage");
        setValidationError(dateOutOfRangeMessage);
        throw new ValidationException(dateOutOfRangeMessage);
    }
    if (isEmpty() && isRequired()) {
        String requiredMessage = getRequiredMessage();
        if (requiredMessage == null) {
            requiredMessage = messages.getMessage("validationFail.defaultRequiredMessage");
        }
        throw new RequiredValueMissingException(requiredMessage, this);
    }
    value = getValue();
    triggerValidators(value);
}
Also used : Messages(io.jmix.core.Messages)

Aggregations

Messages (io.jmix.core.Messages)18 BaseAction (io.jmix.ui.action.BaseAction)5 Icons (io.jmix.ui.icon.Icons)4 Action (io.jmix.ui.action.Action)3 Window (io.jmix.ui.component.Window)3 MetadataTools (io.jmix.core.MetadataTools)2 Notifications (io.jmix.ui.Notifications)2 UiScreenProperties (io.jmix.ui.UiScreenProperties)2 Collection (java.util.Collection)2 Security (com.haulmont.cuba.core.global.Security)1 Op (com.haulmont.cuba.core.global.filter.Op)1 OpManager (com.haulmont.cuba.core.global.filter.OpManager)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 Window (com.haulmont.cuba.gui.components.Window)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1 CssLayout (com.vaadin.ui.CssLayout)1 Layout (com.vaadin.ui.Layout)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)1