From f1547a093d8e2ed04ee8fdd2b4ae63f1cd0c46f8 Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Mon, 7 Sep 2009 06:00:21 +0000 Subject: [PATCH] Popup Menu for Lookup Record http://sourceforge.net/tracker/?func=detail&atid=879335&aid=2853359&group_id=176962 --- client/src/org/compiere/apps/ASearch.java | 156 ++++++++++++++++++ client/src/org/compiere/apps/search/Find.java | 55 ++++-- 2 files changed, 200 insertions(+), 11 deletions(-) create mode 100755 client/src/org/compiere/apps/ASearch.java diff --git a/client/src/org/compiere/apps/ASearch.java b/client/src/org/compiere/apps/ASearch.java new file mode 100755 index 0000000000..4c027c8359 --- /dev/null +++ b/client/src/org/compiere/apps/ASearch.java @@ -0,0 +1,156 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * 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. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + * Sponsors: * + * - E-evolution (http://www.e-evolution.com/) * + *****************************************************************************/ +package org.compiere.apps; + +import java.awt.Cursor; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JComponent; +import javax.swing.JPopupMenu; + +import org.compiere.apps.search.Find; +import org.compiere.grid.GridController; +import org.compiere.model.GridTab; +import org.compiere.model.MUserQuery; +import org.compiere.util.CLogger; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.Msg; + +/** + * Application Search. + * Called from APanel; Queries Search Table. + * + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2853359 ] Popup Menu for Lookup Record + *
  • http://sourceforge.net/tracker/?func=detail&aid=2853359&group_id=176962&atid=879335 + */ +public class ASearch implements ActionListener +{ + /** + * Constructor + * @param invoker component to display popup (optional) + * @param tableName table name + * @param query query + */ + public ASearch (JComponent invoker, Frame owner, int targetWindowNo, GridController gc ,GridTab gridTab) + { + m_invoker = invoker; + m_owner = owner; + m_targetWindowNo = targetWindowNo; + m_gt = gridTab; + m_gc = gc; + // See What is there + getSearchTargets (); + } // AReport + + /** The Popup */ + private JPopupMenu m_popup = new JPopupMenu("SearchMenu"); + /** The Option List */ + private ArrayList m_list = new ArrayList(); + /** Logger */ + private static CLogger log = CLogger.getCLogger(ASearch.class); + + JComponent m_invoker; + Frame m_owner; + int m_targetWindowNo; + GridTab m_gt; + GridController m_gc; + + /** + * Get the UserQuery for the table. + * Fill the list and the popup menu + * @param invoker component to display popup (optional) + * @param AD_Tab_ID Tab ID + * @param AD_Table_ID Table ID + * @param AD_User_ID User ID + */ + private void getSearchTargets () + { + boolean baseLanguage = Env.isBaseLanguage(Env.getCtx(), "AD_Window"); + MUserQuery[] search = MUserQuery.get(Env.getCtx(), m_gt.getAD_Tab_ID()); + KeyNamePair pp = new KeyNamePair (0, Msg.translate(Env.getCtx(), "Find")); + m_list.add(pp); + m_popup.add(pp.toString()).addActionListener(this); + + for (MUserQuery query: search) + { + pp = new KeyNamePair (query.getAD_UserQuery_ID(), query.getName()); + m_list.add(pp); + m_popup.add(pp.toString()).addActionListener(this); + } + + if (m_invoker.isShowing() && m_list.size() > 1) + { + m_popup.show(m_invoker, 0, m_invoker.getHeight()); + } + else + { + launchSearch(pp); + } + } // getZoomTargets + + + /** + * Action Listener + * @param e event + */ + public void actionPerformed(ActionEvent e) + { + m_popup.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + String cmd = e.getActionCommand(); + for (int i = 0; i < m_list.size(); i++) + { + KeyNamePair pp = (KeyNamePair)m_list.get(i); + if (cmd.equals(pp.getName())) + { + launchSearch (pp); + return; + } + } + } // actionPerformed + + /** + * Launch Search + * @param pp KeyPair + */ + private void launchSearch (KeyNamePair pp) + { + Find find = new Find (m_owner, m_targetWindowNo, m_gc , m_gt, 1); + if(pp.getName().equals(Msg.getMsg(Env.getCtx(), "Find"))) + { + AEnv.showCenterWindow(m_owner, find); + } + else + { + int AD_UserQuery_ID = pp.getKey(); + MUserQuery userQuery = null; + if(AD_UserQuery_ID > 0) + { + userQuery = new MUserQuery(Env.getCtx(),AD_UserQuery_ID, null); + } + find.initFindAdvanced(); + find.parseUserQuery(userQuery); + find.cmd_ok_Advanced(); + } + } +} // ASearch diff --git a/client/src/org/compiere/apps/search/Find.java b/client/src/org/compiere/apps/search/Find.java index 59a3a7fc56..de3a9aa497 100644 --- a/client/src/org/compiere/apps/search/Find.java +++ b/client/src/org/compiere/apps/search/Find.java @@ -50,6 +50,7 @@ import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.InputMap; import javax.swing.JButton; +import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; @@ -64,9 +65,9 @@ import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import org.compiere.apps.ADialog; -import org.compiere.apps.AEnv; import org.compiere.apps.ConfirmPanel; import org.compiere.apps.StatusBar; +import org.compiere.grid.GridController; import org.compiere.grid.ed.AutoCompletion; import org.compiere.grid.ed.VEditor; import org.compiere.grid.ed.VEditorFactory; @@ -75,6 +76,7 @@ import org.compiere.model.DataStatusEvent; import org.compiere.model.DataStatusListener; import org.compiere.model.GridField; import org.compiere.model.GridFieldVO; +import org.compiere.model.GridTab; import org.compiere.model.MLookupFactory; import org.compiere.model.MProduct; import org.compiere.model.MQuery; @@ -94,6 +96,7 @@ 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; import org.compiere.util.Util; import org.compiere.util.ValueNamePair; @@ -107,6 +110,9 @@ import org.compiere.util.ValueNamePair; * * @author Teo Sarca, www.arhipac.ro *
  • BF [ 2564070 ] Saving user queries can produce unnecessary db errors + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2853359 ] Popup Menu for Lookup Record + *
  • http://sourceforge.net/tracker/?func=detail&aid=2853359&group_id=176962&atid=879335 */ public final class Find extends CDialog implements ActionListener, ChangeListener, DataStatusListener @@ -114,7 +120,24 @@ public final class Find extends CDialog private static final long serialVersionUID = 6414604433732835410L; private int m_AD_Tab_ID; - + + /** + * Find Constructor + * @param owner Frame Dialog Onwer + * @param targetWindowNo WindowNo of target window + * @param gc Grid Controller + * @param gridTab GridTab + * @param minRecords number of minimum records + */ + public Find (Frame owner, int targetWindowNo, GridController gc ,GridTab gridTab, int minRecords) + { + this(owner, targetWindowNo, gridTab.getName(), gridTab.getAD_Tab_ID(), + gridTab.getAD_Table_ID(), gridTab.getTableName(), gridTab.getWhereExtended(), + GridField.createFields(Env.getCtx(), targetWindowNo, 0, gridTab.getAD_Tab_ID()), minRecords); + m_gt = gridTab; + m_gc = gc; + } + /** * Find Constructor * @param owner Frame Dialog Onwer @@ -130,7 +153,6 @@ public final class Find extends CDialog int AD_Table_ID, String tableName, String whereExtended, GridField[] findFields, int minRecords) { - super(owner, Msg.getMsg(Env.getCtx(), "Find") + ": " + title, true); log.info(title); // m_targetWindowNo = targetWindowNo; @@ -163,9 +185,11 @@ public final class Find extends CDialog } // this.getRootPane().setDefaultButton(confirmPanelS.getOKButton()); - AEnv.showCenterWindow(owner, this); } // Find - + + GridController m_gc ; + GridTab m_gt; + /** Target Window No */ private int m_targetWindowNo; /** Table ID */ @@ -206,6 +230,11 @@ public final class Find extends CDialog /** Reference ID for Yes/No */ public static final int AD_REFERENCE_ID_YESNO = 319; + /** The Popup */ + private JPopupMenu m_popup = new JPopupMenu("SearchMenu"); + /** The Option List */ + private ArrayList m_list = new ArrayList(); + // private CPanel southPanel = new CPanel(); private BorderLayout southLayout = new BorderLayout(); @@ -551,7 +580,7 @@ public final class Find extends CDialog /** * Init Find GridController */ - private void initFindAdvanced() + public void initFindAdvanced() { log.config(""); advancedTable.setModel(new DefaultTableModel(0, 4)); @@ -718,7 +747,7 @@ public final class Find extends CDialog public void actionPerformed (ActionEvent e) { log.info(e.getActionCommand()); - // + if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) cmd_cancel(); else if (e.getActionCommand().equals(ConfirmPanel.A_REFRESH)) @@ -796,7 +825,7 @@ public final class Find extends CDialog } } // actionPerformed - private void parseUserQuery(MUserQuery userQuery) { + public void parseUserQuery(MUserQuery userQuery) { String code = userQuery.getCode(); String[] segments = code.split(Pattern.quote(SEGMENT_SEPARATOR)); advancedTable.stopEditor(true); @@ -945,7 +974,7 @@ public final class Find extends CDialog /** * Advanced OK Button pressed */ - private void cmd_ok_Advanced() + public void cmd_ok_Advanced() { m_isCancel = false; // teo_sarca [ 1708717 ] // save pending @@ -1107,7 +1136,7 @@ public final class Find extends CDialog } } // cmd_save - private void refreshUserQueries() + public void refreshUserQueries() { Object selected = fQueryName.getSelectedItem(); userQueries = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID); @@ -1462,6 +1491,11 @@ public final class Find extends CDialog // if (query != null) statusBar.setStatusToolTip (query.getWhereClause()); + if(m_gt != null && m_gc!= null) + { + m_gt.setQuery(getQuery()); + m_gc.query(false, 0, 0); + } return m_total; } // getNoOfRecords @@ -1535,5 +1569,4 @@ public final class Find extends CDialog return comp; } } // ProxyRenderer - } // Find