new MenuItem(entryMenu,SWT.SEPARATOR);
MenuItem rename = new MenuItem(entryMenu,SWT.PUSH);
rename.setText("Rename Contact");
rename.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
InputDialog dialog = new InputDialog(
entryMenu.getShell(),
"Rename Contact",
"Enter New Name for " + (selectedEntry.getName() == null ? selectedEntry.getUser() : selectedEntry.getName()),
(selectedEntry.getName() == null ? selectedEntry.getUser() : selectedEntry.getName()),
null);
dialog.setBlockOnOpen(true);
if(dialog.open() != InputDialog.OK) return;
selectedEntry.setName(dialog.getValue());
}
});
MenuItem remove = new MenuItem(entryMenu,SWT.PUSH);
remove.setText("Remove Contact");
remove.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
activeAccount.xmpp.removeContact(selectedEntry,entryMenu.getShell());
}
});
MenuItem authorization = new MenuItem(entryMenu,SWT.CASCADE);
authorization.setText("Authorization");
Menu authMenu = new Menu(authorization);
authorization.setMenu(authMenu);
MenuItem authSendTo = new MenuItem(authMenu,SWT.PUSH);
authSendTo.setText("(Re)Send Subscribe Authorization");
MenuItem authRequestFrom = new MenuItem(authMenu,SWT.PUSH);
authRequestFrom.setText("(Re)Request Subscribe Authorization");
MenuItem authRemove = new MenuItem(authMenu,SWT.PUSH);
authRemove.setText("Remove Subscribe Authorization");
authSendTo.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
Presence presence = new Presence(Presence.Type.SUBSCRIBED);
presence.setTo(StringUtils.parseBareAddress(selectedEntry.getUser()));
activeAccount.xmpp.getConnection().sendPacket(presence);
}
});
authRequestFrom.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
Presence presence = new Presence(Presence.Type.SUBSCRIBE);
presence.setTo(StringUtils.parseBareAddress(selectedEntry.getUser()));
activeAccount.xmpp.getConnection().sendPacket(presence);
}
});
authRemove.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
Presence presence = new Presence(Presence.Type.UNSUBSCRIBED);
presence.setTo(StringUtils.parseBareAddress(selectedEntry.getUser()));
activeAccount.xmpp.getConnection().sendPacket(presence);
}
});
addToGroupItem = new MenuItem(entryMenu,SWT.CASCADE);
addToGroupItem.setText("Add To Group");
addToGroup = new Menu(addToGroupItem);
addToGroupItem.setMenu(addToGroup);
MenuItem createGroup = new MenuItem(addToGroup,SWT.PUSH);
createGroup.setText("New Group");
createGroup.setData("constant",true);
new MenuItem(addToGroup,SWT.SEPARATOR).setData("constant",true);
createGroup.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
InputDialog dialog = new InputDialog(
addToGroup.getShell(),
"Create Group",
"Name for the newly created Group",
"",
new IInputValidator(){
public String isValid(String newText) {
if(newText.equals("")) return "Enter a valid name.";
if(activeAccount.xmpp.getRoster().getGroup(newText) != null) return "Group already exists.";
if(newText.equalsIgnoreCase("default")) return "Invalid Group Name";
return null;
}});
dialog.setBlockOnOpen(true);
int code = dialog.open();
if(code != InputDialog.OK) return;
RosterGroup group = activeAccount.xmpp.getRoster().createGroup(dialog.getValue());
try {
group.addEntry(selectedEntry);
} catch (XMPPException e) {
e.printStackTrace();
throw new RuntimeException(e);