String comboToolTipText =
"Enter an expression, press enter to add to list";
filterText = (JTextField) filterCombo.getEditor().getEditorComponent();
filterText.setToolTipText(comboToolTipText);
filterText.addKeyListener(
new ExpressionRuleContext(filterModel, filterText));
filterText.getDocument().addDocumentListener(
new DelayedFilterTextDocumentListener(filterText));
filterCombo.setEditable(true);
filterCombo.addActionListener(
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("comboBoxEdited")) {
try {
//verify the expression is valid
ExpressionRule.getRule(
filterCombo.getSelectedItem().toString());
} catch (IllegalArgumentException iae) {
//don't add expressions that aren't valid
return;
}
//should be 'valid expression' check
if (!(v.contains(filterCombo.getSelectedItem()))) {
filterCombo.addItem(filterCombo.getSelectedItem());
}
}
}
});
upperPanel.add(filterCombo, BorderLayout.CENTER);
} else {
filterText = new JTextField();
filterText.setToolTipText("Enter an expression");
filterText.addKeyListener(
new ExpressionRuleContext(filterModel, filterText));
filterText.getDocument().addDocumentListener(
new DelayedFilterTextDocumentListener(filterText));
upperPanel.add(filterText, BorderLayout.CENTER);
}