Search in sources :

Example 6 with GridWindowVO

use of org.compiere.model.GridWindowVO in project adempiere by adempiere.

the class ADServiceImpl method getWindowTabData.

public WindowTabDataDocument getWindowTabData(WindowTabDataReqDocument reqd) throws XFireFault {
    authenticate(webServiceName, "getWindowTabData");
    WindowTabDataReq req = reqd.getWindowTabDataReq();
    WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
    WindowTabData wd = ret.addNewWindowTabData();
    DataSet ds = wd.addNewDataSet();
    WWindowStatus ws = WWindowStatus.get(WindowStatusMap, req.getWindowNo(), false, 0, false, 0);
    if (ws == null) {
        GridWindowVO wo = getWindowVO(req.getWindowNo(), req.getADWindowID(), req.getADMenuID());
        ws = new WWindowStatus(wo);
        WindowStatusMap.put(new Integer(req.getWindowNo()), ws);
        //!!!!!!!!!!
        ws.curTab.query(ws.mWindow.isTransaction());
        ws.curTab.navigate(0);
        ws.curTab.setSingleRow(true);
    }
    if (ws.curTab.getTabNo() != req.getPrevTabNo()) {
        ws.curTab.removeDataStatusListener(ws.ads);
        ws.curTab = ws.mWindow.getTab(req.getPrevTabNo());
        // false
        ws.curTab.query(ws.mWindow.isTransaction());
        ws.curTab.navigate(0);
        ws.updateRecIDMap();
    }
    /*
    	if (ws.curTab.getCurrentRow() != req.getPrevRecNo())  
    	{
    		if (req.getPrevRecNo() >=0)
    			ws.curTab.navigate( req.getPrevRecNo() );     		
    	}
    	*/
    // we assume that it RecordID
    int prevRecNo = ws.getRowNoFromRecordID(req.getPrevRecNo());
    if (ws.curTab.getCurrentRow() != prevRecNo) {
        if (prevRecNo >= 0)
            ws.curTab.navigate(prevRecNo);
    }
    WWindowStatus.changeTabIfNeeded(ws, req.getTabNo());
    if (req.getGetData()) {
        if (req.getFromZoom()) {
            WWindowStatus ws2 = WWindowStatus.get(WindowStatusMap, req.getFromZoomWindowID(), true, req.getFromZoomTabID(), true, req.getFromZoomRowID());
            System.out.println(ws2.curTab.getTableName());
            GridField field = ws2.curTab.getField(req.getFromZoomColumnName());
            ws2 = null;
            if (field == null)
                return null;
            MLookup lookup = (MLookup) field.getLookup();
            if (lookup == null)
                return null;
            //
            MQuery zoomQuery = lookup.getZoomQuery();
            Object value = field.getValue();
            if (value == null) {
                value = req.getFromZoomColumnValue();
            }
            //	If not already exist or exact value
            if (zoomQuery == null || value != null) {
                //	ColumnName might be changed in GridTab.validateQuery
                zoomQuery = new MQuery();
                zoomQuery.addRestriction(req.getFromZoomColumnName(), MQuery.EQUAL, value);
            }
            ws.curTab.setQuery(zoomQuery);
            //ws.curTab.query(ws.mWindow.isTransaction());
            // ADEMPIERE/COMPIERE
            // adempiere
            ws.curTab.query(false, 0, 0);
        //ws.curTab.query(false, 0); // compiere
        } else {
            DataRow findDR = req.getFindCriteria();
            MQuery currentQuery = ws.curTab.getQuery();
            MQuery newQuery = createQuery(ws.curTab.getTableName(), findDR);
            if (findDR.getFieldArray().length > 0) {
                //(!currentQuery.getWhereClause().equals( newQuery.getWhereClause() )) { // change the query for zak�adki
                ws.curTab.setQuery(newQuery);
                //ws.curTab.query(ws.mWindow.isTransaction());
                //ADEMPIERE/COMPIERE
                // adempiere
                ws.curTab.query(false, 0, 0);
            //ws.curTab.query(false, 0); // compiere
            }
        }
        int rc = 0;
        if (req.getRowCount() > 0)
            rc = req.getRowCount();
        else
            rc = ws.curTab.getRowCount();
        int initRowNo = 0;
        if (req.getRowStart() > 0)
            initRowNo = req.getRowStart();
        //ok
        int lastRow = Math.min(rc, initRowNo + MAX_ROWS);
        //initRowNo + 5; // only for testing
        wd.setNumRows(lastRow);
        //lastRow += initRowNo;
        // ok
        wd.setTotalRows(ws.curTab.getRowCount());
        //wd.setTotalRows( 5 ); // only for testing
        wd.setStartRow(initRowNo);
        Map<Integer, Integer> RecordIDMap = ws.getRecordIDMap();
        try {
            RecordIDMap.clear();
            for (int lineNo = initRowNo; lineNo < lastRow; lineNo++) {
                ws.curTab.navigate(lineNo);
                int recID = ws.curTab.getRecord_ID();
                RecordIDMap.put(recID, lineNo);
                DataRow dr = ds.addNewDataRow();
                //System.out.println("row "+lineNo);
                fillDataRow(dr, ws, false, false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        ;
        if (lastRow <= ws.curTab.getRowCount()) {
            //last row
            ws.updateRecIDMap();
        }
    }
    return ret;
}
Also used : DataSet(pl.x3E.adInterface.DataSet) MLookup(org.compiere.model.MLookup) WindowTabData(pl.x3E.adInterface.WindowTabData) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) DataRow(pl.x3E.adInterface.DataRow) TransformerException(javax.xml.transform.TransformerException) WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) WindowTabDataReq(pl.x3E.adInterface.WindowTabDataReq) GridWindowVO(org.compiere.model.GridWindowVO)

Example 7 with GridWindowVO

use of org.compiere.model.GridWindowVO 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>&nbsp;");
                    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;
}
Also used : GridWindow(org.compiere.model.GridWindow) MQuery(org.compiere.model.MQuery) Dimension(java.awt.Dimension) GridField(org.compiere.model.GridField) Point(java.awt.Point) VSortTab(org.compiere.grid.VSortTab) GridTab(org.compiere.model.GridTab) GridSynchronizer(org.compiere.grid.GridSynchronizer) GridWindowVO(org.compiere.model.GridWindowVO) CompiereColor(org.compiere.plaf.CompiereColor) VTabbedPane(org.compiere.grid.VTabbedPane) GridWorkbench(org.compiere.model.GridWorkbench) GridController(org.compiere.grid.GridController) Component(java.awt.Component)

