use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class PropertyWrapper method unsubscribe.
@SuppressWarnings("unchecked")
@Override
public void unsubscribe() {
Datasource datasource = (Datasource) item;
datasource.removeItemChangeListener(weakItemChangeListener);
weakItemChangeListener = null;
datasource.removeItemPropertyChangeListener(weakItemPropertyChangeListener);
weakItemPropertyChangeListener = null;
propertyPath = null;
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class ManagedBeanAttributeDatasource method loadData.
@Override
protected void loadData(Map<String, Object> params) {
data.clear();
Datasource mbeanDs = getDsContext().get("mbeanDs");
ManagedBeanInfo mbean = (ManagedBeanInfo) mbeanDs.getItem();
if (mbean != null) {
try {
jmxControlAPI.loadAttributes(mbean);
} catch (JmxControlException e) {
log.error("Error loading attributes", e);
}
if (mbean.getAttributes() != null) {
for (ManagedBeanAttribute attr : mbean.getAttributes()) {
data.put(attr.getId(), attr);
}
}
}
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class LookupPickerFieldTest method testValueLoadFromOptions.
@Test
public void testValueLoadFromOptions() {
LookupPickerField component = factory.createComponent(LookupPickerField.class);
// noinspection unchecked
Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
testDs.setItem(new User());
((DatasourceImpl) testDs).valid();
assertNull(component.getValue());
Group g = new Group();
testDs.getItem().setGroup(g);
// noinspection unchecked
CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
groupsDs.includeItem(g);
Group g1 = new Group();
g1.setId(g.getId());
groupsDs.includeItem(g1);
Group g2 = new Group();
groupsDs.includeItem(g2);
component.setOptionsDatasource(groupsDs);
component.setDatasource(testDs, "group");
assertTrue("Value should be from options ds", g1 == component.getValue());
component.setValue(g2);
Component.ValueChangeListener listener1 = e -> {
assertEquals(g2, e.getPrevValue());
assertEquals(g1, e.getValue());
};
component.addValueChangeListener(listener1);
component.setValue(g);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class CheckBoxDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
CheckBox checkBox = (CheckBox) factory.createComponent(CheckBox.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setActive(true);
checkBox.setDatasource(userDs, "active");
// unbind
checkBox.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
checkBox.setDatasource(userDs, "active");
checkBox.setValue(false);
assertEquals(true, valueWasChanged[0]);
assertEquals(false, user.getActive());
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class CheckBoxDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
CheckBox checkBox = (CheckBox) factory.createComponent(CheckBox.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setActive(true);
checkBox.setDatasource(userDs, "active");
// unbind
checkBox.setDatasource(null, null);
Component.ValueChangeListener valueChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
checkBox.addValueChangeListener(valueChangeListener);
user.setActive(false);
assertEquals(true, checkBox.getValue());
}
Aggregations