use of java.beans.PropertyEditor in project geronimo-xbean by apache.
the class PropertyEditors method toString.
public static String toString(Object value) throws PropertyEditorException {
if (value == null)
throw new NullPointerException("value is null");
// get an editor for this type
Class type = value.getClass();
PropertyEditor editor = findConverterOrEditor(type);
if (editor instanceof Converter) {
Converter converter = (Converter) editor;
return converter.toString(value);
}
if (editor == null) {
throw new PropertyEditorException("Unable to find PropertyEditor for " + type.getSimpleName());
}
// create the string value
editor.setValue(value);
String textValue;
try {
textValue = editor.getAsText();
} catch (Exception e) {
throw new PropertyEditorException("Error while converting a \"" + type.getSimpleName() + "\" to text " + " using the property editor " + editor.getClass().getSimpleName(), e);
}
return textValue;
}
use of java.beans.PropertyEditor in project JWildfire by thargor6.
the class DancingFractalsController method motionTableClicked.
public void motionTableClicked() {
if (!refreshing) {
if (motionPropertyPnl != null) {
motionPropertyRootPnl.remove(motionPropertyPnl);
motionPropertyPnl = null;
}
if (project.getMotions().size() > 0 && motionTable.getSelectedRow() >= 0 && motionTable.getSelectedRow() < project.getMotions().size()) {
Motion motion = project.getMotions().get(motionTable.getSelectedRow());
@SuppressWarnings("rawtypes") Map<Class, PropertyEditor> editors = new HashMap<Class, PropertyEditor>();
editors.put(Motion.class, new MotionTypeEditor(project.getMotions()));
motionPropertyPnl = new PropertyPanel(motion, editors);
motionPropertyPnl.setDescriptionVisible(false);
PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
refreshing = true;
try {
int oldSel = motionTable.getSelectedRow();
refreshMotionTable();
motionTable.getSelectionModel().setSelectionInterval(oldSel, oldSel);
enableControls();
} finally {
refreshing = false;
}
}
};
motionPropertyPnl.addPropertySheetChangeListener(listener);
motionPropertyRootPnl.add(motionPropertyPnl, BorderLayout.CENTER);
enableControls();
}
}
refreshMotionLinksTable();
motionPropertyRootPnl.invalidate();
motionPropertyRootPnl.validate();
}
use of java.beans.PropertyEditor in project opennms by OpenNMS.
the class Global method convertStringTo.
public <T> T convertStringTo(String value, Class<T> typeClass) {
if (typeClass == String.class) {
return typeClass.cast(value);
} else {
try {
final PropertyEditor editor = getDefaultEditor(typeClass);
editor.setAsText(value);
return typeClass.cast(editor.getValue());
} catch (Exception e) {
throw new IllegalArgumentException("Unable to find a property editor for " + typeClass);
}
}
}
use of java.beans.PropertyEditor in project opennms by OpenNMS.
the class Coercions method coerceToObject.
// -------------------------------------
/**
* Coerces a value to the specified Class that is not covered by any
* of the above cases
*/
public static Object coerceToObject(Object pValue, Class pClass, Logger pLogger) throws ELException {
if (pValue == null) {
return null;
} else if (pClass.isAssignableFrom(pValue.getClass())) {
return pValue;
} else if (pValue instanceof String) {
String str = (String) pValue;
PropertyEditor pe = PropertyEditorManager.findEditor(pClass);
if (pe == null) {
if ("".equals(str)) {
return null;
} else {
if (pLogger.isLoggingError()) {
pLogger.logError(Constants.NO_PROPERTY_EDITOR, str, pClass.getName());
}
return null;
}
}
try {
pe.setAsText(str);
return pe.getValue();
} catch (IllegalArgumentException exc) {
if ("".equals(str)) {
return null;
} else {
if (pLogger.isLoggingError()) {
pLogger.logError(Constants.PROPERTY_EDITOR_ERROR, exc, pValue, pClass.getName());
}
return null;
}
}
} else {
if (pLogger.isLoggingError()) {
pLogger.logError(Constants.COERCE_TO_OBJECT, pValue.getClass().getName(), pClass.getName());
}
return null;
}
}
use of java.beans.PropertyEditor in project opennms by OpenNMS.
the class Global method convertStringTo.
/**
* Convert string to.
*
* @param <T> the generic type
* @param value the value
* @param typeClass the type class
* @return the t
*/
public <T> T convertStringTo(String value, Class<T> typeClass) {
if (typeClass == String.class) {
return typeClass.cast(value);
} else {
try {
final PropertyEditor editor = getDefaultEditor(typeClass);
editor.setAsText(value);
return typeClass.cast(editor.getValue());
} catch (Exception e) {
throw new IllegalArgumentException("Unable to find a property editor for " + typeClass);
}
}
}
Aggregations