Java Code Examples for org.openide.nodes.Node.Property#getValueType()

The following examples show how to use org.openide.nodes.Node.Property#getValueType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InplaceEditorFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 2
Source File: PropUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Gets a property editor appropriate to the property.
 *  This method centralizes all code for fetching property editors
 *  used by the property sheet, such that future alternative
 *  registration systems for property editors may be easily
 *  implemented.
 *  <P><strong>Note:</strong>  This method will return a property
 *  editor with the value of the property already assigned.  Client
 *  code need not set the value in the property editor unless it
 *  should be changed, as this can result in unnecessary event
 *  firing.
 */
static PropertyEditor getPropertyEditor(Property p, boolean updateEditor) {
    PropertyEditor result = p.getPropertyEditor();

    //XXX Next few lines replicate a hack in the original property sheet.
    //Correct solution is to move IndexedPropertyEditor & custom editor
    //to the Nodes package and just return an instance from
    //IndexedProperty.getPropertyEditor.  Appears to be here due to some
    //kind of dependancy avoidance.
    if (p instanceof Node.IndexedProperty && (result == null)) {
        result = new IndexedPropertyEditor();

        // indexed property editor does not want to fire immediately
        p.setValue(PropertyEnv.PROP_CHANGE_IMMEDIATE, Boolean.FALSE);
    }

    if (result == null) {
        result = getPropertyEditor(p.getValueType()); //XXX is this agood idea?
    }

    //handle a type with no registered property editor here
    if (result == null) {
        java.util.List<String> missing = getMissing();
        String type = p.getValueType().getName();

        if (!(missing.contains(type))) {
            Logger.getAnonymousLogger().fine(
                "No property editor registered for type " + type
            ); //NOI18N
            missing.add(type);
        }

        result = new NoPropertyEditorEditor();
    } else if (p.canRead()) {
        try {
            try {
                try {
                    if (
                        ((p.getValueType() == Boolean.class) || (p.getValueType() == Boolean.TYPE)) &&
                            (p.getValue() == null)
                    ) {
                        // Allows Module folder nodes that use null to
                        // indicate indeterminate state to work
                        result = new Boolean3WayEditor();
                    }

                    if (updateEditor || null == result.getValue()) {
                        updateEdFromProp(p, result, p.getDisplayName());
                    }
                } catch (ProxyNode.DifferentValuesException dve) {
                    if ((p.getValueType() == Boolean.class) || (p.getValueType() == Boolean.TYPE)) {
                        result = new Boolean3WayEditor();
                    } else {
                         if(result instanceof ExPropertyEditor)
                             result = new ExDifferentValuesEditor(result);
                         else
                             result = new DifferentValuesEditor(result);
                    }
                }
            } catch (IllegalAccessException iae) {
                throw (IllegalStateException) new IllegalStateException("Error getting property value").initCause(iae);
            }
        } catch (InvocationTargetException ite) {
            throw (IllegalStateException) new IllegalStateException("Error getting property value").initCause(ite);
        }
    }

    return result;
}
 
Example 3
Source File: SheetTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** In the case that an edit request is made on a boolean checkbox property, an
 *  edit request should simply toggle its state without instantiating a custom
 *  editor component.  Returns true if the state was toggled, in which case the
 *  editor instantiation portion of editCellAt() should be aborted  */
boolean checkEditBoolean(int row) {
    FeatureDescriptor fd = getSheetModel().getPropertySetModel().getFeatureDescriptor(row);

    if (fd != null && fd.getValue("stringValues") != null) {
        return false; //NOI18N
    }

    Property p = (fd instanceof Property) ? (Property) fd : null;

    if (p != null) {
        Class c = p.getValueType();

        //only do this if the property is supplying no special values for
        //the tags - if it is, we are using the radio button renderer
        if ((c == Boolean.class) || (c == boolean.class)) {
            if (!isCellEditable(row, 1)) {
                return true;
            }

            //Okay, try to toggle it
            try {
                Boolean b = null;

                //get the current value
                try {
                    Object value = p.getValue();
                    if( value instanceof Boolean ) {
                        b = (Boolean) value;
                    } else {
                        //150048 - somebody has sneaked in a wrong value
                        return false;
                    }
                } catch (ProxyNode.DifferentValuesException dve) {
                    //If we're represeting conflicting multi-selected 
                    //properties, we'll make them both true when we toggle
                    b = Boolean.FALSE;
                }

                if (isEditing()) {
                    removeEditor();
                }

                changeSelection(row, 1, false, false);

                //Toggle the value
                Boolean newValue = ((b == null) || Boolean.FALSE.equals(b)) ? Boolean.TRUE : Boolean.FALSE;
                p.setValue(newValue);

                //Force an event so we'll repaint
                /*
                tableChanged(new TableModelEvent (getSheetModel(), row,
                    row, 1, TableModelEvent.UPDATE));
                 */
                paintRow(row);

                return true;
            } catch (Exception ex) {
                //Something wrong, log it
                Exceptions.printStackTrace(ex);
            }
        }
    }

    return false;
}
 
Example 4
Source File: SheetTableModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Utility method that returns the short description
 *  of the property in question,
 *  used by the table to supply tooltips.  */
public String getDescriptionFor(int row, int column) {
    if ((row == -1) || (column == -1)) {
        return ""; //NOI18N
    }

    FeatureDescriptor fd = model.getFeatureDescriptor(row);
    Property p = (fd instanceof Property) ? (Property) fd : null;
    String result = null;

    if (p != null) {
        try {
            //try to get the short description, fall back to the value
            if (column == 0) {
                result = p.getShortDescription();
            } else {
                 PropertyEditor ped = PropUtils.getPropertyEditor (p);
                 if (ped != null) {
                     result = ped.getAsText();
                 } else {
                     //IZ 44152, Debugger can produce > 512K strings, so add
                     //some special handling for very long strings
                     if (p.getValueType() == String.class) {
                         String s = (String) p.getValue();
                         if (s != null && s.length() > 2048) {
                             return "";
                         } else {
                             return s;
                         }
                     }
                 }
            }
        } catch (Exception e) {
            //Suppress the exception, this is a tooltip
            result = (column == 0) ? p.getShortDescription() : e.toString();
        }
    } else {
        PropertySet ps = (PropertySet) fd;
        result = ps.getShortDescription();
    }

    if (result == null) {
        result = ""; //NOI18N
    }

    return result;
}