Search in sources :

Example 1 with IMasterDetailProvider

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());
}
Also used : CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) DetailListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo) SetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo) SingleSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo) DetailSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo) ListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo) ViewerObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) IMasterDetailProvider(org.eclipse.wb.internal.rcp.databinding.model.beans.IMasterDetailProvider) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) TreeViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo) ViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo) BindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) ViewerObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)

Example 2 with IMasterDetailProvider

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;
}
Also used : IModelSupport(org.eclipse.wb.internal.core.databinding.parser.IModelSupport) MapsEmfObservableInfo(org.eclipse.wb.internal.rcp.databinding.emf.model.observables.MapsEmfObservableInfo) DetailValueEmfObservableInfo(org.eclipse.wb.internal.rcp.databinding.emf.model.observables.DetailValueEmfObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) ListEmfObservableInfo(org.eclipse.wb.internal.rcp.databinding.emf.model.observables.ListEmfObservableInfo) DetailListEmfObservableInfo(org.eclipse.wb.internal.rcp.databinding.emf.model.observables.DetailListEmfObservableInfo) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) ValueEmfObservableInfo(org.eclipse.wb.internal.rcp.databinding.emf.model.observables.ValueEmfObservableInfo) DirectFieldModelSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectFieldModelSupport) IMasterDetailProvider(org.eclipse.wb.internal.rcp.databinding.model.beans.IMasterDetailProvider) IModelResolverFilter(org.eclipse.wb.internal.core.databinding.parser.IModelResolverFilter)

Aggregations

ObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo)2 IMasterDetailProvider (org.eclipse.wb.internal.rcp.databinding.model.beans.IMasterDetailProvider)2 KnownElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo)2 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)1 IModelResolverFilter (org.eclipse.wb.internal.core.databinding.parser.IModelResolverFilter)1 IModelSupport (org.eclipse.wb.internal.core.databinding.parser.IModelSupport)1 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)1 DetailListEmfObservableInfo (org.eclipse.wb.internal.rcp.databinding.emf.model.observables.DetailListEmfObservableInfo)1 DetailValueEmfObservableInfo (org.eclipse.wb.internal.rcp.databinding.emf.model.observables.DetailValueEmfObservableInfo)1 ListEmfObservableInfo (org.eclipse.wb.internal.rcp.databinding.emf.model.observables.ListEmfObservableInfo)1 MapsEmfObservableInfo (org.eclipse.wb.internal.rcp.databinding.emf.model.observables.MapsEmfObservableInfo)1 ValueEmfObservableInfo (org.eclipse.wb.internal.rcp.databinding.emf.model.observables.ValueEmfObservableInfo)1 DirectFieldModelSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectFieldModelSupport)1 DetailListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo)1 DetailSetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo)1 ListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo)1 MapsBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)1 SetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo)1 WritableListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)1 WritableSetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo)1