Recommit FR[2181150] Dynamic tab display with fix to always display tabs of included panels.
https://sourceforge.net/tracker2/?func=detail&aid=2181150&group_id=176962&atid=879335
This commit is contained in:
parent
29655f4656
commit
36f89eb186
|
@ -1,288 +1,328 @@
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
* under the terms version 2 of the GNU General Public License as published *
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
* by the Free Software Foundation. This program is distributed in the hope *
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
* See the GNU General Public License for more details. *
|
* See the GNU General Public License for more details. *
|
||||||
* You should have received a copy of the GNU General Public License along *
|
* You should have received a copy of the GNU General Public License along *
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||||
* For the text or an alternative of this public license, you may reach us *
|
* For the text or an alternative of this public license, you may reach us *
|
||||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.grid;
|
package org.compiere.grid;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import org.compiere.apps.*;
|
import org.compiere.apps.*;
|
||||||
import org.compiere.model.*;
|
import org.compiere.model.*;
|
||||||
import org.compiere.swing.*;
|
import org.compiere.swing.*;
|
||||||
import org.compiere.util.*;
|
import org.compiere.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tabbed Pane - either Workbench or Window Tab
|
* Tabbed Pane - either Workbench or Window Tab
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: VTabbedPane.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $
|
* @version $Id: VTabbedPane.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $
|
||||||
*/
|
*/
|
||||||
public class VTabbedPane extends CTabbedPane
|
public class VTabbedPane extends CTabbedPane
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param isWorkbench is this a workbench tab (tabs on the left side)
|
* @param isWorkbench is this a workbench tab (tabs on the left side)
|
||||||
*/
|
*/
|
||||||
public VTabbedPane (boolean isWorkbench)
|
public VTabbedPane (boolean isWorkbench)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
setTabLayoutPolicy (JTabbedPane.SCROLL_TAB_LAYOUT);
|
setTabLayoutPolicy (JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||||
setWorkbench (isWorkbench);
|
setWorkbench (isWorkbench);
|
||||||
setFocusable(false);
|
setFocusable(false);
|
||||||
} // VTabbedPane
|
} // VTabbedPane
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger log = CLogger.getCLogger (VTabbedPane.class);
|
private static CLogger log = CLogger.getCLogger (VTabbedPane.class);
|
||||||
/** Workbench */
|
/** Workbench */
|
||||||
private boolean m_workbenchTab = false;
|
private boolean m_workbenchTab = false;
|
||||||
/** List of dependent Variables */
|
/** List of dependent Variables */
|
||||||
private ArrayList<String> m_dependents = new ArrayList<String>();
|
private ArrayList<String> m_dependents = new ArrayList<String>();
|
||||||
/** Disabled Icon */
|
/** Disabled Icon */
|
||||||
private static Icon s_disabledIcon = null;
|
private static Icon s_disabledIcon = null;
|
||||||
|
|
||||||
/**
|
private ArrayList<Component> components = new ArrayList<Component>();
|
||||||
* toString
|
private ArrayList<GridTab> gTabs = new ArrayList<GridTab>();
|
||||||
* @return info
|
private ArrayList<String> tabNames = new ArrayList<String>();
|
||||||
*/
|
|
||||||
public String toString()
|
/**
|
||||||
{
|
* toString
|
||||||
return (m_workbenchTab ? "WorkbenchTab" : "WindowTab")
|
* @return info
|
||||||
+ " - selected " + getSelectedIndex() + " of " + getTabCount();
|
*/
|
||||||
} // toString
|
public String toString()
|
||||||
|
{
|
||||||
/**
|
return (m_workbenchTab ? "WorkbenchTab" : "WindowTab")
|
||||||
* Add Tab
|
+ " - selected " + getSelectedIndex() + " of " + getTabCount();
|
||||||
* @param tabName name
|
} // toString
|
||||||
* @param gTab grid tab model
|
|
||||||
* @param tabElement GridController or VSortTab
|
/**
|
||||||
*/
|
* Add Tab
|
||||||
public void addTab(String tabName, GridTab gTab, Component tabElement)
|
* @param tabName name
|
||||||
{
|
* @param gTab grid tab model
|
||||||
int index = getTabCount();
|
* @param tabElement GridController or VSortTab
|
||||||
super.addTab (tabName, gTab.getIcon(),
|
*/
|
||||||
tabElement, gTab.getDescription());
|
public void addTab(String tabName, GridTab gTab, Component tabElement)
|
||||||
ArrayList<String> dependents = gTab.getDependentOn();
|
{
|
||||||
for (int i = 0; i < dependents.size(); i++)
|
int index = getTabCount();
|
||||||
{
|
tabNames.add(tabName);
|
||||||
String name = dependents.get(i);
|
gTabs.add(gTab);
|
||||||
if (!m_dependents.contains(name))
|
components.add(tabElement);
|
||||||
m_dependents.add(name);
|
|
||||||
}
|
super.addTab (tabName, gTab.getIcon(),
|
||||||
if (s_disabledIcon == null)
|
tabElement, gTab.getDescription());
|
||||||
s_disabledIcon = Env.getImageIcon("Cancel10.gif");
|
|
||||||
setDisabledIconAt(index, s_disabledIcon);
|
ArrayList<String> dependents = gTab.getDependentOn();
|
||||||
} // addTab
|
for (int i = 0; i < dependents.size(); i++)
|
||||||
|
{
|
||||||
|
String name = dependents.get(i);
|
||||||
/**
|
if (!m_dependents.contains(name))
|
||||||
* Set Workbench - or Window
|
m_dependents.add(name);
|
||||||
* @param isWorkbench
|
}
|
||||||
*/
|
if (s_disabledIcon == null)
|
||||||
public void setWorkbench (boolean isWorkbench)
|
s_disabledIcon = Env.getImageIcon("Cancel10.gif");
|
||||||
{
|
setDisabledIconAt(index, s_disabledIcon);
|
||||||
m_workbenchTab = isWorkbench;
|
} // addTab
|
||||||
if (m_workbenchTab)
|
|
||||||
super.setTabPlacement(JTabbedPane.BOTTOM);
|
private void hideTab(String tabName) {
|
||||||
else
|
|
||||||
super.setTabPlacement(Language.getLoginLanguage().isLeftToRight()
|
int tabIndex = indexOfTab(tabName);
|
||||||
? JTabbedPane.LEFT : JTabbedPane.RIGHT);
|
|
||||||
} // setWorkbench
|
if ( tabIndex != -1 )
|
||||||
|
removeTabAt(tabIndex);
|
||||||
/**
|
}
|
||||||
* Tab is Workbench (not Window)
|
|
||||||
* @return true if Workbench
|
private void showTab(String tabName) {
|
||||||
*/
|
int insertAt = 0;
|
||||||
public boolean isWorkbench()
|
|
||||||
{
|
if ( indexOfTab(tabName) != -1 ) // already visible
|
||||||
return m_workbenchTab;
|
return;
|
||||||
} // toString
|
|
||||||
|
for ( int i = 0; i < tabNames.size(); i++ )
|
||||||
/**
|
{
|
||||||
* Set Tab Placement.
|
String name = tabNames.get(i);
|
||||||
* Do not use - set via setWorkBench
|
if ( name.equals(tabName))
|
||||||
* @param notUsed
|
{
|
||||||
*/
|
insertTab (tabName, gTabs.get(i).getIcon(),
|
||||||
public void setTabPlacement (int notUsed)
|
components.get(i), gTabs.get(i).getDescription(), insertAt);
|
||||||
{
|
break;
|
||||||
new java.lang.IllegalAccessError("Do not use VTabbedPane.setTabPlacement directly");
|
}
|
||||||
} // setTabPlacement
|
|
||||||
|
if ( indexOfTab(name) != -1 ) // tab is visible, insert after
|
||||||
/**
|
insertAt ++;
|
||||||
* Dispose all contained VTabbedPanes and GridControllers
|
}
|
||||||
* @param aPanel
|
|
||||||
*/
|
}
|
||||||
public void dispose (APanel aPanel)
|
/**
|
||||||
{
|
* Set Workbench - or Window
|
||||||
Component[] comp = getComponents();
|
* @param isWorkbench
|
||||||
for (int i = 0; i < comp.length; i++)
|
*/
|
||||||
{
|
public void setWorkbench (boolean isWorkbench)
|
||||||
if (comp[i] instanceof VTabbedPane)
|
{
|
||||||
{
|
m_workbenchTab = isWorkbench;
|
||||||
VTabbedPane tp = (VTabbedPane)comp[i];
|
if (m_workbenchTab)
|
||||||
tp.removeChangeListener(aPanel);
|
super.setTabPlacement(JTabbedPane.BOTTOM);
|
||||||
tp.dispose(aPanel);
|
else
|
||||||
}
|
super.setTabPlacement(Language.getLoginLanguage().isLeftToRight()
|
||||||
else if (comp[i] instanceof GridController)
|
? JTabbedPane.LEFT : JTabbedPane.RIGHT);
|
||||||
{
|
} // setWorkbench
|
||||||
GridController gc = (GridController)comp[i];
|
|
||||||
gc.removeDataStatusListener(aPanel);
|
/**
|
||||||
gc.dispose();
|
* Tab is Workbench (not Window)
|
||||||
}
|
* @return true if Workbench
|
||||||
}
|
*/
|
||||||
removeAll();
|
public boolean isWorkbench()
|
||||||
} // dispose
|
{
|
||||||
|
return m_workbenchTab;
|
||||||
@Override
|
} // toString
|
||||||
//hengsin, bug [ 1637763 ]
|
|
||||||
public boolean isEnabledAt(int index) {
|
/**
|
||||||
boolean enabled = super.isEnabledAt(index);
|
* Set Tab Placement.
|
||||||
if (!enabled) return enabled;
|
* Do not use - set via setWorkBench
|
||||||
Component comp = getComponentAt(index);
|
* @param notUsed
|
||||||
GridController gc = null;
|
*/
|
||||||
if (comp instanceof GridController)
|
public void setTabPlacement (int notUsed)
|
||||||
gc = (GridController)comp;
|
{
|
||||||
// Display
|
new java.lang.IllegalAccessError("Do not use VTabbedPane.setTabPlacement directly");
|
||||||
if (gc != null)
|
} // setTabPlacement
|
||||||
{
|
|
||||||
enabled = isDisplay(gc);
|
/**
|
||||||
}
|
* Dispose all contained VTabbedPanes and GridControllers
|
||||||
return enabled;
|
* @param aPanel
|
||||||
}
|
*/
|
||||||
|
public void dispose (APanel aPanel)
|
||||||
//hengsin, bug [ 1637763 ]
|
{
|
||||||
private boolean isDisplay(GridController gc)
|
Component[] comp = getComponents();
|
||||||
{
|
for (int i = 0; i < comp.length; i++)
|
||||||
String logic = gc.getDisplayLogic();
|
{
|
||||||
if (logic != null && logic.length() > 0)
|
if (comp[i] instanceof VTabbedPane)
|
||||||
{
|
{
|
||||||
boolean display = Evaluator.evaluateLogic(gc, logic);
|
VTabbedPane tp = (VTabbedPane)comp[i];
|
||||||
if (!display)
|
tp.removeChangeListener(aPanel);
|
||||||
{
|
tp.dispose(aPanel);
|
||||||
log.info("Not displayed - " + logic);
|
}
|
||||||
return false;
|
else if (comp[i] instanceof GridController)
|
||||||
}
|
{
|
||||||
}
|
GridController gc = (GridController)comp[i];
|
||||||
return true;
|
gc.removeDataStatusListener(aPanel);
|
||||||
}
|
gc.dispose();
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Set Selected Index.
|
removeAll();
|
||||||
* Register/Unregister Mnemonics
|
} // dispose
|
||||||
* @param index index
|
|
||||||
*/
|
@Override
|
||||||
public void setSelectedIndex (int index)
|
//hengsin, bug [ 1637763 ]
|
||||||
{
|
public boolean isEnabledAt(int index) {
|
||||||
Component newC = getComponentAt(index);
|
boolean enabled = super.isEnabledAt(index);
|
||||||
GridController newGC = null;
|
if (!enabled) return enabled;
|
||||||
if (newC instanceof GridController)
|
Component comp = getComponentAt(index);
|
||||||
newGC = (GridController)newC;
|
GridController gc = null;
|
||||||
// Display
|
if (comp instanceof GridController)
|
||||||
if (newGC != null)
|
gc = (GridController)comp;
|
||||||
{
|
// Display
|
||||||
//hengsin, bug [ 1637763 ]
|
if (gc != null)
|
||||||
if(isDisplay(newGC) == false)
|
{
|
||||||
return;
|
enabled = isDisplay(gc);
|
||||||
}
|
}
|
||||||
|
return enabled;
|
||||||
//
|
}
|
||||||
int oldIndex = getSelectedIndex();
|
|
||||||
if (newGC != null && oldIndex >= 0 && index != oldIndex)
|
//hengsin, bug [ 1637763 ]
|
||||||
{
|
private boolean isDisplay(GridController gc)
|
||||||
Component oldC = getComponentAt(oldIndex);
|
{
|
||||||
if (oldC != null && oldC instanceof GridController)
|
String logic = gc.getDisplayLogic();
|
||||||
{
|
if (logic != null && logic.length() > 0)
|
||||||
GridController oldGC = (GridController)oldC;
|
{
|
||||||
if (newGC.getTabLevel() > oldGC.getTabLevel()+1)
|
boolean display = Evaluator.evaluateLogic(gc, logic);
|
||||||
{
|
if (!display)
|
||||||
// validate
|
{
|
||||||
// Search for right tab
|
log.info("Not displayed - " + logic);
|
||||||
GridController rightGC = null;
|
return false;
|
||||||
boolean canJump = true;
|
}
|
||||||
int currentLevel = newGC.getTabLevel();
|
}
|
||||||
for (int i = index-1; i >=0; i--)
|
return true;
|
||||||
{
|
}
|
||||||
Component rightC = getComponentAt(i);
|
|
||||||
if (rightC instanceof GridController)
|
/**
|
||||||
{
|
* Set Selected Index.
|
||||||
GridController gc = (GridController)rightC;
|
* Register/Unregister Mnemonics
|
||||||
//can only skip level if all parent data are not stale
|
* @param index index
|
||||||
if (gc.getTabLevel() < currentLevel)
|
*/
|
||||||
{
|
public void setSelectedIndex (int index)
|
||||||
if (gc.getTabLevel() == oldGC.getTabLevel()+1)
|
{
|
||||||
{
|
Component newC = getComponentAt(index);
|
||||||
rightGC = gc;
|
GridController newGC = null;
|
||||||
}
|
if (newC instanceof GridController)
|
||||||
if (!gc.isCurrent())
|
newGC = (GridController)newC;
|
||||||
canJump = false;
|
// Display
|
||||||
currentLevel = gc.getTabLevel();
|
if (newGC != null)
|
||||||
}
|
{
|
||||||
}
|
//hengsin, bug [ 1637763 ]
|
||||||
}
|
if(isDisplay(newGC) == false)
|
||||||
if (canJump == false)
|
return;
|
||||||
{
|
}
|
||||||
if (rightGC != null )
|
|
||||||
ADialog.warn(0, this, "TabSwitchJumpGo", rightGC.getTitle());
|
//
|
||||||
else
|
int oldIndex = getSelectedIndex();
|
||||||
ADialog.warn(0, this, "TabSwitchJump");
|
if (newGC != null && oldIndex >= 0 && index != oldIndex)
|
||||||
return;
|
{
|
||||||
}
|
Component oldC = getComponentAt(oldIndex);
|
||||||
}
|
if (oldC != null && oldC instanceof GridController)
|
||||||
oldGC.setMnemonics(false);
|
{
|
||||||
}
|
GridController oldGC = (GridController)oldC;
|
||||||
}
|
if (newGC.getTabLevel() > oldGC.getTabLevel()+1)
|
||||||
// Switch
|
{
|
||||||
super.setSelectedIndex (index);
|
// validate
|
||||||
if (newGC != null)
|
// Search for right tab
|
||||||
newGC.setMnemonics(true);
|
GridController rightGC = null;
|
||||||
} // setSelectedIndex
|
boolean canJump = true;
|
||||||
|
int currentLevel = newGC.getTabLevel();
|
||||||
/**
|
for (int i = index-1; i >=0; i--)
|
||||||
* Evaluate Tab Logic
|
{
|
||||||
* @param e event
|
Component rightC = getComponentAt(i);
|
||||||
*/
|
if (rightC instanceof GridController)
|
||||||
public void evaluate (DataStatusEvent e)
|
{
|
||||||
{
|
GridController gc = (GridController)rightC;
|
||||||
boolean process = e == null;
|
//can only skip level if all parent data are not stale
|
||||||
String columnName = null;
|
if (gc.getTabLevel() < currentLevel)
|
||||||
if (!process)
|
{
|
||||||
{
|
if (gc.getTabLevel() == oldGC.getTabLevel()+1)
|
||||||
columnName = e.getColumnName();
|
{
|
||||||
if (columnName != null)
|
rightGC = gc;
|
||||||
process = m_dependents.contains(columnName);
|
}
|
||||||
else
|
if (!gc.isCurrent())
|
||||||
process = true;
|
canJump = false;
|
||||||
}
|
currentLevel = gc.getTabLevel();
|
||||||
|
}
|
||||||
if (process)
|
}
|
||||||
{
|
}
|
||||||
log.config(columnName == null ? "" : columnName);
|
if (canJump == false)
|
||||||
for (int i = 0; i < getTabCount(); i++)
|
{
|
||||||
{
|
if (rightGC != null )
|
||||||
Component c = getComponentAt(i);
|
ADialog.warn(0, this, "TabSwitchJumpGo", rightGC.getTitle());
|
||||||
if (c instanceof GridController)
|
else
|
||||||
{
|
ADialog.warn(0, this, "TabSwitchJump");
|
||||||
GridController gc = (GridController)c;
|
return;
|
||||||
String logic = gc.getDisplayLogic();
|
}
|
||||||
boolean display = true;
|
}
|
||||||
if (logic != null && logic.length() > 0)
|
oldGC.setMnemonics(false);
|
||||||
display = Evaluator.evaluateLogic(gc, logic);
|
}
|
||||||
setEnabledAt(i, display);
|
}
|
||||||
}
|
// Switch
|
||||||
}
|
super.setSelectedIndex (index);
|
||||||
}
|
if (newGC != null)
|
||||||
} // evaluate
|
newGC.setMnemonics(true);
|
||||||
|
} // setSelectedIndex
|
||||||
} // VTabbdPane
|
|
||||||
|
/**
|
||||||
|
* Evaluate Tab Logic
|
||||||
|
* @param e event
|
||||||
|
*/
|
||||||
|
public void evaluate (DataStatusEvent e)
|
||||||
|
{
|
||||||
|
boolean process = e == null;
|
||||||
|
String columnName = null;
|
||||||
|
if (!process)
|
||||||
|
{
|
||||||
|
columnName = e.getColumnName();
|
||||||
|
if (columnName != null)
|
||||||
|
process = m_dependents.contains(columnName);
|
||||||
|
else
|
||||||
|
process = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process)
|
||||||
|
{
|
||||||
|
log.config(columnName == null ? "" : columnName);
|
||||||
|
for (int i = 0; i < components.size(); i++)
|
||||||
|
{
|
||||||
|
Component c = components.get(i);
|
||||||
|
if (c instanceof GridController)
|
||||||
|
{
|
||||||
|
GridController gc = (GridController)c;
|
||||||
|
if (!gc.isDetailGrid()) //ignore included tabs
|
||||||
|
{
|
||||||
|
boolean display = isDisplay(gc);
|
||||||
|
if ( display )
|
||||||
|
showTab(tabNames.get(i));
|
||||||
|
else
|
||||||
|
hideTab(tabNames.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // evaluate
|
||||||
|
|
||||||
|
} // VTabbdPane
|
||||||
|
|
Loading…
Reference in New Issue