this.addPage(addBuddyWizardPage);
}
@Override
public boolean performFinish() {
final JID jid = this.addBuddyWizardPage.getBuddy();
final String nickname = this.addBuddyWizardPage.getNickname();
if (this.addBuddyWizardPage.isBuddyAlreadyAdded()) {
log.debug("Buddy " + jid.toString() + " already added."); //$NON-NLS-1$ //$NON-NLS-2$
return true;
}
/*
* Listeners that sets the autoSubscribe flag to true and removes itself
* from the subscriptionManager.
*/
final SubscriptionManagerListener subscriptionManagerListener = new SubscriptionManagerListener() {
public void subscriptionReceived(IncomingSubscriptionEvent event) {
if (jid.equals(event.getBuddy()))
event.autoSubscribe = true;
subscriptionManager.removeSubscriptionManagerListener(this);
}
};
try {
getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
try {
/*
* Register for incoming subscription request from
* subscription response.
*/
subscriptionManager
.addSubscriptionManagerListener(subscriptionManagerListener);
RosterUtils.addToRoster(saros.getSarosNet()
.getConnection(), jid, nickname, SubMonitor
.convert(monitor));
cachedBuddy = jid;
} catch (CancellationException e) {
throw new InterruptedException();
}
}
});
} catch (InvocationTargetException e) {
log.warn(e.getCause().getMessage(), e.getCause());
subscriptionManager
.removeSubscriptionManagerListener(subscriptionManagerListener);
this.addBuddyWizardPage.setErrorMessage(e.getMessage());
// Leave the wizard open
return false;
} catch (InterruptedException e) {
log.debug("Adding buddy " + jid.toString() //$NON-NLS-1$
+ " was canceled by the user."); //$NON-NLS-1$
subscriptionManager
.removeSubscriptionManagerListener(subscriptionManagerListener);
}