KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > APanel


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;
15
16 import javax.swing.*;
17 import javax.swing.event.*;
18 import java.awt.*;
19 import java.awt.event.*;
20 import java.awt.print.*;
21 import java.io.*;
22 import java.util.*;
23 import java.sql.*;
24
25 import org.compiere.model.*;
26 import org.compiere.process.*;
27 import org.compiere.util.*;
28 import org.compiere.grid.*;
29 import org.compiere.grid.ed.*;
30 import org.compiere.images.ImageFactory;
31 import org.compiere.apps.search.*;
32 import org.compiere.print.*;
33 import org.compiere.plaf.*;
34 import org.compiere.swing.*;
35
36 /**
37  * Main Application Panel.
38  * <pre>
39  * Structure:
40  * (MenuBar) -> to be added to owning window
41  * northPanel (ToolBar)
42  * tabPanel
43  * southPanel (StatusBar)
44  * </pre>
45  *
46  * @author Jorg Janke
47  * @version $Id: APanel.java,v 1.91 2003/10/27 15:22:03 jjanke Exp $
48  */

49 public final class APanel extends CPanel
50     implements DataStatusListener, ChangeListener, ActionListener, ASyncProcess
51 {
52     /**
53      * Constructs a new instance.
54      * Need to call initPanel for dynamic initialization
55      */

56     public APanel()
57     {
58         super();
59         m_ctx = Env.getCtx();
60         //
61
try
62         {
63             jbInit();
64         }
65         catch (Exception JavaDoc e)
66         {
67             Log.error("APanel", e);
68         }
69         createMenu();
70     } // APanel
71

72     /**
73      * Dispose
74      */

75     public void dispose()
76     {
77         Log.trace(Log.l1_User, "APanel.dispose");
78         // ignore changes
79
m_disposing = true;
80         // close panels
81
tabPanel.dispose(this);
82         tabPanel = null;
83         // All Workbenches
84
for (int i = 0; i < m_mWorkbench.getWindowCount(); i++)
85         {
86             m_curWindowNo = m_mWorkbench.getWindowNo(i);
87             Log.trace(Log.l1_User, "APanel.dispose #" + m_curWindowNo);
88             Env.setAutoCommit(m_ctx, m_curWindowNo, false);
89             m_mWorkbench.dispose(i);
90             Env.clearWinContext(m_ctx, m_curWindowNo);
91         } // all Workbenchens
92

93         // Get rid of remaining model
94
if (m_mWorkbench != null)
95             m_mWorkbench.dispose();
96         m_mWorkbench = null;
97         // MenuBar
98
if (menuBar != null)
99             menuBar.removeAll();
100         menuBar = null;
101         // ToolBar
102
if (toolBar != null)
103             toolBar.removeAll();
104         toolBar = null;
105         // Prepare GC
106
this.removeAll();
107     } // dispose
108

109     /**
110      * The Layout.
111      */

112     private BorderLayout mainLayout = new BorderLayout();
113     private VTabbedPane tabPanel = new VTabbedPane(true);
114     private StatusBar statusBar = new StatusBar();
115     private CPanel northPanel = new CPanel();
116     private JToolBar toolBar = new JToolBar();
117     private JMenuBar menuBar = new JMenuBar();
118     private FlowLayout northLayout = new FlowLayout();
119
120     /**
121      * Initializes the state of this instance.
122      * @throws Exception
123      */

124     private void jbInit() throws Exception JavaDoc
125     {
126         this.setLocale(Language.getLanguage().getLocale());
127         this.setLayout(mainLayout);
128
129         // tabPanel
130
mainLayout.setHgap(2);
131         mainLayout.setVgap(2);
132         this.add(tabPanel, BorderLayout.CENTER);
133         // southPanel
134
this.add(statusBar, BorderLayout.SOUTH);
135         // northPanel
136
this.add(northPanel, BorderLayout.NORTH);
137         northPanel.setLayout(northLayout);
138         northLayout.setAlignment(FlowLayout.LEFT);
139         northPanel.add(toolBar, null);
140     } // jbInit
141

142     private AppsAction aPrevious, aNext, aParent, aDetail, aFirst, aLast,
143                             aNew, aCopy, aDelete, aIgnore, aPrint,
144                             aRefresh, aHistory, aAttachment, aMulti, aFind;
145     public AppsAction aSave, aLock;
146     // Local (added to toolbar)
147
private AppsAction aReport, aEnd, aHome, aHelp, aProduct,
148                             aAccount, aCalculator, aCalendar, aEditor, aPreference, aScript,
149                             aOnline, aSendMail, aAbout, aPrintScr, aScrShot, aExit, aBPartner;
150
151     /*************************************************************************/
152
153     /**
154      * Create Menu and Toolbar and registers keyboard actions.
155      * - started from constructor
156      */

157     private void createMenu()
158     {
159         /**
160          * Menu
161          */

162     // menuBar.setHelpMenu();
163
// File
164
JMenu mFile = AEnv.getMenu("File");
165         menuBar.add(mFile);
166         aPrintScr = addAction("PrintScreen", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, 0), false);
167         aScrShot = addAction("ScreenShot", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, Event.SHIFT_MASK), false);
168         aReport = addAction("Report", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.ALT_MASK), false);
169         aPrint = addAction("Print", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK), false);
170         mFile.addSeparator();
171         aEnd = addAction("End", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK), false);
172         aExit = addAction("Exit", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.SHIFT_MASK+Event.ALT_MASK), false);
173         // Edit
174
JMenu mEdit = AEnv.getMenu("Edit");
175         menuBar.add(mEdit);
176         aNew = addAction("New", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK), false);
177         aSave = addAction("Save", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK), false);
178         mEdit.addSeparator();
179         aCopy = addAction("Copy", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK), false);
180         aDelete = addAction("Delete", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK), false);
181         aIgnore = addAction("Ignore", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), false);
182         aRefresh = addAction("Refresh", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), false);
183         mEdit.addSeparator();
184         aFind = addAction("Find", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK), true); // toggle
185
if (m_isPersonalLock)
186             aLock = addAction("Lock", mEdit, null, true); // toggle
187
// View
188
JMenu mView = AEnv.getMenu("View");
189         menuBar.add(mView);
190         aProduct = addAction("InfoProduct", mView, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.CTRL_MASK), false);
191         aBPartner = addAction("InfoBPartner", mView, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.SHIFT_MASK+Event.CTRL_MASK), false);
192         if (MRole.getDefault().isShowAcct())
193             aAccount = addAction("InfoAccount", mView, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.ALT_MASK+Event.CTRL_MASK), false);
194         AEnv.addMenuItem("InfoSchedule", null, null, mView, this);
195         mView.addSeparator();
196         AEnv.addMenuItem("InfoOrder", "Info", null, mView, this);
197         AEnv.addMenuItem("InfoInvoice", "Info", null, mView, this);
198         AEnv.addMenuItem("InfoInOut", "Info", null, mView, this);
199         AEnv.addMenuItem("InfoPayment", "Info", null, mView, this);
200         AEnv.addMenuItem("InfoCashLine", "Info", null, mView, this);
201         AEnv.addMenuItem("InfoAssignment", "Info", null, mView, this);
202         AEnv.addMenuItem("InfoAsset", "Info", null, mView, this);
203         mView.addSeparator();
204         aAttachment = addAction("Attachment", mView, KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0), true); // toggle
205
aHistory = addAction("History", mView, KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0), true); // toggle
206
mView.addSeparator();
207         aMulti = addAction("Multi", mView, KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), true); // toggle
208
// Go
209
JMenu mGo = AEnv.getMenu("Go");
210         menuBar.add(mGo);
211         aFirst = addAction("First", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, Event.ALT_MASK), false);
212         aPrevious = addAction("Previous", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_UP, Event.ALT_MASK), false);
213         aNext = addAction("Next", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Event.ALT_MASK), false);
214         aLast = addAction("Last", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, Event.ALT_MASK), false);
215         mGo.addSeparator();
216         aParent = addAction("Parent", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Event.ALT_MASK), false);
217         aDetail = addAction("Detail", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Event.ALT_MASK), false);
218         mGo.addSeparator();
219         aHome = addAction("Home", mGo, null, false);
220         // Tools
221
JMenu mTools = AEnv.getMenu("Tools");
222         menuBar.add(mTools);
223         aCalculator = addAction("Calculator", mTools, null, false);
224         aCalendar = addAction("Calendar", mTools, null, false);
225         aEditor = addAction("Editor", mTools, null, false);
226         aScript = addAction("Script", mTools, null, false);
227         mTools.addSeparator();
228         aPreference = addAction("Preference", mTools, null, false);
229         // Help
230
JMenu mHelp = AEnv.getMenu("Help");
231         menuBar.add(mHelp);
232         aHelp = addAction("Help", mHelp, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), false);
233         aOnline = addAction("Online", mHelp, null, false);
234         aSendMail = addAction("SendMail", mHelp, null, false);
235         aAbout = addAction("About", mHelp, null, false);
236
237         /**
238          * KeyBoard Actions
239          *
240          * Function Keys (if not defined above)
241          */

