Package java.beans

Examples of java.beans.PropertyEditor


        }
    }

    private void writeParameter(XMLStreamWriter writer, int index, FilterProperty property) {
        try {
            PropertyEditor editor = property.getPropertyEditor();
            if (editor == null) {
                editor = PropertyEditorManager.findEditor(property.getValueType());
            }
            if (editor == null) {
                return;
            }
            Object val = property.getValue();
            editor.setValue(val);
            writer.writeStartElement("parameter");
            writer.writeAttribute("index", String.valueOf(index));
            writer.writeCharacters(editor.getAsText());
            writer.writeEndElement();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here


                        int index = Integer.parseInt(reader.getAttributeValue(null, "index"));
                        property = query.getFilter().getProperties()[index];
                    }
                } else if (eventType.equals(XMLStreamReader.CHARACTERS) && property != null) {
                    try {
                        PropertyEditor editor = property.getPropertyEditor();
                        if (editor == null) {
                            editor = PropertyEditorManager.findEditor(property.getValueType());
                        }
                        if (editor != null) {
                            String textValue = reader.getText();
                            editor.setAsText(textValue);
                            property.setValue(editor.getValue());
                            model.updateParameters(query);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
View Full Code Here

                log.debug("No editor for property " + name);
                editors[i] = null;
                continue;
            }

            PropertyEditor propertyEditor;
            Class<?> editorClass = descriptors[i].getPropertyEditorClass();

            if (log.isDebugEnabled()) {
                log.debug("Property " + name + " has editor class " + editorClass);
            }

            if (editorClass != null) {
                try {
                    propertyEditor = (PropertyEditor) editorClass.newInstance();
                } catch (InstantiationException e) {
                    log.error("Can't create property editor.", e);
                    throw new Error(e.toString());
                } catch (IllegalAccessException e) {
                    log.error("Can't create property editor.", e);
                    throw new Error(e.toString());
                }
            } else {
                Class<?> c = descriptors[i].getPropertyType();
                propertyEditor = PropertyEditorManager.findEditor(c);
            }

            if (log.isDebugEnabled()) {
                log.debug("Property " + name + " has property editor " + propertyEditor);
            }

            if (propertyEditor == null) {
                log.debug("No editor for property " + name);
                editors[i] = null;
                continue;
            }

            if (!propertyEditor.supportsCustomEditor()) {
                propertyEditor = createWrapperEditor(propertyEditor, descriptors[i]);

                if (log.isDebugEnabled()) {
                    log.debug("Editor for property " + name + " is wrapped in " + propertyEditor);
                }
            }
            if(propertyEditor instanceof TestBeanPropertyEditor)
            {
                ((TestBeanPropertyEditor)propertyEditor).setDescriptor(descriptors[i]);
            }
            if (propertyEditor.getCustomEditor() instanceof JScrollPane) {
                scrollerCount++;
            }

            editors[i] = propertyEditor;
View Full Code Here

        boolean notNull = Boolean.TRUE.equals(descriptor.getValue(NOT_UNDEFINED));
        boolean notExpression = Boolean.TRUE.equals(descriptor.getValue(NOT_EXPRESSION));
        boolean notOther = Boolean.TRUE.equals(descriptor.getValue(NOT_OTHER));

        PropertyEditor guiEditor;
        if (notNull && tags == null) {
            guiEditor = new FieldStringEditor();
        } else {
            ComboStringEditor e = new ComboStringEditor();
            e.setNoUndefined(notNull);
View Full Code Here

    /**
     * Save values from the GUI fields into the property map
     */
    void saveGuiFields() {
        for (int i = 0; i < editors.length; i++) {
            PropertyEditor propertyEditor=editors[i]; // might be null (e.g. in testing)
            if (propertyEditor != null) {
                Object value = propertyEditor.getValue();
                String name = descriptors[i].getName();
                if (value == null) {
                    propertyMap.remove(name);
                    if (log.isDebugEnabled()) {
                        log.debug("Unset " + name);
View Full Code Here

        }
    }

    void clearGuiFields() {
        for (int i = 0; i < editors.length; i++) {
            PropertyEditor propertyEditor=editors[i]; // might be null (e.g. in testing)
            if (propertyEditor != null) {
                try {
                if (propertyEditor instanceof WrapperEditor){
                    WrapperEditor we = (WrapperEditor) propertyEditor;
                    String tags[]=we.getTags();
                    if (tags != null && tags.length > 0) {
                        we.setAsText(tags[0]);
                    } else {
                        we.setValue("");
                    }
                } else if (propertyEditor instanceof ComboStringEditor) {
                    ComboStringEditor cse = (ComboStringEditor) propertyEditor;
                    cse.setAsText(cse.getInitialEditValue());
                } else {
                    propertyEditor.setAsText("");
                }
                } catch (IllegalArgumentException ex){
                    log.error("Failed to set field "+descriptors[i].getName(),ex);
                }
            }
View Full Code Here

            throwMBeanException(new IllegalArgumentException(
                    "Unknown attribute: " + aname));
        }
       
        try {
            PropertyEditor e = getPropertyEditor(
                    getParent(aname).getClass(),
                    pdesc.getName(), pdesc.getPropertyType());
            e.setAsText((String) avalue);
            OgnlContext ctx = (OgnlContext) Ognl.createDefaultContext(source);
            ctx.setTypeConverter(typeConverter);
            Ognl.setValue(aname, ctx, source, e.getValue());
        } catch (Throwable e) {
            throwMBeanException(e);
        }
    }
View Full Code Here

                paramTypes[i] = getAttributeClass(signature[i]);
            } catch (ClassNotFoundException e) {
                throwMBeanException(e);
            }
           
            PropertyEditor e = getPropertyEditor(
                    source.getClass(), "p" + i, paramTypes[i]);
            if (e == null) {
                throwMBeanException(new RuntimeException("Conversion failure: " + params[i]));
            }
           
            e.setValue(params[i]);
            params[i] = e.getAsText();
        }
       
        try {
            // Find the right method.
            for (Method m: source.getClass().getMethods()) {
                if (!m.getName().equalsIgnoreCase(name)) {
                    continue;
                }
                Class<?>[] methodParamTypes = m.getParameterTypes();
                if (methodParamTypes.length != params.length) {
                    continue;
                }
               
                Object[] convertedParams = new Object[params.length];
                for (int i = 0; i < params.length; i ++) {
                    if (Iterable.class.isAssignableFrom(methodParamTypes[i])) {
                        // Generics are not supported.
                        convertedParams = null;
                        break;
                    }
                    PropertyEditor e = getPropertyEditor(source.getClass(), "p" + i, methodParamTypes[i]);
                    if (e == null) {
                        convertedParams = null;
                        break;
                    }

                    e.setAsText((String) params[i]);
                    convertedParams[i] = e.getValue();
                }
                if (convertedParams == null) {
                    continue;
                }
               
View Full Code Here

                    return v;
                }
            }
        }
       
        PropertyEditor editor = getPropertyEditor(type, attrName, v.getClass());
        if (editor != null) {
            editor.setValue(v);
            return editor.getAsText();
        }
       
        return v.toString();
    }
View Full Code Here

    private synchronized Object getValue(GAttributeInfo attribute, String value, Artifact configurationName, AbstractName gbeanName, ClassLoader classLoader) {
        if (value == null) {
            return null;
        }
        value = substituteVariables(attribute.getName(), value);
        PropertyEditor editor = loadPropertyEditor(attribute, classLoader);
        editor.setAsText(value);
        log.debug("Setting value for " + configurationName + "/" + gbeanName + "/" + attribute.getName() + " to value " + value);
        return editor.getValue();
    }
View Full Code Here

TOP

Related Classes of java.beans.PropertyEditor

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.