use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo in project windowbuilder by eclipse.
the class BeansObserveTypeContainer method createList.
/**
* create {@link ListBeanObservableInfo}.
*/
AstObjectInfo createList(AstEditor editor, Expression[] arguments, int startIndex) throws Exception {
// prepare object
BeanBindableInfo bindableObject = getBindableObject(arguments[startIndex]);
if (bindableObject == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.BeansObserveTypeContainer_argumentNotFound, arguments[startIndex]), new Throwable());
return null;
}
// prepare property
BeanPropertyBindableInfo bindableProperty = getBindableProperty(bindableObject, editor, arguments[startIndex + 1]);
// create observable
ListBeanObservableInfo observable = new ListBeanObservableInfo(bindableObject, bindableProperty);
observable.setCodeSupport(new BeanObservableListCodeSupport());
return observable;
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo in project windowbuilder by eclipse.
the class TreeInputElementUiContentProvider method createJFaceProviders.
/**
* Fill JFace page.
*/
private List<IUiContentProvider> createJFaceProviders() {
List<IUiContentProvider> providers = Lists.newArrayList();
//
if (m_binding.isDesignerMode()) {
// create fake objects
// create factory
ObservableFactoryInfo factory = new ObservableFactoryInfo("");
m_defaultObjects.add(factory);
factory.createContentProviders(providers, m_provider);
// create advisor
TreeStructureAdvisorInfo advisor = new TreeStructureAdvisorInfo("");
m_defaultObjects.add(advisor);
advisor.createContentProviders(providers, m_provider);
// content provider always exist
m_binding.getContentProvider().createContentProviders(providers, m_provider, false);
// create label provider
LabelProviderInfo labelProvider = new LabelProviderInfo("");
m_defaultObjects.add(labelProvider);
labelProvider.createContentProviders(providers, m_provider, false);
} else {
// add life objects
createDefaultProviders(providers, false);
}
//
final ObservableInfo inputObservable = m_binding.getInputObservable();
if (inputObservable instanceof ListBeanObservableInfo || inputObservable instanceof SetBeanObservableInfo || inputObservable instanceof BeanFieldInputObservableInfo) {
final ChooseClassUiContentProvider contentProviderJFaceEditor = (ChooseClassUiContentProvider) providers.get(0);
//
try {
String factoryValue = inputObservable.getBindableProperty().getReference() + ", " + ClassUtils.getShortClassName(inputObservable.getBindableObject().getObjectType()) + ".class)";
//
if (inputObservable instanceof ListBeanObservableInfo) {
factoryValue = "listFactory(" + factoryValue;
contentProviderJFaceEditor.getConfiguration().addDefaultStart(factoryValue);
contentProviderJFaceEditor.addClassToCombo(factoryValue);
} else if (inputObservable instanceof SetBeanObservableInfo) {
factoryValue = "setFactory(" + factoryValue;
contentProviderJFaceEditor.getConfiguration().addDefaultStart(factoryValue);
contentProviderJFaceEditor.addClassToCombo(factoryValue);
}
} catch (Throwable e) {
}
//
new ChooseClassRouter(contentProviderJFaceEditor, new Runnable() {
@Override
public void run() {
String className = contentProviderJFaceEditor.getClassName();
if (className.startsWith("listFactory") || className.startsWith("setFactory")) {
m_elementTypeJFaceUIProvider.setClassName(CoreUtils.getClassName(inputObservable.getBindableObject().getObjectType()));
}
}
});
}
//
m_labelProviderJFaceEditor = (ChooseClassUiContentProvider) providers.get(providers.size() - 1);
new ChooseClassRouter(m_labelProviderJFaceEditor, new Runnable() {
@Override
public void run() {
m_elementTypeJFaceUIProvider.calculateFinish();
}
});
//
providers.add(m_elementTypeJFaceUIProvider);
return providers;
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo 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.beans.observables.ListBeanObservableInfo in project windowbuilder by eclipse.
the class BeanObservableTest method test_WritableList.
private void test_WritableList(String line) throws Exception {
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public java.util.List getNames() {", " return null;", " }", "}"));
waitForAutoBuild();
//
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", " protected Shell m_shell;", " private DataBindingContext m_bindingContext;", " private TestBean m_bean0;", " private java.util.ArrayList m_list;", " 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_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " IObservableList observeList = BeansObservables.observeList(Realm.getDefault(), m_bean0, \"names\", java.lang.String.class);", line, " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindList(observeList, writableList, null, null);", " return bindingContext;", " }", " public TestBean getBean1() {", " return null;", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IBindingInfo> bindings = provider.getBindings();
//
assertNotNull(bindings);
assertEquals(1, bindings.size());
//
BindingInfo binding = (BindingInfo) bindings.get(0);
//
assertInstanceOf(ListBeanObservableInfo.class, binding.getTargetObservable());
ListBeanObservableInfo targetObservable = (ListBeanObservableInfo) binding.getTargetObservable();
//
assertEquals("observeList", targetObservable.getVariableIdentifier());
//
BeanBindableTest.assertBindable(FieldBeanBindableInfo.class, null, true, "m_bean0 - TestBean|m_bean0|test.TestBean", targetObservable.getBindableObject());
BeanBindableTest.assertBindable(BeanPropertyDescriptorBindableInfo.class, null, true, "names|\"names\"|java.util.List", targetObservable.getBindableProperty());
//
assertInstanceOf(WritableListBeanObservableInfo.class, binding.getModelObservable());
WritableListBeanObservableInfo modelObservable = (WritableListBeanObservableInfo) binding.getModelObservable();
//
assertEquals("writableList", modelObservable.getVariableIdentifier());
assertEquals("WritableList(m_list, String.class)", modelObservable.getPresentationText());
assertNotNull(modelObservable.getElementType());
assertSame(String.class, modelObservable.getElementType());
//
BeanBindableTest.assertBindable(FieldBeanBindableInfo.class, null, true, "m_list - ArrayList|m_list|java.util.ArrayList", modelObservable.getBindableObject());
BeanBindableTest.assertBindable(CollectionPropertyBindableInfo.class, null, false, "Collection as WritableList/Properties.selfList()|m_list|java.util.ArrayList", modelObservable.getBindableProperty());
//
modelObservable.setElementType(null);
assertEquals("WritableList(m_list, ?????.class)", modelObservable.getPresentationText());
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo in project windowbuilder by eclipse.
the class CodeGenerationTest method test_BeanObservebleInfo.
public void test_BeanObservebleInfo() throws Exception {
CompositeInfo shell = parseComposite("public class Test {", " private String m_bean;", " protected Shell m_shell;", " 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();", " }", "}");
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IObserveInfo> observes = provider.getObserves(ObserveType.BEANS);
//
BeanBindableInfo bindableObject = (BeanBindableInfo) observes.get(0);
BeanPropertyBindableInfo bindableProperty = (BeanPropertyBindableInfo) bindableObject.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(0);
//
assertObservableInfo(new ListBeanObservableInfo(bindableObject, bindableProperty), new BeanObservableListCodeSupport(), "observeList", "org.eclipse.core.databinding.observable.list.IObservableList observeList = org.eclipse.core.databinding.beans.PojoObservables.observeList(org.eclipse.core.databinding.observable.Realm.getDefault(), m_bean, \"bytes\");", "org.eclipse.core.databinding.observable.list.IObservableList beanBytesObserveList = org.eclipse.core.databinding.beans.PojoObservables.observeList(org.eclipse.core.databinding.observable.Realm.getDefault(), m_bean, \"bytes\");");
//
assertObservableInfo(new SetBeanObservableInfo(bindableObject, bindableProperty), new BeanObservableSetCodeSupport(), "observeSet", "org.eclipse.core.databinding.observable.set.IObservableSet observeSet = org.eclipse.core.databinding.beans.PojoObservables.observeSet(org.eclipse.core.databinding.observable.Realm.getDefault(), m_bean, \"bytes\");", "org.eclipse.core.databinding.observable.set.IObservableSet beanBytesObserveSet = org.eclipse.core.databinding.beans.PojoObservables.observeSet(org.eclipse.core.databinding.observable.Realm.getDefault(), m_bean, \"bytes\");");
//
assertObservableInfo(new ValueBeanObservableInfo(bindableObject, bindableProperty), new BeanObservableValueCodeSupport(), "observeValue", "org.eclipse.core.databinding.observable.value.IObservableValue observeValue = org.eclipse.core.databinding.beans.PojoObservables.observeValue(m_bean, \"bytes\");", "org.eclipse.core.databinding.observable.value.IObservableValue beanBytesObserveValue = org.eclipse.core.databinding.beans.PojoObservables.observeValue(m_bean, \"bytes\");");
}
Aggregations