Search in sources :

Example 6 with EclipseCollabSharedObject

use of org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject 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 7 with EclipseCollabSharedObject

use of org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject in project ecf by eclipse.

the class EditorCompoundContributionItem method getContributionItems.

protected IContributionItem[] getContributionItems() {
    final ITextSelection textSelection = getSelection();
    if (textSelection == null)
        return EMPTY;
    final IEditorPart editorPart = getEditorPart();
    if (editorPart == null)
        return EMPTY;
    final IFile file = getFileForPart(editorPart);
    if (file == null)
        return EMPTY;
    final IProject project = file.getProject();
    if (isConnected(project.getWorkspace().getRoot()) == null)
        return EMPTY;
    final IAction action = new Action() {

        public void run() {
            final ClientEntry entry = isConnected(project.getWorkspace().getRoot());
            if (entry == null) {
                MessageDialog.openInformation(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.EditorCompoundContributionItem_EXCEPTION_NOT_CONNECTED_TITLE, Messages.EditorCompoundContributionItem_EXCEPTION_NOT_CONNECTED_MESSAGE);
                return;
            }
            final EclipseCollabSharedObject collabsharedobject = entry.getSharedObject();
            if (collabsharedobject != null) {
                // $NON-NLS-1$
                collabsharedobject.sendOpenAndSelectForFile(null, project.getName() + "/" + file.getProjectRelativePath().toString(), textSelection.getOffset(), textSelection.getLength());
            }
        }
    };
    final ClientEntry entry = isConnected(project.getWorkspace().getRoot());
    if (entry == null)
        return EMPTY;
    final EclipseCollabSharedObject collabsharedobject = entry.getSharedObject();
    if (collabsharedobject == null)
        return EMPTY;
    action.setText(NLS.bind(Messages.EditorCompoundContributionItem_SHARE_SELECTION_MENU_ITEM_NAME, collabsharedobject.getWindowTitle()));
    if (menuImageDescriptor != null)
        action.setImageDescriptor(menuImageDescriptor);
    // action.setAccelerator(SWT.CTRL | SWT.SHIFT | '1');
    return new IContributionItem[] { new Separator(), new ActionContributionItem(action) };
}
Also used : EclipseCollabSharedObject(org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IFile(org.eclipse.core.resources.IFile) IAction(org.eclipse.jface.action.IAction) IContributionItem(org.eclipse.jface.action.IContributionItem) IEditorPart(org.eclipse.ui.IEditorPart) ITextSelection(org.eclipse.jface.text.ITextSelection) IProject(org.eclipse.core.resources.IProject) Separator(org.eclipse.jface.action.Separator)

Example 8 with EclipseCollabSharedObject

use of org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject in project ecf by eclipse.

the class JoinGroupWizardAction method run.

public void run(IAction action) {
    if (!connected) {
        JoinGroupWizard wizard = new JoinGroupWizard(resource, PlatformUI.getWorkbench(), connectID);
        Shell shell = null;
        if (targetPart == null) {
            shell = (window == null) ? null : window.getShell();
        } else {
            shell = targetPart.getSite().getShell();
        }
        // Create the wizard dialog
        WizardDialog dialog = new WizardDialog(shell, wizard);
        // Open the wizard dialog
        dialog.open();
    } else {
        ClientEntry client = isConnected(resource);
        if (client == null) {
            connected = false;
            action.setText(CONNECT_PROJECT_MENU_TEXT);
        } else {
            EclipseCollabSharedObject collab = client.getSharedObject();
            if (collab != null) {
                collab.chatGUIDestroy();
            }
        }
    }
}
Also used : EclipseCollabSharedObject(org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject) JoinGroupWizard(org.eclipse.ecf.internal.example.collab.ui.JoinGroupWizard) Shell(org.eclipse.swt.widgets.Shell) ClientEntry(org.eclipse.ecf.internal.example.collab.ClientEntry) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

EclipseCollabSharedObject (org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject)8 IProject (org.eclipse.core.resources.IProject)3 ID (org.eclipse.ecf.core.identity.ID)3 ClientEntry (org.eclipse.ecf.internal.example.collab.ClientEntry)3 IFile (org.eclipse.core.resources.IFile)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 File (java.io.File)1 IContainer (org.eclipse.ecf.core.IContainer)1 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)1 ISharedObjectContainer (org.eclipse.ecf.core.sharedobject.ISharedObjectContainer)1 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)1 SharedObjectEventListener (org.eclipse.ecf.example.collab.share.SharedObjectEventListener)1 JoinGroupWizard (org.eclipse.ecf.internal.example.collab.ui.JoinGroupWizard)1 SharedObjectContainerUI (org.eclipse.ecf.internal.example.collab.ui.SharedObjectContainerUI)1 TCPClientSOContainer (org.eclipse.ecf.provider.generic.TCPClientSOContainer)1 Action (org.eclipse.jface.action.Action)1 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)1 IAction (org.eclipse.jface.action.IAction)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 Separator (org.eclipse.jface.action.Separator)1