242         int c = CPanel.WHEN_IN_FOCUSED_WINDOW; // default condition = WHEN_FOCUSED
243
// ESC = Ignore
244
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), aIgnore.getName());
245         getActionMap().put(aIgnore.getName(), aIgnore);
246         // F1 = Help
247
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), aHelp.getName());
248         getActionMap().put(aHelp.getName(), aHelp);
249         // F2 = New
250
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), aNew.getName());
251         getActionMap().put(aNew.getName(), aNew);
252         // F3 = Delete
253
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), aDelete.getName());
254         getActionMap().put(aDelete.getName(), aDelete);
255         // F4 = Save
256
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), aSave.getName());
257         getActionMap().put(aSave.getName(), aSave);
258         // F5 = Refresh
259
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), aRefresh.getName());
260         getActionMap().put(aRefresh.getName(), aRefresh);
261         // F6 = Find
262
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), aFind.getName());
263         getActionMap().put(aFind.getName(), aFind);
264         // F7 = Arrachment
265
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0), aAttachment.getName());
266         getActionMap().put(aAttachment.getName(), aAttachment);
267         // F8 = Multi
268
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), aMulti.getName());
269         getActionMap().put(aMulti.getName(), aMulti);
270         // F9 = History
271
getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0), aHistory.getName());
272         getActionMap().put(aHistory.getName(), aHistory);
273
274         /**
275          * ToolBar
276          */

277         toolBar.add(aIgnore.getButton()); // ESC
278
toolBar.addSeparator();
279         toolBar.add(aHelp.getButton()); // F1
280
toolBar.add(aNew.getButton());
281         toolBar.add(aDelete.getButton());
282         toolBar.add(aSave.getButton());
283         toolBar.addSeparator();
284         toolBar.add(aRefresh.getButton()); // F5
285
toolBar.add(aFind.getButton());
286         toolBar.add(aAttachment.getButton());
287         toolBar.add(aMulti.getButton());
288         toolBar.addSeparator();
289         toolBar.add(aHistory.getButton()); // F9
290
toolBar.add(aHome.getButton()); // F10 is Windows Menu Key
291
toolBar.add(aParent.getButton());
292         toolBar.add(aDetail.getButton());
293         toolBar.addSeparator();
294         toolBar.add(aFirst.getButton());
295         toolBar.add(aPrevious.getButton());
296         toolBar.add(aNext.getButton());
297         toolBar.add(aLast.getButton());
298         toolBar.addSeparator();
299         toolBar.add(aReport.getButton());
300         toolBar.add(aPrint.getButton());
301         toolBar.addSeparator();
302         if (m_isPersonalLock)
303             toolBar.add(aLock.getButton());
304         toolBar.add(aProduct.getButton());
305         toolBar.addSeparator();
306         toolBar.add(aEnd.getButton());
307         //
308
if (Log.getTraceLevel() > Log.l6_Database)
309             AEnv.printActionInputMap(this);
310     } // createMenu
311

312
313     /**
314      * Add (Toggle) Action to Toolbar and Menu
315      * @param action action
316      * @param menu manu
317      * @param accelerator accelerator
318      * @param toggle toggle button
319      * @return AppsAction
320      */

321     private AppsAction addAction (String JavaDoc action, JMenu menu, KeyStroke accelerator, boolean toggle)
322     {
323         AppsAction act = new AppsAction(action, accelerator, toggle);
324         if (menu != null)
325             menu.add(act.getMenuItem());
326         act.setDelegate(this);
327         return act;
328     } // addAction
329

330     /**
331      * Return MenuBar
332      * @return JMenuBar
333      */

334     public JMenuBar getMenuBar()
335     {
336         return menuBar;
337     } // getMenuBar
338

339     /**
340      * Get Title of Window
341      * @return String with Title
342      */

343     public String JavaDoc getTitle()
344     {
345         if (m_mWorkbench.getWindowCount() > 1)
346         {
347             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
348             sb.append(m_mWorkbench.getName()).append(" ")
349                 .append(Env.getContext(m_ctx, "#AD_User_Name")).append("@")
350                 .append(Env.getContext(m_ctx, "#AD_Client_Name")).append(".")
351                 .append(Env.getContext(m_ctx, "#AD_Org_Name")).append(" [")
352                 .append(Env.getContext(m_ctx, "#DB_UID")).append("]");
353             return sb.toString();
354         }
355         return Env.getHeader(m_ctx, m_curWindowNo);
356     } // getTitle
357

358
359     private Properties m_ctx;
360     private boolean m_isSOTrx;
361
362     /** Workbench Model */
363     private MWorkbench m_mWorkbench;
364     /** Current MTab */
365     private MTab m_curTab;
366     /** Current GridController */
367     private GridController m_curGC;
368     /** Current Window Panel */
369     private JTabbedPane m_curWinTab = null;
370     /** Current Window No */
371     private int m_curWindowNo;
372     /** Current Window Panel Index */
373     private int m_curTabIndex = -1;
374     /** Current Tab Order */
375     private APanelTab m_curAPanelTab = null;
376
377     /** Dispose active */
378     private boolean m_disposing = false;
379     /** Save Error Message indicator */
380     private boolean m_errorDisplayed = false;
381     /** Only current row flag */
382     private boolean m_onlyCurrentRows = true;
383     /** Number of days to show */
384     private int m_onlyCurrentDays = 1;
385     /** Process Info */
386     private boolean m_isLocked = false;
387     /** Show Personal Lock */
388     private boolean m_isPersonalLock = MRole.getDefault().isPersonalLock();
389     /** Last Modifier of Action Event */
390     private int m_lastModifiers;
391
392     /*************************************************************************/
393
394     /**
395      * Dynamic Panel Initialization - either single window or workbench.
396      * <pre>
397      * either
398      * - Workbench tabPanel (VTabbedPane)
399      * - Tab (GridController)
400      * or
401      * - Workbench tabPanel (VTabbedPane)
402      * - Window (VTabbedPane)
403      * - Tab (GridController)
404      * </pre>
405      * tabPanel
406      * @param AD_Workbench_ID if > 0 this is a workbench, AD_Window_ID ignored
407      * @param AD_Window_ID if not a workbench, Window ID
408      * @param query if not a Workbench, Zoom Query - additional SQL where clause
409      * @param isSOTrx Sales Order Trx
410      * @return true if Panel is initialized successfully
411      */

