Example usage for java.beans PropertyEditor getTags

List of usage examples for java.beans PropertyEditor getTags

Introduction

In this page you can find the example usage for java.beans PropertyEditor getTags.

Prototype

String[] getTags();

Source Link

Document

If the property value must be one of a set of known tagged values, then this method should return an array of the tags.

Usage

From source file:org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer.java

/**
 * Validate the descriptor attributes.//from   w ww .ja  va  2s  .c  om
 * 
 * @param pd the descriptor
 * @param pe the propertyEditor
 */
private static void validateAttributes(PropertyDescriptor pd, PropertyEditor pe) {
    final Object deflt = pd.getValue(DEFAULT);
    if (deflt == null) {
        if (notNull(pd)) {
            log.warn(getDetails(pd) + " requires a value but does not provide a default.");
        }
        if (noSaveDefault(pd)) {
            log.warn(getDetails(pd) + " specifies DEFAULT_NO_SAVE but does not provide a default.");
        }
    } else {
        final Class<?> defltClass = deflt.getClass(); // the DEFAULT class
        // Convert int to Integer etc:
        final Class<?> propClass = ClassUtils.primitiveToWrapper(pd.getPropertyType());
        if (!propClass.isAssignableFrom(defltClass)) {
            log.warn(getDetails(pd) + " has a DEFAULT of class " + defltClass.getCanonicalName());
        }
    }
    if (notOther(pd) && pd.getValue(TAGS) == null && pe.getTags() == null) {
        log.warn(getDetails(pd) + " does not have tags but other values are not allowed.");
    }
    if (!notNull(pd)) {
        Class<?> propertyType = pd.getPropertyType();
        if (propertyType.isPrimitive()) {
            log.warn(getDetails(pd) + " allows null but is a primitive type");
        }
    }
    if (!pd.attributeNames().hasMoreElements()) {
        log.warn(getDetails(pd) + " does not appear to have been configured");
    }
}

From source file:org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer.java

/**
 * Find the default typeEditor and a suitable guiEditor for the given
 * property descriptor, and combine them in a WrapperEditor.
 *
 * @param typeEditor/*w  ww .  j a v  a  2s. co  m*/
 * @param descriptor
 * @return the wrapper editor
 */
private WrapperEditor createWrapperEditor(PropertyEditor typeEditor, PropertyDescriptor descriptor) {
    String[] editorTags = typeEditor.getTags();
    String[] additionalTags = (String[]) descriptor.getValue(TAGS);
    String[] tags = null;
    if (editorTags == null) {
        tags = additionalTags;
    } else if (additionalTags == null) {
        tags = editorTags;
    } else {
        tags = new String[editorTags.length + additionalTags.length];
        int j = 0;
        for (String editorTag : editorTags) {
            tags[j++] = editorTag;
        }
        for (String additionalTag : additionalTags) {
            tags[j++] = additionalTag;
        }
    }

    boolean notNull = notNull(descriptor);
    boolean notExpression = notExpression(descriptor);
    boolean notOther = notOther(descriptor);

    PropertyEditor guiEditor;
    if (notNull && tags == null) {
        guiEditor = new FieldStringEditor();
    } else {
        guiEditor = new ComboStringEditor(tags, notExpression && notOther, notNull,
                (ResourceBundle) descriptor.getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE));
    }

    WrapperEditor wrapper = new WrapperEditor(typeEditor, guiEditor, !notNull, // acceptsNull
            !notExpression, // acceptsExpressions
            !notOther, // acceptsOther
            descriptor.getValue(DEFAULT));

    return wrapper;
}

From source file:org.lnicholls.galleon.gui.HMEConfigurationPanel.java

