Search in sources :

Example 1 with EndpointDescription

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription in project ecf by eclipse.

the class EndpointDiscoveryView method makeActions.

protected void makeActions() {
    copyValueAction = new Action() {

        public void run() {
            Object o = ((ITreeSelection) viewer.getSelection()).getFirstElement();
            String data = ((EndpointPropertyNode) o).getPropertyValue().toString();
            if (data != null && data.length() > 0) {
                clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
            }
        }
    };
    copyValueAction.setText(Messages.EndpointDiscoveryView_COPY_PROPERTY_VALUE);
    copyValueAction.setToolTipText(Messages.EndpointDiscoveryView_COPY_PROPERTY_VALUE);
    copyValueAction.setImageDescriptor(RSAImageRegistry.DESC_PROPERTY_OBJ);
    copyNameAction = new Action() {

        public void run() {
            Object o = ((ITreeSelection) viewer.getSelection()).getFirstElement();
            String data = ((EndpointPropertyNode) o).getPropertyName();
            if (data != null && data.length() > 0) {
                clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
            }
        }
    };
    copyNameAction.setText(Messages.EndpointDiscoveryView_COPY_PROPERTY_NAME);
    copyNameAction.setToolTipText(Messages.EndpointDiscoveryView_COPY_PROPERTY_NAME);
    copyNameAction.setImageDescriptor(RSAImageRegistry.DESC_PROPERTY_OBJ);
    importAction = new Action() {

        public void run() {
            EndpointNode edNode = getEDNodeSelected();
            if (edNode != null) {
                RemoteServiceAdmin rsa = discovery.getRSA();
                if (rsa == null)
                    showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IS_NULL);
                else {
                    // Do import
                    EndpointDescription ed = edNode.getEndpointDescription();
                    ImportRegistration reg = (ImportRegistration) rsa.importService(ed);
                    if (reg == null) {
                        logError(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED, // $NON-NLS-1$
                        new Exception("Import Registration Is Null"));
                        showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED_PREFIX + // $NON-NLS-1$
                        "Import Registration Is Null" + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
                        return;
                    }
                    // Check if import exception in returned registration
                    Throwable exception = reg.getException();
                    if (exception != null) {
                        logError(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED, exception);
                        showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED_PREFIX + exception.getMessage() + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
                    } else {
                        // Success! Set registration
                        // and refresh
                        edNode.setImportReference((ImportReference) reg.getImportReference());
                        viewer.refresh();
                    }
                }
            }
        }
    };
    importAction.setText(Messages.EndpointDiscoveryView_IMPORT_REMOTE_SERVICE);
    importAction.setToolTipText(Messages.EndpointDiscoveryView_IMPORT_REMOTE_SERVICE_TT);
    importAction.setImageDescriptor(RSAImageRegistry.DESC_RSPROXY_CO);
    edefDiscoverAction = new Action() {

        public void run() {
            IEndpointDescriptionLocator locator = discovery.getEndpointDescriptionLocator();
            if (locator != null) {
                FileDialog dialog = new FileDialog(viewer.getControl().getShell(), SWT.OPEN);
                // $NON-NLS-1$
                dialog.setFilterExtensions(new String[] { "*.xml" });
                dialog.setText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE);
                dialog.setFilterPath(null);
                String result = dialog.open();
                if (result != null)
                    try {
                        EndpointDescription[] eds = (EndpointDescription[]) new EndpointDescriptionReader().readEndpointDescriptions(new FileInputStream(result));
                        if (eds != null) {
                            for (int i = 0; i < eds.length; i++) locator.discoverEndpoint(eds[i]);
                        }
                    } catch (IOException e) {
                        logError(Messages.EndpointDiscoveryView_ERROR_MSG_ENDPOINT_PARSING_FAILED, e);
                        showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_ENDPOINT_PARSING_FAILED_PREFIX + e.getMessage() + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
                    }
            }
        }
    };
    edefDiscoverAction.setText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE_DIALOG);
    edefDiscoverAction.setToolTipText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE_DIALOG_TT);
    edefDiscoverAction.setEnabled(discovery.getRSA() != null);
    edefDiscoverAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE));
    undiscoverAction = new Action() {

        public void run() {
            EndpointNode endpoint = getEDNodeSelected();
            if (endpoint != null && endpoint.getImportReference() == null) {
                IEndpointDescriptionLocator l = discovery.getEndpointDescriptionLocator();
                if (l != null && MessageDialog.openQuestion(viewer.getControl().getShell(), Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_QUESTION_TITLE, Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_QUESTION))
                    l.undiscoverEndpoint(endpoint.getEndpointDescription());
            }
        }
    };
    undiscoverAction.setText(Messages.EndpointDiscoveryView_REMOVE_ENDPOINT);
    undiscoverAction.setToolTipText(Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_TT);
}
Also used : EndpointPropertyNode(org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointPropertyNode) Action(org.eclipse.jface.action.Action) RemoteServiceAdmin(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin) EndpointNode(org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointNode) AbstractEndpointNode(org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.AbstractEndpointNode) ImportReference(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportReference) EndpointDescriptionReader(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionReader) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription) IOException(java.io.IOException) ImportRegistration(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportRegistration) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IEndpointDescriptionLocator(org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionLocator) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 2 with EndpointDescription

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription in project ecf by eclipse.

the class EndpointDiscoveryView method createPartControl.

public void createPartControl(Composite parent) {
    this.discovery = DiscoveryComponent.getDefault();
    this.discovery.setView(this);
    IViewSite viewSite = getViewSite();
    this.contentProvider = createContentProvider(viewSite);
    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setContentProvider(this.contentProvider);
    viewer.setLabelProvider(new WorkbenchLabelProvider());
    viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
    viewer.setInput(viewSite);
    makeActions();
    hookContextMenu();
    contributeToActionBars();
    // setup clipboard
    clipboard = new Clipboard(viewer.getControl().getDisplay());
    getSite().setSelectionProvider(viewer);
    // Add any previously discovered endpoints
    viewer.getControl().getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            IEndpointDescriptionLocator locator = discovery.getEndpointDescriptionLocator();
            if (locator != null) {
                EndpointDescription[] eds = locator.getDiscoveredEndpoints();
                for (EndpointDescription ed : eds) handleEndpointDescription(EndpointEvent.ADDED, ed);
            }
        }
    });
    showServicesInRegistryBrowser();
}
Also used : IViewSite(org.eclipse.ui.IViewSite) IEndpointDescriptionLocator(org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionLocator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Clipboard(org.eclipse.swt.dnd.Clipboard) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription)

Example 3 with EndpointDescription

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription in project ecf by eclipse.

the class RemoteServiceAdminView method updateExports.

private void updateExports(ExportedServicesRootNode exportedRoot) {
    RemoteServiceAdmin rsa = getLocalRSA();
    if (rsa != null && exportedRoot != null) {
        exportedRoot.clearChildren();
        List<ExportRegistration> exportRegistrations = rsa.getExportedRegistrations();
        for (ExportRegistration er : exportRegistrations) {
            ExportRegistrationNode exportRegistrationNode = new ExportRegistrationNode(er);
            ExportReference eRef = (ExportReference) er.getExportReference();
            if (eRef != null) {
                exportRegistrationNode.addChild(new ServiceIdNode(eRef.getExportedService(), Messages.RSAView_SERVICE_ID_LABEL));
                EndpointDescription ed = (EndpointDescription) eRef.getExportedEndpoint();
                if (ed != null)
                    exportRegistrationNode.addChild(new EndpointDescriptionRSANode(ed));
            }
            exportedRoot.addChild(exportRegistrationNode);
        }
    }
}
Also used : RemoteServiceAdmin(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin) ServiceIdNode(org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.ServiceIdNode) ExportRegistration(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ExportRegistration) ExportReference(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ExportReference) EndpointDescriptionRSANode(org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.EndpointDescriptionRSANode) ExportRegistrationNode(org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.ExportRegistrationNode) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription)

Example 4 with EndpointDescription

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription in project ecf by eclipse.

the class RemoteServiceAdminView method updateImports.

