1 package org
.argeo
.eclipse
.ui
.specific
;
3 import java
.io
.InputStream
;
5 import org
.apache
.commons
.logging
.Log
;
6 import org
.apache
.commons
.logging
.LogFactory
;
7 import org
.argeo
.ArgeoException
;
8 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
9 import org
.eclipse
.jface
.wizard
.WizardPage
;
10 import org
.eclipse
.rwt
.widgets
.Upload
;
11 import org
.eclipse
.rwt
.widgets
.UploadAdapter
;
12 import org
.eclipse
.rwt
.widgets
.UploadEvent
;
13 import org
.eclipse
.rwt
.widgets
.UploadItem
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Display
;
19 import org
.eclipse
.swt
.widgets
.Label
;
21 public class ImportFileSystemWizardPage
extends WizardPage
{
22 private Log log
= LogFactory
.getLog(ImportFileSystemWizardPage
.class);
24 private Upload uploadFile
;
26 public ImportFileSystemWizardPage() {
27 super("Import from file system");
28 setDescription("Import files from the local file system into the JCR repository");
31 public void createControl(Composite parent
) {
33 Composite composite
= new Composite(parent
, SWT
.NONE
);
34 composite
.setLayout(new GridLayout(2, false));
35 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
37 new Label(composite
, SWT
.NONE
).setText("Pick up a file");
39 uploadFile
= new Upload(composite
, SWT
.BORDER
);
40 uploadFile
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
41 uploadFile
.setBrowseButtonText("Open...");
42 uploadFile
.addUploadListener(new UploadManager(uploadFile
));
44 setControl(composite
);
47 public String
getObjectPath() {
48 // NOTE Returns the full file name of the last uploaded file including
49 // the file path as selected by the user on his local machine.
50 // The full path including the directory and file drive are only
51 // returned, if the browser supports reading this properties. In Firefox
52 // 3, only the filename is returned.
53 return uploadFile
.getPath();
56 public String
getObjectName() {
57 return uploadFile
.getUploadItem().getFileName();
60 public String
getObjectType() {
64 public void performFinish() {
65 boolean success
= uploadFile
.performUpload();
67 throw new ArgeoException("Cannot upload file named "
68 + uploadFile
.getPath());
71 protected void handleUploadFinished(final Upload upload
) {
72 if (log
.isTraceEnabled()) {
73 UploadItem uploadItem
= upload
.getUploadItem();
74 log
.trace("filename : " + uploadItem
.getFileName());
75 log
.trace("content-type : " + uploadItem
.getContentType());
79 public InputStream
getFileInputStream() {
80 return uploadFile
.getUploadItem().getFileInputStream();
83 private class UploadManager
extends UploadAdapter
{
84 private Upload upload
;
86 public UploadManager(Upload upload
) {
91 public void uploadFinished(UploadEvent uploadEvent
) {
92 handleUploadFinished(upload
);
95 public void uploadInProgress(UploadEvent uploadEvent
) {
98 public void uploadException(UploadEvent uploadEvent
) {
99 Exception exc
= uploadEvent
.getUploadException();
101 MessageDialog
.openError(Display
.getCurrent().getActiveShell(),
102 "Error", exc
.getMessage());