use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.
the class XMPPHyperlink method openContainer.
/**
* @param presenceContainerAdapter
*/
private void openContainer(IContainer container) {
final IPresenceContainerAdapter presenceContainerAdapter = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
final IChatManager chatManager = presenceContainerAdapter.getChatManager();
final IRosterManager rosterManager = presenceContainerAdapter.getRosterManager();
if (chatManager != null && rosterManager != null) {
try {
// get local ID
final XMPPID localID = (XMPPID) rosterManager.getRoster().getUser().getID();
final Namespace ns = container.getConnectNamespace();
// create target ID
final XMPPID targetID = (isXMPPS) ? new XMPPSID(ns, getURI().getAuthority()) : new XMPPID(ns, getURI().getAuthority());
// If they are same, just tell user and return
if (localID.equals(targetID)) {
MessageDialog.openError(null, Messages.XMPPHyperlink_MESSAGING_ERROR_TITLE, Messages.XMPPHyperlink_MESSAGING_ERROR_MESSAGE);
return;
} else {
final String localHost = localID.getHostname();
final String targetHost = targetID.getHostname();
// it's pretty obvious that we wish to message to them
if (localHost.equals(targetHost)) {
openMessagesView(chatManager, localID, targetID, targetID.getUsername());
} else {
// Otherwise, ask the user whether messaging, or
// connecting is desired
final MessageDialog messageDialog = new MessageDialog(null, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_TITLE, null, NLS.bind(Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_MESSAGE, new Object[] { targetHost, localHost, targetID.getName(), localID.getName() }), MessageDialog.QUESTION, new String[] { Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_SEND_MESSAGE, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_CONNECT, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_CANCEL }, 2);
final int selected = messageDialog.open();
switch(selected) {
case 0:
openMessagesView(chatManager, localID, targetID, targetID.getUsername());
return;
case 1:
super.open();
return;
default:
return;
}
}
}
} catch (final Exception e) {
MessageDialog.openError(null, Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_TITLE, NLS.bind(Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_MESSAGE, e.getLocalizedMessage()));
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_LOG_STATUS_MESSAGE, e));
}
}
}
use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.
the class ResourcesShareHandler method run.
private void run(Shell shell, final ResourcesShare share, final String projectName) {
final boolean[] ret = { false };
try {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
dialog.open();
dialog.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask("Sharing " + projectName, IProgressMonitor.UNKNOWN);
monitor.subTask("Sending request...");
share.startShare(getRosterEntry().getRoster().getUser().getID(), getRosterEntry().getUser().getID(), projectName);
monitor.subTask("Waiting for acknowledgement...");
while (true) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
Thread.sleep(50);
Boolean response = share.getResponse();
if (response != null) {
ret[0] = response.booleanValue();
return;
}
}
} catch (ECFException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, SyncResourcesUI.PLUGIN_ID, "Could not send share request", e.getCause());
StatusManager.getManager().handle(status);
SyncResourcesUI.log(status);
} catch (InterruptedException e) {
// operation canceled, stop sharing this project
share.stopSharing(projectName);
return;
}
if (ret[0]) {
IRosterManager manager = getRosterEntry().getRoster().getPresenceContainerAdapter().getRosterManager();
manager.addRosterListener(new RosterListener(share, projectName, getRosterEntry()));
} else {
MessageDialog.openInformation(shell, null, "Sharing request denied.");
}
}
use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.
the class AbstractAdapterAccessTest method testGetRosterManager.
public void testGetRosterManager() {
final IPresenceContainerAdapter adapter = getPresenceAdapter();
assertNotNull(adapter);
final IRosterManager rosterManager = adapter.getRosterManager();
assertNotNull(rosterManager);
}
use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.
the class BrowseDialog method fillContentProvider.
/* (non-Javadoc)
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#fillContentProvider(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.AbstractContentProvider, org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.ItemsFilter, org.eclipse.core.runtime.IProgressMonitor)
*/
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) {
progressMonitor.beginTask(Messages.BrowseDialog_scanning, containers.length);
// cycle through all the containers and grab entries
for (int i = 0; i < containers.length; i++) {
IContainer container = containers[i];
IPresenceContainerAdapter presenceContainer = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
if (presenceContainer != null) {
IRosterManager manager = presenceContainer.getRosterManager();
if (manager != null) {
Collection items = manager.getRoster().getItems();
for (Iterator it = items.iterator(); it.hasNext(); ) {
IRosterItem item = (IRosterItem) it.next();
addRosterItem(item, contentProvider, itemsFilter);
}
}
}
progressMonitor.worked(1);
}
progressMonitor.done();
}
use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.
the class XMPPHyperlink method chooseAccount.
/**
* @param adapters
*/
private void chooseAccount(final IContainer[] containers) {
// If there's only one choice then use it
if (containers.length == 1) {
openContainer(containers[0]);
return;
} else {
final IPresenceContainerAdapter[] adapters = new IPresenceContainerAdapter[containers.length];
for (int i = 0; i < containers.length; i++) adapters[i] = (IPresenceContainerAdapter) containers[i].getAdapter(IPresenceContainerAdapter.class);
final ListDialog dialog = new ListDialog(null);
dialog.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
return adapters;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
dialog.setInput(adapters);
dialog.setAddCancelButton(true);
dialog.setBlockOnOpen(true);
dialog.setTitle(Messages.XMPPHyperlink_SELECT_ACCOUNT_TITLE);
dialog.setMessage(Messages.XMPPHyperlink_SELECT_ACCOUNT_MESSAGE);
dialog.setHeightInChars(adapters.length > 4 ? adapters.length : 4);
dialog.setInitialSelections(new IPresenceContainerAdapter[] { adapters[0] });
dialog.setLabelProvider(new ILabelProvider() {
public Image getImage(Object element) {
return null;
}
public String getText(Object element) {
final IRosterManager manager = ((IPresenceContainerAdapter) element).getRosterManager();
if (manager == null)
return null;
return manager.getRoster().getUser().getID().getName();
}
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
});
final int result = dialog.open();
if (result == ListDialog.OK) {
final Object[] res = dialog.getResult();
if (res.length > 0)
openContainer((IContainer) res[0]);
}
}
}
Aggregations