412     public boolean initPanel (int AD_Workbench_ID, int AD_Window_ID, MQuery query, boolean isSOTrx)
413     {
414         Log.trace(Log.l1_User, "APanel.initPanel",
415             "WB=" + AD_Workbench_ID + ", Win=" + AD_Window_ID + ", Query=" + query + ", SO=" + isSOTrx);
416         this.setName("APanel" + AD_Window_ID);
417         m_isSOTrx = isSOTrx;
418
419
420         // Single Window
421
if (AD_Workbench_ID == 0)
422             m_mWorkbench = new MWorkbench(m_ctx, AD_Window_ID);
423         else
424         // Workbench
425
{
426         // m_mWorkbench = new MWorkbench(m_ctx);
427
// if (!m_mWorkbench.initWorkbench (AD_Workbench_ID))
428
// {
429
// Log.error("APanel.initWindow - No Workbench Model");
430
// return false;
431
// }
432
// tabPanel.setWorkbench(true);
433
// tabPanel.addChangeListener(this);
434
ADialog.warn(0, this, "","Not implemented yet");
435             return false;
436         }
437
438         /**
439          * WorkBench Loop
440          */

441         for (int wb = 0; wb < m_mWorkbench.getWindowCount(); wb++)
442         {
443             // Get/set WindowNo
444
m_curWindowNo = Env.createWindowNo (this); // Timing: ca. 1.5 sec
445
m_mWorkbench.setWindowNo(wb, m_curWindowNo);
446             // Set AutoCommit/SO for this Window
447
Env.setAutoCommit(m_ctx, m_curWindowNo, Env.isAutoCommit(m_ctx));
448             Env.setContext(m_ctx, m_curWindowNo, "IsSOTrx", isSOTrx ? "Y" : "N");
449
450             // Workbench Window
451
VTabbedPane window = null;
452             // just one window
453
if (m_mWorkbench.getWindowCount() == 1)
454             {
455                 window = tabPanel;
456                 window.setWorkbench(false);
457             }
458             else
459             {
460                 VTabbedPane tp = new VTabbedPane(false);
461                 window = tp;
462             }
463             // Window Init
464
window.addChangeListener(this);
465
466             /**
467              * Init Model
468              */

469             int wbType = m_mWorkbench.getWindowType(wb);
470
471             /**
472              * Window
473              */

474             if (wbType == MWorkbench.TYPE_WINDOW)
475             {
476                 HashMap includedMap = new HashMap(2);
477                 //
478
MWindowVO wVO = AEnv.getMWindowVO(m_curWindowNo, m_mWorkbench.getWindowID(wb), 0);
479                 if (wVO == null)
480                 {
481                     ADialog.error(0, null, "AccessTableNoView", "(No Window Model Info)");
482                     return false;
483                 }
484                 MWindow mWindow = new MWindow (wVO); // Timing: ca. 0.3-1 sec
485
m_mWorkbench.setMWindow(wb, mWindow);
486                 if (wb == 0)
487                     m_onlyCurrentRows = mWindow.isTransaction(); // default = only current
488

489                 /**
490                  * Window Tabs
491                  */

492                 int tabSize = mWindow.getTabCount();
493                 for (int tab = 0; tab < tabSize; tab++)
494                 {
495                     boolean included = false;
496                     // MTab
497
MTab mTab = m_mWorkbench.getMWindow(wb).getTab(tab);
498                     // Query first tab
499
if (tab == 0)
500                     {
501                         // initial user query for single workbench tab
502
if (m_mWorkbench.getWindowCount() == 1)
503                         {
504                             // Query automatically if high volume and no query
505
if (mTab.isHighVolume() && (query == null || !query.isActive()))
506                             {
507                                 Find find = new Find(Env.getFrame(this), m_curWindowNo, mTab);
508                                 query = find.getQuery();
509                                 find = null;
510                             }
511                         }
512                         else if (wb != 0)
513                         // workbench dynamic query for dependent windows
514
{
515                             query = m_mWorkbench.getQuery();
516                         }
517                         // Set initial Query on first tab
518
if (query != null)
519                         {
520                             m_onlyCurrentRows = false; // Query might involve history
521
mTab.setQuery(query);
522                         }
523                         if (wb == 0)
524                             m_curTab = mTab;
525                     } // query on first tab
526

527                     Component tabElement = null;
528                     // GridController
529
if (mTab.isSortTab())
530                     {
531                         VSortTab st = new VSortTab(m_curWindowNo, mTab.getAD_Table_ID(),
532                             mTab.getAD_ColumnSortOrder_ID(), mTab.getAD_ColumnSortYesNo_ID());
533                         st.setTabLevel(mTab.getTabLevel());
534                         tabElement = st;
535                     }
536                     else // normal tab
537
{
538                         GridController gc = new GridController(); // Timing: ca. .1 sec
539
CompiereColor cc = mWindow.getColor();
540                         if (cc != null)
541                             gc.setBackgroundColor(cc); // set color on Window level
542
gc.initGrid(mTab, false, m_curWindowNo, this, mWindow); // will set color on Tab level
543
// Timing: ca. 6-7 sec for first .2 for next
544
gc.addDataStatusListener(this);
545                         gc.registerESCAction(aIgnore); // register Escape Key
546
// Set First Tab
547
if (wb == 0 && tab == 0)
548                         {
549                             m_curGC = gc;
550                             Dimension size = gc.getPreferredSize(); // Screen Sizing
551
size.width += 4;
552                             size.height += 4;
553                             gc.setPreferredSize(size);
554                         }
555                         tabElement = gc;
556                         // If we have a query, switch to single row
557
if (tab == 0 && query != null)
558                             gc.switchSingleRow();
559
560                         // Store GC if it has a included Tab
561
if (mTab.getIncluded_Tab_ID() != 0)
562                             includedMap.put(new Integer JavaDoc(mTab.getIncluded_Tab_ID()), gc);
563
564                         // Is this tab included?
565
if (includedMap.size() > 0)
566                         {
567                             GridController parent = (GridController)includedMap.get(new Integer JavaDoc(mTab.getAD_Tab_ID()));
568                             if (parent != null)
569                             {
570                                 included = parent.includeTab(gc);
571                                 if (!included)
572                                     Log.error("APanel.initPanel - Not Included = " + gc);
573                             }
574                         }
575                     } // normal tab
576

577                     if (!included) // Add to TabbedPane
578
{
579                         StringBuffer JavaDoc tabName = new StringBuffer JavaDoc ();
580                         if (CompierePLAF.isActive ())
581                             tabName.append (mTab.getName ()).append (" ");
582                         else
583                         {
584                             tabName.append ("<html>");
585                             int pos = mTab.getName ().indexOf (" ");
586                             if (pos == -1)
587                                 tabName.append (mTab.getName ()).append ("<br>");
588                             else
589                             {
590                                 tabName.append (mTab.getName ().substring (0,
591                                   pos))
592                                   .append ("<br>").append (mTab.getName ().
593                                   substring (pos + 1));
594                                 tabName.append ("</html>");
595                             }
596                         }
597                         window.addTab (tabName.toString(), mTab.getIcon(), tabElement, mTab.getDescription());
598                         // caused stateChanged for first tab - 3 seconds
599
window.setMnemonicAt (tab, KeyEvent.VK_1 + tab); // 1,2,3,..
600
}
601                 } // Tab Loop
602
// Tab background
603
// window.setBackgroundColor(new CompiereColor(Color.magenta, Color.green));
604
} // Type-MWindow
605

606             // Single Workbench Window Tab
607
if (m_mWorkbench.getWindowCount() == 1)
608             {
609                 window.setToolTipText(m_mWorkbench.getDescription(wb));
610             }
611             else
612             // Add Workbench Window Tab
613
{
614                 tabPanel.addTab(m_mWorkbench.getName(wb), m_mWorkbench.getIcon(wb), window, m_mWorkbench.getDescription(wb));
615             }
616             // Used for Env.getHeader
617
Env.setContext(m_ctx, m_curWindowNo, "WindowName", m_mWorkbench.getName(wb));
618
619         } // Workbench Loop
620

621         // stateChanged (<->) triggered
622
toolBar.setName(getTitle());
623         m_curTab.getTableModel().setChanged(false);
624         // Set Detail Button
625
aDetail.setEnabled(0 != m_curWinTab.getTabCount()-1);
626
627         // setPreferredSize comes here
628
Log.trace(Log.l1_User, "APanel.initPanel - fini");
629         m_curWinTab.requestFocusInWindow();
630         return true;
631     } // initPanel
632

