[ adempiere-Patches-2761420 ] Advanced Search

- Refactor to work for both swing and zk client
This commit is contained in:
Heng Sin Low 2009-04-24 07:41:10 +00:00
parent 75eaa4c2c9
commit 648979a759
7 changed files with 510 additions and 366 deletions

View File

@ -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<String> codeList = new ArrayList<String>();
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<Integer> idSO = new Vector<Integer>();
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<Integer> idPO = new Vector<Integer>();
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<Integer> 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);
}

View File

@ -22,6 +22,7 @@
* * * *
* Contributors: * * Contributors: *
* - Jan Roessler * * - Jan Roessler *
* - Heng Sin Low *
* * * *
* Sponsors: * * Sponsors: *
* - Schaeffer * * - Schaeffer *
@ -29,263 +30,30 @@
package de.schaeffer.compiere.tools; package de.schaeffer.compiere.tools;
import java.sql.PreparedStatement; import org.adempiere.util.AbstractDocumentSearch;
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.apps.AEnv; import org.compiere.apps.AEnv;
import org.compiere.apps.AWindow; import org.compiere.apps.AWindow;
import org.compiere.model.MColumn;
import org.compiere.model.MQuery; 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.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Executes search and opens windows for defined transaction codes * Executes search and opens windows for defined transaction codes
* *
* @author Jan Roessler, jr@schaeffer-ag.de * @author Jan Roessler, jr@schaeffer-ag.de
* *
*/ */
public class DocumentSearch { public class DocumentSearch extends AbstractDocumentSearch {
/** the logger */ /** the logger */
static CLogger log = CLogger.getCLogger(DocumentSearch.class); static CLogger log = CLogger.getCLogger(DocumentSearch.class);
private static boolean windowOpened = false; @Override
protected boolean openWindow(int windowId, MQuery query) {
/**
* @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<String> codeList = new ArrayList<String>();
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<Integer> idSO = new Vector<Integer>();
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<Integer> idPO = new Vector<Integer>();
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<Integer> 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 AWindow frame = new AWindow(); final AWindow frame = new AWindow();
AEnv.addToWindowManager(frame); AEnv.addToWindowManager(frame);
final MQuery query = new MQuery(tableName);
query.addRestriction(whereString);
final boolean ok = frame.initWindow(windowId, query); final boolean ok = frame.initWindow(windowId, query);
if (!ok) {
log.severe("Unable to open window: " + whereString);
}
frame.pack(); frame.pack();
AEnv.showCenterScreen(frame); AEnv.showCenterScreen(frame);
if (!windowOpened && ok) return ok;
windowOpened = true;
} }
} }

View File

@ -110,7 +110,7 @@ import de.schaeffer.compiere.tools.DocumentSearch;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: VTreePanel.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ * @version $Id: VTreePanel.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $
* *
* Contributors: * Contributors:
* kthiemann / Carlos Ruiz - 2761420 - Advanced Search * kthiemann / Carlos Ruiz - 2761420 - Advanced Search
*/ */
@ -118,7 +118,7 @@ public final class VTreePanel extends CPanel
implements ActionListener, DragGestureListener, DragSourceListener, DropTargetListener implements ActionListener, DragGestureListener, DragSourceListener, DropTargetListener
{ {
/** /**
* *
*/ */
private static final long serialVersionUID = -6798614427038652192L; private static final long serialVersionUID = -6798614427038652192L;
@ -163,7 +163,7 @@ public final class VTreePanel extends CPanel
if ("lookAndFeel".equals(evt.getPropertyName())) if ("lookAndFeel".equals(evt.getPropertyName()))
m_lookAndFeelChanged = true; m_lookAndFeelChanged = true;
} }
}); });
} }
// base settings // base settings
@ -193,7 +193,7 @@ public final class VTreePanel extends CPanel
m_root = vTree.getRoot(); m_root = vTree.getRoot();
m_root.setName(Msg.getMsg(Env.getCtx(), vTree.getName() ) ); // translate name of menu. 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. // m_root.setName(Msg.getMsg(Env.getCtx(), "Menu") ); // @Trifon; this is the hardcoded way.
log.config("root=" + m_root); log.config("root=" + m_root);
m_nodeTableName = vTree.getNodeTableName(); m_nodeTableName = vTree.getNodeTableName();
treeModel = new DefaultTreeModel(m_root, true); treeModel = new DefaultTreeModel(m_root, true);
@ -206,7 +206,7 @@ public final class VTreePanel extends CPanel
jt.removeAll(); jt.removeAll();
toolbarMap = new HashMap<Integer, JToolBar>(); toolbarMap = new HashMap<Integer, JToolBar>();
Enumeration<?> enTop = m_root.children(); Enumeration<?> enTop = m_root.children();
JToolBar jt = null; JToolBar jt = null;
Map<JToolBar,String> titleMap = new HashMap<JToolBar, String>(); Map<JToolBar,String> titleMap = new HashMap<JToolBar, String>();
while (enTop.hasMoreElements()) while (enTop.hasMoreElements())
{ {
@ -237,7 +237,7 @@ public final class VTreePanel extends CPanel
jt2.setFloatable(false); jt2.setFloatable(false);
jt2.setRollover(true); jt2.setRollover(true);
jt2.setBorder(BorderFactory.createEmptyBorder()); jt2.setBorder(BorderFactory.createEmptyBorder());
JXTaskPane barPart = new JXTaskPane(); JXTaskPane barPart = new JXTaskPane();
//Begin - [FR 1953769] //Begin - [FR 1953769]
barPart.setUI(new AdempiereTaskPaneUI()); barPart.setUI(new AdempiereTaskPaneUI());
@ -247,7 +247,7 @@ public final class VTreePanel extends CPanel
barPart.setLayout(new BorderLayout()); barPart.setLayout(new BorderLayout());
barPart.add(jt2, BorderLayout.NORTH); barPart.add(jt2, BorderLayout.NORTH);
barPart.setTitle(titleMap.get(jt2)); barPart.setTitle(titleMap.get(jt2));
bar.add(barPart); bar.add(barPart);
//Begin - [FR 1953769] //Begin - [FR 1953769]
bar.setBackground(AdempierePLAF.getFormBackground()); bar.setBackground(AdempierePLAF.getFormBackground());
@ -334,12 +334,12 @@ public final class VTreePanel extends CPanel
treePane.getViewport().add(tree, null); treePane.getViewport().add(tree, null);
treePane.setBorder(new ShadowBorder()); treePane.setBorder(new ShadowBorder());
tree.setBorder(BorderFactory.createEmptyBorder()); tree.setBorder(BorderFactory.createEmptyBorder());
CPanel treePart = new CPanel(); CPanel treePart = new CPanel();
treePart.setLayout(new BorderLayout()); treePart.setLayout(new BorderLayout());
treePart.add(treePane, BorderLayout.CENTER); treePart.add(treePane, BorderLayout.CENTER);
treePart.setBorder(BorderFactory.createEmptyBorder()); treePart.setBorder(BorderFactory.createEmptyBorder());
// //
treeExpand.setText(Msg.getMsg(Env.getCtx(), "ExpandTree")); treeExpand.setText(Msg.getMsg(Env.getCtx(), "ExpandTree"));
treeExpand.setActionCommand("Expand"); treeExpand.setActionCommand("Expand");
@ -367,7 +367,7 @@ public final class VTreePanel extends CPanel
removeSplitPaneBorder(); removeSplitPaneBorder();
this.add(centerSplitPane, BorderLayout.CENTER); this.add(centerSplitPane, BorderLayout.CENTER);
// //
mFrom.setText(Msg.getMsg(Env.getCtx(), "ItemMove")); mFrom.setText(Msg.getMsg(Env.getCtx(), "ItemMove"));
mFrom.setActionCommand("From"); mFrom.setActionCommand("From");
@ -376,7 +376,7 @@ public final class VTreePanel extends CPanel
mTo.setText(Msg.getMsg(Env.getCtx(), "ItemInsert")); mTo.setText(Msg.getMsg(Env.getCtx(), "ItemInsert"));
mTo.setActionCommand("To"); mTo.setActionCommand("To");
mTo.addActionListener(this); mTo.addActionListener(this);
mBarAdd.setText(Msg.getMsg(Env.getCtx(), "BarAdd")); mBarAdd.setText(Msg.getMsg(Env.getCtx(), "BarAdd"));
mBarAdd.setActionCommand("BarAdd"); mBarAdd.setActionCommand("BarAdd");
mBarAdd.addActionListener(this); mBarAdd.addActionListener(this);
@ -403,7 +403,7 @@ public final class VTreePanel extends CPanel
} }
} }
} }
/** /**
* Set Divider Location * Set Divider Location
* @param location location (80 default) * @param location location (80 default)
@ -412,7 +412,7 @@ public final class VTreePanel extends CPanel
{ {
centerSplitPane.setDividerLocation(location); centerSplitPane.setDividerLocation(location);
} // setDividerLocation } // setDividerLocation
/** /**
* Get Divider Location * Get Divider Location
* @return divider location * @return divider location
@ -421,8 +421,8 @@ public final class VTreePanel extends CPanel
{ {
return centerSplitPane.getDividerLocation(); return centerSplitPane.getDividerLocation();
} // getDividerLocation } // getDividerLocation
/************************************************************************* /*************************************************************************
* Drag & Drop * Drag & Drop
*/ */
@ -607,10 +607,10 @@ public final class VTreePanel extends CPanel
.append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID) .append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID)
.append(" AND Node_ID=").append(nd.getNode_ID()); .append(" AND Node_ID=").append(nd.getNode_ID());
log.fine(sql.toString()); 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()); //stmt.executeUpdate(sql.toString());
no = DB.executeUpdate(sql.toString(),trx.getTrxName()); 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) if (oldParent != newParent)
for (int i = 0; i < newParent.getChildCount(); i++) 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(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID)
.append(" AND Node_ID=").append(nd.getNode_ID()); .append(" AND Node_ID=").append(nd.getNode_ID());
log.fine(sql.toString()); 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()); //stmt.executeUpdate(sql.toString());
no = DB.executeUpdate(sql.toString(),trx.getTrxName()); 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
} }
// COMMIT ********************* // COMMIT *********************
trx.commit(true); trx.commit(true);
//begin vpj-cd e-evolution 07/12/2005 PostgreSQL //begin vpj-cd e-evolution 07/12/2005 PostgreSQL
//stmt.close(); //stmt.close();
//end vpj-cd e-evolution 07/12/2005 PostgreSQL //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 (SQLException e)
catch (Exception e) catch (Exception e)
//end vpj-cd e-evolution 07/12/2005 PostgreSQL //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().length() > 0
&& treeSearch.getText().substring(0, 1).equals(PREFIX_DOCUMENT_SEARCH)) { && treeSearch.getText().substring(0, 1).equals(PREFIX_DOCUMENT_SEARCH)) {
setBusy(true); setBusy(true);
if (DocumentSearch.openDocumentsByDocumentNo(treeSearch.getText().substring(1))) DocumentSearch search = new DocumentSearch();
if (search.openDocumentsByDocumentNo(treeSearch.getText().substring(1)))
treeSearch.setText(null); treeSearch.setText(null);
setBusy(false); setBusy(false);
return; return;
} }
// *** Tree *** // *** Tree ***
if (e.getSource() instanceof JTree if (e.getSource() instanceof JTree
|| (e.getSource() == treeSearch && e.getModifiers() != 0)) // InputEvent.CTRL_MASK || (e.getSource() == treeSearch && e.getModifiers() != 0)) // InputEvent.CTRL_MASK
@ -816,14 +817,14 @@ public final class VTreePanel extends CPanel
{ {
if (m_root == null) if (m_root == null)
return false; return false;
log.config("NodeID=" + nodeID log.config("NodeID=" + nodeID
+ ", Show=" + show + ", root=" + m_root); + ", Show=" + show + ", root=" + m_root);
// try to find the node // try to find the node
MTreeNode node = m_root.findNode (nodeID); MTreeNode node = m_root.findNode (nodeID);
if (node != null) if (node != null)
{ {
TreePath treePath = new TreePath(node.getPath()); TreePath treePath = new TreePath(node.getPath());
log.config("Node=" + node log.config("Node=" + node
+ ", Path=" + treePath.toString()); + ", Path=" + treePath.toString());
tree.setSelectionPath(treePath); tree.setSelectionPath(treePath);
if (show) if (show)
@ -850,7 +851,7 @@ public final class VTreePanel extends CPanel
firePropertyChange(NODE_SELECTION, null, nd); firePropertyChange(NODE_SELECTION, null, nd);
} // setSelectedNode } // setSelectedNode
/************************************************************************** /**************************************************************************
* Node Changed - synchronize Node * Node Changed - synchronize Node
* *
@ -865,13 +866,13 @@ public final class VTreePanel extends CPanel
String name, String description, boolean isSummary, String imageIndicator) String name, String description, boolean isSummary, String imageIndicator)
{ {
log.config("Save=" + save + ", KeyID=" + keyID log.config("Save=" + save + ", KeyID=" + keyID
+ ", Name=" + name + ", Description=" + description + ", Name=" + name + ", Description=" + description
+ ", IsSummary=" + isSummary + ", ImageInd=" + imageIndicator + ", IsSummary=" + isSummary + ", ImageInd=" + imageIndicator
+ ", root=" + m_root); + ", root=" + m_root);
// if ID==0=root - don't update it // if ID==0=root - don't update it
if (keyID == 0) if (keyID == 0)
return; return;
// try to find the node // try to find the node
MTreeNode node = m_root.findNode(keyID); 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) else if (CLogger.retrieveException().getMessage().indexOf("ORA-00001")!=-1)
ADialog.error(0, this, "BookmarkExist", null); ADialog.error(0, this, "BookmarkExist", null);
} // barAdd } // 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. * the CPanel yet a new one is created and added.
* @param nd * @param nd
* @return top level parent JToolBar for the given MTreenode * @return top level parent JToolBar for the given MTreenode
@ -1005,7 +1006,7 @@ public final class VTreePanel extends CPanel
int topParentId = getTopParentId(nd); int topParentId = getTopParentId(nd);
JToolBar parent = toolbarMap.get(topParentId); JToolBar parent = toolbarMap.get(topParentId);
if(parent==null){ if(parent==null){
Enumeration<?> enTop =m_root.children(); Enumeration<?> enTop =m_root.children();
while (enTop.hasMoreElements()) { while (enTop.hasMoreElements()) {
MTreeNode ndTop = (MTreeNode)enTop.nextElement(); MTreeNode ndTop = (MTreeNode)enTop.nextElement();
if(ndTop.getNode_ID()==topParentId){ if(ndTop.getNode_ID()==topParentId){
@ -1105,7 +1106,7 @@ public final class VTreePanel extends CPanel
bar.remove(parentPanel); bar.remove(parentPanel);
//remove from toolBarMap.. //remove from toolBarMap..
toolbarMap.values().remove(parentBar); toolbarMap.values().remove(parentBar);
} }
bar.validate(); bar.validate();
bar.repaint(); bar.repaint();
@ -1193,7 +1194,7 @@ public final class VTreePanel extends CPanel
treeSearch.setCursor(Cursor.getDefaultCursor()); treeSearch.setCursor(Cursor.getDefaultCursor());
} }
} // set Busy } // set Busy
} // VTreePanel } // VTreePanel
@ -1222,8 +1223,8 @@ class VTreePanel_mouseAdapter extends java.awt.event.MouseAdapter
{ {
m_adaptee.mouseClicked(e); m_adaptee.mouseClicked(e);
} }
} // VTreePanel_mouseAdapter } // VTreePanel_mouseAdapter
/** /**

View File

@ -1,6 +1,6 @@
/****************************************************************************** /******************************************************************************
* Copyright (C) 2008 Low Heng Sin * * 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 * * 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 * * 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 * * 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 WINDOWNO_ATTRIBUTE = "desktop.windowno";
public static final String CLASS_NAME_KEY = "ZK_DESKTOP_CLASS"; public static final String CLASS_NAME_KEY = "ZK_DESKTOP_CLASS";
/** /**
* *
* @return ClientInfo * @return ClientInfo
*/ */
public ClientInfo getClientInfo(); public ClientInfo getClientInfo();
/** /**
* *
* @param nodeId * @param nodeId
*/ */
public void onMenuSelected(int nodeId); public void onMenuSelected(int nodeId);
/** /**
* *
* @param window * @param window
* @return windowNo * @return windowNo
*/ */
public int registerWindow(Object window); public int registerWindow(Object window);
/** /**
* *
* @param WindowNo * @param WindowNo
* @return Object * @return Object
*/ */
@ -66,23 +66,23 @@ public interface IDesktop extends UIPart {
* @return boolean * @return boolean
*/ */
public boolean closeActiveWindow(); public boolean closeActiveWindow();
/** /**
* *
* @param windowNo * @param windowNo
* @return boolean * @return boolean
*/ */
public boolean closeWindow(int windowNo); public boolean closeWindow(int windowNo);
/** /**
* *
* @param url * @param url
* @param closeable * @param closeable
*/ */
public void showURL(String url, boolean closeable); public void showURL(String url, boolean closeable);
/** /**
* *
* @param doc * @param doc
* @param string * @param string
* @param closeable * @param closeable
@ -90,48 +90,55 @@ public interface IDesktop extends UIPart {
public void showURL(WebDoc doc, String string, boolean closeable); public void showURL(WebDoc doc, String string, boolean closeable);
/** /**
* *
* @param win * @param win
*/ */
public void showWindow(Window win); public void showWindow(Window win);
/** /**
* *
* @param win * @param win
* @param position * @param position
*/ */
public void showWindow(Window win, String position); public void showWindow(Window win, String position);
/** /**
* *
* @param window_ID * @param window_ID
* @param query * @param query
*/ */
public void showZoomWindow(int window_ID, MQuery query); public void showZoomWindow(int window_ID, MQuery query);
/** /**
* *
* @param window_ID
* @param query
*/
public void showWindow(int window_ID, MQuery query);
/**
*
* @param windowNo * @param windowNo
*/ */
public void unregisterWindow(int windowNo); public void unregisterWindow(int windowNo);
/** /**
* *
* @param processId * @param processId
* @param soTrx * @param soTrx
* @return ProcessDialog * @return ProcessDialog
*/ */
public ProcessDialog openProcessDialog(int processId, boolean soTrx); public ProcessDialog openProcessDialog(int processId, boolean soTrx);
/** /**
* *
* @param formId * @param formId
* @return ADWindow * @return ADWindow
*/ */
public ADForm openForm(int formId); public ADForm openForm(int formId);
/** /**
* *
* @param windowId * @param windowId
* @return ADWindow * @return ADWindow
*/ */
@ -144,7 +151,7 @@ public interface IDesktop extends UIPart {
public void openTask(int task_ID); public void openTask(int task_ID);
/** /**
* *
* @param workflow_ID * @param workflow_ID
*/ */
public void openWorkflow(int workflow_ID); public void openWorkflow(int workflow_ID);
@ -172,10 +179,10 @@ public interface IDesktop extends UIPart {
public void logout(); public void logout();
/** /**
* Invoke by the server push thread. If the desktop argument is not null, must activate desktop * 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 * before making update to UI. For performance reason, keep the activate of desktop as short
* as possible. * as possible.
* @param template * @param template
*/ */
public void onServerPush(ServerPushTemplate template); public void onServerPush(ServerPushTemplate template);
} }

View File

@ -1,6 +1,6 @@
/****************************************************************************** /******************************************************************************
* Copyright (C) 2008 Low Heng Sin * * 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 * * 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 * * 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 * * 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 { public abstract class TabbedDesktop extends AbstractDesktop {
protected WindowContainer windowContainer; protected WindowContainer windowContainer;
public TabbedDesktop() { public TabbedDesktop() {
super(); super();
windowContainer = new WindowContainer(); windowContainer = new WindowContainer();
} }
/** /**
* *
* @param processId * @param processId
* @param soTrx * @param soTrx
* @return ProcessDialog * @return ProcessDialog
@ -69,62 +69,62 @@ public abstract class TabbedDesktop extends AbstractDesktop {
} }
/** /**
* *
* @param formId * @param formId
* @return ADWindow * @return ADWindow
*/ */
public ADForm openForm(int formId) { public ADForm openForm(int formId) {
ADForm form = ADForm.openForm(formId); ADForm form = ADForm.openForm(formId);
DesktopTabpanel tabPanel = new DesktopTabpanel(); DesktopTabpanel tabPanel = new DesktopTabpanel();
form.setParent(tabPanel); form.setParent(tabPanel);
//do not show window title when open as tab //do not show window title when open as tab
form.setTitle(null); form.setTitle(null);
windowContainer.addWindow(tabPanel, form.getFormName(), true); windowContainer.addWindow(tabPanel, form.getFormName(), true);
return form; return form;
} }
/** /**
* *
* @param workflow_ID * @param workflow_ID
*/ */
public void openWorkflow(int workflow_ID) { public void openWorkflow(int workflow_ID) {
WFPanel p = new WFPanel(); WFPanel p = new WFPanel();
p.load(workflow_ID); p.load(workflow_ID);
DesktopTabpanel tabPanel = new DesktopTabpanel(); DesktopTabpanel tabPanel = new DesktopTabpanel();
p.setParent(tabPanel); p.setParent(tabPanel);
windowContainer.addWindow(tabPanel, p.getWorkflow().get_Translation(MWorkflow.COLUMNNAME_Name), true); windowContainer.addWindow(tabPanel, p.getWorkflow().get_Translation(MWorkflow.COLUMNNAME_Name), true);
} }
/** /**
* *
* @param windowId * @param windowId
* @return ADWindow * @return ADWindow
*/ */
public ADWindow openWindow(int windowId) { public ADWindow openWindow(int windowId) {
ADWindow adWindow = new ADWindow(Env.getCtx(), windowId); ADWindow adWindow = new ADWindow(Env.getCtx(), windowId);
DesktopTabpanel tabPanel = new DesktopTabpanel(); DesktopTabpanel tabPanel = new DesktopTabpanel();
if (adWindow.createPart(tabPanel) != null) { if (adWindow.createPart(tabPanel) != null) {
windowContainer.addWindow(tabPanel, adWindow.getTitle(), true); windowContainer.addWindow(tabPanel, adWindow.getTitle(), true);
return adWindow; return adWindow;
} else { } else {
//user cancel //user cancel
return null; return null;
} }
} }
/** /**
* *
* @param taskId * @param taskId
*/ */
public void openTask(int taskId) { public void openTask(int taskId) {
MTask task = new MTask(Env.getCtx(), taskId, null); MTask task = new MTask(Env.getCtx(), taskId, null);
new WTask(task.getName(), task); new WTask(task.getName(), task);
} }
/** /**
* @param url * @param url
*/ */
@ -132,9 +132,9 @@ public abstract class TabbedDesktop extends AbstractDesktop {
{ {
showURL(url, url, closeable); showURL(url, url, closeable);
} }
/** /**
* *
* @param url * @param url
* @param title * @param title
* @param closeable * @param closeable
@ -144,7 +144,7 @@ public abstract class TabbedDesktop extends AbstractDesktop {
Iframe iframe = new Iframe(url); Iframe iframe = new Iframe(url);
addWin(iframe, title, closeable); addWin(iframe, title, closeable);
} }
/** /**
* @param webDoc * @param webDoc
* @param title * @param title
@ -153,15 +153,15 @@ public abstract class TabbedDesktop extends AbstractDesktop {
public void showURL(WebDoc webDoc, String title, boolean closeable) public void showURL(WebDoc webDoc, String title, boolean closeable)
{ {
Iframe iframe = new Iframe(); Iframe iframe = new Iframe();
AMedia media = new AMedia(title, "html", "text/html", webDoc.toString().getBytes()); AMedia media = new AMedia(title, "html", "text/html", webDoc.toString().getBytes());
iframe.setContent(media); iframe.setContent(media);
addWin(iframe, title, closeable); addWin(iframe, title, closeable);
} }
/** /**
* *
* @param fr * @param fr
* @param title * @param title
* @param closeable * @param closeable
@ -177,12 +177,12 @@ public abstract class TabbedDesktop extends AbstractDesktop {
window.setStyle("padding: 0; margin: 0; border: none"); window.setStyle("padding: 0; margin: 0; border: none");
window.appendChild(fr); window.appendChild(fr);
window.setStyle("position: absolute"); window.setStyle("position: absolute");
Tabpanel tabPanel = new Tabpanel(); Tabpanel tabPanel = new Tabpanel();
window.setParent(tabPanel); window.setParent(tabPanel);
windowContainer.addWindow(tabPanel, title, closeable); windowContainer.addWindow(tabPanel, title, closeable);
} }
/** /**
* @param AD_Window_ID * @param AD_Window_ID
* @param query * @param query
@ -190,14 +190,27 @@ public abstract class TabbedDesktop extends AbstractDesktop {
public void showZoomWindow(int AD_Window_ID, MQuery query) public void showZoomWindow(int AD_Window_ID, MQuery query)
{ {
ADWindow wnd = new ADWindow(Env.getCtx(), AD_Window_ID, query); ADWindow wnd = new ADWindow(Env.getCtx(), AD_Window_ID, query);
DesktopTabpanel tabPanel = new DesktopTabpanel(); DesktopTabpanel tabPanel = new DesktopTabpanel();
wnd.createPart(tabPanel); wnd.createPart(tabPanel);
windowContainer.insertAfter(windowContainer.getSelectedTab(), tabPanel, wnd.getTitle(), true, true); 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 * @param window
*/ */
protected void showEmbedded(Window window) protected void showEmbedded(Window window)
@ -211,7 +224,7 @@ public abstract class TabbedDesktop extends AbstractDesktop {
else else
windowContainer.addWindow(tabPanel, title, true); windowContainer.addWindow(tabPanel, title, true);
} }
/** /**
* Close active tab * Close active tab
* @return boolean * @return boolean
@ -223,7 +236,7 @@ public abstract class TabbedDesktop extends AbstractDesktop {
Tabpanel panel = (Tabpanel) windowContainer.getSelectedTab().getLinkedPanel(); Tabpanel panel = (Tabpanel) windowContainer.getSelectedTab().getLinkedPanel();
Component component = panel.getFirstChild(); Component component = panel.getFirstChild();
Object att = component.getAttribute(WINDOWNO_ATTRIBUTE); Object att = component.getAttribute(WINDOWNO_ATTRIBUTE);
if ( windowContainer.closeActiveWindow() ) if ( windowContainer.closeActiveWindow() )
{ {
if (att != null && (att instanceof Integer)) if (att != null && (att instanceof Integer))
@ -239,7 +252,7 @@ public abstract class TabbedDesktop extends AbstractDesktop {
} }
return false; return false;
} }
/** /**
* @return Component * @return Component
*/ */
@ -247,13 +260,13 @@ public abstract class TabbedDesktop extends AbstractDesktop {
{ {
return windowContainer.getSelectedTab().getLinkedPanel().getFirstChild(); return windowContainer.getSelectedTab().getLinkedPanel().getFirstChild();
} }
/** /**
* *
* @param windowNo * @param windowNo
* @return boolean * @return boolean
*/ */
public boolean closeWindow(int windowNo) public boolean closeWindow(int windowNo)
{ {
Tabbox tabbox = windowContainer.getComponent(); Tabbox tabbox = windowContainer.getComponent();
Tabpanels panels = tabbox.getTabpanels(); Tabpanels panels = tabbox.getTabpanels();
@ -269,7 +282,7 @@ public abstract class TabbedDesktop extends AbstractDesktop {
{ {
Tab tab = panel.getLinkedTab(); Tab tab = panel.getLinkedTab();
panel.getLinkedTab().onClose(); panel.getLinkedTab().onClose();
if (tab.getParent() == null) if (tab.getParent() == null)
{ {
unregisterWindow(windowNo); unregisterWindow(windowNo);
return true; return true;
@ -278,7 +291,7 @@ public abstract class TabbedDesktop extends AbstractDesktop {
{ {
return false; return false;
} }
} }
} }
} }
return false; return false;

View File

@ -22,6 +22,7 @@ import java.util.TreeMap;
import org.adempiere.webui.component.AutoComplete; import org.adempiere.webui.component.AutoComplete;
import org.adempiere.webui.component.Label; import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.Panel;
import org.adempiere.webui.util.DocumentSearch;
import org.adempiere.webui.util.TreeItemAction; import org.adempiere.webui.util.TreeItemAction;
import org.adempiere.webui.util.TreeNodeAction; import org.adempiere.webui.util.TreeNodeAction;
import org.adempiere.webui.util.TreeUtils; import org.adempiere.webui.util.TreeUtils;
@ -47,18 +48,20 @@ import org.zkoss.zul.event.TreeDataListener;
public class TreeSearchPanel extends Panel implements EventListener, TreeDataListener public class TreeSearchPanel extends Panel implements EventListener, TreeDataListener
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private TreeMap<String, Object> treeNodeItemMap = new TreeMap<String, Object>(); private TreeMap<String, Object> treeNodeItemMap = new TreeMap<String, Object>();
private String[] treeValues; private String[] treeValues;
private String[] treeDescription; private String[] treeDescription;
private Label lblSearch; private Label lblSearch;
private AutoComplete cmbSearch; private AutoComplete cmbSearch;
private Tree tree; private Tree tree;
private String eventToFire; private String eventToFire;
private static final String PREFIX_DOCUMENT_SEARCH = "/";
/** /**
* @param tree * @param tree
*/ */
@ -66,7 +69,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
{ {
this(tree, Events.ON_CLICK); this(tree, Events.ON_CLICK);
} }
/** /**
* @param tree * @param tree
* @param event * @param event
@ -74,48 +77,48 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
public TreeSearchPanel(Tree tree, String event) public TreeSearchPanel(Tree tree, String event)
{ {
super(); super();
this.tree = tree; this.tree = tree;
this.eventToFire = event; this.eventToFire = event;
init(); init();
} }
private void init() private void init()
{ {
lblSearch = new Label(); lblSearch = new Label();
lblSearch.setValue(Msg.getMsg(Env.getCtx(),"TreeSearch").replaceAll("&", "") + ":"); lblSearch.setValue(Msg.getMsg(Env.getCtx(),"TreeSearch").replaceAll("&", "") + ":");
lblSearch.setTooltiptext(Msg.getMsg(Env.getCtx(),"TreeSearchText")); lblSearch.setTooltiptext(Msg.getMsg(Env.getCtx(),"TreeSearchText"));
cmbSearch = new AutoComplete(); cmbSearch = new AutoComplete();
cmbSearch.setAutodrop(true); cmbSearch.setAutodrop(true);
cmbSearch.addEventListener(Events.ON_CHANGE, this); cmbSearch.addEventListener(Events.ON_CHANGE, this);
this.appendChild(lblSearch); this.appendChild(lblSearch);
this.appendChild(cmbSearch); this.appendChild(cmbSearch);
} }
private void addTreeItem(Treeitem treeItem) private void addTreeItem(Treeitem treeItem)
{ {
String key = treeItem.getLabel(); String key = treeItem.getLabel();
treeNodeItemMap.put(key, treeItem); treeNodeItemMap.put(key, treeItem);
} }
private void addTreeItem(SimpleTreeNode node) { private void addTreeItem(SimpleTreeNode node) {
Object data = node.getData(); Object data = node.getData();
if (data instanceof MTreeNode) { if (data instanceof MTreeNode) {
MTreeNode mNode = (MTreeNode) data; MTreeNode mNode = (MTreeNode) data;
treeNodeItemMap.put(mNode.getName(), node); treeNodeItemMap.put(mNode.getName(), node);
} }
} }
/** /**
* populate the searchable list * populate the searchable list
*/ */
public void initialise() public void initialise()
{ {
refreshSearchList(); refreshSearchList();
if (tree.getModel() != null) if (tree.getModel() != null)
{ {
tree.getModel().addTreeDataListener(this); tree.getModel().addTreeDataListener(this);
} }
@ -127,23 +130,23 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
TreeUtils.traverse(tree, new TreeItemAction() { TreeUtils.traverse(tree, new TreeItemAction() {
public void run(Treeitem treeItem) { public void run(Treeitem treeItem) {
addTreeItem(treeItem); addTreeItem(treeItem);
} }
}); });
} else { } else {
TreeUtils.traverse(tree.getModel(), new TreeNodeAction() { TreeUtils.traverse(tree.getModel(), new TreeNodeAction() {
public void run(SimpleTreeNode treeNode) { public void run(SimpleTreeNode treeNode) {
addTreeItem(treeNode); addTreeItem(treeNode);
} }
}); });
} }
treeValues = new String[treeNodeItemMap.size()]; treeValues = new String[treeNodeItemMap.size()];
treeDescription = new String[treeNodeItemMap.size()]; treeDescription = new String[treeNodeItemMap.size()];
int i = -1; int i = -1;
for (Object value : treeNodeItemMap.values()) for (Object value : treeNodeItemMap.values())
{ {
i++; i++;
if (value instanceof Treeitem) if (value instanceof Treeitem)
{ {
@ -159,7 +162,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
treeDescription[i] = mNode.getDescription(); treeDescription[i] = mNode.getDescription();
} }
} }
cmbSearch.setDescription(treeDescription); cmbSearch.setDescription(treeDescription);
cmbSearch.setDict(treeValues); 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))) if (cmbSearch.equals(event.getTarget()) && (event.getName().equals(Events.ON_CHANGE)))
{ {
String value = cmbSearch.getValue(); 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); Object node = treeNodeItemMap.get(value);
Treeitem treeItem = null; Treeitem treeItem = null;
if (node == null) { if (node == null) {
@ -180,7 +193,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
} else if (node instanceof Treeitem) { } else if (node instanceof Treeitem) {
treeItem = (Treeitem) node; treeItem = (Treeitem) node;
} else { } else {
SimpleTreeNode sNode = (SimpleTreeNode) node; SimpleTreeNode sNode = (SimpleTreeNode) node;
int[] path = tree.getModel().getPath(tree.getModel().getRoot(), sNode); int[] path = tree.getModel().getPath(tree.getModel().getRoot(), sNode);
treeItem = tree.renderItemByPath(path); treeItem = tree.renderItemByPath(path);
tree.setSelectedItem(treeItem); 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 * 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) { while (parent != null) {
if (!parent.isOpen()) if (!parent.isOpen())
parent.setOpen(true); parent.setOpen(true);
parent = parent.getParentItem(); parent = parent.getParentItem();
} }
selectedItem.getTree().setSelectedItem(selectedItem); selectedItem.getTree().setSelectedItem(selectedItem);

View File

@ -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;
}
}