|
What this is
Other links
The source code// $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/WrapperEditor.java,v 1.8 2004/02/10 21:24:01 jsalvata Exp $ /* * Copyright 2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.jmeter.testbeans.gui; import java.awt.Component; import java.beans.PropertyChangeEvent; 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; /** * This is an implementation of a full-fledged property editor, providing * both object-text transformation and an editor GUI (a custom editor * component), from two simpler property editors providing only one * of these functionalities each, namely: *
* The resulting editor provides optional support for null values (you
* can choose whether null is to be a valid property value).
* It also provides optional support for JMeter 'expressions' (you can
* choose whether they make valid property values).
*
* @author Jordi Salvat i Alabart
* @version $Revision: 1.8 $ updated on $Date: 2004/02/10 21:24:01 $
*/
class WrapperEditor extends PropertyEditorSupport
implements PropertyChangeListener
{
protected static Logger log= LoggingManager.getLoggerForClass();
/**
* The type's property editor.
*/
PropertyEditor typeEditor;
/**
* The gui property editor
*/
PropertyEditor guiEditor;
/**
* Whether to allow null as a property value.
*/
boolean acceptsNull;
/**
* Whether to allow JMeter 'expressions' as property values.
*/
boolean acceptsExpressions;
/**
* Whether to allow any constant values different from the provided tags.
*/
boolean acceptsOther;
/**
* Keep track of the last valid value in the editor, so that we can
* revert to it if the user enters an invalid value.
*/
private String lastValidValue= null;
/**
* Constructor for use when a PropertyEditor is delegating to us.
*/
WrapperEditor(
Object source,
PropertyEditor typeEditor,
PropertyEditor guiEditor,
boolean acceptsNull,
boolean acceptsExpressions,
boolean acceptsOther,
Object defaultValue)
{
super(source);
initialize(typeEditor, guiEditor, acceptsNull, acceptsExpressions,
acceptsOther, defaultValue);
}
/**
* Constructor for use for regular instantiation and by subclasses.
*/
WrapperEditor(
PropertyEditor typeEditor,
PropertyEditor guiEditor,
boolean acceptsNull,
boolean acceptsExpressions,
boolean acceptsOther,
Object defaultValue)
{
super();
initialize(typeEditor, guiEditor, acceptsNull, acceptsExpressions,
acceptsOther, defaultValue);
}
private void initialize(
PropertyEditor typeEditor,
PropertyEditor guiEditor,
boolean acceptsNull,
boolean acceptsExpressions,
boolean acceptsOther,
Object defaultValue)
{
this.typeEditor= typeEditor;
this.guiEditor= guiEditor;
this.acceptsNull= acceptsNull;
this.acceptsExpressions= acceptsExpressions;
this.acceptsOther= acceptsOther;
setValue(defaultValue);
lastValidValue= getAsText();
if (guiEditor instanceof ComboStringEditor)
{
String[] tags= ((ComboStringEditor)guiEditor).getTags();
// Provide an initial edit value if necessary -- this is an
// heuristic that tries to provide the most convenient
// initial edit value:
String v;
if (! acceptsOther) v="${}";
else if (isValidValue("")) v= "";
else if (acceptsExpressions) v= "${}";
else if (tags != null && tags.length>0) v= tags[0];
else v= getAsText();
((ComboStringEditor)guiEditor).setInitialEditValue(v);
}
guiEditor.addPropertyChangeListener(this);
}
public boolean supportsCustomEditor()
{
return true;
}
public Component getCustomEditor()
{
return guiEditor.getCustomEditor();
}
public String[] getTags()
{
return guiEditor.getTags();
}
/**
* Determine wheter a string is one of the known tags.
*
* @param text
* @return true iif text equals one of the getTags()
*/
private boolean isATag(String text)
{
String[] tags= getTags();
if (tags == null) return false;
for (int i=0; i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.