/** * Set the object to be edited. * * @param value The object to be edited. */ public void setObject(Object value) { if (!(_type.isInstance(value))) { throw new IllegalArgumentException(value.getClass() + " is not of type " + _type); } _value = value; // Disable event generation. _squelchChangeEvents = true; // Iterate over each property, doing a lookup on the associated editor // and setting the editor's value to the value of the property. Iterator it = _prop2Editor.keySet().iterator(); while (it.hasNext()) { PropertyDescriptor desc = (PropertyDescriptor) it.next(); PropertyEditor editor = (PropertyEditor) _prop2Editor.get(desc); Method reader = desc.getReadMethod(); if (reader != null) { try { Object val = reader.invoke(_value, null); editor.setValue(val); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InvocationTargetException ex) { ex.getTargetException().printStackTrace(); } } } // Enable event generation. _squelchChangeEvents = false; }
@Override public void actionPerformed(java.awt.event.ActionEvent e) { try { PropertyEditor propEd = property.getPropertyEditor(); propEd.setValue(property.getValue()); final Component custEditor = propEd.getCustomEditor(); Object[] options = buttons(); DialogDescriptor descriptor = new DialogDescriptor( custEditor, (String) getValue(Action.NAME), true, options, DialogDescriptor.CANCEL_OPTION, DialogDescriptor.DEFAULT_ALIGN, HelpCtx.DEFAULT_HELP, (ActionEvent e1) -> { try { String action = e1.getActionCommand(); switch (action) { case OK_COMMAND: Object value = property.getPropertyEditor().getValue(); property.setValue(value); break; case RESTORE_COMMAND: property.restoreDefaultValue(); break; } dialog.dispose(); } catch (Exception ex) { NotifyDescriptor descriptor2 = new NotifyDescriptor.Message( NbBundle.getMessage(PropertyAction.class, "MSG_InvalidValue")); // NOI18N DialogDisplayer.getDefault().notify(descriptor2); } }); descriptor.setClosingOptions(new Object[0]); dialog = DialogDisplayer.getDefault().createDialog(descriptor); dialog.setVisible(true); dialog = null; } catch (Exception ex) { ErrorManager.getDefault().notify(ex); } }