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;
}
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);
}
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);");
}
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));
}
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;
}
Aggregations