633     /**
634      * Get Window Index
635      * @return Window Index
636      */

637     private int getWindowIndex()
638     {
639         // only one window
640
if (m_mWorkbench.getWindowCount() == 1)
641             return 0;
642         // workbench
643
return tabPanel.getSelectedIndex();
644     } // getWindowIndex
645

646     /**
647      * Is first Tab (on Window)
648      * @return true if the panel displays the first tab
649      */

650     private boolean isFirstTab()
651     {
652         return m_curWinTab.getSelectedIndex() == 0;
653     } // isFirstTab
654

655     /*************************************************************************/
656
657     /**
658      * Data Status Listener (row change) ^ | v
659      * @param e event
660      */

661     public void dataStatusChanged (DataStatusEvent e)
662     {
663         if (m_disposing)
664             return;
665         Log.trace(Log.l1_User, "APanel.dataStatusChanged", e.getMessage());
666         String JavaDoc dbInfo = e.getMessage();
667         if (m_curTab != null && m_curTab.isQueryActive())
668             dbInfo = "[ " + dbInfo + " ]";
669         statusBar.setStatusDB(dbInfo, e.Created, e.CreatedBy, e.Updated, e.UpdatedBy, e.Info);
670
671         // Set Message / Info
672
if (e.getAD_Message() != null || e.getInfo() != null)
673         {
674             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
675             String JavaDoc msg = e.getMessage();
676             if (msg != null && msg.length() > 0)
677                 sb.append(Msg.getMsg(m_ctx, e.getAD_Message()));
678             String JavaDoc info = e.getInfo();
679             if (info != null && info.length() > 0)
680             {
681                 if (sb.length() > 0 && !sb.toString().trim().endsWith(":"))
682                     sb.append(": ");
683                 sb.append(info);
684             }
685             if (sb.length() > 0)
686             {
687                 int pos = sb.indexOf("\n");
688                 if (pos != -1) // replace CR/NL
689
sb.replace(pos, pos+1, " - ");
690                 setStatusLine (sb.toString (), e.isError ());
691             }
692         }
693
694         // Confirm Error
695
if (e.isError() && !e.isConfirmed())
696         {
697             ADialog.error(m_curWindowNo, this, e.getAD_Message(), e.getInfo());
698             e.setConfirmed(true); // show just once - if MTable.setCurrentRow is involved the status event is re-issued
699
m_errorDisplayed = true;
700         }
701
702         // update Navigation
703
boolean firstRow = e.isFirstRow();
704         aFirst.setEnabled(!firstRow);
705         aPrevious.setEnabled(!firstRow);
706         boolean lastRow = e.isLastRow();
707         aNext.setEnabled(!lastRow);
708         aLast.setEnabled(!lastRow);
709
710         // update Change
711
boolean changed = e.isChanged() || e.isInserting();
712         boolean readOnly = m_curTab.isReadOnly();
713         //
714
aIgnore.setEnabled(changed & !readOnly);
715         aSave.setEnabled(changed & !readOnly);
716         //
717
aNew.setEnabled(!changed & !readOnly);
718         aCopy.setEnabled(!changed & !readOnly);
719         aDelete.setEnabled(!changed & !readOnly);
720         aRefresh.setEnabled(!changed);
721         // No Rows
722
if (e.getTotalRows() == 0)
723             aNew.setEnabled(true);
724
725         // Single-Multi
726
aMulti.setPressed(!m_curGC.isSingleRow());
727
728         // History (on first Tab only)
729
if (isFirstTab())
730             aHistory.setPressed(!m_curTab.isOnlyCurrentRows());
731
732         // Transaction info
733
String JavaDoc trxInfo = m_curTab.getTrxInfo();
734         if (trxInfo != null)
735             statusBar.setInfo(trxInfo);
736
737         // Check Attachment
738
boolean canHaveAttachment = m_curTab.canHaveAttachment(); // not single _ID column
739
//
740
if (canHaveAttachment && e.isLoading() && m_curTab.getCurrentRow() > e.getLoadedRows())
741             canHaveAttachment = false;
742         if (canHaveAttachment && m_curTab.getCurrentKeyID() == -1) // No Key
743
canHaveAttachment = false;
744         if (canHaveAttachment)
745         {
746             aAttachment.setEnabled(true);
747             aAttachment.setPressed(m_curTab.hasAttachment());
748         }
749         else
750             aAttachment.setEnabled(false);
751         // Lock Indicator
752
if (m_isPersonalLock)
753             aLock.setPressed(m_curTab.isLocked());
754
755     // Log.trace(Log.l1_User, "APanel.dataStatusChanged - fini", e.getMessage());
756
} // dataStatusChanged
757

758     /**
759      * Set Status Line to text
760      * @param text clear text
761      * @param error error flag
762      */

763     public void setStatusLine (String JavaDoc text, boolean error)
764     {
765         Log.trace(Log.l5_DData, "APanel.setStatusLine = " + text);
766         statusBar.setStatusLine(text, error);
767     } // setStatusLine
768

769     /**
770      * Indicate Busy
771      * @param busy busy
772      */

773     private void setBusy (boolean busy)
774     {
775         m_isLocked = busy;
776         //
777
JFrame frame = Env.getFrame(this);
778         if (frame == null) // during init
779
return;
780         if (frame instanceof AWindow)
781             ((AWindow)frame).setBusy(busy);
782     // String processing = Msg.getMsg(m_ctx, "Processing");
783
if (busy)
784         {
785     // setStatusLine(processing);
786
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
787             frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
788         }
789         else
790         {
791             this.setCursor(Cursor.getDefaultCursor());
792             frame.setCursor(Cursor.getDefaultCursor());
793     // if (statusBar.getStatusLine().equals(processing))
794
// statusBar.setStatusLine("");
795
}
796     } // set Busy
797

798     /*************************************************************************/
799
800     /**
801      * Change Listener - (tab change) <->
802      * @param e event
803      */

