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

The following examples show how to use org.openide.nodes.Node.Property#getValue() . 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: EditorPropertyDisplayer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public final void setShowCustomEditorButton(boolean val) {
    //If the property descriptor explicitly says it does not
    //want a custom editor button, this overrides anything set on
    //the PropertyPanel.
    if (getProperty() != null) {
        Property p = getProperty();
        Boolean explicit = (Boolean) p.getValue("suppressCustomEditor"); //NOI18N

        if (explicit != null) {
            val = explicit.booleanValue();
            System.err.println("Found explicit value: " + val);
        }
    }

    if (showCustomEditorButton != val) {
        showCustomEditorButton = val;
        replaceInner();
    }
}
 
Example 2
Source File: PropUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Update a property editor from a Node.Property, such that the
 * value in the property editor will reflect the value of the property */
private static void updateEdFromProp(Property p, PropertyEditor ed, String title)
throws ProxyNode.DifferentValuesException, IllegalAccessException, InvocationTargetException {
    Object newValue = p.getValue();

    //IZ 44152, monstrous length strings from the debugger - skip the
    //equality test and blindly assign
    if (newValue instanceof String && (((String) newValue).length() > 2048)) {
        ed.setValue(newValue);

        return;
    }

    Object oldValue = ed.getValue();

    if ((newValue == null) && (oldValue == null)) {
        return;
    }

    // test if newValue is not equal to oldValue
    if (((newValue != null) && !newValue.equals(oldValue)) || ((newValue == null) && (oldValue != null))) {
        // <RAVE>
        // #5050567 Kind of mysterious livelock experienced here.
        // When updating arrays.
        // The question is whether the setter of the bean has to check if the value
        // is equal and not fire property change.. or is if the responsibility
        // is also here.
        if (
            oldValue instanceof Object[] && newValue instanceof Object[] &&
                Arrays.equals((Object[]) oldValue, (Object[]) newValue)
        ) {
            return;
        }

        // </RAVE>
        ed.setValue(newValue);
    }
}
 
Example 3
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
String getDisplayNameWithMnemonic( Property p ) {
    String res;
    Object displayNameWithMnemonic = p.getValue(ATTR_DISPLAY_NAME_WITH_MNEMONIC);
    if( null !=displayNameWithMnemonic && displayNameWithMnemonic.toString().length() > 0 ) {
        res = displayNameWithMnemonic.toString();
    } else {
        res = p.getDisplayName();
    }
    return res;
}
 
Example 4
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
boolean isSortOrderDescending() {
    if (sortColumn == -1) {
        return false;
    }

    Property p = allPropertyColumns[sortColumn].getProperty();
    Object o = p.getValue(ATTR_DESCENDING_ORDER);

    if ((o != null) && o instanceof Boolean) {
        return ((Boolean) o).booleanValue();
    }

    return false;
}
 
Example 5
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * If true, column is currently used for sorting
 * @param Index to the array of all properties (the column may not be visible)
 */
boolean isSortingColumnEx(int column) {
    Property p = allPropertyColumns[column].getProperty();
    Object o = p.getValue(ATTR_SORTING_COLUMN);

    if ((o != null) && o instanceof Boolean) {
        return ((Boolean) o).booleanValue();
    }

    return false;
}
 
Example 6
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * If true, column property should be comparable - allows sorting
 * @param column Index to the array of all properties
 */
boolean isComparableColumnEx(int column) {
    Property p = allPropertyColumns[column].getProperty();
    Object o = p.getValue(ATTR_COMPARABLE_COLUMN);

    if ((o != null) && o instanceof Boolean) {
        return ((Boolean) o).booleanValue();
    }

    return false;
}
 
Example 7
Source File: SheetTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**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;
}
 
Example 8
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void makeAccessibleCheckBox(JCheckBox box, Property p) {
    box.getAccessibleContext().setAccessibleName(p.getDisplayName());
    box.getAccessibleContext().setAccessibleDescription(p.getShortDescription());

    Object mnemonicChar = p.getValue(ATTR_MNEMONIC_CHAR);

    if ((null != mnemonicChar) && (mnemonicChar.toString().length() > 0)) {
        box.setMnemonic(mnemonicChar.toString().charAt(0));
    }
}
 
Example 9
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void makeAccessibleCheckBox(JCheckBox box, Property p) {
    box.getAccessibleContext().setAccessibleName(p.getDisplayName());
    box.getAccessibleContext().setAccessibleDescription(p.getShortDescription());

    Object mnemonicChar = p.getValue(ATTR_MNEMONIC_CHAR);

    if ((null != mnemonicChar) && (mnemonicChar.toString().length() > 0)) {
        box.setMnemonic(mnemonicChar.toString().charAt(0));
    }
}
 
Example 10
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
String getDisplayNameWithMnemonic( Property p ) {
    String res = null;
    Object displayNameWithMnemonic = p.getValue(ATTR_DISPLAY_NAME_WITH_MNEMONIC);
    if( null !=displayNameWithMnemonic && displayNameWithMnemonic.toString().length() > 0 ) {
        res = displayNameWithMnemonic.toString();
    } else {
        res = p.getDisplayName();
    }
    return res;
}
 
Example 11
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Helper method to ask if column representing a property should be
 * visible
 */
private boolean isVisible(Property p) {
    Object o = p.getValue(ATTR_INVISIBLE);

    if ((o != null) && o instanceof Boolean) {
        return !((Boolean) o).booleanValue();
    }

    return true;
}
 
Example 12
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
boolean isSortOrderDescending() {
    if (sortColumn == -1) {
        return false;
    }

    Property p = allPropertyColumns[sortColumn].getProperty();
    Object o = p.getValue(ATTR_DESCENDING_ORDER);

    if ((o != null) && o instanceof Boolean) {
        return ((Boolean) o).booleanValue();
    }

    return false;
}
 
Example 13
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * If true, column is currently used for sorting
 * @param Index to the array of all properties (the column may not be visible)
 */
boolean isSortingColumnEx(int column) {
    Property p = allPropertyColumns[column].getProperty();
    Object o = p.getValue(ATTR_SORTING_COLUMN);

    if ((o != null) && o instanceof Boolean) {
        return ((Boolean) o).booleanValue();
    }

    return false;
}
 
Example 14
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * If true, column property should be comparable - allows sorting
 * @param column Index to the array of all properties
 */
boolean isComparableColumnEx(int column) {
    Property p = allPropertyColumns[column].getProperty();
    Object o = p.getValue(ATTR_COMPARABLE_COLUMN);

    if ((o != null) && o instanceof Boolean) {
        return ((Boolean) o).booleanValue();
    }

    return false;
}
 
Example 15
Source File: ResultsOutlineCellRenderer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setToolTip(Component renderer, Property<?> property)
        throws IllegalAccessException, InvocationTargetException {
    if (renderer instanceof JLabel) {
        Object val = property.getValue();
        if (val != null) {
            ((JLabel) renderer).setToolTipText(val.toString());
        }
    }
}
 
Example 16
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 17
Source File: ResultsOutlineCellRenderer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
String getDisplayValue(Property<?> p) throws IllegalAccessException,
        InvocationTargetException {
    Object value = p.getValue();
    return value != null ? value.toString() : ""; // NOI18N
}
 
Example 18
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 19
Source File: RendererFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 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;
}
 
Example 20
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;
}