Search in sources :

Example 1 with WidgetPropertyBindableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo in project windowbuilder by eclipse.

the class AbstractViewerInputBindingInfo method getViewerInutElementType.

// //////////////////////////////////////////////////////////////////////////
// 
// Utils
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * @return {@link Class} of element into given viewer input or <code>null</code> if its not set.
 */
public static Class<?> getViewerInutElementType(ObservableInfo observable, DatabindingsProvider provider) throws Exception {
    if (observable.getBindableObject() instanceof WidgetBindableInfo) {
        // prepare widget
        WidgetBindableInfo widget = (WidgetBindableInfo) observable.getBindableObject();
        // prepare input property
        WidgetPropertyBindableInfo property = widget.resolvePropertyReference("setInput");
        // find input binding
        for (AbstractBindingInfo binding : provider.getBindings0()) {
            if (binding.getTarget() == widget && binding.getTargetProperty() == property) {
                AbstractViewerInputBindingInfo viewerBinding = (AbstractViewerInputBindingInfo) binding;
                return viewerBinding.getElementType();
            }
        }
    }
    // 
    return null;
}
Also used : AbstractBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.AbstractBindingInfo) WidgetPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo)

Example 2 with WidgetPropertyBindableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo in project windowbuilder by eclipse.

the class DatabindingParser method parseBinding.

private BindingInfo parseBinding(DocumentElement element, String property, Map<String, String> attributes) throws Exception {
    WidgetBindableInfo target = m_widgetContainer.resolve(element);
    if (target == null) {
        m_provider.addWarning(MessageFormat.format(Messages.DatabindingParser_widgetNotFound, element), new Throwable());
        return null;
    }
    // 
    WidgetPropertyBindableInfo targetProperty = target.resolvePropertyByText(property);
    if (targetProperty == null) {
        m_provider.addWarning(MessageFormat.format(Messages.DatabindingParser_widgetPropertyNotFound, element, property), new Throwable());
        return null;
    }
    // 
    String path = attributes.get("path");
    String elementName = attributes.get("elementname");
    // 
    if (elementName != null) {
        WidgetBindableInfo model = m_widgetContainer.resolve(elementName);
        if (model == null) {
            m_provider.addWarning(MessageFormat.format(Messages.DatabindingParser_widgetNotFound, elementName), new Throwable());
            return null;
        }
        // 
        if (path.toLowerCase().startsWith("singleselection.(") && path.endsWith(")")) {
            if (property.equalsIgnoreCase("input")) {
            // XXX
            }
            // XXX
            return null;
        }
        // 
        WidgetPropertyBindableInfo modelProperty = model.resolvePropertyByText(path.toLowerCase());
        if (modelProperty == null) {
            m_provider.addWarning(MessageFormat.format(Messages.DatabindingParser_widgetPropertyNotFound, element, path), new Throwable());
            return null;
        }
        // 
        return createBinding(target, targetProperty, model, modelProperty, attributes);
    }
    // 
    BeanBindableInfo model = null;
    String source = attributes.get("source");
    // 
    if (source != null) {
        String sourceReference = StringUtils.substringBetween(source, "{StaticResource", "}").trim();
        model = (BeanBindableInfo) m_beanContainer.resolve(sourceReference);
    } else {
        model = m_beanContainer.getDataContext();
    }
    // 
    if (model == null) {
        m_provider.addWarning(Messages.DatabindingParser_beanNotFound, new Throwable());
        return null;
    }
    // 
    PropertyBindableInfo modelProperty = model.resolvePropertyReference("\"" + path.toLowerCase() + "\"");
    if (modelProperty == null) {
        m_provider.addWarning(MessageFormat.format(Messages.DatabindingParser_beanPropertyNotFound, path), new Throwable());
        return null;
    }
    // 
    if (property.equalsIgnoreCase("input")) {
        // XXX
        return null;
    }
    // 
    return createBinding(target, targetProperty, model, modelProperty, attributes);
}
Also used : PropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.PropertyBindableInfo) WidgetPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo) WidgetPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo) BeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.xwt.model.widgets.WidgetBindableInfo)

