This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 183336 - CustomProperty Editor example does not work properly
Summary: CustomProperty Editor example does not work properly
Status: NEW
Alias: None
Product: usersguide
Classification: Unclassified
Component: IDE (show other bugs)
Version: -S1S-
Hardware: PC Linux
: P3 normal (vote)
Assignee: issues@mobility
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-01 10:22 UTC by toki78
Modified: 2011-11-16 16:40 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description toki78 2010-04-01 10:22:11 UTC
Hi,
I tried out your example
http://platform.netbeans.org/tutorials/60/nbm-property-editors.html
Unfortunately it doesn't work. The editor does not store the value.
I applied some minor changes, but I'm not sure, if this is Netbeans conformant.



import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorSupport;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.openide.explorer.propertysheet.ExPropertyEditor;
import org.openide.explorer.propertysheet.InplaceEditor;
import org.openide.explorer.propertysheet.PropertyEnv;
import org.openide.explorer.propertysheet.PropertyModel;
import org.openide.util.Exceptions;

/**
 *
 * @author thorsten
 */
public class RahmenstilPropertyEditor extends PropertyEditorSupport
        implements ExPropertyEditor, InplaceEditor.Factory {

    private static final String[] values = new String[]{
        "none", "dotted", "dashed", "solid", "double",
        "groove", "ridge", "inset", "outset"};

    @Override
    public String getAsText() {
        return getValue().toString();
    }

    @Override
    public boolean supportsCustomEditor() {
        return false;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        ed.cb.setSelectedItem(text);
        setValue(text);
    }

    public void attachEnv(PropertyEnv pe) {
        pe.registerInplaceEditorFactory(this);
    }
    private Inplace ed = new Inplace();

    public InplaceEditor getInplaceEditor() {
        if (ed == null) {
            ed = new Inplace();
        }
        return ed;
    }

    private class Inplace implements InplaceEditor, ActionListener {

        private PropertyEditor editor = null;
        private PropertyEnv propertyEnv = null;
        public JComboBox cb = new JComboBox(values);
        private PropertyModel model = null;

        public void connect(PropertyEditor propertyEditor, PropertyEnv env) {
            editor = propertyEditor;
            propertyEnv = env;
            reset();
            cb.addActionListener(this);
        }

        public JComponent getComponent() {
            return cb;
        }

        public void clear() {
            //avoid memory leaks:
            editor = null;
            model = null;
            cb.removeActionListener(this);
        }

        public Object getValue() {
            try {
                return model.getValue();
            } catch (InvocationTargetException ex) {
                Exceptions.printStackTrace(ex);
                return null;
            }
        }

        public void setValue(Object object) {
            cb.setSelectedItem(object);
            try {
                model.setValue(object);
            } catch (InvocationTargetException ex) {
                Exceptions.printStackTrace(ex);
            }
        }

        public boolean supportsTextEntry() {
            return false;
        }

        public void reset() {
            cb.setSelectedIndex(0);
        }

        public KeyStroke[] getKeyStrokes() {
            return new KeyStroke[0];
        }

        public PropertyEditor getPropertyEditor() {
            return editor;
        }

        public PropertyModel getPropertyModel() {
            return model;
        }

        public void setPropertyModel(PropertyModel propertyModel) {
            model = propertyModel;
        }

        public boolean isKnownComponent(Component component) {
            return component == cb || cb.isAncestorOf(component);
        }

        public void addActionListener(ActionListener actionListener) {
        }

        public void removeActionListener(ActionListener actionListener) {
        }

        public void actionPerformed(ActionEvent e) {
            try {
                model.setValue(cb.getSelectedItem());
            } catch (InvocationTargetException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
}

Best Regards
Thorsten Kiefer
Comment 1 Irina Filippova 2010-04-01 16:16:37 UTC
Assigning to Geertjan for evaluation. Geertjan, can you please take a look?
Comment 2 Geertjan Wielenga 2010-04-01 22:29:23 UTC
You're by no means the first person to have followed the tutorial. Anyway, reassigning this to Tim Boudreau, who wrote the tutorial.
Comment 3 Geertjan Wielenga 2010-04-01 22:30:23 UTC
And, by the way, here is the current version of the tutorial:

http://platform.netbeans.org/tutorials/nbm-property-editors.html
Comment 4 _ tboudreau 2011-05-26 02:44:48 UTC
Uy... I *am* the default assignee for javacard...