use of org.eclipse.wb.internal.rcp.databinding.model.beans.IMasterDetailProvider in project windowbuilder by eclipse.
the class ViewerObservableTest method test_observeSingleSelection.
// //////////////////////////////////////////////////////////////////////////
//
// Viewer
//
// //////////////////////////////////////////////////////////////////////////
public void test_observeSingleSelection() throws Exception {
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", " protected Shell m_shell;", " private TableViewer m_viewer;", " private DataBindingContext m_bindingContext;", " public static void main(String[] args) {", " Test test = new Test();", " test.open();", " }", " public void open() {", " Display display = new Display();", " createContents();", " m_shell.open();", " m_shell.layout();", " while (!m_shell.isDisposed()) {", " if (!display.readAndDispatch()) {", " display.sleep();", " }", " }", " }", " protected void createContents() {", " m_shell = new Shell();", " m_shell.setLayout(new GridLayout());", " m_viewer = new TableViewer(m_shell, SWT.BORDER);", " m_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " IObservableValue observeValue = BeansObservables.observeValue(getClass(), \"name\");", " IObservableValue observeWidget = ViewersObservables.observeSingleSelection(m_viewer);", " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindValue(observeWidget, observeValue, null, null);", " return bindingContext;", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IBindingInfo> bindings = provider.getBindings();
//
assertNotNull(bindings);
assertEquals(1, bindings.size());
//
BindingInfo binding = (BindingInfo) bindings.get(0);
//
assertInstanceOf(SingleSelectionObservableInfo.class, binding.getTargetObservable());
ViewerObservableInfo observable = (ViewerObservableInfo) binding.getTargetObservable();
//
assertEquals("observeWidget", observable.getVariableIdentifier());
assertEquals("m_viewer.selection", observable.getPresentationText());
//
WidgetBindableTest.assertBindable(shell.getChildrenControls().get(0).getChildren().get(0), WidgetBindableInfo.class, provider.getObserves(ObserveType.WIDGETS).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0), false, "m_viewer|m_viewer|org.eclipse.jface.viewers.TableViewer", observable.getBindableObject());
//
WidgetBindableTest.assertBindableProperty(WidgetPropertyBindableInfo.class, "single selection|observeSingleSelection|java.lang.Object", observable.getBindableProperty());
//
assertInstanceOf(IMasterDetailProvider.class, observable);
IMasterDetailProvider detailProvider = (IMasterDetailProvider) observable;
//
ObservableInfo masterObservable = detailProvider.getMasterObservable();
assertNotNull(masterObservable);
assertNotSame(masterObservable, observable);
assertInstanceOf(SingleSelectionObservableInfo.class, masterObservable);
assertNull(masterObservable.getVariableIdentifier());
assertEquals("m_viewer.selection", observable.getPresentationText());
//
WidgetBindableTest.assertBindable(shell.getChildrenControls().get(0).getChildren().get(0), WidgetBindableInfo.class, provider.getObserves(ObserveType.WIDGETS).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0), false, "m_viewer|m_viewer|org.eclipse.jface.viewers.TableViewer", masterObservable.getBindableObject());
//
WidgetBindableTest.assertBindableProperty(WidgetPropertyBindableInfo.class, "part of selection|observeSingleSelection|java.lang.Object", masterObservable.getBindableProperty());
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.IMasterDetailProvider in project windowbuilder by eclipse.
the class EmfObserveTypeContainer method getMasterObservable.
public static ObservableInfo getMasterObservable(AstEditor editor, IModelResolver resolver, Expression expression) throws Exception {
// prepare master detail observable
ObservableInfo masterDetailObservable = (ObservableInfo) resolver.getModel(expression, new IModelResolverFilter() {
@Override
public boolean accept(IModelSupport modelSupport) throws Exception {
if (modelSupport instanceof DirectFieldModelSupport) {
ObservableInfo observable = (ObservableInfo) modelSupport.getModel();
return observable.getBindableObject().getType() == TYPE;
}
return true;
}
});
if (masterDetailObservable == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.EmfObserveTypeContainer_masterObservableNotFound, expression), new Throwable());
return null;
}
Assert.instanceOf(IMasterDetailProvider.class, masterDetailObservable);
// extract master observable
IMasterDetailProvider masterDetailProvider = (IMasterDetailProvider) masterDetailObservable;
ObservableInfo masterObservable = masterDetailProvider.getMasterObservable();
//
return masterObservable;
}
Aggregations