📄 gridcontroller.java
字号:
}
// TreeNavigation - Synchronize -- select node in tree
if (m_tree != null)
m_tree.setSelectedNode (m_mTab.getRecord_ID()); // ignores new (-1)
// log.config( "GridController.valueChanged (" + m_mTab.toString() + ") - fini",
// "Row in Table=" + rowTable + ", in Model=" + rowCurrent);
// Query Included Tab
if (vIncludedGC != null)
vIncludedGC.getMTab().query(false, 0);
} // valueChanged
/**
* PropertyChange Listener - Tree Panel - node selection
* @param e event
*/
public void propertyChange(PropertyChangeEvent e)
{
// System.out.println("propertyChange");
// System.out.println(e);
if (e == null)
return;
Object value = e.getNewValue();
if (value == null)
return;
log.config(e.getPropertyName() + "=" + value
+ " - " + value.getClass().toString());
if (!(value instanceof MTreeNode))
return;
// We Have a TreeNode
int nodeID = ((MTreeNode)value).getNode_ID();
// root of tree selected - ignore
if (nodeID == 0)
return;
// Search all rows for mode id
int size = m_mTab.getRowCount();
int row = -1;
for (int i = 0; i < size; i++)
{
if (m_mTab.getKeyID(i) == nodeID)
{
row = i;
break;
}
}
if (row == -1)
{
log.log(Level.SEVERE, "Tab does not have ID with Node_ID=" + nodeID);
return;
}
// Navigate to node row
m_mTab.navigate(row);
} // propertyChange
/**
* Dynamic Display.
* - Single Row Screen layout and update of dynamic Lookups
* <p>
* Single Row layout:
* the components's name is the ColumnName; if it matches, the
* MField.isDisplayed(true) is used to determine if it is visible
* if the component is a VEditor, setEnabled is set from the MField
* <p>
* Multi Row layout is not changed:
* VCellRenderer calls JTable.isCellEditable -> checks MField.isEditable (Active, isDisplayed)
* VCellEditor.isCellEditable calls MField.isEditable(true) <br>
* If a column is not displayed, the width is set to 0 in dynInit
* <p>
* Dynamic update of data is handeled in VLookup.focusGained/Lost.
* When focus is gained the model is temporarily updated with the
* specific validated data, if lost, it is switched back to the
* unvalidated data (i.e. everything). This allows that the display
* methods have a lookup to display. <br>
* Here: if the changed field has dependents and the dependent
* is a Lookup and this lookup has a dynamic dependence of the changed field,
* the value of that field is set to null (in MTab.processDependencies -
* otherwise it would show an invalid value).
* As Editors listen for value changed of their MField, the display is updated.
* <p>
* Called from GridController.valueChanged/dataStatusChanged, APane;.stateChanged/unlock/cmd_...
* @param col selective column number or 0 if all
*/
public void dynamicDisplay (int col)
{
// log.config( "GridController.dynamicDisplay (" + m_mTab.toString() + ") SingleRow=" + isSingleRow() + ", OnlyMultiRow=" + m_onlyMultiRow);
// Don't update if multi-row
if (!isSingleRow() || m_onlyMultiRow)
return;
if (!m_mTab.isOpen())
return;
// Selective
if (col != 0)
{
MField changedField = m_mTab.getField(col);
String columnName = changedField.getColumnName();
ArrayList dependants = m_mTab.getDependantList(columnName);
log.config("(" + m_mTab.toString() + ") "
+ columnName + " - Dependents=" + dependants.size());
// No Dependents and no Callout - Set just Background
if (dependants.size() == 0 && changedField.getCallout().length() > 0)
{
Component[] comp = vPanel.getComponents();
for (int i = 0; i < comp.length; i++)
{
if (columnName.equals(comp[i].getName ()) && comp[i] instanceof VEditor)
{
VEditor ve = (VEditor)comp[i];
boolean manMissing = false;
boolean noValue = changedField.getValue() == null || changedField.getValue().toString().length() == 0;
if (noValue && changedField.isEditable(true) && changedField.isMandatory(true)) // check context
manMissing = true;
ve.setBackground(manMissing || changedField.isError());
break;
}
}
return;
}
} // selective
// complete single row re-display
boolean noData = m_mTab.getRowCount() == 0;
log.config(m_mTab.toString() + " - Rows=" + m_mTab.getRowCount());
// All Components in vPanel (Single Row)
Component[] comp = vPanel.getComponents();
for (int i = 0; i < comp.length; i++)
{
String columnName = comp[i].getName();
if (columnName != null)
{
MField mField = m_mTab.getField(columnName);
if (mField != null)
{
if (mField.isDisplayed(true)) // check context
{
if (!comp[i].isVisible())
comp[i].setVisible(true); // visibility
if (comp[i] instanceof VEditor)
{
VEditor ve = (VEditor)comp[i];
if (noData)
ve.setReadWrite(false);
else
{
boolean rw = mField.isEditable(true); // r/w - check Context
ve.setReadWrite(rw);
// Log.trace(7, "GridController.dynamicDisplay RW=" + rw, mField);
boolean manMissing = false;
// least expensive operations first // missing mandatory
if (rw && mField.getValue() == null && mField.isMandatory(true)) // check context
manMissing = true;
ve.setBackground(manMissing || mField.isError());
}
}
}
else if (comp[i].isVisible())
comp[i].setVisible(false);
}
}
} // all components
log.config(m_mTab.toString() + " - fini - " + (col==0 ? "complete" : "seletive"));
} // dynamicDisplay
/**
* Row Changed - synchronize with Tree
*
* @param save true the row was saved (changed/added), false if the row was deleted
* @param keyID the ID of the row changed
*/
public void rowChanged (boolean save, int keyID)
{
if (m_tree == null || keyID <= 0)
return;
String name = (String)m_mTab.getValue("Name");
String description = (String)m_mTab.getValue("Description");
Boolean IsSummary = (Boolean)m_mTab.getValue("IsSummary");
String imageIndicator = (String)m_mTab.getValue("Action"); // Menu - Action
//
m_tree.nodeChanged(save, keyID, name, description,
IsSummary.booleanValue(), imageIndicator);
} // rowChanged
/**************************************************************************
* Vetoable Change Listener.
* Called from VEditor
* <pre>
* - for Save Confirmation dialog
* - for Single Row from VEditor: Update MTable
* </pre>
* @param e event
* @throws PropertyVetoException
*/
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
{
if (m_mTab.isProcessed()) // only active records
{
Object source = e.getSource();
if (source instanceof VEditor)
{
if (!((VEditor)source).isReadWrite())
{
log.config("(" + m_mTab.toString() + ") " + e.getPropertyName());
return;
}
}
else
{
log.config("(" + m_mTab.toString() + ") " + e.getPropertyName());
return;
}
}
log.config("(" + m_mTab.toString() + ") "
+ e.getPropertyName() + "=" + e.getNewValue() + " (" + e.getOldValue() + ") "
+ (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));
// Save Confirmation dialog MTable-RowSave
if (e.getPropertyName().equals(MTable.PROPERTY))
{
// throw new PropertyVetoException calls this method (??) again
if (m_vetoActive)
{
m_vetoActive = false;
return;
}
if (!Env.isAutoCommit(Env.getCtx(), m_WindowNo) || m_mTab.getCommitWarning().length() > 0)
{
if (!ADialog.ask(m_WindowNo, this, "SaveChanges?", m_mTab.getCommitWarning()))
{
m_vetoActive = true;
throw new PropertyVetoException ("UserDeniedSave", e);
}
}
return;
} // saveConfirmation
// Get Row/Col Info
MTable mTable = m_mTab.getTableModel();
int row = m_mTab.getCurrentRow();
int col = mTable.findColumn(e.getPropertyName());
//
if (e.getNewValue() == null && e.getOldValue() != null
&& e.getOldValue().toString().length() > 0) // some editors return "" instead of null
mTable.setChanged (true);
else
{
// mTable.setValueAt (e.getNewValue(), row, col, true);
mTable.setValueAt (e.getNewValue(), row, col); // -> dataStatusChanged -> dynamicDisplay
// Force Callout
if (e.getPropertyName().equals("S_ResourceAssignment_ID"))
{
MField mField = m_mTab.getField(col);
if (mField != null && mField.getCallout().length() > 0)
m_mTab.processFieldChange(mField); // Dependencies & Callout
}
}
// log.config( "GridController.vetoableChange (" + m_mTab.toString() + ") - fini", e.getPropertyName() + "=" + e.getNewValue());
} // vetoableChange
/**************************************************************************
* Get Model Tab
* @return Model Tab
*/
public MTab getMTab()
{
return m_mTab;
} // getMTab
/**
* Get VTable
* @return VTable
*/
public VTable getTable()
{
return vTable;
} // getTable
/**
* Set Window level Mnemonics
* @param set true if set otherwise unregiser
*/
public void setMnemonics (boolean set)
{
if (vPanel != null)
vPanel.setMnemonics(set);
} // setMnemonics
/**
* Stop Table & SR Editors and move focus to graphPanel
* @param saveValue save value
*/
public void stopEditor (boolean saveValue)
{
log.config("(" + m_mTab.toString() + ") TableEditing=" + vTable.isEditing());
// MultiRow - remove editors
vTable.stopEditor(saveValue);
// SingleRow - stop editors by changing focus
if (m_singleRow)
vPanel.transferFocus();
// graphPanel.requestFocus();
//
// log.config( "GridController.stopEditor (" + m_mTab.toString() + ") - fini",
// "Editing=" + vTable.isEditing());
} // stopEditors
public void mouseClicked(MouseEvent e)
{
log.finest("" + this + " - " + e);
}
public void mousePressed(MouseEvent e)
{
log.finest("" + this + " - " + e);
}
public void mouseReleased(MouseEvent e)
{
log.finest("" + this + " - " + e);
}
public void mouseEntered(MouseEvent e)
{
log.finest("" + this + " - " + e);
}
public void mouseExited(MouseEvent e)
{
log.finest("" + this + " - " + e);
}
} // GridController
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -