IDEMPIERE-4472 Window Advanced Search - Allow select column from wind… (#959)

* IDEMPIERE-4472 Window Advanced Search - Allow select column from window tabs - 2pack compatibility

Based on pull request #170 from igorpojzl.
Difference from #170:
- use AD_Tab_UU instead of AD_Tab_ID
- use Combobox for table list

* IDEMPIERE-4472 Window Advanced Search - Allow select column from window tabs - 2pack compatibility

Fix attribute search

* IDEMPIERE-4472 Window Advanced Search - Allow select column from window tabs - 2pack compatibility

Merge patch from Carlos (increse length of AD_UserQuery.Code)
This commit is contained in:
hengsin 2021-11-01 22:05:49 +08:00 committed by GitHub
parent 7380c99a58
commit ed4c1a81d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1302 additions and 171 deletions

View File

@ -0,0 +1,15 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-4364 Advanced Search - Allow select column from window tabs
-- Nov 1, 2021, 11:09:11 AM CET
UPDATE AD_Column SET FieldLength=4000, AD_Reference_ID=10,Updated=TO_DATE('2021-11-01 11:09:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=14361
;
-- Nov 1, 2021, 11:09:14 AM CET
ALTER TABLE AD_UserQuery MODIFY Code VARCHAR2(4000 CHAR) DEFAULT NULL
;
SELECT register_migration_script('202111011110_IDEMPIERE-4364.sql') FROM dual
;

View File

@ -0,0 +1,11 @@
-- IDEMPIERE-4364 Advanced Search - Allow select column from window tabs
-- Nov 1, 2021, 11:09:11 AM CET
UPDATE AD_Column SET FieldLength=4000, AD_Reference_ID=10,Updated=TO_TIMESTAMP('2021-11-01 11:09:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=14361
;
-- Nov 1, 2021, 11:09:14 AM CET
INSERT INTO t_alter_column values('ad_userquery','Code','VARCHAR(4000)',null,'NULL')
;
SELECT register_migration_script('202111011110_IDEMPIERE-4364.sql') FROM dual
;

View File

@ -619,5 +619,39 @@ public class GridWindow implements Serializable
return m_vo.AD_Window_UU; return m_vo.AD_Window_UU;
} }
/**
* Get {@link GridTab} by Tab ID
* @param ad_tab_id
* @return {@link GridTab}
*/
public GridTab getGridTab (int ad_tab_id)
{
for (int i = 0; i < m_tabs.size(); i++)
{
GridTab tab = getTab(i);
if (tab.getAD_Tab_ID()==ad_tab_id)
return tab;
}
return null;
} // getTab
/**
* Get {@link GridTab} by Tab UUID
* @param ad_tab_uu
* @return {@link GridTab}
*/
public GridTab getGridTab (String ad_tab_uu)
{
for (int i = 0; i < m_tabs.size(); i++)
{
GridTab tab = getTab(i);
if (tab.getAD_Tab_UU() != null && tab.getAD_Tab_UU().equals(ad_tab_uu))
return tab;
}
return null;
} // getTab
} // MWindow } // MWindow

View File

