⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridcontroller.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}   //  registerESCAction

	/**
	 *  Query Tab and resize Table
	 *  (called from APanel)
	 *  @param onlyCurrentRows only current rows
	 *  @param onlyCurrentDays how many days back
	 */
	public void query (boolean onlyCurrentRows, int onlyCurrentDays)
	{
		//  start loading while building screen
		m_mTab.query(onlyCurrentRows, onlyCurrentDays);
		//  Update UI
		vTable.autoSize();
	}   //  query

	/*************************************************************************/

	/**
	 *  Switch from single to multi & vice versa
	 */
	public void switchRowPresentation()
	{
		stopEditor(true);
		if (m_singleRow)
			switchMultiRow();
		else
			switchSingleRow();
	}   //  switchRowPresentation

	/**
	 *  Switch to SingleRow Presentation
	 */
	public void switchSingleRow()
	{
		if (m_onlyMultiRow)
			return;
		cardLayout.first(cardPanel);
		m_singleRow = true;
		dynamicDisplay(0);
	}   //  switchSingleRow

	/**
	 *  Switch to MultiRow Presentation
	 */
	public void switchMultiRow()
	{
		cardLayout.last(cardPanel);
		m_singleRow = false;
	}   //  switchSingleRow

	/**
	 *  Is Single Row presentation
	 *  @return true if Single Row is displayed
	 */
	public boolean isSingleRow()
	{
		return m_singleRow;
	}   //  isSingleRow

	/*************************************************************************/

	/**
	 *  Remove Listener - pass on to MTab
	 *  @param l listener
	 */
	public synchronized void removeDataStatusListener(DataStatusListener l)
	{
		m_mTab.removeDataStatusListener(l);
	}   //  removeDataStatusListener

	/**
	 *  Add Data Status Listener - pass on to MTab
	 *  @param l listener
	 */
	public synchronized void addDataStatusListener(DataStatusListener l)
	{
		m_mTab.addDataStatusListener(l);
	}

	/**
	 *  Data Status Listener - for MTab events.
	 *  <p>
	 *  Callouts are processed here for GUI changes
	 *  - same as in MTab.setValue for batch changes
	 *  <p>
	 *  call dynamicDisplay
	 *  @param e event
	 */
	public void dataStatusChanged(DataStatusEvent e)
	{
	//	if (e.getChangedColumn() == 0)
	//		return;
		if (m_mTab == null)
			return;
		Log.trace(Log.l2_Sub, "GridController.dataStatusChanged (" + m_mTab.toString() + ")", e.toString());
		int col = e.getChangedColumn();

		//  Process Callout only for specific columns
		if (col != 0)
		{
			MField mField = m_mTab.getField(col);
			if (mField != null && mField.getCallout().length() > 0)
			{
				String msg = m_mTab.processFieldChange(mField);     //  Dependencies & Callout
				if (msg.length() > 0)
					ADialog.error(m_WindowNo, this, msg);
			}
		}
		dynamicDisplay(col);
	}   //  dataStatusChanged

	/*************************************************************************/

	/**
	 *  List Selection Listener (VTable) - row changed
	 *  @param e event
	 */
	public void valueChanged(ListSelectionEvent e)
	{
		//	nothing or initiated by mouse (wait for "real" one)
		if (e.getValueIsAdjusting())
			return;
		//  no rows
		if (m_mTab.getRowCount() == 0)
			return;

	//	vTable.stopEditor(graphPanel);
		int rowTable = vTable.getSelectedRow();
		int rowCurrent = m_mTab.getCurrentRow();
		Log.trace(Log.l2_Sub, "GridController.valueChanged (" + m_mTab.toString() + ")",
			"Row in Table=" + rowTable + ", in Model=" + rowCurrent);

		if (rowTable == -1)  //  nothing selected
		{
			if (rowCurrent >= 0)
			{
				vTable.setRowSelectionInterval(rowCurrent, rowCurrent); //  causes this method to be called again
				return;
			}
		}
		else
		{
			if (rowTable != rowCurrent)
				m_mTab.navigate(rowTable);
			dynamicDisplay(0);
		}

		//	TreeNavigation - Synchronize 	-- select node in tree
		if (m_tree != null)
			m_tree.setSelectedNode (m_mTab.getCurrentKeyID());	//	ignores new (-1)

	//	Log.trace(Log.l2_Sub, "GridController.valueChanged (" + m_mTab.toString() + ") - fini",
	//		"Row in Table=" + rowTable + ", in Model=" + rowCurrent);
	}   //  valueChanged

	/**
	 *  PropertyChange Listener - Tree Panel - node selection
	 *  @param e event
	 */
	public void propertyChange(PropertyChangeEvent e)
	{
		if (e == null)
			return;
		Object value = e.getNewValue();
		if (value == null)
			return;
		Log.trace(Log.l2_Sub, "GridController.propertyChange",
			e.getPropertyName() + "=" + value
			+ " - " + value.getClass().toString());
		if (!(value instanceof MTreeNode))
			return;

		//  We Have a TreeNode
		int nodeID = ((MTreeNode)value).getID();
		//  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.error("GridController.propertyChange - 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)
	{
		if (!isSingleRow() || m_onlyMultiRow)
			return;
		//  Selective
/*		if (col != 0)
		{
			Log.trace(Log.l3_Util, "GridController.dynamicDisplay (" + m_mTab.toString() + ") - seletive");
			MField changedField = m_mTab.getField(col);
			String columnName = changedField.getColumnName();
			return
		}   //  selective
*/
		//  complete single row re-display
		Log.trace(Log.l3_Util, "GridController.dynamicDisplay (" + m_mTab.toString() + ")");
		//  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];
							boolean rw = mField.isEditable(true);       //  r/w - check Context
							ve.setReadWrite(rw);
							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());
							//
						//	Log.trace(Log.l5_DData, "GridController.dynamicDisplay RW=" + rw, mField);
						}
					}
					else if (comp[i].isVisible())
						comp[i].setVisible(false);
				}
			}
		}   //  all components
	//	Log.trace(Log.l3_Util, "GridController.dynamicDisplay (" + 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)
			return;
		String name = (String)m_mTab.getValue("Name");
		String description = (String)m_mTab.getValue("Description");
		String sum = (String)m_mTab.getValue("IsSummary");
		boolean isSummary = (sum == null ? false : sum.equals("Y"));
		String imageIndicator = (String)m_mTab.getValue("Action");  //  Menu - Action
		//
		m_tree.nodeChanged(save, keyID, name, description, isSummary, imageIndicator);
	}   //  rowChanged


	/*************************************************************************/

	/**
	 *  Vetoable Change Listener.
	 *  <pre>
	 *  - for Single Row from VEditor: Update MTable
	 *  - for Save Confirmation dialog
	 *  </pre>
	 *  @param e event
	 *  @throws PropertyVetoException
	 */
	public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
	{
		Log.trace(Log.l2_Sub, "GridController.vetoableChange (" + m_mTab.toString() + ")",
			e.getPropertyName() + "=" + e.getNewValue());

		//  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.getOldValue() != null)
		{
			mTable.setChanged (true);
			if (e.getNewValue() != null)
				mTable.setValueAt (e.getNewValue(), row, col, true);
		}
		else
			mTable.setValueAt (e.getNewValue(), row, col);

		Log.trace(Log.l2_Sub, "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 Table Column
	 *  (Find uses it to overwrite Editor/Renderer)
	 *  @param index index of column
	 *  @return table column
	 */
	protected TableColumn getTableColumn (int index)
	{
	//	Log.trace(Log.l5_DData, "GridController.getTableColumn", "index=" + index);
		TableColumnModel tcm = vTable.getColumnModel();
		if (index >= 0 && index < tcm.getColumnCount())
			return tcm.getColumn(index);
		Log.error("GridController.getTableColumn - No TableColumn for index=" + index);
		return null;
	}   //  getTableColumn

	/**
	 *  Get VTable
	 *  @return VTable
	 */
	public VTable getTable()
	{
		return vTable;
	}   //  getTable

	/**
	 *  Stop Table & SR Editors and move focus to graphPanel
	 *  @param saveValue save value
	 */
	public void stopEditor (boolean saveValue)
	{
		Log.trace(Log.l2_Sub, "GridController.stopEditor (" + 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.trace(Log.l2_Sub, "GridController.stopEditor (" + m_mTab.toString() + ") - fini",
	//		"Editing=" + vTable.isEditing());
	}   //  stopEditors

}   //  GridController

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -