IDEMPIERE-1968:valid check box in info window can manual editable

This commit is contained in:
hieplq 2014-06-04 00:19:25 +07:00
parent 95aef084ec
commit ea3bbe1418
4 changed files with 156 additions and 0 deletions

View File

@ -0,0 +1,22 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Jun 3, 2014 4:22:36 PM ICT
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_DATE('2014-06-03 16:22:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=201639
;
-- Jun 3, 2014 11:42:11 PM ICT
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_Column SET AD_Process_ID=NULL,Updated=TO_DATE('2014-06-03 23:42:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=15759
;
-- Jun 3, 2014 11:44:39 PM ICT
UPDATE AD_Column SET IsToolbarButton='N', AD_Reference_ID=10,Updated=TO_DATE('2014-06-03 23:44:39','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=15759
;
-- Jun 3, 2014 11:47:13 PM ICT
UPDATE AD_Field SET IsDisplayed='N',Updated=TO_DATE('2014-06-03 23:47:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=13580
;
SELECT register_migration_script('201406031604_IDEMPIERE-1968.sql') FROM dual
;

View File

@ -0,0 +1,18 @@
-- Jun 3, 2014 4:22:36 PM ICT
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_TIMESTAMP('2014-06-03 16:22:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=201639
;
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_Column SET AD_Process_ID=NULL,Updated=TO_TIMESTAMP('2014-06-03 23:42:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=15759
;
-- Jun 3, 2014 11:44:39 PM ICT
UPDATE AD_Column SET IsToolbarButton='N', AD_Reference_ID=10,Updated=TO_TIMESTAMP('2014-06-03 23:44:39','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=15759
;
-- Jun 3, 2014 11:47:13 PM ICT
UPDATE AD_Field SET IsDisplayed='N',Updated=TO_TIMESTAMP('2014-06-03 23:47:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=13580
;
SELECT register_migration_script('201406031604_IDEMPIERE-1968.sql') FROM dual
;

View File

@ -131,5 +131,38 @@ public class MInfoColumn extends X_AD_InfoColumn
return true;
}
/**
* when change field relate to sql, call valid from infoWindow
*/
@Override
protected boolean afterSave(boolean newRecord, boolean success) {
if (!success)
return success;
// evaluate need valid
boolean isNeedValid = newRecord || is_ValueChanged (MInfoColumn.COLUMNNAME_SelectClause);
// call valid of parrent
if (isNeedValid){
MInfoWindow parentInfo = new MInfoWindow (getCtx(), this.getAD_InfoWindow_ID(), get_TrxName());
parentInfo.validate();
parentInfo.saveEx();
}
return super.afterSave(newRecord, success);
}
/**
* when delete record, call valid from parent to set state
* when delete all, valid state is false
* when delete a wrong column can make valid state to true
*/
@Override
protected boolean afterDelete(boolean success) {
MInfoWindow parentInfo = new MInfoWindow (getCtx(), this.getAD_InfoWindow_ID(), get_TrxName());
parentInfo.validate();
parentInfo.saveEx();
return super.afterDelete(success);
}
} // MInfoColumn

View File

@ -329,6 +329,17 @@ public class MInfoWindow extends X_AD_InfoWindow
}
}
}
// evaluate need valid
boolean isNeedValid = is_new() || is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_AD_Table_ID) || is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_WhereClause) ||
is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_FromClause) || is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_OrderByClause) ||
is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_OtherClause) || is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_IsDistinct);
// valid config
if (isNeedValid){
validate();
}
return true;
}
@ -363,4 +374,76 @@ public class MInfoWindow extends X_AD_InfoWindow
}
public void validate ()
{
// default, before complete check is invalid
this.setIsValid(false);
// add DISTINCT clause
StringBuilder builder = new StringBuilder("SELECT ");
if (this.isDistinct())
builder.append("DISTINCT ");
MInfoColumn[] infoColumns = this.getInfoColumns();
// none column make this invalid
if (infoColumns.length == 0){
return;
}
// build select clause
for (int columnIndex = 0; columnIndex < infoColumns.length; columnIndex++) {
if (columnIndex > 0)
{
builder.append(", ");
}
builder.append(infoColumns[columnIndex].getSelectClause());
}
// build from clause
builder.append( " FROM ").append(this.getFromClause());
// build where clause add (1=2) because not need get result, decrease load
if (this.getWhereClause() != null && this.getWhereClause().trim().length() > 0) {
builder.append(" WHERE (1=2) AND (").append(this.getWhereClause()).append(")");
} else {
builder.append(" WHERE 1=2");
}
// build other (having) clause
if (this.getOtherClause() != null && this.getOtherClause().trim().length() > 0) {
builder.append(" ").append(this.getOtherClause());
}
// build order (having) clause
if (this.getOrderByClause() != null && this.getOrderByClause().trim().length() > 0) {
builder.append(" ORDER BY ").append(this.getOrderByClause());
}
// replace env value by dummy value
while(builder.indexOf("@") >= 0) {
int start = builder.indexOf("@");
int end = builder.indexOf("@", start+1);
if (start >=0 && end > start) {
builder.replace(start, end+1, "0");
} else {
break;
}
}
// try run sql
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(builder.toString(), null);
pstmt.executeQuery();
}catch (Exception ex){
log.log(Level.WARNING, ex.getMessage());
return;
} finally {
DB.close(pstmt);
}
// valid state
this.setIsValid(true);
}
} // MInfoWindow