use of org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo in project windowbuilder by eclipse.
the class ViewerPropertyCheckedElementsCodeSupport method addSourceCode.
// //////////////////////////////////////////////////////////////////////////
//
// Code generation
//
// //////////////////////////////////////////////////////////////////////////
@Override
public void addSourceCode(ObservableInfo observable, List<String> lines, CodeGenerationSupport generationSupport) throws Exception {
super.addSourceCode(observable, lines, generationSupport);
CheckedElementsObservableInfo checkedObservable = (CheckedElementsObservableInfo) observable;
String sourceCode = "org.eclipse.jface.databinding.viewers.ViewerProperties.checkedElements(" + CoreUtils.getClassName(checkedObservable.getElementType()) + ".class)";
if (getVariableIdentifier() != null) {
if (generationSupport.addModel(this)) {
lines.add("org.eclipse.jface.databinding.viewers.IViewerSetProperty " + getVariableIdentifier() + " = " + sourceCode + ";");
}
sourceCode = getVariableIdentifier();
}
lines.add("org.eclipse.core.databinding.observable.set.IObservableSet " + observable.getVariableIdentifier() + " = " + sourceCode + ".observe(" + observable.getBindableObject().getReference() + ");");
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo 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);");
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo in project windowbuilder by eclipse.
the class ViewerObservableTest method test_observeCheckedElements.
public void test_observeCheckedElements() throws Exception {
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public java.util.Set getNames() {", " return null;", " }", "}"));
waitForAutoBuild();
//
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", " protected Shell m_shell;", " private CheckboxTreeViewer m_viewer;", " private TestBean m_bean;", " 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 CheckboxTreeViewer(m_shell, SWT.BORDER);", " m_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " IObservableSet observeSet = BeansObservables.observeSet(Realm.getDefault(), m_bean, \"names\");", " IObservableSet observeWidget = ViewersObservables.observeCheckedElements(m_viewer, Integer.class);", " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindSet(observeWidget, observeSet, 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(CheckedElementsObservableInfo.class, binding.getTargetObservable());
CheckedElementsObservableInfo observable = (CheckedElementsObservableInfo) binding.getTargetObservable();
//
assertEquals("observeWidget", observable.getVariableIdentifier());
assertEquals("m_viewer.checkedElements(Integer.class)", 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.CheckboxTreeViewer", observable.getBindableObject());
//
WidgetBindableTest.assertBindableProperty(WidgetPropertyBindableInfo.class, "checked elements|observeCheckedElements|java.lang.Object", observable.getBindableProperty());
//
assertNotNull(observable.getElementType());
assertEquals("java.lang.Integer", observable.getElementType().getName());
//
observable.setElementType(null);
assertEquals("m_viewer.checkedElements(?????.class)", observable.getPresentationText());
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo in project windowbuilder by eclipse.
the class CheckedElementsObservableCodeSupport method addSourceCode.
// //////////////////////////////////////////////////////////////////////////
//
// Code generation
//
// //////////////////////////////////////////////////////////////////////////
@Override
public void addSourceCode(ObservableInfo observable, List<String> lines, CodeGenerationSupport generationSupport) throws Exception {
// prepare variable
if (observable.getVariableIdentifier() == null) {
observable.setVariableIdentifier(generationSupport.generateLocalName(observable.getBindableObject().getReference(), observable.getBindableProperty().getReference()));
}
CheckedElementsObservableInfo checkedObservable = (CheckedElementsObservableInfo) observable;
lines.add("org.eclipse.core.databinding.observable.set.IObservableSet " + observable.getVariableIdentifier() + " = org.eclipse.jface.databinding.viewers.ViewersObservables." + observable.getBindableProperty().getReference() + "(" + observable.getBindableObject().getReference() + ", " + CoreUtils.getClassName(checkedObservable.getElementType()) + ".class);");
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo 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;
}
Aggregations