java.beans.PropertyEditor#getTags ( )源码实例Demo

下面列出了java.beans.PropertyEditor#getTags ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: RendererPropertyDisplayer.java
public void setRadioButtonMax(int i) {
    if (i != radioButtonMax) {
        Dimension oldPreferredSize = null;

        if (isShowing()) {
            oldPreferredSize = getPreferredSize();
        }

        int old = radioButtonMax;
        radioButtonMax = i;

        if (oldPreferredSize != null) {
            //see if the change will affect anything
            PropertyEditor ed = PropUtils.getPropertyEditor(prop);
            String[] tags = ed.getTags();

            if (tags != null) {
                if ((tags.length >= i) != (tags.length >= old)) {
                    firePropertyChange("preferredSize", oldPreferredSize, getPreferredSize()); //NOI18N
                }
            }
        }
    }
}
 
源代码2 项目: netbeans   文件: EditorPropertyDisplayer.java
public final void setRadioButtonMax(int max) {
    if (max != radioButtonMax) {
        int old = radioButtonMax;
        boolean needChange = false;

        if (inplace != null) {
            InplaceEditor innermost = PropUtils.findInnermostInplaceEditor(inplace);

            if (innermost instanceof JComboBox || innermost instanceof RadioInplaceEditor) {
                PropertyEditor ped = innermost.getPropertyEditor();
                int tagCount = (ped.getTags() == null) ? (-1) : ped.getTags().length;
                needChange = (old <= tagCount) != (max <= tagCount);
            }
        }

        radioButtonMax = max;

        if (needChange && (inner != null)) {
            replaceInner();
            firePropertyChange("preferredSize", null, null); //NOI18N
        }
    }
}
 
源代码3 项目: netbeans   文件: Property.java
/** Returns true if this property can be edited as text by inplace text field.
 * It can be both for string renderer or combo box renderer.
 * @return true if this property can be edited, false otherwise
 */
@SuppressWarnings("deprecation")
public boolean canEditAsText() {
    if (property.canRead() && property.canWrite()) {
        Boolean val = (Boolean)property.getValue("canEditAsText");  // NOI18N
        if (val != null) {
            return val.booleanValue();
        }
        PropertyEditor pe = getPropertyEditor();
        if (pe instanceof EnhancedPropertyEditor && pe.getTags() !=  null) {
            return ((EnhancedPropertyEditor)pe).supportsEditingTaggedValues();
        } else {
            return pe.getTags() == null;
        }
    } else {
        return false;
    }
}
 
源代码4 项目: meka   文件: GenericObjectEditor.java
/**
 * Tries to determine a view for the editor.
 *
 * @param editor	the editor to get the view for
 * @return		the view, null if failed to determine one
 */
public static JComponent findView(PropertyEditor editor) {
	JComponent	result;

	result = null;

	if (editor.supportsCustomEditor() && editor.isPaintable()) {
		result = new PropertyPanel(editor);
	}
	else if (editor.supportsCustomEditor() && (editor.getCustomEditor() instanceof JComponent)) {
		result = (JComponent) editor.getCustomEditor();
	}
	else if (editor.getTags() != null) {
		result = new PropertyValueSelector(editor);
	}
	else if (editor.getAsText() != null) {
		result = new PropertyText(editor);
	}

	return result;
}
 
源代码5 项目: pentaho-reporting   文件: 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
      }
    }
  } else if ( Color[].class.equals( arrayType ) ) {
    return ColorUtility.getPredefinedExcelColors();
  }

  return null;
}
 
源代码6 项目: netbeans   文件: StringInplaceEditor.java
@Override
public void connect(PropertyEditor p, PropertyEnv env) {
    setActionCommand(COMMAND_SUCCESS);
    this.env = env;
    
    if(PropUtils.supportsValueIncrement( env ) ) {
        PropUtils.wrapUpDownArrowActions( this, this );
    }

    if (editor == p) {
        return;
    }

    editor = p;

    boolean editable = PropUtils.checkEnabled(this, p, env);
    setEnabled(editable);

    //Undocumented, but in NB 3.5 and earlier, getAsText() returning null for
    //paintable editors was yet another way to disable a property editor
    if ((p.getTags() == null) && (p.getAsText() == null) && p.isPaintable()) {
        editable = false;
    }

    setEditable(editable);
    reset();
    added = false;
}
 
