Index: src/org/netbeans/modules/debugger/support/StopAction.java =================================================================== RCS file: /cvs/debuggercore/src/org/netbeans/modules/debugger/support/StopAction.java,v retrieving revision 1.9 diff -u -r1.9 StopAction.java --- src/org/netbeans/modules/debugger/support/StopAction.java 2001/03/06 11:39:12 1.9 +++ src/org/netbeans/modules/debugger/support/StopAction.java 2001/06/22 15:01:44 @@ -23,6 +23,7 @@ import org.openide.util.NbBundle; import org.netbeans.modules.debugger.CoreBreakpoint; +import org.netbeans.modules.debugger.support.util.Utils; /** * This actions stops debugging. @@ -47,24 +48,9 @@ public Node.Property[] getProperties () { ResourceBundle bundle = NbBundle.getBundle (StopAction.class); return new Node.Property[] { - new PropertySupport.ReadWrite ( - StopAction.PROP_STOP, - Boolean.TYPE, - bundle.getString ("PROP_stop"), - bundle.getString ("HINT_stop") - ) { - public Object getValue () { - return new Boolean (getStop ()); - } - public void setValue (Object val) throws IllegalArgumentException { - try { - setStop (((Boolean)val).booleanValue ()); - } catch (ClassCastException e) { - throw new IllegalArgumentException (); - } - } - } - }; + Utils.createProperty (this, Boolean.TYPE, PROP_STOP, bundle, + "getStop", "setStop" ) + }; } /** Index: src/org/netbeans/modules/debugger/support/java/nodes/JavaThreadNode.java =================================================================== RCS file: /cvs/debuggercore/src/org/netbeans/modules/debugger/support/java/nodes/JavaThreadNode.java,v retrieving revision 1.6 diff -u -r1.6 JavaThreadNode.java --- src/org/netbeans/modules/debugger/support/java/nodes/JavaThreadNode.java 2001/05/23 16:05:33 1.6 +++ src/org/netbeans/modules/debugger/support/java/nodes/JavaThreadNode.java 2001/06/22 15:01:44 @@ -45,6 +45,7 @@ import org.netbeans.modules.debugger.support.actions.*; import org.netbeans.modules.debugger.support.java.MonitorInfoProducer; +import org.netbeans.modules.debugger.support.util.Utils; /** * This class representates threads and threadGroups as a Node. @@ -160,110 +161,40 @@ // default sheet with "properties" property set // NOI18N Sheet sheet = Sheet.createDefault(); Sheet.Set props = sheet.get(Sheet.PROPERTIES); - props.put (new PropertySupport.ReadOnly ( - PROP_THREAD_NAME, - String.class, - getLocalizedString ("PROP_thread_name"), - getLocalizedString ("HINT_thread_name") - ) { - public Object getValue () throws InvocationTargetException { - try { - return thread.getName (); - } catch (java.lang.Exception e) { - throw new InvocationTargetException (e); - } - } - }); - props.put (new PropertySupport.ReadOnly ( - PROP_THREAD_STATE, - String.class, - getLocalizedString ("PROP_thread_state"), - getLocalizedString ("HINT_thread_state") - ) { - public Object getValue () throws InvocationTargetException { - try { - return thread.getState (); - } catch (java.lang.Exception e) { - throw new InvocationTargetException (e); - } - } - }); - props.put (new PropertySupport.ReadOnly ( - PROP_THREAD_CLASS, - String.class, - getLocalizedString ("PROP_thread_class"), - getLocalizedString ("HINT_thread_class") - ) { - public Object getValue () throws InvocationTargetException { - try { - return thread.getClassName (); - } catch (java.lang.Exception e) { - throw new InvocationTargetException (e); - } - } - }); - props.put (new PropertySupport.ReadOnly ( - PROP_THREAD_METHOD, - String.class, - getLocalizedString ("PROP_thread_method"), - getLocalizedString ("HINT_thread_method") - ) { - public Object getValue () throws InvocationTargetException { - try { - return thread.getMethod (); - } catch (java.lang.Exception e) { - throw new InvocationTargetException (e); - } - } - }); - props.put (new PropertySupport.ReadOnly ( - PROP_THREAD_LINE, - Integer.TYPE, - getLocalizedString ("PROP_thread_line"), - getLocalizedString ("HINT_thread_line") - ) { - public Object getValue () throws InvocationTargetException { - try { - return new Integer (thread.getLineNumber ()); - } catch (java.lang.Exception e) { - throw new InvocationTargetException (e); - } - } - }); - props.put (new PropertySupport.ReadOnly ( - PROP_THREAD_STACK_DEPTH, - Integer.TYPE, - getLocalizedString ("PROP_thread_stack_depth"), - getLocalizedString ("HINT_thread_stack_depth") - ) { - public Object getValue () throws InvocationTargetException { - try { - return new Integer (thread.getStackDepth ()); - } catch (java.lang.Exception e) { - throw new InvocationTargetException (e); - } - } - }); - props.put (new PropertySupport.ReadWrite ( - PROP_THREAD_SUSPENDED, - Boolean.TYPE, - getLocalizedString ("PROP_thread_suspended"), - getLocalizedString ("HINT_thread_suspended") - ) { - public Object getValue () throws InvocationTargetException { - try { - return new Boolean (thread.isSuspended ()); - } catch (java.lang.Exception e) { - throw new InvocationTargetException (e); - } - } - public void setValue (Object val) throws - InvocationTargetException { - if (!(val instanceof Boolean)) - throw new IllegalArgumentException (); - setSuspended (((Boolean)val).booleanValue ()); - } - }); + props.put (Utils.createProperty (thread, String.class, PROP_THREAD_NAME, + getLocalizedString ("PROP_thread_name"), + getLocalizedString ("HINT_thread_name"), + "getName", null)); + + props.put (Utils.createProperty (thread, String.class, PROP_THREAD_STATE, + getLocalizedString ("PROP_thread_state"), + getLocalizedString ("HINT_thread_state"), + "getState", null)); + + props.put (Utils.createProperty (thread, String.class, PROP_THREAD_CLASS, + getLocalizedString ("PROP_thread_class"), + getLocalizedString ("HINT_thread_class"), + "getClassName", null)); + + props.put (Utils.createProperty (thread, String.class, PROP_THREAD_METHOD, + getLocalizedString ("PROP_thread_method"), + getLocalizedString ("HINT_thread_method"), + "getMethod", null)); + + props.put (Utils.createProperty (thread, Integer.TYPE, PROP_THREAD_LINE, + getLocalizedString ("PROP_thread_line"), + getLocalizedString ("HINT_thread_line"), + "getLineNumber", null)); + + props.put (Utils.createProperty (thread, Integer.TYPE, PROP_THREAD_STACK_DEPTH, + getLocalizedString ("PROP_thread_stack_depth"), + getLocalizedString ("HINT_thread_stack_depth"), + "getStackDepth", null)); + + props.put (Utils.createProperty (thread, Boolean.TYPE, PROP_THREAD_SUSPENDED, + getLocalizedString ("PROP_thread_suspended"), + getLocalizedString ("HINT_thread_suspended"), + "isSuspended", "setSuspended")); // and set new sheet setSheet (sheet); } Index: src/org/netbeans/modules/debugger/support/nodes/VariableNode.java =================================================================== RCS file: /cvs/debuggercore/src/org/netbeans/modules/debugger/support/nodes/VariableNode.java,v retrieving revision 1.30 diff -u -r1.30 VariableNode.java --- src/org/netbeans/modules/debugger/support/nodes/VariableNode.java 2001/05/23 16:05:33 1.30 +++ src/org/netbeans/modules/debugger/support/nodes/VariableNode.java 2001/06/22 15:01:44 @@ -140,16 +140,12 @@ // default sheet with "properties" property set // NOI18N Sheet sheet = Sheet.createDefault (); Sheet.Set ps = sheet.get (Sheet.PROPERTIES); - ps.put (new PropertySupport.ReadOnly ( - Watch.PROP_VARIABLE_NAME, - String.class, - getLocalizedString ("PROP_watch_name"), - getLocalizedString ("HINT_watch_name") - ) { - public Object getValue () { - return variable.getVariableName (); - } - }); + ps.put (Utils.createProperty (variable, String.class, + Watch.PROP_VARIABLE_NAME, + getLocalizedString ("PROP_watch_name"), + getLocalizedString ("HINT_watch_name"), + "getVariableName", null) + ); createCommonProperties (ps); // and set new sheet setSheet (sheet); @@ -179,37 +175,15 @@ /** Helper method, creates properties common to variable * and watch contexts. */ - void createCommonProperties ( - final Sheet.Set ps - ) { - ps.put (new PropertySupport.ReadOnly ( - Watch.PROP_TYPE, - String.class, - getLocalizedString ("PROP_watch_type"), - getLocalizedString ("HINT_watch_type") - ) { - public Object getValue () { - return variable.getType (); - } - }); - ps.put (new PropertySupport.ReadWrite ( - Watch.PROP_AS_TEXT, - String.class, - getLocalizedString ("PROP_watch_value"), - getLocalizedString ("HINT_watch_value") - ) { - public Object getValue () { - return variable.getAsText (); - } - public void setValue (Object val) throws IllegalArgumentException { - try { - variable.setAsText ((String)val); - } catch (ClassCastException e) { - throw new IllegalArgumentException (); - } - catch (DebuggerException e) {} - } - }); + void createCommonProperties (final Sheet.Set ps) { + ps.put (Utils.createProperty (variable, String.class, Watch.PROP_TYPE, + getLocalizedString ("PROP_watch_type"), + getLocalizedString ("HINT_watch_type"), + "getType", null)); + ps.put (Utils.createProperty (variable, String.class, Watch.PROP_AS_TEXT, + getLocalizedString ("PROP_watch_value"), + getLocalizedString ("HINT_watch_value"), + "getAsText", null)); } /** Index: src/org/netbeans/modules/debugger/support/util/Utils.java =================================================================== RCS file: /cvs/debuggercore/src/org/netbeans/modules/debugger/support/util/Utils.java,v retrieving revision 1.47 diff -u -r1.47 Utils.java --- src/org/netbeans/modules/debugger/support/util/Utils.java 2001/06/21 18:30:34 1.47 +++ src/org/netbeans/modules/debugger/support/util/Utils.java 2001/06/22 15:01:44 @@ -21,6 +21,7 @@ import org.openide.text.Line; import org.openide.text.NbDocument; import org.openide.nodes.Node; +import org.openide.nodes.PropertySupport; import org.openide.loaders.DataNode; import org.openide.src.*; import org.openide.cookies.LineCookie; @@ -1044,6 +1045,34 @@ ); } }; + + + public static Node.Property createProperty (Object inst, Class type, + String name, String dispName, + String shortDesc, + String getter, String setter ) { + Node.Property prop; + + try { + prop = new PropertySupport.Reflection (inst, type, getter, setter); + } catch (NoSuchMethodException e) { + throw new IllegalStateException (e.getMessage()); + } + + prop.setName (name); + prop.setDisplayName (dispName); + prop.setShortDescription (shortDesc); + return prop; + } + + public static Node.Property createProperty (Object instance, Class type, + String name, ResourceBundle bundle, + String getter, String setter ) { + return createProperty( instance, type, name, + bundle.getString("PROP_" + name), bundle.getString("HINT_" + name), + getter, setter); + } + // innerclasses .........................................................................