IDEMPIERE-1970 Improve t_selection logic for info window / change viewID to point to an info column instead of a column

This commit is contained in:
Carlos Ruiz 2014-09-05 19:23:26 -05:00
parent ddd8c6f6ec
commit f021e8f5f1
7 changed files with 138 additions and 84 deletions

View File

@ -0,0 +1,37 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
update ad_infoprocess set ad_column_id=null where ad_column_id is not null;
ALTER TABLE AD_INFOPROCESS RENAME COLUMN AD_COLUMN_ID TO AD_INFOCOLUMN_ID;
ALTER TABLE AD_INFOPROCESS DROP CONSTRAINT ADCOLUMN_ADINFOPROCESS;
-- Sep 5, 2014 5:40:41 PM COT
-- IDEMPIERE-1970 Improve t_selection logic for info window
INSERT INTO AD_Val_Rule (Code,AD_Val_Rule_ID,EntityType,Name,Type,AD_Val_Rule_UU,CreatedBy,UpdatedBy,Updated,AD_Org_ID,IsActive,AD_Client_ID,Created) VALUES ('AD_InfoColumn.AD_InfoWindow_ID=@AD_InfoWindow_ID@',200065,'D','AD_InfoColumn from Info Window','S','010f3e1f-dd6c-48c7-8fe1-945e0a2482a2',100,100,TO_DATE('2014-09-05 17:40:37','YYYY-MM-DD HH24:MI:SS'),0,'Y',0,TO_DATE('2014-09-05 17:40:37','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 5, 2014 5:40:55 PM COT
UPDATE AD_Column SET FieldLength=10, IsUpdateable='N', ColumnName='AD_InfoColumn_ID', Description='Info Window Column', Help='Column in the Info Window for display and/or selection. If used for selection, the column cannot be a SQL expression. The SQL clause must be fully qualified based on the FROM clause in the Info Window definition', Name='Info Column', FKConstraintName=NULL, AD_Element_ID=3069, AD_Val_Rule_ID=200065,Updated=TO_DATE('2014-09-05 17:40:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377
;
-- Sep 5, 2014 5:41:00 PM COT
UPDATE AD_Column SET FKConstraintName='ADInfoColumn_ADInfoProcess', FKConstraintType='N',Updated=TO_DATE('2014-09-05 17:41:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377
;
-- Sep 5, 2014 5:41:00 PM COT
ALTER TABLE AD_InfoProcess MODIFY AD_InfoColumn_ID NUMBER(10) DEFAULT NULL
;
-- Sep 5, 2014 5:41:00 PM COT
ALTER TABLE AD_InfoProcess ADD CONSTRAINT ADInfoColumn_ADInfoProcess FOREIGN KEY (AD_InfoColumn_ID) REFERENCES ad_infocolumn(ad_infocolumn_id) DEFERRABLE INITIALLY DEFERRED
;
-- Sep 5, 2014 5:44:01 PM COT
UPDATE AD_Column SET IsUpdateable='Y',Updated=TO_DATE('2014-09-05 17:44:01','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377
;
SELECT register_migration_script('201409051741_IDEMPIERE-1970.sql') FROM dual
;

View File

@ -0,0 +1,34 @@
update ad_infoprocess set ad_column_id=null where ad_column_id is not null;
ALTER TABLE ad_infoprocess RENAME ad_column_id TO ad_infocolumn_id;
ALTER TABLE ad_infoprocess DROP CONSTRAINT adcolumn_adinfoprocess CASCADE;
-- Sep 5, 2014 5:40:41 PM COT
-- IDEMPIERE-1970 Improve t_selection logic for info window
INSERT INTO AD_Val_Rule (Code,AD_Val_Rule_ID,EntityType,Name,Type,AD_Val_Rule_UU,CreatedBy,UpdatedBy,Updated,AD_Org_ID,IsActive,AD_Client_ID,Created) VALUES ('AD_InfoColumn.AD_InfoWindow_ID=@AD_InfoWindow_ID@',200065,'D','AD_InfoColumn from Info Window','S','010f3e1f-dd6c-48c7-8fe1-945e0a2482a2',100,100,TO_TIMESTAMP('2014-09-05 17:40:37','YYYY-MM-DD HH24:MI:SS'),0,'Y',0,TO_TIMESTAMP('2014-09-05 17:40:37','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 5, 2014 5:40:55 PM COT
UPDATE AD_Column SET FieldLength=10, IsUpdateable='N', ColumnName='AD_InfoColumn_ID', Description='Info Window Column', Help='Column in the Info Window for display and/or selection. If used for selection, the column cannot be a SQL expression. The SQL clause must be fully qualified based on the FROM clause in the Info Window definition', Name='Info Column', FKConstraintName=NULL, AD_Element_ID=3069, AD_Val_Rule_ID=200065,Updated=TO_TIMESTAMP('2014-09-05 17:40:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377
;
-- Sep 5, 2014 5:41:00 PM COT
UPDATE AD_Column SET FKConstraintName='ADInfoColumn_ADInfoProcess', FKConstraintType='N',Updated=TO_TIMESTAMP('2014-09-05 17:41:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377
;
-- Sep 5, 2014 5:41:00 PM COT
INSERT INTO t_alter_column values('ad_infoprocess','AD_InfoColumn_ID','NUMERIC(10)',null,'NULL')
;
-- Sep 5, 2014 5:41:00 PM COT
ALTER TABLE AD_InfoProcess ADD CONSTRAINT ADInfoColumn_ADInfoProcess FOREIGN KEY (AD_InfoColumn_ID) REFERENCES ad_infocolumn(ad_infocolumn_id) DEFERRABLE INITIALLY DEFERRED
;
-- Sep 5, 2014 5:44:01 PM COT
UPDATE AD_Column SET IsUpdateable='Y',Updated=TO_TIMESTAMP('2014-09-05 17:44:01','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377
;
SELECT register_migration_script('201409051741_IDEMPIERE-1970.sql') FROM dual
;

View File

@ -16,7 +16,7 @@ package org.adempiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.model.MColumn;
import org.compiere.model.MProcess;
import org.compiere.model.X_AD_InfoProcess;
import org.compiere.util.Env;
@ -33,7 +33,7 @@ public class MInfoProcess extends X_AD_InfoProcess {
/**
*
*/
private static final long serialVersionUID = -2167041563372362436L;
private static final long serialVersionUID = 2478699719088685214L;
/**
* {@inheritDoc}
@ -89,25 +89,4 @@ public class MInfoProcess extends X_AD_InfoProcess {
return retValue;
}
/**
* name of column define is ViewID
* @return
*/
public String getViewIDName (){
// no column define
if (getAD_Column_ID() == 0)
return null;
// return cache value
if (m_viewIDName != null)
return m_viewIDName;
MColumn viewIDColumn = (MColumn)getAD_Column();
if (viewIDColumn != null){
return viewIDColumn.getColumnName();
}
return null;
}
}

View File

@ -49,20 +49,20 @@ public interface I_AD_InfoProcess
*/
public int getAD_Client_ID();
/** Column name AD_Column_ID */
public static final String COLUMNNAME_AD_Column_ID = "AD_Column_ID";
/** Column name AD_InfoColumn_ID */
public static final String COLUMNNAME_AD_InfoColumn_ID = "AD_InfoColumn_ID";
/** Set ViewID Column.
* Name of unique column in a view. value of this column will save to t_selection table
/** Set Info Column.
* Info Window Column
*/
public void setAD_Column_ID (int AD_Column_ID);
public void setAD_InfoColumn_ID (int AD_InfoColumn_ID);
/** Get ViewID Column.
* Name of unique column in a view. value of this column will save to t_selection table
/** Get Info Column.
* Info Window Column
*/
public int getAD_Column_ID();
public int getAD_InfoColumn_ID();
public org.compiere.model.I_AD_Column getAD_Column() throws RuntimeException;
public org.compiere.model.I_AD_InfoColumn getAD_InfoColumn() throws RuntimeException;
/** Column name AD_InfoProcess_ID */
public static final String COLUMNNAME_AD_InfoProcess_ID = "AD_InfoProcess_ID";

View File

@ -30,7 +30,7 @@ public class X_AD_InfoProcess extends PO implements I_AD_InfoProcess, I_Persiste
/**
*
*/
private static final long serialVersionUID = 20140606L;
private static final long serialVersionUID = 20140905L;
/** Standard Constructor */
public X_AD_InfoProcess (Properties ctx, int AD_InfoProcess_ID, String trxName)
@ -76,29 +76,29 @@ public class X_AD_InfoProcess extends PO implements I_AD_InfoProcess, I_Persiste
return sb.toString();
}
public org.compiere.model.I_AD_Column getAD_Column() throws RuntimeException
public org.compiere.model.I_AD_InfoColumn getAD_InfoColumn() throws RuntimeException
{
return (org.compiere.model.I_AD_Column)MTable.get(getCtx(), org.compiere.model.I_AD_Column.Table_Name)
.getPO(getAD_Column_ID(), get_TrxName()); }
return (org.compiere.model.I_AD_InfoColumn)MTable.get(getCtx(), org.compiere.model.I_AD_InfoColumn.Table_Name)
.getPO(getAD_InfoColumn_ID(), get_TrxName()); }
/** Set ViewID Column.
@param AD_Column_ID
Name of unique column in a view. value of this column will save to t_selection table
/** Set Info Column.
@param AD_InfoColumn_ID
Info Window Column
*/
public void setAD_Column_ID (int AD_Column_ID)
public void setAD_InfoColumn_ID (int AD_InfoColumn_ID)
{
if (AD_Column_ID < 1)
set_Value (COLUMNNAME_AD_Column_ID, null);
if (AD_InfoColumn_ID < 1)
set_Value (COLUMNNAME_AD_InfoColumn_ID, null);
else
set_Value (COLUMNNAME_AD_Column_ID, Integer.valueOf(AD_Column_ID));
set_Value (COLUMNNAME_AD_InfoColumn_ID, Integer.valueOf(AD_InfoColumn_ID));
}
/** Get ViewID Column.
@return Name of unique column in a view. value of this column will save to t_selection table
/** Get Info Column.
@return Info Window Column
*/
public int getAD_Column_ID ()
public int getAD_InfoColumn_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_AD_Column_ID);
Integer ii = (Integer)get_Value(COLUMNNAME_AD_InfoColumn_ID);
if (ii == null)
return 0;
return ii.intValue();

View File

@ -612,12 +612,15 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
if (infoColumn.isDisplayed(infoContext, p_WindowNo))
{
ColumnInfo columnInfo = null;
String colSQL = infoColumn.getSelectClause();
if (! colSQL.toUpperCase().contains(" AS "))
colSQL += " AS " + infoColumn.getColumnName();
if (infoColumn.getAD_Reference_ID() == DisplayType.ID)
{
if (infoColumn.getSelectClause().equalsIgnoreCase(keySelectClause))
continue;
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), DisplayType.getClass(infoColumn.getAD_Reference_ID(), true));
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, DisplayType.getClass(infoColumn.getAD_Reference_ID(), true));
}
else if (DisplayType.isLookup(infoColumn.getAD_Reference_ID()))
{
@ -627,8 +630,8 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
editor = WebEditorFactory.getEditor(gridFields.get(i), true);
editor.setMandatory(false);
editor.setReadWrite(false);
editorMap.put(infoColumn.getSelectClause(), editor);
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), ValueNamePair.class, (String)null);
editorMap.put(colSQL, editor);
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, ValueNamePair.class, (String)null);
}
else
{
@ -637,7 +640,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
}
else
{
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), DisplayType.getClass(infoColumn.getAD_Reference_ID(), true));
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, DisplayType.getClass(infoColumn.getAD_Reference_ID(), true));
}
columnInfo.setColDescription(infoColumn.get_Translation("Description"));
columnInfo.setGridField(gridFields.get(i));
@ -681,9 +684,12 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
editor = WebEditorFactory.getEditor(gridField, true);
editor.setMandatory(false);
editor.setReadWrite(false);
editorMap.put(infoColumn.getSelectClause(), editor);
ColumnInfo columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), KeyNamePair.class, (String)null);
String colSQL = infoColumn.getSelectClause();
if (! colSQL.toUpperCase().contains(" AS "))
colSQL += " AS " + infoColumn.getColumnName();
editorMap.put(colSQL, editor);
ColumnInfo columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, KeyNamePair.class, (String)null);
return columnInfo;
}
@ -916,7 +922,6 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
String fromClause = m_sqlMain.substring(fromIndex);
// get alias of main table
String alias = getTableName();
StringBuilder sqlBuilder = new StringBuilder(selectClause);
// reset flag relate viewID to recount
@ -925,29 +930,25 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
// add View_ID column to select clause
for (MInfoProcess infoProcess : infoProcessList) {
String columnInQuery = infoProcess.getViewIDName();
// this process hasn't viewID column, next other infoProcess
if (columnInQuery == null)
if (infoProcess.getAD_InfoColumn_ID() <= 0)
continue;
// add alias of main table to column
columnInQuery = alias + "." + columnInQuery;
MInfoColumn infocol = (MInfoColumn) infoProcess.getAD_InfoColumn();
// maintain varial relate to ViewID, it can init just one time when load infoWindow define
// but let it here for simple logic control
numOfViewID++;
isHasViewID = true;
// if query is include this viewID column, not need add
if (sqlBuilder.toString().toLowerCase().contains(columnInQuery.toLowerCase())){
continue;
}
if (! infocol.isDisplayed()) {
// add column to SELECT clause of main sql
sqlBuilder.append(", ");
sqlBuilder.append (columnInQuery);
sqlBuilder.append (infocol.getSelectClause());
sqlBuilder.append(" AS ");
sqlBuilder.append (infocol.getColumnName());
sqlBuilder.append(" ");
}
}
sqlBuilder.append(fromClause);
// update main sql
@ -1594,12 +1595,15 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
if (infoColumn.isDisplayed(infoContext, p_WindowNo))
{
ColumnInfo columnInfo = null;
String colSQL = infoColumn.getSelectClause();
if (! colSQL.toUpperCase().contains(" AS "))
colSQL += " AS " + infoColumn.getColumnName();
if (infoColumn.getAD_Reference_ID() == DisplayType.ID)
{
if (infoColumn.getSelectClause().equalsIgnoreCase(keySelectClause))
continue;
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), DisplayType.getClass(infoColumn.getAD_Reference_ID(), true));
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, DisplayType.getClass(infoColumn.getAD_Reference_ID(), true));
}
else if (DisplayType.isLookup(infoColumn.getAD_Reference_ID()))
{
@ -1609,8 +1613,8 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
editor = WebEditorFactory.getEditor(getGridField(infoColumn), true);
editor.setMandatory(false);
editor.setReadWrite(false);
editorMap.put(infoColumn.getSelectClause(), editor);
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), ValueNamePair.class, (String)null);
editorMap.put(colSQL, editor);
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, ValueNamePair.class, (String)null);
}
else
{
@ -1620,7 +1624,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
}
else
{
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), DisplayType.getClass(infoColumn.getAD_Reference_ID(), true));
columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, DisplayType.getClass(infoColumn.getAD_Reference_ID(), true));
}
columnInfo.setColDescription(infoColumn.get_Translation("Description"));
columnInfo.setGridField(getGridField(infoColumn));

View File

@ -60,6 +60,7 @@ import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.window.FDialog;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MInfoColumn;
import org.compiere.model.MInfoWindow;
import org.compiere.model.MPInstance;
import org.compiere.model.MProcess;
@ -524,12 +525,11 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
// with each process have viewID, read it form resultSet by name
for (MInfoProcess infoProcess : infoProcessList){
if (infoProcess.getAD_Column_ID() == 0){
if (infoProcess.getAD_InfoColumn_ID() <= 0)
continue;
}
String viewIDSql = infoProcess.getViewIDName();
String viewIDValue = rs.getString(viewIDSql);
MInfoColumn infocol = (MInfoColumn) infoProcess.getAD_InfoColumn();
String viewIDValue = rs.getString(infocol.getColumnName());
if (rs.wasNull()) {
data.add(null);
} else {
@ -1511,7 +1511,7 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
return index;
}
// just increase index when process is have ViewID column
if (infoProcessList[i].getAD_Column_ID() > 0)
if (infoProcessList[i].getAD_InfoColumn_ID() > 0)
index++;
}
return -1;