804     public void stateChanged (ChangeEvent e)
805     {
806         if (m_disposing)
807             return;
808         Log.trace(Log.l1_User, "APanel.stateChanged");
809         setBusy(true);
810
811         VTabbedPane tp = (VTabbedPane)e.getSource();
812         boolean back = false;
813         boolean isAPanelTab = false;
814
815         // Workbench Tab Change
816
if (tp.isWorkbench())
817         {
818             int WBIndex = tabPanel.getSelectedIndex();
819             m_curWindowNo = m_mWorkbench.getWindowNo(WBIndex);
820             // Window Change
821
Log.trace(Log.l1_User, "APanel.stateChanged curWin=" + m_curWindowNo, "Win=" + tp);
822             if (tp.getSelectedComponent() instanceof JTabbedPane)
823                 m_curWinTab = (JTabbedPane)tp.getSelectedComponent();
824             else
825                 throw new java.lang.IllegalArgumentException JavaDoc("APanel.stateChanged - Window does not contain Tabs");
826             if (m_curWinTab.getSelectedComponent() instanceof GridController)
827                 m_curGC = (GridController)m_curWinTab.getSelectedComponent();
828         // else if (m_curWinTab.getSelectedComponent() instanceof APanelTab)
829
// isAPanelTab = true;
830
else
831                 throw new java.lang.IllegalArgumentException JavaDoc("APanel.stateChanged - Window-Tab does not contain GridControler");
832             // change pointers
833
m_curTabIndex = m_curWinTab.getSelectedIndex();
834         }
835         else
836         {
837             // Just a Tab Change
838
Log.trace(Log.l1_User, "APanel.stateChanged", "Tab=" + tp);
839             m_curWinTab = tp;
840             int tpIndex = m_curWinTab.getSelectedIndex();
841             back = tpIndex < m_curTabIndex;
842             GridController gc = null;
843             if (m_curWinTab.getSelectedComponent() instanceof GridController)
844                 gc = (GridController)m_curWinTab.getSelectedComponent();
845             else if (m_curWinTab.getSelectedComponent() instanceof APanelTab)
846                 isAPanelTab = true;
847             else
848                 throw new java.lang.IllegalArgumentException JavaDoc("APanel.stateChanged - Tab does not contain GridControler");
849             // Save old Tab
850
if (m_curGC != null)
851             {
852                 m_curGC.stopEditor(true);
853                 // has anything changed?
854
if (m_curTab.needSave(true, false))
855                 { // do we have real change
856
if (m_curTab.needSave(true, true))
857                     { // explicitly ask when changing tabs
858
if (ADialog.ask(m_curWindowNo, this, "SaveChanges?", m_curTab.getCommitWarning()))
859                         { // yes we want to save
860
if (!m_curTab.dataSave(true))
861                             { // there is a problem, so we go back
862
m_curWinTab.setSelectedIndex(m_curTabIndex);
863                                 setBusy(false);
864                                 return;
865                             }
866                         }
867                         else // Don't save
868
m_curTab.dataIgnore();
869                     }
870                     else // new record, but nothing changed
871
m_curTab.dataIgnore();
872                 } // there is a change
873
}
874             if (m_curAPanelTab != null)
875             {
876                 m_curAPanelTab.saveData();
877                 m_curAPanelTab.unregisterPanel();
878                 m_curAPanelTab = null;
879             }
880
881             // new tab
882
// if (m_curTabIndex >= 0)
883
// m_curWinTab.setForegroundAt(m_curTabIndex, CompierePLAF.getTextColor_Normal());
884
// m_curWinTab.setForegroundAt(tpIndex, CompierePLAF.getTextColor_OK());
885
m_curTabIndex = tpIndex;
886             if (!isAPanelTab)
887                 m_curGC = gc;
888         }
889
890         // Sort Tab Handling
891
if (isAPanelTab)
892         {
893             m_curAPanelTab = (APanelTab)m_curWinTab.getSelectedComponent();
894             m_curAPanelTab.registerAPanel(this);
895             m_curAPanelTab.loadData();
896         }
897         else // Cur Tab Setting
898
{
899             m_curGC.activate();
900             m_curTab = m_curGC.getMTab();
901
902             // Refresh only current row when tab is current
903
if (back && m_curTab.isCurrent())
904                 m_curTab.dataRefresh();
905             else // Requery & autoSize
906
m_curGC.query (m_onlyCurrentRows, m_onlyCurrentDays);
907
908             // Set initial record
909
if (m_curTab.getRowCount() == 0)
910             {
911                 // Automatically create New Record, if none & tab not RO
912
if (!m_curTab.isReadOnly())
913                 {
914                     Log.trace(Log.l3_Util, "APanel.stateChanged - no record - creating new");
915                     m_curTab.dataNew(false);
916                 }
917                 m_curTab.navigateCurrent(); // updates counter
918
m_curGC.dynamicDisplay(0);
919             }
920             else
921                 m_curTab.navigateCurrent();
922         }
923
924         // Update <-> Navigation
925
aDetail.setEnabled(m_curTabIndex != m_curWinTab.getTabCount()-1);
926         aParent.setEnabled(m_curTabIndex != 0 && m_curWinTab.getTabCount() > 1);
927
928         // History (on first tab only)
929
if (m_mWorkbench.getMWindow(getWindowIndex()).isTransaction())
930             aHistory.setEnabled(isFirstTab());
931         else
932         {
933             aHistory.setPressed(false);
934             aHistory.setEnabled(false);
935         }
936         // Document Print
937
aPrint.setEnabled(m_curTab.isPrinted());
938         // Query
939
aFind.setPressed(m_curTab.isQueryActive());
940
941         // Single-Multi
942
if (isAPanelTab)
943         {
944             aMulti.setPressed(false);
945             aMulti.setEnabled(false);
946         }
947         else
948         {
949             aMulti.setEnabled(true);
950             aMulti.setPressed(!m_curGC.isSingleRow());
951         }
952         //
953
aNew.setEnabled(!isAPanelTab);
954         aDelete.setEnabled(!isAPanelTab);
955         aFind.setEnabled(!isAPanelTab);
956         aRefresh.setEnabled(!isAPanelTab);
957         aAttachment.setEnabled(!isAPanelTab);
958         //
959
m_curWinTab.requestFocusInWindow();
960         setBusy(false);
961         Log.trace(Log.l1_User, "APanel.stateChanged - fini");
962     } // stateChanged
963

964     /**
965      * Navigate to Detail Tab ->
966      */

967     private void cmd_detail()
968     {
969         int index = m_curWinTab.getSelectedIndex();
970         if (index == m_curWinTab.getTabCount()-1)
971             return;
972         m_curWinTab.setSelectedIndex(index+1);
973     } // navigateDetail
974

975     /**
976      * Navigate to Parent Tab <-
977      */

978     private void cmd_parent()
979     {
980         int index = m_curWinTab.getSelectedIndex();
981         if (index == 0)
982             return;
983         m_curWinTab.setSelectedIndex(index-1);
984     } // navigateParent
985

986     /*************************************************************************/
987
988     /**
989      * Action Listener
990      * @param e event
991      */

