📄 mtab.java
字号:
{
if (errorLog != null)
m_mTable.fireDataStatusEEvent(errorLog);
} // fireDataStatusEvent
/**
* Get Current Row
* @return current row
*/
public int getCurrentRow()
{
if (m_currentRow != verifyRow(m_currentRow))
setCurrentRow(m_mTable.getRowCount()-1, true);
return m_currentRow;
} // getCurrentRow
/**
* Get Current TableKey_ID
* @return ID
*/
public int getCurrentKeyID()
{
return m_mTable.getKeyID(m_currentRow);
} // getCurrentKeyID
/**
* Get Key ID of row
* @param row row number
* @return The Key ID of the row or -1 if not found
*/
public int getKeyID (int row)
{
return m_mTable.getKeyID (row);
} // getCurrentKeyID
/**
* Navigate absulute - goto Row - (zero based).
* - does nothing, if in current row
* - saves old row if required
* @param targetRow target row
* @return current row
*/
public int navigate (int targetRow)
{
// nothing to do
if (targetRow == m_currentRow)
return m_currentRow;
Log.trace(Log.l1_User, "MTab.navigate - Row=" + targetRow);
// Row range check
int newRow = verifyRow(targetRow);
// Check, if we have old uncommitted data
m_mTable.dataSave(newRow, false);
// new position
return setCurrentRow(newRow, true);
} // navigate
/**
* Navigate relatively - i.e. plus/minus from current position
* @param rowChange row change
* @return current row
*/
public int navigateRelative (int rowChange)
{
return navigate (m_currentRow + rowChange);
} // navigateRelative
/**
* Navigate to current now (reload)
* @return current row
*/
public int navigateCurrent()
{
Log.trace(Log.l1_User, "MTab.navigateCurrent");
return setCurrentRow(m_currentRow, true);
} // navigateCurrent
/**
* Row Range check
* @param targetRow target row
* @return checked row
*/
private int verifyRow (int targetRow)
{
int newRow = targetRow;
// Table Open?
if (!m_mTable.isOpen())
{
Log.error("MTab.verifyRow - Table not open");
return -1;
}
// Row Count
int rows = getRowCount();
if (rows == 0)
{
Log.trace(Log.l4_Data, "MTab.verifyRow", "No Rows");
return -1;
}
if (newRow >= rows)
{
newRow = rows-1;
Log.trace(Log.l4_Data, "MTab.verifyRow", "Set to max Row: " + newRow);
}
else if (newRow < 0)
{
newRow = 0;
Log.trace(Log.l4_Data, "MTab.verifyRow", "Set to first Row");
}
return newRow;
} // verifyRow
/**
* Set current row and load data into fields.
* If there is no row - load nulls
* @param newCurrentRow new current row
* @param fireEvents fire events
* @return current row
*/
private int setCurrentRow (int newCurrentRow, boolean fireEvents)
{
int oldCurrentRow = m_currentRow;
m_currentRow = verifyRow (newCurrentRow);
Log.trace(Log.l4_Data, "MTab.setCurrentRow = " + m_currentRow, "fire=" + fireEvents);
// Update Field Values
int size = m_mTable.getColumnCount();
for (int i = 0; i < size; i++)
{
MField mField = m_mTable.getField(i);
// get Value from Table
if (m_currentRow >= 0)
{
Object value = m_mTable.getValueAt(m_currentRow, i);
mField.setValue(value, m_mTable.isInserting());
}
else
{ // no rows - set to a reasonable value - not updateable
// Object value = null;
// if (mField.isKey() || mField.isParent() || mField.getColumnName().equals(m_linkColumnName))
// value = mField.getDefault();
mField.setValue();
}
}
loadDependentInfo();
if (!fireEvents) // prevents informing twice
return m_currentRow;
// inform VTable/.. -> rowChanged
m_propertyChangeSupport.firePropertyChange(PROPERTY, oldCurrentRow, m_currentRow);
// inform APanel/.. -> dataStatus with row updated
if (m_DataStatusEvent == null)
{
Log.trace(Log.l5_DData, "MTab.setCurrentRow - no existing data status event");
}
else
{
m_DataStatusEvent.setCurrentRow(m_currentRow);
String status = m_DataStatusEvent.getAD_Message();
if (status == null || status.length() == 0)
m_DataStatusEvent.setInfo("NavigateOrUpdate", null, false);
fireDataStatusChanged(m_DataStatusEvent);
}
return m_currentRow;
} // setCurrentRow
/*************************************************************************/
/**
* Get RowCount
* @return row count
*/
public int getRowCount()
{
int count = m_mTable.getRowCount();
// Wait a bit if currently loading
if (count == 0 && m_mTable.isLoading())
{
try
{
Thread.sleep(100); // .1 sec
}
catch (Exception e) {}
count = m_mTable.getRowCount();
}
return count;
} // getRowCount
/**
* Get Column/Field Count
* @return field count
*/
public int getFieldCount()
{
return m_mTable.getColumnCount();
} // getFieldCount
/**
* Get Field by index
* @param index index
* @return MField
*/
public MField getField (int index)
{
return m_mTable.getField(index);
} // getField
/**
* Get Field by DB column name
* @param columnName column name
* @return MField
*/
public MField getField (String columnName)
{
return m_mTable.getField(columnName);
} // getField
/**
* Set New Value & call Callout
* @param columnName database column name
* @param value value
* @return error message or ""
*/
public String setValue (String columnName, Object value)
{
if (columnName == null)
return "NoColumn";
return setValue(m_mTable.getField(columnName), value);
} // setValue
/**
* Set New Value & call Callout
* @param field field
* @param value value
* @return error message or ""
*/
public String setValue (MField field, Object value)
{
if (field == null)
return "NoField";
Log.trace(Log.l3_Util, "MTab.setValue - "
+ field.getColumnName() + "=" + value + " for row=" + m_currentRow);
int col = m_mTable.findColumn(field.getColumnName());
m_mTable.setValueAt(value, m_currentRow, col, false);
//
return processFieldChange (field);
} // setValue
/**
* Process Field Change - evaluate Dependencies and process Callouts.
*
* called from MTab.setValue or GridController.dataStatusChanged
* @param changedField changed field
* @return error message or ""
*/
public String processFieldChange (MField changedField)
{
processDependencies (changedField);
return processCallout (changedField);
} // processFieldChange
/**
* Evaluate Dependencies
* @param changedField changed field
*/
private void processDependencies (MField changedField)
{
String columnName = changedField.getColumnName();
// Log.trace(Log.l4_Data, "Changed Column", columnName);
// when column name is not in list of DependentOn fields - fini
if (!isDependentOn(columnName))
return;
// Get dependent MFields (may be because of display or dynamic lookup)
ArrayList list = getDependentFieldList(columnName);
for (int i = 0; i < list.size(); i++)
{
MField dependentField = (MField)list.get(i);
// Log.trace(Log.l5_DData, "Dependent Field", dependentField==null ? "null" : dependentField.getColumnName());
// if the field has a lookup
if (dependentField != null && dependentField.getLookup() instanceof MLookup)
{
MLookup mLookup = (MLookup)dependentField.getLookup();
// Log.trace(Log.l6_Database, "Lookup Validation", mLookup.getValidation());
// if the lookup is dynamic (i.e. contains this columnName as variable)
if (mLookup.getValidation().indexOf("@"+columnName+"@") != -1)
{
Log.trace(Log.l6_Database, "MTab.processDependencies",
columnName + " changed - " + dependentField.getColumnName() + " set to null");
// invalidate current selection
setValue(dependentField, null);
}
}
} // for all dependent fields
} // processDependencies
/**
* Process Callout(s).
* <p>
* The Callout is in the string of
* "class.method;class.method;"
* If there is no class name, i.e. only a method name, the class is regarded
* as CalloutSystem.
* The class needs to comply with the Interface Callout.
*
* For a limited time, the old nptation of Sx_matheod / Ux_menthod is maintained.
*
* @param field field
* @return error message or ""
* @see org.compiere.model.Callout
*/
private String processCallout (MField field)
{
String callout = field.getCallout();
if (callout.length() == 0)
return "";
Object value = field.getValue();
Object oldValue = field.getOldValue();
Log.trace(Log.l3_Util, "MTab.processCallout - " + field.getColumnName() + "=" + value
+ " (" + callout + ") - old=" + oldValue);
StringTokenizer st = new StringTokenizer(callout, ";", false);
while (st.hasMoreTokens()) // for each callout
{
String cmd = st.nextToken().trim();
Callout call = null;
String method = null;
int methodStart = cmd.lastIndexOf(".");
try
{
if (methodStart == -1) // no class
{
// old version compatibility
if (cmd.charAt(0) == 'S' && cmd.charAt(2) == '_')
{
call = new CalloutSystem();
if (cmd.length() > 3)
method = cmd.substring(3);
}
else if (cmd.charAt(0) == 'U' && cmd.charAt(2) == '_')
{
Class cClass = Class.forName("com.compiere.custom.CalloutUser");
call = (Callout)cClass.newInstance();
if (cmd.length() > 3)
method = cmd.substring(3);
}
else
{
call = new CalloutSystem();
method = cmd;
}
}
else
{
Class cClass = Class.forName(cmd.substring(0,methodStart));
call = (Callout)cClass.newInstance();
method = cmd.substring(methodStart+1);
}
}
catch (Exception e)
{
Log.error("MTab.processCallout", e);
return "CalloutNameInvalid = " + cmd + " (" + e.toString() + ")";
}
String retValue = "";
if (call != null && method != null && !method.equals(""))
retValue = call.start(m_vo.ctx, method, m_vo.WindowNo, this, field, value, oldValue);
else
retValue = "CalloutNameInvalid = " + method;
if (!retValue.equals("")) // interrupt on first error
{
Log.error("MTab.processCallout - " + retValue);
return retValue;
}
} // for each callout
return "";
} // processCallout
/**
* Get Value of Field with columnName
* @param columnName column name
* @return value
*/
public Object getValue (String columnName)
{
if (columnName == null)
return null;
MField field = m_mTable.getField(columnName);
return getValue(field);
} // getValue
/**
* Get Value of Field
* @param field field
* @return value
*/
public Object getValue (MField field)
{
if (field == null)
return null;
return field.getValue();
} // getValue
/**
* Get Value of Field in row
* @param row row
* @param columnName column name
* @return value
*/
public Object getValue (int row, String columnName)
{
int col = m_mTable.findColumn(columnName);
if (col == -1)
return null;
return m_mTable.getValueAt(row, col);
} // getValue
/**
* toString
* @return String representation
*/
public String toString()
{
String retValue = "MTab #" + m_vo.TabNo;
if (m_vo != null)
retValue += " " + m_vo.Name + " (" + m_vo.AD_Tab_ID + ")";
return retValue;
} // toString
/*************************************************************************/
/**
* @param l listener
*/
public synchronized void removePropertyChangeListener(PropertyChangeListener l)
{
m_propertyChangeSupport.removePropertyChangeListener(l);
}
/**
* @param l listener
*/
public synchronized void addPropertyChangeListener(PropertyChangeListener l)
{
m_propertyChangeSupport.addPropertyChangeListener(l);
}
/**
* @param l listener
*/
public synchronized void removeDataStatusListener(DataStatusListener l)
{
if (m_dataStatusListeners != null && m_dataStatusListeners.contains(l))
{
Vector v = (Vector) m_dataStatusListeners.clone();
v.removeElement(l);
m_dataStatusListeners = v;
}
}
/**
* @param l listener
*/
public synchronized void addDataStatusListener(DataStatusListener l)
{
Vector v = m_dataStatusListeners == null ? new Vector(2) : (Vector) m_dataStatusListeners.clone();
if (!v.contains(l))
{
v.addElement(l);
m_dataStatusListeners = v;
}
}
} // M_Tab
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -