KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > packager > InitClass


1 /*******************************************************************************
2  * Copyright (c) 2004, Dirk von der Weiden.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution.
6  *
7  * Contributors:
8  * Dirk von der Weiden - initial API and implementation
9  *
10  * Created on 04.04.2004
11  *
12  * date: 04.04.2004
13  * project: WiSer DeployTool
14  *
15  *******************************************************************************/

16
17 package packager;
18
19 import Jmc.baseTools.*;
20 import Jmc.commonGui.*;
21 import Jmc.model.*;
22
23 import packager.model.*;
24
25 import java.io.*;
26
27 /**
28  * @author Dirk
29  *
30  * date: 04.04.2004
31  * project: DeployTool
32  *
33  * <p>
34  * This is the initial class to to do the initialisation of the DeployTool.
35  * </p>
36  */

37 public class InitClass implements base_executableObject_if
38 {
39     /**
40          * <p>
41          * This method is called by the framework as a last step of application startup after all XML
42      * definition has been processed.
43      * </p><p>
44          *
45          * @return null in this case
46          * </p><p>
47          * @param xObj the preinitialised application interface which represents the current
48      * application instance.
49          * </p>
50          */

51     /* Corresponding XML definition code:
52      * ----------------------------------
53      *
54      * The init class is specified within the following line of XML-code:
55      *
56      * <appInit class = "packager.InitClass"/>
57      *
58      * in the file xml_gui/packager.xml.
59      *
60      */

61     public Object JavaDoc pcmf_execObj(Object JavaDoc xObj)
62     {
63     // do cast to interface
64
base_appl_if l_appl = (base_appl_if)xObj;
65
66     try
67     {
68       // get widgets by name
69
base_treeView_if l_sourceTree = (base_treeView_if)base_registredObject.pcmf_getObjByName("sourceTree");
70       base_treeView_if l_targetTree = (base_treeView_if)base_registredObject.pcmf_getObjByName("targetTree");
71       
72       // do all initialising steps
73

74       // read startpoint for displaying the directory structure in the source tree-view
75
File l_root = new File ((String JavaDoc)base_environment.pcmf_getParameter("environment.xml", "packager", "rootSource"));
76       
77       // build up directory structure to display it in the source tree-view
78
this.pcmf_buildTree(l_sourceTree.pcmf_getRoot(), l_root, l_appl);
79
80       // read startpoint for displaying the directory structure in the source tree-view
81
l_root = new File ((String JavaDoc)base_environment.pcmf_getParameter("environment.xml", "packager", "rootTarget"));
82       
83       // build up directory structure to display it in the target tree-view
84
this.pcmf_buildTree(l_targetTree.pcmf_getRoot(), l_root, l_appl);
85       
86       // get model objects from the application and initialise them
87
((MainModel)l_appl.pcmf_getGuiObj().pcmf_getModel()).pcmf_setCopyNodes((base_multipleModelValue_if)l_appl.pcmf_getGuiObj().pcmf_newModelValue("copyNodes", false));
88       ((MainModel)l_appl.pcmf_getGuiObj().pcmf_getModel()).pcmf_setAppl(l_appl);
89       
90       // enable all pages of the application to give a visual feedback to the user to see that startup has been completed
91
// they are disabled in the XML definition
92
l_appl.pcmf_getActive().pcmf_enable();
93       
94       // hide all nodes lower than level 1 which are displayed in both tree-views
95
l_targetTree.pcmf_getRoot().pcmf_hideLevel(1);
96       l_sourceTree.pcmf_getRoot().pcmf_hideLevel(1);
97             
98       // repaint the tree-views
99
l_targetTree.pcmf_repaint();
100       l_sourceTree.pcmf_repaint();
101              
102       // put out a message
103
base_log.pcmf_log(l_appl.pcmf_getGuiObj().pcmf_getName(), "startup complete", this, base_log.MESSAGE);
104     }
105     catch (Exception JavaDoc e)
106     {
107       // Something went wrong
108
base_log.pcmf_logException(l_appl.pcmf_getGuiObj().pcmf_getName(), this, e);
109       base_log.pcmf_log(l_appl.pcmf_getGuiObj().pcmf_getName(), "startup error", this, base_log.FATAL);
110     }
111     
112         return null;
113     }
114
115   /**
116      * <p>
117      * Reads directory structure recursively
118      * </p><p>
119      *
120      * </p><p>
121      * @param xRoot root-node to insert into tree-view from which the further drill-down is started.
122      * @param xFile corresponding file object from file system.
123      * @param xAppl interface to application instance.
124      * </p>
125      */

126   public void pcmf_buildTree(base_treeNode xRoot, File xFile, base_appl_if xAppl)
127   {
128     File l_subs[] = xFile.listFiles();
129     if (l_subs == null)
130       return;
131       
132     for (int i = 0; i < l_subs.length; i++)
133     {
134       if (l_subs[i].isDirectory())
135       {
136         base_treeNode l_mod = (base_treeNode)xAppl.pcmf_getGuiObj().pcmf_newModelValue("folder", true);
137         l_mod.pcmf_setValue(l_subs[i]);
138         xRoot.pcmf_addNode(l_subs[i].getName(), l_mod);
139         this.pcmf_buildTree(l_mod, l_subs[i], xAppl);
140       }
141     }
142   }
143 }
144
Popular Tags