diff --git a/base/src/org/adempiere/util/AbstractDocumentSearch.java b/base/src/org/adempiere/util/AbstractDocumentSearch.java new file mode 100644 index 0000000000..17a0261448 --- /dev/null +++ b/base/src/org/adempiere/util/AbstractDocumentSearch.java @@ -0,0 +1,292 @@ +/********************************************************************** +* This file is part of Adempiere ERP Bazaar * +* http://www.adempiere.org * +* * +* Copyright (C) Jan Roessler - Schaeffer * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* 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., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Jan Roessler * +* - Heng Sin Low * +* * +* Sponsors: * +* - Schaeffer * +**********************************************************************/ +package org.adempiere.util; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.Vector; + +import org.compiere.model.MColumn; +import org.compiere.model.MQuery; +import org.compiere.model.MRole; +import org.compiere.model.MSearchDefinition; +import org.compiere.model.MTable; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; + +/** + * Executes search and opens windows for defined transaction codes + * + * @author Jan Roessler, jr@schaeffer-ag.de + * + */ +public abstract class AbstractDocumentSearch { + + /** the logger */ + static CLogger log = CLogger.getCLogger(AbstractDocumentSearch.class); + protected boolean windowOpened = false; + + /** + * @param searchString + */ + public boolean openDocumentsByDocumentNo(String searchString) { + windowOpened = false; + + log.fine("Search started with String: " + searchString); + + // Check if / how many transaction-codes are used + if (searchString != null && !"".equals(searchString)) { + String[] codes = searchString.trim().replaceAll(" ", " ").split(" "); + + List codeList = new ArrayList(); + boolean codeSearch = true; + searchString = ""; + + // Analyze String to separate transactionCodes from searchString + for (int i = 0; i < codes.length; i++) { + try { + String s = codes[i]; + if (MSearchDefinition.isValidTransactionCode(s) && codeSearch) { + codeList.add(s); + } else { + // Build the searchString with eventually appearing + // whitespaces + codeSearch = false; + searchString += s; + if (i != (codes.length - 1)) { + searchString += " "; + } + } + } catch (SQLException e) { + log.severe(e.toString()); + e.printStackTrace(); + } + } + + // Start the search for every single code + if (codeList.size() > 0) { + for (int i = 0; i < codeList.size(); i++) { + log.fine("Search with Transaction: '" + codeList.get(i) + "' for: '" + + searchString + "'"); + getID(codeList.get(i), searchString); + } + } else { + log.fine("Search without Transaction: " + searchString); + getID(null, searchString); + } + } else { + log.fine("Search String is invalid"); + } + return windowOpened; + } + + /** + * search for id's that fit the searchString + * + * @param transactionCode + * @param searchString + */ + private void getID(String transactionCode, String searchString) { + + ResultSet rsSO = null; + ResultSet rsPO = null; + PreparedStatement pstmtSO = null; + PreparedStatement pstmtPO = null; + String sqlSO = null; + String sqlPO = null; + + final Properties ctx = Env.getCtx(); + final MRole role = MRole.get(ctx, Env.getAD_Role_ID(ctx), Env.getAD_User_ID(ctx), true); + + try { + for (MSearchDefinition msd : MSearchDefinition.getForCode(transactionCode)) { + + MTable table = new MTable(Env.getCtx(), msd.getAD_Table_ID(), null); + // SearchDefinition with a given table and column + if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_TABLE)) { + MColumn column = new MColumn(Env.getCtx(), msd.getAD_Column_ID(), null); + sqlSO = "SELECT " + table.getTableName() + "_ID FROM " + table.getTableName() + " "; + // search for an Integer + if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) { + sqlSO += "WHERE " + column.getColumnName() + "=?"; + // search for a String + } else { + sqlSO += "WHERE UPPER(" + column.getColumnName()+ ") LIKE UPPER(?)"; + } + + if (msd.getPO_Window_ID() != 0) { + sqlPO = sqlSO + " AND IsSOTrx='N'"; + sqlSO += " AND IsSOTrx='Y'"; + } + pstmtSO = DB.prepareStatement(sqlSO, null); + pstmtPO = DB.prepareStatement(sqlPO, null); + // search for a Integer + if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) { + pstmtSO.setInt(1, Integer.valueOf(searchString.replaceAll("\\D", ""))); + if (msd.getPO_Window_ID() != 0) { + pstmtPO.setInt(1, Integer.valueOf(searchString.replaceAll("\\D", ""))); + } + // search for a String + } else if (msd.getDataType().equals(MSearchDefinition.DATATYPE_STRING)) { + pstmtSO.setString(1, searchString); + if (msd.getPO_Window_ID() != 0) { + pstmtPO.setString(1, searchString); + } + } + // SearchDefinition with a special query + } else if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_QUERY)) { + sqlSO = msd.getQuery(); + pstmtSO = DB.prepareStatement(sqlSO, null); + // count '?' in statement + int count = 1; + for (char c : sqlSO.toCharArray()) { + if (c == '?') { + count++; + } + } + for (int i = 1; i < count; i++) { + if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) { + pstmtSO.setInt(i, Integer.valueOf(searchString.replaceAll("\\D", ""))); + } else if (msd.getDataType().equals(MSearchDefinition.DATATYPE_STRING)) { + pstmtSO.setString(i, searchString); + } + } + } + if (pstmtSO != null) { + log.fine("SQL Sales: " + sqlSO); + rsSO = pstmtSO.executeQuery(); + Vector idSO = new Vector(); + while (rsSO.next()) { + idSO.add(new Integer(rsSO.getInt(1))); + } + if (role.getWindowAccess(msd.getAD_Window_ID()) != null) { + log.fine("Open Window: " + msd.getAD_Window_ID() + " / Table: " + + table.getTableName() + " / Number of Results: " + idSO.size()); + + if (idSO.size() == 0 && (searchString == null || searchString.trim().length() == 0)) { + // No search string - open the window with new record + idSO.add(new Integer(0)); + } + + openWindow(idSO, table.getTableName(), msd.getAD_Window_ID()); + } else { + log.warning("Role is not allowed to view this window"); + } + } + if (pstmtPO != null) { + log.fine("SQL Purchase: " + sqlPO); + rsPO = pstmtPO.executeQuery(); + Vector idPO = new Vector(); + while (rsPO.next()) { + idPO.add(new Integer(rsPO.getInt(1))); + } + if (role.getWindowAccess(msd.getPO_Window_ID()) != null) { + log.fine("Open Window: " + msd.getPO_Window_ID() + " / Table: " + + table.getTableName() + " / Number of Results: " + idPO.size()); + openWindow(idPO, table.getTableName(), msd.getPO_Window_ID()); + } else { + log.warning("Role is not allowed to view this window"); + } + } + DB.close(rsSO, pstmtSO); + DB.close(rsPO, pstmtPO); + pstmtSO = null; + pstmtPO = null; + rsSO = null; + rsPO = null; + } + } catch (Exception e) { + log.severe(e.toString()); + e.printStackTrace(); + } finally { + DB.close(rsSO, pstmtSO); + DB.close(rsPO, pstmtPO); + rsSO = null; + rsPO = null; + pstmtSO = null; + pstmtPO = null; + } + } + + /** + * opens window with the given documents + * + * @param ids + * - document id's + * @param tableName + * @param windowId + */ + private void openWindow(Vector ids, String tableName, int windowId) { + if (ids == null || ids.size() == 0) { + return; + } + String whereString = " " + tableName + "_ID"; + // create query string + if (ids.size() == 1) { + if (ids.get(0).intValue() == 0) { + whereString = null; + } else { + whereString += "=" + ids.get(0).intValue(); + } + } else { + whereString += " IN ("; + for (int i = 0; i < ids.size(); i++) { + whereString += ids.get(i).intValue(); + if (i < ids.size() - 1) { + whereString += ","; + } else { + whereString += ") "; + } + } + } + log.fine(whereString); + + final MQuery query = new MQuery(tableName); + query.addRestriction(whereString); + final boolean ok = openWindow(windowId, query); + if (!ok) { + log.severe("Unable to open window: " + whereString); + } + if (!windowOpened && ok) + windowOpened = true; + } + + /** + * @param windowId + * @param query + * @return true if windowId open successfully + */ + protected abstract boolean openWindow(int windowId, MQuery query); +} diff --git a/client/src/de/schaeffer/compiere/tools/DocumentSearch.java b/client/src/de/schaeffer/compiere/tools/DocumentSearch.java index 44a9832cb9..4882445585 100644 --- a/client/src/de/schaeffer/compiere/tools/DocumentSearch.java +++ b/client/src/de/schaeffer/compiere/tools/DocumentSearch.java @@ -22,6 +22,7 @@ * * * Contributors: * * - Jan Roessler * +* - Heng Sin Low * * * * Sponsors: * * - Schaeffer * @@ -29,263 +30,30 @@ package de.schaeffer.compiere.tools; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.Vector; - +import org.adempiere.util.AbstractDocumentSearch; import org.compiere.apps.AEnv; import org.compiere.apps.AWindow; -import org.compiere.model.MColumn; import org.compiere.model.MQuery; -import org.compiere.model.MRole; -import org.compiere.model.MSearchDefinition; -import org.compiere.model.MTable; import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; /** * Executes search and opens windows for defined transaction codes - * + * * @author Jan Roessler, jr@schaeffer-ag.de - * + * */ -public class DocumentSearch { +public class DocumentSearch extends AbstractDocumentSearch { /** the logger */ static CLogger log = CLogger.getCLogger(DocumentSearch.class); - private static boolean windowOpened = false; - - /** - * @param searchString - */ - public static boolean openDocumentsByDocumentNo(String searchString) { - windowOpened = false; - - log.fine("Search started with String: " + searchString); - - // Check if / how many transaction-codes are used - if (searchString != null && !"".equals(searchString)) { - String[] codes = searchString.trim().replaceAll(" ", " ").split(" "); - - List codeList = new ArrayList(); - boolean codeSearch = true; - searchString = ""; - - // Analyze String to separate transactionCodes from searchString - for (int i = 0; i < codes.length; i++) { - try { - String s = codes[i]; - if (MSearchDefinition.isValidTransactionCode(s) && codeSearch) { - codeList.add(s); - } else { - // Build the searchString with eventually appearing - // whitespaces - codeSearch = false; - searchString += s; - if (i != (codes.length - 1)) { - searchString += " "; - } - } - } catch (SQLException e) { - log.severe(e.toString()); - e.printStackTrace(); - } - } - - // Start the search for every single code - if (codeList.size() > 0) { - for (int i = 0; i < codeList.size(); i++) { - log.fine("Search with Transaction: '" + codeList.get(i) + "' for: '" - + searchString + "'"); - getID(codeList.get(i), searchString); - } - } else { - log.fine("Search without Transaction: " + searchString); - getID(null, searchString); - } - } else { - log.fine("Search String is invalid"); - } - return windowOpened; - } - - /** - * search for id's that fit the searchString - * - * @param transactionCode - * @param searchString - */ - private static void getID(String transactionCode, String searchString) { - - ResultSet rsSO = null; - ResultSet rsPO = null; - PreparedStatement pstmtSO = null; - PreparedStatement pstmtPO = null; - String sqlSO = null; - String sqlPO = null; - - final Properties ctx = Env.getCtx(); - final MRole role = MRole.get(ctx, Env.getAD_Role_ID(ctx), Env.getAD_User_ID(ctx), true); - - try { - for (MSearchDefinition msd : MSearchDefinition.getForCode(transactionCode)) { - - MTable table = new MTable(Env.getCtx(), msd.getAD_Table_ID(), null); - // SearchDefinition with a given table and column - if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_TABLE)) { - MColumn column = new MColumn(Env.getCtx(), msd.getAD_Column_ID(), null); - sqlSO = "SELECT " + table.getTableName() + "_ID FROM " + table.getTableName() + " "; - // search for an Integer - if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) { - sqlSO += "WHERE " + column.getColumnName() + "=?"; - // search for a String - } else { - sqlSO += "WHERE UPPER(" + column.getColumnName()+ ") LIKE UPPER(?)"; - } - - if (msd.getPO_Window_ID() != 0) { - sqlPO = sqlSO + " AND IsSOTrx='N'"; - sqlSO += " AND IsSOTrx='Y'"; - } - pstmtSO = DB.prepareStatement(sqlSO, null); - pstmtPO = DB.prepareStatement(sqlPO, null); - // search for a Integer - if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) { - pstmtSO.setInt(1, Integer.valueOf(searchString.replaceAll("\\D", ""))); - if (msd.getPO_Window_ID() != 0) { - pstmtPO.setInt(1, Integer.valueOf(searchString.replaceAll("\\D", ""))); - } - // search for a String - } else if (msd.getDataType().equals(MSearchDefinition.DATATYPE_STRING)) { - pstmtSO.setString(1, searchString); - if (msd.getPO_Window_ID() != 0) { - pstmtPO.setString(1, searchString); - } - } - // SearchDefinition with a special query - } else if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_QUERY)) { - sqlSO = msd.getQuery(); - pstmtSO = DB.prepareStatement(sqlSO, null); - // count '?' in statement - int count = 1; - for (char c : sqlSO.toCharArray()) { - if (c == '?') { - count++; - } - } - for (int i = 1; i < count; i++) { - if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) { - pstmtSO.setInt(i, Integer.valueOf(searchString.replaceAll("\\D", ""))); - } else if (msd.getDataType().equals(MSearchDefinition.DATATYPE_STRING)) { - pstmtSO.setString(i, searchString); - } - } - } - if (pstmtSO != null) { - log.fine("SQL Sales: " + sqlSO); - rsSO = pstmtSO.executeQuery(); - Vector idSO = new Vector(); - while (rsSO.next()) { - idSO.add(new Integer(rsSO.getInt(1))); - } - if (role.getWindowAccess(msd.getAD_Window_ID()) != null) { - log.fine("Open Window: " + msd.getAD_Window_ID() + " / Table: " - + table.getTableName() + " / Number of Results: " + idSO.size()); - - if (idSO.size() == 0 && (searchString == null || searchString.trim().length() == 0)) { - // No search string - open the window with new record - idSO.add(new Integer(0)); - } - - openWindow(idSO, table.getTableName(), msd.getAD_Window_ID()); - } else { - log.warning("Role is not allowed to view this window"); - } - } - if (pstmtPO != null) { - log.fine("SQL Purchase: " + sqlPO); - rsPO = pstmtPO.executeQuery(); - Vector idPO = new Vector(); - while (rsPO.next()) { - idPO.add(new Integer(rsPO.getInt(1))); - } - if (role.getWindowAccess(msd.getPO_Window_ID()) != null) { - log.fine("Open Window: " + msd.getPO_Window_ID() + " / Table: " - + table.getTableName() + " / Number of Results: " + idPO.size()); - openWindow(idPO, table.getTableName(), msd.getPO_Window_ID()); - } else { - log.warning("Role is not allowed to view this window"); - } - } - DB.close(rsSO, pstmtSO); - DB.close(rsPO, pstmtPO); - pstmtSO = null; - pstmtPO = null; - rsSO = null; - rsPO = null; - } - } catch (Exception e) { - log.severe(e.toString()); - e.printStackTrace(); - } finally { - DB.close(rsSO, pstmtSO); - DB.close(rsPO, pstmtPO); - rsSO = null; - rsPO = null; - pstmtSO = null; - pstmtPO = null; - } - } - - /** - * opens window with the given documents - * - * @param ids - * - document id's - * @param tableName - * @param windowId - */ - private static void openWindow(Vector ids, String tableName, int windowId) { - if (ids == null || ids.size() == 0) { - return; - } - String whereString = " " + tableName + "_ID"; - // create query string - if (ids.size() == 1) { - if (ids.get(0).intValue() == 0) { - whereString = null; - } else { - whereString += "=" + ids.get(0).intValue(); - } - } else { - whereString += " IN ("; - for (int i = 0; i < ids.size(); i++) { - whereString += ids.get(i).intValue(); - if (i < ids.size() - 1) { - whereString += ","; - } else { - whereString += ") "; - } - } - } - log.fine(whereString); + @Override + protected boolean openWindow(int windowId, MQuery query) { final AWindow frame = new AWindow(); AEnv.addToWindowManager(frame); - final MQuery query = new MQuery(tableName); - query.addRestriction(whereString); final boolean ok = frame.initWindow(windowId, query); - if (!ok) { - log.severe("Unable to open window: " + whereString); - } frame.pack(); AEnv.showCenterScreen(frame); - if (!windowOpened && ok) - windowOpened = true; + return ok; } } diff --git a/client/src/org/compiere/grid/tree/VTreePanel.java b/client/src/org/compiere/grid/tree/VTreePanel.java index 61dabeb159..d155d5a4b3 100644 --- a/client/src/org/compiere/grid/tree/VTreePanel.java +++ b/client/src/org/compiere/grid/tree/VTreePanel.java @@ -110,7 +110,7 @@ import de.schaeffer.compiere.tools.DocumentSearch; * * @author Jorg Janke * @version $Id: VTreePanel.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ - * + * * Contributors: * kthiemann / Carlos Ruiz - 2761420 - Advanced Search */ @@ -118,7 +118,7 @@ public final class VTreePanel extends CPanel implements ActionListener, DragGestureListener, DragSourceListener, DropTargetListener { /** - * + * */ private static final long serialVersionUID = -6798614427038652192L; @@ -163,7 +163,7 @@ public final class VTreePanel extends CPanel if ("lookAndFeel".equals(evt.getPropertyName())) m_lookAndFeelChanged = true; } - + }); } // base settings @@ -193,7 +193,7 @@ public final class VTreePanel extends CPanel m_root = vTree.getRoot(); m_root.setName(Msg.getMsg(Env.getCtx(), vTree.getName() ) ); // translate name of menu. // m_root.setName(Msg.getMsg(Env.getCtx(), "Menu") ); // @Trifon; this is the hardcoded way. - + log.config("root=" + m_root); m_nodeTableName = vTree.getNodeTableName(); treeModel = new DefaultTreeModel(m_root, true); @@ -206,7 +206,7 @@ public final class VTreePanel extends CPanel jt.removeAll(); toolbarMap = new HashMap(); Enumeration enTop = m_root.children(); - JToolBar jt = null; + JToolBar jt = null; Map titleMap = new HashMap(); while (enTop.hasMoreElements()) { @@ -237,7 +237,7 @@ public final class VTreePanel extends CPanel jt2.setFloatable(false); jt2.setRollover(true); jt2.setBorder(BorderFactory.createEmptyBorder()); - + JXTaskPane barPart = new JXTaskPane(); //Begin - [FR 1953769] barPart.setUI(new AdempiereTaskPaneUI()); @@ -247,7 +247,7 @@ public final class VTreePanel extends CPanel barPart.setLayout(new BorderLayout()); barPart.add(jt2, BorderLayout.NORTH); barPart.setTitle(titleMap.get(jt2)); - + bar.add(barPart); //Begin - [FR 1953769] bar.setBackground(AdempierePLAF.getFormBackground()); @@ -334,12 +334,12 @@ public final class VTreePanel extends CPanel treePane.getViewport().add(tree, null); treePane.setBorder(new ShadowBorder()); tree.setBorder(BorderFactory.createEmptyBorder()); - + CPanel treePart = new CPanel(); treePart.setLayout(new BorderLayout()); treePart.add(treePane, BorderLayout.CENTER); treePart.setBorder(BorderFactory.createEmptyBorder()); - + // treeExpand.setText(Msg.getMsg(Env.getCtx(), "ExpandTree")); treeExpand.setActionCommand("Expand"); @@ -367,7 +367,7 @@ public final class VTreePanel extends CPanel removeSplitPaneBorder(); this.add(centerSplitPane, BorderLayout.CENTER); - + // mFrom.setText(Msg.getMsg(Env.getCtx(), "ItemMove")); mFrom.setActionCommand("From"); @@ -376,7 +376,7 @@ public final class VTreePanel extends CPanel mTo.setText(Msg.getMsg(Env.getCtx(), "ItemInsert")); mTo.setActionCommand("To"); mTo.addActionListener(this); - + mBarAdd.setText(Msg.getMsg(Env.getCtx(), "BarAdd")); mBarAdd.setActionCommand("BarAdd"); mBarAdd.addActionListener(this); @@ -403,7 +403,7 @@ public final class VTreePanel extends CPanel } } } - + /** * Set Divider Location * @param location location (80 default) @@ -412,7 +412,7 @@ public final class VTreePanel extends CPanel { centerSplitPane.setDividerLocation(location); } // setDividerLocation - + /** * Get Divider Location * @return divider location @@ -421,8 +421,8 @@ public final class VTreePanel extends CPanel { return centerSplitPane.getDividerLocation(); } // getDividerLocation - - + + /************************************************************************* * Drag & Drop */ @@ -607,10 +607,10 @@ public final class VTreePanel extends CPanel .append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID) .append(" AND Node_ID=").append(nd.getNode_ID()); log.fine(sql.toString()); - //begin vpj-cd e-evolution 07/12/2005 PostgreSQL + //begin vpj-cd e-evolution 07/12/2005 PostgreSQL //stmt.executeUpdate(sql.toString()); no = DB.executeUpdate(sql.toString(),trx.getTrxName()); - //end vpj-cd e-evolution 07/12/2005 PostgreSQL + //end vpj-cd e-evolution 07/12/2005 PostgreSQL } if (oldParent != newParent) for (int i = 0; i < newParent.getChildCount(); i++) @@ -624,18 +624,18 @@ public final class VTreePanel extends CPanel .append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID) .append(" AND Node_ID=").append(nd.getNode_ID()); log.fine(sql.toString()); - //begin vpj-cd e-evolution 07/12/2005 PostgreSQL + //begin vpj-cd e-evolution 07/12/2005 PostgreSQL //stmt.executeUpdate(sql.toString()); no = DB.executeUpdate(sql.toString(),trx.getTrxName()); //end vpj-cd e-evolution 07/12/2005 PostgreSQL } // COMMIT ********************* trx.commit(true); - //begin vpj-cd e-evolution 07/12/2005 PostgreSQL + //begin vpj-cd e-evolution 07/12/2005 PostgreSQL //stmt.close(); //end vpj-cd e-evolution 07/12/2005 PostgreSQL } - ///begin vpj-cd e-evolution 07/12/2005 PostgreSQL + ///begin vpj-cd e-evolution 07/12/2005 PostgreSQL //catch (SQLException e) catch (Exception e) //end vpj-cd e-evolution 07/12/2005 PostgreSQL @@ -665,12 +665,13 @@ public final class VTreePanel extends CPanel && treeSearch.getText().length() > 0 && treeSearch.getText().substring(0, 1).equals(PREFIX_DOCUMENT_SEARCH)) { setBusy(true); - if (DocumentSearch.openDocumentsByDocumentNo(treeSearch.getText().substring(1))) + DocumentSearch search = new DocumentSearch(); + if (search.openDocumentsByDocumentNo(treeSearch.getText().substring(1))) treeSearch.setText(null); setBusy(false); return; } - + // *** Tree *** if (e.getSource() instanceof JTree || (e.getSource() == treeSearch && e.getModifiers() != 0)) // InputEvent.CTRL_MASK @@ -816,14 +817,14 @@ public final class VTreePanel extends CPanel { if (m_root == null) return false; - log.config("NodeID=" + nodeID + log.config("NodeID=" + nodeID + ", Show=" + show + ", root=" + m_root); // try to find the node MTreeNode node = m_root.findNode (nodeID); if (node != null) { TreePath treePath = new TreePath(node.getPath()); - log.config("Node=" + node + log.config("Node=" + node + ", Path=" + treePath.toString()); tree.setSelectionPath(treePath); if (show) @@ -850,7 +851,7 @@ public final class VTreePanel extends CPanel firePropertyChange(NODE_SELECTION, null, nd); } // setSelectedNode - + /************************************************************************** * Node Changed - synchronize Node * @@ -865,13 +866,13 @@ public final class VTreePanel extends CPanel String name, String description, boolean isSummary, String imageIndicator) { log.config("Save=" + save + ", KeyID=" + keyID - + ", Name=" + name + ", Description=" + description + + ", Name=" + name + ", Description=" + description + ", IsSummary=" + isSummary + ", ImageInd=" + imageIndicator + ", root=" + m_root); // if ID==0=root - don't update it if (keyID == 0) - return; - + return; + // try to find the node MTreeNode node = m_root.findNode(keyID); @@ -994,9 +995,9 @@ public final class VTreePanel extends CPanel else if (CLogger.retrieveException().getMessage().indexOf("ORA-00001")!=-1) ADialog.error(0, this, "BookmarkExist", null); } // barAdd - + /** - * Returns the top level parent JToolBar for the given MTreenode. If the parent is not on + * Returns the top level parent JToolBar for the given MTreenode. If the parent is not on * the CPanel yet a new one is created and added. * @param nd * @return top level parent JToolBar for the given MTreenode @@ -1005,7 +1006,7 @@ public final class VTreePanel extends CPanel int topParentId = getTopParentId(nd); JToolBar parent = toolbarMap.get(topParentId); if(parent==null){ - Enumeration enTop =m_root.children(); + Enumeration enTop =m_root.children(); while (enTop.hasMoreElements()) { MTreeNode ndTop = (MTreeNode)enTop.nextElement(); if(ndTop.getNode_ID()==topParentId){ @@ -1105,7 +1106,7 @@ public final class VTreePanel extends CPanel bar.remove(parentPanel); //remove from toolBarMap.. toolbarMap.values().remove(parentBar); - + } bar.validate(); bar.repaint(); @@ -1193,7 +1194,7 @@ public final class VTreePanel extends CPanel treeSearch.setCursor(Cursor.getDefaultCursor()); } } // set Busy - + } // VTreePanel @@ -1222,8 +1223,8 @@ class VTreePanel_mouseAdapter extends java.awt.event.MouseAdapter { m_adaptee.mouseClicked(e); } - - + + } // VTreePanel_mouseAdapter /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/IDesktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/IDesktop.java index 002e1e2d20..410f5c6ee0 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/IDesktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/IDesktop.java @@ -1,6 +1,6 @@ /****************************************************************************** * Copyright (C) 2008 Low Heng Sin * - * Copyright (C) 2008 Idalica Corporation * + * Copyright (C) 2008 Idalica Corporation * * 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 * @@ -34,28 +34,28 @@ public interface IDesktop extends UIPart { public static final String WINDOWNO_ATTRIBUTE = "desktop.windowno"; public static final String CLASS_NAME_KEY = "ZK_DESKTOP_CLASS"; - + /** - * + * * @return ClientInfo */ public ClientInfo getClientInfo(); /** - * + * * @param nodeId */ public void onMenuSelected(int nodeId); /** - * + * * @param window * @return windowNo */ public int registerWindow(Object window); - + /** - * + * * @param WindowNo * @return Object */ @@ -66,23 +66,23 @@ public interface IDesktop extends UIPart { * @return boolean */ public boolean closeActiveWindow(); - + /** - * + * * @param windowNo * @return boolean */ - public boolean closeWindow(int windowNo); + public boolean closeWindow(int windowNo); /** - * + * * @param url * @param closeable */ public void showURL(String url, boolean closeable); /** - * + * * @param doc * @param string * @param closeable @@ -90,48 +90,55 @@ public interface IDesktop extends UIPart { public void showURL(WebDoc doc, String string, boolean closeable); /** - * + * * @param win */ public void showWindow(Window win); - + /** - * + * * @param win * @param position */ public void showWindow(Window win, String position); /** - * + * * @param window_ID * @param query */ public void showZoomWindow(int window_ID, MQuery query); /** - * + * + * @param window_ID + * @param query + */ + public void showWindow(int window_ID, MQuery query); + + /** + * * @param windowNo */ public void unregisterWindow(int windowNo); - + /** - * + * * @param processId * @param soTrx * @return ProcessDialog */ public ProcessDialog openProcessDialog(int processId, boolean soTrx); - + /** - * + * * @param formId * @return ADWindow */ public ADForm openForm(int formId); - + /** - * + * * @param windowId * @return ADWindow */ @@ -144,7 +151,7 @@ public interface IDesktop extends UIPart { public void openTask(int task_ID); /** - * + * * @param workflow_ID */ public void openWorkflow(int workflow_ID); @@ -172,10 +179,10 @@ public interface IDesktop extends UIPart { public void logout(); /** - * Invoke by the server push thread. If the desktop argument is not null, must activate desktop - * before making update to UI. For performance reason, keep the activate of desktop as short + * Invoke by the server push thread. If the desktop argument is not null, must activate desktop + * before making update to UI. For performance reason, keep the activate of desktop as short * as possible. - * @param template + * @param template */ public void onServerPush(ServerPushTemplate template); } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/TabbedDesktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/TabbedDesktop.java index 1a2c70dcc8..0d54790383 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/TabbedDesktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/TabbedDesktop.java @@ -1,6 +1,6 @@ /****************************************************************************** * Copyright (C) 2008 Low Heng Sin * - * Copyright (C) 2008 Idalica Corporation * + * Copyright (C) 2008 Idalica Corporation * * 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 * @@ -42,16 +42,16 @@ import org.zkoss.zul.Tabpanels; * */ public abstract class TabbedDesktop extends AbstractDesktop { - + protected WindowContainer windowContainer; - + public TabbedDesktop() { super(); windowContainer = new WindowContainer(); } - + /** - * + * * @param processId * @param soTrx * @return ProcessDialog @@ -69,62 +69,62 @@ public abstract class TabbedDesktop extends AbstractDesktop { } /** - * + * * @param formId * @return ADWindow */ public ADForm openForm(int formId) { ADForm form = ADForm.openForm(formId); - + DesktopTabpanel tabPanel = new DesktopTabpanel(); form.setParent(tabPanel); //do not show window title when open as tab form.setTitle(null); windowContainer.addWindow(tabPanel, form.getFormName(), true); - + return form; } /** - * + * * @param workflow_ID */ public void openWorkflow(int workflow_ID) { WFPanel p = new WFPanel(); p.load(workflow_ID); - + DesktopTabpanel tabPanel = new DesktopTabpanel(); p.setParent(tabPanel); windowContainer.addWindow(tabPanel, p.getWorkflow().get_Translation(MWorkflow.COLUMNNAME_Name), true); } - + /** - * + * * @param windowId * @return ADWindow */ public ADWindow openWindow(int windowId) { ADWindow adWindow = new ADWindow(Env.getCtx(), windowId); - + DesktopTabpanel tabPanel = new DesktopTabpanel(); if (adWindow.createPart(tabPanel) != null) { - windowContainer.addWindow(tabPanel, adWindow.getTitle(), true); + windowContainer.addWindow(tabPanel, adWindow.getTitle(), true); return adWindow; } else { - //user cancel + //user cancel return null; } } - + /** - * + * * @param taskId */ public void openTask(int taskId) { MTask task = new MTask(Env.getCtx(), taskId, null); new WTask(task.getName(), task); } - + /** * @param url */ @@ -132,9 +132,9 @@ public abstract class TabbedDesktop extends AbstractDesktop { { showURL(url, url, closeable); } - + /** - * + * * @param url * @param title * @param closeable @@ -144,7 +144,7 @@ public abstract class TabbedDesktop extends AbstractDesktop { Iframe iframe = new Iframe(url); addWin(iframe, title, closeable); } - + /** * @param webDoc * @param title @@ -153,15 +153,15 @@ public abstract class TabbedDesktop extends AbstractDesktop { public void showURL(WebDoc webDoc, String title, boolean closeable) { Iframe iframe = new Iframe(); - + AMedia media = new AMedia(title, "html", "text/html", webDoc.toString().getBytes()); iframe.setContent(media); - + addWin(iframe, title, closeable); } - + /** - * + * * @param fr * @param title * @param closeable @@ -177,12 +177,12 @@ public abstract class TabbedDesktop extends AbstractDesktop { window.setStyle("padding: 0; margin: 0; border: none"); window.appendChild(fr); window.setStyle("position: absolute"); - + Tabpanel tabPanel = new Tabpanel(); window.setParent(tabPanel); windowContainer.addWindow(tabPanel, title, closeable); } - + /** * @param AD_Window_ID * @param query @@ -190,14 +190,27 @@ public abstract class TabbedDesktop extends AbstractDesktop { public void showZoomWindow(int AD_Window_ID, MQuery query) { ADWindow wnd = new ADWindow(Env.getCtx(), AD_Window_ID, query); - + DesktopTabpanel tabPanel = new DesktopTabpanel(); wnd.createPart(tabPanel); windowContainer.insertAfter(windowContainer.getSelectedTab(), tabPanel, wnd.getTitle(), true, true); } - + + /** + * @param AD_Window_ID + * @param query + */ + public void showWindow(int AD_Window_ID, MQuery query) + { + ADWindow wnd = new ADWindow(Env.getCtx(), AD_Window_ID, query); + + DesktopTabpanel tabPanel = new DesktopTabpanel(); + wnd.createPart(tabPanel); + windowContainer.addWindow(tabPanel, wnd.getTitle(), true); + } + /** - * + * * @param window */ protected void showEmbedded(Window window) @@ -211,7 +224,7 @@ public abstract class TabbedDesktop extends AbstractDesktop { else windowContainer.addWindow(tabPanel, title, true); } - + /** * Close active tab * @return boolean @@ -223,7 +236,7 @@ public abstract class TabbedDesktop extends AbstractDesktop { Tabpanel panel = (Tabpanel) windowContainer.getSelectedTab().getLinkedPanel(); Component component = panel.getFirstChild(); Object att = component.getAttribute(WINDOWNO_ATTRIBUTE); - + if ( windowContainer.closeActiveWindow() ) { if (att != null && (att instanceof Integer)) @@ -239,7 +252,7 @@ public abstract class TabbedDesktop extends AbstractDesktop { } return false; } - + /** * @return Component */ @@ -247,13 +260,13 @@ public abstract class TabbedDesktop extends AbstractDesktop { { return windowContainer.getSelectedTab().getLinkedPanel().getFirstChild(); } - + /** - * + * * @param windowNo * @return boolean */ - public boolean closeWindow(int windowNo) + public boolean closeWindow(int windowNo) { Tabbox tabbox = windowContainer.getComponent(); Tabpanels panels = tabbox.getTabpanels(); @@ -269,7 +282,7 @@ public abstract class TabbedDesktop extends AbstractDesktop { { Tab tab = panel.getLinkedTab(); panel.getLinkedTab().onClose(); - if (tab.getParent() == null) + if (tab.getParent() == null) { unregisterWindow(windowNo); return true; @@ -278,7 +291,7 @@ public abstract class TabbedDesktop extends AbstractDesktop { { return false; } - } + } } } return false; diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/panel/TreeSearchPanel.java b/zkwebui/WEB-INF/src/org/adempiere/webui/panel/TreeSearchPanel.java index 48f8529692..9c17789a9e 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/panel/TreeSearchPanel.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/panel/TreeSearchPanel.java @@ -22,6 +22,7 @@ import java.util.TreeMap; import org.adempiere.webui.component.AutoComplete; import org.adempiere.webui.component.Label; import org.adempiere.webui.component.Panel; +import org.adempiere.webui.util.DocumentSearch; import org.adempiere.webui.util.TreeItemAction; import org.adempiere.webui.util.TreeNodeAction; import org.adempiere.webui.util.TreeUtils; @@ -47,18 +48,20 @@ import org.zkoss.zul.event.TreeDataListener; public class TreeSearchPanel extends Panel implements EventListener, TreeDataListener { private static final long serialVersionUID = 1L; - + private TreeMap treeNodeItemMap = new TreeMap(); private String[] treeValues; private String[] treeDescription; - + private Label lblSearch; private AutoComplete cmbSearch; - + private Tree tree; private String eventToFire; - + + private static final String PREFIX_DOCUMENT_SEARCH = "/"; + /** * @param tree */ @@ -66,7 +69,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis { this(tree, Events.ON_CLICK); } - + /** * @param tree * @param event @@ -74,48 +77,48 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis public TreeSearchPanel(Tree tree, String event) { super(); - this.tree = tree; + this.tree = tree; this.eventToFire = event; init(); } - + private void init() { lblSearch = new Label(); lblSearch.setValue(Msg.getMsg(Env.getCtx(),"TreeSearch").replaceAll("&", "") + ":"); lblSearch.setTooltiptext(Msg.getMsg(Env.getCtx(),"TreeSearchText")); - + cmbSearch = new AutoComplete(); cmbSearch.setAutodrop(true); - + cmbSearch.addEventListener(Events.ON_CHANGE, this); - + this.appendChild(lblSearch); this.appendChild(cmbSearch); } - + private void addTreeItem(Treeitem treeItem) { String key = treeItem.getLabel(); treeNodeItemMap.put(key, treeItem); } - + private void addTreeItem(SimpleTreeNode node) { Object data = node.getData(); if (data instanceof MTreeNode) { MTreeNode mNode = (MTreeNode) data; treeNodeItemMap.put(mNode.getName(), node); - } + } } - + /** * populate the searchable list */ public void initialise() { refreshSearchList(); - - if (tree.getModel() != null) + + if (tree.getModel() != null) { tree.getModel().addTreeDataListener(this); } @@ -127,23 +130,23 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis TreeUtils.traverse(tree, new TreeItemAction() { public void run(Treeitem treeItem) { addTreeItem(treeItem); - } + } }); } else { TreeUtils.traverse(tree.getModel(), new TreeNodeAction() { public void run(SimpleTreeNode treeNode) { addTreeItem(treeNode); - } + } }); } - + treeValues = new String[treeNodeItemMap.size()]; treeDescription = new String[treeNodeItemMap.size()]; - + int i = -1; - + for (Object value : treeNodeItemMap.values()) - { + { i++; if (value instanceof Treeitem) { @@ -159,7 +162,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis treeDescription[i] = mNode.getDescription(); } } - + cmbSearch.setDescription(treeDescription); cmbSearch.setDict(treeValues); } @@ -173,6 +176,16 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis if (cmbSearch.equals(event.getTarget()) && (event.getName().equals(Events.ON_CHANGE))) { String value = cmbSearch.getValue(); + + if (value != null && value.trim().length() > 0 + && value.substring(0, 1).equals(PREFIX_DOCUMENT_SEARCH)) + { + DocumentSearch search = new DocumentSearch(); + if (search.openDocumentsByDocumentNo(value.substring(1))) + cmbSearch.setText(null); + return; + } + Object node = treeNodeItemMap.get(value); Treeitem treeItem = null; if (node == null) { @@ -180,7 +193,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis } else if (node instanceof Treeitem) { treeItem = (Treeitem) node; } else { - SimpleTreeNode sNode = (SimpleTreeNode) node; + SimpleTreeNode sNode = (SimpleTreeNode) node; int[] path = tree.getModel().getPath(tree.getModel().getRoot(), sNode); treeItem = tree.renderItemByPath(path); tree.setSelectedItem(treeItem); @@ -193,7 +206,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis } } } - + /** * don't call this directly, use internally for post selection event */ @@ -212,7 +225,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis while (parent != null) { if (!parent.isOpen()) parent.setOpen(true); - + parent = parent.getParentItem(); } selectedItem.getTree().setSelectedItem(selectedItem); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/util/DocumentSearch.java b/zkwebui/WEB-INF/src/org/adempiere/webui/util/DocumentSearch.java new file mode 100644 index 0000000000..fdec31de53 --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/util/DocumentSearch.java @@ -0,0 +1,50 @@ +/********************************************************************** +* This file is part of Adempiere ERP Bazaar * +* http://www.adempiere.org * +* * +* Copyright (C) Heng Sin Low * +* Copyright (C) Idalica Corporation * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* 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., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Jan Roessler * +* - Heng Sin Low +* * +* Sponsors: * +* - Schaeffer * +* - Idalica Corporation * +**********************************************************************/ +package org.adempiere.webui.util; + +import org.adempiere.util.AbstractDocumentSearch; +import org.adempiere.webui.session.SessionManager; +import org.compiere.model.MQuery; + +/** + * + * @author hengsin + * + */ +public class DocumentSearch extends AbstractDocumentSearch { + + @Override + protected boolean openWindow(int windowId, MQuery query) { + SessionManager.getAppDesktop().showWindow(windowId, query); + return true; + } + +}