KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > packager > listeners > AddFile_li


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.listeners;
18
19 import Jmc.baseGui.*;
20 import Jmc.baseTools.*;
21 import Jmc.commonGui.*;
22 import Jmc.model.*;
23
24 import java.util.*;
25
26 import packager.model.*;
27
28 /**
29  * @author Dirk
30  *
31  * date: 13.04.2004
32  * project: DeployTool
33  *
34  * <p>
35  * This listener's execution method is called when the button "add item" is pressed.
36  * </p>
37  */

38 /* Corresponding XML definition code:
39  * ----------------------------------
40  *
41  * The following lines from the xml_gui/packager.xml file show the corresponding configuration:
42  *
43  * <button name="add item" orphan="false" register="" submit="true" disable="false">
44  * ...
45  * <srvListener object = "AddFile_listener"/>
46  * </button>
47  *
48  * The tag <srvListener> connects the listener object to widget. In this case the attribute "object" is used
49  * which means that initialised instance of a listener object has to be available. This instance is created
50  * by the following xScript call in the file xml_script/packager_init.xml:
51  *
52  * <Declare objname = "AddFile_listener" objtype = "packager.listeners.AddFile_li" objctx = "forever"/>
53  *
54  * It is also possible to use the attribute "class" whithin the <srvListener> tag to add a new instance
55  * (presumed the availability of a parameterless cunstructor - you find an example with a paramtrized
56  * constructor in "GetInput_li.java") of a listener. In this case you don't
57  * have to use any xScripts. It would look like this:
58  *
59  * <srvListener class = "packager.listeners.AddFile_li"/>
60  *
61  */

62 public class AddFile_li implements base_guiListener
63 {
64     /**
65          * <p>
66          * Execution method of the listener
67          * </p><p>
68          *
69          * </p><p>
70          * @param xParam widget which provided the event
71          * </p>
72          */

73     public void pcmf_execListener(base_guiObj xParam) throws Exception JavaDoc
74     {
75     // get widget by name
76
base_table_if l_stable = (base_table_if)base_registredObject.pcmf_getObjByName("sourceTable");
77     
78     // get model form application
79
MainModel l_model = (MainModel)xParam.pcmf_getAppl().pcmf_getGuiObj().pcmf_getModel();
80     
81     // get application instance
82
base_appl_if l_appl = xParam.pcmf_getAppl();
83     
84     // there is no target selected
85
if (l_model.pcmf_getTarget() == null || l_model.pcmf_getTarget().pcmf_getValue().toString().trim().equals(""))
86     {
87       // show an error message
88
// get a new error message model object.
89

90       /* Corresponding XML definition code:
91        * ----------------------------------
92        * It's declaration is made in xml_parameter/xml_gui within the following lines:
93        *
94        * <multipleValue name="errorMsg" class="Jmc.model.base_splitTreeMultiValue">
95        * <view stdImgObject = "error_icon" font="nFont" template="Error: {$NAME}, [{$VALUE}]"/>
96        * </multipleValue>
97        *
98        * The <view> tags expresses that if the model value is displayed within a widget (e.g. in a table-cell)
99        * it is represented by the named icon, and a text in a special font. The "template" attribute defines
100        * the text displayed $NAME is substituted by the model instance name while $VALUE stands for the string
101        * represantaion of the value
102        *
103        */

104       base_treeNode l_message = (base_treeNode)l_appl.pcmf_getGuiObj().pcmf_newModelValue("errorMsg", false);
105       l_message.pcmf_setName("selection");
106       l_message.pcmf_setValue("no copy target selected");
107
108       // set the message
109
l_model.pcmf_addMessage(l_message);
110       return;
111     }
112     
113     // prepare new copy-node
114
base_multipleModelValue_if l_node = null;
115     base_singleModelValue_if l_target = null;
116     base_singleModelValue_if l_source = null;
117     base_singleModelValue_if l_type = null;
118     
119     // get selected row(s) of the source table which displays the files and folders
120
ArrayList l_select = l_stable.pcmf_getSelectedTableRows();
121     Iterator l_it = l_select.iterator();
122     ArrayList l_row = null;
123     
124     // no selection
125
if (l_it.hasNext() == false)
126     {
127       // show an error message in the same way described above
128
base_treeNode l_message = (base_treeNode)l_appl.pcmf_getGuiObj().pcmf_newModelValue("errorMsg", false);
129       l_message.pcmf_setName("selection");
130       l_message.pcmf_setValue("no copy source selected");
131
132       l_model.pcmf_addMessage(l_message);
133       return;
134     }
135     do
136     {
137       // create and add new copy-nodes
138
l_row = (ArrayList)l_it.next();
139       l_node = (base_multipleModelValue_if)l_appl.pcmf_getGuiObj().pcmf_newModelValue("copyNode", true);
140       l_target = (base_singleModelValue_if)l_node.pcmf_getModelValue("target");
141       l_source = (base_singleModelValue_if)l_node.pcmf_getModelValue("source");
142       l_type = (base_singleModelValue_if)l_node.pcmf_getModelValue("type");
143     
144       l_target.pcmf_setValueValidate(l_model.pcmf_getTarget());
145       l_source.pcmf_setValueValidate(l_row.get(0));
146       
147       l_type.pcmf_setValueValidate(((base_modelValue_if)l_model.pcmf_getTarget()).pcmf_getMyTemplate());
148     
149       l_model.pcmf_addCopyNode(l_node);
150     }
151     while (l_it.hasNext());
152     
153     // update the view of the copy-targets
154
l_model.pcmf_updateTargetView();
155     }
156 }
157
Popular Tags