use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class CompositeMapTest method testChangeInSecondMap.
@Test
public void testChangeInSecondMap() {
SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0");
person0.getCart().setNumItems(13);
persons.add(person0);
MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
composedMap.addMapChangeListener(tracker);
assertEquals(0, tracker.count);
person0.getCart().setNumItems(42);
assertEquals(1, tracker.count);
assertEquals(0, tracker.event.diff.getAddedKeys().size());
assertEquals(0, tracker.event.diff.getRemovedKeys().size());
assertEquals(Collections.singleton(person0), tracker.event.diff.getChangedKeys());
assertEquals(Integer.valueOf(13), tracker.event.diff.getOldValue(person0));
assertEquals(Integer.valueOf(42), tracker.event.diff.getNewValue(person0));
assertEquals(Integer.valueOf(42), composedMap.get(person0));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class CompositeMapTest method testRemoveSharedFromFirstMap.
@Test
public void testRemoveSharedFromFirstMap() {
SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1");
person1.getCart().setNumItems(42);
persons.add(person1);
SimplePerson person2 = new SimplePerson("p1", "a1", "c1", "s1");
person2.setCart(person1.getCart());
persons.add(person2);
assertTrue("person2 should be added", composedMap.containsKey(person2));
MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
composedMap.addMapChangeListener(tracker);
assertEquals(0, tracker.count);
persons.remove(person2);
assertEquals(1, tracker.count);
assertEquals(0, tracker.event.diff.getAddedKeys().size());
assertEquals(0, tracker.event.diff.getChangedKeys().size());
assertEquals(Collections.singleton(person2), tracker.event.diff.getRemovedKeys());
assertEquals(Integer.valueOf(42), tracker.event.diff.getOldValue(person2));
assertFalse("person2 should be removed", composedMap.containsKey(person2));
assertEquals(Integer.valueOf(42), composedMap.get(person1));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class CompositeMapTest method testChangeInFirstMapFromShared.
@Test
public void testChangeInFirstMapFromShared() {
SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0");
person0.getCart().setNumItems(13);
persons.add(person0);
SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1");
person1.setCart(person0.getCart());
persons.add(person1);
MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
composedMap.addMapChangeListener(tracker);
assertEquals(0, tracker.count);
person1.setCart(new SimpleCart());
assertEquals(1, tracker.count);
assertEquals(0, tracker.event.diff.getAddedKeys().size());
assertEquals(0, tracker.event.diff.getRemovedKeys().size());
assertEquals(Collections.singleton(person1), tracker.event.diff.getChangedKeys());
assertEquals(Integer.valueOf(13), tracker.event.diff.getOldValue(person1));
assertEquals(Integer.valueOf(0), tracker.event.diff.getNewValue(person1));
assertEquals(Integer.valueOf(0), composedMap.get(person1));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class TestMasterDetail method bind.
private void bind(Control parent) {
Realm realm = DisplayRealm.getRealm(parent.getDisplay());
TableViewer peopleViewer = new TableViewer(personsTable);
ViewerSupport.bind(peopleViewer, new WritableList<>(realm, model.getPersonList(), SimpleModel.class), BeanProperties.values(SimplePerson.class, "name", "state"));
IObservableValue<SimplePerson> selectedPerson = ViewerProperties.singleSelection(SimplePerson.class).observe(peopleViewer);
DataBindingContext dbc = new DataBindingContext(realm) {
@Override
protected <T, M> UpdateValueStrategy<T, M> createTargetToModelUpdateValueStrategy(IObservableValue<T> fromValue, IObservableValue<M> toValue) {
return new CustomUpdateValueStrategy<>();
}
};
IConverter<String, String> upperCaseConverter = new IConverter<>() {
@Override
public String convert(String fromObject) {
return fromObject.toUpperCase();
}
@Override
public Object getFromType() {
return String.class;
}
@Override
public Object getToType() {
return String.class;
}
};
IValidator<String> vowelValidator = value -> {
if (!value.matches("[aeiouAEIOU]*")) {
return ValidationStatus.error("only vowels allowed");
}
return Status.OK_STATUS;
};
Binding b = dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(name), BeanProperties.value(SimplePerson.class, "name", String.class).observeDetail(selectedPerson), new CustomUpdateValueStrategy<String, String>().setConverter(upperCaseConverter).setAfterGetValidator(vowelValidator), null);
// AggregateValidationStatus status = new AggregateValidationStatus(dbc
// .getBindings(), AggregateValidationStatus.MAX_SEVERITY);
dbc.bindValue(WidgetProperties.text().observe(validationStatus), b.getValidationStatus(), null, new UpdateValueStrategy<Object, String>().setConverter(new ObjectToStringConverter()));
dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(address), BeanProperties.value(SimplePerson.class, "address", String.class).observeDetail(selectedPerson));
dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(city), BeanProperties.value(SimplePerson.class, "city", String.class).observeDetail(selectedPerson));
dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(state), BeanProperties.value(SimplePerson.class, "state", String.class).observeDetail(selectedPerson));
TableViewer ordersViewer = new TableViewer(ordersTable);
ViewerSupport.bind(ordersViewer, BeanProperties.list(SimplePerson.class, "orders", SimpleOrder.class).observeDetail(selectedPerson), BeanProperties.values(SimpleOrder.class, "orderNumber", "date"));
}
use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.
the class ListDetailValueObservableListTest method testUnmodifiability.
@Test
public void testUnmodifiability() {
WritableList masterObservableList = new WritableList();
masterObservableList.add(new SimplePerson());
masterObservableList.add(new SimplePerson());
ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterObservableList, BeansObservables.valueFactory("name"), null);
try {
ldol.add("name");
fail("ListDetailValueObservableList must not be modifiable.");
} catch (UnsupportedOperationException e) {
// expected exception
}
try {
ldol.remove(masterObservableList.get(0));
fail("ListDetailValueObservableList must not be modifiable.");
} catch (UnsupportedOperationException e) {
// expected exception
}
try {
ldol.removeAll(Collections.singleton(masterObservableList.get(0)));
fail("ListDetailValueObservableList must not be modifiable.");
} catch (UnsupportedOperationException e) {
// expected exception
}
try {
ldol.retainAll(Collections.EMPTY_LIST);
fail("ListDetailValueObservableList must not be modifiable.");
} catch (UnsupportedOperationException e) {
// expected exception
}
try {
ldol.move(0, 1);
fail("ListDetailValueObservableList must not be modifiable.");
} catch (UnsupportedOperationException e) {
// expected exception
}
}
Aggregations