KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jmc > plugins > serverFileChooser > ServerFileChooser


1 /*
2  * Wi.Ser Framework
3  *
4  * Version: $@VERSION@$, $@DATE@$
5  * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public
18  * License along with this library located in GPL.txt in the
19  * license directory; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  * If this agreement does not cover your requirements, please contact us
24  * via email to get detailed information about the commercial license
25  * or our service offerings!
26  *
27  */

28 package Jmc.plugins.serverFileChooser;
29
30 import java.io.File JavaDoc;
31 import java.util.ArrayList JavaDoc;
32
33 import Jmc.baseGui.base_guiListener;
34 import Jmc.baseGui.base_guiObj;
35 import Jmc.baseTools.base_environment;
36 import Jmc.baseTools.base_log;
37 import Jmc.baseTools.base_registredObject;
38 import Jmc.baseTools.base_table;
39 import Jmc.baseTools.base_treeNode;
40 import Jmc.commonGui.base_table_if;
41 import Jmc.commonGui.base_inputField_if;
42 import Jmc.commonGui.base_text_if;
43 import Jmc.commonGui.base_button_if;
44 import Jmc.commonGui.base_treeView_if;
45 import Jmc.commonGui.simpleNode;
46 import Jmc.plugins.base_aggregatedPlugin;
47 import Jmc.model.base_modelValue_if;
48
49 public class ServerFileChooser extends base_aggregatedPlugin
50 {
51   private base_treeNode pem_tmpnodes = null;
52   private simpleNode pem_root = null;
53   private String JavaDoc pem_rootDir = null;
54   
55   private void pemf_addTmpNode(base_treeNode xNode)
56   {
57     this.pem_tmpnodes.pcmf_addNode(xNode.pcmf_getName(), xNode);
58   };
59
60   private void pemf_removeTmpNode(base_treeNode xNode)
61   {
62     this.pem_tmpnodes.pcmf_removeNode(xNode);
63   };
64   
65   private void pemf_deleteTmpNodes()
66   {
67     this.pem_tmpnodes.pcmf_clearAndRelease();
68   };
69
70   /**
71    * @author Dirk
72    *
73    * date: 26.05.2005
74    * project: ServerFileChooser
75    *
76    * <p>
77    * This listener's execution method is called whenever a selection on the source tree-view has been made.
78    * </p>
79    */

80   public class SelectSource_li implements base_guiListener
81   {
82     private base_table pem_tableValues = null;
83   
84     /**
85          * <p>
86          * Execution method of the listener
87          * </p><p>
88          *
89          * </p><p>
90          * @param xParam widget which provided the event
91          * </p>
92          */

93     public void pcmf_execListener(base_guiObj xParam) throws Exception JavaDoc
94     {
95       // get all relevant objects
96
base_treeView_if l_tree = (base_treeView_if)xParam;
97       base_table_if l_table = (base_table_if)ServerFileChooser.this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_Split").pcmf_getSubNode("ServerFileChooser_FormR").pcmf_getSubNode("ServerFileChooser_Table");
98       base_text_if l_label = (base_text_if)ServerFileChooser.this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_TopForm").pcmf_getSubNode("ServerFileChooser_TopLabel");
99           
100       // test whether a selection or an expansion event occurred - only selection is processed here
101
if (l_tree.pcmf_getToggled() != null || l_tree.pcmf_getValue() instanceof base_treeNode == false)
102         return;
103      
104       // cleanup table
105
if (this.pem_tableValues != null)
106         this.pem_tableValues.pcmf_delete();
107       
108       // cleanup registry
109
ServerFileChooser.this.pemf_deleteTmpNodes();
110         
111       // create new table model
112
pem_tableValues = new base_table(0,2);
113       File JavaDoc l_file = (File JavaDoc)((base_treeNode)l_tree.pcmf_getValue()).pcmf_getValue();
114       l_label.pcmf_getGuiObj().pcmf_setValue("path: " + l_file.getAbsolutePath());
115       
116       // fill new table model
117
File JavaDoc l_subs[] = l_file.listFiles();
118       for (int i = 0; i < l_subs.length; i++)
119       {
120         if (l_subs[i].isDirectory())
121         {
122           String JavaDoc l_fname = l_subs[i].getAbsolutePath();
123   
124           ArrayList JavaDoc l_row = new ArrayList JavaDoc(2);
125           // for the meaning this model things of have a look at "AddFile_li.java"
126
base_treeNode l_modelV = (base_treeNode)((base_modelValue_if)base_registredObject.pcmf_getObjByName("sfilech_model_folder")).pcmf_cloneModelValue(true, false);
127           l_modelV.pcmf_setName(l_fname);
128           l_row.add(l_modelV);
129           l_row.add("0");
130           this.pem_tableValues.pcmf_addRowArrayList(l_row);
131         }
132         else
133         {
134           ArrayList JavaDoc l_row = new ArrayList JavaDoc(2);
135           String JavaDoc l_fname = l_subs[i].getAbsolutePath();
136           String JavaDoc l_flen = Long.toString(l_subs[i].length());
137           
138           if (l_subs[i].getName().toLowerCase().indexOf(".class") != -1)
139           {
140             base_treeNode l_modelV = (base_treeNode)((base_modelValue_if)base_registredObject.pcmf_getObjByName("sfilech_model_class")).pcmf_cloneModelValue(true, false);
141             l_modelV.pcmf_setName(l_fname);
142             ServerFileChooser.this.pemf_addTmpNode(l_modelV);
143             l_row.add(l_modelV);
144           }
145           else
146           if (l_subs[i].getName().toLowerCase().indexOf(".xml") != -1)
147           {
148             base_treeNode l_modelV = (base_treeNode)((base_modelValue_if)base_registredObject.pcmf_getObjByName("sfilech_model_xml")).pcmf_cloneModelValue(true, false);
149             l_modelV.pcmf_setName(l_fname);
150             ServerFileChooser.this.pemf_addTmpNode(l_modelV);
151             l_row.add(l_modelV);
152           }
153           else
154           if (l_subs[i].getName().toLowerCase().indexOf(".java") != -1)
155           {
156             base_treeNode l_modelV = (base_treeNode)((base_modelValue_if)base_registredObject.pcmf_getObjByName("sfilech_model_java")).pcmf_cloneModelValue(true, false);
157             l_modelV.pcmf_setName(l_fname);
158             ServerFileChooser.this.pemf_addTmpNode(l_modelV);
159             l_row.add(l_modelV);
160           }
161           else
162           if (l_subs[i].getName().toLowerCase().indexOf(".jar") != -1 ||
163               l_subs[i].getName().toLowerCase().indexOf(".war") != -1 ||
164               l_subs[i].getName().toLowerCase().indexOf(".ear") != -1 ||
165               l_subs[i].getName().toLowerCase().indexOf(".zip") != -1)
166           {
167             base_treeNode l_modelV = (base_treeNode)((base_modelValue_if)base_registredObject.pcmf_getObjByName("sfilech_model_archive")).pcmf_cloneModelValue(true, false);
168             l_modelV.pcmf_setName(l_fname);
169             ServerFileChooser.this.pemf_addTmpNode(l_modelV);
170             l_row.add(l_modelV);
171           }
172           else
173           {
174             base_treeNode l_modelV = (base_treeNode)((base_modelValue_if)base_registredObject.pcmf_getObjByName("sfilech_model_other")).pcmf_cloneModelValue(true, false);
175             l_modelV.pcmf_setName(l_fname);
176             ServerFileChooser.this.pemf_addTmpNode(l_modelV);
177             l_row.add(l_modelV);
178           }
179           
180           l_row.add(l_flen);
181           this.pem_tableValues.pcmf_addRowArrayList(l_row);
182         }
183       }
184       // put table model to table widget
185
l_table.pcmf_setRowsOnly(pem_tableValues);
186     }
187   }
188
189   /**
190    * @author Dirk
191    *
192    * date: 26.05.2005
193    * project: ServerFileChooser
194    *
195    * <p>
196    * This listener's execution method is called whenever a selection on the file table has been made.
197    * </p>
198    */

199   public class SelectFile_li implements base_guiListener
200   {
201     /**
202          * <p>
203          * Execution method of the listener
204          * </p><p>
205          *
206          * </p><p>
207          * @param xParam widget which provided the event
208          * </p>
209          */

210     public void pcmf_execListener(base_guiObj xParam) throws Exception JavaDoc
211     {
212       // get all relevant objects
213
base_inputField_if l_inp = (base_inputField_if)ServerFileChooser.this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_ButForm").pcmf_getSubNode("ServerFileChooser_SelFile");
214       l_inp.pcmf_setValue(((base_table_if)xParam).pcmf_getSelectedTableRow().get(0));
215     }
216   }
217
218   /**
219    * @author Dirk
220    *
221    * date: 26.05.2005
222    * project: ServerFileChooser
223    *
224    * <p>
225    * This listener's execution method is called whenever the reload button has been pressed.
226    * </p>
227    */

228   public class Reload_li implements base_guiListener
229   {
230     /**
231          * <p>
232          * Execution method of the listener
233          * </p><p>
234          *
235          * </p><p>
236          * @param xParam widget which provided the event
237          * </p>
238          */

239     public void pcmf_execListener(base_guiObj xParam) throws Exception JavaDoc
240     {
241       ServerFileChooser.this.pcmf_reload();
242       base_log.pcmf_log(ServerFileChooser.this.pcmf_getPluginObject().pcmf_getAppl().pcmf_getGuiObj().pcmf_getName(), "ServerFileChooser reloaded", this, base_log.MESSAGE);
243     }
244   }
245   
246   /**
247    * @author Dirk
248    *
249    * date: 26.05.2005
250    * project: ServerFileChooser
251    *
252    * <p>
253    * This listener's execution method is called whenever the select or the cancel button have been pressed.
254    * </p>
255    */

256   public class SelectBut_li implements base_guiListener
257   {
258     /**
259          * <p>
260          * Execution method of the listener
261          * </p><p>
262          *
263          * </p><p>
264          * @param xParam widget which provided the event
265          * </p>
266          */

267     public void pcmf_execListener(base_guiObj xParam) throws Exception JavaDoc
268     {
269       // get all relevant objects
270
base_inputField_if l_inp = (base_inputField_if)ServerFileChooser.this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_ButForm").pcmf_getSubNode("ServerFileChooser_SelFile");
271       
272       if (xParam.pcmf_getName().equals("ServerFileChooser_SBut"))
273         ServerFileChooser.this.pcmf_getPluginObject().pcmf_setValue(l_inp.pcmf_getValue());
274       else
275         ServerFileChooser.this.pcmf_getPluginObject().pcmf_setValue("");
276
277       // dispatch event to form
278
ServerFileChooser.this.pcmf_getPluginObject().pcmf_dispatchEvent();
279     }
280   }
281
282   /**
283    * Adds a listener to the cancel button
284    *
285    * @param xListen listener
286    */

287   public void pcmf_addCancelListener (base_guiListener xListen)
288   {
289     base_button_if l_canBut = (base_button_if)ServerFileChooser.this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_ButForm").pcmf_getSubNode("ServerFileChooser_CBut");
290     l_canBut.pcmf_addListener(xListen);
291   }
292
293   /**
294    * Adds a listener to the select button
295    *
296    * @param xListen listener parameter
297    */

298   public void pcmf_addSelectListener (base_guiListener xListen)
299   {
300     base_button_if l_selBut = (base_button_if)ServerFileChooser.this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_ButForm").pcmf_getSubNode("ServerFileChooser_SBut");
301     l_selBut.pcmf_addListener(xListen);
302   }
303
304   /**
305    * Adds a listener to the select button
306    *
307    * @param xListen listener parameter
308    */

309   public void pcmf_setRootDir(String JavaDoc xDir)
310   {
311     try
312     {
313         this.pem_rootDir = xDir;
314         this.pcmf_reload();
315     }
316     catch (Exception JavaDoc e)
317     {
318       // Something went wrong
319
base_log.pcmf_log(this.pcmf_getPluginObject().pcmf_getAppl().pcmf_getGuiObj().pcmf_getName(), "ServerFileChooser cannot set rootDir: " + xDir, this, base_log.FATAL);
320     }
321   }
322   
323   /**
324    * Reloads the tree of the filechooser
325    */

326   public void pcmf_reload() throws Exception JavaDoc
327   {
328     // get widgets by name
329
base_treeView_if l_sourceTree = (base_treeView_if)this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_Split").pcmf_getSubNode("ServerFileChooser_FormL").pcmf_getSubNode("ServerFileChooser_Tree");
330     base_table_if l_table = (base_table_if)ServerFileChooser.this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_Split").pcmf_getSubNode("ServerFileChooser_FormR").pcmf_getSubNode("ServerFileChooser_Table");
331     
332     this.pemf_deleteTmpNodes();
333
334     // do all initialising steps
335
// read startpoint for displaying the directory structure in the source tree-view
336
File JavaDoc l_root = new File JavaDoc (base_environment.pcmf_buildPath(pem_rootDir));
337     
338     this.pem_root.pcmf_clearAndRelease();
339     // build up directory structure to display it in the source tree-view
340
this.pcmf_buildTree(l_sourceTree.pcmf_getRoot(), l_root, this.pcmf_getPluginObject());
341     
342     l_sourceTree.pcmf_getRoot().pcmf_hideLevel(1);
343     l_table.pcmf_setRowsOnly(new base_table(0,2));
344     
345     // repaint
346
l_sourceTree.pcmf_repaint();
347     l_table.pcmf_repaint();
348   }
349   
350   /**
351    * Initialises the calendar plugin. This is a callback function
352    *
353    * @param xPl root form
354    * @param xParam additional parameter
355    */

356   public void pcmf_initPlugin(base_guiObj xPl, Object JavaDoc xParam, String JavaDoc xRoot)
357   {
358     super.pcmf_initPlugin(xPl, xParam, xRoot);
359
360     try
361     {
362       this.pem_root = new simpleNode("root");
363       this.pem_tmpnodes = new base_treeNode("",null);
364       
365       // get widgets by name
366
base_treeView_if l_sourceTree = (base_treeView_if)this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_Split").pcmf_getSubNode("ServerFileChooser_FormL").pcmf_getSubNode("ServerFileChooser_Tree");
367       base_table_if l_table = (base_table_if)this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_Split").pcmf_getSubNode("ServerFileChooser_FormR").pcmf_getSubNode("ServerFileChooser_Table");
368       base_button_if l_selBut = (base_button_if)this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_ButForm").pcmf_getSubNode("ServerFileChooser_SBut");
369       base_button_if l_canBut = (base_button_if)this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_ButForm").pcmf_getSubNode("ServerFileChooser_CBut");
370       base_button_if l_relBut = (base_button_if)this.pcmf_getPluginObject().pcmf_getSubNode("ServerFileChooser_ButForm").pcmf_getSubNode("ServerFileChooser_RBut");
371       
372       l_sourceTree.pcmf_addListener(new SelectSource_li());
373       l_table.pcmf_addListener(new SelectFile_li());
374       l_table.pcmf_addListener(new SelectFile_li());
375       l_canBut.pcmf_addListener(new SelectBut_li());
376       l_selBut.pcmf_addListener(new SelectBut_li());
377       l_relBut.pcmf_addListener(new Reload_li());
378      
379       this.pem_rootDir =(String JavaDoc)base_environment.pcmf_getParameter(this.pcmf_buildPath("xml_parameter/parfile.xml"), "ServerFileCooser", "rootDir");
380       l_sourceTree.pcmf_setRoot(this.pem_root);
381       this.pcmf_reload();
382       
383       // put out a message
384
base_log.pcmf_log(xPl.pcmf_getAppl().pcmf_getGuiObj().pcmf_getName(), "ServerFileChooser startup complete - rootDir: " + this.pem_rootDir, this, base_log.MESSAGE);
385     }
386     catch (Exception JavaDoc e)
387     {
388       // Something went wrong
389
base_log.pcmf_logException(xPl.pcmf_getAppl().pcmf_getGuiObj().pcmf_getName(), this, e);
390       base_log.pcmf_log(xPl.pcmf_getAppl().pcmf_getGuiObj().pcmf_getName(), "ServerFileChooser startup error", this, base_log.FATAL);
391     }
392   }
393
394   /**
395    * <p>
396    * Reads directory structure recursively
397    * </p><p>
398    *
399    * </p><p>
400    * @param xRoot root-node to insert into tree-view from which the further drill-down is started.
401    * @param xFile corresponding file object from file system.
402    * @param xAppl interface to application instance.
403    * </p>
404    */

405   public void pcmf_buildTree(base_treeNode xRoot, File JavaDoc xFile, base_guiObj xPl)
406   {
407     File JavaDoc l_subs[] = xFile.listFiles();
408     if (l_subs == null)
409       return;
410
411     for (int i = 0; i < l_subs.length; i++)
412     {
413       if (l_subs[i].isDirectory())
414       {
415         base_treeNode l_mod = (base_treeNode)((base_modelValue_if)base_registredObject.pcmf_getObjByName("sfilech_model_folder")).pcmf_cloneModelValue(true, false);
416         l_mod.pcmf_setValue(l_subs[i]);
417         xRoot.pcmf_addNode(l_subs[i].getName(), l_mod);
418         this.pcmf_buildTree(l_mod, l_subs[i], xPl);
419       }
420     }
421   }
422   
423   public void pcmf_delete() throws Exception JavaDoc
424   {
425     this.pemf_deleteTmpNodes();
426     this.pem_root.pcmf_delete();
427     super.pcmf_delete();
428   }
429 }
430
Popular Tags