Search in sources :

Example 1 with IPublishedServiceDirectory

use of org.eclipse.ecf.pubsub.IPublishedServiceDirectory in project ecf by eclipse.

the class PubSubAdapterFactory method getDirectory.

protected IPublishedServiceDirectory getDirectory(ISharedObjectContainer container) {
    ID directoryID;
    try {
        directoryID = IDFactory.getDefault().createStringID(PublishedServiceDirectory.SHARED_OBJECT_ID);
    } catch (IDCreateException e) {
        throw new RuntimeException(e);
    }
    final ISharedObjectManager mgr = container.getSharedObjectManager();
    IPublishedServiceDirectory directory = (IPublishedServiceDirectory) mgr.getSharedObject(directoryID);
    if (directory != null)
        return directory;
    try {
        SharedObjectDescription desc = createDirectoryDescription(directoryID);
        mgr.createSharedObject(desc);
        return (IPublishedServiceDirectory) mgr.getSharedObject(directoryID);
    } catch (SharedObjectCreateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}
Also used : IPublishedServiceDirectory(org.eclipse.ecf.pubsub.IPublishedServiceDirectory) SharedObjectDescription(org.eclipse.ecf.core.sharedobject.SharedObjectDescription) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) ISharedObjectManager(org.eclipse.ecf.core.sharedobject.ISharedObjectManager) ID(org.eclipse.ecf.core.identity.ID)

Example 2 with IPublishedServiceDirectory

use of org.eclipse.ecf.pubsub.IPublishedServiceDirectory in project ecf by eclipse.

the class PubSubView method init.

public void init(IViewSite site) throws PartInitException {
    super.init(site);
    final Action shareSomethingAction = new Action("Share something") {

        public void run() {
            try {
                IMasterModel sds = SharedModelFactory.getInstance().createSharedDataSource(container, IDFactory.getDefault().createGUID(), new AppendableList(), ListAppender.ID);
                if (sds == null)
                    MessageDialog.openError(getSite().getShell(), "Error", "Could not share anything.");
                else {
                    sharedLists.add(sds);
                    sharedListViewer.add(sds);
                }
            } catch (SharedObjectCreateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IDCreateException e) {
                throw new RuntimeException(e);
            }
        }
    };
    shareSomethingAction.setEnabled(false);
    IMenuManager mgr = site.getActionBars().getMenuManager();
    mgr.add(new Action("Start") {

        public void run() {
            container = CollabClient.getContainer(ResourcesPlugin.getWorkspace().getRoot());
            if (container == null) {
                MessageDialog.openError(getSite().getShell(), "Error", "Collaboration environment not found.");
                return;
            }
            IPublishedServiceDirectory directory = (IPublishedServiceDirectory) container.getAdapter(IPublishedServiceDirectory.class);
            viewer.setInput(directory);
            setEnabled(false);
            shareSomethingAction.setEnabled(true);
        }
    });
    mgr.add(shareSomethingAction);
    menuManager = new MenuManager();
    subscribeAction = new BaseSelectionListenerAction("Subscribe") {

        public void run() {
            PublishedServiceDescriptor desc = (PublishedServiceDescriptor) getStructuredSelection().getFirstElement();
            IPublishedServiceRequestor requestor = (IPublishedServiceRequestor) container.getAdapter(IPublishedServiceRequestor.class);
            requestor.subscribe(desc.getContainerID(), desc.getSharedObjectID(), new SubscriptionViewOpener());
        }

        protected boolean updateSelection(IStructuredSelection selection) {
            return !selection.isEmpty();
        }
    };
    subscribeAction.setEnabled(false);
    menuManager.add(subscribeAction);
    sharedListMenuManager = new MenuManager();
    appendAction = new BaseSelectionListenerAction("Append...") {

        public void run() {
            InputDialog dlg = new InputDialog(getSite().getShell(), "Append to Shared List", "Enter element to append:", null, null);
            dlg.open();
            String value = dlg.getValue();
            if (value != null) {
                LocalAgent model = (LocalAgent) getStructuredSelection().getFirstElement();
                AppendableList list = (AppendableList) model.getData();
                if (list.add(value)) {
                    try {
                        model.update(value);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }

        protected boolean updateSelection(IStructuredSelection selection) {
            return !selection.isEmpty();
        }
    };
    appendAction.setEnabled(false);
    sharedListMenuManager.add(appendAction);
}
Also used : IPublishedServiceDirectory(org.eclipse.ecf.pubsub.IPublishedServiceDirectory) LocalAgent(org.eclipse.ecf.pubsub.model.impl.LocalAgent) PublishedServiceDescriptor(org.eclipse.ecf.pubsub.PublishedServiceDescriptor) Action(org.eclipse.jface.action.Action) BaseSelectionListenerAction(org.eclipse.ui.actions.BaseSelectionListenerAction) InputDialog(org.eclipse.jface.dialogs.InputDialog) IMasterModel(org.eclipse.ecf.pubsub.model.IMasterModel) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) BaseSelectionListenerAction(org.eclipse.ui.actions.BaseSelectionListenerAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IPublishedServiceRequestor(org.eclipse.ecf.pubsub.IPublishedServiceRequestor) IMenuManager(org.eclipse.jface.action.IMenuManager)

Aggregations

IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)2 SharedObjectCreateException (org.eclipse.ecf.core.sharedobject.SharedObjectCreateException)2 IPublishedServiceDirectory (org.eclipse.ecf.pubsub.IPublishedServiceDirectory)2 IOException (java.io.IOException)1 ID (org.eclipse.ecf.core.identity.ID)1 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)1 SharedObjectDescription (org.eclipse.ecf.core.sharedobject.SharedObjectDescription)1 IPublishedServiceRequestor (org.eclipse.ecf.pubsub.IPublishedServiceRequestor)1 PublishedServiceDescriptor (org.eclipse.ecf.pubsub.PublishedServiceDescriptor)1 IMasterModel (org.eclipse.ecf.pubsub.model.IMasterModel)1 LocalAgent (org.eclipse.ecf.pubsub.model.impl.LocalAgent)1 Action (org.eclipse.jface.action.Action)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 BaseSelectionListenerAction (org.eclipse.ui.actions.BaseSelectionListenerAction)1