use of com.haulmont.cuba.gui.components.CheckBox in project cuba by cuba-platform.
the class CheckBoxDsTest method testDatasourceRepeatableAssign.
@Test
public void testDatasourceRepeatableAssign() {
CheckBox checkBox = uiComponents.create(CheckBox.NAME);
checkBox.setDatasource(null, null);
checkBox.setDatasource(null, null);
Datasource<User> userDs1 = getTestUserDatasource();
checkBox.setDatasource(userDs1, "active");
checkBox.setDatasource(userDs1, "active");
boolean exceptionWasThrown = false;
try {
checkBox.setDatasource(userDs1, null);
} catch (Exception e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);
exceptionWasThrown = false;
try {
checkBox.setDatasource(null, "active");
} catch (Exception e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);
userDs1.getItem().setActive(true);
checkBox.setDatasource(userDs1, "active");
Datasource<User> userDs2 = getTestUserDatasource();
checkBox.setDatasource(userDs2, "active");
checkBox.setValue(false);
assertEquals(true, userDs1.getItem().getActive());
}
use of com.haulmont.cuba.gui.components.CheckBox in project cuba by cuba-platform.
the class CheckBoxDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
CheckBox checkBox = uiComponents.create(CheckBox.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setActive(true);
checkBox.setDatasource(userDs, "active");
// unbind
checkBox.setDatasource(null, null);
// datasource before listener
checkBox.setDatasource(userDs, "active");
assertEquals(true, checkBox.getValue());
boolean[] valueWasChanged = { false };
Consumer listener = e -> valueWasChanged[0] = true;
checkBox.addValueChangeListener(listener);
user.setActive(false);
assertEquals(true, valueWasChanged[0]);
assertEquals(false, checkBox.getValue());
// reset state
checkBox.removeValueChangeListener(listener);
checkBox.setDatasource(null, null);
valueWasChanged[0] = false;
checkBox.setValue(true);
// listener before datasource
checkBox.addValueChangeListener(listener);
checkBox.setDatasource(userDs, "active");
assertEquals(true, valueWasChanged[0]);
assertEquals(false, checkBox.getValue());
}
use of com.haulmont.cuba.gui.components.CheckBox in project cuba by cuba-platform.
the class CheckBoxDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
CheckBox checkBox = uiComponents.create(CheckBox.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setActive(true);
checkBox.setDatasource(userDs, "active");
// unbind
checkBox.setDatasource(null, null);
Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(propertyChangeListener);
checkBox.setValue(false);
assertEquals(true, user.getActive());
}
use of com.haulmont.cuba.gui.components.CheckBox in project cuba by cuba-platform.
the class CheckBoxDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
CheckBox checkBox = uiComponents.create(CheckBox.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setActive(true);
// listener before datasource
Boolean[] valueWasChanged = { false };
Consumer listener = e -> valueWasChanged[0] = true;
checkBox.addValueChangeListener(listener);
checkBox.setDatasource(userDs, "active");
assertEquals(true, valueWasChanged[0]);
// reset state
checkBox.setDatasource(null, null);
checkBox.removeValueChangeListener(listener);
valueWasChanged[0] = false;
// datasource before listener
checkBox.setDatasource(userDs, "active");
checkBox.addValueChangeListener(listener);
user.setActive(false);
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.CheckBox in project cuba by cuba-platform.
the class WebTableFieldFactory method createField.
@SuppressWarnings("unchecked")
@Override
public com.vaadin.v7.ui.Field<?> createField(com.vaadin.v7.data.Container container, Object itemId, Object propertyId, Component uiContext) {
String fieldPropertyId = String.valueOf(propertyId);
Table.Column columnConf = webTable.getColumnsInternal().get(propertyId);
TableDataContainer tableDataContainer = (TableDataContainer) container;
Entity entity = (Entity) tableDataContainer.getInternalItem(itemId);
InstanceContainer instanceContainer = webTable.getInstanceContainer((E) entity);
com.haulmont.cuba.gui.components.Component columnComponent = createField(new ContainerValueSource(instanceContainer, fieldPropertyId), fieldPropertyId, columnConf.getXmlDescriptor());
if (columnComponent instanceof Field) {
Field cubaField = (Field) columnComponent;
Map<Table.Column, String> requiredColumns = webTable.getRequiredColumnsInternal();
if (requiredColumns != null && requiredColumns.containsKey(columnConf)) {
cubaField.setRequired(true);
cubaField.setRequiredMessage(requiredColumns.get(columnConf));
}
}
if (!(columnComponent instanceof CheckBox)) {
// todo get rid of concrete CheckBox class !
columnComponent.setWidthFull();
}
if (columnComponent instanceof BelongToFrame) {
BelongToFrame belongToFrame = (BelongToFrame) columnComponent;
if (belongToFrame.getFrame() == null) {
belongToFrame.setFrame(webTable.getFrame());
}
}
applyPermissions(columnComponent);
columnComponent.setParent(webTable);
Component componentImpl = getComponentImplementation(columnComponent);
if (componentImpl instanceof com.vaadin.v7.ui.Field) {
return (com.vaadin.v7.ui.Field<?>) componentImpl;
}
return new EditableColumnFieldWrapper(componentImpl, columnComponent);
}
Aggregations