IDEMPIERE-3883:preserve sorting of info window
This commit is contained in:
parent
5c809d2e87
commit
6f7949c2bb
|
@ -1633,8 +1633,8 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
|
||||||
dataSql = dataSql + " " + otherClause;
|
dataSql = dataSql + " " + otherClause;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_sqlUserOrder != null && m_sqlUserOrder.trim().length() > 0)
|
if (indexOrderColumn > -1)
|
||||||
dataSql = dataSql + m_sqlUserOrder;
|
dataSql = dataSql + getUserOrderClause();
|
||||||
else
|
else
|
||||||
dataSql = dataSql + m_sqlOrder;
|
dataSql = dataSql + m_sqlOrder;
|
||||||
|
|
||||||
|
|
|
@ -371,7 +371,10 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
||||||
protected String m_sqlCount;
|
protected String m_sqlCount;
|
||||||
/** Order By Clause */
|
/** Order By Clause */
|
||||||
protected String m_sqlOrder;
|
protected String m_sqlOrder;
|
||||||
protected String m_sqlUserOrder;
|
private String m_sqlUserOrder;
|
||||||
|
/* sql column of infocolumn (can be alias) */
|
||||||
|
protected int indexOrderColumn = -1;
|
||||||
|
protected Boolean isColumnSortAscending = null;
|
||||||
/**ValueChange listeners */
|
/**ValueChange listeners */
|
||||||
private ArrayList<ValueChangeListener> listeners = new ArrayList<ValueChangeListener>();
|
private ArrayList<ValueChangeListener> listeners = new ArrayList<ValueChangeListener>();
|
||||||
/** Loading success indicator */
|
/** Loading success indicator */
|
||||||
|
@ -1038,8 +1041,8 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
||||||
int index = sql.lastIndexOf(" WHERE");
|
int index = sql.lastIndexOf(" WHERE");
|
||||||
sql.delete(index, sql.length());
|
sql.delete(index, sql.length());
|
||||||
}
|
}
|
||||||
if (m_sqlUserOrder != null && m_sqlUserOrder.trim().length() > 0)
|
if (indexOrderColumn > -1)
|
||||||
sql.append(m_sqlUserOrder);
|
sql.append(getUserOrderClause());
|
||||||
else
|
else
|
||||||
sql.append(m_sqlOrder);
|
sql.append(m_sqlOrder);
|
||||||
dataSql = Msg.parseTranslation(Env.getCtx(), sql.toString()); // Variables
|
dataSql = Msg.parseTranslation(Env.getCtx(), sql.toString()); // Variables
|
||||||
|
@ -1052,6 +1055,60 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
||||||
return dataSql;
|
return dataSql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* build order clause of current sort order, and save it to m_sqlUserOrder
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getUserOrderClause() {
|
||||||
|
if (indexOrderColumn < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (m_sqlUserOrder == null) {
|
||||||
|
m_sqlUserOrder = getUserOrderClause (indexOrderColumn);
|
||||||
|
}
|
||||||
|
return m_sqlUserOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* build order clause of give column
|
||||||
|
* if call that function before init list will raise a NPE. care about your code
|
||||||
|
* @param col
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getUserOrderClause(int col) {
|
||||||
|
String colsql = p_layout[col].getColSQL().trim();
|
||||||
|
int lastSpaceIdx = colsql.lastIndexOf(" ");
|
||||||
|
if (lastSpaceIdx > 0)
|
||||||
|
{
|
||||||
|
String tmp = colsql.substring(0, lastSpaceIdx).trim();
|
||||||
|
char last = tmp.charAt(tmp.length() - 1);
|
||||||
|
|
||||||
|
String alias = colsql.substring(lastSpaceIdx).trim();
|
||||||
|
boolean hasAlias = alias.matches("^[a-zA-Z_][a-zA-Z0-9_]*$"); // valid SQL alias - starts with letter then digits, letters, underscore
|
||||||
|
|
||||||
|
if (tmp.toLowerCase().endsWith("as") && hasAlias)
|
||||||
|
{
|
||||||
|
colsql = alias;
|
||||||
|
}
|
||||||
|
else if (!(last == '*' || last == '-' || last == '+' || last == '/' || last == '>' || last == '<' || last == '='))
|
||||||
|
{
|
||||||
|
if (alias.startsWith("\"") && alias.endsWith("\""))
|
||||||
|
{
|
||||||
|
colsql = alias;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (hasAlias)
|
||||||
|
{
|
||||||
|
colsql = alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format(" ORDER BY %s %s ", colsql, isColumnSortAscending? "" : "DESC");
|
||||||
|
}
|
||||||
|
|
||||||
private void addDoubleClickListener() {
|
private void addDoubleClickListener() {
|
||||||
Iterator<EventListener<? extends Event>> i = contentPanel.getEventListeners(Events.ON_DOUBLE_CLICK).iterator();
|
Iterator<EventListener<? extends Event>> i = contentPanel.getEventListeners(Events.ON_DOUBLE_CLICK).iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
@ -2206,10 +2263,15 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
||||||
for(Object obj : headers)
|
for(Object obj : headers)
|
||||||
{
|
{
|
||||||
Listheader header = (Listheader) obj;
|
Listheader header = (Listheader) obj;
|
||||||
header.setSortDirection("natural");
|
// idempiere use mix method. sometime call model method, sometime call component method
|
||||||
|
// so index can be difference on complicate case, just wait to fix
|
||||||
|
if (header.getColumnIndex() == indexOrderColumn)
|
||||||
|
header.setSortDirection(isColumnSortAscending?"ascending":"descending");
|
||||||
|
else
|
||||||
|
header.setSortDirection("natural");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_sqlUserOrder="";
|
// m_sqlUserOrder="";
|
||||||
// event == null mean direct call from reset button
|
// event == null mean direct call from reset button
|
||||||
if (event == null)
|
if (event == null)
|
||||||
m_count = 0;
|
m_count = 0;
|
||||||
|
@ -2344,49 +2406,22 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
||||||
public void sort(Comparator<Object> cmpr, boolean ascending) {
|
public void sort(Comparator<Object> cmpr, boolean ascending) {
|
||||||
updateListSelected();
|
updateListSelected();
|
||||||
WListItemRenderer.ColumnComparator lsc = (WListItemRenderer.ColumnComparator) cmpr;
|
WListItemRenderer.ColumnComparator lsc = (WListItemRenderer.ColumnComparator) cmpr;
|
||||||
|
|
||||||
|
// keep column order
|
||||||
|
int col = lsc.getColumnIndex();
|
||||||
|
indexOrderColumn = col;
|
||||||
|
isColumnSortAscending = ascending;
|
||||||
|
m_sqlUserOrder = null; // clear cache value
|
||||||
|
|
||||||
if (m_useDatabasePaging)
|
if (m_useDatabasePaging)
|
||||||
{
|
{
|
||||||
int col = lsc.getColumnIndex();
|
|
||||||
String colsql = p_layout[col].getColSQL().trim();
|
|
||||||
int lastSpaceIdx = colsql.lastIndexOf(" ");
|
|
||||||
if (lastSpaceIdx > 0)
|
|
||||||
{
|
|
||||||
String tmp = colsql.substring(0, lastSpaceIdx).trim();
|
|
||||||
char last = tmp.charAt(tmp.length() - 1);
|
|
||||||
|
|
||||||
String alias = colsql.substring(lastSpaceIdx).trim();
|
|
||||||
boolean hasAlias = alias.matches("^[a-zA-Z_][a-zA-Z0-9_]*$"); // valid SQL alias - starts with letter then digits, letters, underscore
|
|
||||||
|
|
||||||
if (tmp.toLowerCase().endsWith("as") && hasAlias)
|
|
||||||
{
|
|
||||||
colsql = alias;
|
|
||||||
}
|
|
||||||
else if (!(last == '*' || last == '-' || last == '+' || last == '/' || last == '>' || last == '<' || last == '='))
|
|
||||||
{
|
|
||||||
if (alias.startsWith("\"") && alias.endsWith("\""))
|
|
||||||
{
|
|
||||||
colsql = alias;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (hasAlias)
|
|
||||||
{
|
|
||||||
colsql = alias;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_sqlUserOrder = " ORDER BY " + colsql;
|
|
||||||
if (!ascending)
|
|
||||||
m_sqlUserOrder += " DESC ";
|
|
||||||
executeQuery();
|
executeQuery();
|
||||||
renderItems();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Collections.sort(line, lsc);
|
Collections.sort(line, lsc);
|
||||||
renderItems();
|
|
||||||
}
|
}
|
||||||
|
renderItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLookup()
|
public boolean isLookup()
|
||||||
|
|
Loading…
Reference in New Issue