Search in sources :

Example 11 with GridWindowVO

use of org.compiere.model.GridWindowVO in project metasfresh-webui-api by metasfresh.

the class DefaultDocumentDescriptorLoader method load.

public DocumentDescriptor load() {
    // Mark as executed
    if (_executed) {
        throw new IllegalStateException("Already executed");
    }
    _executed = true;
    if (AD_Window_ID <= 0) {
        throw new DocumentLayoutBuildException("No window found for AD_Window_ID=" + AD_Window_ID);
    }
    final Stopwatch stopwatch = Stopwatch.createStarted();
    final GridWindowVO gridWindowVO = GridWindowVO.builder().ctx(Env.getCtx()).windowNo(// TODO: get rid of WindowNo from GridWindowVO
    0).adWindowId(AD_Window_ID).adMenuId(// N/A
    -1).loadAllLanguages(true).applyRolePermissions(false).build();
    // shall never happen
    Check.assumeNotNull(gridWindowVO, "Parameter gridWindowVO is not null");
    final DocumentDescriptor.Builder documentBuilder = DocumentDescriptor.builder();
    final DocumentLayoutDescriptor.Builder layoutBuilder = DocumentLayoutDescriptor.builder().setWindowId(WindowId.of(gridWindowVO.getAD_Window_ID())).setStopwatch(stopwatch).putDebugProperty("generator-name", toString());
    // 
    // Layout: Create UI sections from main tab
    final GridTabVO mainTabVO = gridWindowVO.getTab(GridTabVO.MAIN_TabNo);
    final LayoutFactory rootLayoutFactory = LayoutFactory.ofMainTab(gridWindowVO, mainTabVO);
    {
        layoutBuilder.setCaption(rootLayoutFactory.getWindowCaption());
        layoutBuilder.setSingleRowLayout(rootLayoutFactory.layoutSingleRow());
        layoutBuilder.setGridView(rootLayoutFactory.layoutGridView());
        layoutBuilder.setSideListView(rootLayoutFactory.layoutSideListView());
        // Set special field names
        // IMPORTANT: do this after you created all layouts
        layoutBuilder.setDocumentSummaryElement(rootLayoutFactory.createSpecialElement_DocumentSummary()).setDocActionElement(rootLayoutFactory.createSpecialElement_DocStatusAndDocAction());
    }
    // Layout: Create UI details from child tabs
    for (final GridTabVO detailTabVO : gridWindowVO.getChildTabs(mainTabVO.getTabNo())) {
        // Skip sort tabs because they are not supported
        if (detailTabVO.IsSortTab) {
            continue;
        }
        // Skip tabs which were already used/embedded in root layout
        if (rootLayoutFactory.isSkipAD_Tab_ID(detailTabVO.getAD_Tab_ID())) {
            continue;
        }
        final LayoutFactory detailLayoutFactory = LayoutFactory.ofIncludedTab(gridWindowVO, mainTabVO, detailTabVO);
        final DocumentLayoutDetailDescriptor.Builder layoutDetail = detailLayoutFactory.layoutDetail();
        layoutBuilder.addDetailIfValid(layoutDetail);
        final DocumentEntityDescriptor.Builder detailEntityBuilder = detailLayoutFactory.documentEntity();
        rootLayoutFactory.documentEntity().addIncludedEntity(detailEntityBuilder.build());
    }
    // 
    // Build & return the final descriptor
    final DocumentDescriptor descriptor = documentBuilder.setLayout(layoutBuilder.build()).setEntityDescriptor(rootLayoutFactory.documentEntity().build()).build();
    logger.debug("Descriptor loaded in {}: {}", stopwatch, descriptor);
    return descriptor;
}
Also used : DocumentLayoutDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutDescriptor) Stopwatch(com.google.common.base.Stopwatch) GridTabVO(org.compiere.model.GridTabVO) DocumentLayoutDetailDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutDetailDescriptor) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) DocumentLayoutBuildException(de.metas.ui.web.window.exceptions.DocumentLayoutBuildException) GridWindowVO(org.compiere.model.GridWindowVO) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 12 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
    WebDoc doc = null;
    HttpSession sess = request.getSession();
    WebSessionCtx wsc = WebSessionCtx.get(request);
    if (wsc == null) {
        WebUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    //  Parameter: AD_Window_ID
    int AD_Window_ID = WebUtil.getParameterAsInt(request, "AD_Window_ID");
    //  Get Parameter: Menu_ID
    int AD_Menu_ID = WebUtil.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 = WebUtil.getParameterAsInt(request, "AD_Record_ID");
    int AD_Table_ID = WebUtil.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 = WebDoc.createPopup("No Context");
            doc.addPopupClose(wsc.ctx);
        }
        //	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;
        }
    }
    //  Clean up old Window
    WWindowStatus ws = WWindowStatus.get(request);
    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;
        WebUtil.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);
    }
    if (ws.curTab.isSingleRow())
        doc = getSR_Form(request.getRequestURI(), wsc, ws);
    else
        doc = getMR_Form(request.getRequestURI(), wsc, ws);
    //	fini
    log.fine("Fini");
    //	log.trace(log.l6_Database, doc.toString());
    WebUtil.createResponse(request, response, this, null, doc, false);
    log.fine("Closed");
}
Also used : SQLException(java.sql.SQLException) WebDoc(org.compiere.util.WebDoc) HttpSession(javax.servlet.http.HttpSession) ResultSet(java.sql.ResultSet) GridWindowVO(org.compiere.model.GridWindowVO) PreparedStatement(java.sql.PreparedStatement) WebSessionCtx(org.compiere.util.WebSessionCtx)

