IDEMPIERE-4382 Locator Editor inconsistent in the application of filter (#183)
pass ValidationCode to MLocatorLookup Fix dynamic display support Fix filter for grid view Fix locator dialog not open with the selected locator
This commit is contained in:
parent
40efcea51e
commit
80146138ac
|
@ -42,7 +42,7 @@ public class DefaultLookupFactory implements ILookupFactory{
|
||||||
}
|
}
|
||||||
else if (gridFieldVO.displayType == DisplayType.Locator)
|
else if (gridFieldVO.displayType == DisplayType.Locator)
|
||||||
{
|
{
|
||||||
lookup = new MLocatorLookup (gridFieldVO.ctx, gridFieldVO.WindowNo);
|
lookup = new MLocatorLookup (gridFieldVO.ctx, gridFieldVO.WindowNo, gridFieldVO.ValidationCode);
|
||||||
}
|
}
|
||||||
else if (gridFieldVO.displayType == Account) // not cached
|
else if (gridFieldVO.displayType == Account) // not cached
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.KeyNamePair;
|
import org.compiere.util.KeyNamePair;
|
||||||
import org.compiere.util.NamePair;
|
import org.compiere.util.NamePair;
|
||||||
import org.compiere.util.Util;
|
import org.compiere.util.Util;
|
||||||
|
@ -57,9 +58,21 @@ public final class MLocatorLookup extends Lookup implements Serializable
|
||||||
* @param WindowNo window no
|
* @param WindowNo window no
|
||||||
*/
|
*/
|
||||||
public MLocatorLookup(Properties ctx, int WindowNo)
|
public MLocatorLookup(Properties ctx, int WindowNo)
|
||||||
|
{
|
||||||
|
this(ctx, WindowNo, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param ctx context
|
||||||
|
* @param WindowNo window no
|
||||||
|
* @param validationCode Lookup validation code
|
||||||
|
*/
|
||||||
|
public MLocatorLookup(Properties ctx, int WindowNo, String validationCode)
|
||||||
{
|
{
|
||||||
super (DisplayType.TableDir, WindowNo);
|
super (DisplayType.TableDir, WindowNo);
|
||||||
m_ctx = ctx;
|
m_ctx = ctx;
|
||||||
|
m_validationCode = validationCode;
|
||||||
//
|
//
|
||||||
m_loader = new Loader();
|
m_loader = new Loader();
|
||||||
m_loader.start();
|
m_loader.start();
|
||||||
|
@ -69,6 +82,9 @@ public final class MLocatorLookup extends Lookup implements Serializable
|
||||||
private Properties m_ctx;
|
private Properties m_ctx;
|
||||||
protected int C_Locator_ID;
|
protected int C_Locator_ID;
|
||||||
private Loader m_loader;
|
private Loader m_loader;
|
||||||
|
private String m_validationCode;
|
||||||
|
private String m_parsedValidation;
|
||||||
|
private int m_warehouseActiveCount;
|
||||||
|
|
||||||
/** Only Warehouse */
|
/** Only Warehouse */
|
||||||
private int m_only_Warehouse_ID = 0;
|
private int m_only_Warehouse_ID = 0;
|
||||||
|
@ -300,7 +316,36 @@ public final class MLocatorLookup extends Lookup implements Serializable
|
||||||
return false;
|
return false;
|
||||||
} // isValid
|
} // isValid
|
||||||
|
|
||||||
|
private boolean isNeedRefresh()
|
||||||
|
{
|
||||||
|
if (!Util.isEmpty(m_validationCode))
|
||||||
|
{
|
||||||
|
Properties ctx = new Properties(m_ctx);
|
||||||
|
Env.setContext(ctx, getWindowNo(), "M_Product_ID", getOnly_Product_ID());
|
||||||
|
Env.setContext(ctx, getWindowNo(), "M_Warehouse_ID", getOnly_Warehouse_ID());
|
||||||
|
String parseValidation = Env.parseContext(ctx, getWindowNo(), m_validationCode, false, false);
|
||||||
|
if ((!Util.isEmpty(parseValidation) && !parseValidation.equals(m_parsedValidation)) || (!Util.isEmpty(m_parsedValidation) && !m_parsedValidation.equals(parseValidation)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (!Util.isEmpty(m_parsedValidation))
|
||||||
|
{
|
||||||
|
m_parsedValidation = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_only_Warehouse_ID==0)
|
||||||
|
{
|
||||||
|
int activeCount = DB.getSQLValue(null, "SELECT Count(*) FROM M_Warehouse WHERE IsActive='Y' AND AD_Client_ID=?", Env.getAD_Client_ID(m_ctx));
|
||||||
|
if (m_warehouseActiveCount != activeCount)
|
||||||
|
{
|
||||||
|
m_warehouseActiveCount = activeCount;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Loader
|
* Loader
|
||||||
*/
|
*/
|
||||||
|
@ -336,12 +381,27 @@ public final class MLocatorLookup extends Lookup implements Serializable
|
||||||
|
|
||||||
if (local_only_warehouse_id != 0)
|
if (local_only_warehouse_id != 0)
|
||||||
sql.append(" AND M_Locator.M_Warehouse_ID=?");
|
sql.append(" AND M_Locator.M_Warehouse_ID=?");
|
||||||
|
else
|
||||||
|
m_warehouseActiveCount = DB.getSQLValue(null, "SELECT Count(*) FROM M_Warehouse WHERE IsActive='Y' AND AD_Client_ID=?", Env.getAD_Client_ID(m_ctx));
|
||||||
if (local_only_product_id != 0)
|
if (local_only_product_id != 0)
|
||||||
sql.append(" AND (M_Locator.IsDefault='Y' ") // Default Locator
|
sql.append(" AND (M_Locator.IsDefault='Y' ") // Default Locator
|
||||||
.append("OR EXISTS (SELECT * FROM M_Product p ") // Product Locator
|
.append("OR EXISTS (SELECT * FROM M_Product p ") // Product Locator
|
||||||
.append("WHERE p.M_Locator_ID=M_Locator.M_Locator_ID AND p.M_Product_ID=?)")
|
.append("WHERE p.M_Locator_ID=M_Locator.M_Locator_ID AND p.M_Product_ID=?)")
|
||||||
.append("OR EXISTS (SELECT * FROM M_Storage s ") // Storage Locator
|
.append("OR EXISTS (SELECT * FROM M_Storage s ") // Storage Locator
|
||||||
.append("WHERE s.M_Locator_ID=M_Locator.M_Locator_ID AND s.M_Product_ID=?))");
|
.append("WHERE s.M_Locator_ID=M_Locator.M_Locator_ID AND s.M_Product_ID=?))");
|
||||||
|
m_parsedValidation = null;
|
||||||
|
if (!Util.isEmpty(m_validationCode))
|
||||||
|
{
|
||||||
|
Properties ctx = new Properties(m_ctx);
|
||||||
|
Env.setContext(ctx, getWindowNo(), "M_Product_ID", getOnly_Product_ID());
|
||||||
|
Env.setContext(ctx, getWindowNo(), "M_Warehouse_ID", getOnly_Warehouse_ID());
|
||||||
|
String parseValidation = Env.parseContext(ctx, getWindowNo(), m_validationCode, false, false);
|
||||||
|
m_parsedValidation = parseValidation;
|
||||||
|
if (!Util.isEmpty(parseValidation))
|
||||||
|
{
|
||||||
|
sql.append(" AND ( ").append(parseValidation).append(" ) ");
|
||||||
|
}
|
||||||
|
}
|
||||||
sql.append(" ORDER BY ");
|
sql.append(" ORDER BY ");
|
||||||
if (local_only_warehouse_id == 0)
|
if (local_only_warehouse_id == 0)
|
||||||
sql.append("wh.Name,");
|
sql.append("wh.Name,");
|
||||||
|
@ -465,6 +525,16 @@ public final class MLocatorLookup extends Lookup implements Serializable
|
||||||
return m_lookup.size();
|
return m_lookup.size();
|
||||||
} // refresh
|
} // refresh
|
||||||
|
|
||||||
|
public int refreshIfNeeded()
|
||||||
|
{
|
||||||
|
if (m_loader != null && m_loader.isAlive())
|
||||||
|
return m_lookup.size();
|
||||||
|
else if (isNeedRefresh())
|
||||||
|
return refresh();
|
||||||
|
else
|
||||||
|
return m_lookup.size();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get underlying fully qualified Table.Column Name
|
* Get underlying fully qualified Table.Column Name
|
||||||
* @return Table.ColumnName
|
* @return Table.ColumnName
|
||||||
|
@ -474,4 +544,9 @@ public final class MLocatorLookup extends Lookup implements Serializable
|
||||||
return "M_Locator.M_Locator_ID";
|
return "M_Locator.M_Locator_ID";
|
||||||
} // getColumnName
|
} // getColumnName
|
||||||
|
|
||||||
|
public void dynamicDisplay(Properties ctx)
|
||||||
|
{
|
||||||
|
m_ctx = ctx;
|
||||||
|
m_parsedValidation = null;
|
||||||
|
}
|
||||||
} // MLocatorLookup
|
} // MLocatorLookup
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.beans.PropertyChangeListener;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.adempiere.webui.ClientInfo;
|
import org.adempiere.webui.ClientInfo;
|
||||||
|
@ -424,6 +425,14 @@ public class WLocatorEditor extends WEditor implements EventListener<Event>, Pro
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (M_Locator_ID > 0)
|
||||||
|
{
|
||||||
|
m_mLocator.refreshIfNeeded();
|
||||||
|
boolean valid = m_mLocator.containsKey(M_Locator_ID);
|
||||||
|
if (!valid)
|
||||||
|
M_Locator_ID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (M_Locator_ID == 0)
|
if (M_Locator_ID == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -447,7 +456,11 @@ public class WLocatorEditor extends WEditor implements EventListener<Event>, Pro
|
||||||
|
|
||||||
private int getOnly_Warehouse_ID()
|
private int getOnly_Warehouse_ID()
|
||||||
{
|
{
|
||||||
String only_Warehouse = Env.getContext(Env.getCtx(), m_WindowNo, "M_Warehouse_ID", true);
|
String only_Warehouse = null;
|
||||||
|
if (gridField != null && gridField.getVO().TabNo > 0)
|
||||||
|
only_Warehouse = Env.getContext(Env.getCtx(), m_WindowNo, gridField.getVO().TabNo, "M_Warehouse_ID", false, true);
|
||||||
|
else
|
||||||
|
only_Warehouse = Env.getContext(Env.getCtx(), m_WindowNo, "M_Warehouse_ID", true);
|
||||||
int only_Warehouse_ID = 0;
|
int only_Warehouse_ID = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -472,7 +485,11 @@ public class WLocatorEditor extends WEditor implements EventListener<Event>, Pro
|
||||||
if (!Env.isSOTrx(Env.getCtx(), m_WindowNo))
|
if (!Env.isSOTrx(Env.getCtx(), m_WindowNo))
|
||||||
return 0; // No product restrictions for PO
|
return 0; // No product restrictions for PO
|
||||||
|
|
||||||
String only_Product = Env.getContext(Env.getCtx(), m_WindowNo, "M_Product_ID", true);
|
String only_Product = null;
|
||||||
|
if (gridField != null && gridField.getVO().TabNo > 0)
|
||||||
|
only_Product = Env.getContext(Env.getCtx(), m_WindowNo, gridField.getVO().TabNo, "M_Product_ID", false, true);
|
||||||
|
else
|
||||||
|
only_Product = Env.getContext(Env.getCtx(), m_WindowNo, "M_Product_ID", true);
|
||||||
int only_Product_ID = 0;
|
int only_Product_ID = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -551,5 +568,9 @@ public class WLocatorEditor extends WEditor implements EventListener<Event>, Pro
|
||||||
getComponent().setTableEditorMode(b);
|
getComponent().setTableEditorMode(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dynamicDisplay(Properties ctx) {
|
||||||
|
super.dynamicDisplay(ctx);
|
||||||
|
m_mLocator.dynamicDisplay(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,7 +375,7 @@ public class WLocatorDialog extends Window implements EventListener<Event>
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("LocatorTypes=" + lstLocatorType.getItemCount());
|
if (log.isLoggable(Level.FINE)) log.fine("LocatorTypes=" + lstLocatorType.getItemCount());
|
||||||
|
|
||||||
// Load existing Locators
|
// Load existing Locators
|
||||||
|
m_mLocator.refreshIfNeeded();
|
||||||
m_mLocator.fillComboBox(m_mandatory, true, true, false, false); // IDEMPIERE 90
|
m_mLocator.fillComboBox(m_mandatory, true, true, false, false); // IDEMPIERE 90
|
||||||
|
|
||||||
if (log.isLoggable(Level.FINE)) log.fine(m_mLocator.toString());
|
if (log.isLoggable(Level.FINE)) log.fine(m_mLocator.toString());
|
||||||
|
@ -393,17 +393,22 @@ public class WLocatorDialog extends Window implements EventListener<Event>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int selectedIndex = -1;
|
||||||
for (int i = 0; i < m_mLocator.getSize(); i++)
|
for (int i = 0; i < m_mLocator.getSize(); i++)
|
||||||
{
|
{
|
||||||
Object obj = m_mLocator.getElementAt(i);
|
MLocator obj = (MLocator) m_mLocator.getElementAt(i);
|
||||||
|
if (obj.getM_Locator_ID() == m_M_Locator_ID && m_M_Locator_ID > 0)
|
||||||
|
selectedIndex = i;
|
||||||
|
|
||||||
lstLocator.appendItem(obj.toString(), obj);
|
lstLocator.appendItem(obj.toString(), obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
//lstLocator.setModel(m_mLocator);
|
if (lstLocator.getItemCount() > 0) {
|
||||||
//lstLocator.setValue(m_M_Locator_ID);
|
if (selectedIndex >= 0)
|
||||||
if (lstLocator.getItemCount() > 0)
|
lstLocator.setSelectedIndex(selectedIndex);
|
||||||
lstLocator.setSelectedIndex(0);
|
else
|
||||||
|
lstLocator.setSelectedIndex(0);
|
||||||
|
}
|
||||||
lstLocator.addEventListener(Events.ON_SELECT, this);
|
lstLocator.addEventListener(Events.ON_SELECT, this);
|
||||||
|
|
||||||
displayLocator();
|
displayLocator();
|
||||||
|
|
Loading…
Reference in New Issue