Search in sources :

Example 1 with MethodBeanBindableInfo

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);
    }
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) BodyDeclarationTarget(org.eclipse.wb.internal.core.utils.ast.BodyDeclarationTarget) FieldBeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.FieldBeanBindableInfo) MethodBeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo) StringReferenceProvider(org.eclipse.wb.internal.core.databinding.model.reference.StringReferenceProvider) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 2 with MethodBeanBindableInfo

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);
        }
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) FieldBeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.FieldBeanBindableInfo) PropertyDescriptor(java.beans.PropertyDescriptor) MethodBeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) IReferenceProvider(org.eclipse.wb.internal.core.databinding.model.reference.IReferenceProvider) BeanInfo(java.beans.BeanInfo) FragmentReferenceProvider(org.eclipse.wb.internal.core.databinding.model.reference.FragmentReferenceProvider) JavaInfoReferenceProvider(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.JavaInfoReferenceProvider) Type(org.eclipse.jdt.core.dom.Type) ObserveType(org.eclipse.wb.internal.core.databinding.ui.ObserveType) BeanSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanSupport) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) JavaInfo(org.eclipse.wb.core.model.JavaInfo) LocalVariableBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.LocalVariableBindableInfo)

Aggregations

VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)2 FieldBeanBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.FieldBeanBindableInfo)2 MethodBeanBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo)2 BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)1 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)1 Type (org.eclipse.jdt.core.dom.Type)1 JavaInfo (org.eclipse.wb.core.model.JavaInfo)1 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)1 FragmentReferenceProvider (org.eclipse.wb.internal.core.databinding.model.reference.FragmentReferenceProvider)1 IReferenceProvider (org.eclipse.wb.internal.core.databinding.model.reference.IReferenceProvider)1 StringReferenceProvider (org.eclipse.wb.internal.core.databinding.model.reference.StringReferenceProvider)1 ObserveType (org.eclipse.wb.internal.core.databinding.ui.ObserveType)1 BodyDeclarationTarget (org.eclipse.wb.internal.core.utils.ast.BodyDeclarationTarget)1 BeanSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanSupport)1 LocalVariableBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.LocalVariableBindableInfo)1 JavaInfoReferenceProvider (org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.JavaInfoReferenceProvider)1