some work on the autocomplete user add function

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12241 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Wolf Posdorfer
2011-04-11 09:25:34 +00:00
committed by wolf.posdorfer
parent 59f5c594c0
commit 2ccf65a8e6

View File

@ -522,23 +522,33 @@ public class RosterDialog implements PropertyChangeListener, ActionListener {
}
/**
* Creates a Popupdialog above the Search Button displaying matching Contacts
* @param byname, the Searchname, atleast 5 Chars long
* @param event, the MouseEvent which triggered it
* Creates a Popupdialog above the Search Button displaying matching
* Contacts
*
* @param byname
* , the Searchname, atleast 5 Chars long
* @param event
* , the MouseEvent which triggered it
* @throws XMPPException
*/
public void searchForContact(String byname, MouseEvent event)
throws XMPPException {
if (byname.length() <= 4) {
JOptionPane.showMessageDialog(jidField, Res.getString("message.search.input.short"),
Res.getString("title.notification"),
JOptionPane.ERROR_MESSAGE);
return;
if (byname.contains("@")) {
byname = byname.substring(0, byname.indexOf("@"));
}
if (byname.length() <= 4) {
JOptionPane.showMessageDialog(jidField,
Res.getString("message.search.input.short"),
Res.getString("title.notification"),
JOptionPane.ERROR_MESSAGE);
} else {
JPopupMenu popup = new JPopupMenu();
JMenuItem header = new JMenuItem(Res.getString("group.search.results")+":");
JMenuItem header = new JMenuItem(
Res.getString("group.search.results") + ":");
header.setBackground(UIManager.getColor("List.selectionBackground"));
header.setForeground(Color.red);
popup.add(header);
@ -554,8 +564,8 @@ public class RosterDialog implements PropertyChangeListener, ActionListener {
Form answer = f.createAnswerForm();
answer.setAnswer("Name", true);
answer.setAnswer("Email", true);
answer.setAnswer("search", jidField.getText());
answer.setAnswer("Username", true);
answer.setAnswer("search", byname);
data = usersearchManager.getSearchResults(answer,
"search.jabber.int.kn");
@ -581,6 +591,8 @@ public class RosterDialog implements PropertyChangeListener, ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
jidField.setText(item.getText());
nicknameField.setText(StringUtils
.parseName(item.getText()));
}
});
}
@ -593,12 +605,15 @@ public class RosterDialog implements PropertyChangeListener, ActionListener {
popup.show(_searchForName, event.getX(), event.getY());
} else if (popup.getComponentCount() == 2) {
jidField.setText(((JMenuItem) popup.getComponent(1)).getText());
}else
{
JOptionPane.showMessageDialog(jidField, Res.getString("message.no.results.found"),
Res.getString("title.notification"),JOptionPane.ERROR_MESSAGE);
nicknameField.setText(StringUtils.parseName(((JMenuItem) popup
.getComponent(1)).getText()));
} else {
JOptionPane.showMessageDialog(jidField,
Res.getString("message.no.results.found"),
Res.getString("title.notification"),
JOptionPane.ERROR_MESSAGE);
}
}
}