use of org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo in project windowbuilder by eclipse.
the class ControllerSupport method moveBean.
private static void moveBean(DatabindingsProvider provider, IObserveInfo observe, AstEditor controllerEditor, TypeDeclaration controllerRootNode) throws Exception {
if (observe instanceof FieldBeanBindableInfo) {
//
FieldBeanBindableInfo fieldBindable = (FieldBeanBindableInfo) observe;
VariableDeclarationFragment fragment = fieldBindable.getFragment();
//
if (fragment != null) {
FieldDeclaration fieldDeclaration = AstNodeUtils.getEnclosingFieldDeclaration(fragment);
String modifier = Modifier.ModifierKeyword.fromFlagValue(fieldDeclaration.getModifiers()).toString();
//
controllerEditor.addFieldDeclaration(modifier + " " + CoreUtils.getClassName(fieldBindable.getObjectType()) + " " + fragment.getName().getIdentifier() + ";", new BodyDeclarationTarget(controllerRootNode, true));
}
} else if (observe instanceof MethodBeanBindableInfo) {
IObserveInfo parentObserve = observe.getParent();
if (parentObserve == null) {
MethodBeanBindableInfo methodBindable = (MethodBeanBindableInfo) observe;
methodBindable.setReferenceProvider(new StringReferenceProvider(provider.getControllerViewerField() + "." + methodBindable.getReference()));
} else {
moveBean(provider, parentObserve, controllerEditor, controllerRootNode);
}
} else {
GlobalFactoryHelper.moveBean(observe, controllerEditor, controllerRootNode);
}
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo in project windowbuilder by eclipse.
the class BeansObserveTypeContainer method createObservables.
@Override
public void createObservables(JavaInfo root, final IModelResolver resolver, AstEditor editor, TypeDeclaration rootNode) throws Exception {
m_rootJavaInfo = root;
m_observables = Lists.newArrayList();
// handle fields
ClassLoader classLoader = EditorState.get(m_rootJavaInfo.getEditor()).getEditorLoader();
BeanSupport beanSupport = new BeanSupport(classLoader, resolver);
beanSupport.setProvider(m_provider);
//
for (VariableDeclarationFragment fragment : CoreUtils.getFieldFragments(rootNode)) {
try {
// prepare bean class
Type type = CoreUtils.getType(fragment, true);
Class<?> beanClass = loadClass(AstNodeUtils.getFullyQualifiedName(type, true));
// prepare association widget
JavaInfo widget = getJavaInfoRepresentedBy(fragment.getName().getIdentifier());
//
m_observables.add(new FieldBeanBindableInfo(beanSupport, fragment, beanClass, widget));
} catch (ClassNotFoundException e) {
AbstractParser.addError(editor, "ClassNotFoundException: " + fragment, new Throwable());
} catch (Throwable e) {
throw ReflectionUtils.propagate(e);
}
}
// handle all Composite declared as local variable
for (JavaInfo javaInfo : getLocalComposites()) {
// prepare bean class
Class<?> componentClass = javaInfo.getDescription().getComponentClass();
// prepare reference provider
IReferenceProvider javaReferenceProvider = new JavaInfoReferenceProvider(javaInfo, m_provider);
FragmentReferenceProvider referenceProvider = new FragmentReferenceProvider(javaReferenceProvider);
//
m_observables.add(new FieldBeanBindableInfo(beanSupport, null, componentClass, referenceProvider, javaInfo));
}
// prepare super class
Class<?> superClass = Object.class;
if (rootNode.getSuperclassType() != null) {
String className = AstNodeUtils.getFullyQualifiedName(rootNode.getSuperclassType(), true);
try {
superClass = loadClass(className);
} catch (ClassNotFoundException e) {
AbstractParser.addError(editor, "ClassNotFoundException: " + className, new Throwable());
superClass = Object.class;
}
}
// handle methods from super class
Set<String> methodNames = Sets.newHashSet();
//
BeanInfo beanInfo = Introspector.getBeanInfo(superClass);
for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
if (BeanSupport.isGetter(descriptor)) {
String methodName = descriptor.getReadMethod().getName();
if (!DataBindingsRootInfo.INIT_DATA_BINDINGS_METHOD_NAME.equals(methodName)) {
methodNames.add(methodName);
m_observables.add(new MethodBeanBindableInfo(beanSupport, null, descriptor.getPropertyType(), methodName + "()"));
}
}
}
// handle local methods
for (MethodDeclaration method : rootNode.getMethods()) {
String methodName = method.getName().getIdentifier();
if (!methodNames.contains(methodName) && !DataBindingsRootInfo.INIT_DATA_BINDINGS_METHOD_NAME.equals(methodName) && methodName.startsWith("get")) {
IMethodBinding binding = AstNodeUtils.getMethodBinding(method);
ITypeBinding returnType = binding == null ? null : binding.getReturnType();
//
if (CoreUtils.isIncludeTypeBinding(returnType)) {
String className = AstNodeUtils.getFullyQualifiedName(returnType, true);
try {
Class<?> propertyClass = loadClass(className);
//
m_observables.add(new MethodBeanBindableInfo(beanSupport, null, propertyClass, methodName + "()"));
} catch (ClassNotFoundException e) {
AbstractParser.addError(editor, "ClassNotFoundException: " + className, new Throwable());
}
}
}
}
// handle initDataBindings() local variables
for (VariableDeclarationFragment fragment : CoreUtils.getLocalFragments(rootNode, DataBindingsRootInfo.INIT_DATA_BINDINGS_METHOD_NAME)) {
try {
// prepare bean class
ITypeBinding typeBinding = CoreUtils.getType(fragment, true);
Class<?> beanClass = loadClass(AstNodeUtils.getFullyQualifiedName(typeBinding, true));
m_observables.add(new LocalVariableBindableInfo(beanSupport, fragment, beanClass));
} catch (ClassNotFoundException e) {
AbstractParser.addError(editor, "ClassNotFoundException: " + fragment, new Throwable());
} catch (Throwable e) {
throw ReflectionUtils.propagate(e);
}
}
}
Aggregations