001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.channel.ho.client.swing;
032:
033: import java.awt.*;
034:
035: import javax.swing.*;
036:
037: import de.ug2t.kernel.*;
038: import de.ug2t.unifiedGui.interfaces.*;
039:
040: public final class HoSwingFileCooser extends HoSwingComponent implements
041: IUnFileChooser {
042: private JFileChooser pem_swingObj = null;
043: private String pem_cpath = null;
044: private boolean pem_upload = false;
045:
046: /**
047: * @param xName
048: * @param xAppl
049: * @throws Exception
050: */
051: public HoSwingFileCooser(String xName, String xValue,
052: IUnApplication xAppl) throws Exception {
053: super (xName, xAppl);
054: this .pcmf_setValue(xValue);
055: this .pcmf_setEventOnChange(true);
056: this .pem_cpath = xValue;
057:
058: this .pem_swingObj = null;
059: this .pdm_realSwingCmp = new JLabel();
060:
061: return;
062: }
063:
064: public void pcmf_setUploadReadFile(boolean xUpload) {
065: this .pem_upload = xUpload;
066: }
067:
068: private void pemf_createFsObject() {
069: if (this .pdm_realSwingCmp instanceof JLabel) {
070: Container l_cont = this .pdm_realSwingCmp.getParent();
071:
072: if (l_cont != null)
073: l_cont.remove(this .pdm_realSwingCmp);
074:
075: this .pdm_realSwingCmp = this .pem_swingObj = new JFileChooser(
076: this .pem_cpath);
077:
078: if (l_cont != null)
079: l_cont.add(this .pdm_realSwingCmp);
080: }
081: }
082:
083: public void pcmf_selectReadFile() {
084: try {
085: this .pemf_createFsObject();
086: int l_ret = 0;
087: this .pem_swingObj
088: .setFileSelectionMode(JFileChooser.FILES_ONLY);
089: l_ret = this .pem_swingObj
090: .showOpenDialog(((HoSwingPage) this .pcmf_getAppl()
091: .pcmf_getActive()).pcmf_getRealSwingObj());
092: if (l_ret == JFileChooser.APPROVE_OPTION) {
093: if (this .pem_upload) {
094: this .pcmf_setLocalValue("r"
095: + this .pem_swingObj.getSelectedFile()
096: .getName());
097: this .pem_session.pcmf_writeFile(this .pem_swingObj
098: .getSelectedFile().getAbsolutePath());
099: } else
100: this .pcmf_setLocalValue("r"
101: + this .pem_swingObj.getSelectedFile()
102: .getAbsolutePath());
103:
104: this .pcmf_setRefresh();
105: this .pcmf_dispatchEvent();
106:
107: ((HoSwingPage) this .pcmf_getAppl().pcmf_getActive())
108: .pcmf_setSubmitValue(this .pcmf_getObjName(),
109: this .pcmf_getValue().toString());
110: this .pcmf_addSyncedWidgets((HoSwingPage) this
111: .pcmf_getAppl().pcmf_getActive(), this );
112: if (this .pcmf_getUnComponent().pcmf_isSubmit() == true)
113: ((HoSwingPage) this .pcmf_getAppl().pcmf_getActive())
114: .pcmf_submit();
115: }
116: } catch (Exception e) {
117: KeLog.pcmf_logException("ug2t", this , e);
118: }
119: ;
120:
121: return;
122: }
123:
124: public void pcmf_selectFile() {
125: try {
126: this .pemf_createFsObject();
127: int l_ret = 0;
128: this .pem_swingObj
129: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
130: l_ret = this .pem_swingObj.showDialog(((HoSwingPage) this
131: .pcmf_getAppl().pcmf_getActive())
132: .pcmf_getRealSwingObj(), "select");
133: if (l_ret == JFileChooser.APPROVE_OPTION) {
134: this .pcmf_setLocalValue("s"
135: + this .pem_swingObj.getSelectedFile()
136: .getAbsolutePath());
137: this .pcmf_setRefresh();
138: this .pcmf_dispatchEvent();
139:
140: ((HoSwingPage) this .pcmf_getAppl().pcmf_getActive())
141: .pcmf_setSubmitValue(this .pcmf_getObjName(),
142: this .pcmf_getValue().toString());
143: if (this .pcmf_getUnComponent().pcmf_isSubmit() == true)
144: ((HoSwingPage) this .pcmf_getAppl().pcmf_getActive())
145: .pcmf_submit();
146: }
147: } catch (Exception e) {
148: KeLog.pcmf_logException(this .pcmf_getAppl()
149: .pcmf_getUnComponent().pcmf_getName(), this , e);
150: }
151: ;
152:
153: return;
154: }
155:
156: public void pcmf_selectWriteFile() {
157: try {
158: this .pemf_createFsObject();
159: int l_ret = 0;
160: this .pem_swingObj
161: .setFileSelectionMode(JFileChooser.FILES_ONLY);
162: l_ret = this .pem_swingObj
163: .showSaveDialog(((HoSwingPage) this .pcmf_getAppl()
164: .pcmf_getActive()).pcmf_getRealSwingObj());
165: if (l_ret == JFileChooser.APPROVE_OPTION) {
166: this .pcmf_setLocalValue("w"
167: + this .pem_swingObj.getSelectedFile()
168: .getAbsolutePath());
169: this .pcmf_setRefresh();
170: this .pcmf_dispatchEvent();
171:
172: ((HoSwingPage) this .pcmf_getAppl().pcmf_getActive())
173: .pcmf_setSubmitValue(this .pcmf_getObjName(),
174: this .pcmf_getValue().toString());
175: if (this .pcmf_getUnComponent().pcmf_isSubmit() == true)
176: ((HoSwingPage) this .pcmf_getAppl().pcmf_getActive())
177: .pcmf_submit();
178: }
179: } catch (Exception e) {
180: KeLog.pcmf_logException(this .pcmf_getAppl()
181: .pcmf_getUnComponent().pcmf_getPath(), this , e);
182: }
183: ;
184:
185: return;
186: }
187:
188: public char pcmf_getMode() {
189: return (this .pdm_Element.toString().toCharArray()[0]);
190: };
191: }
|