Example 8 with GridWindowVO

use of org.compiere.model.GridWindowVO in project adempiere by adempiere.

the class AEnv method getMWindowVO.

/**
	 *  Get Window Model
	 *
	 *  @param WindowNo  Window No
	 *  @param AD_Window_ID window
	 *  @param AD_Menu_ID menu
	 *  @return Model Window Value Obkect
	 */
public static GridWindowVO getMWindowVO(int WindowNo, int AD_Window_ID, int AD_Menu_ID) {
    log.config("Window=" + WindowNo + ", AD_Window_ID=" + AD_Window_ID);
    GridWindowVO mWindowVO = null;
    if (//	try cache
    AD_Window_ID != 0 && Ini.isCacheWindow()) {
        mWindowVO = s_windows.get(AD_Window_ID);
        if (mWindowVO != null) {
            mWindowVO = mWindowVO.clone(WindowNo);
            log.info("Cached=" + mWindowVO);
        }
    }
    //  Create Window Model on Client
    if (mWindowVO == null) {
        log.config("create local");
        mWindowVO = GridWindowVO.create(Env.getCtx(), WindowNo, AD_Window_ID, AD_Menu_ID);
        if (mWindowVO != null)
            s_windows.put(AD_Window_ID, mWindowVO);
    }
    //	from Client
    if (mWindowVO == null)
        return null;
    //  Check (remote) context
    if (!mWindowVO.ctx.equals(Env.getCtx())) {
        //  Remote Context is called by value, not reference
        //  Add Window properties to context
        Enumeration<?> keyEnum = mWindowVO.ctx.keys();
        while (keyEnum.hasMoreElements()) {
            String key = (String) keyEnum.nextElement();
            if (key.startsWith(WindowNo + "|")) {
                String value = mWindowVO.ctx.getProperty(key);
                Env.setContext(Env.getCtx(), key, value);
            }
        }
        //  Sync Context
        mWindowVO.setCtx(Env.getCtx());
    }
    return mWindowVO;
}
Also used : GridWindowVO(org.compiere.model.GridWindowVO)

Example 9 with GridWindowVO

