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