0
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.remotecontrol.ftp.ui.actions;
|
|
19 |
|
|
20 |
import org.eclipse.core.resources.ResourcesPlugin;
|
|
21 |
import org.eclipse.core.runtime.IPath;
|
|
22 |
import org.eclipse.jface.action.IAction;
|
|
23 |
import org.eclipse.jface.viewers.TableViewer;
|
|
24 |
import org.eclipse.swt.SWT;
|
|
25 |
import org.eclipse.swt.widgets.FileDialog;
|
|
26 |
import org.eclipse.swt.widgets.Shell;
|
|
27 |
|
|
28 |
import com.nokia.s60tools.remotecontrol.RemoteControlActivator;
|
|
29 |
import com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpUtils;
|
|
30 |
import com.nokia.s60tools.remotecontrol.ftp.ui.view.ViewContentProvider;
|
|
31 |
import com.nokia.s60tools.remotecontrol.preferences.RCPreferences;
|
|
32 |
import com.nokia.s60tools.remotecontrol.resources.ImageKeys;
|
|
33 |
import com.nokia.s60tools.remotecontrol.resources.ImageResourceManager;
|
|
34 |
import com.nokia.s60tools.remotecontrol.resources.Messages;
|
|
35 |
import com.nokia.s60tools.ui.actions.S60ToolsBaseAction;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Action for uploading file from device
|
|
39 |
*/
|
|
40 |
public class UploadFileAction extends S60ToolsBaseAction {
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Viewer that is target for action.
|
|
44 |
*/
|
|
45 |
private TableViewer viewer;
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Content provider
|
|
49 |
*/
|
|
50 |
private ViewContentProvider contentProvider;
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Constructor
|
|
54 |
* @param viewer TableViewer.
|
|
55 |
* @param contentProvider Content provider.
|
|
56 |
*/
|
|
57 |
public UploadFileAction(TableViewer viewer, ViewContentProvider contentProvider) {
|
|
58 |
super(Messages.getString("UploadFileAction.Action_Name"), //$NON-NLS-1$
|
|
59 |
Messages.getString("UploadFileAction.Tooltip_Name"), //$NON-NLS-1$
|
|
60 |
IAction.AS_PUSH_BUTTON,
|
|
61 |
ImageResourceManager.getImageDescriptor(ImageKeys.IMG_UPLOAD));
|
|
62 |
this.viewer = viewer;
|
|
63 |
this.contentProvider = contentProvider;
|
|
64 |
}
|
|
65 |
|
|
66 |
/*
|
|
67 |
* (non-Javadoc)
|
|
68 |
*
|
|
69 |
* @see org.eclipse.jface.action.Action#run()
|
|
70 |
*/
|
|
71 |
public void run() {
|
|
72 |
|
|
73 |
// Show select files dialog to user
|
|
74 |
|
|
75 |
Shell sh = RemoteControlActivator.getCurrentlyActiveWbWindowShell();
|
|
76 |
FileDialog fileDialog = new FileDialog(sh, SWT.MULTI);
|
|
77 |
fileDialog.setText(Messages.getString("UploadFileAction.SelectUploadFiles_DlgText")); //$NON-NLS-1$
|
|
78 |
|
|
79 |
String uploadFilterPath = RCPreferences.getUploadLocation();
|
|
80 |
if (uploadFilterPath == "") { //$NON-NLS-1$
|
|
81 |
// Workspace root is used as default folder
|
|
82 |
IPath location = ResourcesPlugin.getWorkspace().getRoot().getLocation();
|
|
83 |
fileDialog.setFilterPath(location.toString());
|
|
84 |
} else {
|
|
85 |
// use last used folder
|
|
86 |
fileDialog.setFilterPath(uploadFilterPath);
|
|
87 |
}
|
|
88 |
|
|
89 |
if (fileDialog.open() == null) {
|
|
90 |
// User is canceled dialog
|
|
91 |
return;
|
|
92 |
}
|
|
93 |
|
|
94 |
String[] uploadFiles = fileDialog.getFileNames();
|
|
95 |
String srcDir = fileDialog.getFilterPath();
|
|
96 |
// Remember last used folder
|
|
97 |
RCPreferences.setUploadLocation(srcDir);
|
|
98 |
|
|
99 |
// Get upload path
|
|
100 |
String uploadDir = FtpUtils.getUploadDirectory(viewer, contentProvider);
|
|
101 |
|
|
102 |
String[] sourceFiles = getSourceFiles(srcDir, uploadFiles);
|
|
103 |
if(uploadDir != null) {
|
|
104 |
// Uploading files only when not in root.
|
|
105 |
FtpUtils.uploadFiles(uploadDir, sourceFiles);
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
* Returns list of file names concatenated with path.
|
|
111 |
* @param srcDir Directory to be concatenated with file names.
|
|
112 |
* @param uploadFiles List of file names to be concatenated with directory.
|
|
113 |
* @return List of files with path.
|
|
114 |
*/
|
|
115 |
private String[] getSourceFiles(String srcDir, String[] uploadFiles) {
|
|
116 |
String[] srcFiles = new String[uploadFiles.length];
|
|
117 |
for(int i = 0;i < uploadFiles.length;i++) {
|
|
118 |
srcFiles[i] = FtpUtils.addFileSepatorToEnd(srcDir) + uploadFiles[i];
|
|
119 |
}
|
|
120 |
return srcFiles;
|
|
121 |
}
|
|
122 |
}
|