IDEMPIERE-3049 String autocomplete NPE / refactor to apply best practices / drop the AD_Org_ID filter (doesn't make sense for non-org tables) / add ReQuery to context menu
This commit is contained in:
parent
205edcdb73
commit
e287b987c2
|
|
@ -2361,54 +2361,42 @@ public class GridField
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list containing all existing entries of this field
|
* Returns a list containing all existing entries of this field
|
||||||
* with the actual AD_Org_ID and AD_Client_ID.
|
* with the actual AD_Client_ID.
|
||||||
* @return List of existing entries for this field
|
* @return List of existing entries for this field
|
||||||
*/
|
*/
|
||||||
public List<String> getEntries() {
|
public List<String> getEntries() {
|
||||||
|
/* TODO: consider caching the list to avoid repeating queries on every window open (twice, for find and for field) */
|
||||||
|
MColumn column = MColumn.get(Env.getCtx(), getAD_Column_ID());
|
||||||
|
MTable table = MTable.get(Env.getCtx(), column.getAD_Table_ID());
|
||||||
|
String tableName = table.getTableName();
|
||||||
|
String columnName = column.getColumnName();
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
PreparedStatement pstmt1;
|
|
||||||
PreparedStatement pstmt2;
|
|
||||||
String sql = "";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String tableName = null;
|
|
||||||
String columnName = null;
|
|
||||||
int AD_Org_ID = Env.getAD_Org_ID(Env.getCtx());
|
|
||||||
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
|
|
||||||
sql = "SELECT t.TableName, c.ColumnName " +
|
|
||||||
" FROM AD_COLUMN c INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID)" +
|
|
||||||
" WHERE AD_Column_ID=?";
|
|
||||||
pstmt1 = DB.prepareStatement(sql, null);
|
|
||||||
pstmt1.setInt(1, getAD_Column_ID());
|
|
||||||
ResultSet rs1 = pstmt1.executeQuery();
|
|
||||||
if (rs1.next())
|
|
||||||
{
|
|
||||||
tableName = rs1.getString(1);
|
|
||||||
columnName = rs1.getString(2);
|
|
||||||
}
|
|
||||||
DB.close(rs1, pstmt1);
|
|
||||||
|
|
||||||
if (tableName != null && columnName != null) {
|
if (tableName != null && columnName != null) {
|
||||||
sql = "SELECT DISTINCT " + columnName + " FROM " + tableName + " WHERE AD_Client_ID=? "
|
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
|
||||||
+ " AND AD_Org_ID=?";
|
PreparedStatement pstmt = null;
|
||||||
pstmt2 = DB.prepareStatement(sql, null);
|
ResultSet rs = null;
|
||||||
pstmt2.setInt(1, AD_Client_ID);
|
StringBuilder sql = new StringBuilder()
|
||||||
pstmt2.setInt(2, AD_Org_ID);
|
.append("SELECT DISTINCT ")
|
||||||
|
.append(columnName)
|
||||||
|
.append(" FROM ")
|
||||||
|
.append(tableName)
|
||||||
|
.append(" WHERE AD_Client_ID=? AND ")
|
||||||
|
.append(columnName)
|
||||||
|
.append(" IS NOT NULL ORDER BY 1");
|
||||||
|
try {
|
||||||
|
pstmt = DB.prepareStatement(sql.toString(), null);
|
||||||
|
pstmt.setInt(1, AD_Client_ID);
|
||||||
|
|
||||||
ResultSet rs2 = pstmt2.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
while (rs2.next())
|
while (rs.next()) {
|
||||||
{
|
list.add(rs.getString(1));
|
||||||
list.add(rs2.getString(1));
|
|
||||||
}
|
}
|
||||||
DB.close(rs2, pstmt2);
|
} catch (Exception e) {
|
||||||
|
log.log(Level.SEVERE, sql.toString(), e);
|
||||||
|
} finally {
|
||||||
|
DB.close(rs, pstmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,7 @@ public class WStringEditor extends WEditor implements ContextMenuListener
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
getComponent().setMultiline(false);
|
getComponent().setMultiline(false);
|
||||||
|
if (! gridField.isAutocomplete()) // avoid -> Combobox doesn't support multiple rows
|
||||||
getComponent().setRows(gridField.getNumLines() <= 0 || tableEditor ? 1 : gridField.getNumLines());
|
getComponent().setRows(gridField.getNumLines() <= 0 || tableEditor ? 1 : gridField.getNumLines());
|
||||||
if (getComponent().getRows() > 1)
|
if (getComponent().getRows() > 1)
|
||||||
ZKUpdateUtil.setHeight(getComponent(), "100%");
|
ZKUpdateUtil.setHeight(getComponent(), "100%");
|
||||||
|
|
@ -154,7 +155,7 @@ public class WStringEditor extends WEditor implements ContextMenuListener
|
||||||
|
|
||||||
|
|
||||||
if(!(this instanceof WPasswordEditor)){ // check password field
|
if(!(this instanceof WPasswordEditor)){ // check password field
|
||||||
popupMenu = new WEditorPopupMenu(false, false, isShowPreference());
|
popupMenu = new WEditorPopupMenu(false, gridField.isAutocomplete(), isShowPreference());
|
||||||
addTextEditorMenu(popupMenu);
|
addTextEditorMenu(popupMenu);
|
||||||
addChangeLogMenu(popupMenu);
|
addChangeLogMenu(popupMenu);
|
||||||
}
|
}
|
||||||
|
|
@ -289,24 +290,29 @@ public class WStringEditor extends WEditor implements ContextMenuListener
|
||||||
{
|
{
|
||||||
WFieldRecordInfo.start(gridField);
|
WFieldRecordInfo.start(gridField);
|
||||||
}
|
}
|
||||||
|
else if (WEditorPopupMenu.REQUERY_EVENT.equals(evt.getContextEvent()))
|
||||||
|
{
|
||||||
|
actionRefresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dynamicDisplay() {
|
public void dynamicDisplay() {
|
||||||
super.dynamicDisplay();
|
super.dynamicDisplay();
|
||||||
//referesh auto complete list
|
actionRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionRefresh() {
|
||||||
|
//refresh auto complete list
|
||||||
if (gridField.isAutocomplete()) {
|
if (gridField.isAutocomplete()) {
|
||||||
Combobox combo = (Combobox)getComponent();
|
Combobox combo = (Combobox)getComponent();
|
||||||
List<String> items = gridField.getEntries();
|
List<String> items = gridField.getEntries();
|
||||||
if (items.size() != combo.getItemCount())
|
|
||||||
{
|
|
||||||
combo.removeAllItems();
|
combo.removeAllItems();
|
||||||
for(String s : items) {
|
for(String s : items) {
|
||||||
combo.appendItem(s);
|
combo.appendItem(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private AbstractADWindowContent findADWindowContent() {
|
private AbstractADWindowContent findADWindowContent() {
|
||||||
Component parent = getComponent().getParent();
|
Component parent = getComponent().getParent();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue