Search in sources :

Example 51 with IContainer

use of org.eclipse.ecf.core.IContainer in project ecf by eclipse.

the class AbstractHostContainerSelector method selectExistingHostContainers.

/**
 * @param serviceReference service reference
 * @param overridingProperties overriding properties
 * @param serviceExportedInterfaces service exported interfaces to select for
 * @param serviceExportedConfigs service exported configs to select for
 * @param serviceIntents service exported intents to select for
 * @return Collection of existing host containers
 * @since 2.0
 */
protected Collection selectExistingHostContainers(ServiceReference serviceReference, Map<String, Object> overridingProperties, String[] serviceExportedInterfaces, String[] serviceExportedConfigs, String[] serviceIntents) {
    List results = new ArrayList();
    // Get all existing containers
    IContainer[] containers = getContainers();
    // If nothing there, then return empty array
    if (containers == null || containers.length == 0)
        return results;
    for (int i = 0; i < containers.length; i++) {
        ID cID = containers[i].getID();
        // $NON-NLS-1$ //$NON-NLS-2$
        trace("selectExistingHostContainers", "Considering existing container=" + cID);
        // Check to make sure it's a rs container adapter. If it's not go
        // onto next one
        IRemoteServiceContainerAdapter adapter = hasRemoteServiceContainerAdapter(containers[i]);
        if (adapter == null) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            trace("selectExistingHostContainers", "Existing container=" + cID + " does not implement IRemoteServiceContainerAdapter");
            continue;
        }
        // Get container type description and intents
        ContainerTypeDescription description = getContainerTypeDescription(containers[i]);
        // If it has no description go onto next
        if (description == null) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            trace("selectExistingHostContainers", "Existing container=" + cID + " does not have container type description");
            continue;
        }
        // http://bugs.eclipse.org/331532
        if (!description.isServer()) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            trace("selectExistingHostContainers", "Existing container=" + cID + " is not server");
            continue;
        }
        if (matchExistingHostContainer(serviceReference, overridingProperties, containers[i], adapter, description, serviceExportedConfigs, serviceIntents)) {
            trace("selectExistingHostContainers", // $NON-NLS-1$ //$NON-NLS-2$
            "INCLUDING containerID=" + containers[i].getID() + // $NON-NLS-1$
            " configs=" + ((serviceExportedConfigs == null) ? "null" : // $NON-NLS-1$
            Arrays.asList(serviceExportedConfigs).toString()) + // $NON-NLS-1$
            " intents=" + ((serviceIntents == null) ? "null" : // $NON-NLS-1$
            Arrays.asList(serviceIntents).toString()));
            results.add(new RemoteServiceContainer(containers[i], adapter));
        } else {
            trace("selectExistingHostContainers", // $NON-NLS-1$ //$NON-NLS-2$
            "EXCLUDING containerID=" + containers[i].getID() + // $NON-NLS-1$
            " configs=" + ((serviceExportedConfigs == null) ? "null" : // $NON-NLS-1$
            Arrays.asList(serviceExportedConfigs).toString()) + // $NON-NLS-1$
            " intents=" + ((serviceIntents == null) ? "null" : // $NON-NLS-1$
            Arrays.asList(serviceIntents).toString()));
        }
    }
    return results;
}
Also used : ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) RemoteServiceContainer(org.eclipse.ecf.remoteservice.RemoteServiceContainer) IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) ArrayList(java.util.ArrayList) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ArrayList(java.util.ArrayList) List(java.util.List) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer)

Example 52 with IContainer

use of org.eclipse.ecf.core.IContainer in project ecf by eclipse.

the class ResourcesShareHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection iss = (IStructuredSelection) selection;
    Object o = iss.getFirstElement();
    IResource resource = null;
    if (o instanceof IAdaptable) {
        resource = (IResource) ((IAdaptable) o).getAdapter(IResource.class);
    } else {
        return null;
    }
    IPresenceContainerAdapter ipca = getRosterEntry().getRoster().getPresenceContainerAdapter();
    IContainer container = (IContainer) ipca.getAdapter(IContainer.class);
    ResourcesShare sender = SyncResourcesCore.getResourcesShare(container.getID());
    IProject project = resource.getProject();
    String projectName = project.getName();
    if (!SyncResourcesCore.isSharing(projectName)) {
        run(HandlerUtil.getActiveShellChecked(event), sender, projectName);
    } else {
        sender.stopSharing(projectName);
    }
    return null;
}
Also used : IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IAdaptable(org.eclipse.core.runtime.IAdaptable) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IContainer(org.eclipse.ecf.core.IContainer) ResourcesShare(org.eclipse.ecf.internal.sync.resources.core.ResourcesShare) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 53 with IContainer

