use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo in project windowbuilder by eclipse.
the class BeansObserveTypeContainer method createSet.
/**
* Create {@link SetBeanObservableInfo}.
*/
AstObjectInfo createSet(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
SetBeanObservableInfo observable = new SetBeanObservableInfo(bindableObject, bindableProperty);
observable.setCodeSupport(new BeanObservableSetCodeSupport());
return observable;
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo 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.SetBeanObservableInfo 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.SetBeanObservableInfo in project windowbuilder by eclipse.
the class BeanObservableTest method observeSet.
private void observeSet(String line0, String line1) throws Exception {
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public java.util.Set 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;", " 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() {", line0, line1, " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindSet(observeSet0, observeSet1, 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(SetBeanObservableInfo.class, binding.getTargetObservable());
SetBeanObservableInfo targetObservable = (SetBeanObservableInfo) binding.getTargetObservable();
//
assertEquals("observeSet0", targetObservable.getVariableIdentifier());
assertEquals("m_bean0.names(Set)", targetObservable.getPresentationText());
//
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.Set", targetObservable.getBindableProperty());
//
assertInstanceOf(SetBeanObservableInfo.class, binding.getModelObservable());
SetBeanObservableInfo modelObservable = (SetBeanObservableInfo) binding.getModelObservable();
//
assertEquals("observeSet1", modelObservable.getVariableIdentifier());
assertEquals("getBean1().names(Set)", modelObservable.getPresentationText());
//
BeanBindableTest.assertBindable(MethodBeanBindableInfo.class, null, true, "getBean1()|getBean1()|test.TestBean", modelObservable.getBindableObject());
BeanBindableTest.assertBindable(BeanPropertyDescriptorBindableInfo.class, null, true, "names|\"names\"|java.util.Set", modelObservable.getBindableProperty());
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo in project windowbuilder by eclipse.
the class BeanObservableTest method test_WritableSet.
private void test_WritableSet(String line) throws Exception {
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public java.util.Set 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.HashSet m_set;", " 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() {", " IObservableSet observeSet = BeansObservables.observeSet(Realm.getDefault(), m_bean0, \"names\", java.lang.String.class);", line, " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindSet(observeSet, writableSet, 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(SetBeanObservableInfo.class, binding.getTargetObservable());
SetBeanObservableInfo targetObservable = (SetBeanObservableInfo) binding.getTargetObservable();
//
assertEquals("observeSet", 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.Set", targetObservable.getBindableProperty());
//
assertInstanceOf(WritableSetBeanObservableInfo.class, binding.getModelObservable());
WritableSetBeanObservableInfo modelObservable = (WritableSetBeanObservableInfo) binding.getModelObservable();
//
assertEquals("writableSet", modelObservable.getVariableIdentifier());
assertEquals("WritableSet(m_set, String.class)", modelObservable.getPresentationText());
assertNotNull(modelObservable.getElementType());
assertSame(String.class, modelObservable.getElementType());
//
BeanBindableTest.assertBindable(FieldBeanBindableInfo.class, null, true, "m_set - HashSet|m_set|java.util.HashSet", modelObservable.getBindableObject());
BeanBindableTest.assertBindable(CollectionPropertyBindableInfo.class, null, false, "Collection as WritableSet/Properties.selfSet()|m_set|java.util.HashSet", modelObservable.getBindableProperty());
//
modelObservable.setElementType(null);
assertEquals("WritableSet(m_set, ?????.class)", modelObservable.getPresentationText());
}
Aggregations