use of org.compiere.grid.APanelTab in project adempiere by adempiere.
the class APanel method stateChanged.
// set Busy
/**************************************************************************
* Change Listener - (tab change) <->
* @param e event
*/
public void stateChanged(ChangeEvent e) {
//Run LostFocus Event when change tab
if (m_curWinTab != null) {
Component cp = m_window.getFocusOwner();
if (cp != null) {
m_window.dispatchEvent(new FocusEvent(cp, FocusEvent.FOCUS_LOST));
}
}
if (m_disposing)
return;
log.info(e.toString());
setBusy(true, true);
VTabbedPane tp = (VTabbedPane) e.getSource();
boolean back = false;
boolean isAPanelTab = false;
// Workbench Tab Change
if (tp.isWorkbench()) {
int WBIndex = tabPanel.getSelectedIndex();
m_curWindowNo = m_mWorkbench.getWindowNo(WBIndex);
// Window Change
log.info("curWin=" + m_curWindowNo + " - Win=" + tp);
if (tp.getSelectedComponent() instanceof JTabbedPane)
m_curWinTab = (JTabbedPane) tp.getSelectedComponent();
else
throw new java.lang.IllegalArgumentException("Window does not contain Tabs");
if (m_curWinTab.getSelectedComponent() instanceof GridController) {
m_curGC = (GridController) m_curWinTab.getSelectedComponent();
initSwitchLineAction();
} else
throw new java.lang.IllegalArgumentException("Window-Tab does not contain GridControler");
// change pointers
m_curTabIndex = m_curWinTab.getSelectedIndex();
} else {
// Just a Tab Change
log.info("Tab=" + tp);
m_curWinTab = tp;
int tpIndex = m_curWinTab.getSelectedIndex();
// detect no tab change
if (tpIndex == m_curTabIndex)
return;
back = tpIndex < m_curTabIndex;
GridController gc = null;
if (m_curWinTab.getSelectedComponent() instanceof GridController)
gc = (GridController) m_curWinTab.getSelectedComponent();
else if (m_curWinTab.getSelectedComponent() instanceof APanelTab)
isAPanelTab = true;
else
throw new java.lang.IllegalArgumentException("Tab does not contain GridControler");
// Save old Tab
if (m_curGC != null) {
m_curGC.stopEditor(true);
// has anything changed?
if (m_curTab.needSave(true, false)) {
// do we have real change
if (m_curTab.needSave(true, true)) {
// Automatic Save
if (Env.isAutoCommit(m_ctx, m_curWindowNo)) {
if (!m_curTab.dataSave(true)) {
// there is a problem, so we go back
showLastError();
m_curWinTab.setSelectedIndex(m_curTabIndex);
setBusy(false, true);
return;
}
} else // explicitly ask when changing tabs
if (ADialog.ask(m_curWindowNo, this, "SaveChanges?", m_curTab.getCommitWarning())) {
// yes we want to save
if (!m_curTab.dataSave(true)) {
// there is a problem, so we go back
showLastError();
m_curWinTab.setSelectedIndex(m_curTabIndex);
setBusy(false, true);
return;
}
} else // Don't save
{
//VOSS COM
int newRecord = m_curTab.getTableModel().getNewRow();
if (newRecord == -1)
m_curTab.dataIgnore();
else {
m_curWinTab.setSelectedIndex(m_curTabIndex);
setBusy(false, true);
return;
}
}
} else
// new record, but nothing changed
m_curTab.dataIgnore();
}
// there is a change
}
if (m_curAPanelTab != null) {
m_curAPanelTab.saveData();
m_curAPanelTab.unregisterPanel();
m_curAPanelTab = null;
}
// new tab
// if (m_curTabIndex >= 0)
// m_curWinTab.setForegroundAt(m_curTabIndex, AdempierePLAF.getTextColor_Normal());
// m_curWinTab.setForegroundAt(tpIndex, AdempierePLAF.getTextColor_OK());
// previousIndex = m_curTabIndex;
m_curTabIndex = tpIndex;
if (!isAPanelTab) {
m_curGC = gc;
initSwitchLineAction();
}
}
// Sort Tab Handling
if (isAPanelTab) {
m_curAPanelTab = (APanelTab) m_curWinTab.getSelectedComponent();
m_curAPanelTab.registerAPanel(this);
m_curAPanelTab.loadData();
// Consider that APanelTab (e.g. VSortTab) is not navigable - teo_sarca [ 1705444 ]
aFirst.setEnabled(false);
aPrevious.setEnabled(false);
aNext.setEnabled(false);
aLast.setEnabled(false);
} else // Cur Tab Setting
{
int gwTabIndex = m_mWorkbench.getMWindow(0).getTabIndex(m_curGC.getMTab());
//boolean needValidate = false;
if (m_mWorkbench.getMWindow(0).isTabInitialized(gwTabIndex) == false) {
m_mWorkbench.getMWindow(0).initTab(gwTabIndex);
//needValidate = true;
}
m_curGC.activate();
m_curTab = m_curGC.getMTab();
// Refresh only current row when tab is current
if (back && m_curTab.isCurrent())
m_curTab.dataRefresh();
else // Requery & autoSize
{
MRole role = MRole.getDefault();
m_curGC.query(m_onlyCurrentRows, m_onlyCurrentDays, role.getMaxQueryRecords());
/*
if (m_curGC.isNeedToSaveParent())
{
// there is a problem, so we go back
ADialog.error(m_curWindowNo, this, "SaveParentFirst");
m_curWinTab.setSelectedIndex(previousIndex);
setBusy(false, true);
return;
}*/
}
// Set initial record
if (m_curTab.getRowCount() == 0) {
// Automatically create New Record, if none & tab not RO
if (!m_curTab.isReadOnly() && (Env.isAutoNew(m_ctx, m_curWindowNo) || m_curTab.isQueryNewRecord())) {
log.config("No record - New - AutoNew=" + Env.isAutoNew(m_ctx, m_curWindowNo) + " - QueryNew=" + m_curTab.isQueryNewRecord());
m_curTab.dataNew(false);
} else // No Records found
{
aSave.setEnabled(false);
aDelete.setEnabled(false);
aDeleteSelection.setEnabled(false);
}
// updates counter
m_curTab.navigateCurrent();
m_curGC.dynamicDisplay(0);
}
/*
if (needValidate)
{
JFrame frame = Env.getFrame(APanel.this);
if (frame != null)
{
//not sure why, the following lines is needed to make dynamic resize work
//tested on jdk1.5, 1.6 using jgoodies look and feel
frame.getPreferredSize();
if (frame.getExtendedState() != JFrame.MAXIMIZED_BOTH)
{
frame.setMinimumSize(frame.getSize());
revalidate();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = Env.getFrame(APanel.this);
frame.validate();
AEnv.showCenterScreen(frame);
frame.setMinimumSize(null);
}
});
}
}
}*/
// else ##CHANGE
// m_curTab.navigateCurrent();
}
// Update <-> Navigation
aDetail.setEnabled(m_curTabIndex != m_curWinTab.getTabCount() - 1);
aParent.setEnabled(m_curTabIndex != 0 && m_curWinTab.getTabCount() > 1);
// History (on first tab only)
if (m_mWorkbench.getMWindow(getWindowIndex()).isTransaction())
aHistory.setEnabled(isFirstTab());
else {
aHistory.setPressed(false);
aHistory.setEnabled(false);
}
// Document Print
aPrint.setEnabled(m_curTab.isPrinted());
aPrintPreview.setEnabled(m_curTab.isPrinted());
// Query
aFind.setPressed(m_curTab.isQueryActive());
// Order Tab
if (isAPanelTab) {
aMulti.setPressed(false);
aMulti.setEnabled(false);
aNew.setEnabled(false);
aDelete.setEnabled(false);
aDeleteSelection.setEnabled(false);
aFind.setEnabled(false);
aRefresh.setEnabled(false);
aAttachment.setEnabled(false);
aChat.setEnabled(false);
} else // Grid Tab
{
aMulti.setEnabled(true);
aMulti.setPressed(!m_curGC.isSingleRow());
aFind.setEnabled(true);
aRefresh.setEnabled(true);
aAttachment.setEnabled(true);
aChat.setEnabled(true);
}
//
m_curWinTab.requestFocusInWindow();
setBusy(false, true);
log.config("fini");
}
Aggregations