992     public void actionPerformed (ActionEvent e)
993     {
994         Log.trace(Log.l1_User, "APanel.actionPerformed",
995             e.getActionCommand() + " - " + e.getModifiers());
996         // + " - " + new Timestamp(e.getWhen()) + " " + isUILocked());
997
if (m_disposing || isUILocked())
998             return;
999             
1000        m_lastModifiers = e.getModifiers();
1001        String JavaDoc cmd = e.getActionCommand();
1002        // Do ScreenShot w/o busy
1003
if (cmd.equals("ScreenShot"))
1004        {
1005            AEnv.actionPerformed (e.getActionCommand(), m_curWindowNo, this);
1006            return;
1007        }
1008
1009        // Problem: doubleClick detection - can't disable button as clicking button may change button status
1010
setBusy (true);
1011        // Command Buttons
1012
if (e.getSource() instanceof VButton)
1013        {
1014            actionButton((VButton)e.getSource());
1015            setBusy(false);
1016            return;
1017        }
1018
1019        try
1020        {
1021            // File
1022
if (cmd.equals(aReport.getName()))
1023                cmd_report(e.getSource());
1024            else if (cmd.equals(aPrint.getName()))
1025                cmd_print(e.getSource());
1026            else if (cmd.equals(aEnd.getName()))
1027                cmd_end(false);
1028            else if (cmd.equals(aExit.getName()))
1029                cmd_end(true);
1030            // Edit
1031
else if (cmd.equals(aNew.getName()))
1032                cmd_new(false);
1033            else if (cmd.equals(aSave.getName()))
1034                cmd_save(true);
1035            else if (cmd.equals(aCopy.getName()))
1036                cmd_new(true);
1037            else if (cmd.equals(aDelete.getName()))
1038                cmd_delete();
1039            else if (cmd.equals(aIgnore.getName()))
1040                cmd_ignore();
1041            else if (cmd.equals(aRefresh.getName()))
1042                cmd_refresh();
1043            else if (cmd.equals(aFind.getName()))
1044                cmd_find();
1045            else if (m_isPersonalLock && cmd.equals(aLock.getName()))
1046                cmd_lock();
1047            // View
1048
else if (cmd.equals(aAttachment.getName()))
1049                cmd_attachment();
1050            else if (cmd.equals(aHistory.getName()))
1051                cmd_history();
1052            else if (cmd.equals(aMulti.getName()))
1053                m_curGC.switchRowPresentation();
1054            // Go
1055
else if (cmd.equals(aFirst.getName()))
1056                {/*cmd_save(false);*/ m_curTab.navigate(0);}
1057            else if (cmd.equals(aPrevious.getName()))
1058                {/*cmd_save(false);*/ m_curTab.navigateRelative(-1);}
1059            else if (cmd.equals(aNext.getName()))
1060                {/*cmd_save(false); */ m_curTab.navigateRelative(+1);}
1061            else if (cmd.equals(aLast.getName()))
1062                {/*cmd_save(false);*/ m_curTab.navigate(m_curTab.getRowCount()-1);}
1063            else if (cmd.equals(aParent.getName()))
1064                cmd_parent();
1065            else if (cmd.equals(aDetail.getName()))
1066                cmd_detail();
1067            // Help
1068
else if (cmd.equals(aHelp.getName()))
1069                cmd_help();
1070            // General Commands (Environment)
1071
else if (!AEnv.actionPerformed (e.getActionCommand(), m_curWindowNo, this))
1072                Log.error("APanel.actionPerformed - No action for: " + cmd);
1073        }
1074        catch (Exception JavaDoc ex)
1075        {
1076            Log.error("APanel.actionPerformed", ex);
1077            String JavaDoc msg = ex.getMessage();
1078            if (msg == null || msg.length() == 0)
1079                msg = ex.toString();
1080            msg = Msg.parseTranslation(m_ctx, msg);
1081            ADialog.error(m_curWindowNo, this, "Error", msg);
1082        }
1083        //
1084
m_curWinTab.requestFocusInWindow();
1085        setBusy(false);
1086    } // actionPerformed
1087

1088    /**
1089     * Create New Record
1090     * @param copy true if current record is to be copied
1091     */

1092    private void cmd_new (boolean copy)
1093    {
1094        Log.trace(Log.l3_Util, "APanel.cmd_new - copy=" + copy);
1095        cmd_save(false);
1096        m_curTab.dataNew (copy);
1097        m_curGC.dynamicDisplay(0);
1098    // m_curTab.getTableModel().setChanged(false);
1099
} // cmd_new
1100

1101    /**
1102     * Confirm & delete record
1103     */

1104    private void cmd_delete()
1105    {
1106        if (m_curTab.isReadOnly())
1107            return;
1108        int keyID = m_curTab.getCurrentKeyID();
1109        if (ADialog.ask(m_curWindowNo, this, "DeleteRecord?"))
1110            if (m_curTab.dataDelete())
1111                m_curGC.rowChanged(false, keyID);
1112        m_curGC.dynamicDisplay(0);
1113    } // cmd_delete
1114

1115    /**
1116     * If required ask if you want to save and save it
1117     * @param manualCmd true if invoked manually (i.e. force)
1118     * @return true if saved
1119     */

1120    private boolean cmd_save (boolean manualCmd)
1121    {
1122        if (m_curAPanelTab != null)
1123            manualCmd = false;
1124        Log.trace(Log.l3_Util, "APanel.cmd_save - Manual=" + manualCmd);
1125        m_errorDisplayed = false;
1126        m_curGC.stopEditor(true);
1127        boolean saveOK = true;
1128
1129        if (m_curAPanelTab != null)
1130        {
1131            m_curAPanelTab.saveData();
1132            aSave.setEnabled(false); // set explicitly
1133
}
1134
1135        if (m_curTab.getCommitWarning().length() > 0 && m_curTab.needSave(true, false))
1136            if (!ADialog.ask(m_curWindowNo, this, "SaveChanges?", m_curTab.getCommitWarning()))
1137                return false;
1138
1139        // manually initiated
1140
boolean retValue = m_curTab.dataSave(manualCmd);
1141        // if there is no previous error
1142
if (manualCmd && !retValue && !m_errorDisplayed)
1143        {
1144            ADialog.error(m_curWindowNo, this, "SaveIgnored");
1145            setStatusLine(Msg.getMsg(m_ctx, "SaveIgnored"), true);
1146        }
1147        m_curGC.rowChanged(true, m_curTab.getCurrentKeyID());
1148        if (manualCmd)
1149            m_curGC.dynamicDisplay(0);
1150        return retValue;
1151    } // cmd_save
1152

1153    /**
1154     * Ignore
1155     */

1156    private void cmd_ignore()
1157    {
1158        m_curGC.stopEditor(false);
1159        m_curTab.dataIgnore();
1160        m_curGC.dynamicDisplay(0);
1161    } // cmd_ignore
1162

1163    /**
1164     * Refresh
1165     */

1166    private void cmd_refresh()
1167    {
1168        cmd_save(false);
1169        m_curTab.dataRefreshAll();
1170        m_curGC.dynamicDisplay(0);
1171    } // cmd_refresh
1172

1173    /**
1174     * Print standard Report
1175     * @param source event source
1176     */

1177    private void cmd_report (Object JavaDoc source)
1178    {
1179        Log.trace(Log.l1_User, "APanel.cmd_report");
1180        if (!MRole.getDefault().isCanReport(m_curTab.getAD_Table_ID()))
1181        {
1182            ADialog.error(m_curWindowNo, this, "AccessCannotReport");
1183            return;
1184        }
1185        
1186        cmd_save(false);
1187
1188        // Query
1189
MQuery query = new MQuery(m_curTab.getTableName());
1190        // Link for detail records
1191
String JavaDoc link = m_curTab.getLinkColumnName();
1192        // Current row otherwise
1193
if (link.length() == 0)
1194            link = m_curTab.getKeyColumnName();
1195        // Find display
1196
String JavaDoc infoName = null;
1197        String JavaDoc infoDisplay = null;
1198        for (int i = 0; i < m_curTab.getFieldCount(); i++)
1199        {
1200            MField field = m_curTab.getField(i);
1201            if (field.isKey())
1202                infoName = field.getHeader();
1203            if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo") )
1204                && field.getValue() != null)
1205                infoDisplay = field.getValue().toString();
1206            if (infoName != null && infoDisplay != null)
1207                break;
1208        }
1209        if (link.length() != 0)
1210        {
1211            if (link.endsWith("_ID"))
1212                query.addRestriction(link, MQuery.EQUAL,
1213                    new Integer JavaDoc(Env.getContextAsInt(m_ctx, m_curWindowNo, link)),
1214                    infoName, infoDisplay);
1215            else
1216                query.addRestriction(link, MQuery.EQUAL,
1217                    Env.getContext(m_ctx, m_curWindowNo, link),
1218                    infoName, infoDisplay);
1219        }
1220
1221// try
1222
{
1223            new AReport (m_curTab.getAD_Table_ID(), (JComponent)source, query);
1224        }
1225// catch (Exception e)
1226
{
1227// ADialog.error(m_curWindowNo, this, e.getMessage());
1228
}
1229    } // cmd_report
1230

