editionPanel.setEnabled(!isEmpty);
if (isEmpty) {
btnRename.setEnabled(false);
btnRemove.setEnabled(false);
} else {
LogType logType = (LogType) lstTypes.getSelectedValue();
LogTypeManager logTypes = LogTypeManager.getInstance();
logType = logTypes.loadFromFile(logType
.getName());
editionPanel.setLogType(logType);
btnRename.setEnabled(true);
btnRemove.setEnabled(true);
}
}
});
scrollTypes = new JScrollPane(lstTypes);
btnAdd = new JButton(Translator.tr("Add"));
btnAdd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = JOptionPane.showInputDialog(getParent(),
Translator.tr("Enter the name of the new log type"));
if (name == null) {
return;
}
name = name.trim();
if (name.length() == 0) {
DialogFactory.showErrorMessage(null,
Translator.tr("Invalid log type name"));
return;
}
LogType logType = new LogType(name);
try {
LogTypeManager logTypes = LogTypeManager.getInstance();
logTypes.saveToFile(logType);
updateLogTypes();
} catch (IOException ee) {
logger.warning(ee.getMessage());
}
}
});
btnRename = new JButton(Translator.tr("Rename"));
btnRename.setEnabled(false);
btnRename.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
LogType selected = (LogType) lstTypes.getSelectedValue();
String newName = JOptionPane.showInputDialog(getParent(),
tr("Enter the new name of the log type:"),
selected.getName());
if (newName == null) {
return;
}
newName = newName.trim();
if (newName.length() > 0 && !newName.equals(selected.getName())) {
LogTypeManager logTypes = LogTypeManager.getInstance();
logTypes.rename(selected, newName);
updateLogTypes();
}
}
});
btnRemove = new JButton(Translator.tr("Remove"));
btnRemove.setEnabled(false);
btnRemove.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
if (DialogFactory.showQuestionDialog(getParent(), Translator
.tr("Are you sure you want to delete the selected log type?"))) {
LogType selected = (LogType) lstTypes.getSelectedValue();
LogTypeManager logTypes = LogTypeManager.getInstance();
if (!logTypes.remove(selected)) {
DialogFactory.showErrorMessage(getParent(),
Translator.tr("Unable to delete the log type"));
}