use of org.eclipse.ecf.core.IContainer in project ecf by eclipse.

the class HostContainerSelector method selectHostContainers.

// Adding synchronized to make the host container finding
// thread safe to deal with bug
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331836
/**
 * @see org.eclipse.ecf.osgi.services.remoteserviceadmin.IHostContainerSelector#selectHostContainers(org.osgi.framework.ServiceReference,
 *      java.util.Map, java.lang.String[], java.lang.String[],
 *      java.lang.String[])
 * @since 2.0
 */
public synchronized IRemoteServiceContainer[] selectHostContainers(ServiceReference serviceReference, Map<String, Object> overridingProperties, String[] serviceExportedInterfaces, String[] serviceExportedConfigs, String[] serviceIntents) throws SelectContainerException {
    trace(// $NON-NLS-1$
    "selectHostContainers", // $NON-NLS-1$ //$NON-NLS-2$
    "serviceReference=" + serviceReference + ",overridingProperties=" + overridingProperties + // $NON-NLS-1$
    ",exportedInterfaces=" + ((serviceExportedInterfaces == null) ? Collections.EMPTY_LIST : Arrays.asList(serviceExportedInterfaces)) + // $NON-NLS-1$
    ",serviceExportedConfigs=" + ((serviceExportedConfigs == null) ? Collections.EMPTY_LIST : Arrays.asList(serviceExportedConfigs)) + // $NON-NLS-1$
    ",serviceIntents=" + ((serviceIntents == null) ? Collections.EMPTY_LIST : Arrays.asList(serviceIntents)));
    // Find previously created containers that match the given
    // serviceExportedConfigs and serviceIntents
    Collection rsContainers = (reuseExistingContainers) ? selectExistingHostContainers(serviceReference, overridingProperties, serviceExportedInterfaces, serviceExportedConfigs, serviceIntents) : Collections.EMPTY_LIST;
    if (rsContainers.size() == 0 && autoCreateContainer) {
        // If no existing containers are found we'll go through
        // finding/creating/configuring/connecting
        rsContainers = createAndConfigureHostContainers(serviceReference, overridingProperties, serviceExportedInterfaces, serviceExportedConfigs, serviceIntents);
        // if SERVICE_EXPORTED_CONTAINER_CONNECT_TARGET service property is
        // specified, then
        // connect the host container(s)
        Object target = overridingProperties.get(RemoteConstants.ENDPOINT_CONNECTTARGET_ID);
        if (target != null) {
            for (Iterator i = rsContainers.iterator(); i.hasNext(); ) {
                IContainer container = ((IRemoteServiceContainer) i.next()).getContainer();
                try {
                    connectHostContainer(serviceReference, overridingProperties, container, target);
                } catch (Exception e) {
                    logException(// $NON-NLS-1$
                    "doConnectContainer failure containerID=" + container.getID() + " target=" + target, // $NON-NLS-1$
                    e);
                }
            }
        }
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    trace("selectHostContainers", "rsContainers selected=" + rsContainers);
    // return result
    return (IRemoteServiceContainer[]) rsContainers.toArray(new IRemoteServiceContainer[rsContainers.size()]);
}
Also used : IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) Iterator(java.util.Iterator) Collection(java.util.Collection) IContainer(org.eclipse.ecf.core.IContainer)

Example 54 with IContainer

use of org.eclipse.ecf.core.IContainer in project ecf by eclipse.

the class CollabClient method createAndConnectClient.

/**
 * Create a new container instance, and connect to a remote server or group.
 *
 * @param containerType
 *            the container type used to create the new container instance.
 *            Must not be null.
 * @param uri
 *            the uri that is used to create a targetID for connection. Must
 *            not be null.
 * @param nickname
 *            an optional String nickname. May be null.
 * @param connectData
 *            optional connection data. May be null.
 * @param resource
 *            the resource that this container instance is associated with.
 *            Must not be null.
 * @throws Exception
 */
public void createAndConnectClient(final String containerType, String uri, String nickname, final Object connectData, final IResource resource) throws Exception {
    // First create the new container instance
    final IContainer newClient = ContainerFactory.getDefault().createContainer(containerType);
    // Create the targetID instance
    ID targetID = IDFactory.getDefault().createID(newClient.getConnectNamespace(), uri);
    // Setup username
    String username = setupUsername(targetID, nickname);
    // Create a new container entry to hold onto container once created
    final ClientEntry newClientEntry = new ClientEntry(containerType, newClient);
    // Setup sharedobject container if the new instance supports
    // this
    ISharedObjectContainer sharedObjectContainer = (ISharedObjectContainer) newClient.getAdapter(ISharedObjectContainer.class);
    SharedObjectContainerUI socui = new SharedObjectContainerUI(this, sharedObjectContainer);
    socui.setup(sharedObjectContainer, newClientEntry, resource, username);
    // Now connect
    try {
        newClient.connect(targetID, ConnectContextFactory.createUsernamePasswordConnectContext(username, connectData));
    } catch (ContainerConnectException e) {
        // If we have a connect exception then we remove any previously
        // added shared object
        EclipseCollabSharedObject so = newClientEntry.getSharedObject();
        if (so != null)
            so.destroySelf();
        throw e;
    }
    // only add container if the connect was successful
    addClientForResource(newClientEntry, resource);
}
Also used : EclipseCollabSharedObject(org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject) SharedObjectContainerUI(org.eclipse.ecf.internal.example.collab.ui.SharedObjectContainerUI) ISharedObjectContainer(org.eclipse.ecf.core.sharedobject.ISharedObjectContainer) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer)

Example 55 with IContainer

use of org.eclipse.ecf.core.IContainer in project ecf by eclipse.

the class SynchronizeWithHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IRosterEntry selectedEntry = getRosterEntry();
    IRoster roster = selectedEntry.getRoster();
    final IUser remoteUser = roster.getUser();
    final ID localId = remoteUser.getID();
    final ID remoteId = selectedEntry.getUser().getID();
    IContainer container = (IContainer) roster.getPresenceContainerAdapter().getAdapter(IContainer.class);
    final IResource[] resources = getResources(event);
    final RemoteShare share = TeamSynchronization.getShare(container.getID());
    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    final IWorkbenchPartSite site = part == null ? null : part.getSite();
    final Shell shell = HandlerUtil.getActiveShellChecked(event);
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    final boolean[] response = { true };
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            if (resources.length == 1) {
                monitor.beginTask(NLS.bind(Messages.SynchronizeWithHandler_SynchronizeResourceTaskName, resources[0].getName()), IProgressMonitor.UNKNOWN);
            } else {
                monitor.beginTask(Messages.SynchronizeWithHandler_SynchronizeResourcesTaskName, IProgressMonitor.UNKNOWN);
            }
            try {
                if (share.sendShareRequest(localId, remoteId, resources, monitor)) {
                    scheduleRefreshJob(share, localId, remoteId, resources, remoteUser, site);
                } else {
                    response[0] = false;
                }
            } catch (ECFException e) {
                throw new InvocationTargetException(e);
            } catch (OperationCanceledException e) {
                // operation, but check for this just in case
                if (!monitor.isCanceled()) {
                    throw e;
                }
            }
        }
    };
    try {
        dialog.run(true, true, runnable);
        if (!response[0]) {
            MessageDialog.openInformation(shell, null, Messages.SynchronizeWithHandler_SynchronizeRequestDenial);
        }
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof ECFException) {
            MessageDialog.openError(shell, null, Messages.SynchronizeWithHandler_SynchronizeRequestError);
        }
        // $NON-NLS-1$
        TeamSynchronization.log("Failed to contact remote peer", cause);
    } catch (InterruptedException e) {
        Thread.interrupted();
        MessageDialog.openError(shell, null, Messages.SynchronizeWithHandler_SynchronizeRequestInterrupted);
        // $NON-NLS-1$
        TeamSynchronization.log("Synchronization request operation was interrupted", e);
    }
    return null;
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IRoster(org.eclipse.ecf.presence.roster.IRoster) Shell(org.eclipse.swt.widgets.Shell) ECFException(org.eclipse.ecf.core.util.ECFException) RemoteShare(org.eclipse.team.internal.ecf.core.RemoteShare) IUser(org.eclipse.ecf.core.user.IUser) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

IContainer (org.eclipse.ecf.core.IContainer)121 ID (org.eclipse.ecf.core.identity.ID)29 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)20 IRosterEntry (org.eclipse.ecf.presence.roster.IRosterEntry)9 IRoster (org.eclipse.ecf.presence.roster.IRoster)8 IChannelContainerAdapter (org.eclipse.ecf.datashare.IChannelContainerAdapter)7 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)7 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)7 ISharedObjectContainer (org.eclipse.ecf.core.sharedobject.ISharedObjectContainer)5 IPresenceContainerAdapter (org.eclipse.ecf.presence.IPresenceContainerAdapter)5 RemoteServiceContainer (org.eclipse.ecf.remoteservice.RemoteServiceContainer)5 Action (org.eclipse.jface.action.Action)5 IAction (org.eclipse.jface.action.IAction)5 URL (java.net.URL)4 Job (org.eclipse.core.runtime.jobs.Job)4 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)4 IContainerManager (org.eclipse.ecf.core.IContainerManager)4 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)4 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)4 RestClientContainer (org.eclipse.ecf.remoteservice.rest.client.RestClientContainer)4