]> git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java
-> Finalisation of file download for RAP
[lgpl/argeo-commons.git] / eclipse / runtime / org.argeo.eclipse.ui.rap / src / main / java / org / argeo / eclipse / ui / specific / ImportFileSystemWizardPage.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 ImportFileSystemWizardPage extends WizardPage {
17 private final static Log log = LogFactory.getLog(ImportFileSystemWizardPage.class);
18
19 private Upload uploadFile;
20
21 public ImportFileSystemWizardPage() {
22 super("Import from file system");
23 setDescription("Import files from the local file system into the JCR repository");
24 }
25
26 public void createControl(Composite parent) {
27 Composite composite = new Composite(parent, SWT.NONE);
28 composite.setLayout(new GridLayout(2, false));
29 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
30 new Label(composite, SWT.NONE).setText("Pick up a file");
31 uploadFile = new Upload(composite, SWT.BORDER);
32 uploadFile.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
33 uploadFile.setBrowseButtonText("Open...");
34 setControl(composite);
35 }
36
37 public String getObjectPath() {
38 // NOTE Returns the full file name of the last uploaded file including
39 // the file path as selected by the user on his local machine.
40 // The full path including the directory and file drive are only
41 // returned, if the browser supports reading this properties. In Firefox
42 // 3, only the filename is returned.
43 return uploadFile.getPath();
44 }
45
46 public String getObjectName() {
47 return uploadFile.getUploadItem().getFileName();
48 }
49
50 public String getObjectType() {
51 return "nt:file";
52 }
53
54 public void performFinish() {
55 boolean success = uploadFile.performUpload();
56 if (!success)
57 throw new ArgeoException("Cannot upload file named "
58 + uploadFile.getPath());
59 }
60
61 protected void handleUploadFinished(final Upload upload) {
62 }
63
64 public InputStream getFileInputStream() {
65 return uploadFile.getUploadItem().getFileInputStream();
66 }
67 }