From 171ff34dfd960070921a66f66d3e6e033c8b3092 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 18 Jan 2008 00:37:23 +0000 Subject: [PATCH] [ 1869609 ] Tabs within Collapsed Grid disabled - refactor the synchronization code - make it work for level 2 include, for e.g, include period control tab into the period tab ( calendar window ) - remark old include tab code - remove hard coded prefer size, need to make the include tab more configurable ( later ) --- client/src/org/compiere/apps/APanel.java | 26 ++--- .../src/org/compiere/grid/GridController.java | 102 ++++++++++-------- .../org/compiere/grid/GridSynchronizer.java | 14 ++- client/src/org/compiere/grid/VPanel.java | 55 ++++++++-- 4 files changed, 130 insertions(+), 67 deletions(-) diff --git a/client/src/org/compiere/apps/APanel.java b/client/src/org/compiere/apps/APanel.java index 8f89b745ed..e76806fd92 100644 --- a/client/src/org/compiere/apps/APanel.java +++ b/client/src/org/compiere/apps/APanel.java @@ -183,11 +183,16 @@ public final class APanel extends CPanel // tabPanel mainLayout.setHgap(2); mainLayout.setVgap(2); - CPanel dummy = new CPanel(); - dummy.setLayout(new BorderLayout()); - dummy.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); - dummy.add(tabPanel, BorderLayout.CENTER); - this.add(dummy, BorderLayout.CENTER); + if (isNested) + this.add(m_curGC, BorderLayout.CENTER); + else + { + CPanel dummy = new CPanel(); + dummy.setLayout(new BorderLayout()); + dummy.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); + dummy.add(tabPanel, BorderLayout.CENTER); + this.add(dummy, BorderLayout.CENTER); + } // southPanel this.add(statusBar, BorderLayout.SOUTH); // northPanel @@ -697,13 +702,10 @@ public final class APanel extends CPanel { // FR [ 1757088 ] gc.removeDataStatusListener(this); - //gc.initGrid(gTab, false, m_curWindowNo, this, mWindow, false); // will set color on Tab level - m_mWorkbench.getMWindow(0).initTab(tab); - gc.activate(); - included = parent.includeTab(gc,this); - - if (!included) - log.log(Level.SEVERE, "Not Included = " + gc); + GridSynchronizer synchronizer = new GridSynchronizer(mWindow, parent, gc); + if (parent == m_curGC) + synchronizer.activateChild(); + included = parent.includeTab(gc,this,synchronizer); } } initSwitchLineAction(); diff --git a/client/src/org/compiere/grid/GridController.java b/client/src/org/compiere/grid/GridController.java index 3e15d013b7..78afb75498 100644 --- a/client/src/org/compiere/grid/GridController.java +++ b/client/src/org/compiere/grid/GridController.java @@ -143,7 +143,8 @@ public class GridController extends CPanel private BorderLayout graphLayout = new BorderLayout(); private CPanel cardPanel = new CPanel(); private CardLayout cardLayout = new CardLayout(); - private JSplitPane srPane = new JSplitPane(); + //private JSplitPane srPane = new JSplitPane(); + private JScrollPane vPane = new JScrollPane(); private CScrollPane mrPane = new CScrollPane(); private CPanel xPanel = new CPanel(); @@ -170,17 +171,19 @@ public class GridController extends CPanel splitPane.setName("gc_splitPane"); // cardPanel.setLayout(cardLayout); - cardPanel.add(srPane, "srPane"); // Sequence Important! + cardPanel.add(vPane, "vPane"); // Sequence Important! cardPanel.add(mrPane, "mrPane"); cardPanel.setBorder(null); - cardPanel.setName("gc_cardPanel"); + 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 + */ //FR [ 1757088 ] vPane.getViewport().add(xPanel, null); //FR [ 1757088 ] xPanel.add(vPanel); xPanel.setLayout(xLayout); @@ -196,7 +199,7 @@ public class GridController extends CPanel // graphPanel.setBorder(null); graphPanel.setName("gc_graphPanel"); - srPane.setDividerLocation(200); + //srPane.setDividerLocation(200); vPane.setBorder(BorderFactory.createEmptyBorder()); } // jbInit @@ -247,8 +250,8 @@ public class GridController extends CPanel vTable = null; vPanel.removeAll(); vPanel = null; - srPane.removeAll(); - srPane = null; + //srPane.removeAll(); + //srPane = null; splitPane.removeAll(); splitPane = null; m_mTab = null; @@ -273,6 +276,8 @@ public class GridController extends CPanel private boolean init; + private ArrayList synchronizerList = new ArrayList(); + public boolean initGrid (GridTab mTab, boolean onlyMultiRow, int WindowNo, APanel aPanel, GridWindow mWindow) { @@ -304,7 +309,7 @@ public class GridController extends CPanel m_aPanel = aPanel; setName("GC-" + mTab); //FR [ 1757088 ] - vPanel = new VPanel(mTab.getName()); + vPanel = new VPanel(mTab.getName(), m_WindowNo); vPanel.putClientProperty(AdempiereLookAndFeel.HIDE_IF_ONE_TAB, Boolean.TRUE); vPane.getViewport().add(xPanel, null); xPanel.add(vPanel, BorderLayout.CENTER); @@ -315,8 +320,8 @@ public class GridController extends CPanel init(); else { - if (Ini.isPropertyBool(Ini.P_LOAD_TAB_META_DATA_BG)) - m_mTab.initTab(true); + //Load tab meta data, needed for includeTab to work + m_mTab.initTab(false); } @@ -371,10 +376,11 @@ public class GridController extends CPanel } // 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 @@ -421,52 +427,37 @@ public class GridController extends CPanel init = true; } + + /** + * + * @return boolean + */ + public boolean isInit() + { + return init; + } /** * Include Tab - * @param gc grod controller to add - * @return true if included + * @param gc grid controller to add + * @return GridSynchronizer */ //FR [ 1757088 ] - public boolean includeTab (GridController gc , APanel aPanel) + public boolean includeTab (GridController gc , APanel aPanel, GridSynchronizer sync) { GridController detail = gc; int screenWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth() - 630; // Set screen dimension - detail.setPreferredSize(new Dimension(screenWidth, 250)); - /* - ArrayList parents = detail.getMTab().getParentColumnNames(); - // No Parent - no link - if (parents.size() == 0) - ; - // Standard case - else if (parents.size() == 1) - detail.getMTab().setLinkColumnName((String)parents.get(0)); - detail.getMTab().query(false, 0, 0);*/ - /* - int c = VTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT; - vTable.getInputMap(c).put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), aPanel.aSave.getName()); - vTable.getActionMap().put(aPanel.aSave.getName(), aPanel.aSave);*/ - CollapsiblePanel section = vPanel.getIncludedSection(detail.getMTab().getAD_Tab_ID()); - gc.setDetailGrid(true); - - if(section != null) - { - APanel panel = new APanel(gc, m_WindowNo); - String name = detail.getMTab().getName() + ""; - section.setTitle(name); - panel.add(detail); - section.getCollapsiblePane().getContentPane().setLayout(new BorderLayout()); - section.getCollapsiblePane().getContentPane().add(panel, BorderLayout.CENTER); - } - + //detail.setPreferredSize(new Dimension(screenWidth, 250)); + detail.setDetailGrid(true); detail.addMouseListener(detail); detail.enableEvents(AWTEvent.HIERARCHY_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK); - detail.activate(); - - new GridSynchronizer(this, detail); + vPanel.includeTab(detail); + + synchronizerList.add(sync); return true; + } // IncludeTab //FR [ 1757088 ] @@ -510,7 +501,18 @@ public class GridController extends CPanel // if (mField.getColumnName().equals(tc.getIdentifier().toString())) { - if (mField.getDisplayType () == DisplayType.RowID) + //don't show included tab field in grid + if (mField.getIncluded_Tab_ID() > 0) + { + TableCellNone tcn = new TableCellNone(mField.getColumnName()); + tc.setCellRenderer (tcn); + tc.setCellEditor (tcn); + tc.setHeaderValue (null); + tc.setMinWidth (0); + tc.setMaxWidth (0); + tc.setPreferredWidth (0); + } + else if (mField.getDisplayType () == DisplayType.RowID) { tc.setCellRenderer (new VRowIDRenderer (false)); tc.setCellEditor (new VRowIDEditor (false)); @@ -593,8 +595,20 @@ public class GridController extends CPanel if (m_tree != null) m_tree.initTree (AD_Tree_ID); } + + activateChilds(); } // activate + /** + * activate child grid controller ( included tab ) + */ + private void activateChilds() + { + for (GridSynchronizer s : synchronizerList ) + { + s.activateChild(); + } + } /** * Register ESC Actions diff --git a/client/src/org/compiere/grid/GridSynchronizer.java b/client/src/org/compiere/grid/GridSynchronizer.java index aeedfd8196..c13180359a 100644 --- a/client/src/org/compiere/grid/GridSynchronizer.java +++ b/client/src/org/compiere/grid/GridSynchronizer.java @@ -16,6 +16,7 @@ package org.compiere.grid; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import org.compiere.model.GridWindow; import org.compiere.model.StateChangeEvent; import org.compiere.model.StateChangeListener; import org.compiere.model.GridTab; @@ -30,13 +31,16 @@ public class GridSynchronizer implements PropertyChangeListener, StateChangeList private GridController parent; private GridController child; + private GridWindow window; /** * + * @param window * @param parent * @param child */ - public GridSynchronizer(GridController parent, GridController child) { + public GridSynchronizer(GridWindow window, GridController parent, GridController child) { + this.window = window; this.parent = parent; this.child = child; @@ -70,4 +74,12 @@ public class GridSynchronizer implements PropertyChangeListener, StateChangeList } } + /** + * trigger when parent gc activate + */ + public void activateChild() { + window.initTab(window.getTabIndex(child.getMTab())); + child.activate(); + } + } diff --git a/client/src/org/compiere/grid/VPanel.java b/client/src/org/compiere/grid/VPanel.java index ff06006a75..7cd333ae9d 100644 --- a/client/src/org/compiere/grid/VPanel.java +++ b/client/src/org/compiere/grid/VPanel.java @@ -26,6 +26,7 @@ import java.util.*; import java.util.List; // import org.adempiere.plaf.AdempierePLAF; +import org.compiere.apps.APanel; import org.compiere.grid.ed.*; import org.compiere.model.*; import org.compiere.swing.*; @@ -63,11 +64,22 @@ import org.jdesktop.swingx.border.DropShadowBorder; public final class VPanel extends CTabbedPane { - /** - * Constructor - */ - public VPanel(String Name) + private int m_WindowNo; + + public VPanel(String Name) { + this(Name, 0); + } + + /** + * + * @param Name + * @param WindowNo + */ + public VPanel(String Name, int WindowNo) + { + m_WindowNo = WindowNo; + //set up map used for label and field alignment labels.put(0, new ArrayList()); labels.put(2, new ArrayList()); @@ -196,11 +208,17 @@ public final class VPanel extends CTabbedPane m_gbc.gridy = m_line++; m_gbc.gridwidth = 5; m_gbc.fill = GridBagConstraints.HORIZONTAL; - m_gbc.weightx = 1; + m_gbc.weightx = 1; m_gbc.ipadx = 0; m_main.add(m_tab,m_gbc); + + if (includedTabList.containsKey(AD_Tab_ID)) + { + includeTab(includedTabList.get(AD_Tab_ID)); + } return; } + CLabel label = VEditorFactory.getLabel(mField); if (label == null && editor == null) return; @@ -742,6 +760,8 @@ public final class VPanel extends CTabbedPane private ArrayList m_mnemonics = new ArrayList(30); /** Mnemonic Fields */ private ArrayList m_fields = new ArrayList(30); + + private HashMap includedTabList = new HashMap(); /** * Set Window level Mnemonics @@ -788,11 +808,6 @@ public final class VPanel extends CTabbedPane { } // setBackground - //[ 1757088 ] - public CollapsiblePanel getIncludedSection(int AD_Tab_ID) - { - return (CollapsiblePanel)m_tabincludelist.get(AD_Tab_ID); - } private void findChildComponents(CPanel container, List list) { @@ -971,5 +986,25 @@ public final class VPanel extends CTabbedPane super.doLayout(); } + /** + * + * @param detail + */ + public void includeTab(GridController detail) { + CollapsiblePanel section = (CollapsiblePanel)m_tabincludelist.get(detail.getMTab().getAD_Tab_ID()); + if(section != null) + { + APanel panel = new APanel(detail, m_WindowNo); + String name = detail.getMTab().getName() + ""; + section.setTitle(name); + section.getCollapsiblePane().getContentPane().setLayout(new BorderLayout()); + section.getCollapsiblePane().getContentPane().add(panel, BorderLayout.CENTER); + } + + //this can be call before addField + if (!includedTabList.containsKey(detail.getMTab().getAD_Tab_ID())) + includedTabList.put(detail.getMTab().getAD_Tab_ID(), detail); + } + } // VPanel \ No newline at end of file