use of io.jmix.ui.component.Component 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.Component in project jmix by jmix-framework.
the class AttributeRecalculationListener method accept.
@Override
public void accept(HasValue.ValueChangeEvent valueChangeEvent) {
if (Boolean.TRUE.equals(recalculationInProgress.get())) {
return;
}
try {
recalculationInProgress.set(true);
Component component = valueChangeEvent.getComponent();
if (component instanceof HasValueSource && ((HasValueSource<?>) component).getValueSource() instanceof ContainerValueSource) {
ContainerValueSource<?, ?> valueSource = (ContainerValueSource<?, ?>) ((HasValueSource<?>) component).getValueSource();
InstanceContainer<?> container = valueSource.getContainer();
Object entity = container.getItem();
EntityValues.setValue(entity, DynAttrUtils.getPropertyFromAttributeCode(attribute.getCode()), valueChangeEvent.getValue());
recalculationManager.recalculateByAttribute(entity, attribute);
}
} finally {
recalculationInProgress.remove();
}
}
use of io.jmix.ui.component.Component in project jmix by jmix-framework.
the class StandardEditor method getEditedEntityContainer.
protected InstanceContainer<T> getEditedEntityContainer() {
EditedEntityContainer annotation = getClass().getAnnotation(EditedEntityContainer.class);
if (annotation == null || Strings.isNullOrEmpty(annotation.value())) {
throw new IllegalStateException(String.format("StandardEditor %s does not declare @EditedEntityContainer", getClass()));
}
String[] parts = annotation.value().split("\\.");
ScreenData screenData;
if (parts.length == 1) {
screenData = getScreenData();
} else {
Frame frame = getWindow();
for (int i = 0; i < parts.length - 1; i++) {
String part = parts[i];
Component component = frame.getComponent(part);
if (!(component instanceof Frame)) {
throw new IllegalStateException("Path to EditedEntityContainer must include frames only");
}
frame = (Frame) component;
}
screenData = UiControllerUtils.getScreenData(frame.getFrameOwner());
}
return screenData.getContainer(parts[parts.length - 1]);
}
use of io.jmix.ui.component.Component in project jmix by jmix-framework.
the class PresentationsFacetImpl method fillWithInnerComponents.
protected Collection<Component> fillWithInnerComponents(Collection<Component> components, HasInnerComponents hasInnerComponents) {
Collection<Component> innerComponents = hasInnerComponents.getInnerComponents();
components.addAll(innerComponents);
for (Component component : innerComponents) {
if (component instanceof HasInnerComponents) {
fillWithInnerComponents(components, (HasInnerComponents) component);
}
}
return components;
}
use of io.jmix.ui.component.Component in project jmix by jmix-framework.
the class PresentationsFacetProvider method loadFromXml.
@Override
public void loadFromXml(PresentationsFacet facet, Element element, ComponentLoader.ComponentContext context) {
loadId(element).ifPresent(facet::setId);
loadAuto(element).ifPresent(facet::setAuto);
if (!facet.isAuto()) {
List<String> ids = loadComponentIds(context, element);
facet.addComponentIds(ids.toArray(new String[0]));
}
if (isPresentationsAvailable()) {
context.addPostInitTask((context1, window) -> {
Collection<Component> components = facet.getComponents();
for (Component component : components) {
if (component instanceof HasTablePresentations) {
((HasTablePresentations) component).loadPresentations();
}
}
});
}
}
Aggregations