package org.compiere.apps;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import java.util.Vector;
import java.util.logging.Level;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.compiere.apps.form.FormFrame;
import org.compiere.apps.search.Find;
import org.compiere.grid.APanelTab;
import org.compiere.grid.GridController;
import org.compiere.grid.GridSynchronizer;
import org.compiere.grid.ICreateFrom;
import org.compiere.grid.RecordAccessDialog;
import org.compiere.grid.VCreateFromFactory;
import org.compiere.grid.VOnlyCurrentDays;
import org.compiere.grid.VPayment;
import org.compiere.grid.VSortTab;
import org.compiere.grid.VTabbedPane;
import org.compiere.grid.ed.VButton;
import org.compiere.grid.ed.VDocAction;
import org.compiere.model.DataStatusEvent;
import org.compiere.model.DataStatusListener;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.GridTable;
import org.compiere.model.GridWindow;
import org.compiere.model.GridWindowVO;
import org.compiere.model.GridWorkbench;
import org.compiere.model.Lookup;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MProcess;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MUser;
import org.compiere.model.MWindow;
import org.compiere.plaf.CompiereColor;
import org.compiere.print.AReport;
import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoUtil;
import org.compiere.swing.CPanel;
import org.compiere.util.ASyncProcess;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.compiere.util.Msg;
import org.compiere.util.Util;
public final class APanel extends CPanel
implements DataStatusListener, ChangeListener, ActionListener, ASyncProcess
{
private static final long serialVersionUID = 6066778919781303581L;
private boolean isNested = false;
public APanel(GridController gc,
int windowNo){
super();
isNested = true;
m_ctx = Env.getCtx();
try{
m_curGC = gc;
gc.addDataStatusListener(this);
m_curTab = gc.getMTab();
Component tabElement = null;
tabElement = gc;
VTabbedPane tabPane = new VTabbedPane(false);
tabPane.addTab(m_curTab.getName().toString(), m_curTab, tabElement);
m_curWinTab = tabPane;
m_curWindowNo = windowNo;
jbInit();
initSwitchLineAction();
}
catch(Exception e){
log.log(Level.SEVERE, "", e);
}
createMenu();
MRole role = MRole.getDefault();
m_curGC.query (m_onlyCurrentRows, m_onlyCurrentDays, role.getMaxQueryRecords());
m_curTab.navigateCurrent();
m_curGC.dynamicDisplay(0);
}
{
super();
m_window = window;
m_ctx = Env.getCtx();
try
{
jbInit();
}
catch (Exception e)
{
log.log(Level.SEVERE, "", e);
}
createMenu();
}
private static CLogger log = CLogger.getCLogger(APanel.class);
private AWindow m_window;
private boolean isCancel = false;
{
m_disposing = true;
if (m_curAPanelTab != null)
{
m_curAPanelTab.unregisterPanel();
m_curAPanelTab = null;
}
tabPanel.dispose(this);
tabPanel = null;
for (int i = 0; i < m_mWorkbench.getWindowCount(); i++)
{
m_curWindowNo = m_mWorkbench.getWindowNo(i);
log.info("#" + m_curWindowNo);
Env.setAutoCommit(m_ctx, m_curWindowNo, false);
m_mWorkbench.dispose(i);
Env.clearWinContext(m_ctx, m_curWindowNo);
}
if (m_mWorkbench != null)
m_mWorkbench.dispose();
m_mWorkbench = null;
if (menuBar != null)
menuBar.removeAll();
menuBar = null;
if (toolBar != null)
toolBar.removeAll();
toolBar = null;
this.removeAll();
}
private BorderLayout mainLayout = new BorderLayout();
private VTabbedPane tabPanel = new VTabbedPane(true);
private StatusBar statusBar = new StatusBar();
private CPanel northPanel = new CPanel();
private JToolBar toolBar = new JToolBar();
private JMenuBar menuBar = new JMenuBar();
private FlowLayout northLayout = new FlowLayout();
private void jbInit()
throws Exception
{
this.setLocale(Language.getLoginLanguage().getLocale());
this.setLayout(mainLayout);
mainLayout.setHgap(2);
mainLayout.setVgap(2);
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);
}
this.add(statusBar, BorderLayout.SOUTH);
this.add(northPanel, BorderLayout.NORTH);
northPanel.setLayout(northLayout);
northLayout.setAlignment(FlowLayout.LEFT);
toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
toolBar.setBorderPainted(false);
toolBar.setFloatable(false);
northPanel.add(toolBar, null);
}
private AppsAction aPrevious, aNext, aParent, aDetail, aFirst, aLast,
aNew, aCopy, aDelete, aPrint, aPrintPreview,
aExport = null,
aRefresh, aHistory, aAttachment, aChat, aMulti, aFind,
aWorkflow, aZoomAcross, aRequest, aWinSize, aArchive;
public AppsAction aIgnore;
public AppsAction aSave;
public AppsAction aLock;
private AppsAction aReport, aEnd, aHome, aHelp, aProduct, aLogout,
aAccount, aCalculator, aCalendar, aEditor, aPreference, aScript,
aOnline, aMailSupport, aAbout, aPrintScr, aScrShot, aExit, aBPartner,
aDeleteSelection, aShowAllWindow;
private SwitchAction aSwitchLinesDownAction, aSwitchLinesUpAction;
private WindowMenu m_WindowMenu;
private void ()
{
JMenu mFile = AEnv.getMenu("File");
menuBar.add(mFile);
aPrintScr = addAction("PrintScreen", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, 0), false);
aScrShot = addAction("ScreenShot", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, Event.SHIFT_MASK), false);
aReport = addAction("Report", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0), false);
aPrint = addAction("Print", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), false);
aPrintPreview = addAction("PrintPreview", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.SHIFT_MASK+Event.ALT_MASK), false);
if (MRole.getDefault().isCanExport())
{
aExport = addAction("Export", mFile, null, false);
}
mFile.addSeparator();
aEnd = addAction("End", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK), false);
aLogout = addAction("Logout", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.SHIFT_MASK+Event.ALT_MASK), false);
aExit = addAction("Exit", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.SHIFT_MASK+Event.ALT_MASK), false);
JMenu mEdit = AEnv.getMenu("Edit");
menuBar.add(mEdit);
aNew = addAction("New", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), false);
aSave = addAction("Save", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), false);
mEdit.addSeparator();
aCopy = addAction("Copy", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_F2, Event.SHIFT_MASK), false);
aDelete = addAction("Delete", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), false);
aDeleteSelection = addAction("DeleteSelection", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK), false);
aIgnore = addAction("Ignore", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), false);
aRefresh = addAction("Refresh", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), false);
mEdit.addSeparator();
aFind = addAction("Find", mEdit, KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), true);
if (m_isPersonalLock)
aLock = addAction("Lock", mEdit, null, true);
JMenu mView = AEnv.getMenu("View");
menuBar.add(mView);
if (MRole.getDefault().isAllow_Info_Product())
{
aProduct = addAction("InfoProduct", mView, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.ALT_MASK), false);
}
if (MRole.getDefault().isAllow_Info_BPartner())
{
aBPartner = addAction("InfoBPartner", mView, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.SHIFT_MASK+Event.ALT_MASK), false);
}
if (MRole.getDefault().isShowAcct() && MRole.getDefault().isAllow_Info_Account())
{
aAccount = addAction("InfoAccount",mView, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.ALT_MASK+Event.CTRL_MASK), false);
}
if (MRole.getDefault().isAllow_Info_Schedule())
{
AEnv.addMenuItem("InfoSchedule", null, null, mView, this);
}
if (MRole.getDefault().isAllow_Info_MRP())
{
AEnv.addMenuItem("InfoMRP", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_CRP())
{
AEnv.addMenuItem("InfoCRP", "Info", null, mView, this);
}
mView.addSeparator();
if (MRole.getDefault().isAllow_Info_Order())
{
AEnv.addMenuItem("InfoOrder", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_Invoice())
{
AEnv.addMenuItem("InfoInvoice", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_InOut())
{
AEnv.addMenuItem("InfoInOut", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_Payment())
{
AEnv.addMenuItem("InfoPayment", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_CashJournal())
{
AEnv.addMenuItem("InfoCashLine", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_Resource())
{
AEnv.addMenuItem("InfoAssignment", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_Asset())
{
AEnv.addMenuItem("InfoAsset", "Info", null, mView, this);
}
mView.addSeparator();
aAttachment = addAction("Attachment", mView, KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0), true);
aChat = addAction("Chat", mView, null, true);
aHistory = addAction("History", mView, KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0), true);
mView.addSeparator();
aMulti = addAction("Multi", mView, KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), true);
JMenu mGo = AEnv.getMenu("Go");
menuBar.add(mGo);
aFirst = addAction("First", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, Event.ALT_MASK), false);
aPrevious = addAction("Previous", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_UP, Event.ALT_MASK), false);
aNext = addAction("Next", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Event.ALT_MASK), false);
aLast = addAction("Last", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, Event.ALT_MASK), false);
mGo.addSeparator();
aParent = addAction("Parent", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Event.ALT_MASK), false);
aDetail = addAction("Detail", mGo, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Event.ALT_MASK), false);
mGo.addSeparator();
aZoomAcross = addAction("ZoomAcross", mGo, null, false);
aRequest = addAction("Request", mGo, null, false);
aArchive = addAction("Archive", mGo, null, false);
aHome = addAction("Home", mGo, null, false);
JMenu mTools = AEnv.getMenu("Tools");
menuBar.add(mTools);
aCalculator = addAction("Calculator", mTools, null, false);
aCalendar = addAction("Calendar", mTools, null, false);
aEditor = addAction("Editor", mTools, null, false);
MUser user = MUser.get(Env.getCtx());
if (user.isAdministrator())
aScript = addAction("Script", mTools, null, false);
if ("Y".equals(Env.getContext(m_ctx, "#SysAdmin")))
aWinSize = addAction("WinSize", mTools, null, false);
if (AEnv.isWorkflowProcess())
aWorkflow = addAction("WorkFlow", mTools, null, false);
if (MRole.getDefault().isShowPreference())
{
mTools.addSeparator();
aPreference = addAction("Preference", mTools, null, false);
}
AMenu aMenu = (AMenu)Env.getWindow(0);
m_WindowMenu = new WindowMenu(aMenu.getWindowManager(), m_window);
menuBar.add(m_WindowMenu);
aShowAllWindow = addAction("ShowAllWindow", null, KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_MASK), false);
JMenu mHelp = AEnv.getMenu("Help");
menuBar.add(mHelp);
aHelp = addAction("Help", mHelp, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), false);
aOnline = addAction("Online", mHelp, null, false);
aMailSupport = addAction("EMailSupport", mHelp, null, false);
aAbout = addAction("About", mHelp, null, false);
toolBar.add(aIgnore.getButton());
toolBar.addSeparator();
toolBar.add(aHelp.getButton());
toolBar.add(aNew.getButton());
toolBar.add(aCopy.getButton());
toolBar.add(aDelete.getButton());
toolBar.add(aDeleteSelection.getButton());
toolBar.add(aSave.getButton());
toolBar.addSeparator();
toolBar.add(aRefresh.getButton());
toolBar.add(aFind.getButton());
toolBar.add(aAttachment.getButton());
toolBar.add(aChat.getButton());
toolBar.add(aMulti.getButton());
toolBar.addSeparator();
if((m_curGC == null) || (m_curGC != null && !m_curGC.isDetailGrid())){
toolBar.add(aHistory.getButton());
toolBar.add(aHome.getButton());
toolBar.add(aParent.getButton());
toolBar.add(aDetail.getButton());
toolBar.addSeparator();
}
toolBar.add(aFirst.getButton());
toolBar.add(aPrevious.getButton());
toolBar.add(aNext.getButton());
toolBar.add(aLast.getButton());
toolBar.addSeparator();
toolBar.add(aReport.getButton());
toolBar.add(aArchive.getButton());
toolBar.add(aPrintPreview.getButton());
toolBar.add(aPrint.getButton());
if((m_curGC == null) || (m_curGC != null && !m_curGC.isDetailGrid())){
toolBar.addSeparator();
if (m_isPersonalLock)
toolBar.add(aLock.getButton());
toolBar.add(aZoomAcross.getButton());
if (aWorkflow != null)
toolBar.add(aWorkflow.getButton());
toolBar.add(aRequest.getButton());
if (MRole.getDefault().isAllow_Info_Product())
{
toolBar.add(aProduct.getButton());
}
toolBar.addSeparator();
toolBar.add(aEnd.getButton());
}
if (CLogMgt.isLevelAll())
Util.printActionInputMap(this);
}
private AppsAction (String actionName, JMenu menu, KeyStroke accelerator, boolean toggle)
{
AppsAction action = new AppsAction(actionName, accelerator, toggle);
if (menu != null)
menu.add(action.getMenuItem());
action.setDelegate(this);
if (accelerator != null)
{
getInputMap(WHEN_IN_FOCUSED_WINDOW).put(accelerator, actionName);
getActionMap().put(actionName, action);
}
return action;
}
public JMenuBar ()
{
return menuBar;
}
{
if (m_mWorkbench != null && m_mWorkbench.getWindowCount() > 1)
{
StringBuffer sb = new StringBuffer();
sb.append(m_mWorkbench.getName()).append(" ")
.append(Env.getContext(m_ctx, "#AD_User_Name")).append(" (")
.append(Env.getContext(m_ctx, "#AD_Role_Name")).append(") @ ")
.append(Env.getContext(m_ctx, "#AD_Client_Name")).append(".")
.append(Env.getContext(m_ctx, "#AD_Org_Name")).append(" [")
.append(Env.getContext(m_ctx, "#DB_UID")).append("]");
return sb.toString();
}
return Env.getHeader(m_ctx, m_curWindowNo);
}
private Properties m_ctx;
private GridWorkbench m_mWorkbench;
private GridTab m_curTab;
private GridController m_curGC;
private JTabbedPane m_curWinTab = null;
private int m_curWindowNo;
private int m_curTabIndex = -1;
private APanelTab m_curAPanelTab = null;
private boolean m_disposing = false;
private boolean m_errorDisplayed = false;
private boolean m_onlyCurrentRows = true;
private int m_onlyCurrentDays = 0;
private boolean m_isLocked = false;
private boolean m_isPersonalLock = MRole.getDefault().isPersonalLock();
private int m_lastModifiers;
private HashMap<Integer, GridController> includedMap;
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);
if (AD_Workbench_ID == 0)
m_mWorkbench = new GridWorkbench(m_ctx, AD_Window_ID);
else
{
ADialog.warn(0, this, "","Not implemented yet");
return false;
}
Dimension windowSize = m_mWorkbench.getWindowSize();
MQuery detailQuery = null;
for (int wb = 0; wb < m_mWorkbench.getWindowCount(); wb++)
{
m_curWindowNo = Env.createWindowNo (this);
m_mWorkbench.setWindowNo(wb, m_curWindowNo);
Env.setAutoCommit(m_ctx, m_curWindowNo, Env.isAutoCommit(m_ctx));
boolean autoNew = Env.isAutoNew(m_ctx);
Env.setAutoNew(m_ctx, m_curWindowNo, autoNew);
VTabbedPane window = null;
if (m_mWorkbench.getWindowCount() == 1)
{
window = tabPanel;
window.setWorkbench(false);
}
else
{
VTabbedPane tp = new VTabbedPane(false);
window = tp;
}
window.addChangeListener(this);
int wbType = m_mWorkbench.getWindowType(wb);
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)
{
ADialog.error(0, null, "AccessTableNoView", "(No Window Model Info)");
return false;
}
GridWindow mWindow = new GridWindow (wVO, true);
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)
m_onlyCurrentRows = mWindow.isTransaction();
if (windowSize == null)
windowSize = mWindow.getWindowSize();
int tabSize = mWindow.getTabCount();
boolean goSingleRow = query != null;
for (int tab = 0; tab < tabSize; tab++)
{
boolean included = false;
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()));
if (tab == 0)
{
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");
}
}
isCancel = false;
query = initialQuery (query, gTab);
if (isCancel) return false;
if (query != null && query.getRecordCount() <= 1)
goSingleRow = true;
}
else if (wb != 0)
{
query = m_mWorkbench.getQuery();
}
if (query != null)
{
m_onlyCurrentRows = false;
gTab.setQuery(query);
}
if (wb == 0)
m_curTab = gTab;
}
Component tabElement = null;
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
{
GridController gc = new GridController();
CompiereColor cc = mWindow.getColor();
if (cc != null)
gc.setBackgroundColor(cc);
gc.initGrid(gTab, false, m_curWindowNo, this, mWindow, (tab != 0));
gc.addDataStatusListener(this);
gc.registerESCAction(aIgnore);
if (wb == 0 && tab == 0)
{
m_curGC = gc;
Dimension size = gc.getPreferredSize();
size.width += 4;
size.height += 4;
gc.setPreferredSize(size);
}
tabElement = gc;
if (tab == 0 && goSingleRow)
gc.switchSingleRow();
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);
}
}
if (includedMap.size() > 0)
{
GridController parent = (GridController)includedMap.get(new Integer(gTab.getAD_Tab_ID()));
if (parent != null)
{
gc.removeDataStatusListener(this);
GridSynchronizer synchronizer = new GridSynchronizer(mWindow, parent, gc);
if (parent == m_curGC)
synchronizer.activateChild();
included = parent.includeTab(gc,this,synchronizer);
}
}
initSwitchLineAction();
}
if (!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>");
window.addTab (tabName.toString(), gTab, tabElement);
}
}
}
if (m_mWorkbench.getWindowCount() == 1)
{
window.setToolTipText(m_mWorkbench.getDescription(wb));
}
else
{
tabPanel.addTab(m_mWorkbench.getName(wb), m_mWorkbench.getIcon(wb), window, m_mWorkbench.getDescription(wb));
}
Env.setContext(m_ctx, m_curWindowNo, "WindowName", m_mWorkbench.getName(wb));
}
toolBar.setName(getTitle());
m_curTab.getTableModel().setChanged(false);
aDetail.setEnabled(0 != m_curWinTab.getTabCount()-1);
if (m_curWinTab instanceof VTabbedPane)
((VTabbedPane)m_curWinTab).evaluate(null);
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;
}
if (query != null && query.getZoomTableName() != null && query.getZoomColumnName() != null)
{
GridTab gTab = m_mWorkbench.getMWindow(0).getTab(0);
if (!query.getZoomTableName().equalsIgnoreCase(gTab.getTableName()))
{
int tabSize = m_mWorkbench.getMWindow(0).getTabCount();
for (int tab = 0; tab < tabSize; tab++)
{
gTab = m_mWorkbench.getMWindow(0).getTab(tab);
if (gTab.isSortTab())
continue;
if (gTab.getTableName().equalsIgnoreCase(query.getZoomTableName()))
{
if (doZoomToDetail(gTab, query, tab)) {
return true;
}
}
}
}
}
return false;
}
private boolean doZoomToDetail(GridTab gTab, MQuery query,
int tabIndex) {
GridField[] fields = gTab.getFields();
for (GridField field : fields)
{
if (field.getColumnName().equalsIgnoreCase(query.getZoomColumnName()))
{
m_mWorkbench.getMWindow(0).initTab(tabIndex);
int parentId = DB.getSQLValue(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause());
if (parentId > 0)
{
Map<Integer, Object[]>parentMap = new TreeMap<Integer, Object[]>();
int index = tabIndex;
int oldpid = parentId;
GridTab currentTab = gTab;
while (index > 0)
{
index--;
GridTab pTab = m_mWorkbench.getMWindow(0).getTab(index);
if (pTab.getTabLevel() < currentTab.getTabLevel())
{
m_mWorkbench.getMWindow(0).initTab(index);
if (index > 0)
{
if (pTab.getLinkColumnName() != null && pTab.getLinkColumnName().trim().length() > 0)
{
int pid = DB.getSQLValue(null, "SELECT " + pTab.getLinkColumnName() + " FROM " + pTab.getTableName() + " WHERE " + currentTab.getLinkColumnName() + " = ?", oldpid);
if (pid > 0)
{
parentMap.put(index, new Object[]{currentTab.getLinkColumnName(), oldpid});
oldpid = pid;
currentTab = pTab;
}
else
{
parentMap.clear();
break;
}
}
}
else
{
parentMap.put(index, new Object[]{currentTab.getLinkColumnName(), oldpid});
}
}
}
for(Map.Entry<Integer, Object[]> entry : parentMap.entrySet())
{
GridTab pTab = m_mWorkbench.getMWindow(0).getTab(entry.getKey());
Object[] value = entry.getValue();
MQuery pquery = new MQuery(pTab.getAD_Table_ID());
pquery.addRestriction((String)value[0], "=", value[1]);
pTab.setQuery(pquery);
GridController gc = (GridController) tabPanel.getComponentAt(entry.getKey());
gc.activate();
gc.query(false, 0, 0);
}
MQuery targetQuery = new MQuery(gTab.getAD_Table_ID());
targetQuery.addRestriction(gTab.getLinkColumnName(), "=", parentId);
gTab.setQuery(targetQuery);
GridController gc = null;
if (!includedMap.containsKey(gTab.getAD_Tab_ID()))
{
int target = tabPanel.findTabindex(gTab);
gc = (GridController) tabPanel.getComponentAt(target);
}
else
{
GridController parent = includedMap.get(gTab.getAD_Tab_ID());
gc = parent.findChild(gTab);
}
gc.activate();
gc.query(false, 0, 0);
GridTable table = gTab.getTableModel();
int count = table.getRowCount();
for(int i = 0; i < count; i++)
{
int id = table.getKeyID(i);
if (id == ((Integer)query.getZoomValue()).intValue())
{
if (!includedMap.containsKey(gTab.getAD_Tab_ID()))
{
tabPanel.setSelectedIndex(tabPanel.findTabindex(gTab));
}
else
{
GridController parent = includedMap.get(gTab.getAD_Tab_ID());
int pindex = tabPanel.findTabindex(parent.getMTab());
if (pindex >= 0)
tabPanel.setSelectedIndex(pindex);
}
gTab.navigate(i);
return true;
}
}
}
}
}
return false;
}
{
return m_curWindowNo;
}
{
MRole role = MRole.getDefault(m_ctx, false);
if (query != null && query.isActive() && !role.isQueryMax(query.getRecordCount()))
return query;
StringBuffer where = new StringBuffer(Env.parseContext(m_ctx, m_curWindowNo, mTab.getWhereExtended(), false));
boolean require = mTab.isHighVolume();
if (!require && !m_onlyCurrentRows)
{
if (query != null)
{
String wh2 = query.getWhereClause();
if (wh2.length() > 0)
{
if (where.length() > 0)
where.append (" AND ");
where.append(wh2);
}
}
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM ")
.append(mTab.getTableName());
if (where.length() > 0)
sql.append(" WHERE ").append(where);
int no = DB.getSQLValue(null, sql.toString());
require = MRole.getDefault().isQueryRequire(no);
}
if (require)
{
GridField[] findFields = mTab.getFields();
Find find = new Find (Env.getFrame(this), m_curWindowNo, mTab.getName(),
mTab.getAD_Tab_ID(), mTab.getAD_Table_ID(), mTab.getTableName(),
where.toString(), findFields, 10);
query = find.getQuery();
isCancel = (query == null);
find.dispose();
find = null;
}
return query;
}
{
if (m_mWorkbench.getWindowCount() == 1)
return 0;
return tabPanel.getSelectedIndex();
}
{
return m_curWinTab.getSelectedIndex() == 0;
}
{
return m_mWorkbench.getImage(getWindowIndex());
}
{
if (m_disposing)
return;
log.info(e.getMessage());
String dbInfo = e.getMessage();
if (m_curTab != null && m_curTab.isQueryActive())
dbInfo = "[ " + dbInfo + " ]";
statusBar.setStatusDB(dbInfo, e);
if (!isNested)
m_window.setTitle(getTitle());
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)
sb.replace(pos, pos+1, " - ");
setStatusLine (sb.toString (), e.isError ());
}
}
if (e.isError() && !e.isConfirmed())
{
ADialog.error(m_curWindowNo, this, e.getAD_Message(), e.getInfo());
e.setConfirmed(true);
m_errorDisplayed = true;
}
else if (e.isWarning() && !e.isConfirmed())
{
ADialog.warn(m_curWindowNo, this, e.getAD_Message(), e.getInfo());
e.setConfirmed(true);
}
boolean firstRow = e.isFirstRow();
aFirst.setEnabled(!firstRow);
aPrevious.setEnabled(!firstRow);
boolean lastRow = e.isLastRow();
aNext.setEnabled(!lastRow);
aLast.setEnabled(!lastRow);
boolean changed = e.isChanged() || e.isInserting();
int changedColumn = e.getChangedColumn();
boolean inserting = e.isInserting();
if(e.getAD_Message() != null && e.getAD_Message().equals("Saved"))
changed = false;
boolean readOnly = m_curTab.isReadOnly();
boolean insertRecord = !readOnly;
if (insertRecord)
insertRecord = m_curTab.isInsertRecord();
aNew.setEnabled(((inserting && changedColumn>0) || !inserting) && insertRecord);
aCopy.setEnabled(!changed && insertRecord);
aRefresh.setEnabled(!changed);
aDelete.setEnabled(!changed && !readOnly);
aDeleteSelection.setEnabled(!changed && !readOnly);
if (readOnly && m_curTab.isAlwaysUpdateField())
readOnly = false;
aIgnore.setEnabled(changed && !readOnly);
aSave.setEnabled(changed && !readOnly);
if (e.getTotalRows() == 0 && insertRecord) {
aNew.setEnabled(true);
aDelete.setEnabled(false);
aDeleteSelection.setEnabled(false);
}
aMulti.setPressed(!m_curGC.isSingleRow());
if (isFirstTab())
aHistory.setPressed(!m_curTab.isOnlyCurrentRows());
String trxInfo = m_curTab.getTrxInfo();
if (trxInfo != null)
statusBar.setInfo(trxInfo);
boolean canHaveAttachment = m_curTab.canHaveAttachment();
if (canHaveAttachment && e.isLoading() && m_curTab.getCurrentRow() > e.getLoadedRows())
canHaveAttachment = false;
if (canHaveAttachment && m_curTab.getRecord_ID() == -1)
canHaveAttachment = false;
if (canHaveAttachment)
{
aAttachment.setEnabled(true);
aAttachment.setPressed(m_curTab.hasAttachment());
aChat.setEnabled(true);
aChat.setPressed(m_curTab.hasChat());
}
else
{
aAttachment.setEnabled(false);
aChat.setEnabled(false);
}
if (m_isPersonalLock)
aLock.setPressed(m_curTab.isLocked());
if (m_curWinTab instanceof VTabbedPane)
((VTabbedPane)m_curWinTab).evaluate(e);
}
{
log.fine(text);
statusBar.setStatusLine(text, error);
}
private void setBusy (
boolean busy,
boolean focus)
{
m_isLocked = busy;
JFrame frame = Env.getFrame(this);
if (frame == null)
return;
if (frame instanceof AWindow)
((AWindow)frame).setBusy(busy);
if (busy)
{
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
else
{
this.setCursor(Cursor.getDefaultCursor());
frame.setCursor(Cursor.getDefaultCursor());
if (focus)
m_curGC.requestFocus();
}
}
{
if (m_disposing)
return;
log.info(e.toString());
setBusy(true, true);
VTabbedPane tp = (VTabbedPane)e.getSource();
boolean back = false;
boolean isAPanelTab = false;
if (tp.isWorkbench())
{
int WBIndex = tabPanel.getSelectedIndex();
m_curWindowNo = m_mWorkbench.getWindowNo(WBIndex);
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");
m_curTabIndex = m_curWinTab.getSelectedIndex();
}
else
{
log.info("Tab=" + tp);
m_curWinTab = tp;
int tpIndex = m_curWinTab.getSelectedIndex();
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");
if (m_curGC != null)
{
m_curGC.stopEditor(true);
if (m_curTab.needSave(true, false))
{
if (m_curTab.needSave(true, true))
{
if (Env.isAutoCommit(m_ctx, m_curWindowNo))
{
if (!m_curTab.dataSave(true))
{
showLastError();
m_curWinTab.setSelectedIndex(m_curTabIndex);
setBusy(false, true);
return;
}
}
else if (ADialog.ask(m_curWindowNo, this, "SaveChanges?", m_curTab.getCommitWarning()))
{
if (!m_curTab.dataSave(true))
{
showLastError();
m_curWinTab.setSelectedIndex(m_curTabIndex);
setBusy(false, true);
return;
}
}
else
{
int newRecord= m_curTab.getTableModel().getNewRow();
if( newRecord == -1)
m_curTab.dataIgnore();
else
{
m_curWinTab.setSelectedIndex(m_curTabIndex);
setBusy(false, true);
return;
}
}
}
else
m_curTab.dataIgnore();
}
}
if (m_curAPanelTab != null)
{
m_curAPanelTab.saveData();
m_curAPanelTab.unregisterPanel();
m_curAPanelTab = null;
}
m_curTabIndex = tpIndex;
if (!isAPanelTab) {
m_curGC = gc;
initSwitchLineAction();
}
}
if (isAPanelTab)
{
m_curAPanelTab = (APanelTab)m_curWinTab.getSelectedComponent();
m_curAPanelTab.registerAPanel(this);
m_curAPanelTab.loadData();
aFirst.setEnabled(false);
aPrevious.setEnabled(false);
aNext.setEnabled(false);
aLast.setEnabled(false);
}
else
{
int gwTabIndex = m_mWorkbench.getMWindow(0).getTabIndex(m_curGC.getMTab());
if (m_mWorkbench.getMWindow(0).isTabInitialized(gwTabIndex) == false)
{
m_mWorkbench.getMWindow(0).initTab(gwTabIndex);
}
m_curGC.activate();
m_curTab = m_curGC.getMTab();
if (back && m_curTab.isCurrent())
m_curTab.dataRefresh();
else
{
MRole role = MRole.getDefault();
m_curGC.query (m_onlyCurrentRows, m_onlyCurrentDays, role.getMaxQueryRecords());
}
if (m_curTab.getRowCount() == 0)
{
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
{
aSave.setEnabled(false);
aDelete.setEnabled(false);
aDeleteSelection.setEnabled(false);
}
m_curTab.navigateCurrent();
m_curGC.dynamicDisplay(0);
}
}
aDetail.setEnabled(m_curTabIndex != m_curWinTab.getTabCount()-1);
aParent.setEnabled(m_curTabIndex != 0 && m_curWinTab.getTabCount() > 1);
if (m_mWorkbench.getMWindow(getWindowIndex()).isTransaction())
aHistory.setEnabled(isFirstTab());
else
{
aHistory.setPressed(false);
aHistory.setEnabled(false);
}
aPrint.setEnabled(m_curTab.isPrinted());
aPrintPreview.setEnabled(m_curTab.isPrinted());
aFind.setPressed(m_curTab.isQueryActive());
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
{
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");
}
{
int index = m_curWinTab.getSelectedIndex();
if (index == m_curWinTab.getTabCount()-1)
return;
if (m_curWinTab instanceof VTabbedPane)
{
VTabbedPane tabPane = (VTabbedPane)m_curWinTab;
index++;
while ( index < tabPane.getTabCount() )
{
if (tabPane.isEnabledAt(index))
{
m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
tabPane.setSelectedIndex(index);
break;
}
else
index++;
}
}
else
{
m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
m_curWinTab.setSelectedIndex(index+1);
}
}
{
int index = m_curWinTab.getSelectedIndex();
if (index == 0)
return;
if (m_curWinTab instanceof VTabbedPane)
{
VTabbedPane tabPane = (VTabbedPane)m_curWinTab;
index--;
while ( index >= 0 )
{
if (tabPane.isEnabledAt(index))
{
m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
tabPane.setSelectedIndex(index);
break;
}
else
index--;
}
}
else
{
m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
m_curWinTab.setSelectedIndex(index-1);
}
}
{
log.info(e.getActionCommand() + " - " + e.getModifiers());
if (m_disposing || isUILocked())
return;
m_lastModifiers = e.getModifiers();
String cmd = e.getActionCommand();
if (cmd.equals("ScreenShot"))
{
AEnv.actionPerformed (e.getActionCommand(), m_curWindowNo, this);
return;
}
if (!cmd.equals(aShowAllWindow.getName()))
setBusy (true, true);
if (e.getSource() instanceof VButton)
{
setStatusLine(processButtonCallout((VButton)e.getSource()), true);
actionButton((VButton)e.getSource());
setBusy(false, true);
return;
}
try
{
if (cmd.equals(aReport.getName()))
cmd_report();
else if (cmd.equals(aPrint.getName()))
cmd_print();
else if (cmd.equals(aPrintPreview.getName()))
cmd_print(true);
else if (aExport != null && cmd.equals(aExport.getName()))
cmd_export();
else if (cmd.equals(aEnd.getName()))
cmd_end(false);
else if (cmd.equals(aExit.getName()))
cmd_end(true);
else if (cmd.equals(aNew.getName()))
cmd_new(false);
else if (cmd.equals(aSave.getName()))
cmd_save(true);
else if (cmd.equals(aCopy.getName()))
cmd_new(true);
else if (cmd.equals(aDelete.getName()))
cmd_delete();
else if (cmd.equals(aDeleteSelection.getName()))
cmd_deleteSelection();
else if (cmd.equals(aIgnore.getName()))
cmd_ignore();
else if (cmd.equals(aRefresh.getName()))
cmd_refresh();
else if (cmd.equals(aFind.getName()))
cmd_find();
else if (m_isPersonalLock && cmd.equals(aLock.getName()))
cmd_lock();
else if (cmd.equals(aAttachment.getName()))
cmd_attachment();
else if (cmd.equals(aChat.getName()))
cmd_chat();
else if (cmd.equals(aHistory.getName()))
cmd_history();
else if (cmd.equals(aMulti.getName()))
m_curGC.switchRowPresentation();
else if (cmd.equals(aHome.getName())) {
setBusy(false, false);
AEnv.showWindow(Env.getWindow(0));
return;
}
else if (cmd.equals(aFirst.getName()))
{
m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
m_curTab.navigate(0);
}
else if (cmd.equals(aSwitchLinesUpAction.getName()))
{
m_curGC.getTable().removeEditor();
m_curTab.switchRows(m_curTab.getCurrentRow(), m_curTab.getCurrentRow() - 1, m_curGC.getTable().getSortColumn(), m_curGC.getTable().isSortAscending());
m_curGC.getTable().requestFocus();
}
else if (cmd.equals(aPrevious.getName()))
{
m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) {
m_curTab.switchRows(m_curTab.getCurrentRow(), m_curTab.getCurrentRow() - 1, m_curGC.getTable().getSortColumn(), m_curGC.getTable().isSortAscending());
} else {
m_curTab.navigateRelative(-1);
}
}
else if (cmd.equals(aSwitchLinesDownAction.getName()))
{
m_curGC.getTable().removeEditor();
m_curTab.switchRows(m_curTab.getCurrentRow(), m_curTab.getCurrentRow() + 1, m_curGC.getTable().getSortColumn(), m_curGC.getTable().isSortAscending());
m_curGC.getTable().requestFocus();
}
else if (cmd.equals(aNext.getName()))
{
m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) {
m_curTab.switchRows(m_curTab.getCurrentRow(), m_curTab.getCurrentRow() + 1, m_curGC.getTable().getSortColumn(), m_curGC.getTable().isSortAscending());
} else {
m_curTab.navigateRelative(+1);
}
}
else if (cmd.equals(aLast.getName()))
{
m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
m_curTab.navigate(m_curTab.getRowCount()-1);
}
else if (cmd.equals(aParent.getName()))
cmd_parent();
else if (cmd.equals(aDetail.getName()))
cmd_detail();
else if (cmd.equals(aZoomAcross.getName()))
cmd_zoomAcross();
else if (cmd.equals(aRequest.getName()))
cmd_request();
else if (cmd.equals(aArchive.getName()))
cmd_archive();
else if (aWorkflow != null && cmd.equals(aWorkflow.getName()))
{
if (m_curTab.getRecord_ID() <= 0)
;
else if (m_curTab.getTabNo() == 0 && m_mWorkbench.getMWindow(getWindowIndex()).isTransaction())
AEnv.startWorkflowProcess(m_curTab.getAD_Table_ID(), m_curTab.getRecord_ID());
else
AEnv.startWorkflowProcess(m_curTab.getAD_Table_ID(), m_curTab.getRecord_ID());
}
else if (aWinSize != null && cmd.equals(aWinSize.getName()))
cmd_winSize();
else if (cmd.equals(aHelp.getName()))
cmd_help();
else if (cmd.equals(aLogout.getName()))
cmd_logout();
else if (cmd.equals(aShowAllWindow.getName()))
m_WindowMenu.expose();
else if (!AEnv.actionPerformed (e.getActionCommand(), m_curWindowNo, this))
log.log(Level.SEVERE, "No action for: " + cmd);
}
catch (Exception ex)
{
log.log(Level.SEVERE, cmd, ex);
String msg = ex.getMessage();
if (msg == null || msg.length() == 0)
msg = ex.toString();
msg = Msg.parseTranslation(m_ctx, msg);
ADialog.error(m_curWindowNo, this, "Error", msg);
}
m_curWinTab.requestFocusInWindow();
setBusy(false, true);
}
JFrame top = Env.getWindow(0);
if (top instanceof AMenu) {
((AMenu)top).logout();
}
}
{
GridField field = m_curTab.getField(button.getColumnName());
return m_curTab.processCallout(field);
}
private void cmd_new (
boolean copy)
{
log.config("copy=" + copy);
if (!m_curTab.isInsertRecord())
{
log.warning("Insert Record disabled for Tab");
return;
}
m_curGC.stopEditor(true);
m_curGC.acceptEditorChanges();
if(aSave.isEnabled()){
if (Env.isAutoCommit(m_ctx, m_curWindowNo))
{
if (!cmd_save(true))
{
return;
}
}
else if (ADialog.ask(m_curWindowNo, this, "SaveChanges?", m_curTab.getCommitWarning()))
{
if (!cmd_save(true))
{
return;
}
}
else
m_curTab.dataIgnore();
}
if (copy && m_curTab.getCurrentRow() < 0)
copy = false;
m_curTab.dataNew (copy);
m_curGC.dynamicDisplay(0);
}
{
if (m_curTab.isReadOnly())
return;
int keyID = m_curTab.getRecord_ID();
if (ADialog.ask(m_curWindowNo, this, "DeleteRecord?"))
if (m_curTab.dataDelete())
m_curGC.rowChanged(false, keyID);
m_curGC.dynamicDisplay(0);
}
if (m_curTab.isReadOnly())
return;
JPanel messagePanel = new JPanel();
JList list = new JList();
JScrollPane scrollPane = new JScrollPane(list);
Vector<String> data = new Vector<String>();
final String keyColumnName = m_curTab.getKeyColumnName();
String sql = null;
if (! "".equals(keyColumnName)) {
sql = MLookupFactory.getLookup_TableDirEmbed(Env.getLanguage(m_ctx), keyColumnName, "[?","?]")
.replace("[?.?]", "?");
}
int noOfRows = m_curTab.getRowCount();
for(int i = 0; i < noOfRows; i++)
{
StringBuffer displayValue = new StringBuffer();
if ("".equals(keyColumnName))
{
ArrayList<String> parentColumnNames = m_curTab.getParentColumnNames();
for (Iterator<String> iter = parentColumnNames.iterator(); iter.hasNext();)
{
String columnName = iter.next();
GridField field = m_curTab.getField(columnName);
if(field.isLookup()){
Lookup lookup = field.getLookup();
if (lookup != null){
displayValue = displayValue.append(lookup.getDisplay(m_curTab.getValue(i,columnName))).append(" | ");
} else {
displayValue = displayValue.append(m_curTab.getValue(i,columnName)).append(" | ");
}
} else {
displayValue = displayValue.append(m_curTab.getValue(i,columnName)).append(" | ");
}
}
} else {
final int id = m_curTab.getKeyID(i);
String value = DB.getSQLValueStringEx(null, sql, id);
if (value != null)
value = value.replace(" - ", " | ");
displayValue.append(value);
if (displayValue.length() == 0 || CLogMgt.isLevelFine())
{
if (displayValue.length() > 0)
displayValue.append(" | ");
displayValue.append("<").append(id).append(">");
}
}
data.add(displayValue.toString());
}
list.setListData(data);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
messagePanel.add(scrollPane);
final JOptionPane pane = new JOptionPane(
messagePanel,
JOptionPane.QUESTION_MESSAGE,
JOptionPane.OK_CANCEL_OPTION);
final JDialog deleteDialog = pane.createDialog(this.getParent(), Msg.getMsg(m_ctx, "DeleteSelection"));
deleteDialog.setVisible(true);
Integer okCancel = (Integer) pane.getValue();
if(okCancel != null && okCancel == JOptionPane.OK_OPTION)
{
log.fine("ok");
Object[] selectedValues = list.getSelectedValues();
for (int i = 0; i < selectedValues.length; i++)
{
log.fine(selectedValues[i].toString());
}
int[] indices = list.getSelectedIndices();
Arrays.sort(indices);
int offset = 0;
for (int i = 0; i < indices.length; i++)
{
m_curTab.navigate(indices[i]-offset);
int keyID = m_curTab.getRecord_ID();
if (m_curTab.dataDelete())
{
m_curGC.rowChanged(false, keyID);
offset++;
}
}
m_curGC.dynamicDisplay(0);
}
else
{
log.fine("cancel");
}
}
public boolean cmd_save (
boolean manualCmd)
{
if (m_curAPanelTab != null)
manualCmd = false;
log.config("Manual=" + manualCmd);
m_errorDisplayed = false;
m_curGC.stopEditor(true);
m_curGC.acceptEditorChanges();
if (m_curAPanelTab != null)
{
m_curAPanelTab.saveData();
aSave.setEnabled(false);
}
if (m_curTab.getCommitWarning().length() > 0 && m_curTab.needSave(true, false))
if (!ADialog.ask(m_curWindowNo, this, "SaveChanges?", m_curTab.getCommitWarning()))
return false;
boolean retValue = m_curTab.dataSave(manualCmd);
if (manualCmd && !retValue && !m_errorDisplayed)
{
showLastError();
}
if (retValue)
m_curGC.rowChanged(true, m_curTab.getRecord_ID());
if (manualCmd) {
m_curGC.dynamicDisplay(0);
if (!isNested)
m_window.setTitle(getTitle());
}
if(m_curGC.isDetailGrid() && retValue){
m_curGC.getGCParent().refreshMTab(m_curGC);
}
return retValue;
}
String msg = CLogger.retrieveErrorString(null);
if (msg != null)
ADialog.error(m_curWindowNo, this, null, msg);
else
ADialog.error(m_curWindowNo, this, "SaveIgnored");
setStatusLine(Msg.getMsg(m_ctx, "SaveIgnored"), true);
}
{
m_curGC.stopEditor(false);
if (m_curAPanelTab != null)
{
m_curAPanelTab.loadData();
}
m_curTab.dataIgnore();
m_curGC.dynamicDisplay(0);
}
{
cmd_save(false);
m_curTab.dataRefreshAll();
m_curGC.dynamicDisplay(0);
}
{
log.info("");
if (!MRole.getDefault().isCanReport(m_curTab.getAD_Table_ID()))
{
ADialog.error(m_curWindowNo, this, "AccessCannotReport");
return;
}
cmd_save(false);
MQuery query = new MQuery(m_curTab.getTableName());
String queryColumn = m_curTab.getLinkColumnName();
if (queryColumn.length() == 0)
queryColumn = m_curTab.getKeyColumnName();
String infoName = null;
String infoDisplay = null;
for (int i = 0; i < m_curTab.getFieldCount(); i++)
{
GridField field = m_curTab.getField(i);
if (field.isKey())
infoName = field.getHeader();
if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo") )
&& field.getValue() != null)
infoDisplay = field.getValue().toString();
if (infoName != null && infoDisplay != null)
break;
}
if (queryColumn.length() != 0)
{
if (queryColumn.endsWith("_ID"))
query.addRestriction(queryColumn, MQuery.EQUAL,
new Integer(Env.getContextAsInt(m_ctx, m_curWindowNo, queryColumn)),
infoName, infoDisplay);
else
query.addRestriction(queryColumn, MQuery.EQUAL,
Env.getContext(m_ctx, m_curWindowNo, queryColumn),
infoName, infoDisplay);
}
new AReport (m_curTab.getAD_Table_ID(), aReport.getButton(), query, this, m_curWindowNo, m_curTab.getWhereExtended());
}
{
int record_ID = m_curTab.getRecord_ID();
log.info("ID=" + record_ID);
if (record_ID <= 0)
return;
MQuery query = new MQuery();
String link = m_curTab.getKeyColumnName();
if (link.length() == 0)
link = m_curTab.getLinkColumnName();
if (link.length() != 0)
{
if (link.endsWith("_ID"))
query.addRestriction(link, MQuery.EQUAL,
new Integer(Env.getContextAsInt(m_ctx, m_curWindowNo, link)));
else
query.addRestriction(link, MQuery.EQUAL,
Env.getContext(m_ctx, m_curWindowNo, link));
}
new AZoomAcross(aZoomAcross.getButton(), m_curTab.getTableName(),
m_curTab.getAD_Window_ID(), query);
}
{
int record_ID = m_curTab.getRecord_ID();
log.info("ID=" + record_ID);
if (record_ID <= 0)
return;
int AD_Table_ID = m_curTab.getAD_Table_ID();
int C_BPartner_ID = 0;
Object BPartner_ID = m_curTab.getValue("C_BPartner_ID");
if (BPartner_ID != null)
C_BPartner_ID = ((Integer)BPartner_ID).intValue();
new ARequest (aRequest.getButton(), AD_Table_ID, record_ID, C_BPartner_ID);
}
{
int record_ID = m_curTab.getRecord_ID();
log.info("ID=" + record_ID);
if (record_ID <= 0)
return;
int AD_Table_ID = m_curTab.getAD_Table_ID();
new AArchive (aArchive.getButton(), AD_Table_ID, record_ID);
}
{
cmd_print(false);
}
{
int AD_Process_ID = m_curTab.getAD_Process_ID();
log.info("ID=" + AD_Process_ID);
if (AD_Process_ID == 0)
{
cmd_report();
return;
}
cmd_save(false);
int table_ID = m_curTab.getAD_Table_ID();
int record_ID = m_curTab.getRecord_ID();
ProcessInfo pi = new ProcessInfo (getTitle(), AD_Process_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));
pi.setPrintPreview(printPreview);
ProcessCtl.process(this, m_curWindowNo, pi, null);
statusBar.setStatusLine(pi.getSummary(), pi.isError());
}
{
if (m_curTab == null)
return;
cmd_save(false);
new ASearch(aFind,Env.getFrame(this), m_curWindowNo,m_curGC, m_curTab, m_onlyCurrentDays);
}
{
int record_ID = m_curTab.getRecord_ID();
log.info("Record_ID=" + record_ID);
if (record_ID == -1)
{
aAttachment.setEnabled(false);
return;
}
new Attachment (Env.getFrame(this), m_curWindowNo,
m_curTab.getAD_AttachmentID(), m_curTab.getAD_Table_ID(), record_ID, null);
m_curTab.loadAttachments();
aAttachment.setPressed(m_curTab.hasAttachment());
}
{
int record_ID = m_curTab.getRecord_ID();
log.info("Record_ID=" + record_ID);
if (record_ID == -1)
{
aChat.setEnabled(false);
return;
}
String infoName = null;
String infoDisplay = null;
for (int i = 0; i < m_curTab.getFieldCount(); i++)
{
GridField field = m_curTab.getField(i);
if (field.isKey())
infoName = field.getHeader();
if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo") )
&& field.getValue() != null)
infoDisplay = field.getValue().toString();
if (infoName != null && infoDisplay != null)
break;
}
String description = infoName + ": " + infoDisplay;
new AChat (Env.getFrame(this), m_curWindowNo,
m_curTab.getCM_ChatID(), m_curTab.getAD_Table_ID(), record_ID,
description, null);
m_curTab.loadChats();
aChat.setPressed(m_curTab.hasChat());
}
{
log.info("Modifiers=" + m_lastModifiers);
if (!m_isPersonalLock)
return;
int record_ID = m_curTab.getRecord_ID();
if (record_ID == -1)
return;
if ((m_lastModifiers & InputEvent.CTRL_MASK) != 0)
{
new RecordAccessDialog(Env.getFrame(this), m_curTab.getAD_Table_ID(), record_ID);
}
else
{
m_curTab.lock (Env.getCtx(), record_ID, aLock.getButton().isSelected());
m_curTab.loadAttachments();
}
aLock.setPressed(m_curTab.isLocked());
}
{
log.info("");
if (m_mWorkbench.getMWindow(getWindowIndex()).isTransaction())
{
if (m_curTab.needSave(true, true) && !cmd_save(false))
return;
Point pt = new Point (0, aHistory.getButton().getBounds().height);
SwingUtilities.convertPointToScreen(pt, aHistory.getButton());
VOnlyCurrentDays ocd = new VOnlyCurrentDays(Env.getFrame(this), pt);
if (!ocd.isCancel()) {
m_onlyCurrentDays = ocd.getCurrentDays();
if (m_onlyCurrentDays == 1)
{
m_onlyCurrentRows = true;
m_onlyCurrentDays = 0;
}
else
m_onlyCurrentRows = false;
m_curTab.setQuery(null);
MRole role = MRole.getDefault();
int maxRows = role.getMaxQueryRecords();
log.config("OnlyCurrent=" + m_onlyCurrentRows
+ ", Days=" + m_onlyCurrentDays
+ ", MaxRows=" + maxRows);
m_curGC.query(m_onlyCurrentRows, m_onlyCurrentDays, maxRows );
}
else {
if (isFirstTab())
aHistory.setPressed(!m_curTab.isOnlyCurrentRows());
}
}
}
{
log.info("");
Help hlp = new Help (Env.getFrame(this), this.getTitle(), m_mWorkbench.getMWindow(getWindowIndex()));
hlp.setVisible(true);
}
private void cmd_end (
boolean exit)
{
boolean exitSystem = false;
if (!cmd_save(false))
return;
if (exit && ADialog.ask(m_curWindowNo, this, "ExitApplication?"))
exitSystem = true;
Env.getFrame(this).dispose();
if (exitSystem)
AEnv.exit(0);
}
{
Dimension size = getSize();
if (!ADialog.ask(m_curWindowNo, this, "WinSizeSet",
"x=" + size.width + " - y=" + size.height))
{
setPreferredSize(null);
SwingUtilities.getWindowAncestor(this).pack();
size = new Dimension (0,0);
}
MWindow win = new MWindow(m_ctx, m_curTab.getAD_Window_ID(), null);
win.setWindowSize(size);
win.save();
}
{
new AExport(this);
}
{
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;
String col = vButton.getColumnName();
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;
}
if (m_curTab.needSave(true, false))
if (!cmd_save(true))
return;
for (GridTab includedTab : m_curTab.getIncludedTabs())
{
if (includedTab.needSave(true, false))
if(!includedTab.dataSave(true))
return;
}
int table_ID = m_curTab.getAD_Table_ID();
int record_ID = m_curTab.getRecord_ID();
if (record_ID == -1 && m_curTab.getKeyColumnName().equals("AD_Language"))
record_ID = Env.getContextAsInt (m_ctx, m_curWindowNo, "AD_Language_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();
}
if (record_ID == -1 && m_curTab.getKeyColumnName().endsWith("_ID"))
{
ADialog.error(m_curWindowNo, this, "SaveErrorRowNotFound");
return;
}
boolean isProcessMandatory = false;
if (col.equals("PaymentRule"))
{
VPayment vp = new VPayment(m_curWindowNo, m_curTab, vButton);
if (vp.isInitOK())
vp.setVisible(true);
vp.dispose();
if (vp.needSave())
{
cmd_save(false);
cmd_refresh();
}
}
else if (col.equals("DocAction"))
{
isProcessMandatory = true;
VDocAction vda = new VDocAction(m_curWindowNo, m_curTab, vButton, record_ID);
if (vda.getNumberOfOptions() == 0)
{
vda.dispose ();
log.info("DocAction - No Options");
return;
}
else
{
vda.setVisible(true);
if (!vda.isStartProcess())
return;
startWOasking = true;
vda.dispose();
}
}
else if (col.equals("CreateFrom"))
{
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 if (col.equals("Posted") && MRole.getDefault().isShowAcct())
{
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;
}
}
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();
}
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?"))
{
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;
}
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;
}
if (m_curTab.needSave(true, false))
if (!cmd_save(true))
return;
MProcess pr = new MProcess(m_ctx, vButton.getProcess_ID(), null);
int form_ID = pr.getAD_Form_ID();
if (form_ID != 0 )
{
if (m_curTab.needSave(true, false))
if (!cmd_save(true))
return;
FormFrame ff = new FormFrame(getGraphicsConfiguration());
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);
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);
if (dialog.isValidDialog())
{
dialog.validate();
dialog.pack();
AEnv.showCenterWindow(Env.getWindow(m_curWindowNo), dialog);
}
}
}
public void lockUI (ProcessInfo pi)
{
setBusy(true, false);
}
{
boolean notPrint = pi != null
&& pi.getAD_Process_ID() != m_curTab.getAD_Process_ID()
&& pi.isReportingProcess() == false;
setBusy(false, notPrint);
if (notPrint)
{
m_curTab.dataRefresh();
if (pi.isTimeout())
Env.setContext(m_ctx, m_curWindowNo, "Processed", "Y");
m_curGC.dynamicDisplay(0);
setStatusLine(pi.getSummary(), pi.isError());
if ( pi.isError() )
ADialog.error(m_curWindowNo, this, null, pi.getSummary());
ProcessInfoUtil.setLogFromDB(pi);
String logInfo = pi.getLogInfo();
if (logInfo.length() > 0)
ADialog.info(m_curWindowNo, this, Env.getHeader(m_ctx, m_curWindowNo),
pi.getTitle(), logInfo);
}
else
{
setStatusLine(pi.getSummary(), pi.isError());
if ( pi.isError() )
ADialog.error(m_curWindowNo, this, null, pi.getSummary());
}
}
{
return m_isLocked;
}
{
log.config("-");
}
{
return m_curTab;
}
return m_curWinTab.getTabCount();
}
return m_curWinTab.getSelectedIndex();
}
m_curWinTab.setSelectedIndex(index);
}
String title = m_curWinTab.getTitleAt(m_curWinTab.getSelectedIndex());
title = title.substring(title.indexOf("<html>")+6);
title = title.substring(0,title.indexOf('<'));
return title;
}
{
String s = "APanel[curWindowNo=" + m_curWindowNo;
if (m_mWorkbench != null)
s += ",WB=" + m_mWorkbench.toString();
s += "]";
return s;
}
private static final long serialVersionUID = 3837712049468116744L;
private ActionListener al;
private String name;
SwitchAction(String name, KeyStroke accelerator, ActionListener al) {
super(name);
putValue(Action.NAME, name);
putValue(Action.SHORT_DESCRIPTION, name);
putValue(Action.ACCELERATOR_KEY, accelerator);
putValue(Action.ACTION_COMMAND_KEY, name);
this.al = al;
this.name = name;
}
al.actionPerformed(e);
}
return name;
}
}
aSwitchLinesDownAction = new SwitchAction("switchLinesDown", KeyStroke.getKeyStroke(
KeyEvent.VK_DOWN, Event.SHIFT_MASK), this);
aSwitchLinesUpAction = new SwitchAction("switchLinesUp", KeyStroke.getKeyStroke(
KeyEvent.VK_UP, Event.SHIFT_MASK), this);
JTable table = m_curGC.getTable();
table.getInputMap(CPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Event.SHIFT_MASK), "none");
table.getInputMap(CPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
KeyStroke.getKeyStroke(KeyEvent.VK_UP, Event.SHIFT_MASK), "none");
table.getInputMap(CPanel.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Event.SHIFT_MASK), "none");
table.getInputMap(CPanel.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke(KeyEvent.VK_UP, Event.SHIFT_MASK), "none");
getInputMap(CPanel.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Event.SHIFT_MASK),
aSwitchLinesDownAction.getName());
getActionMap().put(aSwitchLinesDownAction.getName(), aSwitchLinesDownAction);
getInputMap(CPanel.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_UP, Event.SHIFT_MASK),
aSwitchLinesUpAction.getName());
getActionMap().put(aSwitchLinesUpAction.getName(), aSwitchLinesUpAction);
}
return isNested;
}
}