Search in sources :

Example 1 with IOutgoingFileTransferResponseEvent

use of org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferResponseEvent in project ecf by eclipse.

the class XMPPCompoundContributionItem method sendFileToTarget.

private void sendFileToTarget(ISendFileTransferContainerAdapter fileTransfer, final ID targetID) {
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final FileDialog fd = new FileDialog(shell, SWT.OPEN);
    // XXX this should be some default path set by preferences
    // $NON-NLS-1$
    fd.setFilterPath(System.getProperty("user.home"));
    fd.setText(NLS.bind(Messages.XMPPCompoundContributionItem_CHOOSE_FILE, targetID.getName()));
    final String res = fd.open();
    if (res != null) {
        final File aFile = new File(res);
        try {
            final IFileID targetFileID = FileIDFactory.getDefault().createFileID(fileTransfer.getOutgoingNamespace(), new Object[] { targetID, res });
            fileTransfer.sendOutgoingRequest(targetFileID, aFile, new IFileTransferListener() {

                public void handleTransferEvent(final IFileTransferEvent event) {
                    Display.getDefault().asyncExec(new Runnable() {

                        public void run() {
                            // bar?)
                            if (event instanceof IOutgoingFileTransferResponseEvent) {
                                if (!((IOutgoingFileTransferResponseEvent) event).requestAccepted())
                                    MessageDialog.openInformation(shell, Messages.XMPPCompoundContributionItem_FILE_SEND_REFUSED_TITLE, NLS.bind(Messages.XMPPCompoundContributionItem_FILE_SEND_REFUSED_MESSAGE, res, targetID.getName()));
                            }
                        }
                    });
                }
            }, null);
        } catch (final Exception e) {
            MessageDialog.openError(shell, Messages.XMPPCompoundContributionItem_SEND_ERROR_TITLE, NLS.bind(Messages.XMPPCompoundContributionItem_SEND_ERROR_MESSAGE, res, e.getLocalizedMessage()));
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IFileTransferEvent(org.eclipse.ecf.filetransfer.events.IFileTransferEvent) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IOutgoingFileTransferResponseEvent(org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferResponseEvent) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Aggregations

File (java.io.File)1 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)1 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)1 IOutgoingFileTransferResponseEvent (org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferResponseEvent)1 IFileID (org.eclipse.ecf.filetransfer.identity.IFileID)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Shell (org.eclipse.swt.widgets.Shell)1