All Downloads are FREE. Search and download functionalities are using the official Maven repository.

extensions.XMAComponent.ext Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
import guidesign;
import dom;
import core;
import pom;

extension extensions::Expression;
extension extensions::XMAComposite;
extension extensions::XMAFunction;
extension extensions::Events;
extension extensions::XMAPage;
extension extensions::EntityExtension;
extension extensions::Field;
extension extensions::FieldFlags;
extension extensions::XMAStatusFlag;
extension extensions::XMAComponent;
extension org::openxma::xmadsl::Extensions;
extension extensions::ClearXMAComponent;
extension extensions::Customization;
extension extensions::Names;
extension extensions::Widgets;

extension org::eclipse::xtend::util::stdlib::cloning;

// declaration and typing of the gloabal var
/*
Component getXmadslComponent():
    let model = ((ComponentModel)GLOBALVAR dslComponent):
    model.component;
    */

Void reloadXMAComponent(Model componentModel):

    let xmaModels = componentModel.elements.typeSelect(Import).select(e|e.importURI.endsWith(".xma")):

    switch (xmaModels.size) {
        case 0: error("Imported xma-model not found")
        case 1: ( let uri = xmaModels.first().importURI:
                  log("Reload xma model: "+uri)
                 // -> loadAndCache(uri)
                )
        default: error("More then 1 xma-model imported")
    }->

    null;

// Extend XMAComponent
XMAComponent extendXMAComponent(Model componentModel):

    let xmadslComponent = componentModel.elements.typeSelect(Component).first():
    (xmadslComponent != null) 
        ? (
            let xmaComp = xmadslComponent.xmaComponent: //
            let tm = createTimeMeasurement("removeElementsWhichAreCreatedFromXmadsl"):
            tm.beginTimeMeasurement()->
            // Remove old generated elements
            xmaComp.removeElementsWhichAreCreatedFromXmadsl(xmadslComponent)->
            tm.endTimeMeasurement()->
            // Generate new elements
            xmadslComponent.transformXmadslToXMA(xmaComp)->
            xmaComp )
        : null;

// Extend XMAComponent
XMAComponent extendXMAComponent(CustomizeComponentModel customizeComponentModel):

    let xmadslComponent = customizeComponentModel.component:
    let xmaComp = xmadslComponent.xmaComponent: //
    let customizedXmadslComponent = (Component)clone(xmadslComponent):

    //printBeginComment("Creating xma model...")->

    // Remove old generated elements
    xmaComp.removeElementsWhichAreCreatedFromXmadsl(xmadslComponent)->

    // Add customizations into Xmadsl-Component
    customizeComponentModel.customizations.addCustomization(xmadslComponent,customizedXmadslComponent)->

    // Transform the xmadsl-model to/into the xma-model
    customizedXmadslComponent.transformXmadslToXMA(xmaComp)->

    //printEndComment("done")->

    xmaComp;

Void printBeginComment(String comment):
    log(comment)->
    null;

Void printEndComment(String comment):
    log(comment)->
    null;

List[Page] getPagesOfComponentHierarchical(Component xmadslComponent):
JAVA org.openxma.dsl.generator.helper.PageExtension.getPagesOfComponentHierarchical(org.openxma.dsl.pom.model.Component);

Void transformXmadslToXMA( Component xmadslComponent, XMAComponent xmaComp):

    let xmadslPages = getPagesOfComponentHierarchical(xmadslComponent):

    // Add inherited properties to XmadslPages
    xmadslComponent.pages.typeSelect(XmadslPage).select(e|e.template != null).addInheritedProperties(xmadslComponent)->

    // Extend the Xmadsl-model
    xmadslComponent.extendPresentationModel()->

    // Functions of Component and of Pages
    xmadslComponent.commands.extendFunction(xmaComp)->
    
    // Component properties
    xmadslComponent.extendComponentProperties(xmaComp)->
    
    // Statusflags
    if (xmadslComponent.conditionsBlock != null)
        then xmaComp.stateFlags.addAll(xmadslComponent.conditionsBlock.statusFlags.createXmaStatusFlag(xmaComp,null,null))->

    // DataVariables of Component and of Pages
    xmadslComponent.dataobjects.mergeDataVariablesOfComponent(xmaComp)->
    if (xmadslComponent.events != null) then xmadslComponent.events.extendEventMappingForComponent(xmaComp)->

    // Page (the DataVariables of all pages are already merged at this point)
    xmadslPages.mergeXmadslPage(xmadslComponent,xmaComp)->

    // Extend the new XMA-model
    xmaComp.setDefaultWidgetProperties()->
    
    // Add PML javadoc to XMA javadoc (IDocumentable to IXMADocumentable)
    xmaComp.setSourceModelElementProperty(xmadslComponent) ->
    xmaComp.setJavaDocComments() -> 
    null;

