use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class LookupPickerFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
LookupPickerField component = (LookupPickerField) factory.createComponent(LookupPickerField.NAME);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
component.setOptionsDatasource(groupsDs);
List<Group> groups = new ArrayList<>(groupsDs.getItems());
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setGroup(groups.get(0));
component.setDatasource(userDs, "group");
// unbind
component.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
component.setDatasource(userDs, "group");
component.setValue(null);
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class DeclarativeColumnGenerator method generateCell.
@Override
public Component generateCell(Entity entity) {
if (unableToFindMethod) {
return null;
}
Frame frame = table.getFrame();
if (frame == null) {
throw new IllegalStateException("Table should be attached to frame");
}
Frame controller = ComponentsHelper.getFrameController(frame);
if (method == null) {
method = findGeneratorMethod(controller.getClass(), methodName);
if (method == null) {
this.unableToFindMethod = true;
String tableId = table.getId() == null ? "" : table.getId();
throw new IllegalStateException(String.format("No suitable method named %s for column generator of table %s", methodName, tableId));
}
}
try {
return (Component) method.invoke(controller, entity);
} catch (Exception e) {
throw new RuntimeException("Exception in declarative Table column generator " + methodName, e);
}
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class AbstractUploadFieldLoader method loadDropZone.
protected void loadDropZone(UploadField uploadField, Element element) {
String dropZoneId = element.attributeValue("dropZone");
if (StringUtils.isNotEmpty(dropZoneId)) {
Component dropZone = context.getFrame().getComponent(dropZoneId);
if (dropZone instanceof BoxLayout) {
uploadField.setDropZone(new UploadField.DropZone((BoxLayout) dropZone));
} else if (dropZone != null) {
log.warn("Unsupported dropZone class {}", dropZone.getClass().getName());
} else {
log.warn("Unable to find dropZone component with id: {}", dropZoneId);
}
}
String dropZonePrompt = element.attributeValue("dropZonePrompt");
if (StringUtils.isNotEmpty(dropZonePrompt)) {
uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt));
}
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class AccordionLoader method createComponent.
@Override
public void createComponent() {
resultComponent = (Accordion) factory.createComponent(Accordion.NAME);
loadId(resultComponent, element);
// noinspection unchecked
List<Element> tabElements = element.elements("tab");
for (Element tabElement : tabElements) {
final String name = tabElement.attributeValue("id");
boolean lazy = Boolean.parseBoolean(tabElement.attributeValue("lazy"));
ComponentLoader tabComponentLoader = getLoader(tabElement, TabComponentLoader.class);
Accordion.Tab tab;
if (lazy) {
tab = resultComponent.addLazyTab(name, tabElement, tabComponentLoader);
} else {
tabComponentLoader.createComponent();
Component tabComponent = tabComponentLoader.getResultComponent();
tab = resultComponent.addTab(name, tabComponent);
pendingLoadComponents.add(tabComponentLoader);
}
pendingLoadTabs.put(tabElement, tab);
}
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class BulkEditorLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadStyleName(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadIcon(resultComponent, element);
loadWidth(resultComponent, element);
loadAlign(resultComponent, element);
loadResponsive(resultComponent, element);
loadTabIndex(resultComponent, element);
if (!userSessionSource.getUserSession().isSpecificPermitted(BulkEditor.PERMISSION)) {
resultComponent.setVisible(false);
}
String openType = element.attributeValue("openType");
if (StringUtils.isNotEmpty(openType)) {
resultComponent.setOpenType(WindowManager.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().getCurrentFrameId());
}
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.getFullFrameId(), "componentId", resultComponent.getId());
}
String loadDynamicAttributes = element.attributeValue("loadDynamicAttributes");
if (StringUtils.isNotEmpty(loadDynamicAttributes)) {
resultComponent.setLoadDynamicAttributes(Boolean.parseBoolean(loadDynamicAttributes));
}
context.addPostInitTask((context1, window) -> {
// todo artamonov here we can use post wrap instead of post init
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", context1.getFullFrameId(), "componentId", resultComponent.getId());
}
resultComponent.setListComponent((ListComponent) bindComponent);
}
});
loadValidators(resultComponent, element);
loadFocusable(resultComponent, element);
}
Aggregations