diff --git a/migration/i1.0a-release/oracle/201301311640_TICKET-1001569.sql b/migration/i1.0a-release/oracle/201301311640_TICKET-1001569.sql new file mode 100644 index 0000000000..d4a8b6f270 --- /dev/null +++ b/migration/i1.0a-release/oracle/201301311640_TICKET-1001569.sql @@ -0,0 +1,42 @@ +-- Jan 30, 2013 3:35:24 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +INSERT INTO AD_Form (Name,AccessLevel,Classname,AD_Form_ID,IsBetaFunctionality,EntityType,AD_Form_UU,AD_Org_ID,UpdatedBy,CreatedBy,Updated,Created,AD_Client_ID,IsActive) VALUES ('VCreateFromBatchStatementUI','3','org.compiere.apps.form.VCreateFromBatchStatementUI',200006,'N','D','f7ea6003-2e6b-4873-9e0b-a8c18ec2ee6d',0,100,100,TO_DATE('2013-01-30 15:35:23','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2013-01-30 15:35:23','YYYY-MM-DD HH24:MI:SS'),0,'Y') +; + +-- Jan 30, 2013 3:35:24 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +INSERT INTO AD_Form_Trl (AD_Language,AD_Form_ID, Name,Help,Description, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Form_Trl_UU ) SELECT l.AD_Language,t.AD_Form_ID, t.Name,t.Help,t.Description, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Form t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Form_ID=200006 AND NOT EXISTS (SELECT * FROM AD_Form_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Form_ID=t.AD_Form_ID) +; + +-- Jan 30, 2013 3:36:19 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +UPDATE AD_Form SET Name='Bank Statement Create From Batch',Updated=TO_DATE('2013-01-30 15:36:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Form_ID=200006 +; + +-- Jan 30, 2013 3:36:19 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +UPDATE AD_Form_Trl SET IsTranslated='N' WHERE AD_Form_ID=200006 +; + +-- Jan 30, 2013 3:37:04 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +INSERT INTO AD_Process (CopyFromProcess,AD_Process_ID,IsDirectPrint,IsReport,AD_Process_UU,AccessLevel,IsBetaFunctionality,IsServerProcess,Statistic_Seconds,Statistic_Count,ShowHelp,EntityType,AD_Form_ID,Name,Value,AD_Org_ID,AD_Client_ID,Created,Updated,UpdatedBy,IsActive,CreatedBy) VALUES ('N',200032,'N','N','986e4432-909a-4ca4-a838-0868f7d022a7','3','N','N',0,0,'Y','D',200006,'Bank Statement Create From Batch','C_BankStatement X_CreateFromBatch',0,0,TO_DATE('2013-01-30 15:37:04','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2013-01-30 15:37:04','YYYY-MM-DD HH24:MI:SS'),100,'Y',100) +; + +-- Jan 30, 2013 3:37:04 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +INSERT INTO AD_Process_Trl (AD_Language,AD_Process_ID, Help,Description,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Process_Trl_UU ) SELECT l.AD_Language,t.AD_Process_ID, t.Help,t.Description,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Process t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_ID=200032 AND NOT EXISTS (SELECT * FROM AD_Process_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Process_ID=t.AD_Process_ID) +; + +-- Jan 30, 2013 3:37:34 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +UPDATE AD_Column SET AD_Process_ID=200032,Updated=TO_DATE('2013-01-30 15:37:34','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=208442 +; + +-- Jan 30, 2013 3:59:04 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +UPDATE AD_Form SET Classname='org.compiere.apps.form.VStatementCreateFromBatch',Updated=TO_DATE('2013-01-30 15:59:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Form_ID=200006 +; + +SELECT register_migration_script('201301311640_TICKET-1001569.sql') FROM dual +; \ No newline at end of file diff --git a/migration/i1.0a-release/postgresql/201301311640_TICKET-1001569.sql b/migration/i1.0a-release/postgresql/201301311640_TICKET-1001569.sql new file mode 100644 index 0000000000..810eae97e6 --- /dev/null +++ b/migration/i1.0a-release/postgresql/201301311640_TICKET-1001569.sql @@ -0,0 +1,42 @@ +-- Jan 30, 2013 3:35:24 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +INSERT INTO AD_Form (Name,AccessLevel,Classname,AD_Form_ID,IsBetaFunctionality,EntityType,AD_Form_UU,AD_Org_ID,UpdatedBy,CreatedBy,Updated,Created,AD_Client_ID,IsActive) VALUES ('VCreateFromBatchStatementUI','3','org.compiere.apps.form.VCreateFromBatchStatementUI',200006,'N','D','f7ea6003-2e6b-4873-9e0b-a8c18ec2ee6d',0,100,100,TO_TIMESTAMP('2013-01-30 15:35:23','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2013-01-30 15:35:23','YYYY-MM-DD HH24:MI:SS'),0,'Y') +; + +-- Jan 30, 2013 3:35:24 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +INSERT INTO AD_Form_Trl (AD_Language,AD_Form_ID, Name,Help,Description, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Form_Trl_UU ) SELECT l.AD_Language,t.AD_Form_ID, t.Name,t.Help,t.Description, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Form t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Form_ID=200006 AND NOT EXISTS (SELECT * FROM AD_Form_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Form_ID=t.AD_Form_ID) +; + +-- Jan 30, 2013 3:36:19 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +UPDATE AD_Form SET Name='Bank Statement Create From Batch',Updated=TO_TIMESTAMP('2013-01-30 15:36:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Form_ID=200006 +; + +-- Jan 30, 2013 3:36:19 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +UPDATE AD_Form_Trl SET IsTranslated='N' WHERE AD_Form_ID=200006 +; + +-- Jan 30, 2013 3:37:04 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +INSERT INTO AD_Process (CopyFromProcess,AD_Process_ID,IsDirectPrint,IsReport,AD_Process_UU,AccessLevel,IsBetaFunctionality,IsServerProcess,Statistic_Seconds,Statistic_Count,ShowHelp,EntityType,AD_Form_ID,Name,Value,AD_Org_ID,AD_Client_ID,Created,Updated,UpdatedBy,IsActive,CreatedBy) VALUES ('N',200032,'N','N','986e4432-909a-4ca4-a838-0868f7d022a7','3','N','N',0,0,'Y','D',200006,'Bank Statement Create From Batch','C_BankStatement X_CreateFromBatch',0,0,TO_TIMESTAMP('2013-01-30 15:37:04','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2013-01-30 15:37:04','YYYY-MM-DD HH24:MI:SS'),100,'Y',100) +; + +-- Jan 30, 2013 3:37:04 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +INSERT INTO AD_Process_Trl (AD_Language,AD_Process_ID, Help,Description,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Process_Trl_UU ) SELECT l.AD_Language,t.AD_Process_ID, t.Help,t.Description,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Process t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_ID=200032 AND NOT EXISTS (SELECT * FROM AD_Process_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Process_ID=t.AD_Process_ID) +; + +-- Jan 30, 2013 3:37:34 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +UPDATE AD_Column SET AD_Process_ID=200032,Updated=TO_TIMESTAMP('2013-01-30 15:37:34','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=208442 +; + +-- Jan 30, 2013 3:59:04 PM SGT +-- Ticket #1001569: Move receipts into batch from QS to Idempiere +UPDATE AD_Form SET Classname='org.compiere.apps.form.VStatementCreateFromBatch',Updated=TO_TIMESTAMP('2013-01-30 15:59:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Form_ID=200006 +; + +SELECT register_migration_script('201301311640_TICKET-1001569.sql') FROM dual +; \ No newline at end of file diff --git a/org.adempiere.base.process/src/org/compiere/process/InOutCreateConfirm.java b/org.adempiere.base.process/src/org/compiere/process/InOutCreateConfirm.java index f7d11ec0ff..a56d35632e 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InOutCreateConfirm.java +++ b/org.adempiere.base.process/src/org/compiere/process/InOutCreateConfirm.java @@ -70,6 +70,9 @@ public class InOutCreateConfirm extends SvrProcess if (confirm == null) throw new Exception ("Cannot create Confirmation for " + shipment.getDocumentNo()); // + + addLog(confirm.getM_InOutConfirm_ID(), null, null, confirm.getDocumentNo(), confirm.get_Table_ID(), confirm.getM_InOutConfirm_ID()); + return confirm.getDocumentNo(); } // doIt diff --git a/org.adempiere.base.process/src/org/compiere/process/InOutCreateInvoice.java b/org.adempiere.base.process/src/org/compiere/process/InOutCreateInvoice.java index 36e725e84e..4a9c781e51 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InOutCreateInvoice.java +++ b/org.adempiere.base.process/src/org/compiere/process/InOutCreateInvoice.java @@ -146,6 +146,8 @@ public class InOutCreateInvoice extends SvrProcess invoice.saveEx(); } + addLog(invoice.getC_Invoice_ID(), invoice.getDateInvoiced(), invoice.getGrandTotal(), invoice.getDocumentNo(), invoice.get_Table_ID(), invoice.getC_Invoice_ID()); + return invoice.getDocumentNo(); } // InOutCreateInvoice diff --git a/org.adempiere.base.process/src/org/compiere/process/InvoiceCreateInOut.java b/org.adempiere.base.process/src/org/compiere/process/InvoiceCreateInOut.java index efb0cd8f0c..51b33ac208 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InvoiceCreateInOut.java +++ b/org.adempiere.base.process/src/org/compiere/process/InvoiceCreateInOut.java @@ -92,6 +92,8 @@ public class InvoiceCreateInOut extends SvrProcess } if (m_inout == null) throw new InvoiceFullyMatchedException(); + + addLog(m_inout.getM_InOut_ID(), m_inout.getMovementDate(), null, m_inout.getDocumentNo(), m_inout.get_Table_ID(), m_inout.getM_InOut_ID()); // return m_inout.getDocumentNo(); } // doIt diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java b/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java index 50a0885c8c..610f9f14ec 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java @@ -2549,12 +2549,12 @@ public final class APanel extends CPanel } // DocAction // Pop up Create From - else if (col.equals("CreateFrom") || col.equals("X_CreateFromBatch")) + else if (col.equals("CreateFrom")) { // Run form only if the button has no process defined - teo_sarca [ 1974354 ] if (vButton.getProcess_ID() <= 0) { - ICreateFrom cf = VCreateFromFactory.create(m_curTab, col); + ICreateFrom cf = VCreateFromFactory.create(m_curTab); if(cf != null) { if(cf.isInitOK()) @@ -2660,7 +2660,7 @@ public final class APanel extends CPanel pi.setAD_User_ID (Env.getAD_User_ID(m_ctx)); pi.setAD_Client_ID (Env.getAD_Client_ID(m_ctx)); ff.setProcessInfo(pi); - ff.openForm(form_ID); + ff.openForm(form_ID, m_curTab); ff.pack(); AEnv.showCenterScreen(ff); return; diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/form/FormFrame.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/FormFrame.java index 477a391026..eadbaadadf 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/form/FormFrame.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/FormFrame.java @@ -39,6 +39,7 @@ import org.compiere.apps.AGlassPane; import org.compiere.apps.AMenu; import org.compiere.apps.Help; import org.compiere.apps.WindowMenu; +import org.compiere.model.GridTab; import org.compiere.model.MRole; import org.compiere.model.MUser; import org.compiere.process.ProcessInfo; @@ -251,6 +252,11 @@ public class FormFrame extends CFrame * @return true if form opened */ public boolean openForm (int AD_Form_ID) + { + return openForm(AD_Form_ID, null); + } + + public boolean openForm (int AD_Form_ID, GridTab gridTab) { Properties ctx = Env.getCtx(); // @@ -296,7 +302,7 @@ public class FormFrame extends CFrame if (className == null) return false; // - return openForm(AD_Form_ID, className, name); + return openForm(AD_Form_ID, className, name, gridTab); } // openForm /** @@ -307,11 +313,17 @@ public class FormFrame extends CFrame * @return true if started */ protected boolean openForm (int AD_Form_ID, String className, String name) + { + return openForm(AD_Form_ID, className, name, null); + } + + protected boolean openForm (int AD_Form_ID, String className, String name, GridTab gridTab) { log.info("AD_Form_ID=" + AD_Form_ID + " - Class=" + className); Properties ctx = Env.getCtx(); Env.setContext(ctx, m_WindowNo, "WindowName", name); setTitle(Env.getHeader(ctx, m_WindowNo)); + this.gridTab = gridTab; try { @@ -481,5 +493,11 @@ public class FormFrame extends CFrame { return menuBar; } - + + private GridTab gridTab; + + public GridTab getGridTab() + { + return gridTab; + } } // FormFrame diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/form/VCreateFromForm.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/VCreateFromForm.java new file mode 100644 index 0000000000..426c54e778 --- /dev/null +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VCreateFromForm.java @@ -0,0 +1,237 @@ +/****************************************************************************** + * Copyright (C) 2013 Elaine Tan * + * Copyright (C) 2013 Trek Global + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.compiere.apps.form; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JScrollPane; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.table.TableModel; + +import org.compiere.apps.ADialog; +import org.compiere.apps.AppsAction; +import org.compiere.apps.ConfirmPanel; +import org.compiere.apps.StatusBar; +import org.compiere.minigrid.MiniTable; +import org.compiere.swing.CPanel; +import org.compiere.swing.CToggleButton; +import org.compiere.util.Env; +import org.compiere.util.Msg; +import org.compiere.util.Trx; +import org.compiere.util.TrxRunnable; + +/** + * + * @author Elaine + * + */ +public class VCreateFromForm extends CPanel implements ActionListener, TableModelListener +{ + + /** + * + */ + private static final long serialVersionUID = -8242250391030501785L; + private CreateFromForm form; + private int windowNo; + /** FormFrame */ + private FormFrame m_frame; + + private CPanel parameterPanel = new CPanel(); + private ConfirmPanel confirmPanel = new ConfirmPanel(true); + private StatusBar statusBar = new StatusBar(); + private MiniTable dataTable = new MiniTable(); + + private static final String SELECT_DESELECT_ALL = "SelectAll"; + protected AppsAction selectDeselectAllAction = new AppsAction (SELECT_DESELECT_ALL, null, Msg.getMsg(Env.getCtx(), SELECT_DESELECT_ALL), true); + + public VCreateFromForm(CreateFromForm createFrom, FormFrame frame) + { + super(); + this.form = createFrom; + this.m_frame = frame; + + try + { + jbInit(); + confirmPanel.addActionListener(this); + + statusBar.setStatusDB(""); + tableChanged(null); + } + catch(Exception e) + { + + } + } + + protected void jbInit() throws Exception + { + m_frame.getContentPane().add(parameterPanel, BorderLayout.NORTH); + + JScrollPane dataPane = new JScrollPane(); + m_frame.getContentPane().add(dataPane, BorderLayout.CENTER); + dataPane.getViewport().add(dataTable, null); + + CToggleButton selectAllButton = (CToggleButton)selectDeselectAllAction.getButton(); + selectAllButton.setMargin(ConfirmPanel.s_insets); + selectAllButton.addActionListener(this); + confirmPanel.addComponent(selectAllButton); + + CPanel southPanel = new CPanel(); + m_frame.getContentPane().add(southPanel, BorderLayout.SOUTH); + BorderLayout southLayout = new BorderLayout(); + southPanel.setLayout(southLayout); + southPanel.add(confirmPanel, BorderLayout.CENTER); + southPanel.add(statusBar, BorderLayout.SOUTH); + } + + public void actionPerformed(ActionEvent e) + { + if (e.getActionCommand().equals(ConfirmPanel.A_OK)) + { + try + { + Trx.run(new TrxRunnable() + { + public void run(String trxName) + { + if (save(trxName)) + { + dispose(); + } + } + }); + } + catch (Exception ex) + { + ADialog.error(windowNo, this, "Error", ex.getLocalizedMessage()); + } + } + // Cancel + else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) + { + dispose(); + } + // Select All + // Trifon + else if (e.getActionCommand().equals(SELECT_DESELECT_ALL)) + { + TableModel model = dataTable.getModel(); + model.removeTableModelListener(this); + + // select or deselect all as required + int rows = model.getRowCount(); + Boolean selectAll = selectDeselectAllAction.isPressed() ? Boolean.FALSE : Boolean.TRUE; + for (int i = 0; i < rows; i++) + model.setValueAt(selectAll, i, 0); + + model.addTableModelListener(this); + + info(); + } + } + + public boolean save(String trxName) + { + dataTable.stopEditor(true); + + TableModel model = dataTable.getModel(); + int rows = model.getRowCount(); + if (rows == 0) + return false; + + return form.save(dataTable, trxName, m_frame.getGridTab()); + } + + public void tableChanged (TableModelEvent e) + { + int type = -1; + if (e != null) + { + type = e.getType(); + if (type != TableModelEvent.UPDATE) + return; + + if (e.getColumn() == 0) + { + TableModel model = dataTable.getModel(); + Boolean isPressed = (Boolean)model.getValueAt(0, 0); + int rows = model.getRowCount(); + boolean equals = true; + for (int i = 1; equals && i < rows; i++) + { + equals = isPressed.equals(model.getValueAt(i, 0)); + } + + if (equals) { + selectDeselectAllAction.setPressed(isPressed); + } + } + } + info(); + dataTable.repaint(); + } + + public void info() + { + TableModel model = dataTable.getModel(); + int rows = model.getRowCount(); + int count = 0; + for (int i = 0; i < rows; i++) + { + if (((Boolean)model.getValueAt(i, 0)).booleanValue()) + count++; + } + setStatusLine(count, null); + + form.info(dataTable, statusBar); + } + + public void setStatusLine(int selectedRowCount, String text) + { + StringBuilder sb = new StringBuilder(String.valueOf(selectedRowCount)); + if (text != null && text.trim().length() > 0) { + sb.append(" - ").append(text); + } + statusBar.setStatusLine(sb.toString()); + // + confirmPanel.getOKButton().setEnabled(selectedRowCount > 0); + } + + public MiniTable getMiniTable() + { + return dataTable; + } + + public CPanel getParameterPanel() + { + return parameterPanel; + } + + public ConfirmPanel getConfirmPanel() + { + return confirmPanel; + } + + public void dispose() + { + if (m_frame != null) + m_frame.dispose(); + m_frame = null; + } +} \ No newline at end of file diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromStatementBatchUI.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/VStatementCreateFromBatch.java similarity index 87% rename from org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromStatementBatchUI.java rename to org.adempiere.ui.swing/src/org/compiere/apps/form/VStatementCreateFromBatch.java index 2cc5871c20..d16c920cab 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromStatementBatchUI.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VStatementCreateFromBatch.java @@ -11,7 +11,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * *****************************************************************************/ -package org.compiere.grid; +package org.compiere.apps.form; import static org.compiere.model.SystemIDs.COLUMN_C_BANKSTATEMENT_C_BANKACCOUNT_ID; @@ -30,13 +30,11 @@ import javax.swing.JLabel; import javax.swing.table.DefaultTableModel; import org.compiere.apps.ADialog; -import org.compiere.apps.AEnv; import org.compiere.apps.ConfirmPanel; import org.compiere.grid.ed.VDate; import org.compiere.grid.ed.VLookup; import org.compiere.grid.ed.VNumber; import org.compiere.grid.ed.VString; -import org.compiere.model.GridTab; import org.compiere.model.MBankStatement; import org.compiere.model.MColumn; import org.compiere.model.MLookup; @@ -56,41 +54,40 @@ import org.compiere.util.Msg; * @author Elaine * */ -public class VCreateFromStatementBatchUI extends CreateFromStatementBatch implements ActionListener +public class VStatementCreateFromBatch extends StatementCreateFromBatch implements ActionListener, FormPanel { - private VCreateFromDialog dialog; - - public VCreateFromStatementBatchUI(GridTab mTab) + private VCreateFromForm form; + private FormFrame m_frame; + + public void init (int WindowNo, FormFrame frame) { - super(mTab); - log.info(getGridTab().toString()); - - dialog = new VCreateFromDialog(this, getGridTab().getWindowNo(), true); - - p_WindowNo = getGridTab().getWindowNo(); - + form = new VCreateFromForm(this, frame); + p_WindowNo = WindowNo; + m_frame = frame; + initForm(); + } + + @Override + public void initForm() + { try { if (!dynInit()) return; jbInit(); - - setInitOK(true); } catch(Exception e) { - log.log(Level.SEVERE, "", e); - setInitOK(false); + log.log(Level.SEVERE, "init", e); } - AEnv.positionCenterWindow(AEnv.getWindow(p_WindowNo), dialog); - } // VCreateFrom + } /** Window No */ private int p_WindowNo; /** Logger */ private CLogger log = CLogger.getCLogger(getClass()); - + private JLabel bankAccountLabel = new JLabel(); protected VLookup bankAccountField; @@ -127,25 +124,25 @@ public class VCreateFromStatementBatchUI extends CreateFromStatementBatch implem */ public boolean dynInit() throws Exception { - log.config(""); - super.dynInit(); + log.config(""); + //Refresh button CButton refreshButton = ConfirmPanel.createRefreshButton(false); refreshButton.setMargin(new Insets (1, 10, 0, 10)); refreshButton.setDefaultCapable(true); refreshButton.addActionListener(this); - dialog.getConfirmPanel().addButton(refreshButton); - dialog.getRootPane().setDefaultButton(refreshButton); + form.getConfirmPanel().addButton(refreshButton); +// form.getRootPane().setDefaultButton(refreshButton); - if (getGridTab().getValue("C_BankStatement_ID") == null) + if (m_frame.getGridTab() != null && m_frame.getGridTab().getValue("C_BankStatement_ID") == null) { - ADialog.error(0, dialog, "SaveErrorRowNotFound"); + ADialog.error(0, form, "SaveErrorRowNotFound"); return false; } - dialog.setTitle(getTitle()); + m_frame.setTitle(getTitle()); int AD_Column_ID = COLUMN_C_BANKSTATEMENT_C_BANKACCOUNT_ID; // C_BankStatement.C_BankAccount_ID MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir); @@ -180,7 +177,7 @@ public class VCreateFromStatementBatchUI extends CreateFromStatementBatch implem amtFromField.addActionListener(this); amtToField.addActionListener(this); - loadBankAccount(); + executeQuery(); return true; } // dynInit @@ -217,7 +214,7 @@ public class VCreateFromStatementBatchUI extends CreateFromStatementBatch implem amtToLabel.setLabelFor(amtToField); amtToField.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo")); - CPanel parameterPanel = dialog.getParameterPanel(); + CPanel parameterPanel = form.getParameterPanel(); parameterPanel.setLayout(new BorderLayout()); CPanel parameterBankPanel = new CPanel(); @@ -290,46 +287,38 @@ public class VCreateFromStatementBatchUI extends CreateFromStatementBatch implem if(e.getActionCommand().equals(ConfirmPanel.A_REFRESH)) { Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); - loadBankAccount(); - dialog.tableChanged(null); + executeQuery(); + form.tableChanged(null); Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); } } // actionPerformed - protected void loadBankAccount() + public void executeQuery() { loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), documentNoField.getText(), dateFromField.getValue(), dateToField.getValue(), amtFromField.getValue(), amtToField.getValue(), - documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getText())); + documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getText(), + m_frame.getGridTab())); } protected void loadTableOIS (Vector data) { // Remove previous listeners - dialog.getMiniTable().getModel().removeTableModelListener(dialog); + form.getMiniTable().getModel().removeTableModelListener(form); // Set Model DefaultTableModel model = new DefaultTableModel(data, getOISColumnNames()); - model.addTableModelListener(dialog); - dialog.getMiniTable().setModel(model); + model.addTableModelListener(form); + form.getMiniTable().setModel(model); // - configureMiniTable(dialog.getMiniTable()); + configureMiniTable(form.getMiniTable()); } - public void showWindow() + public void dispose() { - dialog.setVisible(true); - } - - public void closeWindow() - { - dialog.dispose(); - } - - @Override - public Object getWindow() - { - return dialog; + if (m_frame != null) + m_frame.dispose(); + m_frame = null; } } \ No newline at end of file diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/DefaultCreateFromFactory.java b/org.adempiere.ui.swing/src/org/compiere/grid/DefaultCreateFromFactory.java index c067a3e7f9..0884e327b7 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/DefaultCreateFromFactory.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/DefaultCreateFromFactory.java @@ -30,30 +30,21 @@ public class DefaultCreateFromFactory implements ICreateFromFactory { @Override - public ICreateFrom create(GridTab mTab, String columnName) + public ICreateFrom create(GridTab mTab) { String tableName = mTab.getTableName(); - if (columnName.equals("CreateFrom")) - { - if (tableName.equals(I_C_Invoice.Table_Name)) - return new VCreateFromInvoiceUI(mTab); - else if (tableName.equals(I_C_BankStatement.Table_Name)) -// return new VCreateFromStatementUI(mTab); - return new VCreateFromStatementBatchUI(mTab); - else if (tableName.equals(I_M_InOut.Table_Name)) - return new VCreateFromShipmentUI(mTab); - else if (tableName.equals(I_M_RMA.Table_Name)) - return new VCreateFromRMAUI(mTab); - else if (tableName.equals(I_M_PackageMPS.Table_Name)) - return new VCreateFromPackageShipmentUI(mTab); - else if (tableName.equals(I_X_DepositBatch.Table_Name)) - return new VCreateFromDepositBatchUI(mTab); - } - else if (columnName.equalsIgnoreCase("X_CreateFromBatch")) - { - if (tableName.equals(I_C_BankStatement.Table_Name)) - return new VCreateFromBatchStatementUI(mTab); - } + if (tableName.equals(I_C_Invoice.Table_Name)) + return new VCreateFromInvoiceUI(mTab); + else if (tableName.equals(I_C_BankStatement.Table_Name)) + return new VCreateFromStatementUI(mTab); + else if (tableName.equals(I_M_InOut.Table_Name)) + return new VCreateFromShipmentUI(mTab); + else if (tableName.equals(I_M_RMA.Table_Name)) + return new VCreateFromRMAUI(mTab); + else if (tableName.equals(I_M_PackageMPS.Table_Name)) + return new VCreateFromPackageShipmentUI(mTab); + else if (tableName.equals(I_X_DepositBatch.Table_Name)) + return new VCreateFromDepositBatchUI(mTab); return null; } diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromBatchStatementUI.java b/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromBatchStatementUI.java deleted file mode 100644 index d6b144ee78..0000000000 --- a/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromBatchStatementUI.java +++ /dev/null @@ -1,335 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2013 Elaine Tan * - * Copyright (C) 2013 Trek Global - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - *****************************************************************************/ -package org.compiere.grid; - -import static org.compiere.model.SystemIDs.COLUMN_C_BANKSTATEMENT_C_BANKACCOUNT_ID; - -import java.awt.BorderLayout; -import java.awt.Cursor; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.sql.Timestamp; -import java.util.Vector; -import java.util.logging.Level; - -import javax.swing.JLabel; -import javax.swing.table.DefaultTableModel; - -import org.compiere.apps.ADialog; -import org.compiere.apps.AEnv; -import org.compiere.apps.ConfirmPanel; -import org.compiere.grid.ed.VDate; -import org.compiere.grid.ed.VLookup; -import org.compiere.grid.ed.VNumber; -import org.compiere.grid.ed.VString; -import org.compiere.model.GridTab; -import org.compiere.model.MBankStatement; -import org.compiere.model.MColumn; -import org.compiere.model.MLookup; -import org.compiere.model.MLookupFactory; -import org.compiere.model.MPayment; -import org.compiere.swing.CButton; -import org.compiere.swing.CLabel; -import org.compiere.swing.CPanel; -import org.compiere.swing.CTextField; -import org.compiere.util.CLogger; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.Msg; - -/** - * - * @author Elaine - * - */ -public class VCreateFromBatchStatementUI extends CreateFromBatchStatement implements ActionListener -{ - private VCreateFromDialog dialog; - - public VCreateFromBatchStatementUI(GridTab mTab) - { - super(mTab); - log.info(getGridTab().toString()); - - dialog = new VCreateFromDialog(this, getGridTab().getWindowNo(), true); - - p_WindowNo = getGridTab().getWindowNo(); - - try - { - if (!dynInit()) - return; - jbInit(); - - setInitOK(true); - } - catch(Exception e) - { - log.log(Level.SEVERE, "", e); - setInitOK(false); - } - AEnv.positionCenterWindow(AEnv.getWindow(p_WindowNo), dialog); - } // VCreateFrom - - /** Window No */ - private int p_WindowNo; - - /** Logger */ - private CLogger log = CLogger.getCLogger(getClass()); - - private JLabel bankAccountLabel = new JLabel(); - protected VLookup bankAccountField; - - private CLabel documentNoLabel = new CLabel(Msg.translate(Env.getCtx(), "DocumentNo")); - protected CTextField documentNoField = new CTextField(10); - - private JLabel documentTypeLabel = new JLabel(); - protected VLookup documentTypeField; - - private JLabel authorizationLabel = new JLabel(); - protected VString authorizationField = new VString(); - - private JLabel tenderTypeLabel = new JLabel(); - protected VLookup tenderTypeField; - - private CLabel amtFromLabel = new CLabel(Msg.translate(Env.getCtx(), "PayAmt")); - protected VNumber amtFromField = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom")); - private CLabel amtToLabel = new CLabel("-"); - protected VNumber amtToField = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo")); - - protected CLabel BPartner_idLabel = new CLabel(Msg.translate(Env.getCtx(), "BPartner")); - protected VLookup bPartnerLookup; - - private CLabel dateFromLabel = new CLabel(Msg.translate(Env.getCtx(), "DateTrx")); - protected VDate dateFromField = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom")); - private CLabel dateToLabel = new CLabel("-"); - protected VDate dateToField = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo")); - - - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - public boolean dynInit() throws Exception - { - log.config(""); - - super.dynInit(); - - //Refresh button - CButton refreshButton = ConfirmPanel.createRefreshButton(false); - refreshButton.setMargin(new Insets (1, 10, 0, 10)); - refreshButton.setDefaultCapable(true); - refreshButton.addActionListener(this); - dialog.getConfirmPanel().addButton(refreshButton); - dialog.getRootPane().setDefaultButton(refreshButton); - - if (getGridTab().getValue("C_BankStatement_ID") == null) - { - ADialog.error(0, dialog, "SaveErrorRowNotFound"); - return false; - } - - dialog.setTitle(getTitle()); - - int AD_Column_ID = COLUMN_C_BANKSTATEMENT_C_BANKACCOUNT_ID; // C_BankStatement.C_BankAccount_ID - MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir); - bankAccountField = new VLookup ("C_BankAccount_ID", true, true, true, lookup); - // Set Default - int C_BankAccount_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BankAccount_ID"); - bankAccountField.setValue(new Integer(C_BankAccount_ID)); - bankAccountField.addActionListener(this); - // initial Loading - authorizationField = new VString ("authorization", false, false, true, 10, 30, null, null); - authorizationField.addActionListener(this); - - MLookup lookupDocument = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_DocType_ID), DisplayType.TableDir); - documentTypeField = new VLookup (MPayment.COLUMNNAME_C_DocType_ID,false,false,true,lookupDocument); - documentTypeField.addActionListener(this); - - MLookup lookupTender = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_TenderType), DisplayType.List); - tenderTypeField = new VLookup (MPayment.COLUMNNAME_TenderType,false,false,true,lookupTender); - tenderTypeField.addActionListener(this); - - bPartnerLookup = new VLookup("C_BPartner_ID", false, false, true, - MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search)); - BPartner_idLabel.setLabelFor(bPartnerLookup); - bPartnerLookup.addActionListener(this); - - Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate); - dateToField.setValue(date); - - documentNoField.addActionListener(this); - dateFromField.addActionListener(this); - dateToField.addActionListener(this); - amtFromField.addActionListener(this); - amtToField.addActionListener(this); - - loadBankAccount(); - - return true; - } // dynInit - - /** - * Static Init. - *
-	 *  parameterPanel
-	 *      parameterBankPanel
-	 *      parameterStdPanel
-	 *          bPartner/order/invoice/shopment/licator Label/Field
-	 *  dataPane
-	 *  southPanel
-	 *      confirmPanel
-	 *      statusBar
-	 *  
- * @throws Exception - */ - private void jbInit() throws Exception - { - bankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); - authorizationLabel.setText(Msg.translate(Env.getCtx(), "R_AuthCode")); - - documentTypeLabel.setText(Msg.translate(Env.getCtx(), "C_DocType_ID")); - tenderTypeLabel.setText(Msg.translate(Env.getCtx(), "TenderType")); - - documentNoLabel.setLabelFor(documentNoField); - dateFromLabel.setLabelFor(dateFromField); - dateFromField.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom")); - dateToLabel.setLabelFor(dateToField); - dateToField.setToolTipText(Msg.translate(Env.getCtx(), "DateTo")); - amtFromLabel.setLabelFor(amtFromField); - amtFromField.setToolTipText(Msg.translate(Env.getCtx(), "AmtFrom")); - amtToLabel.setLabelFor(amtToField); - amtToField.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo")); - - CPanel parameterPanel = dialog.getParameterPanel(); - parameterPanel.setLayout(new BorderLayout()); - - CPanel parameterBankPanel = new CPanel(); - parameterBankPanel.setLayout(new GridBagLayout()); - parameterPanel.add(parameterBankPanel, BorderLayout.CENTER); - - parameterBankPanel.add(bankAccountLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - if (bankAccountField != null) - parameterBankPanel.add(bankAccountField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(documentTypeLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - if(documentTypeField!= null) - parameterBankPanel.add(documentTypeField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(tenderTypeLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - if(tenderTypeField!=null) - parameterBankPanel.add(tenderTypeField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(BPartner_idLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(bPartnerLookup, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(documentNoLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(documentNoField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(authorizationLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(authorizationField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(amtFromLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(amtFromField, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - parameterBankPanel.add(amtToLabel, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(amtToField, new GridBagConstraints(5, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(dateFromLabel, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(dateFromField, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - parameterBankPanel.add(dateToLabel, new GridBagConstraints(4, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(dateToField, new GridBagConstraints(5, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - } // jbInit - - /*************************************************************************/ - - /** - * Action Listener - * @param e event - */ - public void actionPerformed(ActionEvent e) - { - log.config("Action=" + e.getActionCommand()); -// Object source = e.getSource(); - if(e.getActionCommand().equals(ConfirmPanel.A_REFRESH)) - { - Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); - loadBankAccount(); - dialog.tableChanged(null); - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); - } - } // actionPerformed - - protected void loadBankAccount() - { - loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), - documentNoField.getText(), dateFromField.getValue(), dateToField.getValue(), - amtFromField.getValue(), amtToField.getValue(), - documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getText())); - } - - protected void loadTableOIS (Vector data) - { - // Remove previous listeners - dialog.getMiniTable().getModel().removeTableModelListener(dialog); - // Set Model - DefaultTableModel model = new DefaultTableModel(data, getOISColumnNames()); - model.addTableModelListener(dialog); - dialog.getMiniTable().setModel(model); - // - - configureMiniTable(dialog.getMiniTable()); - } - - public void showWindow() - { - dialog.setVisible(true); - } - - public void closeWindow() - { - dialog.dispose(); - } - - @Override - public Object getWindow() - { - return dialog; - } -} \ No newline at end of file diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromFactory.java b/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromFactory.java index c2f54bc56d..2eb8f4e4f4 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromFactory.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromFactory.java @@ -20,13 +20,13 @@ import org.compiere.model.GridTab; public class VCreateFromFactory { - public static ICreateFrom create (GridTab mTab, String columnName) + public static ICreateFrom create (GridTab mTab) { ICreateFrom createFrom = null; List factories = Service.locator().list(ICreateFromFactory.class).getServices(); for (ICreateFromFactory factory : factories) { - createFrom = factory.create(mTab, columnName); + createFrom = factory.create(mTab); if (createFrom != null) break; } diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromStatementUI.java b/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromStatementUI.java index 43f7309a5e..c8bd0a8e71 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromStatementUI.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/VCreateFromStatementUI.java @@ -1,6 +1,6 @@ /****************************************************************************** - * Copyright (C) 2009 Low Heng Sin * - * Copyright (C) 2009 Idalica Corporation * + * Copyright (C) 2013 Elaine Tan * + * Copyright (C) 2013 Trek Global * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * * by the Free Software Foundation. This program is distributed in the hope * @@ -37,7 +37,6 @@ import org.compiere.grid.ed.VLookup; import org.compiere.grid.ed.VNumber; import org.compiere.grid.ed.VString; import org.compiere.model.GridTab; -import org.compiere.model.MBankAccount; import org.compiere.model.MBankStatement; import org.compiere.model.MColumn; import org.compiere.model.MLookup; @@ -52,6 +51,11 @@ import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; +/** + * + * @author Elaine + * + */ public class VCreateFromStatementUI extends CreateFromStatement implements ActionListener { private VCreateFromDialog dialog; @@ -149,6 +153,7 @@ public class VCreateFromStatementUI extends CreateFromStatement implements Actio // Set Default int C_BankAccount_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BankAccount_ID"); bankAccountField.setValue(new Integer(C_BankAccount_ID)); + bankAccountField.addActionListener(this); // initial Loading authorizationField = new VString ("authorization", false, false, true, 10, 30, null, null); authorizationField.addActionListener(this); @@ -164,11 +169,16 @@ public class VCreateFromStatementUI extends CreateFromStatement implements Actio bPartnerLookup = new VLookup("C_BPartner_ID", false, false, true, MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search)); BPartner_idLabel.setLabelFor(bPartnerLookup); + bPartnerLookup.addActionListener(this); Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate); dateToField.setValue(date); - - bankAccount = new MBankAccount(Env.getCtx(), C_BankAccount_ID, null); + + documentNoField.addActionListener(this); + dateFromField.addActionListener(this); + dateToField.addActionListener(this); + amtFromField.addActionListener(this); + amtToField.addActionListener(this); loadBankAccount(); @@ -277,7 +287,7 @@ public class VCreateFromStatementUI extends CreateFromStatement implements Actio { log.config("Action=" + e.getActionCommand()); // Object source = e.getSource(); - if ( e.getActionCommand().equals(ConfirmPanel.A_REFRESH) ) + if(e.getActionCommand().equals(ConfirmPanel.A_REFRESH)) { Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); loadBankAccount(); @@ -288,9 +298,10 @@ public class VCreateFromStatementUI extends CreateFromStatement implements Actio protected void loadBankAccount() { - loadTableOIS(getBankData(documentNoField.getText(), bPartnerLookup.getValue(), dateFromField.getValue(), dateToField.getValue(), - amtFromField.getValue(), amtToField.getValue(), documentTypeField.getValue(), tenderTypeField.getValue(), - authorizationField.getText())); + loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), + documentNoField.getText(), dateFromField.getValue(), dateToField.getValue(), + amtFromField.getValue(), amtToField.getValue(), + documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getText())); } protected void loadTableOIS (Vector data) @@ -317,7 +328,8 @@ public class VCreateFromStatementUI extends CreateFromStatement implements Actio } @Override - public Object getWindow() { + public Object getWindow() + { return dialog; } -} +} \ No newline at end of file diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java index 7356a0fb15..dc91450399 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java @@ -2420,9 +2420,9 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements } // DocAction // Pop up Create From - else if (col.equals("CreateFrom") || col.equals("X_CreateFromBatch")) + else if (col.equals("CreateFrom")) { - ICreateFrom cf = WCreateFromFactory.create(adtabPanel.getGridTab(), col); + ICreateFrom cf = WCreateFromFactory.create(adtabPanel.getGridTab()); if(cf != null) { @@ -2593,15 +2593,20 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements { String title = wButton.getDescription(); if (title == null || title.length() == 0) - title = wButton.getDisplay(); + title = wButton.getDisplay(); ProcessInfo pi = new ProcessInfo (title, wButton.getProcess_ID(), table_ID, record_ID); pi.setAD_User_ID (Env.getAD_User_ID(ctx)); pi.setAD_Client_ID (Env.getAD_Client_ID(ctx)); - ADForm form = ADForm.openForm(adFormID); + final IADTabpanel adtabPanel = findADTabpanel(wButton); + GridTab gridTab = null; + if (adtabPanel != null) + gridTab = adtabPanel.getGridTab(); + ADForm form = ADForm.openForm(adFormID, gridTab); form.setProcessInfo(pi); Mode mode = form.getWindowMode(); form.setAttribute(Window.MODE_KEY, form.getWindowMode()); form.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT); + if (mode == Mode.HIGHLIGHTED || mode == Mode.MODAL) { form.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { @Override diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java.orig b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java.orig new file mode 100644 index 0000000000..5641a74bba --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java.orig @@ -0,0 +1,2824 @@ +/****************************************************************************** + * Product: Posterita Ajax UI * + * Copyright (C) 2007 Posterita Ltd. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * Posterita Ltd., 3, Draper Avenue, Quatre Bornes, Mauritius * + * or via info@posterita.org or http://www.posterita.org/ * + *****************************************************************************/ + +package org.adempiere.webui.adwindow; + +import static org.compiere.model.SystemIDs.PROCESS_AD_CHANGELOG_REDO; +import static org.compiere.model.SystemIDs.PROCESS_AD_CHANGELOG_UNDO; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeMap; +import java.util.logging.Level; + +import org.adempiere.util.Callback; +import org.adempiere.webui.AdempiereIdGenerator; +import org.adempiere.webui.AdempiereWebUI; +import org.adempiere.webui.LayoutUtils; +import org.adempiere.webui.WArchive; +import org.adempiere.webui.WRequest; +import org.adempiere.webui.WZoomAcross; +import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.apps.BusyDialogTemplate; +import org.adempiere.webui.apps.ProcessModalDialog; +import org.adempiere.webui.apps.form.WCreateFromFactory; +import org.adempiere.webui.apps.form.WCreateFromWindow; +import org.adempiere.webui.component.Button; +import org.adempiere.webui.component.Listbox; +import org.adempiere.webui.component.ProcessInfoDialog; +import org.adempiere.webui.component.Window; +import org.adempiere.webui.component.ZkCssHelper; +import org.adempiere.webui.editor.IProcessButton; +import org.adempiere.webui.editor.WEditor; +import org.adempiere.webui.event.ActionEvent; +import org.adempiere.webui.event.ActionListener; +import org.adempiere.webui.event.DialogEvents; +import org.adempiere.webui.event.ToolbarListener; +import org.adempiere.webui.exception.ApplicationException; +import org.adempiere.webui.panel.ADForm; +import org.adempiere.webui.panel.InfoPanel; +import org.adempiere.webui.panel.WAttachment; +import org.adempiere.webui.panel.WDocActionPanel; +import org.adempiere.webui.panel.action.ExportAction; +import org.adempiere.webui.panel.action.FileImportAction; +import org.adempiere.webui.panel.action.ReportAction; +import org.adempiere.webui.part.AbstractUIPart; +import org.adempiere.webui.session.SessionManager; +import org.adempiere.webui.window.CustomizeGridViewDialog; +import org.adempiere.webui.window.FDialog; +import org.adempiere.webui.window.FindWindow; +import org.adempiere.webui.window.WChat; +import org.adempiere.webui.window.WRecordAccessDialog; +import org.compiere.grid.ICreateFrom; +import org.compiere.model.DataStatusEvent; +import org.compiere.model.DataStatusListener; +import org.compiere.model.GridField; +import org.compiere.model.GridTab; +import org.compiere.model.GridTable; +import org.compiere.model.GridWindow; +import org.compiere.model.GridWindowVO; +import org.compiere.model.Lookup; +import org.compiere.model.MImage; +import org.compiere.model.MProcess; +import org.compiere.model.MQuery; +import org.compiere.model.MRecentItem; +import org.compiere.model.MRole; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfo; +import org.compiere.process.ProcessInfoLog; +import org.compiere.process.ProcessInfoUtil; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.DisplayType; +import org.compiere.util.Env; +import org.compiere.util.Msg; +import org.compiere.util.Util; +import org.compiere.util.WebDoc; +import org.zkoss.zk.ui.AbstractComponent; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.HtmlBasedComponent; +import org.zkoss.zk.ui.Session; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.sys.ExecutionCtrl; +import org.zkoss.zk.ui.util.Clients; +import org.zkoss.zul.Column; +import org.zkoss.zul.Columns; +import org.zkoss.zul.Div; +import org.zkoss.zul.Hbox; +import org.zkoss.zul.Listitem; +import org.zkoss.zul.Menuitem; +import org.zkoss.zul.Menupopup; +import org.zkoss.zul.Window.Mode; + +/** + * + * This class is based on org.compiere.apps.APanel written by Jorg Janke. + * @author Jorg Janke + * + * @author Ashley G Ramdass + * @author Low Heng Sin + * @date Feb 25, 2007 + * @version $Revision: 0.10 $ + * + * @author Cristina Ghita, www.arhipac.ro + * @see FR [ 2877111 ] See identifiers columns when delete records https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2877111&group_id=176962 + * + * @author hengsin, hengsin.low@idalica.com + * @see FR [2887701] https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2887701&group_id=176962 + * @sponsor www.metas.de + * + * @author Teo Sarca, teo.sarca@gmail.com + *
  • BF [ 2992540 ] Grid/Panel not refreshed after process run + * https://sourceforge.net/tracker/?func=detail&aid=2992540&group_id=176962&atid=955896 + *
  • BF [ 2985892 ] Opening a window using a new record query is not working + * https://sourceforge.net/tracker/?func=detail&aid=2985892&group_id=176962&atid=955896 + */ +public abstract class AbstractADWindowContent extends AbstractUIPart implements ToolbarListener, + EventListener, DataStatusListener, ActionListener +{ + private static final String ON_DEFER_SET_DETAILPANE_SELECTION_EVENT = "onDeferSetDetailpaneSelection"; + + private static final CLogger logger; + + static + { + logger = CLogger.getCLogger(AbstractADWindowContent.class); + } + + private Properties ctx; + + private GridWindow gridWindow; + + protected StatusBar statusBar; + + protected IADTabbox adTabbox; + + private int curWindowNo; + + private boolean m_onlyCurrentRows = true; + + protected ADWindowToolbar toolbar; + + protected String title; + + private boolean newRecord; + + private boolean boolChanges = false; + + private int m_onlyCurrentDays = 0; + + private Component parent; + + private boolean m_findCancelled; + + private boolean m_findCreateNew; + + private boolean m_queryInitiating; + + protected BreadCrumb breadCrumb; + + private int adWindowId; + + private MImage image; + + /** + * Constructor + * @param ctx + * @param windowNo + * @param adWindowId + */ + public AbstractADWindowContent(Properties ctx, int windowNo, int adWindowId) + { + this.ctx = ctx; + this.curWindowNo = windowNo; + this.adWindowId = adWindowId; + + initComponents(); + } + + /** + * @param parent + * @return Component + */ + public Component createPart(Object parent) + { + if (parent instanceof Component) + this.parent = (Component) parent; + + adTabbox = createADTab(); + adTabbox.setSelectionEventListener(this); + adTabbox.setADWindowPanel(this); + + Component comp = super.createPart(parent); + comp.addEventListener(LayoutUtils.ON_REDRAW_EVENT, this); + comp.addEventListener(ON_DEFER_SET_DETAILPANE_SELECTION_EVENT, this); + return comp; + } + + public BreadCrumb getBreadCrumb() + { + return breadCrumb; + } + + /** + * @return StatusBarPanel + */ + public StatusBar getStatusBar() + { + return statusBar; + } + + private void initComponents() + { + /** Initalise toolbar */ + toolbar = new ADWindowToolbar(getWindowNo()); + toolbar.setId("windowToolbar"); + toolbar.addListener(this); + + statusBar = new StatusBar(); + + GridWindowVO gWindowVO = AEnv.getMWindowVO(curWindowNo, adWindowId, 0); + if (gWindowVO == null) + { + throw new ApplicationException(Msg.getMsg(ctx, + "AccessTableNoView") + + "(No Window Model Info)"); + } + gridWindow = new GridWindow(gWindowVO, true); + title = gridWindow.getName(); + image = gridWindow.getMImage(); + } + + /** + * @return IADTab + */ + protected abstract IADTabbox createADTab(); + + private void focusToActivePanel() { + IADTabpanel adTabPanel = adTabbox.getSelectedTabpanel(); + focusToTabpanel(adTabPanel); + } + + private void focusToTabpanel(IADTabpanel adTabPanel ) { + if (adTabPanel != null && adTabPanel instanceof HtmlBasedComponent) { + ((HtmlBasedComponent)adTabPanel).focus(); + } + } + + /** + * @param adWindowId + * @param query + * @return boolean + */ + public boolean initPanel(MQuery query) + { + // This temporary validation code is added to check the reported bug + // [ adempiere-ZK Web Client-2832968 ] User context lost? + // https://sourceforge.net/tracker/?func=detail&atid=955896&aid=2832968&group_id=176962 + // it's harmless, if there is no bug then this must never fail + Session currSess = Executions.getCurrent().getDesktop().getSession(); + int checkad_user_id = -1; + if (currSess != null && currSess.getAttribute("Check_AD_User_ID") != null) + checkad_user_id = (Integer)currSess.getAttribute("Check_AD_User_ID"); + if (checkad_user_id!=Env.getAD_User_ID(ctx)) + { + String msg = "Timestamp=" + new Date() + + ", Bug 2832968 SessionUser=" + + checkad_user_id + + ", ContextUser=" + + Env.getAD_User_ID(ctx) + + ". Please report conditions to your system administrator or in sf tracker 2832968"; + ApplicationException ex = new ApplicationException(msg); + logger.log(Level.SEVERE, msg, ex); + throw ex; + } + // End of temporary code for [ adempiere-ZK Web Client-2832968 ] User context lost? + + // Set AutoCommit for this Window + Env.setAutoCommit(ctx, curWindowNo, Env.isAutoCommit(ctx)); + boolean autoNew = Env.isAutoNew(ctx); + Env.setAutoNew(ctx, curWindowNo, autoNew); + + + + // Set SO/AutoNew for Window + Env.setContext(ctx, curWindowNo, "IsSOTrx", gridWindow.isSOTrx()); + if (!autoNew && gridWindow.isTransaction()) + { + Env.setAutoNew(ctx, curWindowNo, true); + } + + m_onlyCurrentRows = gridWindow.isTransaction(); + + MQuery detailQuery = null; + /** + * Window Tabs + */ + if (query != null && query.getZoomTableName() != null && query.getZoomColumnName() != null + && query.getZoomValue() instanceof Integer && (Integer)query.getZoomValue() > 0) + { + if (!query.getZoomTableName().equalsIgnoreCase(gridWindow.getTab(0).getTableName())) + { + detailQuery = query; + query = new MQuery(); + query.addRestriction("1=2"); + query.setRecordCount(0); + } + } + + int tabSize = gridWindow.getTabCount(); + + GridTab gridTab = null; + for (int tab = 0; tab < tabSize; tab++) + { + gridTab = initTab(query, tab); + if (tab == 0 && gridTab == null && m_findCancelled) + return false; + } + Env.setContext(ctx, curWindowNo, "WindowName", gridWindow.getName()); + Env.setContext(ctx, curWindowNo, "AD_Window_ID", gridWindow.getAD_Window_ID()); + Env.setContext(ctx, curWindowNo, "AD_Window_UU", gridWindow.getAD_Window_UU()); + + if (gridTab != null) + gridTab.getTableModel().setChanged(false); + + adTabbox.setSelectedIndex(0); + // all fields context for window is clear at AbstractADTab.prepareContext, set again IsSOTrx for window + Env.setContext(ctx, curWindowNo, "IsSOTrx", gridWindow.isSOTrx()); + toolbar.enableTabNavigation(adTabbox.getTabCount() > 1); + toolbar.enableFind(true); + adTabbox.evaluate(null); + + if (detailQuery != null && zoomToDetailTab(detailQuery)) + { + return true; + } + + toolbar.updateToolbarAccess(adWindowId); + updateToolbar(); + + return true; + } + + private boolean zoomToDetailTab(MQuery query) { + //zoom to detail + if (query != null && query.getZoomTableName() != null && query.getZoomColumnName() != null) + { + GridTab gTab = gridWindow.getTab(0); + if (!query.getZoomTableName().equalsIgnoreCase(gTab.getTableName())) + { + int tabSize = gridWindow.getTabCount(); + + for (int tab = 0; tab < tabSize; tab++) + { + gTab = gridWindow.getTab(tab); + if (gTab.isSortTab()) + continue; + if (gTab.getTableName().equalsIgnoreCase(query.getZoomTableName())) + { + if (doZoomToDetail(gTab, query, tab)) { + return true; + } + } + } + } + } + return false; + } + + private boolean doZoomToDetail(GridTab gTab, MQuery query, int tabIndex) { + GridField[] fields = gTab.getFields(); + for (GridField field : fields) + { + if (field.getColumnName().equalsIgnoreCase(query.getZoomColumnName())) + { + gridWindow.initTab(tabIndex); + int parentId = DB.getSQLValue(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause()); + if (parentId > 0) + { + MapparentMap = new TreeMap(); + int index = tabIndex; + int oldpid = parentId; + GridTab currentTab = gTab; + while (index > 0) + { + index--; + GridTab pTab = gridWindow.getTab(index); + if (pTab.getTabLevel() < currentTab.getTabLevel()) + { + gridWindow.initTab(index); + if (index > 0) + { + if (pTab.getLinkColumnName() != null && pTab.getLinkColumnName().trim().length() > 0) + { + int pid = DB.getSQLValue(null, "SELECT " + pTab.getLinkColumnName() + " FROM " + pTab.getTableName() + " WHERE " + currentTab.getLinkColumnName() + " = ?", oldpid); + if (pid > 0) + { + parentMap.put(index, new Object[]{currentTab.getLinkColumnName(), oldpid}); + oldpid = pid; + currentTab = pTab; + } + else + { + parentMap.clear(); + break; + } + } + } + else + { + parentMap.put(index, new Object[]{currentTab.getLinkColumnName(), oldpid}); + } + } + } + + for(Map.Entry entry : parentMap.entrySet()) + { + GridTab pTab = gridWindow.getTab(entry.getKey()); + Object[] value = entry.getValue(); + MQuery pquery = new MQuery(pTab.getAD_Table_ID()); + pquery.addRestriction((String)value[0], "=", value[1]); + IADTabpanel tp = adTabbox.findADTabpanel(pTab); + tp.createUI(); + if (tp.getTabLevel() == 0) + { + pTab.setQuery(pquery); + tp.query(); + } + else + { + tp.query(); + pTab.setQuery(pquery); + tp.query(); + } + } + + MQuery targetQuery = new MQuery(gTab.getAD_Table_ID()); + targetQuery.addRestriction(gTab.getLinkColumnName(), "=", parentId); + gTab.setQuery(targetQuery); + IADTabpanel gc = null; + gc = adTabbox.findADTabpanel(gTab); + gc.createUI(); + gc.query(false, 0, 0); + + GridTable table = gTab.getTableModel(); + int count = table.getRowCount(); + for(int i = 0; i < count; i++) + { + int id = table.getKeyID(i); + if (id == ((Integer)query.getZoomValue()).intValue()) + { + setActiveTab(gridWindow.getTabIndex(gTab), null); + gTab.navigate(i); + return true; + } + } + } + } + } + return false; + } + + private void initQueryOnNew(MQuery result) { + GridTab curTab = adTabbox.getSelectedGridTab(); + boolean onNew = false; + if (curTab.isHighVolume() && m_findCreateNew) + onNew = true; + else if (result == null && curTab.getRowCount() == 0 && Env.isAutoNew(ctx, curWindowNo)) + onNew = true; + else if (!curTab.isReadOnly() && curTab.isQueryNewRecord()) + onNew = true; + if (onNew) { + Executions.schedule(AEnv.getDesktop(), new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + onNew(); + } + }, new Event("onInsert")); + } + } + + /** + * @param query + * @param tabIndex + */ + protected GridTab initTab(MQuery query, int tabIndex) { + gridWindow.initTab(tabIndex); + + final GridTab gTab = gridWindow.getTab(tabIndex); + Env.setContext(ctx, curWindowNo, tabIndex, GridTab.CTX_TabLevel, Integer.toString(gTab.getTabLevel())); + + // Query first tab + if (tabIndex == 0) + { + m_queryInitiating = true; + getComponent().setVisible(false); + initialQuery(query, gTab, new Callback() { + @Override + public void onCallback(MQuery result) { + m_queryInitiating = false; + + if (m_findCancelled) { + SessionManager.getAppDesktop().closeWindow(curWindowNo); + return; + } + + if (!getComponent().isVisible()) + getComponent().setVisible(true); + + // Set initial Query on first tab + if (result != null) + { + m_onlyCurrentRows = false; + gTab.setQuery(result); + } + + if (adTabbox.getSelectedTabpanel() != null) + { + initFirstTabpanel(); + + initQueryOnNew(result); + } + } + + }); + } + + if (gTab.isSortTab()) + { + ADSortTab sortTab = new ADSortTab(curWindowNo, gTab); + adTabbox.addTab(gTab, sortTab); + sortTab.registerAPanel(this); + if (tabIndex == 0) { + sortTab.createUI(); + if (!m_queryInitiating) + { + initFirstTabpanel(); + } + } + gTab.addDataStatusListener(this); + } + else + { + ADTabpanel fTabPanel = new ADTabpanel(); + fTabPanel.addEventListener(ADTabpanel.ON_DYNAMIC_DISPLAY_EVENT, this); + gTab.addDataStatusListener(this); + fTabPanel.init(this, curWindowNo, gTab, gridWindow); + adTabbox.addTab(gTab, fTabPanel); + if (tabIndex == 0) { + fTabPanel.createUI(); + if (!m_queryInitiating) + { + initFirstTabpanel(); + } + } + + if (!m_queryInitiating && tabIndex == 0) + { + initQueryOnNew(query); + } + } + + return gTab; + } + + private void initFirstTabpanel() { + adTabbox.getSelectedTabpanel().query(m_onlyCurrentRows, m_onlyCurrentDays, MRole.getDefault().getMaxQueryRecords()); + adTabbox.getSelectedTabpanel().activate(true); + Events.echoEvent(new Event(ADTabpanel.ON_POST_INIT_EVENT, adTabbox.getSelectedTabpanel())); + } + + /** + * Initial Query + * + * @param query + * initial query + * @param mTab + * tab + * @return query or null + */ + private void initialQuery(final MQuery query, GridTab mTab, final Callback callback) + { + // We have a (Zoom) query + if (query != null && query.isActive() && query.getRecordCount() < 10) + { + callback.onCallback(query); + return; + } + + // + StringBuffer where = new StringBuffer(); + // Query automatically if high volume and no query + boolean require = mTab.isHighVolume(); + if (!require && !m_onlyCurrentRows) // No Trx Window + { + String wh1 = Env.parseContext(ctx, curWindowNo, mTab.getWhereExtended(), false); + if (wh1 == null || wh1.length() == 0) + wh1 = mTab.getWhereClause(); + if (wh1 != null && wh1.length() > 0) + where.append(wh1); + // + if (query != null) + { + String wh2 = query.getWhereClause(); + if (wh2.length() > 0) + { + if (where.length() > 0) + where.append(" AND "); + where.append(wh2); + } + } + // + StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM ") + .append(mTab.getTableName()); + if (where.length() > 0) + sql.append(" WHERE ").append(where); + // Does not consider security + int no = DB.getSQLValue(null, sql.toString()); + // + require = MRole.getDefault().isQueryRequire(no); + } + // Show Query + if (require) + { + m_findCancelled = false; + m_findCreateNew = false; + GridField[] findFields = mTab.getFields(); + findWindow = new FindWindow(curWindowNo, + mTab.getName(), mTab.getAD_Table_ID(), mTab.getTableName(), + where.toString(), findFields, 10, mTab.getAD_Tab_ID()); // no query below 10 + setupEmbeddedFindwindow(); + if (findWindow.initialize()) + { + findWindow.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + if (!findWindow.isCancel()) + { + m_findCreateNew = findWindow.isCreateNew(); + MQuery result = findWindow.getQuery(); + callback.onCallback(result); + EventListener listener = findWindow.getEventListeners(DialogEvents.ON_WINDOW_CLOSE).iterator().next(); + findWindow.removeEventListener(DialogEvents.ON_WINDOW_CLOSE, listener); + } + else + { + m_findCancelled = true; + callback.onCallback(null); + } + } + }); + getComponent().addEventListener("onInitialQuery", new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + getComponent().getParent().appendChild(findWindow); + LayoutUtils.openEmbeddedWindow(getComponent().getParent(), findWindow, "overlap"); + } + }); + Events.echoEvent("onInitialQuery", getComponent(), null); + } + else + { + callback.onCallback(query); + } + } + else + { + callback.onCallback(query); + } + } // initialQuery + + private void setupEmbeddedFindwindow() { + findWindow.setTitle(null); + findWindow.setBorder("none"); + findWindow.setStyle("position: absolute; border-bottom: 2px solid #484848; padding: 2px; background-color: #fff;"); + findWindow.setWidth("100%"); + findWindow.setHeight("60%"); + findWindow.setZindex(1000); + findWindow.setSizable(false); + findWindow.setContentStyle("background-color: #fff; width: 99%; margin: auto;"); + } + + public String getTitle() + { + return title; + } + + public MImage getImage() + { + return image; + } + + /** + * @see ToolbarListener#onDetailRecord() + */ + public void onDetailRecord() + { + adTabbox.onDetailRecord(); + } + + /** + * @see ToolbarListener#onParentRecord() + */ + public void onParentRecord() + { + List parents = breadCrumb.getParentLinks(); + if (!parents.isEmpty()) { + Events.sendEvent(parents.get(parents.size()-1), new Event(Events.ON_CLICK, parents.get(parents.size()-1))); + } + } + + /** + * @see ToolbarListener#onFirst() + */ + public void onFirst() + { + Callback callback = new Callback() { + @Override + public void onCallback(Boolean result) { + if (result) { + adTabbox.getSelectedGridTab().navigate(0); + focusToActivePanel(); + } + } + }; + saveAndNavigate(callback); + } + + /** + * @see ToolbarListener#onLast() + */ + public void onLast() + { + Callback callback = new Callback() { + @Override + public void onCallback(Boolean result) { + if (result) { + adTabbox.getSelectedGridTab().navigate(adTabbox.getSelectedGridTab().getRowCount() - 1); + focusToActivePanel(); + } + } + }; + onSave(false, true, callback); + } + + /** + * @see ToolbarListener#onNext() + */ + public void onNext() + { + Callback callback = new Callback() { + @Override + public void onCallback(Boolean result) { + if (result) { + adTabbox.getSelectedGridTab().navigateRelative(+1); + focusToActivePanel(); + } + } + }; + saveAndNavigate(callback); + } + + /** + * @see ToolbarListener#onPrevious() + */ + public void onPrevious() + { + Callback callback = new Callback() { + @Override + public void onCallback(Boolean result) { + if (result) { + adTabbox.getSelectedGridTab().navigateRelative(-1); + focusToActivePanel(); + } + } + }; + saveAndNavigate(callback); + } + + // Elaine 2008/12/04 + private Menupopup m_popup = null; + private Menuitem m_lock = null; + private Menuitem m_access = null; + + private FindWindow findWindow; + + private Div maskDiv; + + /** + * @see ToolbarListener#onLock() + */ + public void onLock() + { + if (!toolbar.isPersonalLock) + return; + if (adTabbox.getSelectedGridTab().getRecord_ID() == -1) // No Key + return; + + if(m_popup == null) + { + m_popup = new Menupopup(); + + m_lock = new Menuitem(Msg.translate(Env.getCtx(), "Lock")); + m_popup.appendChild(m_lock); + m_lock.addEventListener(Events.ON_CLICK, new EventListener() + { + public void onEvent(Event event) throws Exception + { + adTabbox.getSelectedGridTab().lock(Env.getCtx(), adTabbox.getSelectedGridTab().getRecord_ID(), !toolbar.getButton("Lock").isPressed()); + adTabbox.getSelectedGridTab().loadLocks(); // reload + + toolbar.lock(adTabbox.getSelectedGridTab().isLocked()); + } + }); + + m_access = new Menuitem(Msg.translate(Env.getCtx(), "RecordAccessDialog")); + m_popup.appendChild(m_access); + m_access.addEventListener(Events.ON_CLICK, new EventListener() + { + public void onEvent(Event event) throws Exception + { + WRecordAccessDialog recordAccessDialog = new WRecordAccessDialog(null, adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getRecord_ID()); + recordAccessDialog.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + + @Override + public void onEvent(Event event) throws Exception { + toolbar.lock(adTabbox.getSelectedGridTab().isLocked()); + } + }); + + AEnv.showWindow(recordAccessDialog); + } + }); + + m_popup.setPage(toolbar.getButton("Lock").getPage()); + } + m_popup.open(toolbar.getButton("Lock")); + } // lock + // + + + /** + * @see ToolbarListener#onAttachment() + */ + public void onAttachment() + { + int record_ID = adTabbox.getSelectedGridTab().getRecord_ID(); + logger.info("Record_ID=" + record_ID); + + if (record_ID == -1) // No Key + { + //aAttachment.setEnabled(false); + return; + } + + EventListener listener = new EventListener() { + + @Override + public void onEvent(Event event) throws Exception { + toolbar.getButton("Attachment").setPressed(adTabbox.getSelectedGridTab().hasAttachment()); + focusToActivePanel(); + } + }; + // Attachment va = + WAttachment win = new WAttachment ( curWindowNo, adTabbox.getSelectedGridTab().getAD_AttachmentID(), + adTabbox.getSelectedGridTab().getAD_Table_ID(), record_ID, null, listener); + win.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + hideBusyMask(); + } + }); + showBusyMask(); + getComponent().getParent().appendChild(win); + LayoutUtils.openOverlappedWindow(getComponent(), win, "middle_center"); + } + + public void onChat() + { + int recordId = adTabbox.getSelectedGridTab().getRecord_ID(); + logger.info("Record_ID=" + recordId); + + if (recordId== -1) // No Key + { + return; + } + + // Find display + String infoName = null; + String infoDisplay = null; + for (int i = 0; i < adTabbox.getSelectedGridTab().getFieldCount(); i++) + { + GridField field = adTabbox.getSelectedGridTab().getField(i); + if (field.isKey()) + infoName = field.getHeader(); + if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo") ) + && field.getValue() != null) + infoDisplay = field.getValue().toString(); + if (infoName != null && infoDisplay != null) + break; + } + String description = infoName + ": " + infoDisplay; + + WChat chat = new WChat(curWindowNo, adTabbox.getSelectedGridTab().getCM_ChatID(), adTabbox.getSelectedGridTab().getAD_Table_ID(), recordId, description, null); + chat.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + hideBusyMask(); + toolbar.getButton("Chat").setPressed(adTabbox.getSelectedGridTab().hasChat()); + focusToActivePanel(); + } + }); + showBusyMask(); + getComponent().getParent().appendChild(chat); + LayoutUtils.openOverlappedWindow(getComponent(), chat, "middle_center"); + chat.showWindow(); + } + + /** + * @see ToolbarListener#onToggle() + */ + public void onToggle() + { + adTabbox.getSelectedTabpanel().switchRowPresentation(); + //Deepak-Enabling customize button IDEMPIERE-364 + if(!(adTabbox.getSelectedTabpanel() instanceof ADSortTab)) + toolbar.enableCustomize(((ADTabpanel)adTabbox.getSelectedTabpanel()).isGridView()); + focusToActivePanel(); + } + + /** + * @return boolean + */ + public boolean onExit() + { + if (!boolChanges) + { + return true; + } + else + FDialog.info(this.curWindowNo, null, "SaveBeforeClose"); + + return false; + } + + /** + * @param event + * @see EventListener#onEvent(Event) + */ + public void onEvent(Event event) + { + if (CompositeADTabbox.ON_SELECTION_CHANGED_EVENT.equals(event.getName())) + { + Object eventData = event.getData(); + + if (eventData != null && eventData instanceof Object[] && ((Object[])eventData).length == 2) + { + Object[] indexes = (Object[]) eventData; + final int newTabIndex = (Integer)indexes[1]; + + final int originalTabIndex = adTabbox.getSelectedIndex(); + final int originalTabRow = adTabbox.getSelectedGridTab().getCurrentRow(); + setActiveTab(newTabIndex, new Callback() { + + @Override + public void onCallback(Boolean result) { + if (result) + { + if (newTabIndex < originalTabIndex) + { + if (adTabbox.isDetailPaneLoaded()) + adTabbox.setDetailPaneSelectedTab(originalTabIndex, originalTabRow); + else { + Events.echoEvent(new Event(ON_DEFER_SET_DETAILPANE_SELECTION_EVENT, getComponent(), new Integer[]{originalTabIndex, originalTabRow})); + } + } + } + else + { + //reset to original + adTabbox.setSelectedIndex(originalTabIndex); + } + + } + }); + } + } + else if (event.getTarget() instanceof ProcessModalDialog) + { + hideBusyMask(); + ProcessModalDialog dialog = (ProcessModalDialog) event.getTarget(); + onModalClose(dialog.getProcessInfo()); + String s = breadCrumb.getStatusLine(); + boolean b = breadCrumb.getStatusError(); + ProcessInfoLog[] logs = breadCrumb.getPLogs(); + onRefresh(true, false); + breadCrumb.setStatusLine(s, b, logs); + } + else if (ADTabpanel.ON_DYNAMIC_DISPLAY_EVENT.equals(event.getName())) + { + ADTabpanel adtab = (ADTabpanel) event.getTarget(); + if (adtab == adTabbox.getSelectedTabpanel()) { + toolbar.enableProcessButton(adtab.getToolbarButtons().size() > 0); + toolbar.dynamicDisplay(); + } + } + else if (event.getTarget() == getComponent() && event.getName().equals(LayoutUtils.ON_REDRAW_EVENT)) { + ExecutionCtrl ctrl = (ExecutionCtrl) Executions.getCurrent(); + Event evt = ctrl.getNextEvent(); + if (evt != null) { + Events.sendEvent(evt); + Events.postEvent(new Event(LayoutUtils.ON_REDRAW_EVENT, getComponent())); + return; + } + LayoutUtils.redraw((AbstractComponent) getComponent()); + } + else if (event.getName().equals(ON_DEFER_SET_DETAILPANE_SELECTION_EVENT)) { + Integer[] data = (Integer[]) event.getData(); + adTabbox.setDetailPaneSelectedTab(data[0], data[1]); + } + } + + private void setActiveTab(final int newTabIndex, final Callback callback) { + + final int oldTabIndex = adTabbox.getSelectedIndex(); + + if (oldTabIndex == newTabIndex) + { + if (callback != null) + callback.onCallback(true); + } + else + { + Callback command = new Callback() { + + @Override + public void onCallback(Boolean result) { + if (result) { + setActiveTab0(oldTabIndex, newTabIndex, callback); + } else if (callback != null) { + callback.onCallback(false); + } + } + }; + saveAndNavigate(command); + } + + } + + public void saveAndNavigate(final Callback callback) { + if (adTabbox != null) + { + if (adTabbox.isSortTab()) + { + onSave(false, true, callback); + } + else if (adTabbox.needSave(true, false)) + { + if (adTabbox.needSave(true, true)) + { + onSave(false, true, callback); + } + else + { + // new record, but nothing changed + adTabbox.dataIgnore(); + callback.onCallback(true); + } + } // there is a change + else + callback.onCallback(true); + } + else + callback.onCallback(true); + } + + private void setActiveTab0(int oldTabIndex, int newTabIndex, + final Callback callback) { + boolean back = false; + IADTabpanel oldTabpanel = adTabbox.getSelectedTabpanel(); + + if (!adTabbox.updateSelectedIndex(oldTabIndex, newTabIndex)) + { + FDialog.warn(curWindowNo, "TabSwitchJumpGo", title); + if (callback != null) + callback.onCallback(false); + return; + } + + + IADTabpanel newTabpanel = adTabbox.getSelectedTabpanel(); + + boolean activated = newTabpanel.isActivated(); + if (oldTabpanel != null) + oldTabpanel.activate(false); + if (!activated) + newTabpanel.activate(true); + + back = (newTabIndex < oldTabIndex); + if (back && newTabpanel.getTabLevel() > 0) + { + if (newTabpanel.getTabLevel() >= oldTabpanel.getTabLevel()) + back = false; + else if ((newTabIndex - oldTabIndex) > 1) + { + for (int i = oldTabIndex - 1; i > newTabIndex; i--) + { + IADTabpanel next = adTabbox.getADTabpanel(i); + if (next != null && next.getTabLevel() <= newTabpanel.getTabLevel()) + { + back = false; + break; + } + } + } + } + +// if (!activated) +// { + if (!back) + { + newTabpanel.query(); + } + else + { + newTabpanel.refresh(); + } +// } + + if (adTabbox.getSelectedTabpanel() instanceof ADSortTab) + { + ((ADSortTab)adTabbox.getSelectedTabpanel()).registerAPanel(this); + } + else + { + if (adTabbox.getSelectedGridTab().getRowCount() == 0 && Env.isAutoNew(ctx, getWindowNo())) + { + onNew(); + } + } + + updateToolbar(); + + breadCrumb.setNavigationToolbarVisibility(!adTabbox.getSelectedGridTab().isSortTab()); + + if (callback != null) + callback.onCallback(true); + } + + private void updateToolbar() + { + toolbar.enableTabNavigation(breadCrumb.hasParentLink(), adTabbox.getSelectedDetailADTabpanel() != null); + + toolbar.getButton("Attachment").setPressed(adTabbox.getSelectedGridTab().hasAttachment()); + toolbar.getButton("Chat").setPressed(adTabbox.getSelectedGridTab().hasChat()); + toolbar.getButton("Find").setPressed(adTabbox.getSelectedGridTab().isQueryActive()); + + if (toolbar.isPersonalLock) + { + toolbar.lock(adTabbox.getSelectedGridTab().isLocked()); + } + + toolbar.enablePrint(adTabbox.getSelectedGridTab().isPrinted()); + + //Deepak-Enabling customize button IDEMPIERE-364 + if(!(adTabbox.getSelectedTabpanel() instanceof ADSortTab)) + toolbar.enableCustomize(((ADTabpanel)adTabbox.getSelectedTabpanel()).isGridView()); + else + toolbar.enableCustomize(false); + + } + + /** + * @param e + * @see DataStatusListener#dataStatusChanged(DataStatusEvent) + */ + public void dataStatusChanged(DataStatusEvent e) + { + //ignore non-ui thread event. + if (Executions.getCurrent() == null) + return; + + boolean detailTab = false; + if (e.getSource() instanceof GridTable) + { + GridTable gridTable = (GridTable) e.getSource(); + if (adTabbox.getSelectedGridTab() != null && adTabbox.getSelectedGridTab().getTableModel() != gridTable) { + detailTab = true; + } + } else if (e.getSource() instanceof GridTab) + { + GridTab gridTab = (GridTab)e.getSource(); + if (adTabbox.getSelectedGridTab() != gridTab) detailTab = true; + } + + if (!detailTab) + { + String dbInfo = e.getMessage(); + logger.info(dbInfo); + if (adTabbox.getSelectedGridTab() != null && adTabbox.getSelectedGridTab().isQueryActive()) + dbInfo = "[ " + dbInfo + " ]"; + breadCrumb.setStatusDB(dbInfo, e); + } else if (adTabbox.getSelectedDetailADTabpanel() == null) + { + return; + } + + // Set Message / Info + if (e.getAD_Message() != null || e.getInfo() != null) + { + if (GridTab.DEFAULT_STATUS_MESSAGE.equals(e.getAD_Message())) + { + if (detailTab) { + adTabbox.setDetailPaneStatusMessage("", false); + } else { + breadCrumb.setStatusLine ("", false); + } + } + else + { + StringBuilder sb = new StringBuilder(); + String msg = e.getMessage(); + if (msg != null && msg.length() > 0) + { + sb.append(Msg.getMsg(Env.getCtx(), e.getAD_Message())); + } + String info = e.getInfo(); + if (info != null && info.length() > 0) + { + if (sb.length() > 0 && !sb.toString().trim().endsWith(":")) + sb.append(": "); + sb.append(info); + } + if (sb.length() > 0) + { + int pos = sb.indexOf("\n"); + if (pos != -1 && pos+1 < sb.length()) // replace CR/NL + { + sb.replace(pos, pos+1, " - "); + } + if (detailTab) { + adTabbox.setDetailPaneStatusMessage(sb.toString (), e.isError ()); + } else { + breadCrumb.setStatusLine (sb.toString (), e.isError ()); + } + } + } + } + + IADTabpanel tabPanel = detailTab ? adTabbox.getSelectedDetailADTabpanel() + : getADTab().getSelectedTabpanel(); + + // Confirm Error + if (e.isError() && !e.isConfirmed() && tabPanel instanceof ADTabpanel) + { + //focus to error field + GridField[] fields = tabPanel.getGridTab().getFields(); + for (GridField field : fields) + { + if (field.isError()) + { + ((ADTabpanel)tabPanel).setFocusToField(field.getColumnName()); + break; + } + } + e.setConfirmed(true); // show just once - if MTable.setCurrentRow is involved the status event is re-issued + } + // Confirm Warning + else if (e.isWarning() && !e.isConfirmed()) + { + if (! adTabbox.getSelectedGridTab().getTableModel().isImporting()) { + FDialog.warn(curWindowNo, null, e.getAD_Message(), e.getInfo()); + e.setConfirmed(true); // show just once - if MTable.setCurrentRow is involved the status event is re-issued + } + } + + boolean changed = e.isChanged() || e.isInserting(); + boolean readOnly = adTabbox.getSelectedGridTab().isReadOnly(); + boolean insertRecord = !readOnly; + if (!detailTab) + { + // update Change + boolChanges = changed; + + if (insertRecord) + { + insertRecord = tabPanel.getGridTab().isInsertRecord(); + } + toolbar.enableNew(!changed && insertRecord && !tabPanel.getGridTab().isSortTab()); + toolbar.enableRefresh(!changed); + toolbar.enableDelete(!changed && !readOnly && !tabPanel.getGridTab().isSortTab()); + // + if (readOnly && adTabbox.getSelectedGridTab().isAlwaysUpdateField()) + { + readOnly = false; + } + } + else + { + adTabbox.updateDetailPaneToolbar(changed, readOnly); + } + toolbar.enableIgnore(adTabbox.needSave(true, false) || + adTabbox.getSelectedGridTab().isNew() || + (adTabbox.getSelectedDetailADTabpanel() != null && adTabbox.getSelectedDetailADTabpanel().getGridTab().isNew())); + + if (changed && !readOnly && !toolbar.isSaveEnable() ) { + if (tabPanel.getGridTab().getRecord_ID() > 0) { + if (adTabbox.getSelectedIndex() == 0 && !detailTab) { + MRecentItem.addModifiedField(ctx, adTabbox.getSelectedGridTab().getAD_Table_ID(), + adTabbox.getSelectedGridTab().getRecord_ID(), Env.getAD_User_ID(ctx), + Env.getAD_Role_ID(ctx), adTabbox.getSelectedGridTab().getAD_Window_ID(), + adTabbox.getSelectedGridTab().getAD_Tab_ID()); + } else { + /* when a detail record is modified add header to recent items */ + GridTab mainTab = gridWindow.getTab(0); + if (mainTab != null) { + MRecentItem.addModifiedField(ctx, mainTab.getAD_Table_ID(), + mainTab.getRecord_ID(), Env.getAD_User_ID(ctx), + Env.getAD_Role_ID(ctx), mainTab.getAD_Window_ID(), + mainTab.getAD_Tab_ID()); + } + } + } + } + + toolbar.enableSave(adTabbox.needSave(true, false) || + adTabbox.getSelectedGridTab().isNew() || + (adTabbox.getSelectedDetailADTabpanel() != null && adTabbox.getSelectedDetailADTabpanel().getGridTab().isNew())); + + // + // No Rows + if (e.getTotalRows() == 0 && insertRecord && !detailTab) + { + toolbar.enableNew(true); + toolbar.enableDelete(false); + } + + // Transaction info + if (!detailTab) + { + String trxInfo = adTabbox.getSelectedGridTab().getTrxInfo(); + if (trxInfo != null) + { + statusBar.setInfo(trxInfo); + } + } + + // Check Attachment + boolean canHaveAttachment = adTabbox.getSelectedGridTab().canHaveAttachment(); // not single _ID column + // + if (canHaveAttachment && e.isLoading() && + adTabbox.getSelectedGridTab().getCurrentRow() > e.getLoadedRows()) + { + canHaveAttachment = false; + } + if (canHaveAttachment && adTabbox.getSelectedGridTab().getRecord_ID() == -1) // No Key + { + canHaveAttachment = false; + } + if (canHaveAttachment) + { + toolbar.enableAttachment(true); + toolbar.getButton("Attachment").setPressed(adTabbox.getSelectedGridTab().hasAttachment()); + } + else + { + toolbar.enableAttachment(false); + } + + // Check Chat + boolean canHaveChat = true; + if (e.isLoading() && + adTabbox.getSelectedGridTab().getCurrentRow() > e.getLoadedRows()) + { + canHaveChat = false; + } + if (canHaveChat && adTabbox.getSelectedGridTab().getRecord_ID() == -1) // No Key + { + canHaveChat = false; + } + if (canHaveChat) + { + toolbar.enableChat(true); + toolbar.getButton("Chat").setPressed(adTabbox.getSelectedGridTab().hasChat()); + } + else + { + toolbar.enableChat(false); + } + + toolbar.getButton("Find").setPressed(adTabbox.getSelectedGridTab().isQueryActive()); + + // Elaine 2008/12/05 + // Lock Indicator + if (toolbar.isPersonalLock) + { + toolbar.lock(adTabbox.getSelectedGridTab().isLocked()); + } + // + + if (!detailTab) + { + adTabbox.evaluate(e); + } + + toolbar.enablePrint(adTabbox.getSelectedGridTab().isPrinted()); + toolbar.enableReport(true); + toolbar.enableExport(!adTabbox.getSelectedGridTab().isSortTab()); + toolbar.enableFileImport(!changed && !adTabbox.getSelectedGridTab().isSortTab() && adTabbox.getSelectedGridTab().isInsertRecord()); + + //Deepak-Enabling customize button IDEMPIERE-364 + if(!(adTabbox.getSelectedTabpanel() instanceof ADSortTab)) + toolbar.enableCustomize(((ADTabpanel)adTabbox.getSelectedTabpanel()).isGridView()); + } + + /** + * @return boolean + */ + public boolean isFirstTab() + { + int selTabIndex = adTabbox.getSelectedIndex(); + return (selTabIndex == 0); + } + + /** + * refresh all row + * @param fireEvent + */ + public void onRefresh(final boolean fireEvent) + { + onRefresh(fireEvent, true); + } + + /** + * refresh all row + * @param fireEvent + * @param saveCurrentRow + */ + public void onRefresh(final boolean fireEvent, final boolean saveCurrentRow) + { + if (saveCurrentRow) + { + onSave(false, true, new Callback() { + + @Override + public void onCallback(Boolean result) { + adTabbox.getSelectedGridTab().dataRefreshAll(fireEvent, true); + adTabbox.getSelectedTabpanel().dynamicDisplay(0); + focusToActivePanel(); + } + }); + } + else + { + adTabbox.getSelectedGridTab().dataRefreshAll(fireEvent, true); + adTabbox.getSelectedTabpanel().dynamicDisplay(0); + focusToActivePanel(); + } + } + + /** + * @see ToolbarListener#onRefresh() + */ + public void onRefresh() + { + onRefresh(true); + } + + /** + * @see ToolbarListener#onHelp() + */ + public void onHelp() + { + WebDoc doc = gridWindow.getHelpDoc(true); + SessionManager.getAppDesktop().showURL(doc, "Help", true); + } + + /** + * @see ToolbarListener#onNew() + */ + public void onNew() + { + if (!adTabbox.getSelectedGridTab().isInsertRecord()) + { + logger.warning("Insert Record disabled for Tab"); + return; + } + + saveAndNavigate(new Callback() { + @Override + public void onCallback(Boolean result) { + if (result) + { + newRecord = adTabbox.getSelectedGridTab().dataNew(false); + if (newRecord) + { + adTabbox.getSelectedTabpanel().dynamicDisplay(0); + toolbar.enableNew(false); + toolbar.enableDelete(false); + breadCrumb.enableFirstNavigation(adTabbox.getSelectedGridTab().getCurrentRow() > 0); + breadCrumb.enableLastNavigation(adTabbox.getSelectedGridTab().getCurrentRow() + 1 < adTabbox.getSelectedGridTab().getRowCount()); + toolbar.enableTabNavigation(breadCrumb.hasParentLink(), adTabbox.getSelectedDetailADTabpanel() != null); + toolbar.enableIgnore(true); + toolbar.enablePrint(adTabbox.getSelectedGridTab().isPrinted()); + toolbar.enableReport(true); + if (adTabbox.getSelectedGridTab().isSingleRow()) + { + if (adTabbox.getSelectedTabpanel().isGridView()) + { + adTabbox.getSelectedTabpanel().switchRowPresentation(); + } + } + + if (adTabbox.getSelectedTabpanel().isGridView()) + { + adTabbox.getSelectedTabpanel().getGridView().editCurrentRow(); + } + } + else + { + logger.severe("Could not create new record"); + } + focusToActivePanel(); + } + } + }); + } + + // Elaine 2008/11/19 + /** + * @see ToolbarListener#onCopy() + */ + public void onCopy() + { + if (!adTabbox.getSelectedGridTab().isInsertRecord()) + { + logger.warning("Insert Record disabled for Tab"); + return; + } + + newRecord = adTabbox.getSelectedGridTab().dataNew(true); + if (newRecord) + { + adTabbox.getSelectedTabpanel().dynamicDisplay(0); + toolbar.enableNew(false); + toolbar.enableDelete(false); + breadCrumb.enableFirstNavigation(adTabbox.getSelectedGridTab().getCurrentRow() > 0); + breadCrumb.enableLastNavigation(adTabbox.getSelectedGridTab().getCurrentRow() + 1 < adTabbox.getSelectedGridTab().getRowCount()); + toolbar.enableTabNavigation(false); + toolbar.enableIgnore(true); + toolbar.enablePrint(adTabbox.getSelectedGridTab().isPrinted()); + toolbar.enableReport(true); + } + else + { + logger.severe("Could not create new record"); + } + focusToActivePanel(); + } + // + + /** + * @see ToolbarListener#onFind() + */ + public void onFind() + { + if (adTabbox.getSelectedGridTab() == null) + return; + + onSave(false, false, new Callback() { + + @Override + public void onCallback(Boolean result) { + if (result) { + doOnFind(); + } + } + }); + } + + private void doOnFind() { + adTabbox.dataIgnore(); + + // Gets Fields from AD_Field_v + GridField[] findFields = adTabbox.getSelectedGridTab().getFields(); + if (findWindow == null || !findWindow.validate(adTabbox.getSelectedGridTab().getWindowNo(), adTabbox.getSelectedGridTab().getName(), + adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getTableName(), + adTabbox.getSelectedGridTab().getWhereExtended(), findFields, 1, adTabbox.getSelectedGridTab().getAD_Tab_ID())) { + findWindow = new FindWindow (adTabbox.getSelectedGridTab().getWindowNo(), adTabbox.getSelectedGridTab().getName(), + adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getTableName(), + adTabbox.getSelectedGridTab().getWhereExtended(), findFields, 1, adTabbox.getSelectedGridTab().getAD_Tab_ID()); + + setupEmbeddedFindwindow(); + if (!findWindow.initialize()) { + if (findWindow.getTotalRecords() == 0) { + FDialog.info(curWindowNo, getComponent(), "NoRecordsFound"); + } + return; + } + } + + if (!findWindow.getEventListeners(DialogEvents.ON_WINDOW_CLOSE).iterator().hasNext()) { + findWindow.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + hideBusyMask(); + if (!findWindow.isCancel()) + { + MQuery query = findWindow.getQuery(); + + // Confirmed query + if (query != null) + { + m_onlyCurrentRows = false; // search history too + adTabbox.getSelectedGridTab().setQuery(query); + adTabbox.getSelectedTabpanel().query(m_onlyCurrentRows, m_onlyCurrentDays, MRole.getDefault().getMaxQueryRecords()); // autoSize + } + + if (findWindow.isCreateNew()) + onNew(); + else + adTabbox.getSelectedGridTab().dataRefresh(false); // Elaine 2008/07/25 + } + else + { + toolbar.getButton("Find").setPressed(adTabbox.getSelectedGridTab().isQueryActive()); + } + focusToActivePanel(); + } + }); + } + + showBusyMask(); + getComponent().getParent().appendChild(findWindow); + LayoutUtils.openEmbeddedWindow(toolbar, findWindow, "after_start"); + } + + /** + * @see ToolbarListener#onIgnore() + */ + public void onIgnore() + { + IADTabpanel dirtyTabpanel = adTabbox.getDirtyADTabpanel(); + boolean newrecod = adTabbox.getSelectedGridTab().isNew(); + if (dirtyTabpanel != null && dirtyTabpanel.getGridTab().isSortTab()) + { + dirtyTabpanel.refresh(); + toolbar.enableIgnore(false); + } + else + { + adTabbox.dataIgnore(); + toolbar.enableIgnore(false); + if (newrecod) { + onRefresh(true); + } else if (dirtyTabpanel != null) { + dirtyTabpanel.getGridTab().dataRefresh(true); // update statusbar & toolbar + dirtyTabpanel.dynamicDisplay(0); + } + + } + if (dirtyTabpanel != null) + focusToTabpanel(dirtyTabpanel); + } + + /** + * @see ToolbarListener#onSave() + */ + public void onSave() + { + final IADTabpanel dirtyTabpanel = adTabbox.getDirtyADTabpanel(); + onSave(true, false, new Callback() { + @Override + public void onCallback(Boolean result) + { + if (result) + { + String statusLine = breadCrumb.getStatusLine(); + adTabbox.getSelectedGridTab().dataRefreshAll(true, true); + breadCrumb.setStatusLine(statusLine); + } + if (dirtyTabpanel != null) { + if (dirtyTabpanel == adTabbox.getSelectedDetailADTabpanel()) + Clients.scrollIntoView(dirtyTabpanel); + focusToTabpanel(dirtyTabpanel); + } else { + focusToActivePanel(); + } + } + }); + } + + public void onSavePayment() + { + onSave(false, false, new Callback() { + + @Override + public void onCallback(Boolean result) { + onRefresh(true, false); + } + + }); + } + + /** + * @param onSaveEvent + */ + private void onSave(final boolean onSaveEvent, final boolean onNavigationEvent, final Callback callback) + { + final boolean wasChanged = toolbar.isSaveEnable(); + IADTabpanel dirtyTabpanel = adTabbox.getDirtyADTabpanel(); + final boolean newRecord = dirtyTabpanel != null ? (dirtyTabpanel.getGridTab().getRecord_ID() <= 0) : false; + if (dirtyTabpanel == null) { + onSave0(onSaveEvent, onNavigationEvent, newRecord, wasChanged, callback); + return; + } + if (dirtyTabpanel instanceof ADSortTab) + { + ADSortTab sortTab = (ADSortTab) dirtyTabpanel; + sortTab.saveData(); + + if (!onNavigationEvent) + { + toolbar.enableSave(sortTab.isChanged()); // set explicitly + toolbar.enableIgnore(sortTab.isChanged()); + } + if (!sortTab.isChanged()) { + if (sortTab == adTabbox.getSelectedTabpanel()) { + breadCrumb.setStatusLine(Msg.getMsg(Env.getCtx(), "Saved")); + } else { + adTabbox.setDetailPaneStatusMessage(Msg.getMsg(Env.getCtx(), "Saved"), false); + } + } + if (callback != null) + callback.onCallback(true); + } + else + { + if (!Util.isEmpty(dirtyTabpanel.getGridTab().getCommitWarning()) || + (!Env.isAutoCommit(ctx, curWindowNo) && onNavigationEvent)) + { + FDialog.ask(curWindowNo, this.getComponent(), "SaveChanges?", dirtyTabpanel.getGridTab().getCommitWarning(), new Callback() { + + @Override + public void onCallback(Boolean result) + { + if (result) + { + onSave0(onSaveEvent, onNavigationEvent, newRecord, wasChanged, callback); + } + else + { + if (callback != null) + callback.onCallback(false); + } + } + }); + } + else + { + onSave0(onSaveEvent, onNavigationEvent, newRecord, wasChanged, callback); + } + } + } + + private void onSave0(boolean onSaveEvent, boolean navigationEvent, + boolean newRecord, boolean wasChanged, Callback callback) { + IADTabpanel dirtyTabpanel = adTabbox.getDirtyADTabpanel(); + boolean retValue = adTabbox.dataSave(onSaveEvent); + + if (!retValue) + { + showLastError(); + if (callback != null) + callback.onCallback(false); + return; + } else if (!onSaveEvent && dirtyTabpanel != null) //need manual refresh + { + dirtyTabpanel.getGridTab().setCurrentRow(dirtyTabpanel.getGridTab().getCurrentRow()); + } + + if (!navigationEvent && dirtyTabpanel != null) { + dirtyTabpanel.dynamicDisplay(0); + dirtyTabpanel.afterSave(onSaveEvent); + } + + IADTabpanel dirtyTabpanel2 = adTabbox.getDirtyADTabpanel(); + if (dirtyTabpanel2 != null && dirtyTabpanel2 != dirtyTabpanel) { + onSave(onSaveEvent, navigationEvent, callback); + return; + } + + if (wasChanged) { + if (newRecord) { + if (adTabbox.getSelectedGridTab().getRecord_ID() > 0) { + if (adTabbox.getSelectedIndex() == 0) { + MRecentItem.addModifiedField(ctx, adTabbox.getSelectedGridTab().getAD_Table_ID(), + adTabbox.getSelectedGridTab().getRecord_ID(), Env.getAD_User_ID(ctx), + Env.getAD_Role_ID(ctx), adTabbox.getSelectedGridTab().getAD_Window_ID(), + adTabbox.getSelectedGridTab().getAD_Tab_ID()); + } else { + /* when a detail record is modified add header to recent items */ + GridTab mainTab = gridWindow.getTab(0); + if (mainTab != null) { + MRecentItem.addModifiedField(ctx, mainTab.getAD_Table_ID(), + mainTab.getRecord_ID(), Env.getAD_User_ID(ctx), + Env.getAD_Role_ID(ctx), mainTab.getAD_Window_ID(), + mainTab.getAD_Tab_ID()); + } + } + } + } else { + if (adTabbox.getSelectedIndex() == 0) { + MRecentItem.touchUpdatedRecord(ctx, adTabbox.getSelectedGridTab().getAD_Table_ID(), + adTabbox.getSelectedGridTab().getRecord_ID(), Env.getAD_User_ID(ctx)); + } else { + GridTab mainTab = gridWindow.getTab(0); + if (mainTab != null) { + MRecentItem.touchUpdatedRecord(ctx, mainTab.getAD_Table_ID(), + mainTab.getRecord_ID(), Env.getAD_User_ID(ctx)); + } + } + } + } + + if (dirtyTabpanel != null && dirtyTabpanel.getGridTab().isDetail()) { + dirtyTabpanel.getGridTab().refreshParentTabs(); + } + + if (callback != null) + callback.onCallback(true); + } + + private void showLastError() { + String msg = CLogger.retrieveErrorString(null); + if (msg != null) + { + breadCrumb.setStatusLine(Msg.getMsg(Env.getCtx(), msg), true); + } + //other error will be catch in the dataStatusChanged event + } + + /** + * @see ToolbarListener#onSaveCreate() + */ + public void onSaveCreate() + { + onSave(true, true, new Callback() { + + @Override + public void onCallback(Boolean result) + { + if(result) + { + adTabbox.getSelectedGridTab().dataRefreshAll(true, true); + onNew(); + } + } + }); + } + + /** + * @see ToolbarListener#onDelete() + */ + public void onDelete() + { + if (adTabbox.getSelectedGridTab().isReadOnly()) + { + return; + } + + FDialog.ask(curWindowNo, null, "DeleteRecord?", new Callback() { + + @Override + public void onCallback(Boolean result) + { + if (result) + { + //error will be catch in the dataStatusChanged event + adTabbox.getSelectedGridTab().dataDelete(); + + adTabbox.getSelectedTabpanel().dynamicDisplay(0); + focusToActivePanel(); + } + } + }); + } + + // Elaine 2008/12/01 + /** + * @see ToolbarListener#onDelete() + */ + public void onDeleteSelection() + { + if (adTabbox.getSelectedGridTab().isReadOnly()) + { + return; + } + + //show table with deletion rows -> value, name... + final Window messagePanel = new Window(); + messagePanel.setBorder("normal"); + messagePanel.setWidth("600px"); + messagePanel.setTitle(Msg.getMsg(Env.getCtx(), "Find").replaceAll("&", "") + ": " + title); + messagePanel.setClosable(true); + messagePanel.setSizable(true); + messagePanel.setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "deleteSelection"); + + final Listbox listbox = new Listbox(); + listbox.setHeight("400px"); + + // Display the first 5 fields data exclude Organization, Client and YesNo field data + ArrayList columnNames = new ArrayList(); + GridField[] fields = adTabbox.getSelectedGridTab().getFields(); + if(adTabbox.getSelectedGridTab().getField("DocumentNo")!=null){ + columnNames.add(adTabbox.getSelectedGridTab().getField("DocumentNo").getColumnName()); + } + if(adTabbox.getSelectedGridTab().getField("Line")!=null){ + columnNames.add(adTabbox.getSelectedGridTab().getField("Line").getColumnName()); + } + if(adTabbox.getSelectedGridTab().getField("Value")!=null){ + columnNames.add(adTabbox.getSelectedGridTab().getField("Value").getColumnName()); + } + if(adTabbox.getSelectedGridTab().getField("Name")!=null){ + columnNames.add(adTabbox.getSelectedGridTab().getField("Name").getColumnName()); + } + for(int i = 0; i < fields.length; i++) + { + GridField field = fields[i]; + if(field.getColumnName().equalsIgnoreCase("AD_Org_ID") + || field.getColumnName().equalsIgnoreCase("AD_Client_ID") + || field.getDisplayType() == DisplayType.YesNo) + continue; + if (!columnNames.contains(field.getColumnName())) + { + columnNames.add(field.getColumnName()); + } + } + + ArrayList data = new ArrayList(); + int noOfRows = adTabbox.getSelectedGridTab().getRowCount(); + for(int i=0; i parentColumnNames = adTabbox.getSelectedGridTab().getParentColumnNames(); + for (Iterator iter = parentColumnNames.iterator(); iter.hasNext();) + { + String columnName = iter.next(); + GridField field = adTabbox.getSelectedGridTab().getField(columnName); + if(field.isLookup()){ + Lookup lookup = field.getLookup(); + if (lookup != null){ + displayValue = displayValue.append(lookup.getDisplay(adTabbox.getSelectedGridTab().getValue(i,columnName))).append(" | "); + } else { + displayValue = displayValue.append(adTabbox.getSelectedGridTab().getValue(i,columnName)).append(" | "); + } + } else { + displayValue = displayValue.append(adTabbox.getSelectedGridTab().getValue(i,columnName)).append(" | "); + } + } + } else { + displayValue = displayValue.append(adTabbox.getSelectedGridTab().getValue(i,adTabbox.getSelectedGridTab().getKeyColumnName())); + } + + int count = 0; + for(int j=0; j < columnNames.size() && count < 5; j++) + { + Object value = adTabbox.getSelectedGridTab().getValue(i, columnNames.get(j)); + if(value == null) continue; // skip when value is null + String text = value.toString().trim(); + if(text.length() == 0) continue; // skip when value is empty + GridField field = adTabbox.getSelectedGridTab().getField(columnNames.get(j)); + if(field != null) + { + if (field.isLookup()) + { + Lookup lookup = field.getLookup(); + if (lookup != null) + text = lookup.getDisplay(value); + } + else if (DisplayType.isDate(field.getDisplayType())) + { + text = DisplayType.getDateFormat(field.getDisplayType()).format(value); + } + } + if(text.length() > 30) + text = text.substring(0, 30); // display the first 30 characters + displayValue = displayValue.append(" | ").append(text); + count++; + } + + data.add(displayValue.toString()); + } + + for(int i = 0; i < data.size(); i++) + { + String record = data.get(i); + listbox.appendItem(record, record); + } + + listbox.setMultiple(true); + messagePanel.appendChild(listbox); + + Div div = new Div(); + div.setStyle("text-align: center"); + messagePanel.appendChild(div); + + Hbox hbox = new Hbox(); + div.appendChild(hbox); + + Button btnOk = new Button(); + // Invert - Unify OK/Cancel IDEMPIERE-77 + //btnOk.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "OK"))); + btnOk.setImage("/images/Ok16.png"); + btnOk.addEventListener(Events.ON_CLICK, new EventListener() + { + public void onEvent(Event event) throws Exception + { + FDialog.ask(curWindowNo, messagePanel, "DeleteSelection", new Callback() { + + @Override + public void onCallback(Boolean result) + { + if (result) + { + logger.fine("ok"); + Set selectedValues = listbox.getSelectedItems(); + if(selectedValues != null) + { + for(Iterator iter = selectedValues.iterator(); iter.hasNext();) + { + Listitem li = iter.next(); + if(li != null) + logger.fine((String) li.getValue()); + } + } + + int[] indices = listbox.getSelectedIndices(); + Arrays.sort(indices); + int offset = 0; + for (int i = 0; i < indices.length; i++) + { + adTabbox.getSelectedGridTab().navigate(indices[i]-offset); + if (adTabbox.getSelectedGridTab().dataDelete()) + { + offset++; + } + } + adTabbox.getSelectedTabpanel().dynamicDisplay(0); + + messagePanel.dispose(); + } else { + logger.fine("cancel"); + } + } + + }); + } + }); + hbox.appendChild(btnOk); + + Button btnCancel = new Button(); + //btnCancel.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Cancel"))); + btnCancel.setImage("/images/Cancel16.png"); + btnCancel.addEventListener(Events.ON_CLICK, new EventListener() + { + public void onEvent(Event event) throws Exception + { + messagePanel.dispose(); + } + }); + hbox.appendChild(btnCancel); + hbox.setPack("end"); + hbox.setHflex("1"); + + messagePanel.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + hideBusyMask(); + focusToActivePanel(); + } + }); + showBusyMask(); + getComponent().getParent().appendChild(messagePanel); + LayoutUtils.openOverlappedWindow(getComponent(), messagePanel, "middle_center"); + } + // + + /** + * @see ToolbarListener#onPrint() + */ + public void onPrint() { + //Get process defined for this tab + final int AD_Process_ID = adTabbox.getSelectedGridTab().getAD_Process_ID(); + //log.info("ID=" + AD_Process_ID); + + // No report defined + if (AD_Process_ID == 0) + { + onReport(); + + return; + } + + Callback callback = new Callback() { + @Override + public void onCallback(Boolean result) { + if (result) { + int table_ID = adTabbox.getSelectedGridTab().getAD_Table_ID(); + int record_ID = adTabbox.getSelectedGridTab().getRecord_ID(); + + ProcessModalDialog dialog = new ProcessModalDialog(AbstractADWindowContent.this, getWindowNo(), AD_Process_ID,table_ID, record_ID, true); + if (dialog.isValid()) { + dialog.setWidth("500px"); + dialog.setBorder("normal"); + showBusyMask(); + getComponent().getParent().appendChild(dialog); + LayoutUtils.openOverlappedWindow(getComponent(), dialog, "middle_center"); + dialog.focus(); + } + } + } + }; + onSave(false, false, callback); + } + + /** + * @see ToolbarListener#onReport() + */ + public void onReport() { + if (!MRole.getDefault().isCanReport(adTabbox.getSelectedGridTab().getAD_Table_ID())) + { + FDialog.error(curWindowNo, parent, "AccessCannotReport"); + return; + } + + Callback callback = new Callback() { + + @Override + public void onCallback(Boolean result) { + if (result) { + onReport0(); + } + } + }; + onSave(false, false, callback); + } + + private void onReport0() { + ReportAction reportAction = new ReportAction(this); + reportAction.show(); + } + + /** + * @see ToolbarListener#onZoomAcross() + */ + public void onZoomAcross() { + if (toolbar.getEvent() != null) + { + int record_ID = adTabbox.getSelectedGridTab().getRecord_ID(); + if (record_ID <= 0) + return; + + // Query + MQuery query = new MQuery(); + // Current row + String link = adTabbox.getSelectedGridTab().getKeyColumnName(); + // Link for detail records + if (link.length() == 0) + link = adTabbox.getSelectedGridTab().getLinkColumnName(); + if (link.length() != 0) + { + if (link.endsWith("_ID")) + query.addRestriction(link, MQuery.EQUAL, + new Integer(Env.getContextAsInt(ctx, curWindowNo, link))); + else + query.addRestriction(link, MQuery.EQUAL, + Env.getContext(ctx, curWindowNo, link)); + } + new WZoomAcross(toolbar.getEvent().getTarget(), adTabbox.getSelectedGridTab() + .getTableName(), adTabbox.getSelectedGridTab().getAD_Window_ID(), query); + } + } + + // Elaine 2008/07/17 + /** + * @see ToolbarListener#onActiveWorkflows() + */ + public void onActiveWorkflows() { + if (toolbar.getEvent() != null) + { + if (adTabbox.getSelectedGridTab().getRecord_ID() <= 0) + return; + else + AEnv.startWorkflowProcess(adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getRecord_ID()); + } + } + // + + // Elaine 2008/07/22 + /** + * @see ToolbarListener#onRequests() + */ + public void onRequests() + { + if (toolbar.getEvent() != null) + { + if (adTabbox.getSelectedGridTab().getRecord_ID() <= 0) + return; + + int C_BPartner_ID = 0; + Object bpartner = adTabbox.getSelectedGridTab().getValue("C_BPartner_ID"); + if(bpartner != null) + C_BPartner_ID = Integer.valueOf(bpartner.toString()); + + new WRequest(toolbar.getEvent().getTarget(), adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getRecord_ID(), C_BPartner_ID); + } + } + // + + // Elaine 2008/07/22 + /** + * @see ToolbarListener#onProductInfo() + */ + public void onProductInfo() + { + InfoPanel.showProduct(0); + } + // + + + // Elaine 2008/07/28 + /** + * @see ToolbarListener#onArchive() + */ + public void onArchive() + { + if (toolbar.getEvent() != null) + { + if (adTabbox.getSelectedGridTab().getRecord_ID() <= 0) + return; + + new WArchive(toolbar.getEvent().getTarget(), adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getRecord_ID()); + } + } + + // + + @Override + public void onExport() { + ExportAction action = new ExportAction(this); + action.export(); + } + + @Override + public void onFileImport() { + FileImportAction action = new FileImportAction(this); + action.fileImport(); + } + + /************************************************************************** + * Start Button Process + * @param vButton button + */ + private void actionButton (final IProcessButton wButton) + { + if (adTabbox.getSelectedGridTab().hasChangedCurrentTabAndParents()) { + String msg = CLogger.retrieveErrorString("Please ReQuery Window"); + FDialog.error(curWindowNo, parent, null, msg); + return; + } + + logger.info(wButton.toString()); + + final String col = wButton.getColumnName(); + + // Zoom + if (col.equals("Record_ID")) + { + int AD_Table_ID = Env.getContextAsInt (ctx, curWindowNo, "AD_Table_ID"); + int Record_ID = Env.getContextAsInt (ctx, curWindowNo, "Record_ID"); + + AEnv.zoom(AD_Table_ID, Record_ID); + return; + } // Zoom + + // save first --------------- + + if (adTabbox.needSave(true, false)) + { + onSave(false, false, new Callback() { + @Override + public void onCallback(Boolean result) { + if (result) { + actionButton0(col, wButton); + } + } + }); + } + else + { + actionButton0(col, wButton); + } + } + + /************************************************************************** + * Start Button Process + * @param col + * @param wButton + */ + private void actionButton0 (String col, final IProcessButton wButton) + { + final IADTabpanel adtabPanel = findADTabpanel(wButton); + boolean startWOasking = false; + final int table_ID = adtabPanel.getGridTab().getAD_Table_ID(); + + // Record_ID + + int record_ID = adtabPanel.getGridTab().getRecord_ID(); + + // Record_ID - Language Handling + + if (record_ID == -1 && adtabPanel.getGridTab().getKeyColumnName().equals("AD_Language")) + record_ID = Env.getContextAsInt (ctx, curWindowNo, "AD_Language_ID"); + + // Record_ID - Change Log ID + + if (record_ID == -1 + && (wButton.getProcess_ID() == PROCESS_AD_CHANGELOG_UNDO || wButton.getProcess_ID() == PROCESS_AD_CHANGELOG_REDO)) + { + Integer id = (Integer)adtabPanel.getGridTab().getValue("AD_ChangeLog_ID"); + record_ID = id.intValue(); + } + + // Ensure it's saved + + if (record_ID == -1 && adtabPanel.getGridTab().getKeyColumnName().endsWith("_ID")) + { + FDialog.error(curWindowNo, parent, "SaveErrorRowNotFound"); + return; + } + + boolean isProcessMandatory = false; + // Pop up Document Action (Workflow) + if (col.equals("DocAction")) + { + final WDocActionPanel win = new WDocActionPanel(adtabPanel.getGridTab()); + if (win.getNumberOfOptions() == 0) + { + logger.info("DocAction - No Options"); + return; + } + else + { + final int recordIdParam = record_ID; + win.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + public void onEvent(Event event) throws Exception { + hideBusyMask(); + if (!win.isStartProcess()) { + return; + } + boolean startWOasking = true; + boolean isProcessMandatory = true; + executeButtonProcess(wButton, startWOasking, table_ID, recordIdParam, isProcessMandatory); + } + }); + showBusyMask(); + getComponent().getParent().appendChild(win); + LayoutUtils.openOverlappedWindow(getComponent(), win, "middle_center"); + win.focus(); + return; + } + } // DocAction + + // Pop up Create From + else if (col.equals("CreateFrom")) + { + ICreateFrom cf = WCreateFromFactory.create(adtabPanel.getGridTab()); + + if(cf != null) + { + if(cf.isInitOK()) + { + final WCreateFromWindow window = (WCreateFromWindow) cf.getWindow(); + window.setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, AdempiereIdGenerator.escapeId(window.getTitle())); + window.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + hideBusyMask(); + if (!window.isCancel()) { + onRefresh(true, false); + } + } + }); + window.setZindex(1000); + window.setMaximizable(true); + window.setSizable(true); + ZkCssHelper.appendStyle(window, "position: absolute; "); + showBusyMask(); + getComponent().getParent().appendChild(window); + cf.showWindow(); + LayoutUtils.openOverlappedWindow(getComponent(), window, "middle_center"); + window.focus(); + } + return; + } + // else may start process + } // CreateFrom + + // Posting ----- + + else if (col.equals("Posted") && MRole.getDefault().isShowAcct()) + { + // Check Doc Status + + String processed = Env.getContext(ctx, curWindowNo, "Processed"); + + if (!processed.equals("Y")) + { + String docStatus = Env.getContext(ctx, curWindowNo, "DocStatus"); + + if (DocAction.STATUS_Completed.equals(docStatus) + || DocAction.STATUS_Closed.equals(docStatus) + || DocAction.STATUS_Reversed.equals(docStatus) + || DocAction.STATUS_Voided.equals(docStatus)) + ; + else + { + FDialog.error(curWindowNo, parent, "PostDocNotComplete"); + return; + } + } + + // try to get table and record id from context data (eg for unposted view) + // otherwise use current table/record + int tableId = Env.getContextAsInt(ctx, curWindowNo, "AD_Table_ID", true); + int recordId = Env.getContextAsInt(ctx, curWindowNo, "Record_ID", true); + if ( tableId == 0 || recordId == 0 ) + { + tableId = adtabPanel.getGridTab().getAD_Table_ID(); + recordId = adtabPanel.getGridTab().getRecord_ID(); + } + + // Check Post Status + final Object ps = adtabPanel.getGridTab().getValue("Posted"); + + if (ps != null && ps.equals("Y")) + { + new org.adempiere.webui.acct.WAcctViewer(Env.getContextAsInt (ctx, curWindowNo, "AD_Client_ID"), + tableId, recordId); + } + else + { + final int tableIdRef = tableId; + final int recordIdRef = recordId; + FDialog.ask(curWindowNo, null, "PostImmediate?", new Callback() { + + @Override + public void onCallback(Boolean result) + { + if (result) + { + boolean force = ps != null && !ps.equals ("N"); // force when problems + + String error = AEnv.postImmediate (curWindowNo, Env.getAD_Client_ID(ctx), + tableIdRef, recordIdRef, force); + + if (error != null) + breadCrumb.setStatusLine(error, true); + + onRefresh(true, false); + } + } + }); + } + return; + } // Posted + + executeButtonProcess(wButton, startWOasking, table_ID, record_ID, + isProcessMandatory); + } // actionButton + + private Div getMaskDiv() { + if (maskDiv == null) { + maskDiv = new Div(); + maskDiv.setStyle("position: absolute; width: 100%; height: 100%; border: none; margin: 0; background-color: #e4e4e4; " + + "padding: 0; z-index:999; opacity:0.6; top: 0px; left: 0px;"); + } + return maskDiv; + } + + public void hideBusyMask() { + if (maskDiv != null && maskDiv.getParent() != null) { + maskDiv.detach(); + } + } + + public void showBusyMask() { + getComponent().getParent().appendChild(getMaskDiv()); + } + + private void executeButtonProcess(final IProcessButton wButton, + final boolean startWOasking, final int table_ID, final int record_ID, + boolean isProcessMandatory) { + /** + * Start Process ---- + */ + + logger.config("Process_ID=" + wButton.getProcess_ID() + ", Record_ID=" + record_ID); + + if (wButton.getProcess_ID() == 0) + { + if (isProcessMandatory) + { + FDialog.error(curWindowNo, null, null, Msg.parseTranslation(ctx, "@NotFound@ @AD_Process_ID@")); + } + return; + } + + // Save item changed + + if (adTabbox.needSave(true, false)) + { + onSave(false, false, new Callback() { + + @Override + public void onCallback(Boolean result) { + if (result) { + executeButtonProcess0(wButton, startWOasking, table_ID, record_ID); + } + } + }); + } + else + { + executeButtonProcess0(wButton, startWOasking, table_ID, record_ID); + } + } + + private void executeButtonProcess0(final IProcessButton wButton, + boolean startWOasking, int table_ID, int record_ID) { + // call form + MProcess pr = new MProcess(ctx, wButton.getProcess_ID(), null); + int adFormID = pr.getAD_Form_ID(); + if (adFormID != 0 ) + { + String title = wButton.getDescription(); + if (title == null || title.length() == 0) + title = wButton.getDisplay(); + + ProcessInfo pi = new ProcessInfo (title, wButton.getProcess_ID(), table_ID, record_ID); + pi.setAD_User_ID (Env.getAD_User_ID(ctx)); + pi.setAD_Client_ID (Env.getAD_Client_ID(ctx)); + ADForm form = ADForm.openForm(adFormID); + form.setProcessInfo(pi); + Mode mode = form.getWindowMode(); + form.setAttribute(Window.MODE_KEY, form.getWindowMode()); + form.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT); + + final IADTabpanel adtabPanel = findADTabpanel(wButton); + if (adtabPanel != null) + form.setGridTab(adtabPanel.getGridTab()); + + if (mode == Mode.HIGHLIGHTED || mode == Mode.MODAL) { + form.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + hideBusyMask(); + onRefresh(true, false); + } + }); + showBusyMask(); + LayoutUtils.openOverlappedWindow(getComponent(), form, "middle_center"); + form.focus(); + } + else { + SessionManager.getAppDesktop().showWindow(form); + } + } + else + { + ProcessModalDialog dialog = new ProcessModalDialog(this, curWindowNo, wButton.getProcess_ID(), table_ID, record_ID, startWOasking); + + if (dialog.isValid()) + { + dialog.setWidth("500px"); + dialog.setBorder("normal"); + showBusyMask(); + getComponent().getParent().appendChild(dialog); + LayoutUtils.openOverlappedWindow(getComponent(), dialog, "middle_center"); + dialog.focus(); + } + else + { + onRefresh(true, false); + } + } + } + + /** + * @param event + * @see ActionListener#actionPerformed(ActionEvent) + */ + public void actionPerformed(final ActionEvent event) + { + Runnable runnable = new Runnable() { + public void run() { + String error = processButtonCallout((IProcessButton) event.getSource()); + if (error != null && error.trim().length() > 0) + { + breadCrumb.setStatusLine(error, true); + return; + } + actionButton((IProcessButton) event.getSource()); + } + }; + BusyDialogTemplate template = new BusyDialogTemplate(runnable); + template.run(); + } + + /************************************************************************** + * Process Callout(s). + *

    + * The Callout is in the string of + * "class.method;class.method;" + * If there is no class name, i.e. only a method name, the class is regarded + * as CalloutSystem. + * The class needs to comply with the Interface Callout. + * + * @param field field + * @return error message or "" + * @see org.compiere.model.Callout + */ + private String processButtonCallout (IProcessButton button) + { + IADTabpanel adtab = findADTabpanel(button); + if (adtab != null) { + GridField field = adtab.getGridTab().getField(button.getColumnName()); + if (field != null) + return adtab.getGridTab().processCallout(field); + else + return ""; + } else { + return ""; + } + } // processButtonCallout + + public IADTabpanel findADTabpanel(IProcessButton button) { + IADTabpanel adtab = null; + if (button.getADTabpanel() != null) + return button.getADTabpanel(); + + Component c = button instanceof WEditor ? ((WEditor)button).getComponent() : (Component)button; + while (c != null) { + if (c instanceof IADTabpanel) { + adtab = (IADTabpanel) c; + break; + } + c = c.getParent(); + } + return adtab; + } + + /** + * + * @return IADTab + */ + public IADTabbox getADTab() { + return adTabbox; + } + + /** + * @param pi + */ + public void executeASync(ProcessInfo pi) { + } + + /** + * @param pi + */ + private void onModalClose(ProcessInfo pi) { + boolean notPrint = pi != null + && pi.getAD_Process_ID() != adTabbox.getSelectedGridTab().getAD_Process_ID() + && pi.isReportingProcess() == false; + // + // Process Result + + if (Executions.getCurrent() != null) + { + if (notPrint) // refresh if not print + { + updateUI(pi); + } + } + else + { + try { + //acquire desktop, 2 second timeout + Executions.activate(getComponent().getDesktop(), 2000); + try { + if (notPrint) // refresh if not print + { + updateUI(pi); + } + } catch(Error ex){ + throw ex; + } finally{ + //release full control of desktop + Executions.deactivate(getComponent().getDesktop()); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Failed to update UI upon unlock.", e); + } + } + } + + private void updateUI(ProcessInfo pi) { + // Timeout + if (pi.isTimeout()) // set temporarily to R/O + Env.setContext(ctx, curWindowNo, "Processed", "Y"); + // Update Status Line + String summary = pi.getSummary(); + if (summary != null && summary.indexOf('@') != -1) + pi.setSummary(Msg.parseTranslation(Env.getCtx(), summary)); + + // Get Log Info + ProcessInfoUtil.setLogFromDB(pi); + ProcessInfoLog m_logs[] = pi.getLogs(); + breadCrumb.setStatusLine(pi.getSummary(), pi.isError(),m_logs); + if (m_logs != null) { + ProcessInfoDialog dialog = new ProcessInfoDialog(AEnv.getDialogHeader(ctx, curWindowNo),Env.getHeader(ctx, curWindowNo), m_logs); + dialog.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + hideBusyMask(); + } + }); + showBusyMask(); + getComponent().getParent().appendChild(dialog); + LayoutUtils.openOverlappedWindow(this.getComponent(),dialog,"middle_center"); + } + + } + + /** + * + * @return toolbar instance + */ + public ADWindowToolbar getToolbar() { + return toolbar; + } + + /** + * @return active grid tab + */ + public GridTab getActiveGridTab() { + return adTabbox.getSelectedGridTab(); + } + + /** + * @return windowNo + */ + public int getWindowNo() { + return curWindowNo; + } + + /** + * @see ToolbarListener#onCustomize() + */ + public void onCustomize() { + ADTabpanel tabPanel = (ADTabpanel) getADTab().getSelectedTabpanel(); + Columns columns = tabPanel.getGridView().getListbox().getColumns(); + List columnList = columns.getChildren(); + GridField[] fields = tabPanel.getGridView().getFields(); + Map columnsWidth = new HashMap(); + ArrayList gridFieldIds = new ArrayList(); + for (int i = 0; i < fields.length; i++) { + Column column = (Column) columnList.get(i+1); + String width = column.getWidth(); + columnsWidth.put(fields[i].getAD_Field_ID(), width); + gridFieldIds.add(fields[i].getAD_Field_ID()); + + } + CustomizeGridViewDialog.showCustomize(0, adTabbox.getSelectedGridTab().getAD_Tab_ID(), columnsWidth,gridFieldIds,tabPanel.getGridView()); + } + + /** + * @see org.adempiere.webui.event.ToolbarListener#onProcess() + */ + @Override + public void onProcess() { + ProcessButtonPopup popup = new ProcessButtonPopup(); + popup.setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "processButtonPopup"); + ADTabpanel adtab = (ADTabpanel) adTabbox.getSelectedTabpanel(); + popup.render(adtab.getToolbarButtons()); + + LayoutUtils.openPopupWindow(toolbar.getButton("Process"), popup, "after_start"); + } +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/DefaultCreateFromFactory.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/DefaultCreateFromFactory.java index d745d5960f..ee71e674c7 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/DefaultCreateFromFactory.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/DefaultCreateFromFactory.java @@ -32,30 +32,21 @@ public class DefaultCreateFromFactory implements ICreateFromFactory { @Override - public ICreateFrom create(GridTab mTab, String columnName) + public ICreateFrom create(GridTab mTab) { String tableName = mTab.getTableName(); - if (columnName.equals("CreateFrom")) - { - if (tableName.equals(I_C_Invoice.Table_Name)) - return new WCreateFromInvoiceUI(mTab); - else if (tableName.equals(I_C_BankStatement.Table_Name)) -// return new WCreateFromStatementUI(mTab); - return new WCreateFromStatementBatchUI(mTab); - else if (tableName.equals(I_M_InOut.Table_Name)) - return new WCreateFromShipmentUI(mTab); - else if (tableName.equals(I_M_RMA.Table_Name)) - return new WCreateFromRMAUI(mTab); - else if (tableName.equals(I_M_PackageMPS.Table_Name)) - return new WCreateFromPackageShipmentUI(mTab); - else if (tableName.equals(I_X_DepositBatch.Table_Name)) - return new WCreateFromDepositBatchUI(mTab); - } - else if (columnName.equalsIgnoreCase("X_CreateFromBatch")) - { - if (tableName.equals(I_C_BankStatement.Table_Name)) - return new WCreateFromBatchStatementUI(mTab); - } + if (tableName.equals(I_C_Invoice.Table_Name)) + return new WCreateFromInvoiceUI(mTab); + else if (tableName.equals(I_C_BankStatement.Table_Name)) + return new WCreateFromStatementUI(mTab); + else if (tableName.equals(I_M_InOut.Table_Name)) + return new WCreateFromShipmentUI(mTab); + else if (tableName.equals(I_M_RMA.Table_Name)) + return new WCreateFromRMAUI(mTab); + else if (tableName.equals(I_M_PackageMPS.Table_Name)) + return new WCreateFromPackageShipmentUI(mTab); + else if (tableName.equals(I_X_DepositBatch.Table_Name)) + return new WCreateFromDepositBatchUI(mTab); return null; } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java index 2b11a32429..6527b5b55c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java @@ -22,13 +22,13 @@ import org.compiere.model.GridTab; public class WCreateFromFactory { - public static ICreateFrom create (GridTab mTab, String columnName) + public static ICreateFrom create (GridTab mTab) { ICreateFrom createFrom = null; List factories = Service.locator().list(ICreateFromFactory.class).getServices(); for (ICreateFromFactory factory : factories) { - createFrom = factory.create(mTab, columnName); + createFrom = factory.create(mTab); if (createFrom != null) break; } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromForm.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromForm.java new file mode 100644 index 0000000000..b6380228ef --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromForm.java @@ -0,0 +1,269 @@ +/****************************************************************************** + * Copyright (C) 2013 Elaine Tan * + * Copyright (C) 2013 Trek Global + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.webui.apps.form; + +import org.adempiere.webui.component.Button; +import org.adempiere.webui.component.ConfirmPanel; +import org.adempiere.webui.component.ListModelTable; +import org.adempiere.webui.component.ListboxFactory; +import org.adempiere.webui.component.Panel; +import org.adempiere.webui.component.WAppsAction; +import org.adempiere.webui.component.WListbox; +import org.adempiere.webui.event.DialogEvents; +import org.adempiere.webui.event.WTableModelEvent; +import org.adempiere.webui.event.WTableModelListener; +import org.adempiere.webui.panel.ADForm; +import org.adempiere.webui.panel.StatusBarPanel; +import org.adempiere.webui.window.FDialog; +import org.compiere.apps.form.CreateFromForm; +import org.compiere.util.Env; +import org.compiere.util.Msg; +import org.compiere.util.Trx; +import org.compiere.util.TrxRunnable; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.util.Clients; +import org.zkoss.zul.Borderlayout; +import org.zkoss.zul.Center; +import org.zkoss.zul.North; +import org.zkoss.zul.Separator; +import org.zkoss.zul.South; + +/** + * + * @author Elaine + * + */ +public class WCreateFromForm extends ADForm implements EventListener, WTableModelListener, DialogEvents +{ + + /** + * + */ + private static final long serialVersionUID = -3703236565441597403L; + private CreateFromForm form; + + private Panel parameterPanel = new Panel(); + private ConfirmPanel confirmPanel = new ConfirmPanel(true); + private StatusBarPanel statusBar = new StatusBarPanel(); + private WListbox dataTable = ListboxFactory.newDataTable(); + + private boolean isCancel; + + public static final String SELECT_ALL = "SelectAll"; + + public WCreateFromForm(CreateFromForm createFrom) + { + super(); + this.form = createFrom; + } + + protected void initForm() + { + try + { + zkInit(); + confirmPanel.addActionListener(this); + + statusBar.setStatusDB(""); + tableChanged(null); + } + catch(Exception e) + { + + } + } + + protected void zkInit() throws Exception + { + Borderlayout contentPane = new Borderlayout(); + appendChild(contentPane); + + North north = new North(); + contentPane.appendChild(north); + north.appendChild(parameterPanel); + + Center center = new Center(); + contentPane.appendChild(center); + center.appendChild(dataTable); + + WAppsAction selectAllAction = new WAppsAction (SELECT_ALL, null, null); + Button selectAllButton = selectAllAction.getButton(); + confirmPanel.addComponentsLeft(selectAllButton); + selectAllButton.addActionListener(this); + + South south = new South(); + contentPane.appendChild(south); + Panel southPanel = new Panel(); + south.appendChild(southPanel); + southPanel.appendChild(new Separator()); + southPanel.appendChild(confirmPanel); + + southPanel.appendChild(new Separator()); + southPanel.appendChild(statusBar); + + setWidth("750px"); + setHeight("550px"); + setSizable(true); + setBorder("normal"); + contentPane.setWidth("100%"); + contentPane.setHeight("100%"); + } + + public void onEvent(Event e) throws Exception + { + // OK - Save + if (e.getTarget().getId().equals(ConfirmPanel.A_OK)) + { + isCancel = false; + try + { + Trx.run(new TrxRunnable() + { + public void run(String trxName) + { + save(trxName); + } + }); + dispose(); + } + catch (Exception ex) + { + FDialog.error(getWindowNo(), this, "Error", ex.getLocalizedMessage()); + } + } + // Cancel + else if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) + { + isCancel = true; + dispose(); + } + // Select All + // Trifon + else if (e.getTarget().getId().equals(SELECT_ALL)) { + ListModelTable model = dataTable.getModel(); + int rows = model.getSize(); + for (int i = 0; i < rows; i++) + { + model.setValueAt(new Boolean(true), i, 0); + } + //refresh + dataTable.setModel(model); + info(); + } + } + + public void tableChanged (WTableModelEvent e) + { + int type = -1; + if (e != null) + { + type = e.getType(); + if (type != WTableModelEvent.CONTENTS_CHANGED) + return; + } + info(); + } + + public boolean save(String trxName) + { + ListModelTable model = dataTable.getModel(); + int rows = model.getSize(); + if (rows == 0) + return false; + + return form.save(dataTable, trxName, getGridTab()); + } + + public void info() + { + ListModelTable model = dataTable.getModel(); + int rows = model.getRowCount(); + int count = 0; + for (int i = 0; i < rows; i++) + { + if (((Boolean) model.getValueAt(i, 0)).booleanValue()) + count++; + } + setStatusLine(count, null); + + form.info(dataTable, statusBar); + } + + public void setStatusLine(int selectedRowCount, String text) + { + StringBuilder sb = new StringBuilder(String.valueOf(selectedRowCount)); + if (text != null && text.trim().length() > 0) { + sb.append(" - ").append(text); + } + statusBar.setStatusLine(sb.toString()); + // + confirmPanel.getOKButton().setEnabled(selectedRowCount > 0); + } + + public WListbox getWListbox() + { + return dataTable; + } + + public Panel getParameterPanel() + { + return parameterPanel; + } + + public ConfirmPanel getConfirmPanel() + { + return confirmPanel; + } + + public boolean isCancel() + { + return isCancel; + } + + public void postQueryEvent() + { + Clients.showBusy(Msg.getMsg(Env.getCtx(), "Processing")); + Events.echoEvent("onExecuteQuery", this, null); + } + + /** + * Dont call this directly, use internally to handle execute query event + */ + public void onExecuteQuery() + { + try + { + form.executeQuery(); + } + finally + { + Clients.clearBusy(); + } + } + + @Override + public Mode getWindowMode() { + return Mode.HIGHLIGHTED; + } + + @Override + public boolean setVisible(boolean visible) { + boolean ok = super.setVisible(visible); + if (visible && getProcessInfo() != null) + form.initForm(); + return ok; + } +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementBatchUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementBatchUI.java deleted file mode 100644 index e0b9e0d8f7..0000000000 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementBatchUI.java +++ /dev/null @@ -1,311 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2013 Elaine Tan * - * Copyright (C) 2013 Trek Global - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - *****************************************************************************/ -package org.adempiere.webui.apps.form; - -import static org.compiere.model.SystemIDs.COLUMN_C_BANKSTATEMENT_C_BANKACCOUNT_ID; - -import java.sql.Timestamp; -import java.util.Vector; -import java.util.logging.Level; - -import org.adempiere.webui.apps.AEnv; -import org.adempiere.webui.component.Button; -import org.adempiere.webui.component.Column; -import org.adempiere.webui.component.Columns; -import org.adempiere.webui.component.ConfirmPanel; -import org.adempiere.webui.component.Grid; -import org.adempiere.webui.component.GridFactory; -import org.adempiere.webui.component.Label; -import org.adempiere.webui.component.ListModelTable; -import org.adempiere.webui.component.Panel; -import org.adempiere.webui.component.Row; -import org.adempiere.webui.component.Rows; -import org.adempiere.webui.editor.WDateEditor; -import org.adempiere.webui.editor.WEditor; -import org.adempiere.webui.editor.WNumberEditor; -import org.adempiere.webui.editor.WSearchEditor; -import org.adempiere.webui.editor.WStringEditor; -import org.adempiere.webui.editor.WTableDirEditor; -import org.adempiere.webui.window.FDialog; -import org.compiere.grid.CreateFromStatementBatch; -import org.compiere.model.GridTab; -import org.compiere.model.MBankStatement; -import org.compiere.model.MColumn; -import org.compiere.model.MLookup; -import org.compiere.model.MLookupFactory; -import org.compiere.model.MPayment; -import org.compiere.util.CLogger; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.EventListener; -import org.zkoss.zk.ui.event.Events; -import org.zkoss.zul.Borderlayout; -import org.zkoss.zul.Center; -import org.zkoss.zul.Hbox; - -/** - * - * @author Elaine - * - */ -public class WCreateFromStatementBatchUI extends CreateFromStatementBatch implements EventListener -{ - private WCreateFromWindow window; - - public WCreateFromStatementBatchUI(GridTab tab) - { - super(tab); - log.info(getGridTab().toString()); - - window = new WCreateFromWindow(this, getGridTab().getWindowNo()); - - p_WindowNo = getGridTab().getWindowNo(); - - try - { - if (!dynInit()) - return; - zkInit(); - setInitOK(true); - } - catch(Exception e) - { - log.log(Level.SEVERE, "", e); - setInitOK(false); - } - AEnv.showWindow(window); - } - - /** Window No */ - private int p_WindowNo; - - /** Logger */ - private CLogger log = CLogger.getCLogger(getClass()); - - protected Label bankAccountLabel = new Label(); - protected WTableDirEditor bankAccountField; - - protected Label documentNoLabel = new Label(Msg.translate(Env.getCtx(), "DocumentNo")); - protected WStringEditor documentNoField = new WStringEditor(); - - protected Label documentTypeLabel = new Label(); - protected WTableDirEditor documentTypeField; - - protected Label authorizationLabel = new Label(); - protected WStringEditor authorizationField = new WStringEditor(); - - protected Label tenderTypeLabel = new Label(); - protected WTableDirEditor tenderTypeField; - - protected Label amtFromLabel = new Label(Msg.translate(Env.getCtx(), "PayAmt")); - protected WNumberEditor amtFromField = new WNumberEditor("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom")); - protected Label amtToLabel = new Label("-"); - protected WNumberEditor amtToField = new WNumberEditor("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo")); - - protected Label BPartner_idLabel = new Label(Msg.translate(Env.getCtx(), "BPartner")); - protected WEditor bPartnerLookup; - - protected Label dateFromLabel = new Label(Msg.translate(Env.getCtx(), "DateTrx")); - protected WDateEditor dateFromField = new WDateEditor("DateFrom", false, false, true, Msg.translate(Env.getCtx(), "DateFrom")); - protected Label dateToLabel = new Label("-"); - protected WDateEditor dateToField = new WDateEditor("DateTo", false, false, true, Msg.translate(Env.getCtx(), "DateTo")); - - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - public boolean dynInit() throws Exception - { - log.config(""); - - super.dynInit(); - - //Refresh button - Button refreshButton = window.getConfirmPanel().createButton(ConfirmPanel.A_REFRESH); - refreshButton.addEventListener(Events.ON_CLICK, this); - window.getConfirmPanel().addButton(refreshButton); - - if (getGridTab().getValue("C_BankStatement_ID") == null) - { - FDialog.error(0, window, "SaveErrorRowNotFound"); - return false; - } - - window.setTitle(getTitle()); - - int AD_Column_ID = COLUMN_C_BANKSTATEMENT_C_BANKACCOUNT_ID; // C_BankStatement.C_BankAccount_ID - MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir); - bankAccountField = new WTableDirEditor ("C_BankAccount_ID", true, false, true, lookup); - // Set Default - int C_BankAccount_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BankAccount_ID"); - bankAccountField.setValue(new Integer(C_BankAccount_ID)); - // initial Loading - authorizationField = new WStringEditor ("authorization", false, false, true, 10, 30, null, null); - authorizationField.getComponent().addEventListener(Events.ON_CHANGE, this); - - lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_DocType_ID), DisplayType.TableDir); - documentTypeField = new WTableDirEditor (MPayment.COLUMNNAME_C_DocType_ID,false,false,true,lookup); - documentTypeField.getComponent().addEventListener(Events.ON_CHANGE, this); - - lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_TenderType), DisplayType.List); - tenderTypeField = new WTableDirEditor (MPayment.COLUMNNAME_TenderType,false,false,true,lookup); - tenderTypeField.getComponent().addEventListener(Events.ON_CHANGE, this); - - lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search); - bPartnerLookup = new WSearchEditor ("C_BPartner_ID", false, false, true, lookup); - - Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate); - dateToField.setValue(date); - - loadBankAccount(); - - return true; - } // dynInit - - protected void zkInit() throws Exception - { - bankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); - authorizationLabel.setText(Msg.translate(Env.getCtx(), "R_AuthCode")); - - documentTypeLabel.setText(Msg.translate(Env.getCtx(), "C_DocType_ID")); - tenderTypeLabel.setText(Msg.translate(Env.getCtx(), "TenderType")); - - dateFromField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "DateFrom")); - dateToField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "DateTo")); - - amtFromField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "AmtFrom")); - amtToField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "AmtTo")); - - Borderlayout parameterLayout = new Borderlayout(); - parameterLayout.setHeight("130px"); - parameterLayout.setWidth("100%"); - Panel parameterPanel = window.getParameterPanel(); - parameterPanel.appendChild(parameterLayout); - - Grid parameterBankLayout = GridFactory.newGridLayout(); - Panel parameterBankPanel = new Panel(); - parameterBankPanel.appendChild(parameterBankLayout); - - Center center = new Center(); - parameterLayout.appendChild(center); - center.appendChild(parameterBankPanel); - - Columns columns = new Columns(); - parameterBankLayout.appendChild(columns); - Column column = new Column(); - columns.appendChild(column); - column = new Column(); - column.setWidth("15%"); - columns.appendChild(column); - column.setWidth("35%"); - column = new Column(); - column.setWidth("15%"); - columns.appendChild(column); - column = new Column(); - column.setWidth("35%"); - columns.appendChild(column); - - Rows rows = (Rows) parameterBankLayout.newRows(); - Row row = rows.newRow(); - row.appendChild(bankAccountLabel.rightAlign()); - row.appendChild(bankAccountField.getComponent()); - row.appendChild(documentNoLabel.rightAlign()); - row.appendChild(documentNoField.getComponent()); - - row = rows.newRow(); - row.appendChild(documentTypeLabel.rightAlign()); - row.appendChild(documentTypeField.getComponent()); - row.appendChild(authorizationLabel.rightAlign()); - row.appendChild(authorizationField.getComponent()); - - row = rows.newRow(); - row.appendChild(tenderTypeLabel.rightAlign()); - row.appendChild(tenderTypeField.getComponent()); - - row.appendChild(amtFromLabel.rightAlign()); - Hbox hbox = new Hbox(); - hbox.appendChild(amtFromField.getComponent()); - hbox.appendChild(amtToLabel.rightAlign()); - hbox.appendChild(amtToField.getComponent()); - row.appendChild(hbox); - - row = rows.newRow(); - row.appendChild(BPartner_idLabel.rightAlign()); - row.appendChild(bPartnerLookup.getComponent()); - row.appendChild(dateFromLabel.rightAlign()); - - hbox = new Hbox(); - hbox.appendChild(dateFromField.getComponent()); - hbox.appendChild(dateToLabel.rightAlign()); - hbox.appendChild(dateToField.getComponent()); - row.appendChild(hbox); - } - - /** - * Action Listener - * @param e event - * @throws Exception - */ - public void onEvent(Event e) throws Exception - { - log.config("Action=" + e.getTarget().getId()); - if(e.getTarget().equals(window.getConfirmPanel().getButton(ConfirmPanel.A_REFRESH))) - { - loadBankAccount(); - window.tableChanged(null); - } - } - - protected void loadBankAccount() - { - loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), - documentNoField.getValue().toString(), dateFromField.getValue(), dateToField.getValue(), - amtFromField.getValue(), amtToField.getValue(), - documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getValue().toString())); - } - - protected void loadTableOIS (Vector data) - { - window.getWListbox().clear(); - - // Remove previous listeners - window.getWListbox().getModel().removeTableModelListener(window); - // Set Model - ListModelTable model = new ListModelTable(data); - model.addTableModelListener(window); - window.getWListbox().setData(model, getOISColumnNames()); - // - - configureMiniTable(window.getWListbox()); - } - - public void showWindow() - { - window.setVisible(true); - } - - public void closeWindow() - { - window.dispose(); - } - - @Override - public Object getWindow() - { - return window; - } -} \ No newline at end of file diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementUI.java index ec1a025f62..64ad256cf6 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementUI.java @@ -1,6 +1,6 @@ /****************************************************************************** - * Copyright (C) 2009 Low Heng Sin * - * Copyright (C) 2009 Idalica Corporation * + * Copyright (C) 2013 Elaine Tan * + * Copyright (C) 2013 Trek Global * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * * by the Free Software Foundation. This program is distributed in the hope * @@ -21,6 +21,8 @@ import java.util.logging.Level; import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.component.Button; +import org.adempiere.webui.component.Column; +import org.adempiere.webui.component.Columns; import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.Grid; import org.adempiere.webui.component.GridFactory; @@ -38,7 +40,6 @@ import org.adempiere.webui.editor.WTableDirEditor; import org.adempiere.webui.window.FDialog; import org.compiere.grid.CreateFromStatement; import org.compiere.model.GridTab; -import org.compiere.model.MBankAccount; import org.compiere.model.MBankStatement; import org.compiere.model.MColumn; import org.compiere.model.MLookup; @@ -55,6 +56,11 @@ import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Center; import org.zkoss.zul.Hbox; +/** + * + * @author Elaine + * + */ public class WCreateFromStatementUI extends CreateFromStatement implements EventListener { private WCreateFromWindow window; @@ -88,7 +94,7 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event /** Logger */ private CLogger log = CLogger.getCLogger(getClass()); - + protected Label bankAccountLabel = new Label(); protected WTableDirEditor bankAccountField; @@ -164,8 +170,6 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate); dateToField.setValue(date); - - bankAccount = new MBankAccount(Env.getCtx(), C_BankAccount_ID, null); loadBankAccount(); @@ -187,7 +191,7 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event amtToField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "AmtTo")); Borderlayout parameterLayout = new Borderlayout(); - parameterLayout.setHeight("110px"); + parameterLayout.setHeight("130px"); parameterLayout.setWidth("100%"); Panel parameterPanel = window.getParameterPanel(); parameterPanel.appendChild(parameterLayout); @@ -200,6 +204,21 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event parameterLayout.appendChild(center); center.appendChild(parameterBankPanel); + Columns columns = new Columns(); + parameterBankLayout.appendChild(columns); + Column column = new Column(); + columns.appendChild(column); + column = new Column(); + column.setWidth("15%"); + columns.appendChild(column); + column.setWidth("35%"); + column = new Column(); + column.setWidth("15%"); + columns.appendChild(column); + column = new Column(); + column.setWidth("35%"); + columns.appendChild(column); + Rows rows = (Rows) parameterBankLayout.newRows(); Row row = rows.newRow(); row.appendChild(bankAccountLabel.rightAlign()); @@ -253,9 +272,10 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event protected void loadBankAccount() { - loadTableOIS(getBankData(documentNoField.getValue().toString(), bPartnerLookup.getValue(), dateFromField.getValue(), dateToField.getValue(), - amtFromField.getValue(), amtToField.getValue(), documentTypeField.getValue(), tenderTypeField.getValue(), - authorizationField.getValue().toString())); + loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), + documentNoField.getValue().toString(), dateFromField.getValue(), dateToField.getValue(), + amtFromField.getValue(), amtToField.getValue(), + documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getValue().toString())); } protected void loadTableOIS (Vector data) @@ -284,7 +304,8 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event } @Override - public Object getWindow() { + public Object getWindow() + { return window; } -} +} \ No newline at end of file diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromBatchStatementUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WStatementCreateFromBatch.java similarity index 84% rename from org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromBatchStatementUI.java rename to org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WStatementCreateFromBatch.java index 20f2dc3582..91c2ea78f3 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromBatchStatementUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WStatementCreateFromBatch.java @@ -19,7 +19,6 @@ import java.sql.Timestamp; import java.util.Vector; import java.util.logging.Level; -import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Column; import org.adempiere.webui.component.Columns; @@ -37,9 +36,10 @@ import org.adempiere.webui.editor.WNumberEditor; import org.adempiere.webui.editor.WSearchEditor; import org.adempiere.webui.editor.WStringEditor; import org.adempiere.webui.editor.WTableDirEditor; +import org.adempiere.webui.panel.ADForm; +import org.adempiere.webui.panel.IFormController; import org.adempiere.webui.window.FDialog; -import org.compiere.grid.CreateFromBatchStatement; -import org.compiere.model.GridTab; +import org.compiere.apps.form.StatementCreateFromBatch; import org.compiere.model.MBankStatement; import org.compiere.model.MColumn; import org.compiere.model.MLookup; @@ -61,32 +61,28 @@ import org.zkoss.zul.Hbox; * @author Elaine * */ -public class WCreateFromBatchStatementUI extends CreateFromBatchStatement implements EventListener +public class WStatementCreateFromBatch extends StatementCreateFromBatch implements IFormController, EventListener { - private WCreateFromWindow window; + private WCreateFromForm form; - public WCreateFromBatchStatementUI(GridTab tab) + public WStatementCreateFromBatch() + { + form = new WCreateFromForm(this); + p_WindowNo = form.getWindowNo(); + } + + public void initForm() { - super(tab); - log.info(getGridTab().toString()); - - window = new WCreateFromWindow(this, getGridTab().getWindowNo()); - - p_WindowNo = getGridTab().getWindowNo(); - try { if (!dynInit()) return; zkInit(); - setInitOK(true); } catch(Exception e) { log.log(Level.SEVERE, "", e); - setInitOK(false); } - AEnv.showWindow(window); } /** Window No */ @@ -130,22 +126,22 @@ public class WCreateFromBatchStatementUI extends CreateFromBatchStatement implem */ public boolean dynInit() throws Exception { - log.config(""); - super.dynInit(); + log.config(""); + //Refresh button - Button refreshButton = window.getConfirmPanel().createButton(ConfirmPanel.A_REFRESH); + Button refreshButton = form.getConfirmPanel().createButton(ConfirmPanel.A_REFRESH); refreshButton.addEventListener(Events.ON_CLICK, this); - window.getConfirmPanel().addButton(refreshButton); - - if (getGridTab().getValue("C_BankStatement_ID") == null) + form.getConfirmPanel().addButton(refreshButton); + + if (form.getGridTab() != null && form.getGridTab().getValue("C_BankStatement_ID") == null) { - FDialog.error(0, window, "SaveErrorRowNotFound"); + FDialog.error(0, form, "SaveErrorRowNotFound"); return false; } - window.setTitle(getTitle()); + form.setTitle(getTitle()); int AD_Column_ID = COLUMN_C_BANKSTATEMENT_C_BANKACCOUNT_ID; // C_BankStatement.C_BankAccount_ID MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir); @@ -171,7 +167,7 @@ public class WCreateFromBatchStatementUI extends CreateFromBatchStatement implem Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate); dateToField.setValue(date); - loadBankAccount(); + form.postQueryEvent(); return true; } // dynInit @@ -193,7 +189,7 @@ public class WCreateFromBatchStatementUI extends CreateFromBatchStatement implem Borderlayout parameterLayout = new Borderlayout(); parameterLayout.setHeight("130px"); parameterLayout.setWidth("100%"); - Panel parameterPanel = window.getParameterPanel(); + Panel parameterPanel = form.getParameterPanel(); parameterPanel.appendChild(parameterLayout); Grid parameterBankLayout = GridFactory.newGridLayout(); @@ -263,48 +259,39 @@ public class WCreateFromBatchStatementUI extends CreateFromBatchStatement implem public void onEvent(Event e) throws Exception { log.config("Action=" + e.getTarget().getId()); - if(e.getTarget().equals(window.getConfirmPanel().getButton(ConfirmPanel.A_REFRESH))) + if(e.getTarget().equals(form.getConfirmPanel().getButton(ConfirmPanel.A_REFRESH))) { - loadBankAccount(); - window.tableChanged(null); + form.postQueryEvent(); + form.tableChanged(null); } } - protected void loadBankAccount() + public void executeQuery() { loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), documentNoField.getValue().toString(), dateFromField.getValue(), dateToField.getValue(), amtFromField.getValue(), amtToField.getValue(), - documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getValue().toString())); + documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getValue().toString(), + form.getGridTab())); } protected void loadTableOIS (Vector data) { - window.getWListbox().clear(); + form.getWListbox().clear(); // Remove previous listeners - window.getWListbox().getModel().removeTableModelListener(window); + form.getWListbox().getModel().removeTableModelListener(form); // Set Model ListModelTable model = new ListModelTable(data); - model.addTableModelListener(window); - window.getWListbox().setData(model, getOISColumnNames()); + model.addTableModelListener(form); + form.getWListbox().setData(model, getOISColumnNames()); // - configureMiniTable(window.getWListbox()); + configureMiniTable(form.getWListbox()); } - public void showWindow() + public ADForm getForm() { - window.setVisible(true); - } - - public void closeWindow() - { - window.dispose(); - } - - @Override - public Object getWindow() { - return window; + return form; } } \ No newline at end of file diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java index c59b70f6fa..91a41af1b1 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java @@ -98,6 +98,8 @@ public class DashboardController implements EventListener { private DashboardRunnable dashboardRunnable; private ScheduledFuture dashboardFuture; + private final static int DEFAULT_DASHBOARD_WIDTH = 95; + public DashboardController() { dashboardLayout = new Anchorlayout(); dashboardLayout.setSclass("dashboard-layout"); @@ -141,9 +143,9 @@ public class DashboardController implements EventListener { dps = MDashboardPreference.getForSession(isShowInDashboard, AD_User_ID, AD_Role_ID); // based on user and role noOfCols = MDashboardPreference.getForSessionColumnCount(isShowInDashboard, AD_User_ID, AD_Role_ID); - int dashboardWidth = isShowInDashboard ? 95 : 100; + int dashboardWidth = isShowInDashboard ? DEFAULT_DASHBOARD_WIDTH : 100; width = noOfCols <= 0 ? dashboardWidth : dashboardWidth / noOfCols; - int useWidth = 0; + int extraWidth = 100 - (noOfCols <= 0 ? dashboardWidth : width * noOfCols) - (100 - dashboardWidth - 1); for (final MDashboardPreference dp : dps) { MDashboardContent dc = new MDashboardContent(dp.getCtx(), dp.getPA_DashboardContent_ID(), dp.get_TrxName()); @@ -151,19 +153,12 @@ public class DashboardController implements EventListener { int columnNo = dp.getColumnNo(); if(dashboardColumnLayout == null || currentColumnNo != columnNo) { - int anchorWidth = width; - if (columnNo == noOfCols) { - anchorWidth = 100 - useWidth; - } else { - useWidth = useWidth + width; - } - dashboardColumnLayout = new Vlayout(); dashboardColumnLayout.setAttribute("ColumnNo", columnNo); dashboardColumnLayout.setAttribute("IsShowInDashboard", isShowInDashboard); dashboardColumnLayout.setAttribute("IsAdditionalColumn", false); Anchorchildren dashboardColumn = new Anchorchildren(); - dashboardColumn.setAnchor(anchorWidth + "%" + " 100%"); + dashboardColumn.setAnchor(width + "%" + " 100%"); dashboardColumn.setDroppable("true"); dashboardColumn.addEventListener(Events.ON_DROP, this); dashboardColumn.appendChild(dashboardColumnLayout); @@ -381,9 +376,9 @@ public class DashboardController implements EventListener { dashboardColumnLayout = new Vlayout(); dashboardColumnLayout.setAttribute("ColumnNo", "0"); dashboardColumnLayout.setAttribute("IsShowInDashboard", isShowInDashboard); - dashboardColumnLayout.setAttribute("IsAdditionalColumn", false); + dashboardColumnLayout.setAttribute("IsAdditionalColumn", true); Anchorchildren dashboardColumn = new Anchorchildren(); - dashboardColumn.setAnchor((width-2) + "%" + " 100%"); + dashboardColumn.setAnchor((width-5) + "%" + " 100%"); dashboardColumn.setDroppable("true"); dashboardColumn.addEventListener(Events.ON_DROP, this); dashboardColumn.appendChild(dashboardColumnLayout); @@ -400,7 +395,7 @@ public class DashboardController implements EventListener { dashboardColumnLayout.setAttribute("IsShowInDashboard", isShowInDashboard); dashboardColumnLayout.setAttribute("IsAdditionalColumn", true); Anchorchildren dashboardColumn = new Anchorchildren(); - dashboardColumn.setAnchor("1% 100%"); + dashboardColumn.setAnchor(extraWidth + "% 100%"); dashboardColumn.setDroppable("true"); dashboardColumn.addEventListener(Events.ON_DROP, this); dashboardColumn.appendChild(dashboardColumnLayout); @@ -593,10 +588,12 @@ public class DashboardController implements EventListener { layout.setAttribute("IsAdditionalColumn", false); int noOfCols = columnList.size(); - int width = noOfCols <= 0 ? 100 : (100-1) / noOfCols; + int dashboardWidth = DEFAULT_DASHBOARD_WIDTH; + int width = noOfCols <= 0 ? dashboardWidth : dashboardWidth / noOfCols; + int extraWidth = 100 - (noOfCols <= 0 ? dashboardWidth : width * noOfCols) - (100 - dashboardWidth - 1); for (Anchorchildren column : columnList) - column.setAnchor((width-2) + "%" + " 100%"); + column.setAnchor(width + "%" + " 100%"); // additional column Vlayout dashboardColumnLayout = new Vlayout(); @@ -604,7 +601,7 @@ public class DashboardController implements EventListener { dashboardColumnLayout.setAttribute("IsShowInDashboard", isShowInDashboard); dashboardColumnLayout.setAttribute("IsAdditionalColumn", true); Anchorchildren dashboardColumn = new Anchorchildren(); - dashboardColumn.setAnchor("1% 100%"); + dashboardColumn.setAnchor(extraWidth + "% 100%"); dashboardColumn.setDroppable("true"); dashboardColumn.addEventListener(Events.ON_DROP, this); dashboardColumn.appendChild(dashboardColumnLayout); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADForm.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADForm.java index bb2adfa8f4..62249cf9a8 100755 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADForm.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADForm.java @@ -24,6 +24,7 @@ import org.adempiere.webui.component.Window; import org.adempiere.webui.exception.ApplicationException; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.util.ADClassNameMap; +import org.compiere.model.GridTab; import org.compiere.model.MForm; import org.compiere.process.ProcessInfo; import org.compiere.util.CLogger; @@ -46,7 +47,7 @@ public abstract class ADForm extends Window implements EventListener private static final long serialVersionUID = -5183711788893823434L; /** The class' logging enabler */ protected static final CLogger logger; - + static { logger = CLogger.getCLogger(ADForm.class); @@ -286,6 +287,11 @@ public abstract class ADForm extends Window implements EventListener * @return The created form */ public static ADForm openForm (int adFormID) + { + return openForm(adFormID, null); + } + + public static ADForm openForm (int adFormID, GridTab gridTab) { Object obj = null; ADForm form; @@ -337,6 +343,7 @@ public abstract class ADForm extends Window implements EventListener if (obj instanceof ADForm) { form = (ADForm)obj; + form.gridTab = gridTab; form.init(adFormID, name); return form; } @@ -344,6 +351,7 @@ public abstract class ADForm extends Window implements EventListener { IFormController customForm = (IFormController)obj; form = customForm.getForm(); + form.gridTab = gridTab; form.setICustomForm(customForm); form.init(adFormID, name); return form; @@ -405,4 +413,11 @@ public abstract class ADForm extends Window implements EventListener public Mode getWindowMode() { return Mode.EMBEDDED; } + + private GridTab gridTab; + + public GridTab getGridTab() + { + return gridTab; + } } diff --git a/org.adempiere.ui/src/org/compiere/apps/form/CreateFromForm.java b/org.adempiere.ui/src/org/compiere/apps/form/CreateFromForm.java new file mode 100644 index 0000000000..e50bc87179 --- /dev/null +++ b/org.adempiere.ui/src/org/compiere/apps/form/CreateFromForm.java @@ -0,0 +1,50 @@ +/****************************************************************************** + * Copyright (C) 2013 Elaine Tan * + * Copyright (C) 2013 Trek Global + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.compiere.apps.form; + +import org.compiere.apps.IStatusBar; +import org.compiere.minigrid.IMiniTable; +import org.compiere.model.GridTab; +import org.compiere.util.CLogger; + +/** + * + * @author Elaine + * + */ +public abstract class CreateFromForm +{ + /** Logger */ + protected CLogger log = CLogger.getCLogger(getClass()); + + private String title; + + public abstract void initForm(); + + public abstract boolean dynInit() throws Exception; + + public abstract void info(IMiniTable miniTable, IStatusBar statusBar); + + public abstract boolean save(IMiniTable miniTable, String trxName, GridTab gridTab); + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public abstract void executeQuery(); +} diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromBatchStatement.java b/org.adempiere.ui/src/org/compiere/apps/form/StatementCreateFromBatch.java similarity index 59% rename from org.adempiere.ui/src/org/compiere/grid/CreateFromBatchStatement.java rename to org.adempiere.ui/src/org/compiere/apps/form/StatementCreateFromBatch.java index 5e7b888362..a253ab30fa 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromBatchStatement.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/StatementCreateFromBatch.java @@ -11,22 +11,26 @@ * with this program; if not, write to the Free Software Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * *****************************************************************************/ -package org.compiere.grid; +package org.compiere.apps.form; import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.text.DecimalFormat; import java.util.Vector; import java.util.logging.Level; +import org.compiere.apps.IStatusBar; import org.compiere.minigrid.IMiniTable; import org.compiere.model.GridTab; import org.compiere.model.MBankStatement; import org.compiere.model.MBankStatementLine; import org.compiere.model.MPayment; +import org.compiere.util.CLogger; import org.compiere.util.DB; +import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; @@ -36,24 +40,142 @@ import org.compiere.util.Msg; * @author Elaine * */ -public abstract class CreateFromBatchStatement extends CreateFromBatch +public abstract class StatementCreateFromBatch extends CreateFromForm { - public CreateFromBatchStatement(GridTab mTab) - { - super(mTab); - log.info(mTab.toString()); - } - + /** Logger */ + protected CLogger log = CLogger.getCLogger(getClass()); + public boolean dynInit() throws Exception { log.config(""); - setTitle(Msg.getElement(Env.getCtx(), "C_BankStatement_ID") + " .. " + Msg.translate(Env.getCtx(), "X_CreateFromBatch")); - + setTitle(Msg.getElement(Env.getCtx(), "C_BankStatement_ID") + " .. " + Msg.getElement(Env.getCtx(), "X_CreateFromBatch")); + return true; } + + public String getSQLWhere(Object BPartner, String DocumentNo, Object DateFrom, Object DateTo, + Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) + { + StringBuilder sql = new StringBuilder(); + sql.append("WHERE p.Processed='Y' AND p.IsReconciled='N'"); + sql.append(" AND p.DocStatus IN ('CO','CL','RE','VO') AND p.PayAmt<>0"); + sql.append(" AND p.C_BankAccount_ID = ?"); + sql.append(" AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_Payment_ID=l.C_Payment_ID AND l.StmtAmt <> 0)"); + + if(DocType != null) + sql.append(" AND p.C_DocType_ID=?"); + if(TenderType != null && TenderType.toString().length() > 0) + sql.append(" AND p.TenderType=?"); + if(BPartner != null) + sql.append(" AND p.C_BPartner_ID=?"); + + if(DocumentNo.length() > 0) + sql.append(" AND UPPER(p.DocumentNo) LIKE ?"); + if(AuthCode.length() > 0) + sql.append(" AND p.R_AuthCode LIKE ?"); + + if(AmtFrom != null || AmtTo != null) + { + BigDecimal from = (BigDecimal) AmtFrom; + BigDecimal to = (BigDecimal) AmtTo; + if(from == null && to != null) + sql.append(" AND p.PayAmt <= ?"); + else if(from != null && to == null) + sql.append(" AND p.PayAmt >= ?"); + else if(from != null && to != null) + sql.append(" AND p.PayAmt BETWEEN ? AND ?"); + } + + if(DateFrom != null || DateTo != null) + { + Timestamp from = (Timestamp) DateFrom; + Timestamp to = (Timestamp) DateTo; + if(from == null && to != null) + sql.append(" AND TRUNC(p.DateTrx) <= ?"); + else if(from != null && to == null) + sql.append(" AND TRUNC(p.DateTrx) >= ?"); + else if(from != null && to != null) + sql.append(" AND TRUNC(p.DateTrx) BETWEEN ? AND ?"); + } + + log.fine(sql.toString()); + return sql.toString(); + } + + void setParameters(PreparedStatement pstmt, Object BankAccount, Object BPartner, String DocumentNo, Object DateFrom, Object DateTo, + Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode, GridTab gridTab) + throws SQLException + { + // Get StatementDate + Timestamp ts = (Timestamp) gridTab.getValue("StatementDate"); + if (ts == null) + ts = new Timestamp(System.currentTimeMillis()); + + int index = 1; + + pstmt.setTimestamp(index++, ts); + pstmt.setInt(index++, BankAccount != null ? (Integer) BankAccount : (Integer) gridTab.getValue("C_BankAccount_ID")); + + if(DocType != null) + pstmt.setInt(index++, (Integer) DocType); + + if(TenderType != null && TenderType.toString().length() > 0) + pstmt.setString(index++, (String) TenderType); + + if(BPartner != null) + pstmt.setInt(index++, (Integer) BPartner); + + if(DocumentNo.length() > 0) + pstmt.setString(index++, getSQLText(DocumentNo)); + + if(AuthCode.length() > 0) + pstmt.setString(index++, getSQLText(AuthCode)); + + if(AmtFrom != null || AmtTo != null) + { + BigDecimal from = (BigDecimal) AmtFrom; + BigDecimal to = (BigDecimal) AmtTo; + log.fine("Amt From=" + from + ", To=" + to); + if(from == null && to != null) + pstmt.setBigDecimal(index++, to); + else if(from != null && to == null) + pstmt.setBigDecimal(index++, from); + else if(from != null && to != null) + { + pstmt.setBigDecimal(index++, from); + pstmt.setBigDecimal(index++, to); + } + } + + if(DateFrom != null || DateTo != null) + { + Timestamp from = (Timestamp) DateFrom; + Timestamp to = (Timestamp) DateTo; + log.fine("Date From=" + from + ", To=" + to); + if(from == null && to != null) + pstmt.setTimestamp(index++, to); + else if(from != null && to == null) + pstmt.setTimestamp(index++, from); + else if(from != null && to != null) + { + pstmt.setTimestamp(index++, from); + pstmt.setTimestamp(index++, to); + } + } + } + + private String getSQLText(String text) + { + String s = text.toUpperCase(); + if(!s.endsWith("%")) + s += "%"; + log.fine( "String=" + s); + return s; + } protected Vector> getBankAccountData(Object BankAccount, Object BPartner, String DocumentNo, - Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) + Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode, + GridTab gridTab) { log.config ("C_BankAccount_ID=" + BankAccount); @@ -80,7 +202,7 @@ public abstract class CreateFromBatchStatement extends CreateFromBatch try { pstmt = DB.prepareStatement(sql.toString(), null); - setParameters(pstmt, BankAccount, BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode); + setParameters(pstmt, BankAccount, BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode, gridTab); rs = pstmt.executeQuery(); while(rs.next()) { @@ -121,10 +243,10 @@ public abstract class CreateFromBatchStatement extends CreateFromBatch miniTable.autoSize(); } - public boolean save(IMiniTable miniTable, String trxName) + public boolean save(IMiniTable miniTable, String trxName, GridTab gridTab) { // fixed values - int C_BankStatement_ID = ((Integer)getGridTab().getValue("C_BankStatement_ID")).intValue(); + int C_BankStatement_ID = ((Integer) gridTab.getValue("C_BankStatement_ID")).intValue(); MBankStatement bs = new MBankStatement (Env.getCtx(), C_BankStatement_ID, null); log.config(bs.toString()); @@ -144,7 +266,7 @@ public abstract class CreateFromBatchStatement extends CreateFromBatch sql.append(" AND p.C_BankAccount_ID=?"); sql.append(" AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_Payment_ID=l.C_Payment_ID AND l.StmtAmt <> 0)"); - Timestamp ts = (Timestamp) getGridTab().getValue("StatementDate"); + Timestamp ts = (Timestamp) gridTab.getValue("StatementDate"); if(ts == null) ts = new Timestamp(System.currentTimeMillis()); @@ -215,4 +337,21 @@ public abstract class CreateFromBatchStatement extends CreateFromBatch return columnNames; } + + public void info(IMiniTable miniTable, IStatusBar statusBar) + { + DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount); + BigDecimal total = new BigDecimal(0); + int rows = miniTable.getRowCount(); + int count = 0; + for(int i = 0; i < rows; i++) + { + if(((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) + { + total = total.add((BigDecimal) miniTable.getValueAt(i, 4)); + count++; + } + } + statusBar.setStatusLine(String.valueOf(count) + " - " + Msg.getMsg(Env.getCtx(), "Sum") + " " + format.format(total)); + } } \ No newline at end of file diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromStatement.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromStatement.java index 1e51c91601..dfd247f600 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromStatement.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromStatement.java @@ -1,6 +1,6 @@ /****************************************************************************** - * Copyright (C) 2009 Low Heng Sin * - * Copyright (C) 2009 Idalica Corporation * + * Copyright (C) 2013 Elaine Tan * + * Copyright (C) 2013 Trek Global * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * * by the Free Software Foundation. This program is distributed in the hope * @@ -18,221 +18,63 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; -import java.text.DecimalFormat; import java.util.Vector; import java.util.logging.Level; -import org.compiere.apps.IStatusBar; import org.compiere.minigrid.IMiniTable; import org.compiere.model.GridTab; -import org.compiere.model.MBankAccount; import org.compiere.model.MBankStatement; import org.compiere.model.MBankStatementLine; import org.compiere.model.MPayment; import org.compiere.util.DB; -import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; /** - * Create Transactions for Bank Statements + * + * @author Elaine * - * @author Jorg Janke - * @version $Id: VCreateFromStatement.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ - * @author Victor Perez, e-Evolucion - *

  • RF [1811114] http://sourceforge.net/tracker/index.php?func=detail&aid=1811114&group_id=176962&atid=879335 - * @author Teo Sarca, www.arhipac.ro - *
  • BF [ 2007837 ] VCreateFrom.save() should run in trx */ -public abstract class CreateFromStatement extends CreateFrom +public abstract class CreateFromStatement extends CreateFromBatch { - public MBankAccount bankAccount; - - /** - * Protected Constructor - * @param mTab MTab - */ - public CreateFromStatement(GridTab mTab) + public CreateFromStatement(GridTab mTab) { super(mTab); log.info(mTab.toString()); - } // VCreateFromInvoice + } - /** - * Dynamic Init - * @return true if initialized - */ public boolean dynInit() throws Exception { log.config(""); - setTitle(Msg.translate(Env.getCtx(), "C_BankStatement_ID") + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); + setTitle(Msg.getElement(Env.getCtx(), "C_BankStatement_ID") + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); return true; - } // dynInit + } - /************************************************************************** - * Construct SQL Where Clause and define parameters - * (setParameters needs to set parameters) - * Includes first AND - * @return sql where clause - */ - public String getSQLWhere(String DocumentNo, Object BPartner, Object DateFrom, Object DateTo, - Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) - { - StringBuilder sql = new StringBuilder("WHERE p.Processed='Y' AND p.IsReconciled='N'" - + " AND p.DocStatus IN ('CO','CL','RE','VO') AND p.PayAmt<>0" - + " AND p.C_BankAccount_ID = ?"); - - sql.append( " AND NOT EXISTS (SELECT * FROM C_BankStatementLine l " - // Voided Bank Statements have 0 StmtAmt - + "WHERE p.C_Payment_ID=l.C_Payment_ID AND l.StmtAmt <> 0)"); - - if (DocumentNo.length() > 0) - sql.append(" AND UPPER(p.DocumentNo) LIKE ?"); - // - if (BPartner != null) - sql.append(" AND p.C_BPartner_ID=?"); - // - if (DateFrom != null || DateTo != null) - { - Timestamp from = (Timestamp) DateFrom; - Timestamp to = (Timestamp) DateTo; - if (from == null && to != null) - sql.append(" AND TRUNC(p.DateTrx) <= ?"); - else if (from != null && to == null) - sql.append(" AND TRUNC(p.DateTrx) >= ?"); - else if (from != null && to != null) - sql.append(" AND TRUNC(p.DateTrx) BETWEEN ? AND ?"); - } - // - if (AmtFrom != null || AmtTo != null) - { - BigDecimal from = (BigDecimal) AmtFrom; - BigDecimal to = (BigDecimal) AmtTo; - if (from == null && to != null) - sql.append(" AND p.PayAmt <= ?"); - else if (from != null && to == null) - sql.append(" AND p.PayAmt >= ?"); - else if (from != null && to != null) - sql.append(" AND p.PayAmt BETWEEN ? AND ?"); - } - - if(DocType!=null) - sql.append(" AND p.C_DocType_ID=?"); - if(TenderType != null && TenderType.toString().length() > 0) - sql.append(" AND p.TenderType=?"); - if(AuthCode.length() > 0 ) - sql.append(" AND p.R_AuthCode LIKE ?"); - - log.fine(sql.toString()); - return sql.toString(); - } // getSQLWhere - - /** - * Set Parameters for Query. - * (as defined in getSQLWhere) - * @param pstmt statement - * @param forCount for counting records - * @throws SQLException - */ - void setParameters(PreparedStatement pstmt, boolean forCount, - String DocumentNo, Object BPartner, Object DateFrom, Object DateTo, - Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) - throws SQLException - { - int index = 1; - - pstmt.setInt(index++, bankAccount.getC_BankAccount_ID()); - - if (DocumentNo.length() > 0) - pstmt.setString(index++, getSQLText(DocumentNo)); - // - if (BPartner != null) - { - Integer bp = (Integer) BPartner; - pstmt.setInt(index++, bp.intValue()); - log.fine("BPartner=" + bp); - } - // - if (DateFrom != null || DateTo != null) - { - Timestamp from = (Timestamp) DateFrom; - Timestamp to = (Timestamp) DateTo; - log.fine("Date From=" + from + ", To=" + to); - if (from == null && to != null) - pstmt.setTimestamp(index++, to); - else if (from != null && to == null) - pstmt.setTimestamp(index++, from); - else if (from != null && to != null) - { - pstmt.setTimestamp(index++, from); - pstmt.setTimestamp(index++, to); - } - } - // - if (AmtFrom != null || AmtTo != null) - { - BigDecimal from = (BigDecimal) AmtFrom; - BigDecimal to = (BigDecimal) AmtTo; - log.fine("Amt From=" + from + ", To=" + to); - if (from == null && to != null) - pstmt.setBigDecimal(index++, to); - else if (from != null && to == null) - pstmt.setBigDecimal(index++, from); - else if (from != null && to != null) - { - pstmt.setBigDecimal(index++, from); - pstmt.setBigDecimal(index++, to); - } - } - if(DocType!=null) - pstmt.setInt(index++, (Integer) DocType); - if(TenderType!=null && TenderType.toString().length() > 0 ) - pstmt.setString(index++, (String) TenderType); - if(AuthCode.length() > 0 ) - pstmt.setString(index++, getSQLText(AuthCode)); - - } // setParameters - - /** - * Get SQL WHERE parameter - * @param f field - * @return Upper case text with % at the end - */ - private String getSQLText (String text) - { - String s = text.toUpperCase(); - if (!s.endsWith("%")) - s += "%"; - log.fine( "String=" + s); - return s; - } // getSQLText - - protected Vector> getBankData(String DocumentNo, Object BPartner, Object DateFrom, Object DateTo, - Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) + protected Vector> getBankAccountData(Object BankAccount, Object BPartner, String DocumentNo, + Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) { Vector> data = new Vector>(); - String sql = "SELECT p.DateTrx,p.C_Payment_ID,p.DocumentNo, p.C_Currency_ID,c.ISO_Code, p.PayAmt," - + "currencyConvert(p.PayAmt,p.C_Currency_ID,ba.C_Currency_ID,pay.DateAcct,p.C_ConversionType_ID,p.AD_Client_ID,p.AD_Org_ID)," - + " bp.Name " - + "FROM C_BankAccount ba" - + " INNER JOIN C_Payment_v p ON (p.C_BankAccount_ID=ba.C_BankAccount_ID)" - + " INNER JOIN C_Payment pay ON (p.C_Payment_ID=pay.C_Payment_ID)" - + " INNER JOIN C_Currency c ON (p.C_Currency_ID=c.C_Currency_ID)" - + " LEFT OUTER JOIN C_BPartner bp ON (p.C_BPartner_ID=bp.C_BPartner_ID) "; - - sql = sql + getSQLWhere(DocumentNo, BPartner, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode) + " ORDER BY p.DateTrx"; + StringBuilder sql = new StringBuilder(); + sql.append("SELECT p.DateTrx,p.C_Payment_ID,p.DocumentNo, p.C_Currency_ID,c.ISO_Code, p.PayAmt,"); + sql.append("currencyConvert(p.PayAmt,p.C_Currency_ID,ba.C_Currency_ID,?,null,p.AD_Client_ID,p.AD_Org_ID), bp.Name "); + sql.append("FROM C_BankAccount ba"); + sql.append(" INNER JOIN C_Payment_v p ON (p.C_BankAccount_ID=ba.C_BankAccount_ID)"); + sql.append(" INNER JOIN C_Currency c ON (p.C_Currency_ID=c.C_Currency_ID)"); + sql.append(" LEFT OUTER JOIN C_BPartner bp ON (p.C_BPartner_ID=bp.C_BPartner_ID) "); + sql.append(getSQLWhere(BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode)); + sql.append(" ORDER BY p.DateTrx"); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), null); - setParameters(pstmt, false, DocumentNo, BPartner, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode); + setParameters(pstmt, BankAccount, BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode); rs = pstmt.executeQuery(); - while (rs.next()) + while(rs.next()) { Vector line = new Vector(6); line.add(new Boolean(false)); // 0-Selection @@ -249,7 +91,7 @@ public abstract class CreateFromStatement extends CreateFrom } catch (SQLException e) { - log.log(Level.SEVERE, sql, e); + log.log(Level.SEVERE, sql.toString(), e); } finally { @@ -260,25 +102,7 @@ public abstract class CreateFromStatement extends CreateFrom return data; } - public void info(IMiniTable miniTable, IStatusBar statusBar) - { - DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount); - - BigDecimal total = new BigDecimal(0.0); - int rows = miniTable.getRowCount(); - int count = 0; - for(int i = 0; i < rows; i++) - { - if(((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) - { - total = total.add((BigDecimal) miniTable.getValueAt(i, 4)); - count++; - } - } - statusBar.setStatusLine(String.valueOf(count) + " - " + Msg.getMsg(Env.getCtx(), "Sum") + " " + format.format(total)); - } - - protected void configureMiniTable (IMiniTable miniTable) + protected void configureMiniTable(IMiniTable miniTable) { miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection miniTable.setColumnClass(1, Timestamp.class, false); // 1-TrxDate / nmicoud - idempiere 240 Let user choose the 'Statement Line Date' @@ -291,28 +115,24 @@ public abstract class CreateFromStatement extends CreateFrom miniTable.autoSize(); } - /** - * Save Statement - Insert Data - * @return true if saved - */ public boolean save(IMiniTable miniTable, String trxName) { // fixed values - int C_BankStatement_ID = ((Integer)getGridTab().getValue("C_BankStatement_ID")).intValue(); + int C_BankStatement_ID = ((Integer) getGridTab().getValue("C_BankStatement_ID")).intValue(); MBankStatement bs = new MBankStatement (Env.getCtx(), C_BankStatement_ID, trxName); log.config(bs.toString()); // Lines - for (int i = 0; i < miniTable.getRowCount(); i++) + for(int i = 0; i < miniTable.getRowCount(); i++) { - if (((Boolean)miniTable.getValueAt(i, 0)).booleanValue()) + if(((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) { - Timestamp trxDate = (Timestamp)miniTable.getValueAt(i, 1); // 1-DateTrx - KeyNamePair pp = (KeyNamePair)miniTable.getValueAt(i, 2); // 2-C_Payment_ID + Timestamp trxDate = (Timestamp) miniTable.getValueAt(i, 1); // 1-DateTrx + KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2); // 2-C_Payment_ID int C_Payment_ID = pp.getKey(); - pp = (KeyNamePair)miniTable.getValueAt(i, 3); // 3-Currency + pp = (KeyNamePair) miniTable.getValueAt(i, 3); // 3-Currency int C_Currency_ID = pp.getKey(); - BigDecimal TrxAmt = (BigDecimal)miniTable.getValueAt(i, 5); // 5- Conv Amt + BigDecimal TrxAmt = (BigDecimal) miniTable.getValueAt(i, 5); // 5- Conv Amt log.fine("Line Date=" + trxDate + ", Payment=" + C_Payment_ID + ", Currency=" + C_Currency_ID + ", Amt=" + TrxAmt); @@ -323,7 +143,7 @@ public abstract class CreateFromStatement extends CreateFrom bsl.setTrxAmt(TrxAmt); bsl.setStmtAmt(TrxAmt); - bsl.setC_Currency_ID(bankAccount.getC_Currency_ID()); + bsl.setC_Currency_ID(C_Currency_ID); if (!bsl.save()) log.log(Level.SEVERE, "Line not created #" + i); @@ -335,7 +155,7 @@ public abstract class CreateFromStatement extends CreateFrom protected Vector getOISColumnNames() { // Header Info - Vector columnNames = new Vector(6); + Vector columnNames = new Vector(7); columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); columnNames.add(Msg.translate(Env.getCtx(), "Date")); columnNames.add(Msg.getElement(Env.getCtx(), "C_Payment_ID")); @@ -346,4 +166,4 @@ public abstract class CreateFromStatement extends CreateFrom return columnNames; } -} +} \ No newline at end of file diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromStatementBatch.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromStatementBatch.java deleted file mode 100644 index b99504492c..0000000000 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromStatementBatch.java +++ /dev/null @@ -1,169 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2013 Elaine Tan * - * Copyright (C) 2013 Trek Global - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - *****************************************************************************/ -package org.compiere.grid; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Vector; -import java.util.logging.Level; - -import org.compiere.minigrid.IMiniTable; -import org.compiere.model.GridTab; -import org.compiere.model.MBankStatement; -import org.compiere.model.MBankStatementLine; -import org.compiere.model.MPayment; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Msg; - -/** - * - * @author Elaine - * - */ -public abstract class CreateFromStatementBatch extends CreateFromBatch -{ - public CreateFromStatementBatch(GridTab mTab) - { - super(mTab); - log.info(mTab.toString()); - } - - public boolean dynInit() throws Exception - { - log.config(""); - setTitle(Msg.getElement(Env.getCtx(), "C_BankStatement_ID") + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); - - return true; - } - - protected Vector> getBankAccountData(Object BankAccount, Object BPartner, String DocumentNo, - Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) - { - Vector> data = new Vector>(); - - StringBuilder sql = new StringBuilder(); - sql.append("SELECT p.DateTrx,p.C_Payment_ID,p.DocumentNo, p.C_Currency_ID,c.ISO_Code, p.PayAmt,"); - sql.append("currencyConvert(p.PayAmt,p.C_Currency_ID,ba.C_Currency_ID,?,null,p.AD_Client_ID,p.AD_Org_ID), bp.Name "); - sql.append("FROM C_BankAccount ba"); - sql.append(" INNER JOIN C_Payment_v p ON (p.C_BankAccount_ID=ba.C_BankAccount_ID)"); - sql.append(" INNER JOIN C_Currency c ON (p.C_Currency_ID=c.C_Currency_ID)"); - sql.append(" LEFT OUTER JOIN C_BPartner bp ON (p.C_BPartner_ID=bp.C_BPartner_ID) "); - sql.append(getSQLWhere(BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode)); - sql.append(" ORDER BY p.DateTrx"); - - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), null); - setParameters(pstmt, BankAccount, BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode); - rs = pstmt.executeQuery(); - while(rs.next()) - { - Vector line = new Vector(6); - line.add(new Boolean(false)); // 0-Selection - line.add(rs.getTimestamp(1)); // 1-DateTrx - KeyNamePair pp = new KeyNamePair(rs.getInt(2), rs.getString(3)); - line.add(pp); // 2-C_Payment_ID - pp = new KeyNamePair(rs.getInt(4), rs.getString(5)); - line.add(pp); // 3-Currency - line.add(rs.getBigDecimal(6)); // 4-PayAmt - line.add(rs.getBigDecimal(7)); // 5-Conv Amt - line.add(rs.getString(8)); // 6-BParner - data.add(line); - } - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql.toString(), e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - - return data; - } - - protected void configureMiniTable(IMiniTable miniTable) - { - miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection - miniTable.setColumnClass(1, Timestamp.class, false); // 1-TrxDate / nmicoud - idempiere 240 Let user choose the 'Statement Line Date' - miniTable.setColumnClass(2, String.class, true); // 2-Payment - miniTable.setColumnClass(3, String.class, true); // 3-Currency - miniTable.setColumnClass(4, BigDecimal.class, true); // 4-Amount - miniTable.setColumnClass(5, BigDecimal.class, true); // 5-ConvAmount - miniTable.setColumnClass(6, String.class, true); // 6-BPartner - // Table UI - miniTable.autoSize(); - } - - public boolean save(IMiniTable miniTable, String trxName) - { - // fixed values - int C_BankStatement_ID = ((Integer) getGridTab().getValue("C_BankStatement_ID")).intValue(); - MBankStatement bs = new MBankStatement (Env.getCtx(), C_BankStatement_ID, trxName); - log.config(bs.toString()); - - // Lines - for(int i = 0; i < miniTable.getRowCount(); i++) - { - if(((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) - { - Timestamp trxDate = (Timestamp) miniTable.getValueAt(i, 1); // 1-DateTrx - KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2); // 2-C_Payment_ID - int C_Payment_ID = pp.getKey(); - pp = (KeyNamePair) miniTable.getValueAt(i, 3); // 3-Currency - int C_Currency_ID = pp.getKey(); - BigDecimal TrxAmt = (BigDecimal) miniTable.getValueAt(i, 5); // 5- Conv Amt - - log.fine("Line Date=" + trxDate - + ", Payment=" + C_Payment_ID + ", Currency=" + C_Currency_ID + ", Amt=" + TrxAmt); - // - MBankStatementLine bsl = new MBankStatementLine (bs); - bsl.setStatementLineDate(trxDate); - bsl.setPayment(new MPayment(Env.getCtx(), C_Payment_ID, trxName)); - - bsl.setTrxAmt(TrxAmt); - bsl.setStmtAmt(TrxAmt); - bsl.setC_Currency_ID(C_Currency_ID); - - if (!bsl.save()) - log.log(Level.SEVERE, "Line not created #" + i); - } // if selected - } // for all rows - return true; - } // save - - protected Vector getOISColumnNames() - { - // Header Info - Vector columnNames = new Vector(7); - columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); - columnNames.add(Msg.translate(Env.getCtx(), "Date")); - columnNames.add(Msg.getElement(Env.getCtx(), "C_Payment_ID")); - columnNames.add(Msg.translate(Env.getCtx(), "C_Currency_ID")); - columnNames.add(Msg.translate(Env.getCtx(), "Amount")); - columnNames.add(Msg.translate(Env.getCtx(), "ConvertedAmount")); - columnNames.add(Msg.translate(Env.getCtx(), "C_BPartner_ID")); - - return columnNames; - } -} \ No newline at end of file diff --git a/org.adempiere.ui/src/org/compiere/grid/ICreateFromFactory.java b/org.adempiere.ui/src/org/compiere/grid/ICreateFromFactory.java index 3480f1e84b..28796205e7 100644 --- a/org.adempiere.ui/src/org/compiere/grid/ICreateFromFactory.java +++ b/org.adempiere.ui/src/org/compiere/grid/ICreateFromFactory.java @@ -22,6 +22,6 @@ import org.compiere.model.GridTab; */ public interface ICreateFromFactory { - public ICreateFrom create(GridTab mTab, String columnName); + public ICreateFrom create(GridTab mTab); }