Void addInheritedProperties(XmadslPage page, Component component):
JAVA org.openxma.dsl.generator.helper.InheritePageExtension.addInheritedProperties(org.openxma.dsl.pom.model.XmadslPage, org.openxma.dsl.pom.model.Component);

Void extendPresentationModel(Component xmadslComponent):
JAVA org.openxma.dsl.generator.helper.PresentationModelExtension.extendPresentationModel(org.openxma.dsl.pom.model.Component);

Void extendComponentProperties(Component xmadslComponent, XMAComponent xmaComponent):
JAVA org.openxma.xmadsl.GuidesignExtension.extendComponentProperties(org.openxma.dsl.pom.model.Component,at.spardat.xma.guidesign.XMAComponent);

// Create the default widget properties for all Widgets in the XMAComponent
Void setDefaultWidgetProperties(XMAComponent xmaComp):
JAVA org.openxma.dsl.generator.helper.WidgetExtension.setDefaultWidgetProperties(at.spardat.xma.guidesign.XMAComponent);

Void setJavaDocComments(XMAComponent xmaComp):
JAVA org.openxma.dsl.generator.helper.WidgetExtension.setJavaDocComments(at.spardat.xma.guidesign.XMAComponent);


cached XMAPage mergeXmadslPage(Page page, Component xmadslComponent, XMAComponent xmaComp):

    let xmaPage = xmaComp.findOrCreateXmaPage(page):

    //log("Merge page '"+page.id()+"' -> '"+((xmaPage != null) ? xmaPage.id() : "null") +"'")->

    (xmaPage != null)
        ? (
            page.extendPageProperties(xmaPage,xmaComp)->        
            page.mergeDataVariablesOfPage(xmaPage,xmaComp)->
            page.createWidgets(xmadslComponent,xmaComp)->
            page.createMenus(xmaPage)->
            page.createDataMapping(xmadslComponent,xmaComp)->
            page.commands.extendFunction(xmaComp)->
            page.createEventMapping(xmadslComponent,xmaComp)->
            page.createExpressions(xmadslComponent,xmaComp)->
            xmaPage.setSourceModelElementProperty(page)
          ):null->
    xmaPage;

Void createMenus(Page page, XMAPage xmaPage):
JAVA org.openxma.xmadsl.GuidesignExtension.addMenusToPage(org.openxma.dsl.pom.model.Page,at.spardat.xma.guidesign.XMAPage);

XMAPage findOrCreateXmaPage(XMAComponent xmaComponent, Page page):
JAVA org.openxma.xmadsl.GuidesignExtension.findOrCreateXmaPage(at.spardat.xma.guidesign.XMAComponent,org.openxma.dsl.pom.model.Page);

XMAPage createXMAPage(XMAComponent xmaComponent, Page page):
JAVA org.openxma.xmadsl.GuidesignExtension.createXMAPage(at.spardat.xma.guidesign.XMAComponent,org.openxma.dsl.pom.model.Page);

Void extendPageProperties(Page page, XMAPage xmaPage, XMAComponent xmaComponent):
JAVA org.openxma.xmadsl.GuidesignExtension.extendPageProperties(org.openxma.dsl.pom.model.Page,at.spardat.xma.guidesign.XMAPage,at.spardat.xma.guidesign.XMAComponent);

// Merge data object variables for page
cached Page mergeDataVariablesOfPage(Page page, XMAPage xmaPage, XMAComponent xmaComp):

    // Iterate over each DataVariable
    page.dataobjects.mergeSingleDataVariableOfPage(xmaComp,xmaPage)->
    page;


// Merge each DataVariable of Page
cached BusinessData mergeSingleDataVariableOfPage(DataObjectVariable dv, XMAComponent xmaComp, XMAPage xmaPage):

    let data = createBusinessData(dv.type,xmaComp,dv.name,dv.isCollection):

    xmaPage.businessDataVariables.add(data)->
    data;