@ -655,10 +655,50 @@ public class MQuery implements Serializable, Cloneable
Object Code, String InfoName, String InfoDisplay, boolean andCondition, int depth) Object Code, String InfoName, String InfoDisplay, boolean andCondition, int depth)
{ {
Restriction r = new Restriction (ColumnName, Operator, Restriction r = new Restriction (ColumnName, Operator,
Code, InfoName, InfoDisplay, andCondition, depth); Code, InfoName, InfoDisplay, andCondition, false, depth);
m_list.add(r); m_list.add(r);
} // addRestriction } // addRestriction
/*************************************************************************
* Add Restriction
* @param ColumnName ColumnName
* @param Operator Operator, e.g. = != ..
* @param Code Code, e.g 0, All%
* @param InfoName Display Name
* @param InfoDisplay Display of Code (Lookup)
* @param andCondition true=and, false=or
* @param notCondition true=not, false=empty
* @param depth ( = no open brackets )
*/
public void addRestriction (String ColumnName, String Operator,
Object Code, String InfoName, String InfoDisplay, boolean andCondition, boolean notCondition, int depth)
{
Restriction r = new Restriction (ColumnName, Operator,
Code, InfoName, InfoDisplay, andCondition, notCondition, depth);
m_list.add(r);
} // addRestriction
/**
* Add Range Restriction (BETWEEN)
* @param ColumnName ColumnName
* @param Code Code, e.g 0, All%
* @param Code_to Code, e.g 0, All%
* @param InfoName Display Name
* @param InfoDisplay Display of Code (Lookup)
* @param InfoDisplay_to Display of Code (Lookup)
* @param andCondition true=and, false=or
* @param notCondition true=not, false=empty
* @param depth ( = no open brackets )
*/
public void addRangeRestriction (String ColumnName,
Object Code, Object Code_to,
String InfoName, String InfoDisplay, String InfoDisplay_to, boolean andCondition, boolean notCondition, int depth)
{
Restriction r = new Restriction (ColumnName, Code, Code_to,
InfoName, InfoDisplay, InfoDisplay_to, andCondition, notCondition, depth);
m_list.add(r);
}
/************************************************************************* /*************************************************************************
* Add Restriction * Add Restriction
* @param ColumnName ColumnName * @param ColumnName ColumnName
@ -812,7 +852,33 @@ public class MQuery implements Serializable, Cloneable
{ {
if (whereClause == null || whereClause.trim().length() == 0) if (whereClause == null || whereClause.trim().length() == 0)
return; return;
Restriction r = new Restriction (whereClause, andCondition, joinDepth); Restriction r = new Restriction (whereClause, andCondition, false, false, joinDepth);
m_list.add(r);
m_newRecord = whereClause.equals(NEWRECORD);
} // addRestriction
/**
* Add Restriction
* @param whereClause SQL WHERE clause
*/
public void addRestriction (String whereClause, boolean andCondition, boolean notCondition, int joinDepth)
{
if (whereClause == null || whereClause.trim().length() == 0)
return;
Restriction r = new Restriction (whereClause, andCondition, notCondition, false, joinDepth);
m_list.add(r);
m_newRecord = whereClause.equals(NEWRECORD);
} // addRestriction
/**
* Add Restriction
* @param whereClause SQL WHERE clause
*/
public void addRestriction (String whereClause, boolean andCondition, boolean notCondition, boolean existsCondition, int joinDepth)
{
if (whereClause == null || whereClause.trim().length() == 0)
return;
Restriction r = new Restriction (whereClause, andCondition, notCondition, existsCondition, joinDepth);
m_list.add(r); m_list.add(r);
m_newRecord = whereClause.equals(NEWRECORD); m_newRecord = whereClause.equals(NEWRECORD);
} // addRestriction } // addRestriction
@ -899,6 +965,12 @@ public class MQuery implements Serializable, Cloneable
Restriction r = (Restriction)m_list.get(i); Restriction r = (Restriction)m_list.get(i);
if (i != 0) if (i != 0)
sb.append(" ").append(r.andOrCondition).append(" "); sb.append(" ").append(r.andOrCondition).append(" ");
//NOT
sb.append(r.notCondition ? " NOT " : "");
//EXISTS
sb.append(r.existsCondition ? " EXISTS " : "");
for ( ; currentDepth < r.joinDepth; currentDepth++ ) for ( ; currentDepth < r.joinDepth; currentDepth++ )
{ {
sb.append('('); sb.append('(');
@ -947,6 +1019,11 @@ public class MQuery implements Serializable, Cloneable
} }
if (i != 0) if (i != 0)
sb.append(" ").append(r.andOrCondition).append(" "); sb.append(" ").append(r.andOrCondition).append(" ");
//NOT
sb.append(r.notCondition ? " NOT " : "");
//EXISTS
sb.append(r.existsCondition ? " EXISTS " : "");
// //
sb.append(r.getInfoName()) sb.append(r.getInfoName())
.append(r.getInfoOperator()) .append(r.getInfoOperator())
@ -1067,6 +1144,19 @@ public class MQuery implements Serializable, Cloneable
return r.Code; return r.Code;
} // getCode } // getCode
/**
* Get Operator of index
* @param index index
* @return Operator
*/
public Object getCode_to (int index)
{
if (index < 0 || index >= m_list.size())
return null;
Restriction r = (Restriction)m_list.get(index);
return r.Code_to;
} // getCode
/** /**
* Get Restriction Display of index * Get Restriction Display of index
* @param index index * @param index index
@ -1236,6 +1326,44 @@ public class MQuery implements Serializable, Cloneable
return m_reportProcessQuery; return m_reportProcessQuery;
} }
/**
*
* @param ColumnName
* @param Operator
* @param Code
* @param InfoName
* @param InfoDisplay
* @param andCondition
* @param depth
* @return
*/
public String getRestrictionSQL (String ColumnName, String Operator,
Object Code, String InfoName, String InfoDisplay, boolean andCondition, int depth)
{
Restriction r = new Restriction (ColumnName, Operator,
Code, InfoName, InfoDisplay, andCondition, depth);
return r.getSQL(null);
} // getRestrictionSQL
/**
*
* @param ColumnName
* @param Operator
* @param Code
* @param InfoName
* @param InfoDisplay
* @param andCondition
* @param depth
* @return
*/
public String getRestrictionSQL (String ColumnName,
Object Code, Object Code_To, String InfoName, String InfoDisplay, String InfoDisplay_To, boolean andCondition, int depth)
{
Restriction r = new Restriction(ColumnName, Code, Code_To, InfoName,
InfoDisplay, InfoDisplay_To, andCondition, false, depth);
return r.getSQL(null);
}
@Override @Override
public MQuery clone() { public MQuery clone() {
try { try {
@ -1326,6 +1454,26 @@ class Restriction implements Serializable
InfoDisplay = code.toString(); InfoDisplay = code.toString();
} // Restriction } // Restriction
/**
* Restriction
* @param columnName
* @param operator
* @param code
* @param infoName
* @param infoDisplay
* @param andCondition
* @param notCondition
* @param depth
*/
Restriction (String columnName, String operator,
Object code, String infoName, String infoDisplay, boolean andCondition,boolean notCondition, int depth)
{
this (columnName, operator, code, infoName, infoDisplay, andCondition, depth);
this.notCondition = notCondition;
} // Restriction
/** /**
* Range Restriction (BETWEEN) * Range Restriction (BETWEEN)
* @param columnName ColumnName * @param columnName ColumnName
@ -1378,6 +1526,37 @@ class Restriction implements Serializable
InfoDisplay_to = Code_to.toString(); InfoDisplay_to = Code_to.toString();
} // Restriction } // Restriction
/**
* Range Restriction (BETWEEN)
* @param columnName ColumnName
* @param code Code, e.g 0, All%
* @param code_to Code, e.g 0, All%
* @param infoName Display Name
* @param infoDisplay Display of Code (Lookup)
* @param infoDisplay_to Display of Code (Lookup)
*/
Restriction (String columnName,
Object code, Object code_to,
String infoName, String infoDisplay, String infoDisplay_to, boolean andCondition, boolean notCondition, int depth)
{
this (columnName, MQuery.BETWEEN, code, infoName, infoDisplay, andCondition, notCondition, depth);
// Code_to
Code_to = code_to;
if (Code_to instanceof String)
{
if (Code_to.toString().startsWith("'"))
Code_to = Code_to.toString().substring(1);
if (Code_to.toString().endsWith("'"))
Code_to = Code_to.toString().substring(0, Code_to.toString().length()-2);
}
// InfoDisplay_to
if (infoDisplay_to != null)
InfoDisplay_to = infoDisplay_to.trim();
else if (Code_to != null)
InfoDisplay_to = Code_to.toString();
} // Restriction
/** /**
* Create Restriction with direct WHERE clause * Create Restriction with direct WHERE clause
* @param whereClause SQL WHERE Clause * @param whereClause SQL WHERE Clause
@ -1399,11 +1578,40 @@ class Restriction implements Serializable
{ {
DirectWhereClause = whereClause; DirectWhereClause = whereClause;
this.andOrCondition = andOrCondition; this.andOrCondition = andOrCondition;
this.notCondition = false;
this.existsCondition = false;
this.joinDepth = depth; this.joinDepth = depth;
} // Restriction } // Restriction
/**
* Create Restriction with direct WHERE clause
* @param whereClause SQL WHERE Clause
*/
Restriction (String whereClause, boolean andCondition, boolean notCondition, boolean existsCondition, int depth)
{
DirectWhereClause = whereClause;
this.andOrCondition = andCondition ? "AND" : "OR";
this.notCondition = notCondition;
this.existsCondition = existsCondition;
this.joinDepth = depth;
} // Restriction
/**
*
* @param ColumnName
* @param ExistsClause
* @param Code
*/
Restriction (String ExistsClause, Object Code)
{
this.ExistsClause = ExistsClause;
this.Code = Code;
} // Restriction
/** Direct Where Clause */ /** Direct Where Clause */
protected String DirectWhereClause = null; protected String DirectWhereClause = null;
/** Exists Clause */
protected String ExistsClause = null;
/** Column Name */ /** Column Name */
protected String ColumnName; protected String ColumnName;
/** Name */ /** Name */
@ -1422,6 +1630,10 @@ class Restriction implements Serializable
protected String andOrCondition = "AND"; protected String andOrCondition = "AND";
/** And/Or condition nesting depth ( = number of open brackets at and/or) */ /** And/Or condition nesting depth ( = number of open brackets at and/or) */
protected int joinDepth = 0; protected int joinDepth = 0;
/** Not Condition */
protected boolean notCondition = false;
/** Exists Condition */
protected boolean existsCondition = false;
/** /**
* Return SQL construct for this restriction * Return SQL construct for this restriction
@ -1432,6 +1644,22 @@ class Restriction implements Serializable
{ {
if (DirectWhereClause != null) if (DirectWhereClause != null)
return DirectWhereClause; return DirectWhereClause;
if(ExistsClause != null){
StringBuilder sb = new StringBuilder();
sb.append(ExistsClause);
if (Code instanceof String)
sb = new StringBuilder(sb.toString().replaceAll("\\?", DB.TO_STRING(Code.toString())));
else if (Code instanceof Timestamp)
sb = new StringBuilder(sb.toString().replaceAll("\\?", DB.TO_DATE((Timestamp)Code, false)));
else
sb = new StringBuilder(sb.toString().replaceAll("\\?", Code.toString()));
return sb.toString();
}
// verify if is a virtual column, do not prefix tableName if this is a virtualColumn // verify if is a virtual column, do not prefix tableName if this is a virtualColumn
boolean virtualColumn = false; boolean virtualColumn = false;
if (tableName != null && tableName.length() > 0) { if (tableName != null && tableName.length() > 0) {

View File

@ -764,7 +764,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
GridField[] findFields = mTab.getFields(); GridField[] findFields = mTab.getFields();
FindWindow findWindow = new FindWindow(curWindowNo, mTab.getTabNo(), FindWindow findWindow = new FindWindow(curWindowNo, mTab.getTabNo(),
mTab.getName(), mTab.getAD_Table_ID(), mTab.getTableName(), mTab.getName(), mTab.getAD_Table_ID(), mTab.getTableName(),
where.toString(), findFields, 10, mTab.getAD_Tab_ID()); // no query below 10 where.toString(), findFields, 10, mTab.getAD_Tab_ID(), this); // no query below 10
tabFindWindowHashMap.put(mTab, findWindow); tabFindWindowHashMap.put(mTab, findWindow);
setupEmbeddedFindwindow(findWindow); setupEmbeddedFindwindow(findWindow);
if (findWindow.initialize()) if (findWindow.initialize())
@ -3748,7 +3748,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
} else { } else {
findWindow = new FindWindow (adTabbox.getSelectedGridTab().getWindowNo(), adTabbox.getSelectedGridTab().getTabNo(), adTabbox.getSelectedGridTab().getName(), findWindow = new FindWindow (adTabbox.getSelectedGridTab().getWindowNo(), adTabbox.getSelectedGridTab().getTabNo(), adTabbox.getSelectedGridTab().getName(),
adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getTableName(), adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getTableName(),
adTabbox.getSelectedGridTab().getWhereExtended(), findFields, 1, adTabbox.getSelectedGridTab().getAD_Tab_ID()); adTabbox.getSelectedGridTab().getWhereExtended(), findFields, 1, adTabbox.getSelectedGridTab().getAD_Tab_ID(), this);
setupEmbeddedFindwindow(findWindow); setupEmbeddedFindwindow(findWindow);
if (!findWindow.initialize()) { if (!findWindow.initialize()) {
@ -3885,4 +3885,12 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
return true; return true;
} // registerQuickFormTab } // registerQuickFormTab
/**
*
* @return {@link GridWindow}
*/
public GridWindow getGridWindow() {
return gridWindow;
}
} }