Search in sources :

Example 1 with DocumentDescriptor

use of de.metas.ui.web.window.descriptor.DocumentDescriptor 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 2 with DocumentDescriptor

use of de.metas.ui.web.window.descriptor.DocumentDescriptor in project metasfresh-webui-api by metasfresh.

the class WindowRestController method getLayout.

@GetMapping("/{windowId}/{tabId}/layout")
public ResponseEntity<JSONDocumentLayout> getLayout(@PathVariable("windowId") final String windowIdStr, @PathVariable("tabId") final String tabIdStr, @RequestParam(name = PARAM_Advanced, required = false, defaultValue = PARAM_Advanced_DefaultValue) final boolean advanced, final WebRequest request) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final DetailId detailId = DetailId.fromJson(tabIdStr);
    final DocumentDescriptor descriptor = documentCollection.getDocumentDescriptorFactory().getDocumentDescriptor(windowId);
    DocumentPermissionsHelper.checkWindowAccess(descriptor.getEntityDescriptor(), userSession.getUserRolePermissions());
    return ETagResponseEntityBuilder.ofETagAware(request, descriptor).includeLanguageInETag().cacheMaxAge(userSession.getHttpCacheMaxAge()).map(desc -> desc.getLayout().getDetail(detailId)).jsonOptions(() -> newJSONOptions().setShowAdvancedFields(advanced).build()).toJson(JSONDocumentLayout::ofDetailTab);
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) WindowId(de.metas.ui.web.window.datatypes.WindowId) JSONDocumentLayout(de.metas.ui.web.window.datatypes.json.JSONDocumentLayout) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

DocumentDescriptor (de.metas.ui.web.window.descriptor.DocumentDescriptor)2 Stopwatch (com.google.common.base.Stopwatch)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 JSONDocumentLayout (de.metas.ui.web.window.datatypes.json.JSONDocumentLayout)1 DetailId (de.metas.ui.web.window.descriptor.DetailId)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 GetMapping (org.springframework.web.bind.annotation.GetMapping)1