[hg] main-silver: #229789: Use VetoableChangeListener to assure ...

  • From:
  • To:
  • Subject: [hg] main-silver: #229789: Use VetoableChangeListener to assure ...
  • Date: Mon, 10 Jun 2013 14:35:42 -0700

changeset 1c08714ea7b3 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/1c08714ea7b3
description:
        #229789: Use VetoableChangeListener to assure that the new value is 
set when OK button on the property editor is pressed.

diffstat:

 
debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/ValuePropertyEditor.java
 |  46 ++++++---
 1 files changed, 30 insertions(+), 16 deletions(-)

diffs (87 lines):

diff --git 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/ValuePropertyEditor.java
 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/ValuePropertyEditor.java
--- 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/ValuePropertyEditor.java
+++ 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/ValuePropertyEditor.java
@@ -44,9 +44,12 @@
 import java.awt.Component;
 import java.awt.Graphics;
 import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyEditor;
 import java.beans.PropertyEditorManager;
+import java.beans.PropertyVetoException;
+import java.beans.VetoableChangeListener;
 import java.io.InvalidObjectException;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
@@ -87,6 +90,7 @@
     private PropertyEnv env;
     private final List<PropertyChangeListener> listeners = new 
ArrayList<PropertyChangeListener>();
     private VariablesTableModel vtm;
+    private Validate validate = new Validate();
     
     ValuePropertyEditor(ContextProvider contextProvider) {
         this.contextProvider = contextProvider;
@@ -213,22 +217,7 @@
             logger.log(Level.FINE, "ValuePropertyEditor.getValue() = 
(delegate''s) {0}", dpeValue);
             return dpeValue;
         } else {
-            if (dpeValue != delegateValue && currentValue instanceof 
MutableVariable) {
-                if (!(currentValue instanceof VariableWithMirror)) {
-                    setOrigValue(currentValue);
-                    currentValue = new VariableWithMirror(dpeValue);
-                } else {
-                    ((VariableWithMirror) 
currentValue).setFromMirrorObject(dpeValue);
-                }
-                //setVarFromMirror((MutableVariable) currentValue, dpeValue);
-                /*
-                try {
-                    ((MutableVariable) 
currentValue).setFromMirrorObject(dpeValue);
-                } catch (InvalidObjectException ex) {
-                    // TODO: Warn the user.
-                }
-                */
-            }
+            // Set the value from delegatePropertyEditor when vetoableChange 
is fired.
             logger.log(Level.FINE, "ValuePropertyEditor.getValue() = 
(current) {0}", currentValue);
             return currentValue;
         }
@@ -321,6 +310,8 @@
     @Override
     public void attachEnv(PropertyEnv env) {
         //System.out.println("ValuePropertyEditor.attachEnv("+env+"), 
feature descriptor = "+env.getFeatureDescriptor());
+        env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
+        env.addVetoableChangeListener(validate);
         if (delegatePropertyEditor instanceof ExPropertyEditor) {
             //System.out.println("  attaches to "+delegatePropertyEditor);
             ((ExPropertyEditor) delegatePropertyEditor).attachEnv(env);
@@ -348,6 +339,29 @@
         delegatePropertyEditor.removePropertyChangeListener(listener);
     }
     
+    private class Validate implements VetoableChangeListener {
+
+        @Override
+        public void vetoableChange(PropertyChangeEvent evt) throws 
PropertyVetoException {
+            logger.log(Level.FINE, 
"ValuePropertyEditor.Validate.vetoableChange({0})", evt);
+            if (PropertyEnv.PROP_STATE.equals(evt.getPropertyName())) {
+                Object newValue = delegatePropertyEditor.getValue();
+                logger.log(Level.FINE, "  vetoableChange: delegate PE value 
= {0}", newValue);
+                if (newValue != delegateValue && !(newValue instanceof 
String)) {
+                    setVarFromMirror(((MutableVariable) currentValue), 
newValue);
+                    /*
+                    try {
+                        ((MutableVariable) 
currentValue).setFromMirrorObject(newValue);
+                    } catch (InvalidObjectException ex) {
+                        throw new 
PropertyVetoException(ex.getLocalizedMessage(), evt);
+                    }
+                    */
+                }
+            }
+        }
+        
+    }
+    
     /**
      * An artificial variable that holds the newly set mirror object.
      */

[hg] main-silver: #229789: Use VetoableChangeListener to assure ...

mentlicher 06/10/2013

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close