01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.client.gwt.widget;
22:
23: import java.util.ArrayList;
24: import java.util.List;
25: import com.google.gwt.user.client.ui.*;
26:
27: public class FileChooser extends FormPanel {
28:
29: private List _listener = new ArrayList();
30:
31: private FlexTable _content = new FlexTable();
32:
33: private FileUpload _upload = new FileUpload();
34:
35: private String _id;
36:
37: private Hidden _clicked = new Hidden();
38:
39: public FileChooser(String id) {
40: _id = id;
41: _upload.setName(id + ".File");
42: _clicked.setValue("true");
43: setEncoding(FormPanel.ENCODING_MULTIPART);
44: setMethod(FormPanel.METHOD_POST);
45: add(_content);
46: _content.setWidget(0, 0, _upload);
47: _content.getFlexCellFormatter().setColSpan(0, 0, 2);
48: Button okBtn = new Button("Ok");
49: Button cancelBtn = new Button("Cancel");
50: okBtn.addClickListener(new ClickListener() {
51:
52: public void onClick(Widget sender) {
53: _clicked.setName(_id + ".OK");
54: fireOkEvent();
55: }
56: });
57: cancelBtn.addClickListener(new ClickListener() {
58:
59: public void onClick(Widget sender) {
60: _clicked.setName(_id + ".CANCEL");
61: fireCancelEvent();
62: }
63: });
64: _content.setWidget(1, 0, okBtn);
65: _content.setWidget(1, 1, cancelBtn);
66: _content.setWidget(2, 0, _clicked);
67:
68: }
69:
70: public void addChooserListener(ChooserListener l) {
71: _listener.add(l);
72: }
73:
74: private void fireOkEvent() {
75: for (int i = 0; i < _listener.size(); i++) {
76: ChooserListener l = (ChooserListener) _listener.get(i);
77: l.chooseOk(this );
78: }
79: }
80:
81: private void fireCancelEvent() {
82: for (int i = 0; i < _listener.size(); i++) {
83: ChooserListener l = (ChooserListener) _listener.get(i);
84: l.chooseCancel(this);
85: }
86: }
87: }
|