1231    /**
1232     * Print specific Report - or start default Report
1233     * @param source event source
1234     */

1235    private void cmd_print(Object JavaDoc source)
1236    {
1237        // Get process defined for this tab
1238
int AD_Process_ID = m_curTab.getAD_Process_ID();
1239        Log.trace(Log.l1_User, "APanel.cmd_print - " + AD_Process_ID);
1240
1241        // No report defined
1242
if (AD_Process_ID == 0)
1243        {
1244            cmd_report(source);
1245            return;
1246        }
1247
1248        cmd_save(false);
1249        //
1250
int recordID = m_curTab.getCurrentKeyID();
1251        ProcessInfo pi = new ProcessInfo (getTitle(), AD_Process_ID, recordID);
1252
1253        ProcessCtl.process(this, m_curWindowNo, pi); // calls lockUI, unlockUI
1254
} // cmd_print
1255

1256    /**
1257     * Find - Set Query
1258     */

1259    private void cmd_find()
1260    {
1261        if (m_curTab == null)
1262            return;
1263        cmd_save(false);
1264        //
1265
Find find = new Find(Env.getFrame(this), m_curWindowNo, m_curTab);
1266        MQuery query = find.getQuery();
1267        find = null;
1268        // Confirmed query
1269
if (query != null)
1270        {
1271            m_onlyCurrentRows = false; // search history too
1272
m_curTab.setQuery(query);
1273            m_curGC.query(m_onlyCurrentRows, m_onlyCurrentDays); // autoSize
1274
}
1275        aFind.setPressed(m_curTab.isQueryActive());
1276    } // cmd_find
1277

1278    /**
1279     * Attachment
1280     */

1281    private void cmd_attachment()
1282    {
1283        Log.trace(Log.l1_User, "APanel.cmd_attachment");
1284        int record_ID = m_curTab.getCurrentKeyID();
1285        if (record_ID == -1) // No Key
1286
{
1287            aAttachment.setEnabled(false);
1288            return;
1289        }
1290
1291        Attachment va = new Attachment (Env.getFrame(this), m_curWindowNo,
1292            m_curTab.getAD_AttachmentID(), m_curTab.getAD_Table_ID(), record_ID);
1293        va.setVisible(true);
1294        //
1295
m_curTab.loadAttachments(); // reload
1296
aAttachment.setPressed(m_curTab.hasAttachment());
1297    } // attachment
1298

1299    /**
1300     * Lock
1301     */

1302    private void cmd_lock()
1303    {
1304        Log.trace(Log.l1_User, "APanel.cmd_lock - " + m_lastModifiers);
1305        if (!m_isPersonalLock)
1306            return;
1307        int record_ID = m_curTab.getCurrentKeyID();
1308        if (record_ID == -1) // No Key
1309
return;
1310        // Control Pressed
1311
if ((m_lastModifiers & InputEvent.CTRL_MASK) != 0)
1312        {
1313            new RecordAccessDialog(Env.getFrame(this), m_curTab.getAD_Table_ID(), record_ID);
1314        }
1315        else
1316        {
1317            m_curTab.lock (Env.getCtx(), record_ID, aLock.getButton().isSelected());
1318            m_curTab.loadAttachments(); // reload
1319
}
1320        aLock.setPressed(m_curTab.isLocked());
1321    } // lock
1322

1323    /**
1324     * Toggle History
1325     */

1326    private void cmd_history()
1327    {
1328        Log.trace(Log.l1_User, "APanel.cmd_history");
1329        if (m_mWorkbench.getMWindow(getWindowIndex()).isTransaction())
1330        {
1331            if (m_curTab.needSave(true, true) && !cmd_save(false))
1332                return;
1333
1334            Point pt = new Point (0, aHistory.getButton().getBounds().height);
1335            SwingUtilities.convertPointToScreen(pt, aHistory.getButton());
1336            VOnlyCurrentDays ocd = new VOnlyCurrentDays(Env.getFrame(this), pt);
1337            m_onlyCurrentDays = ocd.getCurrentDays();
1338            if (m_onlyCurrentDays == -1) // all
1339
{
1340                m_onlyCurrentRows = false;
1341                m_onlyCurrentDays = 1;
1342            }
1343            else
1344                m_onlyCurrentRows = true;
1345            Log.trace(Log.l4_Data, "APanel.cmd_history OnlyCurrent=" + m_onlyCurrentRows + ", Days=" + m_onlyCurrentDays);
1346            m_curGC.query(m_onlyCurrentRows, m_onlyCurrentDays); // autoSize
1347
}
1348    } // cmd_history
1349

1350    /**
1351     * Help
1352     */

1353    private void cmd_help()
1354    {
1355        Log.trace(Log.l1_User, "CWindow.cmd_help");
1356        Help hlp = new Help (Env.getFrame(this), this.getTitle(), m_mWorkbench.getMWindow(getWindowIndex()));
1357        hlp.show();
1358    } // cmd_help
1359

1360    /**
1361     * Close this screen - after save
1362     * @param exit ask if user wants to exit application
1363     */

1364    private void cmd_end (boolean exit)
1365    {
1366        boolean exitSystem = false;
1367        cmd_save(false);
1368        if (m_curAPanelTab != null)
1369        {
1370            m_curAPanelTab.unregisterPanel();
1371            m_curAPanelTab = null;
1372        }
1373
1374        if (exit && ADialog.ask(m_curWindowNo, this, "ExitApplication?"))
1375            exitSystem = true;
1376
1377        Env.getFrame(this).dispose(); // calls this dispose
1378

1379        if (exitSystem)
1380            AEnv.exit(0);
1381    } // cmd_end
1382

1383    /*************************************************************************/
1384
1385    /**
1386     * Start Button Process
1387     * @param vButton button
1388     */