// Merge DataObjectVariable of Component
cached BusinessData mergeDataVariablesOfComponent(DataObjectVariable dv, XMAComponent xmaComp):

    let data = createBusinessData(dv.type,xmaComp,dv.name,dv.isCollection):

    xmaComp.businessDataVariables.add(data)->
    data;


// EventMapping
cached Page createEventMapping(Page page,Component xmadslComponent, XMAComponent xmaComp):
    if (page.events != null) then page.events.extendEventMappingForPage(page,xmaComp);

// DataMapping
cached Page createDataMapping(Page page, Component xmadslComponent, XMAComponent xmaComp):

    if (page.dataMapping != null) then (

        let xmaPage = xmaComp.findXMAPage(page):
        let accessibleBusinessData = xmaPage.getAccessibleBusinessData():

        page.dataMapping.mapping.typeSelect(DataMapping).mergeDataMapping(page,accessibleBusinessData,xmaComp,xmaPage)
    );
    
List[XMAComposite] getCompositesToBeExtended(XMAPage xmaPage):
JAVA org.openxma.dsl.generator.helper.PageExtension.getCompositesToBeExtended(at.spardat.xma.guidesign.XMAPage);


// CreateWidgets
cached Page createWidgets(Page page, Component xmadslComponent, XMAComponent xmaComp):

    let xmaPage = xmaComp.findXMAPage(page):
    let accessibleBusinessData = xmaPage.getAccessibleBusinessData():
    let xmaCompositesToBeExtended = getCompositesToBeExtended(xmaPage):

    // Extend XMAComposites
    if (xmaCompositesToBeExtended != null) then (
        xmaCompositesToBeExtended
            .extendCompositeIfPossible(page,accessibleBusinessData,xmadslComponent)
    )->

    page;

List[XMAComposite] getAllCompositesOfPage(XMAPage xmaPage):

    let compositeList = (List[XMAComposite]){}:

    xmaPage.addCompositesOfPageToList(compositeList)->
    compositeList;

List[XMATable] getAllContainedTablesWithinPage(emf::EObject eObj):
JAVA org.openxma.dsl.generator.helper.PageExtension.getAllContainedTablesWithinPage(org.eclipse.emf.ecore.EObject);

Void createFormaterForTable(XMATable xmaTable, XMAPage xmaPage):
JAVA org.openxma.dsl.generator.helper.ComplexTypeExtension.createFormaterForTable(at.spardat.xma.guidesign.XMATable,at.spardat.xma.guidesign.XMAPage);


Void addCompositesOfPageToList(emf::EObject obj, List[XMAComposite] compositeList):

    let contentWhichIsNotAPage = obj.eContents.select(e|XMAPage.isInstance(e)==false):

    if (contentWhichIsNotAPage != null && contentWhichIsNotAPage.size>0) then (
        compositeList.addAll(contentWhichIsNotAPage.typeSelect(XMAComposite))->
        contentWhichIsNotAPage.addCompositesOfPageToList(compositeList)
    )->

    null;

// CreateExpressions
cached Page createExpressions(Page page, Component xmadslComponent, XMAComponent xmaComp):

    let xmaPage = xmaComp.findXMAPage(page):
    let accessibleBusinessData = xmaPage.getAccessibleBusinessData():
    let xmaComposites = xmaPage.getAllCompositesOfPage():
    let xmaTables = xmaPage.getAllContainedTablesWithinPage():

    //log("Composites -> createExpressions for page: "+page.id())->
    //logListElements(xmaComposites)->

    if (ReferencedXMAPage.isInstance(page)) then (
        ((ReferencedXMAPage)page).createExpressionsForDataMappingInPage(accessibleBusinessData)
    )->

    // Expressions for elements defined in Composites
    xmaComposites.createExpressionsForComposite(page,accessibleBusinessData,xmadslComponent)->
    xmaTables.createFormaterForTable(xmaPage)->
    
    // Handle logic block
    handleLogicBlock(xmadslComponent,xmaComp,page,xmaPage)->

    // FieldFlag-expressions for referenced XMA widgets
    if (ReferencedXMAPage.isInstance(page)) then (
        let referencedXMAPage = (ReferencedXMAPage)page:
        if (referencedXMAPage.grayLogic != null && referencedXMAPage.grayLogic.widgetGrayLogic != null) then (
            referencedXMAPage.grayLogic.widgetGrayLogic.createGrayLogicExpressions(page,xmadslComponent)
        )
    )->

    page;
    
