Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-02-21 23:08:35 +0000
committerslewis2008-02-21 23:08:35 +0000
commit65d7ba85eb06f50204743d6560b269e92b7e2e5b (patch)
treedf91e13e154bcdb4a170d3b19e5291bed2b90e23 /framework/bundles/org.eclipse.ecf.filetransfer.ui
parent6a17ce4032251da0c2ec8ccb8eee1e8e6f826728 (diff)
downloadorg.eclipse.ecf-65d7ba85eb06f50204743d6560b269e92b7e2e5b.tar.gz
org.eclipse.ecf-65d7ba85eb06f50204743d6560b269e92b7e2e5b.tar.xz
org.eclipse.ecf-65d7ba85eb06f50204743d6560b269e92b7e2e5b.zip
Added contribution from Paul Webster, via bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219636
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.filetransfer.ui')
-rw-r--r--framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml14
-rw-r--r--framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/GetFileHandler.java88
-rw-r--r--framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/ScpDialog.java99
-rw-r--r--framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties7
4 files changed, 208 insertions, 0 deletions
diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml b/framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml
index cda20785a..75d8fb21b 100644
--- a/framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml
+++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml
@@ -13,4 +13,18 @@
id="org.eclipse.ecf.filetransfer.ui"
name="File Transfer"/>
</extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <category
+ id="org.eclipse.ecf.filetransfer.ui.category"
+ name="File Transfer">
+ </category>
+ <command
+ categoryId="org.eclipse.ecf.filetransfer.ui.category"
+ defaultHandler="org.eclipse.ecf.internal.filetransfer.ui.GetFileHandler"
+ description="Use the URL specified to retrieve a file"
+ id="org.eclipse.ecf.filetransfer.ui.getFile"
+ name="Get File">
+ </command>
+ </extension>
</plugin>
diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/GetFileHandler.java b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/GetFileHandler.java
new file mode 100644
index 000000000..bfd0a2a03
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/GetFileHandler.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.filetransfer.ui;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import org.eclipse.core.commands.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.security.ConnectContextFactory;
+import org.eclipse.ecf.filetransfer.IFileTransferListener;
+import org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter;
+import org.eclipse.ecf.filetransfer.events.*;
+import org.eclipse.ecf.filetransfer.identity.FileIDFactory;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class GetFileHandler extends AbstractHandler {
+
+ private static final String SCP_JOB_FAMILY = "scp"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent o) throws ExecutionException {
+ Shell shell = HandlerUtil.getActiveShellChecked(o);
+ ScpDialog dialog = new ScpDialog(shell, Messages.getString("GetFileHandler.FileTransfer"), Messages.getString("GetFileHandler.Source"), null, null); //$NON-NLS-1$ //$NON-NLS-2$
+ if (dialog.open() == Window.OK) {
+ final String scp = dialog.getValue();
+ final String userid = dialog.userid;
+ final String passwd = dialog.passwd;
+ final String fileName = dialog.filename;
+ new Job(SCP_JOB_FAMILY) {
+
+ protected IStatus run(final IProgressMonitor monitor) {
+ try {
+ final IContainer container = ContainerFactory.getDefault().createContainer();
+ IRetrieveFileTransferContainerAdapter adapter = (IRetrieveFileTransferContainerAdapter) container.getAdapter(IRetrieveFileTransferContainerAdapter.class);
+ final FileOutputStream out = new FileOutputStream(fileName);
+ IFileTransferListener listener = new IFileTransferListener() {
+
+ public void handleTransferEvent(IFileTransferEvent event) {
+ if (event instanceof IIncomingFileTransferReceiveStartEvent) {
+ IIncomingFileTransferReceiveStartEvent rse = (IIncomingFileTransferReceiveStartEvent) event;
+ try {
+ rse.receive(out);
+ } catch (IOException e) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "failed to set output file", e)); //$NON-NLS-1$
+ }
+ } else if (event instanceof IIncomingFileTransferReceiveDataEvent) {
+ monitor.worked(1);
+ } else if (event instanceof IIncomingFileTransferReceiveDoneEvent) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "failed to close output file", e)); //$NON-NLS-1$
+ }
+ }
+ }
+ };
+ adapter.setConnectContextForAuthentication(ConnectContextFactory.createUsernamePasswordConnectContext(userid, passwd));
+ monitor.beginTask(SCP_JOB_FAMILY, IProgressMonitor.UNKNOWN);
+ adapter.sendRetrieveRequest(FileIDFactory.getDefault().createFileID(adapter.getRetrieveNamespace(), scp), listener, null);
+
+ } catch (Exception e) {
+ monitor.done();
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "get file failed", e); //$NON-NLS-1$
+ }
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
+ return null;
+ }
+
+}
diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/ScpDialog.java b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/ScpDialog.java
new file mode 100644
index 000000000..199629933
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/ScpDialog.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.filetransfer.ui;
+
+import java.io.File;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.*;
+
+public class ScpDialog extends InputDialog {
+
+ private Text useridText;
+ private Text passwordText;
+ public String userid;
+ public String passwd;
+ public String filename;
+ protected Text fileLocation;
+
+ public ScpDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator) {
+ super(parentShell, dialogTitle, dialogMessage, initialValue, validator);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ Label label = new Label(composite, SWT.WRAP);
+ label.setText(Messages.getString("ScpDialog.OutputFile")); //$NON-NLS-1$
+ GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ label.setLayoutData(data);
+ label.setFont(parent.getFont());
+ fileLocation = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ fileLocation.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ final Button fileBrowse = new Button(composite, SWT.PUSH);
+ fileBrowse.setText(Messages.getString("ScpDialog.Browse")); //$NON-NLS-1$
+ fileBrowse.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Selection) {
+ String scp = getValue();
+ String fileName = ""; //$NON-NLS-1$
+ String path = System.getProperty("user.home"); //$NON-NLS-1$
+ if (Platform.getOS().startsWith("win")) { //$NON-NLS-1$
+ path = path + File.separator + "Desktop"; //$NON-NLS-1$
+ }
+ if (scp != null && scp.length() > 0) {
+ fileName = scp.substring(scp.lastIndexOf('/') + 1);
+ }
+ FileDialog fd = new FileDialog(fileBrowse.getShell(), SWT.SAVE);
+ fd.setText(Messages.getString("ScpDialog.OutputFile")); //$NON-NLS-1$
+ fd.setFileName(fileName);
+ fd.setFilterPath(path);
+ String fname = fd.open();
+ if (fname != null) {
+ fileLocation.setText(fname);
+ }
+ }
+ }
+ });
+
+ label = new Label(composite, SWT.WRAP);
+ label.setText(Messages.getString("ScpDialog.Userid")); //$NON-NLS-1$
+ data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ label.setLayoutData(data);
+ label.setFont(parent.getFont());
+ useridText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ useridText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
+
+ label = new Label(composite, SWT.WRAP);
+ label.setText(Messages.getString("ScpDialog.Password")); //$NON-NLS-1$
+ data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ label.setLayoutData(data);
+ label.setFont(parent.getFont());
+ passwordText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
+ passwordText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == IDialogConstants.OK_ID) {
+ userid = useridText.getText();
+ passwd = passwordText.getText();
+ filename = fileLocation.getText();
+ }
+ super.buttonPressed(buttonId);
+ }
+}
diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties
index a54681c84..f07a80c78 100644
--- a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties
+++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties
@@ -7,3 +7,10 @@ AbstractFileSendAction.TITLE_FILE_TRANSFER_SUCESSFUL=File transfer completed
AbstractFileSendAction.MESSAGE_FILE_TRANSFER_SUCCESSFUL=Transfer of file {0} completed successfully
AbstractFileSendAction.TITLE_FILE_TRANSFER_FAILED=File transfer failed
AbstractFileSendAction.MESSAGE_FILE_TRANSFER_FAILED=Transfer of file {0} failed.\n\nException:
+GetFileHandler.FileTransfer=File Transfer
+GetFileHandler.Source=Transfer Source (http, scp, etc)
+ScpDialog.Browse=Browse...
+ScpDialog.OutputFile=Output File
+ScpDialog.Password=Password
+ScpDialog.TargetFile=File
+ScpDialog.Userid=Userid

Back to the top