KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MWindow


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.ArrayList JavaDoc;
18
19 import org.compiere.plaf.CompiereColor;
20 import org.compiere.util.Log;
21
22 /**
23  * Window Model
24  *
25  * @author Jorg Janke
26  * @version $Id: MWindow.java,v 1.18 2003/09/29 01:01:10 jjanke Exp $
27  */

28 public final class MWindow implements Serializable JavaDoc
29 {
30     /**
31      * Constructor
32      * @param vo value object
33      */

34     public MWindow (MWindowVO vo)
35     {
36         m_vo = vo;
37         if (loadTabData())
38             enableEvents();
39     } // MWindow
40

41     /** Value Object */
42     private MWindowVO m_vo;
43     //
44
private ArrayList JavaDoc m_tabs = new ArrayList JavaDoc();
45
46     /*************************************************************************/
47
48     /**
49      * Dispose
50      */

51     public void dispose()
52     {
53         Log.trace(Log.l2_Sub, "MWindow.dispose - " + m_vo.AD_Window_ID);
54         for (int i = 0; i < getTabCount(); i++)
55             getTab(i).dispose();
56         m_tabs.clear();
57         m_tabs = null;
58     } // dispose
59

60     /**
61      * Load is complete.
62      * Return when async load is complete
63      * Used for performance tests (Base.test())
64      */

65     public void loadCompete ()
66     {
67         // for all tabs
68
for (int i = 0; i < getTabCount(); i++)
69             getTab(i).getMTable().loadComplete();
70     } // loadComplete
71

72     /**
73      * Get Tab data and create MTab(s)
74      * @return true if tab loaded
75      */

76     private boolean loadTabData()
77     {
78         Log.trace(Log.l3_Util, "MWindow.loadTabData");
79
80         if (m_vo.Tabs == null)
81             return false;
82
83         for (int t = 0; t < m_vo.Tabs.size(); t++)
84         {
85             MTabVO mTabVO = (MTabVO)m_vo.Tabs.get(t);
86             if (mTabVO != null)
87             {
88                 MTab mTab = new MTab(mTabVO);
89                 // Set Link Column
90
if (mTab.getLinkColumnName().length() == 0)
91                 {
92                     ArrayList JavaDoc parents = mTab.getParentColumnNames();
93                     // No Parent - no link
94
if (parents.size() == 0)
95                         ;
96                     // Standard case
97
else if (parents.size() == 1)
98                         mTab.setLinkColumnName((String JavaDoc)parents.get(0));
99                     else
100                     {
101                         // More than one parent.
102
// Search prior tabs for the "right parent"
103
// for all previous tabs
104
for (int i = 0; i < m_tabs.size(); i++)
105                         {
106                             // we have a tab
107
MTab tab = (MTab)m_tabs.get(i);
108                             String JavaDoc tabKey = tab.getKeyColumnName(); // may be ""
109
// look, if one of our parents is the key of that tab
110
for (int j = 0; j < parents.size(); j++)
111                             {
112                                 String JavaDoc parent = (String JavaDoc)parents.get(j);
113                                 if (parent.equals(tabKey))
114                                 {
115                                     mTab.setLinkColumnName(parent);
116                                     break;
117                                 }
118                                 // The tab could have more than one key, look into their parents
119
if (tabKey.equals(""))
120                                     for (int k = 0; k < tab.getParentColumnNames().size(); k++)
121                                         if (parent.equals(tab.getParentColumnNames().get(k)))
122                                         {
123                                             mTab.setLinkColumnName(parent);
124                                             break;
125                                         }
126                             } // for all parents
127
} // for all previous tabs
128
} // parents.size > 1
129
} // set Link column
130
mTab.setLinkColumnName(null); // overwrites, if AD_Column_ID exists
131
//
132
m_tabs.add(mTab);
133             }
134         } // for all tabs
135
return true;
136     } // loadTabData
137

138     /**
139      * Get Window Icon
140      * @return Icon for Window
141      */

142     public javax.swing.Icon JavaDoc getIcon()
143     {
144         if (m_vo.AD_Image_ID == 0)
145             return null;
146         //
147
/** @todo Load Image */
148         return null;
149     } // getIcon
150

151     /**
152      * Get Color
153      * @return CompiereColor or null
154      */

155     public CompiereColor getColor()
156     {
157         if (m_vo.AD_Color_ID == 0)
158             return null;
159         MColor mc = new MColor(m_vo.ctx, m_vo.AD_Color_ID);
160         return mc.getCompiereColor();
161     } // getColor
162

163     /**
164      * Open and query first Tab (events should be enabled) and get first row.
165      */

166     public void query()
167     {
168         Log.trace(Log.l2_Sub, "MWindow.open");
169         MTab tab = getTab(0);
170         tab.query(false, 1);
171         if (tab.getRowCount() > 0)
172             tab.navigate(0);
173     } // open
174

175     /**
176      * Enable Events - enable data events of tabs (add listeners)
177      */

178     private void enableEvents()
179     {
180         for (int i = 0; i < getTabCount(); i++)
181             getTab(i).enableEvents();
182     } // enableEvents
183

184     /**
185      * Get number of Tabs
186      * @return number of tabs
187      */

188     public int getTabCount()
189     {
190         return m_tabs.size();
191     } // getTabCount
192

193     /**
194      * Get i-th MTab - null if not valid
195      * @param i index
196      * @return MTab
197      */

198     public MTab getTab (int i)
199     {
200         if (i < 0 || i+1 > m_tabs.size())
201             return null;
202         return (MTab)m_tabs.get(i);
203     } // getTab
204

205     /**
206      * Get Window_ID
207      * @return AD_Window_ID
208      */

209     public int getAD_Window_ID()
210     {
211         return m_vo.AD_Window_ID;
212     } // getAD_Window_ID
213

214     /**
215      * Get WindowNo
216      * @return WindowNo
217      */

218     public int getWindowNo()
219     {
220         return m_vo.WindowNo;
221     } // getWindowNo
222

223     /**
224      * Get Name
225      * @return name
226      */

227     public String JavaDoc getName()
228     {
229         return m_vo.Name;
230     } // getName
231

232     /**
233      * Get Description
234      * @return Description
235      */

236     public String JavaDoc getDescription()
237     {
238         return m_vo.Description;
239     } // getDescription
240

241     /**
242      * Get Help
243      * @return Help
244      */

245     public String JavaDoc getHelp()
246     {
247         return m_vo.Help;
248     } // getHelp
249

250     /**
251      * Get Window Type
252      * @return Window Type see WindowType_*
253      */

254     public String JavaDoc getWindowType()
255     {
256         return m_vo.WindowType;
257     } // getWindowType
258

259     /**
260      * Is Transaction Window
261      * @return true if transaction
262      */

263     public boolean isTransaction()
264     {
265         return m_vo.WindowType.equals(MWindowVO.WINDOWTYPE_TRX);
266     } // isTransaction
267

268     /**
269      * To String
270      * @return String representation
271      */

272     public String JavaDoc toString()
273     {
274         return "MWindow[" + m_vo.WindowNo + "," + m_vo.Name + " (" + m_vo.AD_Window_ID + ")]";
275     } // toString
276

277 } // MWindow
278
Popular Tags