use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class BulkEditAction method actionPerform.
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null && !beforeActionPerformedHandler.beforeActionPerformed()) {
return;
}
Security security = AppBeans.get(Security.class);
if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
Messages messages = AppBeans.get(Messages.class);
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("accessDenied.message")).show();
return;
}
if (target.getSelected().isEmpty()) {
Messages messages = AppBeans.get(Messages.class);
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.HUMANIZED).withCaption(messages.getMessage("actions.BulkEdit.emptySelection")).show();
return;
}
OpenType openType = this.openType;
if (openType.getOpenMode() == OpenMode.DIALOG) {
ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.class);
ThemeConstants theme = themeManager.getConstants();
openType = openType.copy().width(theme.get("cuba.gui.BulkEditAction.editorDialog.width")).height(theme.get("cuba.gui.BulkEditAction.editorDialog.height")).resizable(true);
}
Map<String, Object> params = ParamsMap.of().pair("metaClass", target.getDatasource().getMetaClass()).pair("selected", target.getSelected()).pair("exclude", exclude).pair("includeProperties", includeProperties != null ? includeProperties : Collections.EMPTY_LIST).pair("fieldValidators", fieldValidators).pair("modelValidators", modelValidators).pair("loadDynamicAttributes", loadDynamicAttributes).pair("useConfirmDialog", useConfirmDialog).pair("columnsMode", columnsMode).create();
WindowManager wm = ((WindowManager) getScreenContext(target.getFrame()).getScreens());
WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("bulkEditor");
Window bulkEditor = wm.openWindow(windowInfo, openType, params);
bulkEditor.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
target.getDatasource().refresh();
}
if (target instanceof Component.Focusable) {
((Component.Focusable) target).focus();
}
});
}
use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class AddConditionHelper method addCondition.
/**
* Opens AddCondition window. When condition is selected/created a {@code Handler#handle} method will be called
*
* @param conditionsTree conditions tree is necessary for custom condition editing. It is used for suggestion of
* other component names in 'param where' field.
*/
public void addCondition(final ConditionsTree conditionsTree) {
Map<String, Object> params = new HashMap<>();
ConditionDescriptorsTreeBuilderAPI descriptorsTreeBuilder = AppBeans.getPrototype(ConditionDescriptorsTreeBuilderAPI.NAME, filter, properties.getGenericFilterPropertiesHierarchyDepth(), hideDynamicAttributes, hideCustomConditions, conditionsTree);
Tree<AbstractConditionDescriptor> descriptorsTree = descriptorsTreeBuilder.build();
params.put("descriptorsTree", descriptorsTree);
WindowInfo windowInfo = windowConfig.getWindowInfo("addCondition");
AddConditionWindow window = (AddConditionWindow) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
window.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
Collection<AbstractConditionDescriptor> descriptors = window.getDescriptors();
if (descriptors != null) {
for (AbstractConditionDescriptor descriptor : descriptors) {
_addCondition(descriptor, conditionsTree);
}
}
}
});
}
use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class AddConditionHelper method _addCondition.
protected void _addCondition(AbstractConditionDescriptor descriptor, ConditionsTree conditionsTree) {
final AbstractCondition condition = descriptor.createCondition();
if (descriptor instanceof CustomConditionCreator) {
WindowInfo windowInfo = windowConfig.getWindowInfo("customConditionEditor");
Map<String, Object> params = new HashMap<>();
params.put("condition", condition);
params.put("conditionsTree", conditionsTree);
params.put("filter", filter);
final CustomConditionEditor window = (CustomConditionEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
window.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
handler.handle(condition);
}
});
} else if (descriptor instanceof DynamicAttributesConditionCreator) {
WindowInfo windowInfo = windowConfig.getWindowInfo("dynamicAttributesConditionEditor");
Map<String, Object> params = new HashMap<>();
params.put("condition", condition);
params.put("filter", filter);
DynamicAttributesConditionEditor window = (DynamicAttributesConditionEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
window.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
handler.handle(condition);
}
});
} else {
handler.handle(condition);
}
}
use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class CubaMenuItemCommands method loadParams.
protected Map<String, Object> loadParams(MenuItem item) {
Element descriptor = item.getDescriptor();
if (descriptor == null) {
return Collections.emptyMap();
}
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
for (Element element : descriptor.elements("param")) {
String value = element.attributeValue("value");
EntityLoadInfo info = EntityLoadInfo.parse(value);
if (info == null) {
if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
Boolean booleanValue = Boolean.valueOf(value);
builder.put(element.attributeValue("name"), booleanValue);
} else {
if (value.startsWith("${") && value.endsWith("}")) {
String property = environment.getProperty(value.substring(2, value.length() - 1));
if (!StringUtils.isEmpty(property)) {
value = property;
}
}
builder.put(element.attributeValue("name"), value);
}
} else {
builder.put(element.attributeValue("name"), loadEntityInstance(info));
}
}
String screen = item.getScreen();
if (StringUtils.isNotEmpty(screen)) {
WindowInfo windowInfo = windowConfig.getWindowInfo(screen);
// caption is passed only for legacy screens
if (windowInfo.getDescriptor() != null) {
String caption = menuConfig.getItemCaption(item);
builder.put("caption", caption);
}
}
return builder.build();
}
use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class FragmentComponentLoader method createComponent.
@Override
public void createComponent() {
WindowInfo windowInfo = createWindowInfo(element);
String fragmentId;
if (element.attributeValue("id") != null) {
fragmentId = element.attributeValue("id");
} else {
fragmentId = windowInfo.getId();
}
Timer.Sample createSample = Timer.start(getMeterRegistry());
Fragment fragment = createComponentInternal();
FragmentHelper fragmentHelper = getFragmentHelper();
ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
// setup screen and controller
ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
FrameOwner hostController = parentContext.getFrame().getFrameOwner();
setHostController(controller, hostController);
setWindowId(controller, windowInfo.getId());
setFrame(controller, fragment);
setupScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
setScreenData(controller, applicationContext.getBean(ScreenData.class));
FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
fragmentImpl.setFrameOwner(controller);
fragmentImpl.setId(fragmentId);
FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
((FrameImplementation) fragment).setContext(frameContext);
if (windowInfo.getTemplate() != null) {
String frameId = fragmentId;
if (parentContext.getFullFrameId() != null) {
frameId = parentContext.getFullFrameId() + "." + frameId;
}
innerContext = createInnerContext();
innerContext.setCurrentFrameId(fragmentId);
innerContext.setFullFrameId(frameId);
innerContext.setFrame(fragment);
innerContext.setParent(parentContext);
innerContext.setProperties(loadProperties(element));
LayoutLoader layoutLoader = getLayoutLoader(innerContext);
ScreenXmlLoader screenXmlLoader = applicationContext.getBean(ScreenXmlLoader.class);
Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getComponentContext().getParams());
innerContext.setMessageGroup(fragmentHelper.findMessageGroup(rootElement, windowInfo.getTemplate()));
loadAdditionalData(rootElement);
this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
}
createSample.stop(createScreenTimer(getMeterRegistry(), ScreenLifeCycle.CREATE, windowInfo.getId()));
this.resultComponent = fragment;
}
Aggregations