]>
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
2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.eclipse
.ui
.specific
;
18 import java
.io
.InputStream
;
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
;
31 public class GenericUploadControl
extends Composite
{
32 private final static Log log
= LogFactory
33 .getLog(GenericUploadControl
.class);
35 //private Upload upload;
37 public GenericUploadControl(Composite parent
, int style
, String browseLabel
) {
39 createControl(this, browseLabel
);
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));
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());
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.
58 public String
getLastFileUploadedName() {
62 public boolean isControlEmpty() {
64 if (log
.isTraceEnabled())
65 log
.trace("UploadControl chosen path : " + path
);
66 if (path
== null || "".equals(path
.trim()))
72 public byte[] performUpload() {
73 // boolean success = upload.performUpload();
75 // if (upload.getUploadItem().getFileSize() == -1)
76 // throw new ArgeoException("File "
77 // + upload.getUploadItem().getFileName()
78 // + " has not been uploaded, its size is -1");
80 // InputStream inStream = null;
81 // byte[] fileBA = null;
83 // inStream = upload.getUploadItem().getFileInputStream();
84 // fileBA = IOUtils.toByteArray(inStream);
85 // } catch (Exception e) {
86 // throw new ArgeoException("Cannot read uploaded data", e);
88 // IOUtils.closeQuietly(inStream);
95 public void addModifyListener(ModifyListener listener
) {
96 // upload.addModifyListener(listener);
99 // private class UploadManager extends UploadAdapter {
100 // private Upload upload;
102 // public UploadManager(Upload upload) {
104 // this.upload = upload;
107 // public void uploadFinished(UploadEvent uploadEvent) {
108 // handleUploadFinished(upload);
111 // public void uploadInProgress(UploadEvent uploadEvent) {
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());