Example 3 with WidgetPropertyBindableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo in project windowbuilder by eclipse.

the class CodeGenerationTest method test_ViewerObservableInfo.

public void test_ViewerObservableInfo() throws Exception {
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", "  protected Shell m_shell;", "  private CheckboxTableViewer m_viewer;", "  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 FillLayout());", "    m_viewer = new CheckboxTableViewer(m_shell, SWT.NONE);", "  }", "}" });
    assertNotNull(shell);
    // 
    DatabindingsProvider provider = getDatabindingsProvider();
    List<IObserveInfo> observes = provider.getObserves(ObserveType.WIDGETS);
    // 
    WidgetBindableInfo viewerBindable = (WidgetBindableInfo) observes.get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0);
    // 
    WidgetPropertyBindableInfo singleSelection = (WidgetPropertyBindableInfo) viewerBindable.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(0);
    assertObservableInfo(new SingleSelectionObservableInfo(viewerBindable, singleSelection), new SingleSelectionObservableCodeSupport(), "viewerObservable", "org.eclipse.core.databinding.observable.value.IObservableValue viewerObservable = org.eclipse.jface.databinding.viewers.ViewersObservables.observeSingleSelection(m_viewer);", "org.eclipse.core.databinding.observable.value.IObservableValue viewerObserveSingleSelection = org.eclipse.jface.databinding.viewers.ViewersObservables.observeSingleSelection(m_viewer);");
    // 
    WidgetPropertyBindableInfo multiSelection = (WidgetPropertyBindableInfo) viewerBindable.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(2);
    assertObservableInfo(new MultiSelectionObservableInfo(viewerBindable, multiSelection), new MultiSelectionObservableCodeSupport(), "viewerObservable", "org.eclipse.core.databinding.observable.list.IObservableList viewerObservable = org.eclipse.jface.databinding.viewers.ViewersObservables.observeMultiSelection(m_viewer);", "org.eclipse.core.databinding.observable.list.IObservableList viewerObserveMultiSelection = org.eclipse.jface.databinding.viewers.ViewersObservables.observeMultiSelection(m_viewer);");
    // 
    CheckedElementsObservableInfo checkedObservable = new CheckedElementsObservableInfo(viewerBindable);
    checkedObservable.setElementType(String.class);
    assertObservableInfo(checkedObservable, new CheckedElementsObservableCodeSupport(), "viewerObservable", "org.eclipse.core.databinding.observable.set.IObservableSet viewerObservable = org.eclipse.jface.databinding.viewers.ViewersObservables.observeCheckedElements(m_viewer, java.lang.String.class);", "org.eclipse.core.databinding.observable.set.IObservableSet viewerObserveCheckedElements = org.eclipse.jface.databinding.viewers.ViewersObservables.observeCheckedElements(m_viewer, java.lang.String.class);");
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) MultiSelectionObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.MultiSelectionObservableCodeSupport) SingleSelectionObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SingleSelectionObservableCodeSupport) SingleSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) WidgetPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo) CheckedElementsObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.CheckedElementsObservableCodeSupport)

Example 4 with WidgetPropertyBindableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo in project windowbuilder by eclipse.

the class WidgetBindableTest method test_widget_Viewer_properties.

