Search in sources :

Example 1 with DocumentLayoutBuildException

use of de.metas.ui.web.window.exceptions.DocumentLayoutBuildException 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)

Aggregations

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 DocumentLayoutBuildException (de.metas.ui.web.window.exceptions.DocumentLayoutBuildException)1 GridTabVO (org.compiere.model.GridTabVO)1 GridWindowVO (org.compiere.model.GridWindowVO)1