]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ImportToServerWizardPage.java
5a1669cbe3212faaad3413b970c645e36bcfea0e
[lgpl/argeo-commons.git] / ImportToServerWizardPage.java
1 package org.argeo.eclipse.ui.specific;
2
3 import java.io.InputStream;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.ArgeoException;
8 import org.eclipse.jface.wizard.WizardPage;
9 import org.eclipse.rwt.widgets.Upload;
10 import org.eclipse.swt.SWT;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
15
16 public class ImportToServerWizardPage extends WizardPage {
17 private final static Log log = LogFactory
18 .getLog(ImportToServerWizardPage.class);
19
20 public final static String FILE_ITEM_TYPE = "FILE";
21 public final static String FOLDER_ITEM_TYPE = "FOLDER";
22
23 private Upload uploadFile;
24
25 public ImportToServerWizardPage() {
26 super("Import from file system");
27 setDescription("Import files from the local file system to the server");
28 }
29
30 public void createControl(Composite parent) {
31 Composite composite = new Composite(parent, SWT.NONE);
32 composite.setLayout(new GridLayout(2, false));
33 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
34 new Label(composite, SWT.NONE).setText("Pick up a file");
35 uploadFile = new Upload(composite, SWT.BORDER);
36 uploadFile.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
37 uploadFile.setBrowseButtonText("Open...");
38 setControl(composite);
39 }
40
41 public String getObjectPath() {
42 // NOTE Returns the full file name of the last uploaded file including
43 // the file path as selected by the user on his local machine.
44 // The full path including the directory and file drive are only
45 // returned, if the browser supports reading this properties. In Firefox
46 // 3, only the filename is returned.
47 return uploadFile.getPath();
48 }
49
50 public String getObjectName() {
51 return uploadFile.getUploadItem().getFileName();
52 }
53
54 public String getObjectType() {
55 return FILE_ITEM_TYPE;
56 }
57
58 public void performFinish() {
59 boolean success = uploadFile.performUpload();
60 if (!success)
61 throw new ArgeoException("Cannot upload file named "
62 + uploadFile.getPath());
63 }
64
65 protected void handleUploadFinished(final Upload upload) {
66 }
67
68 public InputStream getFileInputStream() {
69 return uploadFile.getUploadItem().getFileInputStream();
70 }
71
72 public boolean getNeedsProgressMonitor() {
73 return false;
74 }
75
76 }