public void test_widget_Viewer_properties() throws Exception {
    WidgetBindableInfo root = parseBindings("  private TableViewer m_viewer;", "    m_viewer = new TableViewer(m_shell, SWT.NONE);");
    List<IObserveInfo> controls = root.getChildren(ChildrenContext.ChildrenForMasterTable);
    List<IObserveInfo> children = controls.get(0).getChildren(ChildrenContext.ChildrenForMasterTable);
    List<IObserveInfo> properties = children.get(0).getChildren(ChildrenContext.ChildrenForPropertiesTable);
    assertEquals(5, properties.size());
    // 
    assertBindableProperty(WidgetPropertyBindableInfo.class, "single selection|observeSingleSelection|java.lang.Object", properties.get(0));
    assertBindableProperty(WidgetPropertyBindableInfo.class, "part of selection|observeSingleSelection|java.lang.Object", properties.get(1));
    assertBindableProperty(WidgetPropertyBindableInfo.class, "multi selection|observeMultiSelection|java.lang.Object", properties.get(2));
    assertBindableProperty(WidgetPropertyBindableInfo.class, "filters|observeFilters|org.eclipse.jface.viewers.ViewerFilter", properties.get(3));
    // 
    assertBindableProperty(WidgetPropertyBindableInfo.class, "input|setInput|java.lang.Object", properties.get(4));
    // 
    WidgetPropertyBindableInfo inputProperty = (WidgetPropertyBindableInfo) properties.get(4);
    assertNotNull(inputProperty.getObservableFactory());
    assertNull(inputProperty.getObservableFactory().createObservable(null, null, null, false));
    assertNull(inputProperty.getObservableFactory().createObservable((BindableInfo) children.get(0), inputProperty, Type.Input, false));
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo) BindableInfo(org.eclipse.wb.internal.rcp.databinding.model.BindableInfo) WidgetPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo) WidgetPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo)

Example 5 with WidgetPropertyBindableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo in project windowbuilder by eclipse.

the class AbstractViewerInputBindingInfo method createBinding.

private static IBindingInfo createBinding(BindableInfo bindable, BindableInfo bindableProperty, BindableInfo inputBindable, BindableInfo inputBindableProperty, IObservableFactory inputFactory, DatabindingsProvider provider) throws Exception {
    // prepare viewer
    WidgetBindableInfo viewerBindable = (WidgetBindableInfo) bindable;
    // prepare property
    WidgetPropertyBindableInfo viewerBindableProperty = (WidgetPropertyBindableInfo) bindableProperty;
    // create binding
    Class<?> treeViewerClass = viewerBindable.getClassLoader().loadClass("org.eclipse.jface.viewers.AbstractTreeViewer");
    // 
    AbstractViewerInputBindingInfo binding = treeViewerClass.isAssignableFrom(viewerBindable.getObjectType()) ? new TreeViewerInputBindingInfo(viewerBindable, viewerBindableProperty) : new ViewerInputBindingInfo(viewerBindable, viewerBindableProperty);
    // calculate type
    Type type = inputFactory.getType();
    switch(type) {
        case Detail:
        case List:
            type = Type.OnlyList;
            break;
        case Set:
            type = Type.OnlySet;
            break;
    }
    // 
    boolean useViewerSupport = Activator.getStore().getBoolean(IPreferenceConstants.USE_VIEWER_SUPPORT);
    // sets default providers
    binding.setNewInputObservable(provider.createObservable(inputFactory, inputBindable, inputBindableProperty, type), provider, useViewerSupport);
    return binding;
}
Also used : Type(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory.Type) WidgetPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo)

Aggregations

WidgetPropertyBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo)15 WidgetBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo)14 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)8 ItemsSwtObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ItemsSwtObservableInfo)8 TextSwtObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.TextSwtObservableInfo)8 SwtObservableCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SwtObservableCodeSupport)8 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)8 SwtObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SwtObservableInfo)7 ValueBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.context.ValueBindingInfo)6 SwtObservableTextCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SwtObservableTextCodeSupport)6 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)5 CodeGenerationSupport (org.eclipse.wb.internal.core.databinding.model.CodeGenerationSupport)3 ObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo)3 CheckedElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo)3 SingleSelectionObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo)3 CheckedElementsObservableCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.CheckedElementsObservableCodeSupport)3 SwtObservableItemsCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SwtObservableItemsCodeSupport)3 Expression (org.eclipse.jdt.core.dom.Expression)2 DataBindingContextInfo (org.eclipse.wb.internal.rcp.databinding.model.context.DataBindingContextInfo)2 WidgetsObserveTypeContainer (org.eclipse.wb.internal.rcp.databinding.model.widgets.WidgetsObserveTypeContainer)2