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;
}
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);
}
}
}
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);
}
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();
}
}
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);
}
Aggregations