源代码7 项目: netbeans   文件: SheetTable.java
/**Overridden to do the assorted black magic by which one determines if
 * a property is editable */
@Override
public boolean isCellEditable(int row, int column) {
    if (column == 0) {
        return null != getCustomEditor( row );
    }

    FeatureDescriptor fd = getPropertySetModel().getFeatureDescriptor(row);
    boolean result;

    if (fd instanceof PropertySet) {
        result = false;
    } else {
        Property p = (Property) fd;
        result = p.canWrite();

        if (result) {
            Object val = p.getValue("canEditAsText"); //NOI18N

            if (val != null) {
                result &= Boolean.TRUE.equals(val);
                if( !result ) {
                    //#227661 - combo box editor should be allowed to show its popup
                    PropertyEditor ped = PropUtils.getPropertyEditor(p);
                    result |= ped.getTags() != null;
                }
            }
        }
    }

    return result;
}
 
源代码8 项目: netbeans   文件: EnumPropertyEditorTest.java
public void testEnumPropEd() throws Exception {
    EProp prop = new EProp();
    PropertyEditor ed = PropUtils.getPropertyEditor(prop);
    assertEquals( EnumPropertyEditor.class, ed.getClass());
    assertFalse(ed.supportsCustomEditor());
    assertFalse(ed.isPaintable());
    String[] tags = ed.getTags();
    assertNotNull(tags);
    assertEquals("[CHOCOLATE, VANILLA, STRAWBERRY]", Arrays.toString(tags));
    assertEquals(E.VANILLA, ed.getValue());
    assertEquals("VANILLA", ed.getAsText());
    ed.setAsText("STRAWBERRY");
    assertEquals(E.STRAWBERRY, ed.getValue());
    assertEquals(E.class.getName().replace('$', '.') + ".STRAWBERRY", ed.getJavaInitializationString());
}
 
源代码9 项目: pentaho-reporting   文件: 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 );
  }

  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;
}
 
源代码10 项目: pentaho-reporting   文件: ArrayCellEditorDialog.java
private Object[] getSelection( final Class arrayType,
                               final String valueRole,
                               final Class propertyEditorType,
                               final String[] extraFields ) {
  if ( String[].class.equals( arrayType ) ) {
    if ( FIELD_VALUE_ROLE.equals( valueRole ) ) {
      return CellEditorUtility.getFieldsAsString( getReportDesignerContext(), extraFields );
    } else if ( GROUP_VALUE_ROLE.equals( valueRole ) ) {
      return CellEditorUtility.getGroups( getReportDesignerContext() );
    } else if ( QUERY_VALUE_ROLE.equals( valueRole ) ) {
      return CellEditorUtility.getQueryNames( getReportDesignerContext() );
    } else if ( NUMBER_FORMAT_VALUE_ROLE.equals( valueRole ) ) {
      return new NumberFormatModel().getNumberFormats();
    } else if ( DATE_FORMAT_VALUE_ROLE.equals( valueRole ) ) {
      return new DateFormatModel().getNumberFormats();
    }

    if ( propertyEditorType != null && PropertyEditor.class.isAssignableFrom( propertyEditorType ) ) {
      // This is a horrible, horrible hack to make the legacy chart editor work properly ..
      if ( "org.pentaho.reporting.engine.classic.extensions.legacy.charts.propertyeditor.ColorPropertyEditor".
        equals( propertyEditorType.getName() ) ) {
        return CellEditorUtility.getExcelColorsAsText();
      }
      try {
        final PropertyEditor editor = (PropertyEditor) propertyEditorType.newInstance();
        return editor.getTags();
      } catch ( Throwable e ) {
        UncaughtExceptionsModel.getInstance().addException( e );
      }
    }
  } else if ( Color[].class.equals( arrayType ) ) {
    return ColorUtility.getPredefinedExcelColors();
  }

  return null;
}
 
