📄 apanel.java
字号:
* or
* - Workbench tabPanel (VTabbedPane)
* - Window (VTabbedPane)
* - Tab (GridController)
* </pre>
* tabPanel
* @param AD_Workbench_ID if > 0 this is a workbench, AD_Window_ID ignored
* @param AD_Window_ID if not a workbench, Window ID
* @param query if not a Workbench, Zoom Query - additional SQL where clause
* @param isSOTrx Sales Order Trx
* @return true if Panel is initialized successfully
*/
public boolean initPanel (int AD_Workbench_ID, int AD_Window_ID, MQuery query, boolean isSOTrx)
{
Log.trace(Log.l1_User, "APanel.initPanel",
"WB=" + AD_Workbench_ID + ", Win=" + AD_Window_ID + ", Query=" + query + ", SO=" + isSOTrx);
this.setName("APanel" + AD_Window_ID);
m_isSOTrx = isSOTrx;
// Single Window
if (AD_Workbench_ID == 0)
m_mWorkbench = new MWorkbench(m_ctx, AD_Window_ID);
else
// Workbench
{
// m_mWorkbench = new MWorkbench(m_ctx);
// if (!m_mWorkbench.initWorkbench (AD_Workbench_ID))
// {
// Log.error("APanel.initWindow - No Workbench Model");
// return false;
// }
// tabPanel.setWorkbench(true);
// tabPanel.addChangeListener(this);
ADialog.warn(0, this, "","Not implemented yet");
return false;
}
/**
* WorkBench Loop
*/
for (int wb = 0; wb < m_mWorkbench.getWindowCount(); wb++)
{
// Get/set WindowNo
m_curWindowNo = Env.createWindowNo (this); // Timing: ca. 1.5 sec
m_mWorkbench.setWindowNo(wb, m_curWindowNo);
// Set AutoCommit/SO for this Window
Env.setAutoCommit(m_ctx, m_curWindowNo, Env.isAutoCommit(m_ctx));
Env.setContext(m_ctx, m_curWindowNo, "IsSOTrx", isSOTrx ? "Y" : "N");
// Workbench Window
VTabbedPane window = null;
// just one window
if (m_mWorkbench.getWindowCount() == 1)
{
window = tabPanel;
window.setWorkbench(false);
}
else
{
VTabbedPane tp = new VTabbedPane(false);
window = tp;
}
// Window Init
window.addChangeListener(this);
/**
* Init Model
*/
int wbType = m_mWorkbench.getWindowType(wb);
/**
* Window
*/
if (wbType == MWorkbench.TYPE_WINDOW)
{
MWindowVO wVO = AEnv.getMWindowVO(m_curWindowNo, m_mWorkbench.getWindowID(wb), 0);
if (wVO == null)
{
ADialog.error(0, null, "AccessTableNoView", "(No Window Model Info)");
return false;
}
MWindow mWindow = new MWindow (wVO); // Timing: ca. 0.3-1 sec
m_mWorkbench.setMWindow(wb, mWindow);
if (wb == 0)
m_onlyCurrentRows = mWindow.isTransaction(); // default = only current
/**
* Window Tabs
*/
int tabSize = mWindow.getTabCount();
for (int tab = 0; tab < tabSize; tab++)
{
// MTab
MTab mTab = m_mWorkbench.getMWindow(wb).getTab(tab);
// Query first tab
if (tab == 0)
{
// initial user query for single workbench tab
if (m_mWorkbench.getWindowCount() == 1)
{
// Query automatically if high volume and no query
if (mTab.isHighVolume() && (query == null || !query.isActive()))
{
Find find = new Find(Env.getFrame(this), m_curWindowNo, mTab);
query = find.getQuery();
find = null;
}
}
else if (wb != 0)
// workbench dynamic query for dependent windows
{
query = m_mWorkbench.getQuery();
}
// Set initial Query on first tab
if (query != null)
{
m_onlyCurrentRows = false; // Query might involve history
mTab.setQuery(query);
}
if (wb == 0)
m_curTab = mTab;
}
Component tabElement = null;
// GridController
if (!mTab.isSortTab())
{
GridController gc = new GridController(); // Timing: ca. .1 sec
CompiereColor cc = mWindow.getColor();
if (cc != null)
gc.setBackgroundColor(cc); // set color on Window level
gc.initGrid(mTab, false, m_curWindowNo, this); // will set color on Tab level
// Timing: ca. 6-7 sec for first .2 for next
gc.addDataStatusListener(this);
gc.registerESCAction(aIgnore); // register Escape Key
if (wb == 0 && tab == 0)
{
m_curGC = gc;
Dimension size = gc.getPreferredSize(); // Screen Sizing
size.width += 4;
size.height += 4;
gc.setPreferredSize(size);
}
tabElement = gc;
// If we have a query, switch to single row
if (tab == 0 && query != null)
gc.switchSingleRow();
}
else
{
VSortTab st = new VSortTab(m_curWindowNo, mTab.getAD_Table_ID(),
mTab.getAD_ColumnSortOrder_ID(), mTab.getAD_ColumnSortYesNo_ID());
st.setTabLevel(mTab.getTabLevel());
tabElement = st;
}
// Add to TabbedPane
StringBuffer tabName = new StringBuffer();
if (CompierePLAF.isActive())
tabName.append(mTab.getName()).append(" ");
else
{
tabName.append("<html>");
int pos = mTab.getName().indexOf(" ");
if (pos == -1)
tabName.append(mTab.getName()).append("<br>");
else
{
tabName.append(mTab.getName().substring(0,pos))
.append("<br>").append(mTab.getName().substring(pos+1));
tabName.append("</html>");
}
}
window.addTab(tabName.toString(), mTab.getIcon(), tabElement, mTab.getDescription());
// caused stateChanged for first tab - 3 seconds
window.setMnemonicAt(tab, KeyEvent.VK_1+tab); // 1,2,3,..
} // Tab Loop
// Tab background
// window.setBackgroundColor(new CompiereColor(Color.magenta, Color.green));
} // Type-MWindow
// Single Workbench Window Tab
if (m_mWorkbench.getWindowCount() == 1)
{
window.setToolTipText(m_mWorkbench.getDescription(wb));
}
else
// Add Workbench Window Tab
{
tabPanel.addTab(m_mWorkbench.getName(wb), m_mWorkbench.getIcon(wb), window, m_mWorkbench.getDescription(wb));
}
// Used for Env.getHeader
Env.setContext(m_ctx, m_curWindowNo, "WindowName", m_mWorkbench.getName(wb));
} // Workbench Loop
// stateChanged (<->) triggered
toolBar.setName(getTitle());
m_curTab.getTableModel().setChanged(false);
// Set Detail Button
aDetail.setEnabled(0 != m_curWinTab.getTabCount()-1);
// setPreferredSize comes here
Log.trace(Log.l1_User, "APanel.initPanel - fini");
m_curWinTab.requestFocusInWindow();
return true;
} // initPanel
/**
* Get Window Index
* @return Window Index
*/
private int getWindowIndex()
{
// only one window
if (m_mWorkbench.getWindowCount() == 1)
return 0;
// workbench
return tabPanel.getSelectedIndex();
} // getWindowIndex
/**
* Is first Tab (on Window)
* @return true if the panel displays the first tab
*/
private boolean isFirstTab()
{
return m_curWinTab.getSelectedIndex() == 0;
} // isFirstTab
/*************************************************************************/
/**
* Data Status Listener (row change) ^ | v
* @param e event
*/
public void dataStatusChanged (DataStatusEvent e)
{
if (m_disposing)
return;
Log.trace(Log.l1_User, "APanel.dataStatusChanged", e.getMessage());
String dbInfo = e.getMessage();
if (m_curTab != null && m_curTab.isQueryActive())
dbInfo = "[ " + dbInfo + " ]";
statusBar.setStatusDB(dbInfo, e.Created, e.CreatedBy, e.Updated, e.UpdatedBy, e.Info);
// Set Message / Info
if (e.getAD_Message() != null || e.getInfo() != null)
{
StringBuffer sb = new StringBuffer();
String msg = e.getMessage();
if (msg != null && msg.length() > 0)
sb.append(Msg.getMsg(m_ctx, e.getAD_Message()));
String info = e.getInfo();
if (info != null && info.length() > 0)
{
if (sb.length() > 0 && !sb.toString().trim().endsWith(":"))
sb.append(": ");
sb.append(info);
}
if (sb.length() > 0)
{
int pos = sb.indexOf("\n");
if (pos != -1) // replace CR/NL
sb.replace(pos, pos+1, " - ");
setStatusLine (sb.toString (), e.isError ());
}
}
// Confirm Error
if (e.isError() && !e.isConfirmed())
{
ADialog.error(m_curWindowNo, this, e.getAD_Message(), e.getInfo());
e.setConfirmed(true); // show just once - if MTable.setCurrentRow is involved the status event is re-issued
m_errorDisplayed = true;
}
// update Navigation
boolean firstRow = e.isFirstRow();
aFirst.setEnabled(!firstRow);
aPrevious.setEnabled(!firstRow);
boolean lastRow = e.isLastRow();
aNext.setEnabled(!lastRow);
aLast.setEnabled(!lastRow);
// update Change
boolean changed = e.isChanged() || e.isInserting();
boolean readOnly = m_curTab.isReadOnly();
//
aIgnore.setEnabled(changed & !readOnly);
aSave.setEnabled(changed & !readOnly);
//
aNew.setEnabled(!changed & !readOnly);
aCopy.setEnabled(!changed & !readOnly);
aDelete.setEnabled(!changed & !readOnly);
aRefresh.setEnabled(!changed);
// No Rows
if (e.getTotalRows() == 0)
aNew.setEnabled(true);
// Single-Multi
aMulti.setPressed(!m_curGC.isSingleRow());
// History (on first Tab only)
if (isFirstTab())
aHistory.setPressed(!m_curTab.isOnlyCurrentRows());
// Transaction info
String trxInfo = m_curTab.getTrxInfo();
if (trxInfo != null)
statusBar.setInfo(trxInfo);
// Check Attachment
boolean canHave = m_curTab.canHaveAttachment(); // not single _ID column
//
if (canHave && e.isLoading() && m_curTab.getCurrentRow() > e.getLoadedRows())
canHave = false;
if (canHave && m_curTab.getCurrentKeyID() == -1) // No Key
canHave = false;
if (canHave)
{
aAttachment.setEnabled(true);
aAttachment.setPressed(m_curTab.hasAttachment());
}
else
aAttachment.setEnabled(false);
// Log.trace(Log.l1_User, "APanel.dataStatusChanged - fini", e.getMessage());
} // dataStatusChanged
/**
* Set Status Line to text
* @param text clear text
* @param error error flag
*/
public void setStatusLine (String text, boolean error)
{
Log.trace(Log.l5_DData, "APanel.setStatusLine = " + text);
statusBar.setStatusLine(text, error);
} // setStatusLine
/**
* Indicate Busy
* @param busy busy
*/
private void setBusy (boolean busy)
{
m_isLocked = busy;
//
JFrame frame = Env.getFrame(this);
if (frame == null) // during init
return;
if (frame instanceof AWindow)
((AWindow)frame).setBusy(busy);
// String processing = Msg.getMsg(m_ctx, "Processing");
if (busy)
{
// setStatusLine(processing);
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
else
{
this.setCursor(Cursor.getDefaultCursor());
frame.setCursor(Cursor.getDefaultCursor());
// if (statusBar.getStatusLine().equals(processing))
// statusBar.setStatusLine("");
}
} // set Busy
/*************************************************************************/
/**
* Change Listener - (tab change) <->
* @param e event
*/
public void stateChanged (ChangeEvent e)
{
if (m_disposing)
return;
Log.trace(Log.l1_User, "APanel.stateChanged");
setBusy(true);
VTabbedPane tp = (VTabbedPane)e.getSource();
boolean back = false;
boolean isAPanelTab = false;
// Workbench Tab Change
if (tp.isWorkbench())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -