diff --git a/client/src/org/compiere/apps/APanel.java b/client/src/org/compiere/apps/APanel.java index 5cf87fbdd6..4a157a250e 100644 --- a/client/src/org/compiere/apps/APanel.java +++ b/client/src/org/compiere/apps/APanel.java @@ -1988,8 +1988,10 @@ public final class APanel extends CPanel if (!cmd_save(true)) return; + // hengsin - [ 1639242 ] Inconsistent appearance of Process/Report Dialog // globalqss - Add support for Don't ShowHelp option in Process // this code must be changed if integrated the parameters and help in only one window + /* MProcess pr = new MProcess(m_ctx, vButton.getProcess_ID(), null); if (pr.getShowHelp() != null && pr.getShowHelp().equals("N")) { startWOasking = true; @@ -1997,6 +1999,7 @@ public final class APanel extends CPanel // end globalqss // Ask user to start process, if Description and Help is not empty + if (!startWOasking && !(vButton.getDescription().equals("") && vButton.getHelp().equals(""))) if (!ADialog.ask(m_curWindowNo, this, "StartProcess?", // "" + vButton.getText() + "
" + @@ -2013,6 +2016,12 @@ public final class APanel extends CPanel // Trx trx = Trx.get(Trx.createTrxName("AppsPanel"), true); ProcessCtl.process(this, m_curWindowNo, pi, null); // calls lockUI, unlockUI + */ + + ProcessModalDialog dialog = new ProcessModalDialog(m_ctx, Env.getWindow(m_curWindowNo), Env.getHeader(m_ctx, m_curWindowNo), + this, m_curWindowNo, vButton.getProcess_ID(), table_ID, + record_ID, startWOasking); + AEnv.showCenterWindow(Env.getWindow(m_curWindowNo), dialog); } // actionButton diff --git a/client/src/org/compiere/apps/ProcessCtl.java b/client/src/org/compiere/apps/ProcessCtl.java index aa155cfadc..88f4d07195 100644 --- a/client/src/org/compiere/apps/ProcessCtl.java +++ b/client/src/org/compiere/apps/ProcessCtl.java @@ -37,6 +37,7 @@ import org.compiere.wf.*; * @author Jorg Janke * @version $Id: ProcessCtl.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $ * @author Low Heng Sin + * - Added support for having description and parameter in one dialog * - Added support to run db process remotely on server */ public class ProcessCtl extends Thread @@ -59,6 +60,7 @@ public class ProcessCtl extends Thread * @param pi ProcessInfo process info * @param trx Transaction * @return worker started ProcessCtl instance or null for workflow + * @deprecated */ public static ProcessCtl process (ASyncProcess parent, int WindowNo, ProcessInfo pi, Trx trx) { diff --git a/client/src/org/compiere/apps/ProcessModalDialog.java b/client/src/org/compiere/apps/ProcessModalDialog.java new file mode 100644 index 0000000000..dcd6597097 --- /dev/null +++ b/client/src/org/compiere/apps/ProcessModalDialog.java @@ -0,0 +1,278 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2007 Low Heng Sin * + * Copyright (C) 1999-2006 ComPiere, Inc. 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. * + *****************************************************************************/ +package org.compiere.apps; + +import java.awt.*; +import java.awt.event.*; +import java.sql.*; +import java.util.Properties; +import java.util.logging.*; +import javax.swing.*; + +import org.compiere.process.*; +import org.compiere.swing.*; +import org.compiere.util.*; + +/** + * [ 1639242 ] Inconsistent appearance of Process/Report Dialog + * + * Modal Dialog to Start process. + * Displays information about the process + * and lets the user decide to start it + * and displays results (optionally print them). + * Calls ProcessCtl to execute. + * @author Low Heng Sin + * @author arboleda - globalqss + * - Implement ShowHelp option on processes and reports + */ +public class ProcessModalDialog extends CDialog + implements ActionListener +{ + + /** + * Dialog to start a process/report + * @param ctx + * @param parent + * @param title + * @param aProcess + * @param WindowNo + * @param AD_Process_ID + * @param tableId + * @param recordId + * @param autoStart + */ + public ProcessModalDialog (Properties ctx, Frame parent, String title, + ASyncProcess aProcess, int WindowNo, int AD_Process_ID, + int tableId, int recordId, boolean autoStart) + { + super(parent, title, true); + log.info("Process=" + AD_Process_ID ); + m_ctx = ctx; + m_ASyncProcess = aProcess; + m_WindowNo = WindowNo; + m_AD_Process_ID = AD_Process_ID; + m_tableId = tableId; + m_recordId = recordId; + m_autoStart = autoStart; + try + { + jbInit(); + init(); + } + catch(Exception ex) + { + log.log(Level.SEVERE, "", ex); + } + } // ProcessDialog + + private ASyncProcess m_ASyncProcess; + private int m_WindowNo; + private Properties m_ctx; + private int m_tableId; + private int m_recordId; + private boolean m_autoStart; + private int m_AD_Process_ID; + private String m_Name = null; + private StringBuffer m_messageText = new StringBuffer(); + private String m_ShowHelp = null; // Determine if a Help Process Window is shown + + /** Logger */ + private static CLogger log = CLogger.getCLogger(ProcessDialog.class); + // + + private CPanel dialog = new CPanel() + { + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + Dimension m = getMinimumSize(); + if ( d.height < m.height || d.width < m.width ) { + Dimension d1 = new Dimension(); + d1.height = Math.max(d.height, m.height); + d1.width = Math.max(d.width, m.width); + return d1; + } else + return d; + } + }; + private BorderLayout mainLayout = new BorderLayout(); + private ConfirmPanel southPanel = new ConfirmPanel(true); + private CButton bOK = null; + private JEditorPane message = new JEditorPane() + { + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + Dimension m = getMaximumSize(); + if ( d.height > m.height || d.width > m.width ) { + Dimension d1 = new Dimension(); + d1.height = Math.min(d.height, m.height); + d1.width = Math.min(d.width, m.width); + return d1; + } else + return d; + } + }; + private JScrollPane messagePane = new JScrollPane(message); + + private CPanel centerPanel = null; + private ProcessParameterPanel parameterPanel = null; + private JSeparator separator = new JSeparator(); + private ProcessInfo m_pi = null; + + /** + * Static Layout + * @throws Exception + */ + private void jbInit() throws Exception + { + dialog.setLayout(mainLayout); + dialog.setMinimumSize(new Dimension(500, 200)); + southPanel.addActionListener(this); + bOK = southPanel.getOKButton(); + // + message.setContentType("text/html"); + message.setEditable(false); + message.setBackground(Color.white); + message.setFocusable(false); + getContentPane().add(dialog); + dialog.add(southPanel, BorderLayout.SOUTH); + dialog.add(messagePane, BorderLayout.NORTH); + messagePane.setBorder(null); + message.setMaximumSize(new Dimension(600, 300)); + centerPanel = new CPanel(); + centerPanel.setBorder(null); + centerPanel.setLayout(new BorderLayout()); + dialog.add(centerPanel, BorderLayout.CENTER); + // + this.getRootPane().setDefaultButton(bOK); + } // jbInit + + /** + * Set Visible + * (set focus to OK if visible) + * @param visible true if visible + */ + public void setVisible (boolean visible) + { + super.setVisible(visible); + if (visible) { + bOK.requestFocus(); + } + } // setVisible + + /** + * Dispose + */ + public void dispose() + { + super.dispose(); + } // dispose + + + /** + * Dynamic Init + * @return true, if there is something to process (start from menu) + */ + public boolean init() + { + log.config(""); + // + boolean trl = !Env.isBaseLanguage(m_ctx, "AD_Process"); + String sql = "SELECT Name, Description, Help, IsReport, ShowHelp " + + "FROM AD_Process " + + "WHERE AD_Process_ID=?"; + if (trl) + sql = "SELECT t.Name, t.Description, t.Help, p.IsReport, p.ShowHelp " + + "FROM AD_Process p, AD_Process_Trl t " + + "WHERE p.AD_Process_ID=t.AD_Process_ID" + + " AND p.AD_Process_ID=? AND t.AD_Language=?"; + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, m_AD_Process_ID); + if (trl) + pstmt.setString(2, Env.getAD_Language(m_ctx)); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + { + m_Name = rs.getString(1); + m_ShowHelp = rs.getString(5); + // + m_messageText.append(""); + String s = rs.getString(2); // Description + if (rs.wasNull()) + m_messageText.append(Msg.getMsg(m_ctx, "StartProcess?")); + else + m_messageText.append(s); + m_messageText.append(""); + + s = rs.getString(3); // Help + if (!rs.wasNull()) + m_messageText.append("

").append(s).append("

"); + } + + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + return false; + } + + if (m_Name == null) + return false; + // + this.setTitle(m_Name); + message.setMargin(new Insets(10,10,10,10)); + message.setText(m_messageText.toString()); + + // Move from APanel.actionButton + m_pi = new ProcessInfo(m_Name, m_AD_Process_ID, m_tableId, m_recordId); + m_pi.setAD_User_ID (Env.getAD_User_ID(Env.getCtx())); + m_pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx())); + parameterPanel = new ProcessParameterPanel(m_WindowNo, m_pi); + centerPanel.removeAll(); + if (parameterPanel.init()) { + // hasfields + centerPanel.add(separator, BorderLayout.NORTH); + centerPanel.add(parameterPanel, BorderLayout.CENTER); + } else { + if (m_ShowHelp != null && m_ShowHelp.equals("N")) { + m_autoStart = true; + } + if (m_autoStart) + bOK.doClick(); // don't ask first click + } + dialog.revalidate(); + return true; + } // init + + /** + * ActionListener (Start) + * @param e ActionEvent + */ + public void actionPerformed (ActionEvent e) + { + if (e.getSource() == bOK) + { + ProcessCtl.process(m_ASyncProcess, m_WindowNo, parameterPanel, m_pi, null); + dispose(); + } + + else if (e.getSource() == southPanel.getCancelButton()) + dispose(); + } // actionPerformed + +} // ProcessDialog