📄 mfield.java
字号:
{
Log.trace(Log.l5_DData, "MField.getDefault [Number=0] " + m_vo.ColumnName);
return createDefault("0");
}
/**
* No resolution
*/
Log.trace(Log.l5_DData, "MField.getDefault [NONE] " + m_vo.ColumnName);
return null;
} // getDefault
/**
* Create Default Object type.
* <pre>
* Integer (IDs)
* BigDecimal (Numbers)
* Timestamp (Dates)
* default: String
* </pre>
* @param value string
* @return type dependent converted object
*/
private Object createDefault (String value)
{
// true NULL
if (value == null || value.toString().length() == 0)
return null;
try
{
// IDs
if (m_vo.ColumnName.endsWith("_ID"))
return new Integer(value);
// Number
else if (DisplayType.isNumeric(m_vo.displayType))
return new BigDecimal(value);
// Timestamps
if (DisplayType.isDate(m_vo.displayType))
{
java.util.Date date = DisplayType.getDateFormat_JDBC().parse (value);
return new Timestamp (date.getTime());
}
else
return value;
}
catch (Exception e)
{
Log.error("MField.createDefault - " + e.getMessage());
}
return null;
} // createDefault
/**
* Validate Value
* @return true if valid
*/
public boolean validateValue()
{
// null
if (m_value == null)
{
if (isMandatory(true))
{
m_error = true;
return false;
}
else
return true;
}
// not null
if (!isLookup() || m_lookup.containsKey(m_value))
return true;
setValue(null, m_inserting);
m_error = true;
return false;
} // validateValue
/*************************************************************************/
/**
* Is the Column Visible ?
* @param checkContext - check environment (requires correct row position)
* @return true, if visible
*/
public boolean isDisplayed (boolean checkContext)
{
// ** static content **
// not displayed
if (!m_vo.IsDisplayed)
return false;
// no restrictions
if (m_vo.DisplayLogic.equals(""))
return true;
// ** dynamic content **
if (checkContext)
{
boolean retValue = evaluateLogic(m_vo.DisplayLogic);
// Log.trace(Log.l5_DData, "MField.isDisplayed", ColumnName + " => " + retValue);
return retValue;
}
return true;
} // isDisplayed
/**
* Evaluate Logic and return true, if Field is displayed.
* <pre>
* format := <expression> [<logic> <expression>]
* expression := @<context>@<exLogic><value>
* logic := <|> | <&>
* exLogic := <=> | <!=>
*
* context := any global or window context
* value := strings can be with ' or "
* logic operators := AND or OR with the prevoius result from left to right
*
* Example '@AD_Table@=Test | @Language@=GERGER
* </pre>
* @param logic logic string
* @return locic result
*/
private boolean evaluateLogic (String logic)
{
// Conditional
StringTokenizer st = new StringTokenizer(logic.trim(), "&|", true);
int it = st.countTokens();
if (((it/2) - ((it+1)/2)) == 0) // only uneven arguments
{
Log.error ("MField.evatuateLogic - " + getColumnName()
+ " Logic does not comply with format "
+ "'<expression> [<logic> <expression>]' => " + logic);
return false;
}
boolean retValue = evaluateLogicTuple(st.nextToken());
while (st.hasMoreTokens())
{
String logOp = st.nextToken().trim();
boolean temp = evaluateLogicTuple(st.nextToken());
if (logOp.equals("&"))
retValue = retValue & temp;
else if (logOp.equals("|"))
retValue = retValue | temp;
else
{
Log.error("MField.evaluateLogic - " + getColumnName()
+ "Logic operant '|' or '&' expected => " + logic);
return false;
}
} // hasMoreTokens
return retValue;
} // evaluateLogic
/**
* Evaluate @context@=value or @context@!value or @context@^value.
* <pre>
* value: strips ' and " always (no escape or mid stream)
* value: can also be a context variable
* </pre>
* @param logic logic touple
* @return true or false
*/
private boolean evaluateLogicTuple (String logic)
{
StringTokenizer st = new StringTokenizer(logic.trim(), "!=^", true);
if (st.countTokens() != 3)
{
Log.error("MField.evaluateLogicTuple " + getColumnName()
+ " Logic touple does not comply with format "
+ "'@context@=value' or '@context@!value' => " + logic);
return false;
}
// Tag
String tag = st.nextToken().trim(); // get '@tag@'
tag = tag.replace('@', ' ').trim(); // strip 'tag'
String tagEval = Env.getContext(m_vo.ctx, m_vo.WindowNo, tag); // replace with it's value
// Comperator
String compare = st.nextToken();
// Value
String value = st.nextToken(); // get value
String valueEval = value;
// it's a variable
if (value.indexOf('@') != -1)
{
value = value.replace('@', ' ').trim(); // strip tag
valueEval = Env.getContext(m_vo.ctx, m_vo.WindowNo, value); // replace with it's value
}
else // a constant
valueEval = valueEval.replace('\'', ' ').replace('"', ' ').trim(); // strip ' and "
// Handling of ID compare (null => 0)
if (tag.indexOf("_ID") != -1 && tagEval.length() == 0)
tagEval = "0";
if (value.indexOf("_ID") != -1 && valueEval.length() == 0)
valueEval = "0";
// Logical Comparison
if (compare.equals("="))
return tagEval.equals(valueEval);
else
return !tagEval.equals(valueEval);
} // evaluateLogicTouple
/**
* Add Display Dependencies to given List.
* Source: DisplayLogic
* @param list list to be added to
*/
public void addDependencies1 (ArrayList list)
{
// nothing to parse
if (!m_vo.IsDisplayed || m_vo.DisplayLogic.equals(""))
return;
StringTokenizer logic = new StringTokenizer(m_vo.DisplayLogic.trim(), "&|", false);
while (logic.hasMoreTokens())
{
StringTokenizer st = new StringTokenizer(logic.nextToken().trim(), "!=^", false);
while (st.hasMoreTokens())
{
String tag = st.nextToken().trim(); // get '@tag@'
// Do we have a @variable@ ?
if (tag.indexOf('@') != -1)
{
tag = tag.replace('@', ' ').trim(); // strip 'tag'
// Add columns (they might not be a column, but then it is static)
if (!list.contains(tag))
list.add(tag);
}
}
}
} // addDependencies
/*************************************************************************/
/**
* Get Column Name
* @return column name
*/
public String getColumnName()
{
return m_vo.ColumnName;
}
public String getHeader()
{
return m_vo.Header;
}
public int getDisplayType()
{
return m_vo.displayType;
}
public int getAD_Window_ID()
{
return m_vo.AD_Window_ID;
}
public int getWindowNo()
{
return m_vo.WindowNo;
}
public int getAD_Column_ID()
{
return m_vo.AD_Column_ID;
}
public int getDisplayLength()
{
return m_vo.DisplayLength;
}
public boolean isSameLine()
{
return m_vo.IsSameLine;
}
public boolean isDisplayed()
{
return m_vo.IsDisplayed;
}
public String getDisplayLogic()
{
return m_vo.DisplayLogic;
}
public String getDefaultValue()
{
return m_vo.DefaultValue;
}
public boolean isReadOnly()
{
return m_vo.IsReadOnly;
}
public boolean isUpdateable()
{
return m_vo.IsUpdateable;
}
public boolean isHeading()
{
return m_vo.IsHeading;
}
public boolean isFieldOnly()
{
return m_vo.IsFieldOnly;
}
public boolean isEncryptedField()
{
return m_vo.IsEncryptedField;
}
public boolean isSelectionColumn()
{
return m_vo.IsSelectionColumn;
}
public int getSortNo()
{
return m_vo.SortNo;
}
public int getFieldLength()
{
return m_vo.FieldLength;
}
public String getVFormat()
{
return m_vo.VFormat;
}
public String getValueMin()
{
return m_vo.ValueMin;
}
public String getValueMax()
{
return m_vo.ValueMax;
}
public String getFieldGroup()
{
return m_vo.FieldGroup;
}
public boolean isKey()
{
return m_vo.IsKey;
}
public boolean isParent()
{
return m_vo.IsParent;
}
public String getCallout()
{
return m_vo.Callout;
}
public int getAD_Process_ID()
{
return m_vo.AD_Process_ID;
}
public String getDescription()
{
return m_vo.Description;
}
public String getHelp()
{
return m_vo.Help;
}
/**
* Is this a long (string/text) field (over 46/2=23 characters)
* @return true if long field
*/
public boolean isLongField()
{
if (m_vo.displayType == DisplayType.String || m_vo.displayType == DisplayType.Text || m_vo.displayType == DisplayType.Memo)
return (m_vo.DisplayLength >= MAXDISPLAY_LENGTH/2);
return false;
} // isLongField
/**
* Set Value to null.
* <p>
* Do not update context
* Send Bean PropertyChange if there is a change
*/
public void setValue ()
{
// Log.trace(Log.l5_DData, "MField.setValue - " + ColumnName + "=" + newValue);
if (m_setOldValue) // set the old value
m_oldValue = m_value;
m_value = null;
m_inserting = false;
m_error = false; // reset error
// Does not fire, if same value
m_propertyChangeListeners.firePropertyChange(PROPERTY, m_oldValue, null);
// m_propertyChangeListeners.firePropertyChange(PROPERTY, s_oldValue, null);
} // setValue
/**
* Set Value.
* <p>
* Update context, if not text or RowID;
* Send Bean PropertyChange if there is a change
* @param newValue new value
* @param inserting true if inserting
*/
public void setValue (Object newValue, boolean inserting)
{
// Log.trace(Log.l5_DData, "MField.setValue - " + ColumnName + "=" + newValue);
if (m_setOldValue) // set the old value
m_oldValue = m_value;
m_value = newValue;
m_inserting = inserting;
m_error = false; // reset error
//
if (m_vo.displayType == DisplayType.Text || m_vo.displayType == DisplayType.RowID)
;
else
Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.ColumnName, m_value==null ? null : m_value.toString());
// Does not fire, if same value
m_propertyChangeListeners.firePropertyChange(PROPERTY, inserting ? INSERTING : m_oldValue, newValue);
} // setValue
/**
* Get Value
* @return current value
*/
public Object getValue()
{
return m_value;
} // getValue
/**
* Set old/previous Value.
* Used by VColor
* @param value if false property change will always be fires
*/
public void setOldValue (boolean value)
{
m_setOldValue = value;
} // setOldValue
/**
* Get old/previous Value
* @return old value
*/
public Object getOldValue()
{
return m_oldValue;
} // getOldValue
/**
* Set Error Value (the value, which cuased some Error)
* @param errorValue error message
*/
public void setErrorValue (String errorValue)
{
m_errorValue = errorValue;
m_errorValueFlag = true;
} // setErrorValue
/**
* Get Error Value (the value, which cuased some Error) <b>AND</b> reset it to null
* @return error value
*/
public String getErrorValue ()
{
String s = m_errorValue;
m_errorValue = null;
m_errorValueFlag = false;
return s;
} // getErrorValue
/**
* Return true, if value has Error (for HTML interface) <b>AND</b> reset it to false
* @return has error
*/
public boolean isErrorValue()
{
boolean b = m_errorValueFlag;
m_errorValueFlag = false;
return b;
} // isErrorValue
/**
* Overwrite default DisplayLength
* @param length new length
*/
public void setDisplayLength (int length)
{
m_vo.DisplayLength = length;
} // setDisplayLength
/**
* Overwrite Displayed
* @param displayed trie if displayed
*/
public void setDisplayed (boolean displayed)
{
m_vo.IsDisplayed = displayed;
} // setDisplayed
/**
* toString
* @return string representation
*/
public String toString()
{
StringBuffer sb = new StringBuffer("MField[");
sb.append(m_vo.ColumnName).append("=").append(m_value).append("]");
return sb.toString();
} // toString
/*************************************************************************/
/**
* Remove Property Change Listener
* @param l listener
*/
public synchronized void removePropertyChangeListener(PropertyChangeListener l)
{
m_propertyChangeListeners.removePropertyChangeListener(l);
}
/**
* Add Property Change Listener
* @param l listener
*/
public synchronized void addPropertyChangeListener(PropertyChangeListener l)
{
m_propertyChangeListeners.addPropertyChangeListener(l);
}
} // MField
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -