]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java
1 package org
.argeo
.eclipse
.ui
.specific
;
4 import java
.io
.IOException
;
6 import org
.apache
.commons
.io
.FileUtils
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.eclipse
.swt
.SWT
;
10 import org
.eclipse
.swt
.events
.ModifyListener
;
11 import org
.eclipse
.swt
.layout
.GridData
;
12 import org
.eclipse
.swt
.layout
.GridLayout
;
13 import org
.eclipse
.swt
.widgets
.Button
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Event
;
16 import org
.eclipse
.swt
.widgets
.FileDialog
;
17 import org
.eclipse
.swt
.widgets
.Listener
;
18 import org
.eclipse
.swt
.widgets
.Text
;
20 public class GenericUploadControl
extends Composite
{
21 private final static Log log
= LogFactory
22 .getLog(GenericUploadControl
.class);
24 private FileDialog dialog
;
25 private Text filePath
;
27 public GenericUploadControl(Composite parent
, int style
, String browseLabel
) {
29 createControl(this, browseLabel
);
33 private void createControl(final Composite parent
, String browseLabel
) {
34 Composite composite
= new Composite(parent
, SWT
.FILL
);
35 composite
.setLayout(new GridLayout(2, false));
36 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
38 filePath
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
);
39 filePath
.setEnabled(false);
42 Button execute
= new Button(parent
, SWT
.PUSH
);
43 GridData gridData
= new GridData();
44 gridData
.horizontalAlignment
= GridData
.BEGINNING
;
45 execute
.setLayoutData(gridData
);
46 execute
.setText(browseLabel
);
49 Listener executeListener
= new Listener() {
50 public void handleEvent(Event event
) {
51 dialog
= new FileDialog(parent
.getShell());
57 execute
.addListener(SWT
.Selection
, executeListener
);
60 public boolean isControlEmpty() {
61 String path
= filePath
.getText();
62 if (path
== null || "".equals(path
.trim()))
68 public byte[] performUpload() {
69 String path
= filePath
.getText();
72 File file
= new File(path
);
73 byte[] fileBA
= FileUtils
.readFileToByteArray(file
);
75 } catch (IOException e
) {
76 // TODO Auto-generated catch block
83 public void addModifyListener(ModifyListener listener
) {
84 filePath
.addModifyListener(listener
);
87 // private class UploadManager extends UploadAdapter {
88 // private Upload upload;
90 // public UploadManager(Upload upload) {
92 // this.upload = upload;
95 // public void uploadFinished(UploadEvent uploadEvent) {
96 // handleUploadFinished(upload);
99 // public void uploadInProgress(UploadEvent uploadEvent) {
102 // public void uploadException(UploadEvent uploadEvent) {
103 // Exception exc = uploadEvent.getUploadException();
104 // if (exc != null) {
105 // MessageDialog.openError(Display.getCurrent().getActiveShell(),
106 // "Error", exc.getMessage());