Search in sources :

Example 96 with Datasource

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));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Assert.assertTrue(org.junit.Assert.assertTrue) SearchField(com.haulmont.cuba.gui.components.SearchField) Test(org.junit.Test) UUID(java.util.UUID) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Group(com.haulmont.cuba.security.entity.Group) List(java.util.List) Ignore(org.junit.Ignore) Component(com.haulmont.cuba.gui.components.Component) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.security.entity.Group) SearchField(com.haulmont.cuba.gui.components.SearchField) User(com.haulmont.cuba.security.entity.User) UUID(java.util.UUID) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 97 with Datasource

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]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Assert.assertTrue(org.junit.Assert.assertTrue) SearchField(com.haulmont.cuba.gui.components.SearchField) Test(org.junit.Test) UUID(java.util.UUID) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Group(com.haulmont.cuba.security.entity.Group) List(java.util.List) Ignore(org.junit.Ignore) Component(com.haulmont.cuba.gui.components.Component) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.security.entity.Group) SearchField(com.haulmont.cuba.gui.components.SearchField) User(com.haulmont.cuba.security.entity.User) UUID(java.util.UUID) Test(org.junit.Test)

Example 98 with Datasource

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();
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Example 99 with Datasource

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();
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Example 100 with Datasource

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));
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DeclarativeColumnGenerator(com.haulmont.cuba.gui.xml.DeclarativeColumnGenerator) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Logger(org.slf4j.Logger)

Aggregations

Datasource (com.haulmont.cuba.gui.data.Datasource)111 Ignore (org.junit.Ignore)66 Test (org.junit.Test)66 Component (com.haulmont.cuba.gui.components.Component)61 User (com.haulmont.cuba.security.entity.User)56 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)53 Assert.assertTrue (org.junit.Assert.assertTrue)49 Assert.assertEquals (org.junit.Assert.assertEquals)44 Group (com.haulmont.cuba.security.entity.Group)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 Assert (org.junit.Assert)22 List (java.util.List)20 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 Date (java.util.Date)11 Entity (com.haulmont.cuba.core.entity.Entity)10 Role (com.haulmont.cuba.security.entity.Role)10 MetaClass (com.haulmont.chile.core.model.MetaClass)9 LookupField (com.haulmont.cuba.gui.components.LookupField)9