]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.rcp/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
;
19 import java
.io
.IOException
;
21 import org
.apache
.commons
.io
.FileUtils
;
22 import org
.argeo
.ArgeoException
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.events
.ModifyListener
;
25 import org
.eclipse
.swt
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Button
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Event
;
30 import org
.eclipse
.swt
.widgets
.FileDialog
;
31 import org
.eclipse
.swt
.widgets
.Listener
;
32 import org
.eclipse
.swt
.widgets
.Text
;
35 * RCP specific composite that provides a control to upload a file. WARNING: for
36 * the time being we set a GridLayout(2, false) on th eparent control.
38 public class GenericUploadControl
extends Composite
{
39 // private final static Log log = LogFactory
40 // .getLog(GenericUploadControl.class);
42 private FileDialog dialog
;
43 private Text filePath
;
45 public GenericUploadControl(Composite parent
, int style
, String browseLabel
) {
47 createControl(this, browseLabel
);
51 private void createControl(final Composite parent
, String browseLabel
) {
52 parent
.setLayout(new GridLayout(2, false));
54 filePath
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
);
55 GridData gd
= new GridData(GridData
.GRAB_HORIZONTAL
56 | GridData
.FILL_HORIZONTAL
);
57 filePath
.setEditable(false);
58 filePath
.setLayoutData(gd
);
61 Button execute
= new Button(parent
, SWT
.PUSH
);
62 GridData gridData
= new GridData();
63 gridData
.horizontalAlignment
= GridData
.BEGINNING
;
64 execute
.setLayoutData(gridData
);
65 execute
.setText(browseLabel
);
68 Listener executeListener
= new Listener() {
69 public void handleEvent(Event event
) {
70 dialog
= new FileDialog(parent
.getShell());
71 filePath
.setText(dialog
.open());
75 execute
.addListener(SWT
.Selection
, executeListener
);
78 public boolean isControlEmpty() {
79 String path
= filePath
.getText();
80 if (path
== null || "".equals(path
.trim()))
86 public byte[] performUpload() {
87 String path
= filePath
.getText();
90 File file
= new File(path
);
91 byte[] fileBA
= FileUtils
.readFileToByteArray(file
);
93 } catch (IOException e
) {
94 throw new ArgeoException("Unexpected error while "
95 + "reading file at path " + path
, e
);
101 public void addModifyListener(ModifyListener listener
) {
102 filePath
.addModifyListener(listener
);
106 * Always returns null in an RCP environment
108 public String
getLastFileUploadedName() {