public void actionPerformed(ActionEvent e) {
Object o = e.getSource();
if (o == mNewBtn) {
EditFilterComponentDlg dlg = new EditFilterComponentDlg(mParent);
FilterComponent rule = dlg.getFilterComponent();
if (rule != null) {
mComponentTableModel.addElement(rule);
tvbrowser.core.filters.FilterComponentList.getInstance().add(rule);
String text = mFilterRuleTF.getText();
if (text.length() > 0) {
text += " " + mFilterLocalizer.msg("or", "or") + " ";
}
text += rule.getName();
mFilterRuleTF.setText(text);
}
} else if (o == mEditBtn) {
int inx = mRuleTableBox.getSelectedRow();
if(inx == -1) {
return;
}
FilterComponent rule = mComponentTableModel.getElement(inx);
FilterComponentList.getInstance().remove(rule.getName());
mComponentTableModel.removeElement(rule);
EditFilterComponentDlg dlg = new EditFilterComponentDlg(mParent, rule);
FilterComponent newRule = dlg.getFilterComponent();
if (newRule == null) {
newRule = rule;
}
FilterComponentList.getInstance().add(newRule);
mComponentTableModel.addElement(newRule);
// mRuleListBox.repaint();
updateBtns();
} else if (o == mRuleTableBox) {
updateBtns();
} else if (o == mRemoveBtn) {
boolean allowRemove = true;
UserFilter[] userFilterArr = mFilterList.getUserFilterArr();
FilterComponent fc = mComponentTableModel.getElement(mRuleTableBox.getSelectedRow());
// Create the Filter based on the new Rule and check if the FC exists
// there
UserFilter testFilter = new UserFilter("test");
try {
testFilter.setRule(mFilterRuleTF.getText());
if (testFilter.containsRuleComponent(fc.getName())) {
allowRemove = false;
JOptionPane.showMessageDialog(this, mLocalizer.msg("usedByAnotherFilter",
"This filter component is used by filter '{0}'\nRemove the filter first.", mFilterNameTF.getText()));
}
} catch (Exception ex) {
// Filter creation failed, assume the old one is correct
if ((mFilter != null) && (mFilter.containsRuleComponent(fc.getName()))) {
allowRemove = false;
JOptionPane.showMessageDialog(this, mLocalizer.msg("usedByAnotherFilter",
"This filter component is used by filter '{0}'\nRemove the filter first.", mFilterNameTF.getText()));
}
}
for (int i = 0; i < userFilterArr.length && allowRemove; i++) {
if ((userFilterArr[i] != mFilter) && userFilterArr[i].containsRuleComponent(fc.getName())) {
allowRemove = false;
JOptionPane.showMessageDialog(this, mLocalizer.msg("usedByAnotherFilter",
"This filter component is used by filter '{0}'\nRemove the filter first.", userFilterArr[i].toString()));
}
}
if (allowRemove) {
FilterComponentList.getInstance().remove(fc.getName());
mComponentTableModel.removeElement(mRuleTableBox.getSelectedRow());
updateBtns();
}
} else if (o == mOkBtn) {