/** * Wraps a property editor into a component. * * @param editor the editor to wrap * @return a button (if there is a custom editor), combo box (if the editor has tags), or text * field (otherwise) */ public Component getEditorComponent(final PropertyEditor editor) { String[] tags = editor.getTags(); String text = editor.getAsText(); if (editor.supportsCustomEditor()) { return editor.getCustomEditor(); } else if (tags != null) { // make a combo box that shows all tags final JComboBox comboBox = new JComboBox(tags); comboBox.setSelectedItem(text); comboBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) editor.setAsText((String) comboBox.getSelectedItem()); } }); return comboBox; } else { final JTextField textField = new JTextField(text, 10); textField .getDocument() .addDocumentListener( new DocumentListener() { public void insertUpdate(DocumentEvent e) { try { editor.setAsText(textField.getText()); } catch (IllegalArgumentException exception) { } } public void removeUpdate(DocumentEvent e) { try { editor.setAsText(textField.getText()); } catch (IllegalArgumentException exception) { } } public void changedUpdate(DocumentEvent e) {} }); return textField; } }
public static PropertyAction createIfEditable(RADProperty<?> property) { PropertyEditor propEd = property.getPropertyEditor(); return propEd != null && propEd.supportsCustomEditor() ? new PropertyAction(property) : null; }