jsalvata 2004/02/05 01:52:26
Modified: src/core/org/apache/jmeter/resources messages.properties
src/core/org/apache/jmeter/testbeans/gui
FieldStringEditor.java WrapperEditor.java
src/core/org/apache/jmeter/gui/action EditCommand.java
Log:
Warn user when a property value he entered is not accepted.
Revision Changes Path
1.97 +2 -0
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties
Index: messages.properties
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -r1.96 -r1.97
--- messages.properties 5 Feb 2004 01:54:36 -0000 1.96
+++ messages.properties 5 Feb 2004 09:52:26 -0000 1.97
@@ -286,6 +286,8 @@
property_as_field_label={0}\:
property_default_param=Default value
property_edit=Edit
+property_editor.value_is_invalid_message=The text you just entered is not a valid
value for this property.\nThe property will be reverted to its previous value.
+property_editor.value_is_invalid_title=Invalid input
property_name_param=Name of property
property_tool_tip={0}\: {1}
property_undefined=Undefined
1.3 +22 -10
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java
Index: FieldStringEditor.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FieldStringEditor.java 14 Jan 2004 23:10:30 -0000 1.2
+++ FieldStringEditor.java 5 Feb 2004 09:52:26 -0000 1.3
@@ -89,12 +89,10 @@
private JTextField textField;
/**
- * True iif we're currently processing an event triggered by the user
- * selecting or entering a new value. Used to prevent touching at
- * GUI states outside of the event handling method -- otherwise it's
- * a mess.
+ * Value on which we started the editing. Used to avoid firing
+ * PropertyChanged events when there's not been such change.
*/
- private boolean processingItemEvent= false;
+ private String initialValue= "";
protected FieldStringEditor()
{
@@ -112,6 +110,7 @@
public void setAsText(String value)
{
+ initialValue= value;
textField.setText(value);
}
@@ -134,14 +133,27 @@
return textField;
}
+ /* (non-Javadoc)
+ * Avoid needlessly firing PropertyChanged events.
+ */
+ public void firePropertyChange()
+ {
+ String newValue= getAsText();
+
+ if (initialValue.equals(newValue)) return;
+ initialValue= newValue;
+
+ super.firePropertyChange();
+ }
+
/* (non-Javadoc)
* @see
java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e)
- {
- firePropertyChange();
- }
-
+ {
+ firePropertyChange();
+ }
+
/* (non-Javadoc)
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
*/
1.7 +14 -39
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/WrapperEditor.java
Index: WrapperEditor.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/WrapperEditor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WrapperEditor.java 28 Jan 2004 10:35:16 -0000 1.6
+++ WrapperEditor.java 5 Feb 2004 09:52:26 -0000 1.7
@@ -62,6 +62,10 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorSupport;
+
+import javax.swing.JOptionPane;
+
+import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
@@ -122,37 +126,6 @@
*/
private String lastValidValue= null;
-/*
-I formerly used this method to obtain a type against which I could
-validate property values, e.g. in isValidProperty. Later I found that
-simple propertyEditors can do this in a simpler way -- they throw
-InvalidValueException if the value is not of the appropriate type.
-
-TODO: remove this code once I'm reasonably convinced that what
-I said above is true (so I won't need to reinstate this code).
-
- private static Class objectType(Class type)
- {
- // Sorry for this -- I have not found a better way:
- if (! type.isPrimitive()) return type;
- else if (type == boolean.class) return Boolean.class;
- else if (type == char.class) return Character.class;
- else if (type == byte.class) return Byte.class;
- else if (type == short.class) return Short.class;
- else if (type == int.class) return Integer.class;
- else if (type == long.class) return Long.class;
- else if (type == float.class) return Float.class;
- else if (type == double.class) return Double.class;
- else if (type == void.class) return Void.class;
- else
- {
- log.error("Class "+type+" is an unknown primitive type.");
- throw new Error("Class "+type+" is an unknown primitive type");
- // programming error: bail out.
- }
- }
-*/
-
/**
* Constructor for use when a PropertyEditor is delegating to us.
*/
@@ -201,6 +174,7 @@
this.acceptsOther= acceptsOther;
setValue(defaultValue);
+ lastValidValue= getAsText();
if (guiEditor instanceof ComboStringEditor)
{
@@ -496,13 +470,14 @@
}
else
{
- if (log.isDebugEnabled())
- {
- log.debug("Invalid value. Reverting to last valid value.");
- }
- // TODO: warn the user. Maybe with a pop-up? A bell?
-
- // Revert to the previously unselected (presumed valid!) value:
+ // TODO: how to bring the editor back in view & focus?
+ JOptionPane.showMessageDialog(
+ guiEditor.getCustomEditor().getParent(),
+
JMeterUtils.getResString("property_editor.value_is_invalid_message"),
+ JMeterUtils.getResString("property_editor.value_is_invalid_title"),
+ JOptionPane.WARNING_MESSAGE);
+
+ // Revert to the previous value:
guiEditor.setAsText(lastValidValue);
}
}
1.5 +3 -1
jakarta-jmeter/src/core/org/apache/jmeter/gui/action/EditCommand.java
Index: EditCommand.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/EditCommand.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- EditCommand.java 27 Jun 2003 19:12:54 -0000 1.4
+++ EditCommand.java 5 Feb 2004 09:52:26 -0000 1.5
@@ -33,6 +33,8 @@
.getTreeListener()
.getCurrentNode())
.createPopupMenu());
+ // TODO: I believe the following code (to the end of the method) is
obsolete,
+ // since NamePanel no longer seems to be the GUI for any component:
if (!(guiPackage.getCurrentGui() instanceof NamePanel))
{
guiPackage.getMainFrame().setFileLoadEnabled(true);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]