KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > search > Info


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.apps.search;
15
16 import java.awt.BorderLayout JavaDoc;
17 import java.awt.Cursor JavaDoc;
18 import java.awt.Dimension JavaDoc;
19 import java.awt.Frame JavaDoc;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22 import java.awt.event.MouseEvent JavaDoc;
23 import java.awt.event.MouseListener JavaDoc;
24 import java.math.BigDecimal JavaDoc;
25 import java.sql.PreparedStatement JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.sql.Timestamp JavaDoc;
29 import java.util.ArrayList JavaDoc;
30
31 import javax.swing.ImageIcon JavaDoc;
32 import javax.swing.JDialog JavaDoc;
33 import javax.swing.JFrame JavaDoc;
34 import javax.swing.JMenuItem JavaDoc;
35 import javax.swing.JPopupMenu JavaDoc;
36 import javax.swing.JScrollPane JavaDoc;
37 import javax.swing.SwingUtilities JavaDoc;
38 import javax.swing.event.ListSelectionEvent JavaDoc;
39 import javax.swing.event.ListSelectionListener JavaDoc;
40
41 import org.compiere.apps.AEnv;
42 import org.compiere.apps.AWindow;
43 import org.compiere.apps.ConfirmPanel;
44 import org.compiere.apps.StatusBar;
45 import org.compiere.grid.ed.Calculator;
46 import org.compiere.minigrid.IDColumn;
47 import org.compiere.minigrid.MiniTable;
48 import org.compiere.model.MQuery;
49 import org.compiere.model.MRole;
50 import org.compiere.plaf.CompiereColor;
51 import org.compiere.swing.*;
52 import org.compiere.util.*;
53
54 /**
55  * Search Information and return selection - Base Class.
56  * <pre>
57  * Structure:
58  * parameterPanel (JPanel) - for subclasses to add parameter fields
59  * scrollPame (JScrollPane)
60  * m_table (MiniTable)
61  * southPanel (JPanel)
62  * confirmPanel
63  * statusPanel
64  * </pre>
65  *
66  * @author Jorg Janke
67  * @version $Id: Info.java,v 1.27 2003/11/06 07:08:28 jjanke Exp $
68  */