public HMEConfigurationPanel(Object bean) {

    setLayout(new GridLayout(0, 1));

    target = bean;//from   w w w.jav  a 2  s  .co m

    try {

        BeanInfo bi = Introspector.getBeanInfo(target.getClass());

        properties = bi.getPropertyDescriptors();

    } catch (IntrospectionException ex) {

        Tools.logException(HMEConfigurationPanel.class, ex, "PropertySheet: Couldn't introspect");

        return;

    }

    editors = new PropertyEditor[properties.length];

    values = new Object[properties.length];

    views = new Component[properties.length];

    labels = new JLabel[properties.length];

    for (int i = 0; i < properties.length; i++) {

        // Don't display hidden or expert properties.

        if (properties[i].isHidden() || properties[i].isExpert()) {

            continue;

        }

        String name = properties[i].getDisplayName();

        Class type = properties[i].getPropertyType();

        Method getter = properties[i].getReadMethod();

        Method setter = properties[i].getWriteMethod();

        // Only display read/write properties.

        if (getter == null || setter == null) {

            continue;

        }

        Component view = null;

        try {

            Object args[] = {};

            Object value = getter.invoke(target, args);

            values[i] = value;

            PropertyEditor editor = null;

            Class pec = properties[i].getPropertyEditorClass();

            if (pec != null) {

                try {

                    editor = (PropertyEditor) pec.newInstance();

                } catch (Exception ex) {

                    // Drop through.

                }

            }

            if (editor == null) {

                editor = PropertyEditorManager.findEditor(type);

            }

            editors[i] = editor;

            // If we can't edit this component, skip it.

            if (editor == null) {

                // If it's a user-defined property we give a warning.

                String getterClass = properties[i].getReadMethod().getDeclaringClass().getName();

                if (getterClass.indexOf("java.") != 0) {

                    log.error("Warning: Can't find public property editor for property \"" + name

                            + "\".  Skipping.");

                }

                continue;

            }

            // Don't try to set null values:

            if (value == null) {

                // If it's a user-defined property we give a warning.

                String getterClass = properties[i].getReadMethod().getDeclaringClass().getName();

                if (getterClass.indexOf("java.") != 0) {

                    log.error("Warning: Property \"" + name + "\" has null initial value.  Skipping.");

                }

                continue;

            }

            editor.setValue(value);

            // editor.addPropertyChangeListener(adaptor);

            // Now figure out how to display it...

            if (editor.isPaintable() && editor.supportsCustomEditor()) {

                view = new PropertyCanvas(frame, editor);

            } else if (editor.getTags() != null) {

                view = new PropertySelector(editor);

            } else if (editor.getAsText() != null) {

                String init = editor.getAsText();

                view = new PropertyText(editor);

            } else {

                log.error("Warning: Property \"" + name + "\" has non-displayabale editor.  Skipping.");

                continue;

            }

        } catch (InvocationTargetException ex) {

            Tools.logException(HMEConfigurationPanel.class, ex.getTargetException(),
                    "Skipping property " + name);

            continue;

        } catch (Exception ex) {

            Tools.logException(HMEConfigurationPanel.class, ex, "Skipping property " + name);

            continue;

        }

        labels[i] = new JLabel(WordUtils.capitalize(name), JLabel.RIGHT);

        // add(labels[i]);

        views[i] = view;

        // add(views[i]);

    }

    int validCounter = 0;

    for (int i = 0; i < labels.length; i++) {

        if (labels[i] != null)

            validCounter++;

    }

    String rowStrings = ""; // general

    if (validCounter > 0)

        rowStrings = "pref, ";

    else

        rowStrings = "pref";

    int counter = 0;

    for (int i = 0; i < labels.length; i++) {

        if (labels[i] != null) {

            if (++counter == (validCounter))

                rowStrings = rowStrings + "9dlu, " + "pref";

            else

                rowStrings = rowStrings + "9dlu, " + "pref, ";

        }

    }

    FormLayout layout = new FormLayout("right:pref, 3dlu, 50dlu:g, right:pref:grow", rowStrings);

    PanelBuilder builder = new PanelBuilder(layout);

    //DefaultFormBuilder builder = new DefaultFormBuilder(new FormDebugPanel(), layout);

    builder.setDefaultDialogBorder();

    CellConstraints cc = new CellConstraints();

    builder.addSeparator("General", cc.xyw(1, 1, 4));

    counter = 0;

    for (int i = 0; i < labels.length; i++) {

        if (labels[i] != null) {

            counter++;

            builder.add(labels[i], cc.xy(1, counter * 2 + 1));

            builder.add(views[i], cc.xy(3, counter * 2 + 1));

        }

    }

    JPanel panel = builder.getPanel();

    //FormDebugUtils.dumpAll(panel);

    add(panel);

}

