@Override
public void run() {
Utils.runSafeSync(log, new Runnable() {
public void run() {
RosterEntry rosterEntry = null;
List<RosterEntry> selectedRosterEntries = SelectionRetrieverFactory
.getSelectionRetriever(RosterEntry.class).getSelection();
if (selectedRosterEntries.size() == 1) {
/*
* TODO Why forbid renaming self? Is the own entry displayed
* at all?
*/
// Compare the plain-JID portion of the XMPP address
if (!new JID(selectedRosterEntries.get(0).getUser())
.equals(saros.getSarosNet().getMyJID())) {
rosterEntry = selectedRosterEntries.get(0);
}
}
if (rosterEntry == null) {
log.error("RosterEntry should not be null at this point!"); //$NON-NLS-1$
return;
}
Shell shell = EditorAPI.getShell();
assert shell != null : "Action should not be run if the display is disposed"; //$NON-NLS-1$
String message = MessageFormat.format(
Messages.RenameContactAction_rename_message,
rosterEntry.getUser());
if (rosterEntry.getName() != null) {
message += MessageFormat.format(
Messages.RenameContactAction_rename_current_nickname_message, rosterEntry.getName());
}
message += ":"; //$NON-NLS-1$
InputDialog dialog = new InputDialog(shell, Messages.RenameContactAction_new_nickname_dialog_title,
message, rosterEntry.getName(), null);
if (dialog.open() == Window.OK) {
String newName = dialog.getValue();
rosterEntry.setName(newName.length() == 0 ? null : newName);
}
}
});
}