69 public abstract class Info extends CDialog
70     implements ListSelectionListener JavaDoc
71 {
72     /**
73      * Factory Constructor
74      * @param frame parent frame
75      * @param modal new window is modal
76      * @param WindowNo window no
77      * @param tableName table name of the search
78      * @param keyColumn key column of the search
79      * @param value query value
80      * @param multiSelection allow to select more than one row
81      * @param whereClause fully qualified where clause for the search
82      * @return special or general Info Window
83      */

84     public static Info create (Frame JavaDoc frame, boolean modal, int WindowNo,
85         String JavaDoc tableName, String JavaDoc keyColumn, String JavaDoc value,
86         boolean multiSelection, String JavaDoc whereClause)
87     {
88         Info info = null;
89
90         if (tableName.equals("C_BPartner"))
91             info = new InfoBPartner (frame, modal, WindowNo, value, !Env.getContext(Env.getCtx(),"IsSOTrx").equals("N"),
92                     multiSelection, whereClause);
93         else if (tableName.equals("M_Product"))
94             info = new InfoProduct (frame, modal, WindowNo, 0,0, value,
95                     multiSelection, whereClause);
96         else if (tableName.equals("C_Invoice"))
97             info = new InfoInvoice (frame, modal, WindowNo, value,
98                     multiSelection, whereClause);
99         else if (tableName.equals("A_Asset"))
100             info = new InfoAsset (frame, modal, WindowNo, 0, value,
101                     multiSelection, whereClause);
102         else if (tableName.equals("C_Order"))
103             info = new InfoOrder (frame, modal, WindowNo, value,
104                     multiSelection, whereClause);
105         else if (tableName.equals("M_InOut"))
106             info = new InfoInOut (frame, modal, WindowNo, value,
107                     multiSelection, whereClause);
108         else if (tableName.equals("C_Payment"))
109             info = new InfoPayment (frame, modal, WindowNo, value,
110                     multiSelection, whereClause);
111         else if (tableName.equals("C_CashLine"))
112             info = new InfoCashLine (frame, modal, WindowNo, value,
113                     multiSelection, whereClause);
114         else if (tableName.equals("S_ResourceAssigment"))
115             info = new InfoAssignment (frame, modal, WindowNo, value,
116                     multiSelection, whereClause);
117         else
118             info = new InfoGeneral (frame, modal, WindowNo, value,
119                 tableName, keyColumn,
120                 multiSelection, whereClause);
121         //
122
AEnv.positionCenterWindow(frame, info);
123         return info;
124     } // create
125

126     /**
127      * Show BPartner Info (non modal)
128      * @param frame Parent Frame
129      * @param WindowNo window no
130      */

131     public static void showBPartner (Frame JavaDoc frame, int WindowNo)
132     {
133         Info info = new InfoBPartner (frame, false, WindowNo, "",
134             !Env.getContext(Env.getCtx(),"IsSOTrx").equals("N"), false, "");
135         AEnv.showCenterWindow(frame, info);
136     } // showBPartner
137

138     /**
139      * Show Asset Info (non modal)
140      * @param frame Parent Frame
141      * @param WindowNo window no
142      */

143     public static void showAsset (Frame JavaDoc frame, int WindowNo)
144     {
145         Info info = new InfoAsset (frame, false, WindowNo,
146             0, "", false, "");
147         AEnv.showCenterWindow(frame, info);
148     } // showBPartner
149

150     /**
151      * Show Product Info (non modal)
152      * @param frame Parent Frame
153      * @param WindowNo window no
154      */

155     public static void showProduct (Frame JavaDoc frame, int WindowNo)
156     {
157         Info info = new InfoProduct (frame, false, WindowNo,
158             Env.getContextAsInt(Env.getCtx(), WindowNo, "M_Warehouse_ID"),
159             Env.getContextAsInt(Env.getCtx(), WindowNo, "M_PriceList_ID"),
160             "", // value
161
false, "");
162         AEnv.showCenterWindow(frame, info);
163     } // showProduct
164

165     /**
166      * Show Order Info (non modal)
167      * @param frame Parent Frame
168      * @param WindowNo window no
169      * @param value query value
170      */

171     public static void showOrder (Frame JavaDoc frame, int WindowNo, String JavaDoc value)
172     {
173         Info info = new InfoOrder (frame, false, WindowNo, value,
174             false, "");
175         AEnv.showCenterWindow(frame, info);
176     } // showOrder
177

178     /**
179      * Show Invoice Info (non modal)
180      * @param frame Parent Frame
181      * @param WindowNo window no
182      * @param value query value
183      */

184     public static void showInvoice (Frame JavaDoc frame, int WindowNo, String JavaDoc value)
185     {
186         Info info = new InfoInvoice (frame, false, WindowNo, value,
187             false, "");
188         AEnv.showCenterWindow(frame, info);
189     } // showInvoice
190

191     /**
192      * Show Shipment Info (non modal)
193      * @param frame Parent Frame
194      * @param WindowNo window no
195      * @param value query value
196      */

197     public static void showInOut (Frame JavaDoc frame, int WindowNo, String JavaDoc value)
198     {
199         Info info = new InfoInOut (frame, false, WindowNo, value,
200             false, "");
201         AEnv.showCenterWindow(frame, info);
202     } // showInOut
203

204     /**
205      * Show Payment Info (non modal)
206      * @param frame Parent Frame
207      * @param WindowNo window no
208      * @param value query value
209      */

210     public static void showPayment (Frame JavaDoc frame, int WindowNo, String JavaDoc value)
211     {
212         Info info = new InfoPayment (frame, false, WindowNo, value,
213             false, "");
214         AEnv.showCenterWindow(frame, info);
215     } // showPayment
216

217     /**
218      * Show Cash Line Info (non modal)
219      * @param frame Parent Frame
220      * @param WindowNo window no
221      * @param value query value
222      */

223     public static void showCashLine (Frame JavaDoc frame, int WindowNo, String JavaDoc value)
224     {
225         Info info = new InfoCashLine (frame, false, WindowNo, value,
226             false, "");
227         AEnv.showCenterWindow(frame, info);
228     } // showCashLine
229

230     /**
231      * Show Assignment Info (non modal)
232      * @param frame Parent Frame
233      * @param WindowNo window no
234      * @param value query value
235      */

236     public static void showAssignment (Frame JavaDoc frame, int WindowNo, String JavaDoc value)
237     {
238         Info info = new InfoAssignment (frame, false, WindowNo, value,
239             false, "");
240         AEnv.showCenterWindow(frame, info);
241     } // showAssignment
242

243     /** Window Width */
244     static final int INFO_WIDTH = 800;
245
246     /*************************************************************************/
247
248     /**
249      * Detail Constructor
250      * @param frame parent frame
251      * @param modal modal
252      * @param WindowNo window no
253      * @param tableName table name
254      * @param keyColumn key column name
255      * @param multiSelection muiliple selection
256      * @param whereClause where clause
257      */

258     protected Info (Frame JavaDoc frame, boolean modal, int WindowNo,
259         String JavaDoc tableName, String JavaDoc keyColumn,
260         boolean multiSelection, String JavaDoc whereClause)
261     {
262         super (frame, modal);
263         Log.trace(Log.l1_User, "Info for WinNo=" + p_WindowNo + " " + whereClause);
264         p_WindowNo = WindowNo;
265         p_tableName = tableName;
266         p_keyColumn = keyColumn;
267         p_multiSelection = multiSelection;
268         p_whereClause = whereClause;
269
270         try
271         {
272             jbInit();
273         }
274         catch(Exception JavaDoc ex)
275         {
276             Log.error("Info", ex);
277         }
278     } // Info
279

280
281     /** Master (owning) Window */
282     protected int p_WindowNo;
283     /** Table Name */
284     protected String JavaDoc p_tableName;
285     /** Key Column Name */
286     protected String JavaDoc p_keyColumn;
287     /** Enable more than one selection */
288     protected boolean p_multiSelection;
289     /** Initial WHERE Clause */
290     protected String JavaDoc p_whereClause = "";
291
292     /** Table */
293     protected MiniTable p_table = new MiniTable();
294     /** Model Index of Key Column */
295     private int m_keyColumnIndex = -1;
296     /** OK pressed */
297     private boolean m_ok = false;
298     /** Cancel pressed - need to differentiate between OK - Cancel - Exit */
299     private boolean m_cancel = false;
300     /** Result IDs */
301     private ArrayList JavaDoc m_results = new ArrayList JavaDoc(3);
302
303     /** Layout of Grid */
304     protected Info_Column[] p_layout;
305     /** Main SQL Statement */
306     private String JavaDoc m_sqlMain;
307     /** Order By Clause */
308     private String JavaDoc m_sqlAdd;
309
310     /** Loading success indicator */
311     protected boolean p_loadedOK = false;
312
313     /** Worker */
314     private Worker m_worker = null;
315
316     /** Static Layout */
317     private CPanel southPanel = new CPanel();
318     private BorderLayout JavaDoc southLayout = new BorderLayout JavaDoc();
319     ConfirmPanel confirmPanel = new ConfirmPanel(true, true, true, true, true, true, true);
320     protected StatusBar statusBar = new StatusBar();
321     protected CPanel parameterPanel = new CPanel();
322     private JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc();
323     //
324
private JPopupMenu JavaDoc popup = new JPopupMenu JavaDoc();
325     private JMenuItem JavaDoc calcMenu = new JMenuItem JavaDoc();
326
327     /**
328      * Static Init
329      * @throws Exception
330      */

331     protected void jbInit() throws Exception JavaDoc
332     {
333         this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
334         southPanel.setLayout(southLayout);
335         southPanel.add(confirmPanel, BorderLayout.CENTER);
336         southPanel.add(statusBar, BorderLayout.SOUTH);
337         getContentPane().add(southPanel, BorderLayout.SOUTH);
338         this.getContentPane().add(parameterPanel, BorderLayout.NORTH);
339         this.getContentPane().add(scrollPane, BorderLayout.CENTER);
340         scrollPane.getViewport().add(p_table, null);
341         //
342
confirmPanel.addActionListener(this);
343         confirmPanel.getResetButton().setVisible(hasReset());
344         confirmPanel.getCustomizeButton().setVisible(hasCustomize());
345         confirmPanel.getHistoryButton().setVisible(hasHistory());
346         confirmPanel.getZoomButton().setVisible(hasZoom());
347         //
348
popup.add(calcMenu);
349         calcMenu.setText(Msg.getMsg(Env.getCtx(), "Calculator"));
350         calcMenu.setIcon(new ImageIcon JavaDoc(org.compiere.Compiere.class.getResource("images/Calculator16.gif")));
351         calcMenu.addActionListener(this);
352         //
353
p_table.getSelectionModel().addListSelectionListener(this);
354         enableButtons();
355     } // jbInit
356

357     /**
358      * Loaded correctly
359      * @return true if loaded OK
360      */

361     public boolean loadedOK()
362     {
363         return p_loadedOK;
364     } // loadedOK
365

366     /**
367      * Set Status Line
368      * @param text text
369      * @param error error
370      */

371     public void setStatusLine (String JavaDoc text, boolean error)
372     {
373         statusBar.setStatusLine(text, error);
374         Thread.yield();
375     } // setStatusLine
376

377     /**
378      * Set Status DB
379      * @param text text
380      */

381     public void setStatusDB (String JavaDoc text)
382     {
383         statusBar.setStatusDB(text);
384     } // setStatusDB
385

386
387     /*************************************************************************/
388
389     /**
390      * Prepare Table, Construct SQL (m_m_sqlMain, m_sqlAdd)
391      * and size Window
392      * @param layout layout array
393      * @param from from clause
394      * @param staticWhere where clause
395      * @param orderBy order by clause
396      */

397     protected void prepareTable (Info_Column[] layout, String JavaDoc from, String JavaDoc staticWhere, String JavaDoc orderBy)
398     {
399         p_layout = layout;
400         StringBuffer JavaDoc sql = new StringBuffer JavaDoc ("SELECT ");
401         // add columns & sql
402
for (int i = 0; i < layout.length; i++)
403         {
404             if (i > 0)
405                 sql.append(", ");
406             sql.append(layout[i].getColSQL());
407             // adding ID column
408
if (layout[i].isIDcol())
409                 sql.append(",").append(layout[i].getIDcolSQL());
410             // add to model
411
p_table.addColumn(layout[i].getColHeader());
412             if (layout[i].isColorColumn())
413                 p_table.setColorColumn(i);
414             if (layout[i].getColClass() == IDColumn.class)
415                 m_keyColumnIndex = i;
416         }
417         // set editors (two steps)
418
for (int i = 0; i < layout.length; i++)
419             p_table.setColumnClass(i, layout[i].getColClass(), layout[i].isReadOnly(), layout[i].getColHeader());
420
421         sql.append( " FROM ").append(from);
422         sql.append(" WHERE ").append(staticWhere);
423         m_sqlMain = sql.toString();
424         m_sqlAdd = "";
425         if (orderBy != null && orderBy.length() > 0)
426             m_sqlAdd = " ORDER BY " + orderBy;
427
428         // Table Selection
429
p_table.setRowSelectionAllowed(true);
430         p_table.addMouseListener(this);
431         p_table.setMultiSelection(p_multiSelection);
432
433         // Window Sizing
434
parameterPanel.setPreferredSize(new Dimension JavaDoc (INFO_WIDTH, parameterPanel.getPreferredSize().height));
435         scrollPane.setPreferredSize(new Dimension JavaDoc(INFO_WIDTH, 400));
436     } // prepareTable
437

438
439     /*************************************************************************/
440
441     /**
442      * Execute Query
443      */

444     void executeQuery()
445     {
446         // ignore when running
447
if (m_worker != null && m_worker.isAlive())
448             return;
449         m_worker = new Worker();
450         m_worker.start();
451     } // executeQuery
452

453     /**
454      * Save Selection - Called by dispose
455      */

456     protected void saveSelection ()
457     {
458         // Already disposed
459
if (p_table == null)
460             return;
461
462         Log.trace(Log.l3_Util, "Info.saveSelection");
463         if (!m_ok) // did not press OK
464
{
465             m_results.clear();
466             p_table.removeAll();
467             p_table = null;
468             return;
469         }
470
471         // Multi Selection
472
if (p_multiSelection)
473         {
474         }
475         else // singleSelection
476
{
477             Object JavaDoc data = getSelectedRowKey();
478             if (data != null)
479                 m_results.add(data);
480         }
481         Log.trace(Log.l4_Data, "SQL= " + getSelectedSQL());
482
483         // Save Settings of detail info screens
484
saveSelectionDetail();
485         // Cleanup
486
p_table.removeAll();
487         p_table = null;
488     } // saveSelection
489

490     /**
491      * Get the key of currently selected row
492      * @return selected key
493      */

494     protected Integer JavaDoc getSelectedRowKey()
495     {
496         int row = p_table.getSelectedRow();
497         if (row != -1 && m_keyColumnIndex != -1)
498         {
499             Object JavaDoc data = p_table.getModel().getValueAt(row, m_keyColumnIndex);
500             if (data instanceof IDColumn)
501                 data = ((IDColumn)data).getRecord_ID();
502             if (data instanceof Integer JavaDoc)
503                 return (Integer JavaDoc)data;
504         }
505         return null;
506     } // getSelectedRowKey
507

508     /**
509      * Get selected Keys
510      * @return selected keys (Integers)
511      */

512     public Object JavaDoc[] getSelectedKeys()
513     {
514         if (!m_ok || m_results.size() == 0)
515             return null;
516         return m_results.toArray();
517     } // getSelectedKeys;
518

519     /**
520      * Get (first) selected Key
521      * @return selected key
522      */

523     public Object JavaDoc getSelectedKey()
524     {
525         if (!m_ok || m_results.size() == 0)
526             return null;
527         return m_results.get(0);
528     } // getSelectedKey
529

530     /**
531      * Is cancelled?
532      * - if pressed Cancel = true
533      * - if pressed OK or window closed = false
534      * @return true if cancelled
535      */

536     public boolean isCancelled()
537     {
538         return m_cancel;
539     } // isCancelled
540

541     /**
542      * Get where clause for (first) selected key
543      * @return WHERE Clause
544      */

545     public String JavaDoc getSelectedSQL()
546     {
547         // No results
548
Object JavaDoc[] keys = getSelectedKeys();
549         if (keys == null || keys.length == 0)
550         {
551             Log.trace(Log.l3_Util, "Info.getSelectedSQL - no Results - OK=" + m_ok + ", Cancel=" + m_cancel);
552             return "";
553         }
554         //
555
StringBuffer JavaDoc sb = new StringBuffer JavaDoc(getKeyColumn());
556         if (keys.length > 1)
557             sb.append(" IN (");
558         else
559             sb.append("=");
560
561         // Add elements
562
for (int i = 0; i < keys.length; i++)
563         {
564             if (getKeyColumn().endsWith("_ID"))
565                 sb.append(keys[i].toString()).append(",");
566             else
567                 sb.append("'").append(keys[i].toString()).append("',");
568         }
569
570         sb.replace(sb.length()-1, sb.length(), "");
571         if (keys.length > 1)
572             sb.append(")");
573         return sb.toString();
574     } // getSelectedSQL;
575

576     /**
577      * (Button) Action Listener & Popup Menu
578      * @param e event
579      */

580     public void actionPerformed(ActionEvent JavaDoc e)
581     {
582         // Popup => Calculator
583
if (e.getSource().equals(calcMenu))
584         {
585             BigDecimal JavaDoc number = null;
586             Object JavaDoc data = p_table.getSelectedValue();
587             try
588             {
589                 if (data != null)
590                 {
591                     if (data instanceof BigDecimal JavaDoc)
592                         number = (BigDecimal JavaDoc)data;
593                     else
594                         number = new BigDecimal JavaDoc(data.toString());
595                 }
596             }
597             catch (Exception JavaDoc ex) {}
598             Calculator c = new Calculator(null, number);
599             c.setVisible(true);
600             return;
601         } // popup
602

603         // Confirm Panel
604
String JavaDoc cmd = e.getActionCommand();
605         if (cmd.equals(ConfirmPanel.A_OK))
606         {
607             dispose(true);
608         }
609         else if (cmd.equals(ConfirmPanel.A_CANCEL))
610         {
611             m_cancel = true;
612             dispose(false);
613         }
614         //
615
else if (cmd.equals(ConfirmPanel.A_HISTORY))
616             showHistory();
617         else if (cmd.equals(ConfirmPanel.A_CUSTOMIZE))
618             customize();
619         else if (cmd.equals(ConfirmPanel.A_ZOOM))
620             zoom();
621         else if (cmd.equals(ConfirmPanel.A_RESET))
622             doReset();
623         // Default
624
else
625             executeQuery();
626     } // actionPerformed
627

628     /**
629      * Zoom to target
630      * @param AD_Window_ID window id
631      * @param zoomQuery zoom query
632      */

633     void zoom (int AD_Window_ID, MQuery zoomQuery)
634     {
635         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
636         AWindow frame = new AWindow();
637         if (!frame.initWindow(AD_Window_ID, zoomQuery, false)) // !IsSOTrx
638
return;
639         AEnv.showCenterScreen(frame);
640         if (this.isModal())
641         {
642             this.setModal(false); // remove modal option has no effect
643
this.dispose();
644         }
645
646         frame = null;
647         setCursor(Cursor.getDefaultCursor());
648     } // zoom
649

650     /**
651      * Dispose (not OK)
652      */

653     public void dispose()
654     {
655         dispose(false);
656     } //
657

658     /**
659      * Dispose and save Selection
660      * @param ok OK pressed
661      */

662     public void dispose(boolean ok)
663     {
664         Log.trace(Log.l3_Util, "Info.dispose", "OK=" + ok);
665         m_ok = ok;
666
667         // End Worker
668
if (m_worker != null)
669         {
670             // worker continues, but it does not block UI
671
if (m_worker.isAlive())
672                 m_worker.interrupt();
673             Log.trace(Log.l4_Data, "Info.dispose - Worker alive=" + m_worker.isAlive());
674         }
675         m_worker = null;
676         //
677
saveSelection();
678         removeAll();
679         super.dispose();
680     } // dispose
681

682     /**
683      * Get Table name Synonym
684      * @return table name
685      */

686     String JavaDoc getTableName()
687     {
688         return p_tableName;
689     } // getTableName
690

691     /**
692      * Get Key Column Name
693      * @return column name
694      */

695     String JavaDoc getKeyColumn()
696     {
697         return p_keyColumn;
698     } // getKeyColumn
699

700     /*************************************************************************/
701
702     /**
703      * Table Selection Changed
704      * @param e event
705      */

706     public void valueChanged(ListSelectionEvent JavaDoc e)
707     {
708         if (e.getValueIsAdjusting())
709             return;
710         enableButtons();
711     } // calueChanged
712

713     /**
714      * Enable OK, History, Zoom if row selected
715      */

716     void enableButtons ()
717     {
718         boolean enable = p_table.getSelectedRow() != -1;
719         confirmPanel.getOKButton().setEnabled(enable);
720         if (hasHistory())
721             confirmPanel.getHistoryButton().setEnabled(enable);
722         if (hasZoom())
723             confirmPanel.getZoomButton().setEnabled(enable);
724     } // enableButtons
725

726     /*************************************************************************/
727
728     /**
729      * Get dynamic WHERE part of SQL
730      * To be overwritten by concrete classes
731      * @return WHERE clause
732      */

733     abstract String JavaDoc getSQLWhere();
734     /**
735      * Set Parameters for Query
736      * To be overwritten by concrete classes
737      * @param pstmt statement
738      * @throws SQLException
739      */

740     abstract void setParameters(PreparedStatement JavaDoc pstmt) throws SQLException JavaDoc;
741
742     /**
743      * Reset Parameters
744      * To be overwritten by concrete classes
745      */

746     void doReset() {}
747     /**
748      * Has Reset (false)
749      * To be overwritten by concrete classes
750      * @return true if it has reset (default false)
751      */

752     boolean hasReset() {return false;}
753     /**
754      * History dialog
755      * To be overwritten by concrete classes
756      */

757     void showHistory() {}
758     /**
759      * Has History (false)
760      * To be overwritten by concrete classes
761      * @return true if it has history (default false)
762      */

763     boolean hasHistory() {return false;}
764     /**
765      * Customize dialog
766      * To be overwritten by concrete classes
767      */

768     void customize() {}
769     /**
770      * Has Customize (false)
771      * To be overwritten by concrete classes
772      * @return true if it has customize (default false)
773      */

774     boolean hasCustomize() {return false;}
775     /**
776      * Zoom action
777      * To be overwritten by concrete classes
778      */

779     void zoom() {}
780     /**
781      * Has Zoom (false)
782      * To be overwritten by concrete classes
783      * @return true if it has zoom (default false)
784      */

785     boolean hasZoom() {return false;}
786     /**
787      * Save Selection Details
788      * To be overwritten by concrete classes
789      */

790     void saveSelectionDetail() {}
791
792     /*************************************************************************/
793
794     /**
795      * Mouse Clicked
796      * @param e event
797      */

798     public void mouseClicked(MouseEvent JavaDoc e)
799     {
800     // Log.trace(Log.l6_Database, "Info.mouseClicked",
801
// "ClickCount=" + e.getClickCount() + ", Right=" + SwingUtilities.isRightMouseButton(e)
802
// + ", r=" + m_table.getSelectedRow() + ", c=" + m_table.getSelectedColumn());
803

804         // Double click with selected row => exit
805
if (e.getClickCount() > 1 && p_table.getSelectedRow() != -1)
806         {
807             dispose(true); // double_click same as OK
808
}
809         // Right Click => start Calculator
810
else if (SwingUtilities.isRightMouseButton(e))
811         {
812             popup.show(e.getComponent(), e.getX(), e.getY());
813         }
814     } // mouseClicked
815

816
817     /**
818      * Worker
819      */

820     class Worker extends Thread JavaDoc
821     {
822         /**
823          * Do Work (load data)
824          */

825         public void run()
826         {
827             Log.trace(Log.l3_Util, "Info.Worker.run");
828             setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
829             setStatusLine(Msg.getMsg(Env.getCtx(), "StartSearch"), false);
830
831             // Clear Table
832
p_table.setRowCount(0);
833             //
834
StringBuffer JavaDoc sql = new StringBuffer JavaDoc (m_sqlMain);
835             String JavaDoc dynWhere = getSQLWhere();
836             if (dynWhere.length() > 0)
837                 sql.append(dynWhere); // includes first AND
838
sql.append(m_sqlAdd);
839             String JavaDoc xSql = MRole.getDefault().addAccessSQL(sql.toString(), getTableName(),
840             MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
841
842             try
843             {
844                 PreparedStatement JavaDoc pstmt = DB.prepareStatement(xSql);
845                 Log.trace(Log.l4_Data, "SQL=" + xSql);
846                 setParameters (pstmt);
847             // Log.trace(Log.l6_Database, "Info.Worker.run - start query");
848
ResultSet JavaDoc rs = pstmt.executeQuery();
849             // Log.trace(Log.l6_Database, "Info.Worker.run - end query");
850
while (!isInterrupted() & rs.next())
851                 {
852                     int row = p_table.getRowCount();
853                     p_table.setRowCount(row+1);
854                     int colOffset = 1; // columns start with 1
855
for (int col = 0; col < p_layout.length; col++)
856                     {
857                         Object JavaDoc data = null;
858                         Class JavaDoc c = p_layout[col].getColClass();
859                         int colIndex = col + colOffset;
860                         if (c == IDColumn.class)
861                             data = new IDColumn(rs.getInt(colIndex));
862                         else if (c == Boolean JavaDoc.class)
863                             data = new Boolean JavaDoc("Y".equals(rs.getString(colIndex)));
864                         else if (c == Timestamp JavaDoc.class)
865                             data = rs.getTimestamp(colIndex);
866                         else if (c == BigDecimal JavaDoc.class)
867                             data = rs.getBigDecimal(colIndex);
868                         else if (c == Double JavaDoc.class)
869                             data = new Double JavaDoc(rs.getDouble(colIndex));
870                         else if (c == Integer JavaDoc.class)
871                             data = new Integer JavaDoc(rs.getInt(colIndex));
872                         else if (c == KeyNamePair.class)
873                         {
874                             String JavaDoc display = rs.getString(colIndex);
875                             int key = rs.getInt(colIndex+1);
876                             data = new KeyNamePair(key, display);
877                             colOffset++;
878                         }
879                         else
880                             data = rs.getString(colIndex);
881                         // store
882
p_table.setValueAt(data, row, col);
883                     // Log.trace(Log.l6_Database, "r=" + row + ", c=" + col + " " + m_layout[col].getColHeader(),
884
// "data=" + data.toString() + " " + data.getClass().getName() + " * " + m_table.getCellRenderer(row, col));
885
}
886                 }
887                 Log.trace(Log.l4_Data, "Info.Worker.run - interrupted=" + isInterrupted());
888                 rs.close();
889                 pstmt.close();
890             }
891             catch (SQLException JavaDoc e)
892             {
893                 Log.error("Info.Worker.run - " + xSql, e);
894             }
895             p_table.autoSize();
896             //
897
setCursor(Cursor.getDefaultCursor());
898             int no = p_table.getRowCount();
899             setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
900             setStatusDB(Integer.toString(no));
901         } // run
902
} // Worker
903

904 } // Info
905
Popular Tags