From source file:org.pentaho.reporting.designer.core.util.table.ElementMetaDataTable.java

public TableCellEditor getCellEditor(final int row, final int viewColumn) {
    final int column = convertColumnIndexToModel(viewColumn);
    final Object value = getModel().getValueAt(row, column);
    if (value instanceof GroupingHeader) {
        return getDefaultEditor(GroupingHeader.class);
    }/*from w  ww  .j  av a 2s  .  com*/

    final ElementMetaDataTableModel model = (ElementMetaDataTableModel) getModel();
    final PropertyEditor propertyEditor = model.getEditorForCell(row, column);
    final Class columnClass = model.getClassForCell(row, column);

    if (propertyEditor != null) {
        final String[] tags = propertyEditor.getTags();
        if (columnClass.isArray()) {
            arrayCellEditor.setPropertyEditorType(propertyEditor.getClass());
        } else if (tags == null || tags.length == 0) {
            propertyEditorCellEditor.setPropertyEditor(propertyEditor);
            return propertyEditorCellEditor;
        } else {
            taggedPropertyEditorCellEditor.setPropertyEditor(propertyEditor);
            return taggedPropertyEditorCellEditor;
        }
    }

    final TableColumn tableColumn = getColumnModel().getColumn(column);
    final TableCellEditor renderer = tableColumn.getCellEditor();
    if (renderer != null) {
        return renderer;
    }

    if (columnClass.isArray()) {
        return arrayCellEditor;
    }

    final TableCellEditor editor = getDefaultEditor(columnClass);
    if (editor != null && logger.isTraceEnabled()) {
        logger.trace("Using preconfigured default editor for column class " + columnClass + ": " + editor); // NON-NLS
    }
    return editor;
}

From source file:org.pentaho.reporting.libraries.designtime.swing.table.ArrayCellEditorDialog.java

private Object[] getSelection(final Class arrayType, final Class propertyEditorType) {
    if (String[].class.equals(arrayType)) {
        if (propertyEditorType != null && PropertyEditor.class.isAssignableFrom(propertyEditorType)) {
            try {
                final PropertyEditor editor = (PropertyEditor) propertyEditorType.newInstance();
                return editor.getTags();
            } catch (Throwable e) {
                logger.error("Unable to instantiate property editor.", e);// NON-NLS
            }//from w  w  w . j  ava2s.  co  m
        }
    } else if (Color[].class.equals(arrayType)) {
        return ColorUtility.getPredefinedExcelColors();
    }

    return null;
}

From source file:org.pentaho.reporting.libraries.designtime.swing.table.PropertyTable.java

public TableCellEditor getCellEditor(final int row, final int viewColumn) {
    final TableModel tableModel = getModel();
    if (tableModel instanceof PropertyTableModel) {
        final PropertyTableModel model = (PropertyTableModel) getModel();
        final int column = convertColumnIndexToModel(viewColumn);

        final PropertyEditor propertyEditor = model.getEditorForCell(row, column);
        final Class columnClass = model.getClassForCell(row, column);

        if (propertyEditor != null) {
            final String[] tags = propertyEditor.getTags();

            if (columnClass.isArray()) {
                arrayCellEditor.setPropertyEditorType(propertyEditor.getClass());
            } else if (tags == null || tags.length == 0) {
                propertyEditorCellEditor.setPropertyEditor(propertyEditor);
                return propertyEditorCellEditor;
            } else {
                taggedPropertyEditorCellEditor.setPropertyEditor(propertyEditor);
                return taggedPropertyEditorCellEditor;
            }//from  w  w w.j a v  a 2 s.c  o m
        }

        final TableColumn tableColumn = getColumnModel().getColumn(column);
        final TableCellEditor renderer = tableColumn.getCellEditor();
        if (renderer != null) {
            return renderer;
        }

        if (columnClass.isArray()) {
            return arrayCellEditor;
        }

        final TableCellEditor editor = getDefaultEditor(columnClass);
        if (editor != null && logger.isTraceEnabled()) {
            logger.trace("Using preconfigured default editor for column class " + columnClass + ": " + editor); // NON-NLS
        }
        return editor;
    }
    return super.getCellEditor(row, viewColumn);
}