源代码11 项目: netbeans   文件: InplaceEditorFactory.java
InplaceEditor getInplaceEditor(Property p, PropertyEnv env, boolean newInstance) {
    PropertyEditor ped = PropUtils.getPropertyEditor(p);
    InplaceEditor result = (InplaceEditor) p.getValue("inplaceEditor"); //NOI18N
    env.setFeatureDescriptor(p);
    env.setEditable(p.canWrite());

    if (ped instanceof ExPropertyEditor) {
        ExPropertyEditor epe = (ExPropertyEditor) ped;

        //configure the editor/propertyenv
        epe.attachEnv(env);

        if (result == null) {
            result = env.getInplaceEditor();
        }
    } else if (ped instanceof EnhancedPropertyEditor) {
        //handle legacy inplace custom editors
        EnhancedPropertyEditor enh = (EnhancedPropertyEditor) ped;

        if (enh.hasInPlaceCustomEditor()) {
            //Use our wrapper component to handle this
            result = new WrapperInplaceEditor(enh);
        }
    }

    //Okay, the result is null, provide one of the standard inplace editors
    if (result == null) {
        Class c = p.getValueType();

        String[] tags;
        if ((c == Boolean.class) || (c == Boolean.TYPE)) {
            if (ped instanceof PropUtils.NoPropertyEditorEditor) {
                //platform case
                result = getStringEditor(newInstance);
            } else {
                boolean useRadioButtons = useRadioBoolean || (p.getValue("stringValues") != null); //NOI18N
                result = useRadioButtons ? getRadioEditor(newInstance) : getCheckboxEditor(newInstance);
            }
        } else if ((tags = ped.getTags()) != null) {
            if (tags.length <= radioButtonMax) {
                result = getRadioEditor(newInstance);
            } else {
                result = getComboBoxEditor(newInstance);
            }
        } else {
            result = getStringEditor(newInstance);
        }
    }

    if (!tableUI && Boolean.FALSE.equals(p.getValue("canEditAsText"))) { //NOI18N
        result.getComponent().setEnabled(false);
    }

    result.clear(); //XXX shouldn't need to do this!
    result.setPropertyModel(new NodePropertyModel(p, env.getBeans()));
    result.connect(ped, env);

    //XXX?
    if (tableUI) {
        if( result instanceof JTextField )
            result.getComponent().setBorder(BorderFactory.createEmptyBorder(0,3,0,0));
        else
            result.getComponent().setBorder(BorderFactory.createEmptyBorder());
    }

    return result;
}
 
源代码12 项目: netbeans   文件: SheetTable.java
/**  Returns true if a mouse event occured over the custom editor button.
 *   This is used to supply button specific tooltips and launch the custom
 *   editor without needing to instantiate a real button */
private boolean onCustomEditorButton(MouseEvent e) {
    //see if we're in the approximate bounds of the custom editor button
    Point pt = e.getPoint();
    int row = rowAtPoint(pt);
    int col = columnAtPoint(pt);
    FeatureDescriptor fd = getSheetModel().getPropertySetModel().getFeatureDescriptor(row);
    if( null == fd ) {
        //prevent NPE when the activated Node has been destroyed and a new one hasn't been set yet
        return false;
    }

    //see if the event happened over the custom editor button
    boolean success;

    if (PropUtils.noCustomButtons) {
        //#41412 - impossible to invoke custom editor on props w/ no inline
        //edit mode if the no custom buttons switch is set
        success = false;
    } else {
        success = e.getX() > (getWidth() - PropUtils.getCustomButtonWidth());
    }

    //if it's a mouse button event, then we're not showing a tooltip, we're
    //deciding if we should display a custom editor.  For read-only props that
    //support one, we should return true, since clicking the non-editable cell
    //is not terribly useful.
    if (
        (e.getID() == MouseEvent.MOUSE_PRESSED) || (e.getID() == MouseEvent.MOUSE_RELEASED) ||
            (e.getID() == MouseEvent.MOUSE_CLICKED)
    ) {
        //We will show the custom editor for any click on the text value
        //of a property that looks editable but sets canEditAsText to false -
        //the click means the user is trying to edit something, so to just
        //swallow the gesture is confusing
        success |= Boolean.FALSE.equals(fd.getValue("canEditAsText"));

        if (!success && fd instanceof Property) {
            PropertyEditor pe = PropUtils.getPropertyEditor((Property) fd);

            if ((pe != null) && pe.supportsCustomEditor()) {
                //Undocumented but used in Studio - in NB 3.5 and earlier, returning null from getAsText()
                //was a way to make a property non-editable
                success |= (pe.isPaintable() && (pe.getAsText() == null) && (pe.getTags() == null));
            }
        }
    }

    try {
        if (success) { //NOI18N

            if (fd instanceof Property && (col == 1)) {
                boolean supp = PropUtils.getPropertyEditor((Property) fd).supportsCustomEditor();

                return (supp);
            }
        }
    } catch (IllegalStateException ise) {
        //See bugtraq 4941073 - if a property accessed via Reflection throws
        //an unexpected exception (try customize bean on a vanilla GenericServlet
        //to produce this) when the getter is accessed, then we are already
        //displaying "Error fetching property value" in the value area of
        //the propertysheet.  No point in distracting the user with a 
        //stack trace - it's not our bug.
        Logger.getLogger(SheetTable.class.getName()).log(Level.WARNING, null, ise);
    }

    return false;
}
 