use of org.compiere.model.GridWindowVO in project adempiere by adempiere.

the class WWindow method doGet.

/**
	 *  Process the HTTP Get request - Initial Call.
	 *  <br>
	 *  http://localhost/adempiere/WWindow?AD_Window_ID=123
	 *  <br>
	 *  Create Window with request parameters
	 *  AD_Window_ID
	 *  AD_Menu_ID
	 *
	 *  Clean up old/existing window
	 *
	 *  @param request
	 *  @param response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //  Get Session attributes
    MobileDoc doc = null;
    sess = request.getSession();
    MobileSessionCtx wsc = MobileSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    if (wsc == null) {
        MobileUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    String line = request.getParameter("record");
    int lineNo = -1;
    if (!Util.isEmpty(line))
        lineNo = Integer.parseInt(line);
    if (lineNo != -1) {
        ws.curTab.navigate(lineNo);
        ws.curTab.setSingleRow(true);
        doc = getSR_Form(request.getRequestURI(), wsc, ws);
        //
        log.fine("Fini");
        //	log.trace(log.l6_Database, doc.toString());
        MobileUtil.createResponse(request, response, this, null, doc, false);
        return;
    }
    String action = MobileUtil.getParameter(request, "action");
    String strSQL = MobileUtil.getParameter(request, "txtSQL");
    if ("edit".equals(action)) {
        ws.setRO(false);
        doc = getSR_Form(request.getRequestURI(), wsc, ws);
        //
        log.fine("Fini");
        //	log.trace(log.l6_Database, doc.toString());
        MobileUtil.createResponse(request, response, this, null, doc, false);
        return;
    } else if ("insert".equals(action)) {
        if (!ws.curTab.dataNew(false))
            ws.curTab.dataIgnore();
        ws.setRO(false);
        doc = getSR_Form(request.getRequestURI(), wsc, ws);
        //
        log.fine("Fini");
        //	log.trace(log.l6_Database, doc.toString());
        MobileUtil.createResponse(request, response, this, null, doc, false);
        return;
    } else if ("list".equals(action)) {
        ws.setRO(true);
        ws.curTab.setSingleRow(false);
        ws.curTab.query(false);
        ws.curTab.navigate(0);
        doc = getMR_Form(request.getRequestURI(), wsc, ws, ws.curTab.getTabLevel() == 0);
        MobileUtil.createResponse(request, response, this, null, doc, false);
        return;
    } else if (!Util.isEmpty(strSQL)) {
        MQuery query = new MQuery();
        if ("FIND".equals(strSQL)) {
            String value = MobileUtil.getParameter(request, "txtValue");
            String docno = MobileUtil.getParameter(request, "txtDocumentNo");
            String name = MobileUtil.getParameter(request, "txtName");
            String desc = MobileUtil.getParameter(request, "txtDescription");
            if (value != null && value.length() != 0)
                query.addRestriction("UPPER(Value)", MQuery.LIKE, "%" + value.toUpperCase() + "%");
            if (docno != null && docno.length() != 0)
                query.addRestriction("UPPER(DocumentNo)", MQuery.LIKE, "%" + docno.toUpperCase() + "%");
            if (name != null && name.length() != 0)
                query.addRestriction("UPPER(Name)", MQuery.LIKE, "%" + name.toUpperCase() + "%");
            if (desc != null && desc.length() != 0)
                query.addRestriction("(UPPER(Description", MQuery.LIKE, "%" + desc.toUpperCase() + "%");
        } else {
            query.addRestriction(strSQL);
        }
        ws.setRO(true);
        ws.curTab.setSingleRow(false);
        ws.curTab.setQuery(query);
        ws.curTab.query(false);
        ws.curTab.navigate(0);
        doc = getMR_Form(request.getRequestURI(), wsc, ws, ws.curTab.getTabLevel() == 0);
        MobileUtil.createResponse(request, response, this, null, doc, false);
        return;
    } else if ("previous".equals(action)) {
        int curTabLevel = ws.curTab.getTabLevel();
        ws.setRO(true);
        ws.curTab.setSingleRow(true);
        while (curTabLevel <= ws.curTab.getTabLevel()) {
            ws.curTab = ws.mWindow.getTab(ws.curTab.getTabNo() - 1);
        }
        ws.curTab.dataRefresh();
        doc = getSR_Form(request.getRequestURI(), wsc, ws);
        MobileUtil.createResponse(request, response, this, null, doc, false);
        return;
    }
    String tab = request.getParameter("tab");
    int tabNo = -1;
    if (!Util.isEmpty(tab))
        tabNo = Integer.parseInt(tab);
    if (tabNo != -1) {
        ws.mWindow.initTab(tabNo);
        ws.curTab = ws.mWindow.getTab(tabNo);
        ws.curTab.query(false);
        ws.curTab.navigate(0);
        ws.curTab.setSingleRow(false);
        ws.setRO(true);
        doc = getMR_Form(request.getRequestURI(), wsc, ws, false);
        MobileUtil.createResponse(request, response, this, null, doc, false);
        return;
    }
    //  Parameter: AD_Window_ID
    int AD_Window_ID = MobileUtil.getParameterAsInt(request, "AD_Window_ID");
    //  Get Parameter: Menu_ID
    int AD_Menu_ID = MobileUtil.getParameterAsInt(request, "AD_Menu_ID");
    log.info("AD_Window_ID=" + AD_Window_ID + "; AD_Menu_ID=" + AD_Menu_ID);
    String TableName = null;
    //Check to see if Zoom
    int AD_Record_ID = MobileUtil.getParameterAsInt(request, "AD_Record_ID");
    int AD_Table_ID = MobileUtil.getParameterAsInt(request, "AD_Table_ID");
    if (AD_Record_ID != 0 || AD_Table_ID != 0) {
        AD_Window_ID = 0;
        int PO_Window_ID = 0;
        String sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE AD_Table_ID=?";
        try {
            PreparedStatement pstmt = DB.prepareStatement(sql, null);
            pstmt.setInt(1, AD_Table_ID);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                TableName = rs.getString(1);
                AD_Window_ID = rs.getInt(2);
                PO_Window_ID = rs.getInt(3);
            }
            rs.close();
            pstmt.close();
        } catch (SQLException e) {
            log.log(Level.SEVERE, sql, e);
        }
        if (TableName == null || AD_Window_ID == 0) {
            doc = MobileDoc.createPopup("No Context");
        }
        //	PO Zoom ?
        boolean isSOTrx = true;
        if (PO_Window_ID != 0) {
            String whereClause = TableName + "_ID=" + AD_Record_ID;
            isSOTrx = DB.isSOTrx(TableName, whereClause);
            if (!isSOTrx)
                AD_Window_ID = PO_Window_ID;
        }
    }
    if (ws != null) {
        int WindowNo = ws.mWindow.getWindowNo();
        log.fine("Disposing - WindowNo=" + WindowNo + ", ID=" + ws.mWindow.getAD_Window_ID());
        ws.mWindow.dispose();
        Env.clearWinContext(wsc.ctx, WindowNo);
    }
    /**
		 *  New Window data
		 */
    GridWindowVO mWindowVO = GridWindowVO.create(wsc.ctx, s_WindowNo++, AD_Window_ID, AD_Menu_ID);
    if (mWindowVO == null) {
        String msg = Msg.translate(wsc.ctx, "AD_Window_ID") + " " + Msg.getMsg(wsc.ctx, "NotFound") + ", ID=" + AD_Window_ID + "/" + AD_Menu_ID;
        MobileUtil.createErrorPage(request, response, this, msg);
        sess.setAttribute(WWindowStatus.NAME, null);
        return;
    }
    //  Create New Window
    ws = new WWindowStatus(mWindowVO);
    sess.setAttribute(WWindowStatus.NAME, ws);
    //  Query
    if (AD_Record_ID != 0 || AD_Table_ID != 0) {
        //If Zoom
        ws.mWindow.initTab(ws.curTab.getTabNo());
        ws.curTab.setQuery(MQuery.getEqualQuery(TableName + "_ID", AD_Record_ID));
        ws.curTab.query(false);
    } else {
        ws.mWindow.initTab(ws.curTab.getTabNo());
        ws.curTab.query(ws.mWindow.isTransaction());
        ws.curTab.navigate(0);
        ws.curTab.setSingleRow(false);
    }
    //  Create Single/Multi Row
    if (ws.curTab.isSingleRow())
        doc = getSR_Form(request.getRequestURI(), wsc, ws);
    else
        doc = getMR_Form(request.getRequestURI(), wsc, ws, true);
    ws.setRO(true);
    MobileUtil.createResponse(request, response, this, null, doc, false);
    log.fine("Closed");
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) GridWindowVO(org.compiere.model.GridWindowVO) MQuery(org.compiere.model.MQuery) PreparedStatement(java.sql.PreparedStatement)

