use of io.jmix.ui.component.Window in project jmix by jmix-framework.
the class BulkEditorLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
Window window = ComponentsHelper.getWindow(resultComponent);
if (window != null && !(window.getFrameOwner() instanceof LegacyFrame)) {
throw new GuiDevelopmentException("BulkEditor component can be used only in legacy screens based on AbstractWindow", context);
}
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadStyleName(resultComponent, element);
loadHtmlSanitizerEnabled(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadIcon(resultComponent, element);
loadWidth(resultComponent, element);
loadAlign(resultComponent, element);
loadResponsive(resultComponent, element);
loadCss(resultComponent, element);
loadColumns(resultComponent, element);
loadTabIndex(resultComponent, element);
Security security = AppBeans.get(Security.class);
if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
resultComponent.setVisible(false);
}
String openType = element.attributeValue("openType");
if (StringUtils.isNotEmpty(openType)) {
resultComponent.setOpenType(OpenType.valueOf(openType));
}
String exclude = element.attributeValue("exclude");
String includeProperties = element.attributeValue("includeProperties");
if (StringUtils.isNotBlank(exclude) && StringUtils.isNotBlank(includeProperties)) {
throw new GuiDevelopmentException("BulkEditor cannot define simultaneously exclude and includeProperties attributes", getContext());
}
if (StringUtils.isNotBlank(exclude)) {
resultComponent.setExcludePropertiesRegex(exclude.replace(" ", ""));
}
if (StringUtils.isNotBlank(includeProperties)) {
resultComponent.setIncludeProperties(Splitter.on(',').omitEmptyStrings().trimResults().splitToList(includeProperties));
}
String listComponent = element.attributeValue("for");
if (StringUtils.isEmpty(listComponent)) {
throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified", context, "componentId", resultComponent.getId());
}
String loadDynamicAttributes = element.attributeValue("loadDynamicAttributes");
if (StringUtils.isNotEmpty(loadDynamicAttributes)) {
resultComponent.setLoadDynamicAttributes(Boolean.parseBoolean(loadDynamicAttributes));
}
String useConfirmDialog = element.attributeValue("useConfirmDialog");
if (StringUtils.isNotEmpty(useConfirmDialog)) {
resultComponent.setUseConfirmDialog(Boolean.parseBoolean(useConfirmDialog));
}
getComponentContext().addPostInitTask((c, w) -> {
if (resultComponent.getListComponent() == null) {
Component bindComponent = resultComponent.getFrame().getComponent(listComponent);
if (!(bindComponent instanceof ListComponent)) {
throw new GuiDevelopmentException("Specify 'for' attribute: id of table or tree", context, "componentId", resultComponent.getId());
}
resultComponent.setListComponent((ListComponent) bindComponent);
}
});
loadValidators(resultComponent, element);
loadFocusable(resultComponent, element);
}
use of io.jmix.ui.component.Window in project jmix by jmix-framework.
the class BulkEditAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
if (!(target.getItems() instanceof EntityDataUnit)) {
throw new IllegalStateException("BulkEditAction target Items is null " + "or does not implement EntityDataUnit");
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
throw new IllegalStateException("Target is not bound to entity");
}
UiBulkEditContext context = new UiBulkEditContext();
accessManager.applyRegisteredConstraints(context);
if (!context.isPermitted()) {
if (target.getFrame() != null) {
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("accessDenied.message")).show();
}
return;
}
if (target.getSelected().isEmpty() && target.getFrame() != null) {
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("actions.BulkEdit.emptySelection")).show();
return;
}
Window window = ComponentsHelper.getWindowNN(target);
BulkEditorBuilder<?> builder = bulkEditors.builder(metaClass, target.getSelected(), window.getFrameOwner()).withListComponent(target);
if (columnsMode != null) {
builder = builder.withColumnsMode(columnsMode);
}
if (exclude != null) {
builder = builder.withExclude(exclude);
}
if (fieldSorter != null) {
builder = builder.withFieldSorter(fieldSorter);
}
if (includeProperties != null) {
builder = builder.withIncludeProperties(includeProperties);
}
if (openMode != null) {
builder = builder.withOpenMode(openMode);
}
if (useConfirmDialog != null) {
builder = builder.withUseConfirmDialog(useConfirmDialog);
}
builder.create().show();
}
use of io.jmix.ui.component.Window in project jmix by jmix-framework.
the class ScreenDependencyUtils method findWindowVerticalLayout.
protected static Optional<JmixWindowVerticalLayout> findWindowVerticalLayout(FrameOwner frameOwner) {
Window window = UiControllerUtils.getScreen(frameOwner).getWindow();
Component vComponent = window.unwrap(Component.class);
if (vComponent instanceof JmixWindowVerticalLayout) {
return Optional.of(((JmixWindowVerticalLayout) vComponent));
}
return Optional.empty();
}
use of io.jmix.ui.component.Window in project jmix by jmix-framework.
the class FilterDelegateImpl method getDefaultFilter.
protected FilterEntity getDefaultFilter(List<FilterEntity> filters) {
Window window = CubaComponentsHelper.getWindowImplementation(filter);
if (window == null) {
throw new IllegalStateException("There is no window set for filter");
}
// First check if there is parameter with name equal to this filter component id, containing a filter code to apply
Map<String, Object> params = filter.getFrame().getContext().getParams();
String code = (String) params.get(filter.getId());
if (!StringUtils.isBlank(code)) {
for (FilterEntity filter : filters) {
if (code.equals(filter.getCode())) {
return filter;
}
}
}
// No 'filter' parameter found, load default filter
FilterEntity defaultFilter = filter.getFrame().getFrameOwner() instanceof LegacyFrame ? getDefaultFilterFromCubaSettings(filters) : getDefaultFilterFromScreenSettings(filters);
if (defaultFilter != null) {
return defaultFilter;
}
FilterEntity globalDefaultFilter = filters.stream().filter(filterEntity -> Boolean.TRUE.equals(filterEntity.getGlobalDefault())).findAny().orElse(null);
return globalDefaultFilter;
}
use of io.jmix.ui.component.Window in project jmix by jmix-framework.
the class FilterDelegateImpl method getDefaultFilterFromCubaSettings.
@Nullable
protected FilterEntity getDefaultFilterFromCubaSettings(List<FilterEntity> filters) {
Window window = CubaComponentsHelper.getWindowImplementation(filter);
if (window == null) {
throw new IllegalStateException("There is no window set for filter");
}
SettingsImpl settings = new SettingsImpl(window.getId());
String componentPath = CubaComponentsHelper.getFilterComponentPath(filter);
String[] strings = ValuePathHelper.parse(componentPath);
String name = ValuePathHelper.pathSuffix(strings);
Element e = settings.get(name).element("defaultFilter");
if (e != null) {
String defIdStr = e.attributeValue("id");
Boolean applyDefault = Boolean.valueOf(e.attributeValue("applyDefault"));
if (!StringUtils.isBlank(defIdStr)) {
UUID defaultId = null;
try {
defaultId = UUID.fromString(defIdStr);
} catch (IllegalArgumentException ex) {
//
}
if (defaultId != null) {
for (FilterEntity filter : filters) {
if (defaultId.equals(filter.getId())) {
filter.setIsDefault(true);
filter.setApplyDefault(applyDefault);
return filter;
}
}
}
}
}
return null;
}
Aggregations