use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansListObservableFactoryInfo in project windowbuilder by eclipse.
the class TreeViewerInputBindingInfo method setDefaultProviders.
@Override
public void setDefaultProviders(boolean asList, Class<?> elementType, boolean useViewerSupport) throws Exception {
// create advisor
TreeBeanAdvisorInfo advisor = GlobalFactoryHelper.createTreeBeanAdvisor(m_inputObservable);
if (advisor == null) {
advisor = new TreeBeanAdvisorInfo();
}
advisor.setElementType(elementType);
// create factory
BeansObservableFactoryInfo factory = GlobalFactoryHelper.createTreeObservableFactory(m_inputObservable, asList);
if (factory == null) {
factory = asList ? new BeansListObservableFactoryInfo() : new BeansSetObservableFactoryInfo();
}
factory.setElementType(elementType);
// create content provider
m_contentProvider = asList ? new ObservableListTreeContentProviderInfo(factory, advisor) : new ObservableSetTreeContentProviderInfo(factory, advisor);
// create label provider
KnownElementsObservableInfo allElementsObservable = new KnownElementsObservableInfo(m_contentProvider);
TreeObservableLabelProviderInfo labelProvider = GlobalFactoryHelper.createTreeLabelProvider(m_inputObservable, allElementsObservable);
if (labelProvider == null) {
labelProvider = new TreeObservableLabelProviderInfo(allElementsObservable);
}
labelProvider.setElementType(elementType);
m_labelProvider = labelProvider;
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansListObservableFactoryInfo in project windowbuilder by eclipse.
the class TreeInputElementUiContentProvider method createDesignerProviders.
/**
* Fill Designer page.
*/
private List<IUiContentProvider> createDesignerProviders() {
List<IUiContentProvider> providers = Lists.newArrayList();
providers.add(m_elementTypeDesignerUIProvider);
//
if (m_binding.isDesignerMode()) {
// add life objects
createDefaultProviders(providers, true);
} else {
// create fake objects
ObservableCollectionTreeContentProviderInfo contentProvider = m_binding.getContentProvider();
// create factory
boolean asList = contentProvider instanceof ObservableListTreeContentProviderInfo;
BeansObservableFactoryInfo factory = null;
try {
factory = GlobalFactoryHelper.createTreeObservableFactory(m_binding.getInputObservable(), asList);
} catch (Throwable e) {
DesignerPlugin.log(e);
}
if (factory == null) {
factory = asList ? new BeansListObservableFactoryInfo() : new BeansSetObservableFactoryInfo();
}
//
m_defaultObjects.add(factory);
factory.createContentProviders(providers, m_provider);
// create advisor
TreeBeanAdvisorInfo advisor = null;
try {
advisor = GlobalFactoryHelper.createTreeBeanAdvisor(m_binding.getInputObservable());
} catch (Throwable e) {
DesignerPlugin.log(e);
}
if (advisor == null) {
advisor = new TreeBeanAdvisorInfo();
}
m_defaultObjects.add(advisor);
advisor.createContentProviders(providers, m_provider);
// content provider always exist
contentProvider.createContentProviders(providers, m_provider, true);
// create label provider
KnownElementsObservableInfo allElementsObservable = new KnownElementsObservableInfo(contentProvider);
TreeObservableLabelProviderInfo labelProvider = null;
try {
labelProvider = GlobalFactoryHelper.createTreeLabelProvider(m_binding.getInputObservable(), allElementsObservable);
} catch (Throwable e) {
DesignerPlugin.log(e);
}
if (labelProvider == null) {
labelProvider = new TreeObservableLabelProviderInfo(allElementsObservable);
}
m_defaultObjects.add(labelProvider);
labelProvider.createContentProviders(providers, m_provider, true);
}
// content provider for properties: parent/children/has children/text/image
m_contentLabelProvidersEditor = new TreeContentLabelProvidersUiContentProvider(m_binding);
providers.add(m_contentLabelProvidersEditor);
return providers;
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansListObservableFactoryInfo in project windowbuilder by eclipse.
the class ViewerInputParser method parseExpression.
// //////////////////////////////////////////////////////////////////////////
//
// Parser
//
// //////////////////////////////////////////////////////////////////////////
@Override
public AstObjectInfo parseExpression(AstEditor editor, String signature, ClassInstanceCreation creation, Expression[] arguments, IModelResolver resolver, IDatabindingsProvider provider) throws Exception {
ITypeBinding binding = AstNodeUtils.getTypeBinding(creation);
if (binding == null) {
return null;
}
String className = AstNodeUtils.getFullyQualifiedName(binding, false);
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.core.databinding.observable.masterdetail.IObservableFactory")) {
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.BeansListObservableFactory")) {
Assert.isTrue(signature.endsWith("<init>(java.lang.Class,java.lang.String)"));
// create factory
BeansListObservableFactoryInfo observableFactory = new BeansListObservableFactoryInfo(className);
// prepare element type
observableFactory.setElementType(CoreUtils.evaluate(Class.class, editor, arguments[0]));
// prepare property
observableFactory.setPropertyName(CoreUtils.evaluate(String.class, editor, arguments[1]));
//
return observableFactory;
}
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.BeansSetObservableFactory")) {
Assert.isTrue(signature.endsWith("<init>(java.lang.Class,java.lang.String)"));
// create factory
BeansSetObservableFactoryInfo observableFactory = new BeansSetObservableFactoryInfo(className);
// prepare element type
observableFactory.setElementType(CoreUtils.evaluate(Class.class, editor, arguments[0]));
// prepare property
observableFactory.setPropertyName(CoreUtils.evaluate(String.class, editor, arguments[1]));
//
return observableFactory;
}
// create default factory
Assert.isTrue(signature.endsWith("<init>()"));
return new ObservableFactoryInfo(className);
}
// new TreeBeanAdvisor(Class, String, String, String)
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.TreeBeanAdvisor")) {
Assert.isTrue(signature.endsWith("<init>(java.lang.Class,java.lang.String,java.lang.String,java.lang.String)"));
// create advisor
TreeBeanAdvisorInfo advisorInfo = new TreeBeanAdvisorInfo();
// prepare element type
advisorInfo.setElementType(CoreUtils.evaluate(Class.class, editor, arguments[0]));
// prepare parent property
advisorInfo.setParentProperty(CoreUtils.evaluate(String.class, editor, arguments[1]));
// prepare children property
advisorInfo.setChildrenProperty(CoreUtils.evaluate(String.class, editor, arguments[2]));
// prepare hasChildren property
advisorInfo.setHasChildrenProperty(CoreUtils.evaluate(String.class, editor, arguments[3]));
//
return advisorInfo;
}
// new TreeStructureAdvisor()
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.databinding.viewers.TreeStructureAdvisor")) {
Assert.isTrue(signature.endsWith("<init>()"));
return new TreeStructureAdvisorInfo(className);
}
// new ObservableListContentProvider()
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.databinding.viewers.ObservableListContentProvider")) {
return new ObservableListContentProviderInfo(className);
}
// new ObservableSetContentProvider()
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.databinding.viewers.ObservableSetContentProvider")) {
return new ObservableSetContentProviderInfo(className);
}
// new ObservableListTreeContentProvider(IObservableFactory, TreeStructureAdvisor)
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider")) {
Assert.isTrue(signature.endsWith("<init>(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory,org.eclipse.jface.databinding.viewers.TreeStructureAdvisor)"));
// prepare factory
ObservableFactoryInfo observableFactory = (ObservableFactoryInfo) resolver.getModel(arguments[0]);
if (observableFactory == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.ViewerInputParser_objectFactoryArgumentNotFound, arguments[0]), new Throwable());
return null;
}
// prepare advisor
TreeStructureAdvisorInfo advisorInfo = (TreeStructureAdvisorInfo) resolver.getModel(arguments[1]);
if (advisorInfo == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.ViewerInputParser_advisorArgumentNotFound, arguments[1]), new Throwable());
return null;
}
// create content provider
return new ObservableListTreeContentProviderInfo(className, observableFactory, advisorInfo);
}
// new ObservableSetTreeContentProvider(IObservableFactory, TreeStructureAdvisor)
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.databinding.viewers.ObservableSetTreeContentProvider")) {
Assert.isTrue(signature.endsWith("<init>(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory,org.eclipse.jface.databinding.viewers.TreeStructureAdvisor)"));
// prepare factory
ObservableFactoryInfo observableFactory = (ObservableFactoryInfo) resolver.getModel(arguments[0]);
if (observableFactory == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.ViewerInputParser_objectFactoryArgumentNotFound, arguments[0]), new Throwable());
return null;
}
// prepare advisor
TreeStructureAdvisorInfo advisorInfo = (TreeStructureAdvisorInfo) resolver.getModel(arguments[1]);
if (advisorInfo == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.ViewerInputParser_advisorArgumentNotFound, arguments[1]), new Throwable());
return null;
}
// create content provider
return new ObservableSetTreeContentProviderInfo(className, observableFactory, advisorInfo);
}
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider") || AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.databinding.viewers.ObservableMapCellLabelProvider")) {
Assert.isTrue(signature.endsWith("<init>(org.eclipse.core.databinding.observable.map.IObservableMap[])") || signature.endsWith("<init>(org.eclipse.core.databinding.observable.map.IObservableMap)"));
// prepare maps observable
MapsBeanObservableInfo mapsObservable = (MapsBeanObservableInfo) resolver.getModel(arguments[0]);
if (mapsObservable == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.ViewerInputParser_argumentNotFound, arguments[0]), new Throwable());
return null;
}
// create label provider
return new ObservableMapLabelProviderInfo(className, mapsObservable);
}
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.TreeObservableLabelProvider")) {
Assert.isTrue(signature.endsWith("<init>(org.eclipse.core.databinding.observable.set.IObservableSet,java.lang.Class,java.lang.String,java.lang.String)"));
// prepare allElements observable
KnownElementsObservableInfo allElementsObservable = (KnownElementsObservableInfo) resolver.getModel(arguments[0]);
if (allElementsObservable == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.ViewerInputParser_argumentNotFound, arguments[0]), new Throwable());
return null;
}
// create label provider
TreeObservableLabelProviderInfo labelProvider = new TreeObservableLabelProviderInfo(className, allElementsObservable);
// prepare element type
labelProvider.setElementType(CoreUtils.evaluate(Class.class, editor, arguments[1]));
// prepare text property
labelProvider.setTextProperty(CoreUtils.evaluate(String.class, editor, arguments[2]));
// prepare image property
labelProvider.setImageProperty(CoreUtils.evaluate(String.class, editor, arguments[3]));
//
return labelProvider;
}
// default label provider
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.viewers.IBaseLabelProvider")) {
Assert.isTrue(signature.endsWith("<init>()"));
return new LabelProviderInfo(className);
}
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.jface.viewers.CellEditor")) {
return new CellEditorInfo(editor, creation, className);
}
//
return null;
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansListObservableFactoryInfo in project windowbuilder by eclipse.
the class ViewerObservableTest method test_Viewer_TreeInput_List_InputCollection.
// //////////////////////////////////////////////////////////////////////////
//
// Tree Input
//
// //////////////////////////////////////////////////////////////////////////
public void test_Viewer_TreeInput_List_InputCollection() throws Exception {
DataBindingsCodeUtils.ensureDesignerResources(m_testProject.getJavaProject());
//
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public String getName() {", " return null;", " }", " public java.util.List getBeans() {", " return null;", " }", " public TestBean getParent() {", " return null;", " }", " public boolean getHasChildren() {", " return false;", " }", " public org.eclipse.swt.graphics.Image getImage() {", " return null;", " }", "}"));
waitForAutoBuild();
//
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "import org.eclipse.wb.rcp.databinding.BeansListObservableFactory;", "import org.eclipse.wb.rcp.databinding.TreeBeanAdvisor;", "import org.eclipse.wb.rcp.databinding.TreeObservableLabelProvider;", "public class Test {", " private DataBindingContext m_bindingContext;", " protected Shell m_shell;", " private TreeViewer m_viewer;", " private java.util.List m_beans;", " 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 TreeViewer(m_shell, SWT.BORDER);", " m_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " DataBindingContext bindingContext = new DataBindingContext();", " //", " BeansListObservableFactory treeViewerFactoryList = new BeansListObservableFactory(TestBean.class, \"beans\");", " TreeBeanAdvisor treeViewerAdvisor = new TreeBeanAdvisor(TestBean.class, \"parent\", \"beans\", \"hasChildren\");", " ObservableListTreeContentProvider treeViewerContentProviderList = new ObservableListTreeContentProvider(treeViewerFactoryList, treeViewerAdvisor);", " m_viewer.setContentProvider(treeViewerContentProviderList);", " //", " m_viewer.setLabelProvider(new TreeObservableLabelProvider(treeViewerContentProviderList.getKnownElements(), TestBean.class, \"name\", \"image\"));", " //", " WritableList beansWritableList = new WritableList(m_beans, TestBean.class);", " m_viewer.setInput(beansWritableList);", " //", " return bindingContext;", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
//
IObserveInfo shellObserve = provider.getObserves(ObserveType.WIDGETS).get(0);
IObserveInfo viewerObserve = shellObserve.getChildren(ChildrenContext.ChildrenForMasterTable).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0);
IObserveInfo viewerInputProperty = viewerObserve.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(4);
//
IObserveInfo beanObserve = provider.getObserves(ObserveType.BEANS).get(3);
IObserveInfo beanInputCollectionProperty = beanObserve.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(0);
//
List<IBindingInfo> bindings = provider.getBindings();
assertEquals(1, bindings.size());
assertInstanceOf(TreeViewerInputBindingInfo.class, bindings.get(0));
//
TreeViewerInputBindingInfo binding = (TreeViewerInputBindingInfo) bindings.get(0);
//
assertSame(viewerObserve, binding.getViewer());
assertSame(viewerObserve, binding.getTarget());
assertSame(viewerInputProperty, binding.getTargetProperty());
//
assertSame(beanObserve, binding.getModel());
assertSame(beanInputCollectionProperty, binding.getModelProperty());
//
assertNotNull(binding.getInputObservable());
assertInstanceOf(WritableListBeanObservableInfo.class, binding.getInputObservable());
//
ObservableInfo inputObservable = binding.getInputObservable();
assertSame(beanObserve, inputObservable.getBindableObject());
assertSame(beanInputCollectionProperty, inputObservable.getBindableProperty());
//
assertEquals("WritableList(m_beans, TestBean.class)", inputObservable.getPresentationText());
//
assertNull(binding.getVariableIdentifier());
assertEquals("m_viewer.input(ObservableListTreeContentProvider[parent, beans, hasChildren], TreeObservableLabelProvider[name, image])", binding.getPresentationText());
//
assertNotNull(binding.getElementType());
assertEquals("test.TestBean", binding.getElementType().getName());
//
assertNotNull(binding.getLabelProvider());
assertInstanceOf(TreeObservableLabelProviderInfo.class, binding.getLabelProvider());
//
TreeObservableLabelProviderInfo labelProvider = (TreeObservableLabelProviderInfo) binding.getLabelProvider();
assertEquals("org.eclipse.wb.rcp.databinding.TreeObservableLabelProvider", labelProvider.getClassName());
assertSame(binding.getElementType(), ReflectionUtils.getFieldObject(labelProvider, "m_elementType"));
assertEquals("name", labelProvider.getTextProperty());
assertEquals("image", labelProvider.getImageProperty());
//
assertInstanceOf(KnownElementsObservableInfo.class, ReflectionUtils.getFieldObject(labelProvider, "m_allElementsObservable"));
//
KnownElementsObservableInfo knownElementsObservableInfo = (KnownElementsObservableInfo) ReflectionUtils.getFieldObject(labelProvider, "m_allElementsObservable");
assertNull(knownElementsObservableInfo.getBindableObject());
assertNull(knownElementsObservableInfo.getBindableProperty());
//
assertNotNull(knownElementsObservableInfo.getParent());
assertSame(knownElementsObservableInfo.getParent(), binding.getContentProvider());
//
assertInstanceOf(ObservableListTreeContentProviderInfo.class, binding.getContentProvider());
//
ObservableListTreeContentProviderInfo contentProvider = (ObservableListTreeContentProviderInfo) binding.getContentProvider();
assertEquals("org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider", contentProvider.getClassName());
assertEquals("ObservableListTreeContentProvider[parent, beans, hasChildren]", contentProvider.getPresentationText());
//
assertNotNull(contentProvider.getFactoryInfo());
assertInstanceOf(BeansListObservableFactoryInfo.class, contentProvider.getFactoryInfo());
//
BeansListObservableFactoryInfo factory = (BeansListObservableFactoryInfo) contentProvider.getFactoryInfo();
assertSame(factory.getElementType(), binding.getElementType());
assertEquals("beans", ReflectionUtils.getFieldString(factory, "m_propertyName"));
//
assertNotNull(contentProvider.getAdvisorInfo());
assertInstanceOf(TreeBeanAdvisorInfo.class, contentProvider.getAdvisorInfo());
//
TreeBeanAdvisorInfo advisor = (TreeBeanAdvisorInfo) contentProvider.getAdvisorInfo();
assertEquals("org.eclipse.wb.rcp.databinding.TreeBeanAdvisor", advisor.getClassName());
assertEquals("parent", advisor.getParentProperty());
assertEquals("beans", advisor.getChildrenProperty());
assertEquals("hasChildren", advisor.getHasChildrenProperty());
}
Aggregations