Example 10 with GridWindowVO

use of org.compiere.model.GridWindowVO in project adempiere by adempiere.

the class WAccountDialog method initAccount.

//	jbInit
/**
	 *	Dyanmic Init.
	 *  When a row is selected, the editor values are set
	 *  (editors do not change grid)
	 *  @return true if initialized
	 */
private boolean initAccount() {
    m_AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID");
    //	Get AcctSchema Info
    if (s_AcctSchema == null || s_AcctSchema.getC_AcctSchema_ID() != m_C_AcctSchema_ID)
        s_AcctSchema = new MAcctSchema(Env.getCtx(), m_C_AcctSchema_ID, null);
    log.config(s_AcctSchema.toString() + ", #" + s_AcctSchema.getAcctSchemaElements().length);
    Env.setContext(Env.getCtx(), m_WindowNo, "C_AcctSchema_ID", m_C_AcctSchema_ID);
    //  Model
    //	Maintain Account Combinations
    int AD_Window_ID = 153;
    GridWindowVO wVO = AEnv.getMWindowVO(m_WindowNo, AD_Window_ID, 0);
    if (wVO == null)
        return false;
    m_mWindow = new GridWindow(wVO);
    m_mTab = m_mWindow.getTab(0);
    // Make sure is the tab is loaded - teo_sarca [ 1659124 ]
    if (!m_mTab.isLoadComplete())
        m_mWindow.initTab(0);
    //  ParameterPanel restrictions
    m_mTab.getField("Alias").setDisplayLength(15);
    m_mTab.getField("Combination").setDisplayLength(15);
    //  Grid restrictions
    m_mTab.getField("AD_Client_ID").setDisplayed(false);
    m_mTab.getField("C_AcctSchema_ID").setDisplayed(false);
    m_mTab.getField("IsActive").setDisplayed(false);
    m_mTab.getField("IsFullyQualified").setDisplayed(false);
    //  don't show fields not being displayed in this environment
    for (int i = 0; i < m_mTab.getFieldCount(); i++) {
        GridField field = m_mTab.getField(i);
        if (//  check context
        !field.isDisplayed(true))
            field.setDisplayed(false);
    }
    //  GridController
    m_adTabPanel.init(null, m_WindowNo, m_mTab, null);
    //  Prepare Parameter
    parameterLayout.makeNoStrip();
    parameterLayout.setOddRowSclass("even");
    parameterLayout.setParent(parameterPanel);
    parameterLayout.setStyle("background-color: transparent;");
    m_rows = new Rows();
    m_rows.setParent(parameterLayout);
    int TabNo = 0;
    //	Alias
    if (s_AcctSchema.isHasAlias()) {
        GridField alias = m_mTab.getField("Alias");
        f_Alias = WebEditorFactory.getEditor(alias, false);
        addLine(alias, f_Alias, false);
    }
    //	Alias
    //	Combination
    GridField combination = m_mTab.getField("Combination");
    f_Combination = WebEditorFactory.getEditor(combination, false);
    addLine(combination, f_Combination, false);
    m_newRow = true;
    /**
		 *	Create Fields in Element Order
		 */
    MAcctSchemaElement[] elements = s_AcctSchema.getAcctSchemaElements();
    for (int i = 0; i < elements.length; i++) {
        MAcctSchemaElement ase = elements[i];
        String type = ase.getElementType();
        boolean isMandatory = ase.isMandatory();
        //
        if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) {
            GridField field = m_mTab.getField("AD_Org_ID");
            f_AD_Org_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_AD_Org_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Account)) {
            GridField field = m_mTab.getField("Account_ID");
            f_Account_ID = WebEditorFactory.getEditor(field, false);
            //	((VLookup)f_Account_ID).setWidth(400);
            addLine(field, f_Account_ID, isMandatory);
            f_Account_ID.addValueChangeListener(this);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
            GridField field = m_mTab.getField("C_SubAcct_ID");
            f_SubAcct_ID = WebEditorFactory.getEditor(field, false);
            //	((VLookup)f_SubAcct_ID).setWidth(400);
            addLine(field, f_SubAcct_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Product)) {
            GridField field = m_mTab.getField("M_Product_ID");
            f_M_Product_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_M_Product_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner)) {
            GridField field = m_mTab.getField("C_BPartner_ID");
            f_C_BPartner_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_BPartner_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign)) {
            GridField field = m_mTab.getField("C_Campaign_ID");
            f_C_Campaign_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_Campaign_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom)) {
            GridField field = m_mTab.getField("C_LocFrom_ID");
            f_C_LocFrom_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_LocFrom_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo)) {
            GridField field = m_mTab.getField("C_LocTo_ID");
            f_C_LocTo_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_LocTo_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Project)) {
            GridField field = m_mTab.getField("C_Project_ID");
            f_C_Project_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_Project_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion)) {
            GridField field = m_mTab.getField("C_SalesRegion_ID");
            f_C_SalesRegion_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_SalesRegion_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx)) {
            GridField field = m_mTab.getField("AD_OrgTrx_ID");
            f_AD_OrgTrx_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_AD_OrgTrx_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Activity)) {
            GridField field = m_mTab.getField("C_Activity_ID");
            f_C_Activity_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_Activity_ID, isMandatory);
        } else //	User1
        if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1)) {
            GridField field = m_mTab.getField("User1_ID");
            f_User1_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User1_ID.setLabel(ase.getName());				
            addLine(field, f_User1_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
            GridField field = m_mTab.getField("User2_ID");
            f_User2_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User2_ID.setLabel(ase.getName());				
            addLine(field, f_User2_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList3)) {
            GridField field = m_mTab.getField("User3_ID");
            f_User3_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User3_ID.setLabel(ase.getName());
            addLine(field, f_User3_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList4)) {
            GridField field = m_mTab.getField("User4_ID");
            f_User4_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User4_ID.setLabel(ase.getName());
            addLine(field, f_User4_ID, isMandatory);
        }
    }
    //	Create Fields in Element Order
    //	Add description
    m_newRow = true;
    Row row = new Row();
    f_Description.setStyle("font-decoration: italic;");
    row.appendChild(f_Description);
    row.setSpans("4");
    row.setStyle("background-color: transparent;");
    m_rows.appendChild(row);
    //	Finish
    m_query = new MQuery();
    m_query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
    m_query.addRestriction("IsFullyQualified", MQuery.EQUAL, "Y");
    if (m_mAccount.C_ValidCombination_ID == 0)
        m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
    else {
        MQuery query = new MQuery();
        query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
        query.addRestriction("C_ValidCombination_ID", MQuery.EQUAL, m_mAccount.C_ValidCombination_ID);
        m_mTab.setQuery(query);
    }
    m_mTab.query(false);
    m_adTabPanel.getGridTab().addDataStatusListener(this);
    m_adTabPanel.activate(true);
    if (!m_adTabPanel.isGridView())
        m_adTabPanel.switchRowPresentation();
    statusBar.setStatusLine(s_AcctSchema.toString());
    statusBar.setStatusDB("?");
    //	Initial value
    if (m_mAccount.C_ValidCombination_ID != 0)
        m_mTab.navigate(0);
    log.config("fini");
    return true;
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) GridWindow(org.compiere.model.GridWindow) GridWindowVO(org.compiere.model.GridWindowVO) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) Row(org.adempiere.webui.component.Row) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) Rows(org.adempiere.webui.component.Rows)

Aggregations

GridWindowVO (org.compiere.model.GridWindowVO)18 MQuery (org.compiere.model.MQuery)9 GridWindow (org.compiere.model.GridWindow)8 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 GridField (org.compiere.model.GridField)4 HttpSession (javax.servlet.http.HttpSession)3 Dimension (java.awt.Dimension)2 GridController (org.compiere.grid.GridController)2 GridTab (org.compiere.model.GridTab)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MAcctSchemaElement (org.compiere.model.MAcctSchemaElement)2 WebDoc (org.compiere.util.WebDoc)2 WebSessionCtx (org.compiere.util.WebSessionCtx)2 Stopwatch (com.google.common.base.Stopwatch)1 DocumentDescriptor (de.metas.ui.web.window.descriptor.DocumentDescriptor)1 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)1 DocumentLayoutDescriptor (de.metas.ui.web.window.descriptor.DocumentLayoutDescriptor)1 DocumentLayoutDetailDescriptor (de.metas.ui.web.window.descriptor.DocumentLayoutDetailDescriptor)1