Void handleLogicBlock(Component xmadslComponent, XMAComponent xmaComp, Page page, XMAPage xmaPage) :
    if (XmadslPage.isInstance(page)) then (
        let xmadslPage = (XmadslPage)page:
        if (xmadslPage.logicBlock != null) then (
            xmadslPage.logicBlock.createLogicBlockExpressions(page,xmadslComponent,xmaPage,xmaComp)
        )
    )->
    if (TabPage.isInstance(page)) then (
        let tabPage = (TabPage)page:
        if (tabPage.logicBlock != null) then (
            tabPage.logicBlock.createLogicBlockExpressions(page,xmadslComponent,xmaPage,xmaComp)
        )
    )-> 
    if (ReferencedXMAPage.isInstance(page)) then (
        let tabPage = (ReferencedXMAPage)page:
        if (tabPage.logicBlock != null) then (
            tabPage.logicBlock.createLogicBlockExpressions(page,xmadslComponent,xmaPage,xmaComp)
        )
    );  


Void createExpressionsForDataMappingInPage(ReferencedXMAPage referencedXMAPage, List businessDataList):
    if (referencedXMAPage.dataMapping != null) then (
        referencedXMAPage.dataMapping.mapping.createExpressionsForDataMapping(businessDataList)
    )->
    null;

Void createExpressionsForDataMapping(DataMapping dataMapping, List businessDataList):

    let control = dataMapping.control:
    let field = dataMapping.field:

    (control != null)
        ? ((XMAWidget.isInstance(control))
            ? ( let xmaWidget = control.castToXMAWidget():
                field.createExpressionsForWidget(xmaWidget,businessDataList))
            : null)
        : error("Can not create expressions for data-mapping: XMAWidget is null for: "+dataMapping+", field = "+field.id());


// Merge data mapping
cached DataMapping mergeDataMapping(DataMapping dm, Page page, List businessDataList, XMAComponent xmaComp, XMAPage xmaPage):

    let elementId = (dm.control != null ? dm.control.id() : dm.bindingElement.id()):
    let dataWidget = xmaPage.getWidgetForName(elementId):
    let dataObject = dm.field.object:
    let attribute = dm.field.getAttribute():

    let businessData = (BusinessData)businessDataList.selectFirst(e|((BusinessData)e).namInstance == dataObject.name):
    let bdAttribute = businessData.attributes.selectFirst(e|e.namAttrVal == attribute.name):        

    dataWidget.setBDAttribute(bdAttribute)->
    
    // Create a CompoundValidator except in case of mapping a ObjectProperty (which has already a Validator)
    (ObjectProperty.isInstance(dm.bindingElement) == false && dataWidget.isFormatterAttachable())
        ? dataWidget.createAndAttachCompoundValidatorForAttribute(attribute,xmaComp,xmaPage)          
        : null ->
    dm;

// Create BusinessData and add it to businessdataCol of xmaComp

BusinessData createBusinessData(ComplexType type, XMAComponent xmaComp, String name, Boolean isCollection):
JAVA org.openxma.dsl.generator.helper.Util.createBusinessData(org.openxma.dsl.dom.model.ComplexType,at.spardat.xma.guidesign.XMAComponent, java.lang.String, java.lang.Boolean);

XMAPage getContainingXMAPage(emf::EObject obj):
JAVA org.openxma.dsl.pom.scoping.PomElementCollector.getContainingXMAPage(org.eclipse.emf.ecore.EObject);
        
/**
 * Find the XMA-page which corresponds to the XMADSL-page.
 */     
XMAPage findXMAPage(XMAComponent c, Page p):
JAVA org.openxma.xmadsl.GuidesignExtension.findXMAPage(at.spardat.xma.guidesign.XMAComponent,org.openxma.dsl.pom.model.Page);
    
/**
 * Get the XMAComponent for a XMAPage
 */ 
cached XMAComponent getXMAComponent(XMAPage p):
    ((XMAComponent)p.eRootContainer);
        
/**
 * Get and if necessary create the applicationcontext
 */ 
flex::XMAApplicationContext getXMAApplicationContext(XMAComponent c):
JAVA org.openxma.xmadsl.GuidesignExtension.getXMAApplicationContext(at.spardat.xma.guidesign.XMAComponent);
    




© 2015 - 2024 Weber Informatics LLC | Privacy Policy