源代码13 项目: netbeans   文件: RendererFactory.java
/** Get a renderer component appropriate to a given property */
public JComponent getRenderer(Property prop) {
    mdl.setProperty(prop);
    env.reset();

    PropertyEditor editor = preparePropertyEditor(mdl, env);

    if (editor instanceof ExceptionPropertyEditor) {
        return getExceptionRenderer((Exception) editor.getValue());
    }

    JComponent result = null;

    try {
        if (editor.isPaintable()) {
            result = prepareString(editor, env);
        } else {
            Class c = mdl.getPropertyType();

            if ((c == Boolean.class) || (c == boolean.class)) {
                //Special handling for hinting for org.netbeans.beaninfo.BoolEditor
                boolean useRadioRenderer = useRadioBoolean ||
                    (env.getFeatureDescriptor().getValue("stringValues") != null); //NOI18N

                if (useRadioRenderer) {
                    result = prepareRadioButtons(editor, env);
                } else {
                    result = prepareCheckbox(editor, env);
                }
            } else if (editor.getTags() != null) {
                String[] s = editor.getTags();
                boolean editAsText = Boolean.TRUE.equals(prop.getValue("canEditAsText"));

                if ((s.length <= radioButtonMax) && !editAsText) {
                    result = prepareRadioButtons(editor, env);
                } else {
                    result = prepareCombobox(editor, env);
                }
            } else {
                result = prepareString(editor, env);
            }
        }

        if ((result != radioRenderer) && (result != textFieldRenderer)) {
            if ((result != checkboxRenderer) && tableUI && !(result instanceof JComboBox)) {
                result.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
            } else if ((result instanceof JComboBox) && tableUI) {
                result.setBorder(BorderFactory.createEmptyBorder());
            } else if (!(result instanceof JComboBox) && (!(result instanceof JCheckBox))) {
                result.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
            }
        }
    } catch (Exception e) {
        result = getExceptionRenderer(e);
        Logger.getLogger(RendererFactory.class.getName()).log(Level.WARNING, null, e);
    }

    result.setEnabled(prop.canWrite());

    boolean propRequestsSuppressButton = Boolean.TRUE.equals(prop.getValue("suppressCustomEditor")); //NOI18N

    if (
        !(result instanceof JLabel) &&
            ((env.getState() == ReusablePropertyEnv.STATE_INVALID) || (prop.getValue("valueIcon") != null))
    ) { //NOI18N
        result = prepareIconPanel(editor, env, (InplaceEditor) result);
    }

    /* If we need a custom editor button, embed the resulting component in
     an instance of ButtonPanel and return that */
    if (
        editor.supportsCustomEditor() && !PropUtils.noCustomButtons && !suppressButton &&
            !propRequestsSuppressButton
    ) {
        ButtonPanel bp = buttonPanel();
        bp.setInplaceEditor((InplaceEditor) result);
        result = bp;
    }

    return result;
}
 
源代码14 项目: pentaho-reporting   文件: 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;
      }
    }

    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 );
}