Search in sources :

Example 1 with MultiSelectionObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo 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 2 with MultiSelectionObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo in project windowbuilder by eclipse.

the class WidgetsObserveTypeContainer method parseExpression.

@Override
public AstObjectInfo parseExpression(AstEditor editor, String signature, MethodInvocation invocation, Expression[] arguments, IModelResolver resolver) throws Exception {
    if (ArrayUtils.contains(OBSERVABLE_METHODS, signature)) {
        // SWTObservables.observeXXX(Control, ...)
        // 
        // prepare widget
        WidgetBindableInfo bindableWidget = getBindableWidget(arguments[0]);
        if (bindableWidget == null) {
            AbstractParser.addError(editor, MessageFormat.format(Messages.WidgetsObserveTypeContainer_widgetArgumentNotFound, arguments[0]), new Throwable());
            return null;
        }
        // prepare property
        WidgetPropertyBindableInfo bindableProperty = bindableWidget.resolvePropertyReference(invocation.getName().getIdentifier());
        Assert.isNotNull(bindableProperty);
        // 
        if (TEXT_OBSERVABLE_METHOD_1.equals(signature)) {
            int updateEvent = CoreUtils.evaluate(Integer.class, editor, arguments[1]);
            TextSwtObservableInfo observable = new TextSwtObservableInfo(bindableWidget, bindableProperty, updateEvent);
            observable.setCodeSupport(new SwtObservableTextCodeSupport());
            return observable;
        }
        if (TEXT_OBSERVABLE_METHOD_2.equals(signature)) {
            int[] updateEvents = CoreUtils.evaluate(int[].class, editor, arguments[1]);
            TextSwtObservableInfo observable = new TextSwtObservableInfo(bindableWidget, bindableProperty, updateEvents);
            observable.setCodeSupport(new SwtObservableTextCodeSupport());
            return observable;
        }
        Class<?> objectType = bindableWidget.getObjectType();
        if ((TEXT_OBSERVABLE_METHOD_3.equals(signature) || TEXT_OBSERVABLE_METHOD_4.equals(signature)) && (Text.class.isAssignableFrom(objectType) || StyledText.class.isAssignableFrom(objectType))) {
            TextSwtObservableInfo observable = new TextSwtObservableInfo(bindableWidget, bindableProperty, ArrayUtils.EMPTY_INT_ARRAY);
            observable.setCodeSupport(new SwtObservableTextCodeSupport());
            return observable;
        }
        // 
        if (ITEMS_OBSERVABLE_METHOD.equals(signature)) {
            ItemsSwtObservableInfo observable = new ItemsSwtObservableInfo(bindableWidget, bindableProperty);
            observable.setCodeSupport(new SwtObservableItemsCodeSupport());
            return observable;
        }
        // 
        SwtObservableInfo observable = new SwtObservableInfo(bindableWidget, bindableProperty);
        observable.setCodeSupport(new SwtObservableCodeSupport());
        return observable;
    } else if (SWT_DELAY_OBSERVABLE_METHOD.equals(signature) || VIEWER_DELAY_OBSERVABLE_METHOD.equals(signature)) {
        // SWTObservables.observeDelayedValue(int, ISWTObservableValue)
        // ViewersObservables.observeDelayedValue(int, IViewerObservableValue)
        // 
        // prepare observable
        ObservableInfo observableInfo = (ObservableInfo) resolver.getModel(arguments[1]);
        if (observableInfo == null) {
            AbstractParser.addError(editor, MessageFormat.format(Messages.WidgetsObserveTypeContainer_observableArgumentNotFound, arguments[1]), new Throwable());
            return null;
        }
        Assert.isNull(observableInfo.getVariableIdentifier());
        Assert.instanceOf(IDelayValueProvider.class, observableInfo);
        // 
        // prepare delay value
        int delayValue = CoreUtils.evaluate(Integer.class, editor, arguments[0]);
        IDelayValueProvider delayValueProvider = (IDelayValueProvider) observableInfo;
        delayValueProvider.setDelayValue(delayValue);
        // 
        return observableInfo;
    } else if (ArrayUtils.contains(OBSERVABLE_VIEWER_SINGLE_SELECTION_METHODS, signature)) {
        // ViewersObservables.observeSingleSelection(Viewer)
        // ViewersObservables.observeSingleSelection(ISelectionProvider)
        // 
        WidgetBindableInfo bindableWidget = getBindableWidget(arguments[0]);
        if (bindableWidget == null) {
            AbstractParser.addError(editor, MessageFormat.format(Messages.WidgetsObserveTypeContainer_viewerArgumentNotFound, arguments[0]), new Throwable());
            return null;
        }
        SingleSelectionObservableInfo observable = new SingleSelectionObservableInfo(bindableWidget);
        observable.setCodeSupport(new SingleSelectionObservableCodeSupport());
        return observable;
    } else if (ArrayUtils.contains(OBSERVABLE_VIEWER_MULTI_SELECTION_METHODS, signature)) {
        // ViewersObservables.observeMultiSelection(Viewer)
        // ViewersObservables.observeMultiSelection(ISelectionProvider)
        // 
        WidgetBindableInfo bindableWidget = getBindableWidget(arguments[0]);
        if (bindableWidget == null) {
            AbstractParser.addError(editor, MessageFormat.format(Messages.WidgetsObserveTypeContainer_viewerArgumentNotFound, arguments[0]), new Throwable());
            return null;
        }
        MultiSelectionObservableInfo observable = new MultiSelectionObservableInfo(bindableWidget);
        observable.setCodeSupport(new MultiSelectionObservableCodeSupport());
        return observable;
    } else if (ArrayUtils.contains(OBSERVABLE_VIEWER_CHECKED_ELEMENTS_METHODS, signature)) {
        // ViewersObservables.observeCheckedElements(ICheckable, Object)
        // ViewersObservables.observeCheckedElements(CheckboxTableViewer, Object)
        // ViewersObservables.observeCheckedElements(CheckboxTreeViewer, Object)
        // 
        // prepare viewer
        WidgetBindableInfo bindableWidget = getBindableWidget(arguments[0]);
        if (bindableWidget == null) {
            AbstractParser.addError(editor, MessageFormat.format(Messages.WidgetsObserveTypeContainer_viewerArgumentNotFound, arguments[0]), new Throwable());
            return null;
        }
        // prepare element type
        Class<?> elementType = CoreUtils.evaluate(Class.class, editor, arguments[1]);
        // 
        CheckedElementsObservableInfo observable = new CheckedElementsObservableInfo(bindableWidget, elementType);
        observable.setCodeSupport(new CheckedElementsObservableCodeSupport());
        return observable;
    } else if (OBSERVABLE_VIEWER_FILTERS_METHOD.equals(signature)) {
        // ViewersObservables.observeFilters(StructuredViewer)
        // 
        WidgetBindableInfo bindableWidget = getBindableWidget(arguments[0]);
        if (bindableWidget == null) {
            AbstractParser.addError(editor, MessageFormat.format(Messages.WidgetsObserveTypeContainer_viewerArgumentNotFound, arguments[0]), new Throwable());
            return null;
        }
        FiltersObservableInfo observable = new FiltersObservableInfo(bindableWidget);
        observable.setCodeSupport(new FiltersObservableCodeSupport());
        return observable;
    } else if (ArrayUtils.contains(WIDGET_PROPERTIES_METHODS, signature)) {
        // WidgetProperties.XXXX()
        return new WidgetPropertiesCodeSupport(SwtProperties.SWT_OBSERVABLES_TO_WIDGET_PROPERTIES.get(invocation.getName().getIdentifier()));
    } else if (ITEMS_WIDGET_PROPERTY.equals(signature)) {
        // WidgetProperties.items()
        return new WidgetPropertyItemsCodeSupport();
    } else if (ArrayUtils.contains(TEXT_WIDGET_PROPERTIES, signature)) {
        // WidgetProperties.text(...)
        int[] events = ArrayUtils.EMPTY_INT_ARRAY;
        if (arguments.length == 1) {
            Object objectValue = CoreUtils.evaluateObject(editor, arguments[0]);
            if (objectValue instanceof Integer) {
                Integer value = (Integer) objectValue;
                events = new int[] { value.intValue() };
            } else if (objectValue instanceof int[]) {
                events = (int[]) objectValue;
            } else {
                Assert.fail("");
            }
        }
        return new WidgetPropertyTextCodeSupport(events);
    } else if (SINGLE_SELECTION_VIEWER_PROPERTY.equals(signature)) {
        // ViewerProperties.singleSelection()
        return new ViewerPropertySingleSelectionCodeSupport();
    } else if (MULTI_SELECTION_VIEWER_PROPERTY.equals(signature)) {
        // ViewerProperties.multipleSelection()
        return new ViewerPropertyMultiSelectionCodeSupport();
    } else if (CHECKED_ELEMENTS_VIEWER_PROPERTY.equals(signature)) {
        // ViewerProperties.checkedElements(...)
        Class<?> elementType = CoreUtils.evaluate(Class.class, editor, arguments[0]);
        return new ViewerPropertyCheckedElementsCodeSupport(elementType);
    } else if (FILTERS_ELEMENTS_VIEWER_PROPERTY.equals(signature)) {
        // ViewerProperties.filters()
        return new ViewerPropertyFiltersCodeSupport();
    }
    return null;
}
Also used : SwtObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SwtObservableInfo) TextSwtObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.TextSwtObservableInfo) ItemsSwtObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ItemsSwtObservableInfo) FiltersObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.FiltersObservableInfo) SingleSelectionObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SingleSelectionObservableCodeSupport) SwtObservableTextCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SwtObservableTextCodeSupport) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) WidgetPropertyItemsCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.properties.WidgetPropertyItemsCodeSupport) ViewerPropertyFiltersCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.properties.ViewerPropertyFiltersCodeSupport) WidgetPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo) IDelayValueProvider(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.IDelayValueProvider) MultiSelectionObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.MultiSelectionObservableCodeSupport) TextSwtObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.TextSwtObservableInfo) SingleSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo) ViewerPropertyCheckedElementsCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.properties.ViewerPropertyCheckedElementsCodeSupport) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo) WidgetPropertiesCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.properties.WidgetPropertiesCodeSupport) CheckedElementsObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.CheckedElementsObservableCodeSupport) SwtObservableItemsCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SwtObservableItemsCodeSupport) ViewerPropertyMultiSelectionCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.properties.ViewerPropertyMultiSelectionCodeSupport) SwtObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SwtObservableInfo) SingleSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) TextSwtObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.TextSwtObservableInfo) ItemsSwtObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ItemsSwtObservableInfo) FiltersObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.FiltersObservableInfo) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) StyledText(org.eclipse.swt.custom.StyledText) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) ViewerPropertySingleSelectionCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.properties.ViewerPropertySingleSelectionCodeSupport) SwtObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SwtObservableCodeSupport) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) FiltersObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.FiltersObservableCodeSupport) WidgetPropertyTextCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.properties.WidgetPropertyTextCodeSupport) ItemsSwtObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ItemsSwtObservableInfo)

