Package com.palantir.ptoss.cinch.core

Examples of com.palantir.ptoss.cinch.core.ObjectFieldMethod


        model1.setSimpleString("string1");
        model2.setSimpleString("string2");
        model.setOtherString("other");
        BindingContext context = new BindingContext(this);
        assertNull(context.findGetter("simpleString"));
        ObjectFieldMethod ofm = context.findGetter("model1.simpleString");
        assertEquals("string1", ofm.getMethod().invoke(ofm.getObject(), (Object[])null));
        ofm = context.findGetter("model2.simpleString");
        assertEquals("string2", ofm.getMethod().invoke(ofm.getObject(), (Object[])null));
        ofm = context.findGetter("otherString");
        assertEquals("other", ofm.getMethod().invoke(ofm.getObject(), (Object[])null));
    }
View Full Code Here


    }

    public void testSetterIndex() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        BindingContext context = new BindingContext(this);
        assertNull(context.findSetter("simpleString"));
        ObjectFieldMethod ofm = context.findSetter("model1.simpleString");
        ofm.getMethod().invoke(ofm.getObject(), new Object[] { "set1" });
        assertEquals("set1", model1.getSimpleString());

        ofm = context.findSetter("model2.simpleString");
        ofm.getMethod().invoke(ofm.getObject(), new Object[] { "set2" });
        assertEquals("set2", model2.getSimpleString());

        ofm = context.findSetter("otherString");
        ofm.getMethod().invoke(ofm.getObject(), new Object[] { "setOther" });
        assertEquals("setOther", model.getOtherString());
    }
View Full Code Here

            final Method setVisibleMethod = field.getType().getMethod("setVisible", boolean.class);
            if (setVisibleMethod == null) {
                throw new BindingException("no setVisible call on VisibleIf field: " + field);
            }
            final Object setVisibleObject = context.getFieldObject(field, Object.class);
            final ObjectFieldMethod getter = context.findGetter(to);
            if (getter == null) {
                throw new BindingException("could not find bindable property: " + to);
            }
            if (getter.getMethod().getReturnType() != boolean.class) {
                throw new BindingException("VisibleIf binding must return boolean: " + to);
            }
            final Binding binding = new Binding() {
                public <T extends Enum<?> & ModelUpdate> void update(final T... changed) {
                    try {
                        getter.getMethod().setAccessible(true);
                        boolean visible = (Boolean)getter.getMethod().invoke(getter.getObject());
                        if (invert) {
                            visible = !visible;
                        }
                        setVisibleMethod.invoke(setVisibleObject, visible);
                    } catch (final Exception e) {
                        Wiring.logger.error("exception during VisibleIf binding", e);
                    }
                }
            };
            ((BindableModel)getter.getObject()).bind(binding);
            return Collections.singleton(binding);
        }
View Full Code Here

        private static void wire(String call, Field field, BindingContext context)
                throws SecurityException, NoSuchMethodException, IllegalArgumentException,
                        IllegalAccessException, InvocationTargetException {
            Method aalMethod = field.getType().getMethod("addActionListener", ActionListener.class);
            Object actionObject = context.getFieldObject(field, Object.class);
            final ObjectFieldMethod ofm = context.getBindableMethod(call);
            if (ofm == null) {
                throw new BindingException("could not find bindable method: " + call);
            }
            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        boolean accessible = ofm.getMethod().isAccessible();
                        ofm.getMethod().setAccessible(true);
                        ofm.getMethod().invoke(ofm.getObject());
                        ofm.getMethod().setAccessible(accessible);
                    } catch (InvocationTargetException itex) {
                        logger.error("exception during action firing", itex.getCause());
                    } catch (Exception ex) {
                        logger.error("exception during action firing", ex);
                    }
View Full Code Here

            final Method adjustMethod = _adjustMethod;
            final Method addChangeMethod = field.getType().getMethod("addChangeListener", ChangeListener.class);
            if (addChangeMethod != null) {
                final Object changeObject = context.getFieldObject(field, Object.class);
                final ObjectFieldMethod ofm = context.getBindableMethod(call);
                if (ofm == null) {
                    throw new BindingException("could not find bindable method: " + call);
                }
                final ChangeListener changeListener = new ChangeListener() {
                    public void stateChanged(ChangeEvent e) {
                        try {
                            if (adjustMethod != null && !change.onAdjust()) {
                                if ((Boolean) adjustMethod.invoke(changeObject)) return;
                            }
                            ofm.getMethod().invoke(ofm.getObject());
                        } catch (InvocationTargetException itex) {
                            logger.error("exception during action firing", itex.getCause());
                        } catch (Exception ex) {
                            logger.error("exception during action firing", ex);
                        }
View Full Code Here

     * @param target the model and field to bind this {@link Mutator} to.
     * @return the {@link Mutator}
     * @throws IntrospectionException
     */
    public static Mutator create(BindingContext context, String target) throws IntrospectionException {
        final ObjectFieldMethod getter = context.findGetter(target);
        final ObjectFieldMethod setter = context.findSetter(target);
        if (getter == null && setter == null) {
            throw new IllegalArgumentException("could not find either getter/setter for " + target);
        }
        BindableModel model = null;
        BindableModel getterModel = null;
        BindableModel setterModel = null;
        if (getter != null) {
            getterModel = context.getFieldObject(getter.getField(), BindableModel.class);
            model = getterModel;
        }
        if (setter != null) {
            setterModel = context.getFieldObject(setter.getField(), BindableModel.class);
            model = setterModel;
        }
        if (getterModel != null && setterModel != null && getterModel != setterModel) {
            throw new IllegalStateException("setter and getter must be on same BindableModel.");
        }
View Full Code Here

    private static List<ObjectFieldMethod> getParameterlessMethods(Object tupleObject, Class<?> klass) {
        List<ObjectFieldMethod> methods = Lists.newArrayList();
        for (Method method : klass.getDeclaredMethods()) {
            if (method.getParameterTypes().length == 0) {
                methods.add(new ObjectFieldMethod(tupleObject, null, method));
            }
        }
        return methods;
    }
View Full Code Here

                throw new BindingException("call on @OnClick on " + field.getName() + " must be specified");
            }
            Method amlMethod = field.getType().getMethod("addMouseListener", MouseListener.class);
            if (amlMethod != null) {
                Object actionObject = context.getFieldObject(field, Object.class);
                final ObjectFieldMethod ofm = context.getBindableMethod(call);
                if (ofm == null) {
                    throw new BindingException("could not find bindable method: " + call);
                }
                MouseListener mouseListener = new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        if (e.getButton() != onClick.button().getConstant() || e.getClickCount() != onClick.count()) {
                            return;
                        }
                        try {
                            ofm.getMethod().setAccessible(true);
                            ofm.getMethod().invoke(ofm.getObject());
                        } catch (Exception ex) {
                            logger.error("exception during action firing", ex);
                        }
                    }
                };
View Full Code Here

TOP

Related Classes of com.palantir.ptoss.cinch.core.ObjectFieldMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.