Example 13 with GridWindowVO

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

the class Base method test.

/**
	 *  Base Test
	 */
public static void test() {
    //$NON-NLS-1$
    System.out.println("** Before Init **");
    getMemoryUsed();
    Properties ctx = Login.initTest(false);
    //	Log.printProperties(System.getProperties(), "System", false);
    //
    //  cleanup Init
    System.gc();
    //
    System.out.println("** Before Creation **");
    long start = getMemoryUsed();
    //  *******************************************************************
    //  Table=100, Shipper=142, Window=102, Reference=101
    int AD_Window_ID = 102;
    long startTime = System.currentTimeMillis();
    GridWindowVO vo = GridWindowVO.create(Env.getCtx(), 1, AD_Window_ID);
    GridWindow w = new GridWindow(vo);
    long endDef = System.currentTimeMillis();
    System.out.println("Load Definition Time in ms = " + String.valueOf(endDef - startTime));
    if (//  optional step
    1 == 2) {
        w.loadCompete();
        long endDefComplete = System.currentTimeMillis();
        System.out.println("Load Definition Complete Time in ms = " + String.valueOf(endDefComplete - startTime));
    }
    w.query();
    long endData = System.currentTimeMillis();
    System.out.println("Load Data Time in ms = " + String.valueOf(endData - startTime));
    w.loadCompete();
    long endDataComplete = System.currentTimeMillis();
    System.out.println("Load Data Complete Time in ms = " + String.valueOf(endDataComplete - startTime));
    w.getTab(0).navigate(0);
    //  *******************************************************************
    //		sleep();
    System.out.println("** Before Dispose **");
    getMemoryUsed();
    w.dispose();
    //		sleep();
    //
    System.out.println("** Before GC **");
    getMemoryUsed();
    w = null;
    System.gc();
    System.out.println("** After GC **");
    getMemoryUsed();
    System.gc();
    System.out.println("** Final **");
    long complete = System.currentTimeMillis();
    System.out.println("Complete Time in ms = " + String.valueOf(complete - startTime));
    long end = getMemoryUsed();
    System.out.println("Memory increase in kB = End-Start=" + String.valueOf((end - start) / 1024));
    listThreads();
    //
    System.out.println("API Test");
    System.out.println("64.72=" + MConversionRate.convert(ctx, new BigDecimal(100.0), 116, 100, 0, 0));
    System.out.println("0.647169=" + MConversionRate.getRate(116, 100, null, 0, 0, 0));
    System.out.println("12.5=" + MUOMConversion.convert(101, 102, new BigDecimal(100.0), true));
}
Also used : GridWindow(org.compiere.model.GridWindow) GridWindowVO(org.compiere.model.GridWindowVO) Properties(java.util.Properties) BigDecimal(java.math.BigDecimal)

Example 14 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;
    String locale = Env.getLanguage(Env.getCtx()).getLocale().toString();
    if (//	try cache
    AD_Window_ID != 0 && Ini.isCacheWindow()) {
        synchronized (windowCache) {
            CCache<Integer, GridWindowVO> cache = windowCache.get(locale);
            if (cache != null) {
                mWindowVO = cache.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) {
            synchronized (windowCache) {
                CCache<Integer, GridWindowVO> cache = windowCache.get(locale);
                if (cache == null) {
                    cache = new CCache<Integer, GridWindowVO>("AD_Window", 10);
                    windowCache.put(locale, cache);
                }
                cache.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<Object> 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 15 with GridWindowVO

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

the class ADServiceImpl method getADWindow.

public WindowDocument getADWindow(int WindowNo, int AD_Window_ID, int AD_Menu_ID) throws XFireFault {
    authenticate(webServiceName, "getADWindow");
    WindowDocument wc = (WindowDocument) WindowCache.get(new String("" + AD_Window_ID + "_" + AD_Menu_ID));
    //if (wc != null)			return wc;
    WindowDocument res = WindowDocument.Factory.newInstance();
    Window w = res.addNewWindow();
    GridWindowVO wo = getWindowVO(WindowNo, AD_Window_ID, AD_Menu_ID);
    if (wo != null) {
        fillWindow(w, wo);
        WindowCache.put(new String("" + AD_Window_ID + "_" + AD_Menu_ID), res);
    }
    return res;
}
Also used : Window(pl.x3E.adInterface.Window) GridWindowVO(org.compiere.model.GridWindowVO) WindowDocument(pl.x3E.adInterface.WindowDocument)

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