1389    private void actionButton (VButton vButton)
1390    {
1391        Log.trace(Log.l1_User, "APanel.actionButton", vButton.toString());
1392
1393        boolean startWOasking = false;
1394        String JavaDoc col = vButton.getColumnName();
1395
1396        // Zoom
1397
if (col.equals("Record_ID"))
1398        {
1399            int AD_Table_ID = Env.getContextAsInt (m_ctx, m_curWindowNo, "AD_Table_ID");
1400            int Record_ID = Env.getContextAsInt (m_ctx, m_curWindowNo, "Record_ID");
1401            boolean IsSOTrx = !"N".equals(Env.getContext(m_ctx, m_curWindowNo, "IsSOTrx"));
1402            //
1403
String JavaDoc TableName = null;
1404            int AD_Window_ID = 0;
1405            String JavaDoc sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE AD_Table_ID=?";
1406            try
1407            {
1408                PreparedStatement pstmt = DB.prepareStatement(sql);
1409                pstmt.setInt(1, AD_Table_ID);
1410                ResultSet rs = pstmt.executeQuery();
1411                if (rs.next())
1412                {
1413                    TableName = rs.getString(1);
1414                    AD_Window_ID = rs.getInt(2);
1415                    if (!IsSOTrx && rs.getInt(3) != 0) // Point to PO Window
1416
AD_Window_ID = rs.getInt(3);
1417                }
1418                rs.close();
1419                pstmt.close();
1420            }
1421            catch (SQLException e)
1422            {
1423                Log.error ("GridController.startProcess-Zoom", e);
1424            }
1425            // Nothing to Zoom to
1426
if (TableName == null || AD_Window_ID == 0)
1427                return;
1428
1429            Log.trace(Log.l1_User, "Zoom to - " + TableName
1430                + " - Record_ID=" + Record_ID + " (IsSOTrx=" + IsSOTrx + ")");
1431            AWindow frame = new AWindow();
1432            if (!frame.initWindow(AD_Window_ID, MQuery.getEqualQuery(TableName + "_ID", Record_ID), IsSOTrx))
1433                return;
1434            AEnv.showCenterScreen(frame);
1435            frame = null;
1436            return;
1437        } // Zoom
1438

1439        // save first ---------------
1440
if (m_curTab.needSave(true, false))
1441            if (!cmd_save(true))
1442                return;
1443        //
1444
int record_ID = m_curTab.getCurrentKeyID();
1445        if (record_ID == -1 && m_curTab.getKeyColumnName().endsWith("_ID"))
1446        {
1447            ADialog.error(m_curWindowNo, this, "SaveErrorRowNotFound");
1448            return;
1449        }
1450
1451        // Pop up Payment Rules
1452
if (col.equals("PaymentRule"))
1453        {
1454            VPayment vp = new VPayment(m_curWindowNo, m_curTab, vButton);
1455            if (vp.isInitOK()) // may not be allowed
1456
vp.show();
1457            vp.dispose();
1458        } // PaymentRule
1459

1460        // Pop up Document Action
1461
else if (col.equals("DocAction"))
1462        {
1463            VDocAction vda = new VDocAction(m_curWindowNo, m_curTab, vButton);
1464            // Something to select from?
1465
if (vda.getNumberOfOptions() == 0)
1466            {
1467                vda.dispose ();
1468                return;
1469            }
1470            else
1471            {
1472                vda.show();
1473                if (!vda.getStartProcess())
1474                    return;
1475                startWOasking = true;
1476                vda.dispose();
1477            }
1478        } // DocAction
1479

1480        // Pop up Create From
1481
else if (col.equals("CreateFrom"))
1482        {
1483            // m_curWindowNo
1484
VCreateFrom vcf = VCreateFrom.create (m_curTab);
1485            if (vcf != null)
1486            {
1487                if (vcf.isInitOK())
1488                {
1489                    vcf.show();
1490                    vcf.dispose();
1491                    m_curTab.dataRefresh();
1492                }
1493                else
1494                    vcf.dispose();
1495                return;
1496            }
1497            // else may start process
1498
} // CreateFrom
1499

1500        // Posting -----
1501
else if (col.equals("Posted") && MRole.getDefault().isShowAcct())
1502        {
1503            // Check Doc Status
1504
String JavaDoc processed = Env.getContext(m_ctx, m_curWindowNo, "Processed");
1505            if (!processed.equals("Y"))
1506            {
1507                ADialog.error(m_curWindowNo, this, "PostDocNotComplete");
1508                return;
1509            }
1510
1511            // Check Post Status
1512
Object JavaDoc ps = m_curTab.getValue("Posted");
1513            if (ps != null && ps.equals("Y"))
1514            {
1515                new org.compiere.acct.AcctViewer (Env.getContextAsInt (m_ctx, m_curWindowNo, "AD_Client_ID"),
1516                    m_curTab.getAD_Table_ID(), m_curTab.getCurrentKeyID());
1517            }
1518            else
1519            {
1520                if (ADialog.ask(m_curWindowNo, this, "PostImmediate?"))
1521                {
1522                    AEnv.postImmediate (m_curWindowNo, Env.getContextAsInt (m_ctx, m_curWindowNo, "AD_Client_ID"),
1523                        m_curTab.getAD_Table_ID(), m_curTab.getCurrentKeyID(), true);
1524                    m_curTab.dataRefresh();
1525                }
1526            }
1527            return;
1528        } // Posted
1529

1530        /**
1531         * Start Process ----
1532         */

1533
1534        Log.trace(Log.l3_Util, "APanel.actionButton", "Process_ID=" + vButton.getProcess_ID());
1535        if (vButton.getProcess_ID() == 0)
1536            return;
1537        // Save item changed
1538
if (m_curTab.needSave(true, false))
1539            if (!cmd_save(true))
1540                return;
1541
1542        // Ask user to start process, if Description and Help is not empty
1543
if (!startWOasking && !(vButton.getDescription().equals("") && vButton.getHelp().equals("")))
1544            if (!ADialog.ask(m_curWindowNo, this, "StartProcess?", vButton.getDescription()
1545                + "\n" + vButton.getHelp()))
1546                return;
1547        //
1548
String JavaDoc title = vButton.getDescription();
1549        if (title == null || title.length() == 0)
1550            title = vButton.getName();
1551        ProcessInfo pi = new ProcessInfo (title, vButton.getProcess_ID(), record_ID);
1552
1553        ProcessCtl.process(this, m_curWindowNo, pi); // calls lockUI, unlockUI
1554
} // actionButton
1555

1556    /*************************************************************************/
1557
1558    /**
1559     * Lock User Interface.
1560     * Called from the Worker before processing
1561     * @param pi process info
1562     */

1563    public void lockUI (ProcessInfo pi)
1564    {
1565    // Log.trace(Log.l5_DData, "APanel.lockUI");
1566
setBusy(true);
1567    } // lockUI
1568

1569    /**
1570     * Unlock User Interface.
1571     * Called from the Worker when processing is done
1572     * @param pi of execute ASync call
1573     */

1574    public void unlockUI (ProcessInfo pi)
1575    {
1576        Log.trace(Log.l5_DData, "APanel.unlockUI");
1577        setBusy(false);
1578        // Process Result
1579
if (pi != null)
1580        {
1581            // Refresh data
1582
m_curTab.dataRefresh();
1583            m_curGC.dynamicDisplay(0);
1584            // Update Status Line
1585
setStatusLine(pi.getSummary(), pi.isError());
1586            // Get Log Info
1587
ProcessInfoUtil.setLogFromDB(pi);
1588            String JavaDoc log = pi.getLogInfo();
1589            if (log.length() > 0)
1590                ADialog.info(m_curWindowNo, this, Env.getHeader(m_ctx, m_curWindowNo),
1591                    pi.getTitle(), log); // clear text
1592
}
1593    } // unlockUI
1594

1595    /**
1596     * Is the UI locked (Internal method)
1597     * @return true, if UI is locked
1598     */

1599    public boolean isUILocked()
1600    {
1601        return m_isLocked;
1602    } // isLoacked
1603

1604    /**
1605     * Method to be executed async.
1606     * Called from the ASyncProcess worker
1607     * @param pi process info
1608     */

1609    public void executeASync (ProcessInfo pi)
1610    {
1611        Log.trace(Log.l3_Util, "APanel.executeASync");
1612    } // executeASync
1613

1614    /**
1615     * String representation
1616     * @return String representation
1617     */

1618    public String JavaDoc toString()
1619    {
1620        String JavaDoc s = "APanel[curWindowNo=" + m_curWindowNo;
1621        if (m_mWorkbench != null)
1622            s += ",WB=" + m_mWorkbench.toString();
1623        s += "]";
1624        return s;
1625    } // toString
1626

1627} // APanel
1628
Popular Tags