Example 3 with MultiSelectionObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo in project windowbuilder by eclipse.

the class BeansObserveTypeContainer method createMultiSelection.

AstObjectInfo createMultiSelection(AstEditor editor, Expression[] arguments, IModelResolver resolver) throws Exception {
    BeanBindableInfo bindableObject = m_rootJavaInfo.getChildRepresentedBy(arguments[0]) == null ? getBindableObject(arguments[0]) : null;
    if (bindableObject != null) {
        MultiSelectionObservableInfo observable = new MultiSelectionObservableInfo(bindableObject);
        observable.setCodeSupport(new MultiSelectionObservableCodeSupport());
        return observable;
    }
    return null;
}
Also used : MultiSelectionObservableCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.MultiSelectionObservableCodeSupport) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) FieldBeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.FieldBeanBindableInfo) BeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo) MethodBeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo)

Aggregations

MultiSelectionObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo)3 MultiSelectionObservableCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.MultiSelectionObservableCodeSupport)3 WidgetBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo)2 WidgetPropertyBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetPropertyBindableInfo)2 CheckedElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo)2 SingleSelectionObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo)2 CheckedElementsObservableCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.CheckedElementsObservableCodeSupport)2 SingleSelectionObservableCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.standard.SingleSelectionObservableCodeSupport)2 StyledText (org.eclipse.swt.custom.StyledText)1 Text (org.eclipse.swt.widgets.Text)1 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)1 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)1 ObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo)1 BeanBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo)1 FieldBeanBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.FieldBeanBindableInfo)1 MethodBeanBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo)1 FiltersObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.FiltersObservableInfo)1 IDelayValueProvider (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.IDelayValueProvider)1 ItemsSwtObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ItemsSwtObservableInfo)1 SwtObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SwtObservableInfo)1