use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableListTreeContentProviderInfo 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.ObservableListTreeContentProviderInfo in project windowbuilder by eclipse.
the class TreeInputElementUiContentProvider method saveJFaceObjects.
private void saveJFaceObjects() throws Exception {
ObservableCollectionTreeContentProviderInfo contentProvider = m_binding.getContentProvider();
ObservableFactoryInfo factoryInfo = contentProvider.getFactoryInfo();
if (factoryInfo instanceof AbstractFactoryInfo) {
AbstractFactoryInfo aFactoryInfo = (AbstractFactoryInfo) factoryInfo;
//
if (aFactoryInfo.isCancel()) {
//
ObservableFactoryInfo newFactoryInfo = new ObservableFactoryInfo(aFactoryInfo.getOriginalClassName());
newFactoryInfo.setVariableIdentifier(aFactoryInfo.getVariableIdentifier());
contentProvider.setFactoryInfo(newFactoryInfo);
//
boolean version_1_3 = Activator.getStore().getBoolean(IPreferenceConstants.GENERATE_CODE_FOR_VERSION_1_3);
ObservableInfo inputObservable = m_binding.getInputObservable();
ObservableInfo newInputObservable = null;
if (contentProvider instanceof ObservableListTreeContentProviderInfo) {
newInputObservable = new ListBeanObservableInfo((BeanBindableInfo) inputObservable.getBindableObject(), (BeanPropertyBindableInfo) inputObservable.getBindableProperty());
if (version_1_3) {
newInputObservable.setCodeSupport(new ListPropertyCodeSupport());
} else {
newInputObservable.setCodeSupport(new BeanObservableListCodeSupport());
}
} else {
newInputObservable = new SetBeanObservableInfo((BeanBindableInfo) inputObservable.getBindableObject(), (BeanPropertyBindableInfo) inputObservable.getBindableProperty());
if (version_1_3) {
newInputObservable.setCodeSupport(new SetPropertyCodeSupport());
} else {
newInputObservable.setCodeSupport(new BeanObservableSetCodeSupport());
}
}
newInputObservable.setVariableIdentifier(inputObservable.getVariableIdentifier());
m_binding.setInputObservable(newInputObservable);
}
} else if (factoryInfo.getClassName().startsWith("listFactory(") || factoryInfo.getClassName().startsWith("setFactory(")) {
//
AbstractFactoryInfo newFactoryInfo = null;
//
if (contentProvider instanceof ObservableListTreeContentProviderInfo) {
newFactoryInfo = new BeansObservableListFactoryInfo();
} else {
newFactoryInfo = new BeansObservableSetFactoryInfo();
}
//
ObservableInfo inputObservable = m_binding.getInputObservable();
//
newFactoryInfo.setPropertyName(inputObservable.getBindableProperty().getReference());
newFactoryInfo.setElementType(inputObservable.getBindableObject().getObjectType());
newFactoryInfo.setVariableIdentifier(factoryInfo.getVariableIdentifier());
contentProvider.setFactoryInfo(newFactoryInfo);
//
m_binding.setInputObservable(new BeanFieldInputObservableInfo(inputObservable.getBindableObject(), inputObservable.getBindableProperty()));
}
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableListTreeContentProviderInfo in project windowbuilder by eclipse.
the class ViewerObservableTest method test_Viewer_TreeInput_List_JFace.
public void test_Viewer_TreeInput_List_JFace() 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;", " }", "}"));
waitForAutoBuild();
//
createModelCompilationUnit("test", "TestFactory.java", DatabindingTestUtils.getTestSource("public class TestFactory implements IObservableFactory {", " public IObservable createObservable(Object target) {", " return null;", " }", "}"));
waitForAutoBuild();
//
createModelCompilationUnit("test", "TestAdvisor.java", DatabindingTestUtils.getTestSource("// filler filler filler filler filler", "// filler filler filler filler filler", "public class TestAdvisor extends TreeStructureAdvisor {", "}"));
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();", " //", " TestFactory treeFactory = new TestFactory();", " TestAdvisor treeAdvisor = new TestAdvisor();", " ObservableListTreeContentProvider treeViewerContentProviderList = new ObservableListTreeContentProvider(treeFactory, treeAdvisor);", " m_viewer.setContentProvider(treeViewerContentProviderList);", " //", " m_viewer.setLabelProvider(new LabelProvider());", " //", " 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, LabelProvider)", binding.getPresentationText());
//
assertNotNull(binding.getElementType());
assertEquals("test.TestBean", binding.getElementType().getName());
//
assertNotNull(binding.getLabelProvider());
//
AbstractLabelProviderInfo labelProvider = binding.getLabelProvider();
assertEquals("org.eclipse.jface.viewers.LabelProvider", labelProvider.getClassName());
//
assertInstanceOf(ObservableListTreeContentProviderInfo.class, binding.getContentProvider());
//
ObservableListTreeContentProviderInfo contentProvider = (ObservableListTreeContentProviderInfo) binding.getContentProvider();
assertEquals("org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider", contentProvider.getClassName());
assertEquals("ObservableListTreeContentProvider", contentProvider.getPresentationText());
//
assertNotNull(contentProvider.getFactoryInfo());
//
ObservableFactoryInfo factory = contentProvider.getFactoryInfo();
assertEquals("test.TestFactory", factory.getClassName());
//
assertNotNull(contentProvider.getAdvisorInfo());
//
TreeStructureAdvisorInfo advisor = contentProvider.getAdvisorInfo();
assertEquals("test.TestAdvisor", advisor.getClassName());
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableListTreeContentProviderInfo 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