]> git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java
First try to solve RAP specific file download service issue revealed by the upgrade...
[lgpl/argeo-commons.git] / base / runtime / org.argeo.eclipse.ui.rap / src / main / java / org / argeo / eclipse / ui / specific / GenericUploadControl.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.eclipse.ui.specific;
17
18 import java.io.InputStream;
19
20 import org.apache.commons.io.IOUtils;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.argeo.ArgeoException;
24 //import org.eclipse.rap.rwt.widgets.Upload;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.ModifyListener;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Composite;
30
31 public class GenericUploadControl extends Composite {
32 private final static Log log = LogFactory
33 .getLog(GenericUploadControl.class);
34
35 //private Upload upload;
36
37 public GenericUploadControl(Composite parent, int style, String browseLabel) {
38 super(parent, style);
39 createControl(this, browseLabel);
40
41 }
42
43 private void createControl(Composite parent, String browseLabel) {
44 parent.setLayout(new GridLayout(1, false));
45 parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
46
47 // upload = new Upload(parent, SWT.BORDER);
48 // upload.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
49 // upload.setBrowseButtonText(browseLabel);
50 // upload.addModifyListener(new UploadListener());
51 parent.pack();
52 }
53
54 /**
55 * Wrap upload.getLastFileUploaded(). Gets the name of the last uploaded
56 * file. This method can be called even if the upload has not finished yet.
57 */
58 public String getLastFileUploadedName() {
59 return "";
60 }
61
62 public boolean isControlEmpty() {
63 String path = "";
64 if (log.isTraceEnabled())
65 log.trace("UploadControl chosen path : " + path);
66 if (path == null || "".equals(path.trim()))
67 return true;
68 else
69 return false;
70 }
71
72 public byte[] performUpload() {
73 // boolean success = upload.performUpload();
74 // if (success) {
75 // if (upload.getUploadItem().getFileSize() == -1)
76 // throw new ArgeoException("File "
77 // + upload.getUploadItem().getFileName()
78 // + " has not been uploaded, its size is -1");
79 //
80 // InputStream inStream = null;
81 // byte[] fileBA = null;
82 // try {
83 // inStream = upload.getUploadItem().getFileInputStream();
84 // fileBA = IOUtils.toByteArray(inStream);
85 // } catch (Exception e) {
86 // throw new ArgeoException("Cannot read uploaded data", e);
87 // } finally {
88 // IOUtils.closeQuietly(inStream);
89 // }
90 // return fileBA;
91 // }
92 return null;
93 }
94
95 public void addModifyListener(ModifyListener listener) {
96 // upload.addModifyListener(listener);
97 }
98
99 // private class UploadManager extends UploadAdapter {
100 // private Upload upload;
101 //
102 // public UploadManager(Upload upload) {
103 // super();
104 // this.upload = upload;
105 // }
106 //
107 // public void uploadFinished(UploadEvent uploadEvent) {
108 // handleUploadFinished(upload);
109 // }
110 //
111 // public void uploadInProgress(UploadEvent uploadEvent) {
112 // }
113 //
114 // public void uploadException(UploadEvent uploadEvent) {
115 // Exception exc = uploadEvent.getUploadException();
116 // if (exc != null) {
117 // MessageDialog.openError(Display.getCurrent().getActiveShell(),
118 // "Error", exc.getMessage());
119 // }
120 // }
121 //
122 // }
123 //
124
125 }