use of maspack.widgets.AutoCompleteStringField in project artisynth_core by artisynth.
the class MenuBarHandler method selectClass.
private Class<?> selectClass(String existingClassName) {
// ClassDialog dialog =
// ClassDialog.createDialog (
// myFrame, "Choose model class", "Load", "class", existingClassName);
WidgetDialog dialog = WidgetDialog.createDialog(myFrame, "Choose model class", "Load");
// find all instances of 'RootModel' and create an AutoComplete test field
ArrayList<String> demoClassNames = ClassFinder.findClassNames("artisynth.models", RootModel.class);
AutoCompleteStringField widget = new AutoCompleteStringField("class:", lastSelectedClassName, 30, demoClassNames);
// widget.addValueCheckListener (
// new ValueCheckListener() {
// public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
// String className = (String)e.getValue();
// if (className != null || !className.equals("")) {
// Class type = getClassFromName (className);
// if (type == null) {
// return PropertyUtils.illegalValue (
// "class not found", errMsg);
// }
// if (!RootModel.class.isAssignableFrom (type)) {
// return PropertyUtils.illegalValue (
// "class not an instance of RootModel", errMsg);
// }
// }
// return PropertyUtils.validValue (className, errMsg);
// }
// });
dialog.setValidator(new WidgetDialog.Validator() {
public String validateSettings(PropertyPanel panel) {
StringField widget = (StringField) panel.getWidgets()[0];
String className = widget.getStringValue();
if (className != null) {
Class<?> type = getClassFromName(className);
if (type == null) {
return "class not found";
}
if (!RootModel.class.isAssignableFrom(type)) {
return "class not an instance of RootModel";
}
}
return null;
}
});
dialog.addWidget(widget);
GuiUtils.locateCenter(dialog, myFrame);
dialog.setVisible(true);
if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
String className = widget.getStringValue();
if (className != null && !className.equals("")) {
lastSelectedClassName = className;
return getClassFromName(className);
}
}
return null;
}
Aggregations