📄 gridcontroller.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.grid;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import org.compiere.apps.*;
import org.compiere.grid.ed.*;
import org.compiere.grid.tree.*;
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* The Grid Controller is the panel for single and multi-row presentation
* and links to the Model Tab.
*
* <pre>
* UI Structure:
* this (BorderLayout)
* splitPane (JSplitPane)
* left
* graphicPanel
* right
* cardPanel JPanel (CardLayout)
* srPane JSplitPane
* vPane JScrollPane
* vPanel VPanel (GridBagLayout)
* vIncludedGC GridController
* mrPane JScrollPane
* vTable VTable
*
* <B>DataBinding:<B>
* - MultiRow - is automatic between VTable and MTable
* - SingleRow
* - from VEditors via fireVetoableChange(m_columnName, null, getText());
* (vetoableChange)
* - to VEditors via updateSingleRow -> Editor.setValue(object)
*
* Event Chains
* -- Navigation --
* (VTable selection -> GridController.valueChanged)
* (APanel selection)
* + MTab.navivate
* + MTab.setCurrentRow
* + Update all MFields
* + MField.setValue
* + setContext
* + fire PropertyChange "Value"
* + VEditor.propertyChange
* + VEditor.setValue
* + MTab.fireProperyChange "CurrentRow"
* + VTable.propertyChange (setRowSelectionInterval)
* + GridController.valueChange
* + GridController.dynamicDisplay(complete)
* + MTab.fireDataStatusChanged
* + APanel.statusChanged
*
* -- ValueChanges --
* VEditor.fireVetoableChange
* + (VCellEditor.vetoableChange/getCellEditorValue) -- multi-row source
* + (GridController.vetoableChange) -- single-row source
* + MTable.setValueAt
* + MField.setValue
* + setContext
* + fire PropertyChange "Value"
* + VEditor.setValue
* + MTable.fireDataStatusChanged
* + MTab.dataStatusChanged
* + MTab.fireDataStatusChanged
* + APanel.statusChanged
* + GridController.dataStatusChanged
* + GridController.dynamicDisplay(selective)
* </pre>
* @author Jorg Janke
* @version $Id: GridController.java,v 1.72 2006/01/28 01:29:12 jjanke Exp $
*/
public class GridController extends CPanel
implements DataStatusListener, ListSelectionListener,
VetoableChangeListener, PropertyChangeListener, MouseListener
{
/**
* Constructor - you need to call initGrid for instanciation
*/
public GridController()
{
try
{
jbInit();
}
catch(Exception e)
{
log.log(Level.SEVERE, "", e);
}
} // GridController
/**
* toString
* @return string representation
*/
public String toString()
{
return "GridController for " + m_mTab;
} // toString
/** Logger */
private static CLogger log = CLogger.getCLogger(GridController.class);
/**
* The Layout
*/
private BorderLayout mainLayout = new BorderLayout();
private JSplitPane splitPane = new JSplitPane();
private CPanel graphPanel = new CPanel();
private BorderLayout graphLayout = new BorderLayout();
private CPanel cardPanel = new CPanel();
private CardLayout cardLayout = new CardLayout();
private JSplitPane srPane = new JSplitPane();
private JScrollPane vPane = new JScrollPane();
private GridController vIncludedGC = null;
private CScrollPane mrPane = new CScrollPane();
private CPanel xPanel = new CPanel();
private FlowLayout xLayout = new FlowLayout();
private VTable vTable = new VTable();
private VPanel vPanel = new VPanel();
/**
* Static Layout init
* @throws Exception
*/
private void jbInit() throws Exception
{
this.setLayout(mainLayout);
this.add(splitPane, BorderLayout.CENTER);
splitPane.setOpaque(false);
graphPanel.setLayout(graphLayout);
//
splitPane.add(graphPanel, JSplitPane.LEFT);
splitPane.add(cardPanel, JSplitPane.RIGHT);
splitPane.setBorder(null);
splitPane.setName("gc_splitPane");
//
cardPanel.setLayout(cardLayout);
cardPanel.add(srPane, "srPane"); // Sequence Important!
cardPanel.add(mrPane, "mrPane");
cardPanel.setBorder(null);
cardPanel.setName("gc_cardPanel");
// single row (w/o xPane it would be centered)
srPane.setBorder(null);
srPane.setName("gc_srPane");
srPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
srPane.add(vPane, JSplitPane.TOP);
srPane.setTopComponent(vPane);
srPane.setBottomComponent(null); // otherwise a button is created/displayed
//
vPane.getViewport().add(xPanel, null);
xPanel.add(vPanel);
vPane.setBorder(null);
xPanel.setLayout(xLayout);
xPanel.setName("gc_xPanel");
xLayout.setAlignment(FlowLayout.LEFT);
xLayout.setHgap(0);
xLayout.setVgap(0);
// multi-row
mrPane.setBorder(null);
mrPane.getViewport().add(vTable, null);
mrPane.setName("gc_mrPane");
//
graphPanel.setBorder(null);
graphPanel.setName("gc_graphPanel");
srPane.setDividerLocation(200);
} // jbInit
/**
* Displose
*/
public void dispose()
{
log.config( "(" + m_mTab.toString() + ")");
// clear info
stopEditor(false);
if (m_mTab.needSave(true, false))
m_mTab.dataIgnore();
vIncludedGC = null;
// Listeners
m_mTab.getTableModel().removeDataStatusListener(this);
m_mTab.getTableModel().removeVetoableChangeListener(this);
vTable.getSelectionModel().removeListSelectionListener(this);
m_mTab.removePropertyChangeListener(vTable);
// editors
Component[] comp = vPanel.getComponents();
for (int i = 0; i < comp.length; i++)
{
if (comp[i] instanceof VEditor)
{
VEditor vEditor = (VEditor)comp[i];
vEditor.removeVetoableChangeListener(this);
String columnName = comp[i].getName();
MField mField = m_mTab.getField(columnName);
if (mField != null)
mField.removePropertyChangeListener(vEditor);
vEditor.dispose();
}
}
/** @todo Remove APanel Button listeners */
vTable.removeAll();
vTable.setModel(new DefaultTableModel()); // remove reference
vTable = null;
vPanel.removeAll();
vPanel = null;
srPane.removeAll();
srPane = null;
splitPane.removeAll();
splitPane = null;
m_mTab = null;
m_tree = null;
this.removeAll();
} // dispose
/** Model Tab */
private MTab m_mTab = null;
/** Window */
private int m_WindowNo;
/** Only Multi-Row exist */
private boolean m_onlyMultiRow = false;
/** Single/Multi Row indicator */
private boolean m_singleRow = true;
/** Veto Active */
private boolean m_vetoActive = false;
/** Tree Panel (optional) */
private VTreePanel m_tree;
/**************************************************************************
* Init Grid.
* <pre>
* - Map table to model
* - Update (multi-row) table info with renderers/editors
* - build single-row panel
* - initialize display
* </pre>
* @param mTab tab
* @param onlyMultiRow only table
* @param WindowNo window no
* @param aPanel optional Application Panel for adding button listeners
* @param mWindow parent Window Model
* @return true if initialized
*/
public boolean initGrid (MTab mTab, boolean onlyMultiRow,
int WindowNo, APanel aPanel, MWindow mWindow)
{
log.config( "(" + mTab.toString() + ")");
m_mTab = mTab;
m_WindowNo = WindowNo;
m_onlyMultiRow = onlyMultiRow;
setName("GC-" + mTab);
// Set up Multi Row Table
vTable.setModel(m_mTab.getTableModel());
// Update Table Info -------------------------------------------------
int size = setupVTable (aPanel, m_mTab, vTable);
// Set Color on Tab Level
// this.setBackgroundColor (mTab.getColor());
// Single Row -------------------------------------------------------
if (!m_onlyMultiRow)
{
for (int i = 0; i < size; i++)
{
MField mField = m_mTab.getField(i);
if (mField.isDisplayed())
{
VEditor vEditor = VEditorFactory.getEditor(m_mTab, mField, false);
if (vEditor == null)
{
log.severe("Editor not created for " + mField.getColumnName());
continue;
}
// MField => VEditor - New Field value to be updated to editor
mField.addPropertyChangeListener(vEditor);
// VEditor => this - New Editor value to be updated here (MTable)
vEditor.addVetoableChangeListener(this);
// Add to VPanel
vPanel.addField(vEditor, mField);
// APanel Listen to buttons
if (mField.getDisplayType() == DisplayType.Button && aPanel != null)
((JButton)vEditor).addActionListener (aPanel);
}
} // for all fields
// No Included Grid Controller
srPane.setResizeWeight(1); // top part gets all
srPane.setDividerSize (0);
srPane.setDividerLocation (9999);
// Use SR to size MR
mrPane.setPreferredSize(vPanel.getPreferredSize());
} // Single-Row
// Tree Graphics Layout
int AD_Tree_ID = 0;
if (m_mTab.isTreeTab())
AD_Tree_ID = MTree.getDefaultAD_Tree_ID (
Env.getAD_Client_ID(Env.getCtx()), m_mTab.getKeyColumnName());
if (m_mTab.isTreeTab() && AD_Tree_ID != 0)
{
m_tree = new VTreePanel(m_WindowNo, false, true);
if (m_mTab.getTabNo() == 0) // initialize other tabs later
m_tree.initTree(AD_Tree_ID);
m_tree.addPropertyChangeListener(VTreePanel.NODE_SELECTION, this);
graphPanel.add(m_tree, BorderLayout.CENTER);
splitPane.setDividerLocation(250);
// splitPane.resetToPreferredSizes();
}
else // No Graphics - hide
{
graphPanel.setPreferredSize(new Dimension(0,0));
splitPane.setDividerSize(0);
splitPane.setDividerLocation(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -