use of org.compiere.model.GridTab in project adempiere by adempiere.
the class POWrapper method getPO.
/**
*
* @param model
* @param checkOtherWrapper
* if the given <code>model</code> is handled by a {@link GridTabWrapper} and this param is
* <code>true</code>, then this method <b>loads a new PO from DB</b>, only using the given
* <code>model</code>'s table name and record ID. If this param is <code>false</code> and
* <code>model</code> is not handled by <code>POWrapper</code>, then this method returns
* <code>null</code>.
* @return
*/
@SuppressWarnings("unchecked")
public static <T extends PO> T getPO(Object model, boolean checkOtherWrapper) {
if (model == null)
return null;
if (model instanceof PO)
return (T) model;
if (Proxy.isProxyClass(model.getClass())) {
InvocationHandler ih = Proxy.getInvocationHandler(model);
if (ih instanceof POWrapper) {
POWrapper wrapper = (POWrapper) ih;
return (T) wrapper.getPO();
}
if (ih instanceof GridTabWrapper && checkOtherWrapper) {
// using the grid tab wrapper to load the PO
final GridTab gridTab = GridTabWrapper.getGridTab(model);
final String tableName = gridTab.get_TableName();
final int recordID = gridTab.getKeyID(gridTab.getCurrentRow());
return (T) MTable.get(Env.getCtx(), tableName).getPO(recordID, null);
}
}
return null;
}
use of org.compiere.model.GridTab in project adempiere by adempiere.
the class GridTabWrapper method isNull.
/**
* Check if given columnName's value is null
*
* @param model
* @param columnName
* @return true if columnName's value is null
*/
public static boolean isNull(Object model, String columnName) {
final GridTab gridTab = getGridTab(model);
if (gridTab == null) {
return true;
}
final Object value = gridTab.getValue(columnName);
return value == null;
}
use of org.compiere.model.GridTab in project adempiere by adempiere.
the class InterfaceWrapperHelper method getValue.
private static <T> T getValue(final Object model, final String columnName, final boolean throwExIfColumnNotFound) {
Check.assumeNotNull(model, "model is not null");
Check.assumeNotNull(columnName, "columnName is not null");
if (GridTabWrapper.isHandled(model)) {
final GridTab gridTab = GridTabWrapper.getGridTab(model);
final GridField gridField = gridTab.getField(columnName);
if (gridField == null) {
if (throwExIfColumnNotFound) {
throw new AdempiereException("No field with ColumnName=" + columnName + " found in " + gridTab + " for " + model);
} else {
return null;
}
}
@SuppressWarnings("unchecked") final T value = (T) gridField.getValue();
return value;
} else if (POWrapper.isHandled(model)) {
PO po = POWrapper.getPO(model, false);
final int idx = po.get_ColumnIndex(columnName);
if (idx < 0) {
if (throwExIfColumnNotFound) {
throw new AdempiereException("No columnName " + columnName + " found for " + model);
} else {
return null;
}
}
@SuppressWarnings("unchecked") T value = (T) po.get_Value(idx);
return value;
} else {
throw new AdempiereException("Model wrapping is not supported for " + model + " (class:" + model.getClass() + ")");
}
}
use of org.compiere.model.GridTab in project adempiere by adempiere.
the class APanel method actionButton.
/**************************************************************************
* Start Button Process
* @param vButton button
*/
protected void actionButton(VButton vButton) {
log.info(vButton.toString());
if (m_curTab.hasChangedCurrentTabAndParents()) {
String msg = CLogger.retrieveErrorString("Please ReQuery Window");
ADialog.error(m_curWindowNo, this, null, msg);
return;
}
boolean startWOasking = false;
// boolean batch = false;
String col = vButton.getColumnName();
// Zoom
if (col.equals("Record_ID")) {
int AD_Table_ID = Env.getContextAsInt(m_ctx, m_curWindowNo, "AD_Table_ID");
int Record_ID = Env.getContextAsInt(m_ctx, m_curWindowNo, "Record_ID");
AEnv.zoom(AD_Table_ID, Record_ID);
return;
}
// save first ---------------
if (m_curTab.needSave(true, false))
if (!cmd_save(true))
return;
// Save included tabs if necessary - teo_sarca BF [ 2876892 ]
for (GridTab includedTab : m_curTab.getIncludedTabs()) {
if (includedTab.needSave(true, false))
if (!includedTab.dataSave(true))
return;
}
//
int table_ID = m_curTab.getAD_Table_ID();
// Record_ID
int record_ID = m_curTab.getRecord_ID();
// Record_ID - Language Handling
if (record_ID == -1 && m_curTab.getKeyColumnName().equals("AD_Language"))
record_ID = Env.getContextAsInt(m_ctx, m_curWindowNo, "AD_Language_ID");
// Record_ID - Change Log ID
if (record_ID == -1 && (vButton.getProcess_ID() == 306 || vButton.getProcess_ID() == 307)) {
Integer id = (Integer) m_curTab.getValue("AD_ChangeLog_ID");
record_ID = id.intValue();
}
// Ensure it's saved
if (record_ID == -1 && m_curTab.getKeyColumnName().endsWith("_ID")) {
ADialog.error(m_curWindowNo, this, "SaveErrorRowNotFound");
return;
}
boolean isProcessMandatory = false;
// Pop up Payment Rules
if (col.equals("PaymentRule")) {
VPayment vp = new VPayment(m_curWindowNo, m_curTab, vButton);
if (// may not be allowed
vp.isInitOK())
vp.setVisible(true);
vp.dispose();
if (vp.needSave()) {
cmd_save(false);
cmd_refresh();
}
} else // Pop up Document Action (Workflow)
if (col.equals("DocAction")) {
isProcessMandatory = true;
VDocAction vda = new VDocAction(m_curWindowNo, m_curTab, vButton, record_ID);
// Something to select from?
if (vda.getNumberOfOptions() == 0) {
vda.dispose();
log.info("DocAction - No Options");
return;
} else {
vda.setVisible(true);
if (!vda.isStartProcess())
return;
// batch = vda.isBatch();
startWOasking = true;
vda.dispose();
}
} else // Pop up Create From
if (col.equals("CreateFrom")) {
// Run form only if the button has no process defined - teo_sarca [ 1974354 ]
if (vButton.getProcess_ID() <= 0) {
ICreateFrom cf = VCreateFromFactory.create(m_curTab);
if (cf != null) {
if (cf.isInitOK()) {
cf.showWindow();
cf.closeWindow();
m_curTab.dataRefresh();
} else
cf.closeWindow();
return;
}
// else may start process
}
} else // Posting -----
if (col.equals("Posted") && MRole.getDefault().isShowAcct()) {
// Check Doc Status
String processed = Env.getContext(m_ctx, m_curWindowNo, "Processed");
if (!processed.equals("Y")) {
String docStatus = Env.getContext(m_ctx, m_curWindowNo, "DocStatus");
if (DocAction.STATUS_Completed.equals(docStatus) || DocAction.STATUS_Closed.equals(docStatus) || DocAction.STATUS_Reversed.equals(docStatus) || DocAction.STATUS_Voided.equals(docStatus))
;
else {
ADialog.error(m_curWindowNo, this, "PostDocNotComplete");
return;
}
}
// try to get table and record id from context data (eg for unposted view)
// otherwise use current table/record
int tableId = Env.getContextAsInt(m_ctx, m_curWindowNo, "AD_Table_ID", true);
int recordId = Env.getContextAsInt(m_ctx, m_curWindowNo, "Record_ID", true);
if (tableId == 0 || recordId == 0) {
tableId = m_curTab.getAD_Table_ID();
recordId = m_curTab.getRecord_ID();
}
// Check Post Status
Object ps = m_curTab.getValue("Posted");
if (ps != null && ps.equals("Y")) {
new org.compiere.acct.AcctViewer(Env.getContextAsInt(m_ctx, m_curWindowNo, "AD_Client_ID"), tableId, recordId);
} else {
if (ADialog.ask(m_curWindowNo, this, "PostImmediate?")) {
// force when problems
boolean force = ps != null && !ps.equals("N");
String error = AEnv.postImmediate(m_curWindowNo, Env.getAD_Client_ID(m_ctx), tableId, recordId, force);
if (error != null)
ADialog.error(m_curWindowNo, this, "PostingError-N", error);
cmd_refresh();
}
}
return;
}
// Posted
/**
* Start Process ----
* or invoke user form
*/
log.config("Process_ID=" + vButton.getProcess_ID() + ", Record_ID=" + record_ID);
if (vButton.getProcess_ID() == 0) {
if (isProcessMandatory) {
ADialog.error(m_curWindowNo, this, null, Msg.parseTranslation(m_ctx, "@NotFound@ @AD_Process_ID@"));
}
return;
}
// Save item changed
if (m_curTab.needSave(true, false))
if (!cmd_save(true))
return;
// call form
MProcess pr = new MProcess(m_ctx, vButton.getProcess_ID(), null);
// Validate Access
MRole role = MRole.getDefault(m_ctx, false);
Boolean accessRW = role.checkProcessAccess(pr.getAD_Process_ID());
if (accessRW == null || !accessRW.booleanValue()) {
ADialog.error(m_curWindowNo, this, null, Msg.parseTranslation(m_ctx, "@AccessCannotProcess@"));
return;
}
//
int form_ID = pr.getAD_Form_ID();
if (form_ID != 0) {
if (m_curTab.needSave(true, false))
if (!cmd_save(true))
return;
// Yamel Senih FR [ 114 ] 2015-11-23 Add Support to Dialog for create from
FormFrame ff = new FormFrame(getWindowNo());
String title = vButton.getDescription();
if (title == null || title.length() == 0)
title = vButton.getName();
ProcessInfo pi = new ProcessInfo(title, vButton.getProcess_ID(), table_ID, record_ID);
pi.setAD_User_ID(Env.getAD_User_ID(m_ctx));
pi.setAD_Client_ID(Env.getAD_Client_ID(m_ctx));
ff.setProcessInfo(pi);
ff.openForm(form_ID);
ff.pack();
AEnv.showCenterScreen(ff);
// Refresh
m_curTab.dataRefresh();
// End Yamel Senih
return;
}
int browse_ID = pr.getAD_Browse_ID();
if (browse_ID != 0) {
if (m_curTab.needSave(true, false))
if (!cmd_save(true))
return;
String title = vButton.getDescription();
if (title == null || title.length() == 0)
title = vButton.getName();
ProcessInfo pi = new ProcessInfo(title, vButton.getProcess_ID(), table_ID, record_ID);
pi.setAD_User_ID(Env.getAD_User_ID(m_ctx));
pi.setAD_Client_ID(Env.getAD_Client_ID(m_ctx));
FormFrame ff = new FormFrame(getWindowNo());
ff.setProcessInfo(pi);
MBrowse browse = new MBrowse(Env.getCtx(), browse_ID, null);
new VBrowser(ff, true, getWindowNo(), "", browse, "", true, "", Env.isSOTrx(Env.getCtx(), m_curWindowNo));
ff.pack();
AEnv.showCenterScreen(ff);
// Yamel Senih
// Refresh
m_curTab.dataRefresh();
return;
} else {
ProcessModalDialog dialog = new ProcessModalDialog(m_ctx, Env.getWindow(m_curWindowNo), Env.getHeader(m_ctx, m_curWindowNo), this, m_curWindowNo, vButton.getProcess_ID(), table_ID, record_ID, startWOasking);
// BR [ 323 ]
if (!startWOasking) {
dialog.validate();
dialog.pack();
AEnv.showCenterWindow(Env.getWindow(m_curWindowNo), dialog);
}
}
}
use of org.compiere.model.GridTab in project adempiere by adempiere.
the class APanel method initPanel.
/**************************************************************************
* Dynamic Panel Initialization - either single window or workbench.
* <pre>
* either
* - Workbench tabPanel (VTabbedPane)
* - Tab (GridController)
* 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
* @return true if Panel is initialized successfully
*/
public boolean initPanel(int AD_Workbench_ID, int AD_Window_ID, MQuery query) {
log.info("WB=" + AD_Workbench_ID + ", Win=" + AD_Window_ID + ", Query=" + query);
this.setName("APanel" + AD_Window_ID);
// Single Window
if (AD_Workbench_ID == 0)
m_mWorkbench = new GridWorkbench(m_ctx, AD_Window_ID);
else // Workbench
{
// m_mWorkbench = new MWorkbench(m_ctx);
// if (!m_mWorkbench.initWorkbench (AD_Workbench_ID))
// {
// log.log(Level.SEVERE, "APanel.initWindow - No Workbench Model");
// return false;
// }
// tabPanel.setWorkbench(true);
// tabPanel.addChangeListener(this);
log.warning("Workbench Not implemented yet [" + this + "]");
loadError = "Workbench Not implemented yet";
return false;
}
Dimension windowSize = m_mWorkbench.getWindowSize();
MQuery detailQuery = null;
/**
* WorkBench Loop
*/
for (int wb = 0; wb < m_mWorkbench.getWindowCount(); wb++) {
// Get/set WindowNo
// Timing: ca. 1.5 sec
m_curWindowNo = Env.createWindowNo(this);
m_mWorkbench.setWindowNo(wb, m_curWindowNo);
// Set AutoCommit for this Window
Env.setAutoCommit(m_ctx, m_curWindowNo, Env.isAutoCommit(m_ctx));
boolean autoNew = Env.isAutoNew(m_ctx);
Env.setAutoNew(m_ctx, m_curWindowNo, autoNew);
// 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 == GridWorkbench.TYPE_WINDOW) {
includedMap = new HashMap<Integer, GridController>(4);
//
GridWindowVO wVO = AEnv.getMWindowVO(m_curWindowNo, m_mWorkbench.getWindowID(wb), 0);
if (wVO == null) {
log.warning("AccessTableNoView for [" + this + "]");
loadError = "AccessTableNoView";
return false;
}
// Timing: ca. 0.3-1 sec
GridWindow mWindow = new GridWindow(wVO, true);
// Set SO/AutoNew for Window
Env.setContext(m_ctx, m_curWindowNo, "IsSOTrx", mWindow.isSOTrx());
if (!autoNew && mWindow.isTransaction())
Env.setAutoNew(m_ctx, m_curWindowNo, true);
m_mWorkbench.setMWindow(wb, mWindow);
if (wb == 0)
// default = only current
m_onlyCurrentRows = mWindow.isTransaction();
if (windowSize == null)
windowSize = mWindow.getWindowSize();
/**
* Window Tabs
*/
int tabSize = mWindow.getTabCount();
// Zoom Query
boolean goSingleRow = query != null;
for (int tab = 0; tab < tabSize; tab++) {
boolean included = false;
// MTab
if (tab == 0)
mWindow.initTab(0);
GridTab gTab = mWindow.getTab(tab);
Env.setContext(m_ctx, m_curWindowNo, tab, GridTab.CTX_TabLevel, Integer.toString(gTab.getTabLevel()));
// Query first tab
if (tab == 0) {
// initial user query for single workbench tab
if (m_mWorkbench.getWindowCount() == 1) {
if (query != null && query.getZoomTableName() != null && query.getZoomColumnName() != null && query.getZoomValue() instanceof Integer && (Integer) query.getZoomValue() > 0) {
if (!query.getZoomTableName().equalsIgnoreCase(gTab.getTableName())) {
detailQuery = query;
query = new MQuery();
query.addRestriction("1=2");
}
}
//Goodwill
isCancel = false;
query = initialQuery(query, gTab);
if (isCancel)
//Cancel opening window
return false;
if (query != null && query.getRecordCount() <= 1)
goSingleRow = true;
} else if (wb != 0) // workbench dynamic query for dependent windows
{
query = m_mWorkbench.getQuery();
}
// Set initial Query on first tab
if (query != null) {
// Query might involve history
m_onlyCurrentRows = false;
gTab.setQuery(query);
}
if (wb == 0)
m_curTab = gTab;
}
// query on first tab
Component tabElement = null;
// GridController
if (gTab.isSortTab()) {
VSortTab st = new VSortTab(m_curWindowNo, gTab.getAD_Table_ID(), gTab.getAD_ColumnSortOrder_ID(), gTab.getAD_ColumnSortYesNo_ID());
st.setTabLevel(gTab.getTabLevel());
tabElement = st;
} else // normal tab
{
// Timing: ca. .1 sec
GridController gc = new GridController();
CompiereColor cc = mWindow.getColor();
if (cc != null)
// set color on Window level
gc.setBackgroundColor(cc);
// will set color on Tab level
gc.initGrid(gTab, false, m_curWindowNo, this, mWindow, (tab != 0));
// Timing: ca. 6-7 sec for first .2 for next
gc.addDataStatusListener(this);
// register Escape Key
gc.registerESCAction(aIgnore);
// Set First Tab
if (wb == 0 && tab == 0) {
m_curGC = gc;
// Screen Sizing
Dimension size = gc.getPreferredSize();
size.width += 4;
size.height += 4;
gc.setPreferredSize(size);
}
tabElement = gc;
// If we have a zoom query, switch to single row
if (tab == 0 && goSingleRow)
gc.switchSingleRow();
// FR [ 1757088 ]
GridField[] fields = gc.getMTab().getFields();
int m_tab_id = 0;
for (int f = 0; f < fields.length; f++) {
m_tab_id = fields[f].getIncluded_Tab_ID();
if (m_tab_id != 0) {
includedMap.put(m_tab_id, gc);
}
}
// Is this tab included?
if (includedMap.size() > 0) {
GridController parent = (GridController) includedMap.get(new Integer(gTab.getAD_Tab_ID()));
if (parent != null) {
// FR [ 1757088 ]
gc.removeDataStatusListener(this);
GridSynchronizer synchronizer = new GridSynchronizer(mWindow, parent, gc);
if (parent == m_curGC)
synchronizer.activateChild();
included = parent.includeTab(gc, this, synchronizer);
}
}
initSwitchLineAction();
}
if (// Add to TabbedPane
!included) {
StringBuffer tabName = new StringBuffer();
tabName.append("<html>");
if (gTab.isReadOnly())
tabName.append("<i>");
int pos = gTab.getName().indexOf(" ");
if (pos == -1)
tabName.append(gTab.getName()).append("<br> ");
else {
tabName.append(gTab.getName().substring(0, pos)).append("<br>").append(gTab.getName().substring(pos + 1));
}
if (gTab.isReadOnly())
tabName.append("</i>");
tabName.append("</html>");
// Add Tab - sets ALT-<number> and Shift-ALT-<x>
window.addTab(tabName.toString(), gTab, tabElement);
}
}
// Tab Loop
// Tab background
// window.setBackgroundColor(new AdempiereColor(Color.magenta, Color.green));
}
// 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);
// Enable/Disable Tabs dynamically
if (m_curWinTab instanceof VTabbedPane)
((VTabbedPane) m_curWinTab).evaluate(null);
// Size
if (windowSize != null)
setPreferredSize(windowSize);
else
revalidate();
if (detailQuery != null && zoomToDetailTab(detailQuery)) {
return true;
}
Dimension size = getPreferredSize();
log.info("fini - " + size);
m_curWinTab.requestFocusInWindow();
return true;
}
Aggregations