KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
17 import java.sql.*;
18 import java.util.*;
19 import javax.swing.*;
20
21 import org.compiere.util.*;
22
23 /**
24  * Workbench Model
25  *
26  * @author Jorg Janke
27  * @version $Id: MWorkbench.java,v 1.5 2002/08/23 04:02:30 jjanke Exp $
28  */

29 public class MWorkbench implements Serializable
30 {
31     /**
32      * Workbench Model Constructor
33      */

34     public MWorkbench (Properties ctx)
35     {
36         m_ctx = ctx;
37     } // MWorkbench
38

39     /**
40      * No Workbench - Just Frame for Window
41      */

42     public MWorkbench (Properties ctx, int AD_Window_ID)
43     {
44         m_ctx = ctx;
45         m_windows.add (new WBWindow(TYPE_WINDOW, AD_Window_ID));
46     } // MWorkbench
47

48     /** Properties */
49     private Properties m_ctx;
50
51     /** List of windows */
52     private ArrayList m_windows = new ArrayList();
53
54     private int AD_Workbench_ID = 0;
55     private String JavaDoc Name = "";
56     private String JavaDoc Description = "";
57     private String JavaDoc Help = "";
58     private int AD_Column_ID = 0;
59     private int AD_Image_ID = 0;
60     private int AD_Color_ID = 0;
61     private int PA_Goal_ID = 0;
62     private String JavaDoc ColumnName = "";
63
64     /**
65      * Init Workbench
66      */

67     public boolean initWorkbench (int ad_Workbench_ID)
68     {
69         AD_Workbench_ID = ad_Workbench_ID;
70         // Get WB info
71
String JavaDoc sql = null;
72         if (Env.isBaseLanguage(m_ctx, "AD_Workbench"))
73             sql = "SELECT w.Name,w.Description,w.Help," // 1..3
74
+ " w.AD_Column_ID,w.AD_Image_ID,w.AD_Color_ID,w.PA_Goal_ID," // 4..7
75
+ " c.ColumnName " // 8
76
+ "FROM AD_Workbench w, AD_Column c "
77                 + "WHERE w.AD_Workbench_ID=?" // #1
78
+ " AND w.IsActive='Y'"
79                 + " AND w.AD_Column_ID=c.AD_Column_ID";
80         else
81             sql = "SELECT t.Name,t.Description,t.Help,"
82                 + " w.AD_Column_ID,w.AD_Image_ID,w.AD_Color_ID,w.PA_Goal_ID,"
83                 + " c.ColumnName "
84                 + "FROM AD_Workbench w, AD_Workbench_Trl t, AD_Column c "
85                 + "WHERE w.AD_Workbench_ID=?" // #1
86
+ " AND w.IsActive='Y'"
87                 + " AND w.AD_Workbench_ID=t.AD_Workbench_ID"
88                 + " AND t.AD_Language='" + Env.getAD_Language(m_ctx) + "'"
89                 + " AND w.AD_Column_ID=c.AD_Column_ID";
90         try
91         {
92             PreparedStatement pstmt = DB.prepareStatement(sql);
93             pstmt.setInt(1, AD_Workbench_ID);
94             ResultSet rs = pstmt.executeQuery();
95             if (rs.next())
96             {
97                 Name = rs.getString(1);
98                 Description = rs.getString(2);
99                 if (Description == null)
100                     Description = "";
101                 Help = rs.getString(3);
102                 if (Help == null)
103                     Help = "";
104                 //
105
AD_Column_ID = rs.getInt(4);
106                 AD_Image_ID = rs.getInt(5);
107                 AD_Color_ID = rs.getInt(6);
108                 PA_Goal_ID = rs.getInt(7);
109                 ColumnName = rs.getString(8);
110             }
111             else
112                 AD_Workbench_ID = 0;
113             rs.close();
114             pstmt.close();
115         }
116         catch (SQLException e)
117         {
118             Log.error("MWorkbench.initWorkbench", e);
119         }
120
121         if (AD_Workbench_ID == 0)
122             return false;
123         return initWorkbenchWindows();
124     } // initWorkbench
125

126     /**
127      * String Representation
128      */

129     public String JavaDoc toString()
130     {
131         return "MWorkbench ID=" + AD_Workbench_ID + " " + Name
132             + ", windows=" + m_windows.size() + ", LinkColumn=" + ColumnName;
133     } // toString
134

135     /**
136      * Dispose
137      */

138     public void dispose()
139     {
140         for (int i = 0; i < m_windows.size(); i++)
141         {
142             dispose(i);
143         }
144         m_windows.clear();
145         m_windows = null;
146     } // dispose
147

148     /**
149      * Get Workbench Query
150      * ColumnName=@#ColumnName@
151      */

152     public MQuery getQuery()
153     {
154         return MQuery.getEqualQuery(ColumnName, "@#" + ColumnName + "@");
155     } // getQuery
156

157     /*************************************************************************/
158
159     public int getAD_Workbench_ID()
160     {
161         return AD_Workbench_ID;
162     }
163     public String JavaDoc getName()
164     {
165         return Name;
166     }
167     public String JavaDoc getDescription()
168     {
169         return Description;
170     }
171     public String JavaDoc getHelp()
172     {
173         return Help;
174     }
175     public int getAD_Column_ID()
176     {
177         return AD_Column_ID;
178     }
179     public int getAD_Image_ID()
180     {
181         return AD_Image_ID;
182     }
183     public int getAD_Color_ID()
184     {
185         return AD_Color_ID;
186     }
187     public int getPA_Goal_ID()
188     {
189         return PA_Goal_ID;
190     }
191
192     /*************************************************************************/
193
194     /** Window */
195     public static final int TYPE_WINDOW = 1;
196     /** Form */
197     public static final int TYPE_FORM = 2;
198     /** Process */
199     public static final int TYPE_PROCESS = 3;
200     /** Task */
201     public static final int TYPE_TASK = 4;
202
203     /**
204      * Init Workbench Windows
205      */

206     private boolean initWorkbenchWindows()
207     {
208         String JavaDoc sql = "SELECT AD_Window_ID, AD_Form_ID, AD_Process_ID, AD_Task_ID "
209             + "FROM AD_WorkbenchWindow "
210             + "WHERE AD_Workbench_ID=? AND IsActive='Y'"
211             + "ORDER BY SeqNo";
212         try
213         {
214             PreparedStatement pstmt = DB.prepareStatement(sql);
215             pstmt.setInt(1, AD_Workbench_ID);
216             ResultSet rs = pstmt.executeQuery();
217             while (rs.next())
218             {
219                 int AD_Window_ID = rs.getInt(1);
220                 int AD_Form_ID = rs.getInt(2);
221                 int AD_Process_ID = rs.getInt(3);
222                 int AD_Task_ID = rs.getInt(4);
223                 //
224
if (AD_Window_ID > 0)
225                     m_windows.add (new WBWindow(TYPE_WINDOW, AD_Window_ID));
226                 else if (AD_Form_ID > 0)
227                     m_windows.add (new WBWindow(TYPE_FORM, AD_Form_ID));
228                 else if (AD_Process_ID > 0)
229                     m_windows.add (new WBWindow(TYPE_PROCESS, AD_Process_ID));
230                 else if (AD_Task_ID > 0)
231                     m_windows.add (new WBWindow(TYPE_TASK, AD_Task_ID));
232             }
233             rs.close();
234             pstmt.close();
235         }
236         catch (SQLException e)
237         {
238             Log.error("MWorkbench.initWorkbenchWindows", e);
239             return false;
240         }
241         return true;
242     } // initWorkbenchWindows
243

244     /**
245      * Get Window Count
246      */

247     public int getWindowCount()
248     {
249         return m_windows.size();
250     } // getWindowCount
251

252     /**
253      * Get Window Type of Window
254      * @return -1 if not valid
255      */

256     public int getWindowType (int index)
257     {
258         if (index < 0 || index > m_windows.size())
259             return -1;
260         WBWindow win = (WBWindow)m_windows.get(index);
261         return win.Type;
262     } // getWindowType
263

264     /**
265      * Get ID for Window
266      * @return -1 if not valid
267      */

268     public int getWindowID (int index)
269     {
270         if (index < 0 || index > m_windows.size())
271             return -1;
272         WBWindow win = (WBWindow)m_windows.get(index);
273         return win.ID;
274     } // getWindowID
275

276     /*************************************************************************/
277
278     /**
279      * Set Window Model of Window
280      */

281     public void setMWindow (int index, MWindow mw)
282     {
283         if (index < 0 || index > m_windows.size())
284             throw new IllegalArgumentException JavaDoc ("MWorkbench.setMWindow - Index invalid: " + index);
285         WBWindow win = (WBWindow)m_windows.get(index);
286         if (win.Type != TYPE_WINDOW)
287             throw new IllegalArgumentException JavaDoc ("MWorkbench.setMWindow - Not a MWindow: " + index);
288         win.mWindow = mw;
289     } // setMWindow
290

291     /**
292      * Get Window Model of Window
293      */

294     public MWindow getMWindow (int index)
295     {
296         if (index < 0 || index > m_windows.size())
297             throw new IllegalArgumentException JavaDoc ("MWorkbench.getMWindow - Index invalid: " + index);
298         WBWindow win = (WBWindow)m_windows.get(index);
299         if (win.Type != TYPE_WINDOW)
300             throw new IllegalArgumentException JavaDoc ("MWorkbench.getMWindow - Not a MWindow: " + index);
301         return win.mWindow;
302     } // getMWindow
303

304     /**
305      * Get Name of Window
306      * @return Window Name or null if not set
307      */

308     public String JavaDoc getName (int index)
309     {
310         if (index < 0 || index > m_windows.size())
311             throw new IllegalArgumentException JavaDoc ("MWorkbench.getName - Index invalid: " + index);
312         WBWindow win = (WBWindow)m_windows.get(index);
313         if (win.mWindow != null && win.Type == TYPE_WINDOW)
314             return win.mWindow.getName();
315         return null;
316     } // getName
317

318     /**
319      * Get Description of Window
320      * @return Window Description or null if not set
321      */

322     public String JavaDoc getDescription (int index)
323     {
324         if (index < 0 || index > m_windows.size())
325             throw new IllegalArgumentException JavaDoc ("MWorkbench.getDescription - Index invalid: " + index);
326         WBWindow win = (WBWindow)m_windows.get(index);
327         if (win.mWindow != null && win.Type == TYPE_WINDOW)
328             return win.mWindow.getDescription();
329         return null;
330     } // getDescription
331

332     /**
333      * Get Help of Window
334      * @return Window Help or null if not set
335      */

336     public String JavaDoc getHelp (int index)
337     {
338         if (index < 0 || index > m_windows.size())
339             throw new IllegalArgumentException JavaDoc ("MWorkbench.getHelp - Index invalid: " + index);
340         WBWindow win = (WBWindow)m_windows.get(index);
341         if (win.mWindow != null && win.Type == TYPE_WINDOW)
342             return win.mWindow.getHelp();
343         return null;
344     } // getHelp
345

346     /**
347      * Get Icon of Window
348      * @return Window Icon or null if not set
349      */

350     public Icon getIcon (int index)
351     {
352         if (index < 0 || index > m_windows.size())
353             throw new IllegalArgumentException JavaDoc ("MWorkbench.getIcon - Index invalid: " + index);
354         WBWindow win = (WBWindow)m_windows.get(index);
355         if (win.mWindow != null && win.Type == TYPE_WINDOW)
356             return win.mWindow.getIcon();
357         return null;
358     } // getIcon
359

360     /**
361      * Get AD_Color_ID of Window
362      * @return Window Color or Workbench color if not set
363      */

364     public int getAD_Color_ID (int index)
365     {
366         if (index < 0 || index > m_windows.size())
367             throw new IllegalArgumentException JavaDoc ("MWorkbench.getAD_Color_ID - Index invalid: " + index);
368         WBWindow win = (WBWindow)m_windows.get(index);
369         int retValue = -1;
370     // if (win.mWindow != null && win.Type == TYPE_WINDOW)
371
// return win.mWindow.getAD_Color_ID();
372
if (retValue == -1)
373             return getAD_Color_ID();
374         return retValue;
375     } // getAD_Color_ID
376

377     /**
378      * Set WindowNo of Window
379      */

380     public void setWindowNo (int index, int windowNo)
381     {
382         if (index < 0 || index > m_windows.size())
383             throw new IllegalArgumentException JavaDoc ("MWorkbench.setWindowNo - Index invalid: " + index);
384         WBWindow win = (WBWindow)m_windows.get(index);
385         win.WindowNo = windowNo;
386     } // getWindowNo
387

388     /**
389      * Get WindowNo of Window
390      * @return WindowNo of Window if previously set, otherwise -1;
391      */

392     public int getWindowNo (int index)
393     {
394         if (index < 0 || index > m_windows.size())
395             throw new IllegalArgumentException JavaDoc ("MWorkbench.getWindowNo - Index invalid: " + index);
396         WBWindow win = (WBWindow)m_windows.get(index);
397         return win.WindowNo;
398     } // getWindowNo
399

400     /**
401      * Dispose of Window
402      */

403     public void dispose (int index)
404     {
405         if (index < 0 || index > m_windows.size())
406             throw new IllegalArgumentException JavaDoc ("MWorkbench.getWindowNo - Index invalid: " + index);
407         WBWindow win = (WBWindow)m_windows.get(index);
408         if (win.mWindow != null)
409             win.mWindow.dispose();
410         win.mWindow = null;
411     } // dispose
412

413     /*************************************************************************/
414
415     /**
416      * Window Type
417      */

418     class WBWindow
419     {
420         public WBWindow (int type, int id)
421         {
422             Type = type;
423             ID = id;
424         }
425         public int Type = 0;
426         public int ID = 0;
427         public int WindowNo = -1;
428         //
429
public MWindow mWindow = null;
430     // public MFrame mFrame = null;
431
// public MProcess mProcess = null;
432
} // WBWindow
433
} // Workbench
434
Popular Tags