private void updateImports(ImportedEndpointsRootNode importedRoot) {
    RemoteServiceAdmin rsa = getLocalRSA();
    if (rsa != null && importedRoot != null) {
        importedRoot.clearChildren();
        List<ImportRegistration> importRegistrations = rsa.getImportedRegistrations();
        for (ImportRegistration ir : importRegistrations) {
            ImportRegistrationNode importRegistrationNode = new ImportRegistrationNode(ir);
            ImportReference iRef = (ImportReference) ir.getImportReference();
            if (iRef != null) {
                importRegistrationNode.addChild(new ServiceIdNode(iRef.getImportedService(), Messages.RSAView_PROXY_SERVICE_ID_LABEL));
                EndpointDescription ed = (EndpointDescription) iRef.getImportedEndpoint();
                if (ed != null)
                    importRegistrationNode.addChild(new EndpointDescriptionRSANode(ed, ir));
            }
            importedRoot.addChild(importRegistrationNode);
        }
    }
}
Also used : RemoteServiceAdmin(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin) ImportReference(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportReference) ServiceIdNode(org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.ServiceIdNode) ImportRegistrationNode(org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.ImportRegistrationNode) EndpointDescriptionRSANode(org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.EndpointDescriptionRSANode) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription) ImportRegistration(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportRegistration)

Example 5 with EndpointDescription

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription in project ecf by eclipse.

the class RSACommand method importservice.

@Descriptor("Import a remote service via Remote Service Admin.  If -e is used, the given endpoint URL is read to read the EndpointDescription.  If not used, an EndpointDescription is expected from the console input (e.g. copy and paste)")
public RemoteServiceAdmin.ImportReference importservice(CommandSession cs, @Descriptor("Optional URL indicating location of an Endpoint Description (EDEF format)") @Parameter(names = { "-e", "--edefurl" }, absentValue = "") String endpointurl) {
    InputStream ins = null;
    URL url = null;
    if ("".equals(endpointurl)) {
        ins = cs.getKeyboard();
        cs.getConsole().println("Waiting for console input.   To complete enter an empty line...");
    } else {
        try {
            url = new URL(endpointurl);
            ins = url.openStream();
        } catch (IOException e) {
            e.printStackTrace(cs.getConsole());
        }
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(ins));
    StringBuffer buf = new StringBuffer();
    // read from the input stream until an empty line is encountered
    while (true) {
        try {
            String line = br.readLine();
            if (line != null && line.length() > 0)
                buf.append(line).append("\n");
            else
                break;
        } catch (IOException e) {
            e.printStackTrace(cs.getConsole());
            return null;
        }
    }
    // Close the input stream if this was from a url
    if (url != null)
        try {
            ins.close();
        } catch (IOException e) {
            e.printStackTrace(cs.getConsole());
        }
    ByteArrayInputStream bins = new ByteArrayInputStream(buf.toString().getBytes());
    EndpointDescriptionReader r = new EndpointDescriptionReader();
    org.osgi.service.remoteserviceadmin.EndpointDescription[] eds = null;
    try {
        eds = r.readEndpointDescriptions(bins);
    } catch (IOException e) {
        e.printStackTrace(cs.getConsole());
        return null;
    }
    // should be only one
    org.osgi.service.remoteserviceadmin.ImportRegistration reg = getRSA().importService(eds[0]);
    if (reg == null)
        return null;
    else {
        Throwable t = reg.getException();
        if (t != null) {
            t.printStackTrace(cs.getConsole());
            return null;
        } else {
            RemoteServiceAdmin.ImportReference ir = (RemoteServiceAdmin.ImportReference) reg.getImportReference();
            if (ir != null) {
                EndpointDescription ed = (EndpointDescription) ir.getImportedEndpoint();
                if (ed == null) {
                    cs.getConsole().println("Cannot get endpoint description for imported endpoint");
                    return null;
                }
                cs.getConsole().println("endpoint.id=" + ed.getId() + " with service.id=" + ir.getImportedService().getProperty(Constants.SERVICE_ID) + " successfully imported:");
                return ir;
            } else
                return null;
        }
    }
}
Also used : RemoteServiceAdmin(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EndpointDescriptionReader(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionReader) IOException(java.io.IOException) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription) URL(java.net.URL) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) Descriptor(org.apache.felix.service.command.Descriptor)

Aggregations

EndpointDescription (org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription)8 RemoteServiceAdmin (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin)5 IOException (java.io.IOException)2 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)2 EndpointDescriptionReader (org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionReader)2 IEndpointDescriptionLocator (org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionLocator)2 ImportReference (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportReference)2 ImportRegistration (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportRegistration)2 EndpointDescriptionRSANode (org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.EndpointDescriptionRSANode)2 ServiceIdNode (org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.ServiceIdNode)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 Descriptor (org.apache.felix.service.command.Descriptor)1 ExportReference (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ExportReference)1 ExportRegistration (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ExportRegistration)1 AbstractEndpointNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.AbstractEndpointNode)1