Thanks for your guide.
I think I'm half way, but I have 2 major problem.
I will go without up/down radio buttons, I will do just top-down search.
My first problem is that
I don't want my search dialog disappear when I click "ok" button,
because I want if I click ok first, then it will search first instance, and
if I click ok again(without having to re-open the search dialog again), it will search the next instance.
I want my search dialog only disappear when I click "cancel" button.
But current my dialog disappears when I click the 'ok' button.
My second problem is that,
I don't know where to put "addMouseListener" to have e.getClickCount();
Belows are my codes.
First I tried to use JOptionPane.
class MenuAction_SearchResource extends MenuAction {
public void actionPerformed(ActionEvent e) {
// we only allow on a resource
if (_node.getName().equals("resource")) {
int value = JOptionPane.showConfirmDialog(EditorFrame.getInstance(),
"Resource Search",
"Resource Search", JOptionPane.OK_CANCEL_OPTION);
if (value == JOptionPane.OK_OPTION) {
System.out.println("ok");
// select the organization that this resource is being referred
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int count = e.getClickCount();
System.out.println("count click: " + count);
Element resource = _node.getElement();
Element rootElement = _contentPackage.getRootElement();
Namespace ns = rootElement.getNamespace();
Element oranizationsElement = rootElement.getChild("organizations", ns);
List oragnizations = new ArrayList(oranizationsElement.getChildren());
// we get organization
ListIterator organizationIter = oragnizations.listIterator();
while(organizationIter.hasNext())
{
Element organization = (Element)organizationIter.next();
highlightBackReference(organization, resource, ns);
}
}
});
} else if (value == JOptionPane.CANCEL_OPTION) {
System.out.println("cancel");
}
}
}
}
And it didn't work.It only prints ok when I click the ok button
So I created JDialog(below codes), but it didn't work either.
if (_node.getName().equals("resource")) {
final JOptionPane optionPane = new JOptionPane(
"Resource Search",
JOptionPane.PLAIN_MESSAGE,
JOptionPane.OK_CANCEL_OPTION);
final JDialog dialog = new JDialog(EditorFrame.getInstance(),
"Search Resource",
true);
dialog.setContentPane(optionPane);
optionPane.addPropertyChangeListener(
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (dialog.isVisible()
&& (e.getSource() == optionPane)
&& (prop.equals(JOptionPane.VALUE_PROPERTY))) {
//If you were going to check something
//before closing the window, you'd do
//it here.
dialog.setVisible(false);
}
}
});
dialog.pack();
dialog.setVisible(true);
int value = ((Integer)optionPane.getValue()).intValue();
if (value == JOptionPane.OK_OPTION) {
System.out.println("ok");
optionPane.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int count = e.getClickCount();
System.out.println("count click: " + count);
// select the organization that this resource is being referred
Element resource = _node.getElement();
Element rootElement = _contentPackage.getRootElement();
Namespace ns = rootElement.getNamespace();
Element oranizationsElement = rootElement.getChild("organizations", ns);
List oragnizations = new ArrayList(oranizationsElement.getChildren());
// we get organization
ListIterator organizationIter = oragnizations.listIterator();
while(organizationIter.hasNext())
{
Element organization = (Element)organizationIter.next();
highlightBackReference(organization, resource, ns);
}
}
});
} else if (value == JOptionPane.CANCEL_OPTION) {
System.out.println("cancel");
}
}
What am I doing wrong?
Thanks for your help.