/**
* Updates the currently selected entry from the values found in the detail editor.
*/
protected void writeSelectedEntry()
{
final ConfigDescriptionEntry entry;
switch (getEntryType())
{
case ConfigDescriptionEditor.TYPE_CLASS:
{
final ClassConfigDescriptionEntry ce = new ClassConfigDescriptionEntry(keyNameField.getText());
ce.setDescription(descriptionField.getText());
ce.setGlobal(globalField.isSelected());
ce.setHidden(hiddenField.isSelected());
try
{
final String className = baseClassField.getText();
if (className == null)
{
ce.setBaseClass(Object.class);
}
else
{
final ClassLoader classLoader = ObjectUtilities.getClassLoader(getClass());
final Class c = Class.forName(className, false, classLoader);
ce.setBaseClass(c);
}
}
catch (Exception e)
{
// invalid
ConfigDescriptionEditor.logger.debug("Class is invalid; defaulting to Object.class"); //$NON-NLS-1$
ce.setBaseClass(Object.class);
}
entry = ce;
break;
}
case ConfigDescriptionEditor.TYPE_ENUM:
{
final EnumConfigDescriptionEntry ece = new EnumConfigDescriptionEntry(keyNameField.getText());
ece.setDescription(descriptionField.getText());
ece.setGlobal(globalField.isSelected());
ece.setHidden(hiddenField.isSelected());
final String[] enumEntries = new String[enumEntryListModel.getSize()];
for (int i = 0; i < enumEntryListModel.getSize(); i++)
{
enumEntries[i] = String.valueOf(enumEntryListModel.get(i));
}
ece.setOptions(enumEntries);
entry = ece;
break;
}
default:
{
final TextConfigDescriptionEntry te = new TextConfigDescriptionEntry(keyNameField.getText());
te.setDescription(descriptionField.getText());
te.setGlobal(globalField.isSelected());
te.setHidden(hiddenField.isSelected());
entry = te;
break;
}
}
final ConfigDescriptionEntry selectedEntry = getSelectedEntry();
if (selectedEntry == null)
{
model.add(entry);
return;
}
if (ObjectUtilities.equal(selectedEntry.getKeyName(), entry.getKeyName()) == false)
{
model.remove(selectedEntry);
}
model.add(entry);