use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class SearchFieldDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
SearchField searchField = factory.createComponent(SearchField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
searchField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = getTestUserDatasource();
Group group = groupsDs.getItems().iterator().next();
User user = userDs.getItem();
user.setGroup(group);
searchField.setDatasource(userDs, "group");
// unbind
searchField.setDatasource(null, null);
Component.ValueChangeListener listener = e -> {
throw new RuntimeException("Value was changed externally");
};
searchField.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class SearchFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
SearchField searchField = factory.createComponent(SearchField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
searchField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = getTestUserDatasource();
Group group = groupsDs.getItems().iterator().next();
userDs.getItem().setGroup(group);
searchField.setDatasource(userDs, "group");
// unbind
searchField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
searchField.setDatasource(userDs, "group");
searchField.setValue(null);
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DsContextTest method createMasterDsContext.
private void createMasterDsContext() {
masterDsContext = new DsContextImpl(dataService);
DsBuilder masterDsBuilder = new DsBuilder(masterDsContext);
masterDsBuilder.reset().setId("masterDs").setMetaClass(metadataSession.getClass(TestMasterEntity.class)).setViewName("withDetails");
masterDs = masterDsBuilder.buildDatasource();
masterDsBuilder.reset().setId("detailsDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setMaster(masterDs).setProperty("details");
detailsDs = masterDsBuilder.buildCollectionDatasource();
masterDsBuilder.reset().setId("masterPartsDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setMaster(detailsDs).setProperty("parts");
masterPartsDs = masterDsBuilder.buildCollectionDatasource();
for (Datasource ds : masterDsContext.getAll()) {
((DatasourceImplementation) ds).initialized();
}
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DsContextTest method createPartDsContext.
private void createPartDsContext() {
partDsContext = new DsContextImpl(dataService);
DsBuilder partDsBuilder = new DsBuilder(partDsContext);
partDsBuilder.reset().setId("partDs").setMetaClass(metadataSession.getClass(TestPartEntity.class)).setViewName("_local");
partDs = partDsBuilder.buildDatasource();
for (Datasource ds : partDsContext.getAll()) {
((DatasourceImplementation) ds).initialized();
}
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class AbstractTableLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadEditable(resultComponent, element);
loadValidators(resultComponent, element);
loadSettingsEnabled(resultComponent, element);
loadAlign(resultComponent, element);
loadStyleName(resultComponent, element);
loadHeight(resultComponent, element);
loadWidth(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadTabIndex(resultComponent, element);
loadSortable(resultComponent, element);
loadReorderingAllowed(resultComponent, element);
loadColumnControlVisible(resultComponent, element);
loadAggregatable(resultComponent, element);
loadAggregationStyle(resultComponent, element);
loadPresentations(resultComponent, element);
loadActions(resultComponent, element);
loadContextMenuEnabled(resultComponent, element);
loadMultiLineCells(resultComponent, element);
loadColumnHeaderVisible(resultComponent, element);
loadShowSelection(resultComponent, element);
loadTextSelectionEnabled(resultComponent, element);
loadResponsive(resultComponent, element);
Element columnsElement = element.element("columns");
Element rowsElement = element.element("rows");
if (rowsElement == null) {
throw new GuiDevelopmentException("Table doesn't have 'rows' element", context.getCurrentFrameId(), "Table ID", element.attributeValue("id"));
}
String rowHeaderMode = rowsElement.attributeValue("rowHeaderMode");
if (StringUtils.isBlank(rowHeaderMode)) {
rowHeaderMode = rowsElement.attributeValue("headerMode");
if (StringUtils.isNotBlank(rowHeaderMode)) {
Logger log = LoggerFactory.getLogger(AbstractTableLoader.class);
log.warn("Attribute headerMode is deprecated. Use rowHeaderMode.");
}
}
if (!StringUtils.isEmpty(rowHeaderMode)) {
resultComponent.setRowHeaderMode(Table.RowHeaderMode.valueOf(rowHeaderMode));
}
loadButtonsPanel(resultComponent);
// must be before datasource setting
loadRowsCount(resultComponent, element);
String datasource = rowsElement.attributeValue("datasource");
if (StringUtils.isBlank(datasource)) {
throw new GuiDevelopmentException("Table 'rows' element doesn't have 'datasource' attribute", context.getCurrentFrameId(), "Table ID", element.attributeValue("id"));
}
Datasource ds = context.getDsContext().get(datasource);
if (ds == null) {
throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context.getCurrentFrameId());
}
if (!(ds instanceof CollectionDatasource)) {
throw new GuiDevelopmentException("Not a CollectionDatasource: " + datasource, context.getCurrentFrameId());
}
CollectionDatasource cds = (CollectionDatasource) ds;
List<Table.Column> availableColumns;
if (columnsElement != null) {
availableColumns = loadColumns(resultComponent, columnsElement, cds);
} else {
availableColumns = new ArrayList<>();
}
for (Table.Column column : availableColumns) {
resultComponent.addColumn(column);
loadValidators(resultComponent, column);
loadRequired(resultComponent, column);
}
addDynamicAttributes(resultComponent, ds, availableColumns);
resultComponent.setDatasource(cds);
for (Table.Column column : availableColumns) {
if (column.getXmlDescriptor() != null) {
String generatorMethod = column.getXmlDescriptor().attributeValue("generator");
if (StringUtils.isNotEmpty(generatorMethod)) {
// noinspection unchecked
resultComponent.addGeneratedColumn(String.valueOf(column), new DeclarativeColumnGenerator(resultComponent, generatorMethod));
}
}
}
String multiselect = element.attributeValue("multiselect");
if (StringUtils.isNotEmpty(multiselect)) {
resultComponent.setMultiSelect(Boolean.parseBoolean(multiselect));
}
}
Aggregations