Implement [ 1795398 ] Process Parameter: add display and readonly logic
This commit is contained in:
parent
19beaeaf8b
commit
373b60f28e
|
@ -54,6 +54,7 @@ import org.compiere.util.Evaluator;
|
|||
* @author Jorg Janke
|
||||
* @author Victor Perez , e-Evolution.SC FR [ 1757088 ], [1877902] Implement JSR 223 Scripting APIs to Callout
|
||||
* @author Carlos Ruiz, qss FR [1877902]
|
||||
* @author Juan David Arboleda (arboleda), GlobalQSS, [ 1795398 ] Process Parameter: add display and readonly logic
|
||||
* @see http://sourceforge.net/tracker/?func=detail&atid=879335&aid=1877902&group_id=176962 to FR [1877902]
|
||||
* @version $Id: GridField.java,v 1.5 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
|
@ -324,6 +325,25 @@ public class GridField
|
|||
return isDisplayed (checkContext);
|
||||
} // isMandatory
|
||||
|
||||
/**
|
||||
* Is parameter Editable - checks if parameter is Read Only
|
||||
* @param checkContext if true checks Context
|
||||
* @return true, if editable
|
||||
*/
|
||||
public boolean isEditablePara(boolean checkContext) {
|
||||
if (checkContext && m_vo.ReadOnlyLogic.length() > 0)
|
||||
{
|
||||
boolean retValue = !Evaluator.evaluateLogic(this, m_vo.ReadOnlyLogic);
|
||||
log.finest(m_vo.ColumnName + " R/O(" + m_vo.ReadOnlyLogic + ") => R/W-" + retValue);
|
||||
if (!retValue)
|
||||
return false;
|
||||
}
|
||||
|
||||
// ultimately visibility decides
|
||||
return isDisplayed (checkContext);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is it Editable - checks IsActive, IsUpdateable, and isDisplayed
|
||||
* @param checkContext if true checks Context for Active, IsProcessed, LinkColumn
|
||||
|
@ -413,7 +433,7 @@ public class GridField
|
|||
if (checkContext && !Env.getContext(m_vo.ctx, m_vo.WindowNo, "IsActive").equals("Y"))
|
||||
return false;
|
||||
|
||||
// ultimately visibily decides
|
||||
// ultimately visibility decides
|
||||
return isDisplayed (checkContext);
|
||||
} // isEditable
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.compiere.util.Env;
|
|||
* @author Jorg Janke
|
||||
* @author Victor Perez , e-Evolution.SC FR [ 1757088 ] , [1877902] Implement JSR 223 Scripting APIs to Callout
|
||||
* @author Carlos Ruiz, qss FR [1877902]
|
||||
* @author Juan David Arboleda (arboleda), GlobalQSS, [ 1795398 ] Process Parameter: add display and readonly logic
|
||||
* @see http://sourceforge.net/tracker/?func=detail&atid=879335&aid=1877902&group_id=176962 to FR [1877902]
|
||||
* @version $Id: GridFieldVO.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
|
@ -292,6 +293,9 @@ public class GridFieldVO implements Serializable
|
|||
//
|
||||
vo.AD_Reference_Value_ID = rs.getInt("AD_Reference_Value_ID");
|
||||
vo.ValidationCode = rs.getString("ValidationCode");
|
||||
vo.ReadOnlyLogic = rs.getString("ReadOnlyLogic");
|
||||
vo.DisplayLogic= rs.getString("DisplayLogic");
|
||||
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
|
|
|
@ -188,6 +188,19 @@ public interface I_AD_Process_Para
|
|||
*/
|
||||
public String getDescription();
|
||||
|
||||
/** Column name DisplayLogic */
|
||||
public static final String COLUMNNAME_DisplayLogic = "DisplayLogic";
|
||||
|
||||
/** Set Display Logic.
|
||||
* If the Field is displayed, the result determines if the field is actually displayed
|
||||
*/
|
||||
public void setDisplayLogic (String DisplayLogic);
|
||||
|
||||
/** Get Display Logic.
|
||||
* If the Field is displayed, the result determines if the field is actually displayed
|
||||
*/
|
||||
public String getDisplayLogic();
|
||||
|
||||
/** Column name EntityType */
|
||||
public static final String COLUMNNAME_EntityType = "EntityType";
|
||||
|
||||
|
@ -281,6 +294,19 @@ public interface I_AD_Process_Para
|
|||
*/
|
||||
public String getName();
|
||||
|
||||
/** Column name ReadOnlyLogic */
|
||||
public static final String COLUMNNAME_ReadOnlyLogic = "ReadOnlyLogic";
|
||||
|
||||
/** Set Read Only Logic.
|
||||
* Logic to determine if field is read only (applies only when field is read-write)
|
||||
*/
|
||||
public void setReadOnlyLogic (String ReadOnlyLogic);
|
||||
|
||||
/** Get Read Only Logic.
|
||||
* Logic to determine if field is read only (applies only when field is read-write)
|
||||
*/
|
||||
public String getReadOnlyLogic();
|
||||
|
||||
/** Column name SeqNo */
|
||||
public static final String COLUMNNAME_SeqNo = "SeqNo";
|
||||
|
||||
|
|
|
@ -339,6 +339,23 @@ public class X_AD_Process_Para extends PO implements I_AD_Process_Para, I_Persis
|
|||
return (String)get_Value(COLUMNNAME_Description);
|
||||
}
|
||||
|
||||
/** Set Display Logic.
|
||||
@param DisplayLogic
|
||||
If the Field is displayed, the result determines if the field is actually displayed
|
||||
*/
|
||||
public void setDisplayLogic (String DisplayLogic)
|
||||
{
|
||||
set_Value (COLUMNNAME_DisplayLogic, DisplayLogic);
|
||||
}
|
||||
|
||||
/** Get Display Logic.
|
||||
@return If the Field is displayed, the result determines if the field is actually displayed
|
||||
*/
|
||||
public String getDisplayLogic ()
|
||||
{
|
||||
return (String)get_Value(COLUMNNAME_DisplayLogic);
|
||||
}
|
||||
|
||||
/** EntityType AD_Reference_ID=389 */
|
||||
public static final int ENTITYTYPE_AD_Reference_ID=389;
|
||||
/** Set Entity Type.
|
||||
|
@ -494,6 +511,23 @@ public class X_AD_Process_Para extends PO implements I_AD_Process_Para, I_Persis
|
|||
return new KeyNamePair(get_ID(), getName());
|
||||
}
|
||||
|
||||
/** Set Read Only Logic.
|
||||
@param ReadOnlyLogic
|
||||
Logic to determine if field is read only (applies only when field is read-write)
|
||||
*/
|
||||
public void setReadOnlyLogic (String ReadOnlyLogic)
|
||||
{
|
||||
set_Value (COLUMNNAME_ReadOnlyLogic, ReadOnlyLogic);
|
||||
}
|
||||
|
||||
/** Get Read Only Logic.
|
||||
@return Logic to determine if field is read only (applies only when field is read-write)
|
||||
*/
|
||||
public String getReadOnlyLogic ()
|
||||
{
|
||||
return (String)get_Value(COLUMNNAME_ReadOnlyLogic);
|
||||
}
|
||||
|
||||
/** Set Sequence.
|
||||
@param SeqNo
|
||||
Method of ordering records; lowest number comes first
|
||||
|
|
|
@ -50,6 +50,8 @@ import org.compiere.util.Env;
|
|||
* - checks, if parameters exist and inquires and saves them
|
||||
*
|
||||
* @author Low Heng Sin
|
||||
* @author Juan David Arboleda (arboleda), GlobalQSS, [ 1795398 ] Process
|
||||
* Parameter: add display and readonly logic
|
||||
* @version 2006-12-01
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
|
@ -91,6 +93,7 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
private ArrayList<VEditor> m_vEditors2 = new ArrayList<VEditor>(); // for ranges
|
||||
private ArrayList<GridField> m_mFields = new ArrayList<GridField>();
|
||||
private ArrayList<GridField> m_mFields2 = new ArrayList<GridField>();
|
||||
private ArrayList<JLabel> m_separators = new ArrayList<JLabel>();
|
||||
//
|
||||
private BorderLayout mainLayout = new BorderLayout();
|
||||
private CPanel centerPanel = new CPanel();
|
||||
|
@ -116,6 +119,7 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
m_vEditors2.clear();
|
||||
m_mFields.clear();
|
||||
m_mFields2.clear();
|
||||
m_separators.clear();
|
||||
this.removeAll();
|
||||
} // dispose
|
||||
|
||||
|
@ -182,7 +186,7 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
+ "p.AD_Reference_ID, p.AD_Process_Para_ID, "
|
||||
+ "p.FieldLength, p.IsMandatory, p.IsRange, p.ColumnName, "
|
||||
+ "p.DefaultValue, p.DefaultValue2, p.VFormat, p.ValueMin, p.ValueMax, "
|
||||
+ "p.SeqNo, p.AD_Reference_Value_ID, vr.Code AS ValidationCode "
|
||||
+ "p.SeqNo, p.AD_Reference_Value_ID, vr.Code AS ValidationCode, p.ReadOnlyLogic, p.DisplayLogic "
|
||||
+ "FROM AD_Process_Para p"
|
||||
+ " LEFT OUTER JOIN AD_Val_Rule vr ON (p.AD_Val_Rule_ID=vr.AD_Val_Rule_ID) "
|
||||
+ "WHERE p.AD_Process_ID=?" // 1
|
||||
|
@ -193,7 +197,7 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
+ "p.AD_Reference_ID, p.AD_Process_Para_ID, "
|
||||
+ "p.FieldLength, p.IsMandatory, p.IsRange, p.ColumnName, "
|
||||
+ "p.DefaultValue, p.DefaultValue2, p.VFormat, p.ValueMin, p.ValueMax, "
|
||||
+ "p.SeqNo, p.AD_Reference_Value_ID, vr.Code AS ValidationCode "
|
||||
+ "p.SeqNo, p.AD_Reference_Value_ID, vr.Code AS ValidationCode, p.ReadOnlyLogic, p.DisplayLogic "
|
||||
+ "FROM AD_Process_Para p"
|
||||
+ " INNER JOIN AD_Process_Para_Trl t ON (p.AD_Process_Para_ID=t.AD_Process_Para_ID)"
|
||||
+ " LEFT OUTER JOIN AD_Val_Rule vr ON (p.AD_Val_Rule_ID=vr.AD_Val_Rule_ID) "
|
||||
|
@ -204,23 +208,29 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
|
||||
// Create Fields
|
||||
boolean hasFields = false;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, m_processInfo.getAD_Process_ID());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
hasFields = true;
|
||||
createField (rs);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null;
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
// both vectors the same?
|
||||
if (m_mFields.size() != m_mFields2.size()
|
||||
|
@ -235,18 +245,18 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
centerPanel.add(Box.createVerticalStrut(10), gbc); // bottom gap
|
||||
gbc.gridx = 3;
|
||||
centerPanel.add(Box.createHorizontalStrut(12), gbc); // right gap
|
||||
dynamicDisplay();
|
||||
}
|
||||
else
|
||||
dispose();
|
||||
return hasFields;
|
||||
} // initDialog
|
||||
|
||||
} // init
|
||||
|
||||
/**
|
||||
* Create Field.
|
||||
* - creates Fields and adds it to m_mFields list
|
||||
* - creates Editor and adds it to m_vEditors list
|
||||
* Handeles Ranges by adding additional mField/vEditor.
|
||||
* Handles Ranges by adding additional mField/vEditor.
|
||||
* <p>
|
||||
* mFields are used for default value and mandatory checking;
|
||||
* vEditors are used to retrieve the value (no data binding)
|
||||
|
@ -303,7 +313,9 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
gbc.gridx = 2;
|
||||
gbc.weightx = 0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
centerPanel.add (new JLabel(" - "), gbc);
|
||||
JLabel dash = new JLabel(" - ");
|
||||
centerPanel.add (dash, gbc);
|
||||
m_separators.add(dash);
|
||||
// To Field
|
||||
gbc.gridx = 3;
|
||||
gbc.insets = fieldInsetRight;
|
||||
|
@ -327,6 +339,7 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
}
|
||||
else
|
||||
{
|
||||
m_separators.add(null);
|
||||
m_mFields2.add (null);
|
||||
m_vEditors2.add (null);
|
||||
}
|
||||
|
@ -340,10 +353,81 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException
|
||||
{
|
||||
// log.fine( "ProcessParameterPanel.vetoableChange");
|
||||
String value = evt.getNewValue() == null ? "" : evt.getNewValue().toString();
|
||||
Env.setContext(Env.getCtx(), m_WindowNo, evt.getPropertyName(), value);
|
||||
processNewValue(evt.getNewValue(), evt.getPropertyName());
|
||||
} // vetoableChange
|
||||
|
||||
private void processNewValue(Object value, String name) {
|
||||
if (value == null)
|
||||
value = new String("");
|
||||
|
||||
if (value instanceof String)
|
||||
Env.setContext(Env.getCtx(), m_WindowNo, name, (String) value);
|
||||
else if (value instanceof Integer)
|
||||
Env.setContext(Env.getCtx(), m_WindowNo, name, ((Integer) value)
|
||||
.intValue());
|
||||
else if (value instanceof Boolean)
|
||||
Env.setContext(Env.getCtx(), m_WindowNo, name, ((Boolean) value)
|
||||
.booleanValue());
|
||||
else if (value instanceof Timestamp)
|
||||
Env.setContext(Env.getCtx(), m_WindowNo, name, (Timestamp) value);
|
||||
else
|
||||
Env.setContext(Env.getCtx(), m_WindowNo, name, value.toString());
|
||||
|
||||
dynamicDisplay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Display.
|
||||
*
|
||||
**/
|
||||
public void dynamicDisplay() {
|
||||
Component[] comps = centerPanel.getComponents();
|
||||
for (int i = 0; i < comps.length; i++) {
|
||||
Component comp = comps[i];
|
||||
String columnName = comp.getName();
|
||||
|
||||
if (columnName != null && columnName.length() > 0) {
|
||||
int index = getIndex(columnName);
|
||||
if (m_mFields.get(index) != null) {
|
||||
if (m_mFields.get(index).isDisplayed(true)) { // check
|
||||
// context
|
||||
if (!comp.isVisible()) {
|
||||
comp.setVisible(true); // visibility
|
||||
if (m_mFields.get(index).getVO().isRange)
|
||||
m_separators.get(index).setText(" - ");
|
||||
}
|
||||
boolean rw = m_mFields.get(index).isEditablePara(true); // r/w - check if field is Editable
|
||||
m_vEditors.get(index).setReadWrite(rw);
|
||||
if (m_mFields.get(index).getVO().isRange)
|
||||
m_vEditors2.get(index).setReadWrite(rw);
|
||||
} else {
|
||||
if (comp.isVisible()) {
|
||||
comp.setVisible(false);
|
||||
if (m_mFields.get(index).getVO().isRange)
|
||||
m_separators.get(index).setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // Dynamic Display.
|
||||
|
||||
/**
|
||||
* getIndex. Get m_mFields index from columnName
|
||||
*
|
||||
* @param columnName
|
||||
* @return int
|
||||
**/
|
||||
private int getIndex(String columnName) {
|
||||
|
||||
for (int i = 0; i < m_mFields.size(); i++) {
|
||||
if (m_mFields.get(i).getColumnName().equals(columnName)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} // getIndex
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.compiere.apps.ProcessParameters#saveParameters()
|
||||
*/
|
||||
|
@ -496,4 +580,3 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
|||
}
|
||||
}
|
||||
} // ProcessParameterPanel
|
||||
|
||||
|
|
Loading…
Reference in New Issue