use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo in project windowbuilder by eclipse.
the class EmfObserveTypeContainer method parseExpression.
@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;
}
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.core.databinding.observable.masterdetail.IObservableFactory")) {
String className = AstNodeUtils.getFullyQualifiedName(binding, false);
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.EMFBeansListObservableFactory")) {
return createObserveFactory(editor, signature, arguments, className, false);
}
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.EMFEditBeansListObservableFactory")) {
return createObserveFactory(editor, signature, arguments, className, true);
}
}
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.EMFTreeBeanAdvisor")) {
Assert.isTrue(signature.endsWith("<init>(org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EStructuralFeature)"));
// create advisor
EmfTreeBeanAdvisorInfo advisorInfo = new EmfTreeBeanAdvisorInfo(m_propertiesSupport);
// prepare parent property
advisorInfo.setEMFParentProperty(getArgumentReference(editor, arguments[0]));
// prepare children property
advisorInfo.setEMFChildrenProperty(getArgumentReference(editor, arguments[1]));
// prepare hasChildren property
advisorInfo.setEMFHasChildrenProperty(getArgumentReference(editor, arguments[2]));
//
return advisorInfo;
}
//
if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.EMFTreeObservableLabelProvider")) {
Assert.isTrue(signature.endsWith("<init>(org.eclipse.core.databinding.observable.set.IObservableSet,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EStructuralFeature)"));
// prepare allElements observable
KnownElementsObservableInfo allElementsObservable = (KnownElementsObservableInfo) resolver.getModel(arguments[0]);
if (allElementsObservable == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.EmfObserveTypeContainer_argumentNotFound, arguments[0]), new Throwable());
return null;
}
// create label provider
EmfTreeObservableLabelProviderInfo labelProvider = new EmfTreeObservableLabelProviderInfo(AstNodeUtils.getFullyQualifiedName(binding, false), allElementsObservable, m_propertiesSupport);
// prepare text property
labelProvider.setEMFTextProperty(getArgumentReference(editor, arguments[1]));
// prepare image property
labelProvider.setEMFImageProperty(getArgumentReference(editor, arguments[2]));
//
return labelProvider;
}
return null;
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo in project windowbuilder by eclipse.
the class MapsBeanObservableInfo method addSourceCode.
// //////////////////////////////////////////////////////////////////////////
//
// Code generation
//
// //////////////////////////////////////////////////////////////////////////
@Override
public void addSourceCode(List<String> lines, CodeGenerationSupport generationSupport) throws Exception {
// prepare variable
if (getVariableIdentifier() == null) {
if (m_properties.length == 1) {
setVariableIdentifier(generationSupport.generateLocalName("observeMap"));
} else {
setVariableIdentifier(generationSupport.generateLocalName("observeMaps"));
}
}
//
KnownElementsObservableInfo domainObservable = (KnownElementsObservableInfo) m_domainObservable;
//
if (m_properties.length == 1) {
String observeMethod = isPojoBean(m_elementType) ? " = " + DataBindingsCodeUtils.getPojoObservablesClass() + ".observeMap(" : " = org.eclipse.core.databinding.beans.BeansObservables.observeMap(";
// add code
lines.add("org.eclipse.core.databinding.observable.map.IObservableMap " + getVariableIdentifier() + observeMethod + domainObservable.getSourceCode() + ", " + CoreUtils.getClassName(m_elementType) + ".class, \"" + m_properties[0] + "\");");
} else {
String observeMethod = isPojoBean(m_elementType) ? " = " + DataBindingsCodeUtils.getPojoObservablesClass() + ".observeMaps(" : " = org.eclipse.core.databinding.beans.BeansObservables.observeMaps(";
// add code
lines.add("org.eclipse.core.databinding.observable.map.IObservableMap[] " + getVariableIdentifier() + observeMethod + domainObservable.getSourceCode() + ", " + CoreUtils.getClassName(m_elementType) + ".class, new java.lang.String[]{\"" + StringUtils.join(m_properties, "\", \"") + "\"});");
}
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo 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.KnownElementsObservableInfo in project windowbuilder by eclipse.
the class MapsEmfObservableInfo method addSourceCode.
// //////////////////////////////////////////////////////////////////////////
//
// Code generation
//
// //////////////////////////////////////////////////////////////////////////
@Override
public void addSourceCode(List<String> lines, CodeGenerationSupport generationSupport) throws Exception {
// prepare variable
if (getVariableIdentifier() == null) {
setVariableIdentifier(generationSupport.generateLocalName("observeMaps"));
}
// prepare properties
StringBuffer properties = new StringBuffer();
for (Iterator<PropertyInfo> I = m_emfProperties.iterator(); I.hasNext(); ) {
PropertyInfo property = I.next();
properties.append(property.reference);
if (I.hasNext()) {
properties.append(", ");
}
}
// add code
KnownElementsObservableInfo domainObservable = (KnownElementsObservableInfo) getDomainObservable();
//
lines.add("org.eclipse.core.databinding.observable.map.IObservableMap[] " + getVariableIdentifier() + m_propertiesSupport.getEMFObservablesCode("observeMaps(") + domainObservable.getSourceCode() + ", new org.eclipse.emf.ecore.EStructuralFeature[]{" + properties.toString() + "});");
}
use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo in project windowbuilder by eclipse.
the class ViewerObservableTest method test_Viewer_Input_List_InputCollection.
public void test_Viewer_Input_List_InputCollection() throws Exception {
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public String getName() {", " return null;", " }", " public java.util.List getBeans() {", " return null;", " }", "}"));
waitForAutoBuild();
//
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", " private DataBindingContext m_bindingContext;", " protected Shell m_shell;", " private TableViewer 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 TableViewer(m_shell, SWT.BORDER);", " m_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " DataBindingContext bindingContext = new DataBindingContext();", " //", " ObservableListContentProvider viewerContentProvider = new ObservableListContentProvider();", " m_viewer.setContentProvider(viewerContentProvider);", " IObservableMap[] viewerLabelProviderMaps = BeansObservables.observeMaps(viewerContentProvider.getKnownElements(), TestBean.class, new String[]{\"name\"});", " m_viewer.setLabelProvider(new ObservableMapLabelProvider(viewerLabelProviderMaps));", " //", " m_viewer.setInput(new WritableList(m_beans, TestBean.class));", " //", " 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(ViewerInputBindingInfo.class, bindings.get(0));
//
ViewerInputBindingInfo binding = (ViewerInputBindingInfo) 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(ObservableListContentProvider, ObservableMaps[name])", binding.getPresentationText());
//
assertNotNull(binding.getElementType());
assertEquals("test.TestBean", binding.getElementType().getName());
//
ObservableMapLabelProviderInfo labelProvider = binding.getLabelProvider();
assertNotNull(labelProvider);
assertEquals("org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider", labelProvider.getClassName());
assertEquals("ObservableMaps[name]", labelProvider.getPresentationText());
assertNull(labelProvider.getVariableIdentifier());
//
MapsBeanObservableInfo mapsObservable = labelProvider.getMapsObservable();
assertNotNull(mapsObservable);
assertNotNull(mapsObservable.getElementType());
assertEquals("test.TestBean", mapsObservable.getElementType().getName());
assertNull(mapsObservable.getBindableObject());
assertNull(mapsObservable.getBindableProperty());
//
String[] properties = mapsObservable.getProperties();
assertNotNull(properties);
assertEquals(1, properties.length);
assertEquals("name", properties[0]);
//
assertNotNull(mapsObservable.getDomainObservable());
assertInstanceOf(KnownElementsObservableInfo.class, mapsObservable.getDomainObservable());
//
KnownElementsObservableInfo knownElementsObservableInfo = (KnownElementsObservableInfo) mapsObservable.getDomainObservable();
assertNull(knownElementsObservableInfo.getBindableObject());
assertNull(knownElementsObservableInfo.getBindableProperty());
//
assertNotNull(knownElementsObservableInfo.getParent());
assertSame(knownElementsObservableInfo.getParent(), ReflectionUtils.getFieldObject(binding, "m_contentProvider"));
assertInstanceOf(ObservableListContentProviderInfo.class, knownElementsObservableInfo.getParent());
//
ObservableListContentProviderInfo contentProvider = (ObservableListContentProviderInfo) knownElementsObservableInfo.getParent();
assertEquals("org.eclipse.jface.databinding.viewers.ObservableListContentProvider", contentProvider.getClassName());
}
Aggregations