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

extensions.FieldFlags.ext Maven / Gradle / Ivy

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

extension extensions::Expression;
extension extensions::Field;
extension extensions::XMAPage;
extension extensions::XMAComponent;
extension org::openxma::dsl::common::extensions::LogUtil;
extension org::openxma::xmadsl::Extensions;
extension extensions::Widgets;


/*
 * Set flags for a field (combination of the default attribute-flag and the 
 * custom field-flag
 */	
XMAWidget setFieldFlags(XMAWidget dataWidget, IField f, boolean isFieldWithSimpleLayout):

	// Cast to IFormaterAttachable in case this interface is implemented
	let canBeMandatoryWidget = dataWidget.castToICanBeMandatory():	
	let editableWidget = dataWidget.castToIEditable():
	let xmaPage = dataWidget.getContainingXMAPage():
	let xmaComponent = xmaPage.getXMAComponent():		
		
	// EnabledFlag	
	dataWidget.setEnabledFlagForWidget(xmaComponent,xmaPage,f)->
	
	// VisibilityFlags (visible, collapsed)
	dataWidget.setVisibilityFlags(xmaComponent,xmaPage,f,isFieldWithSimpleLayout)->
	
	// EditableFlag
	if (editableWidget != null)
		then editableWidget.setEditableFlagForWidget(xmaComponent,xmaPage,f)->	
	
	// MandatoryFlag
	if (canBeMandatoryWidget != null)
		then canBeMandatoryWidget.setMandatoryFlagForWidget(xmaComponent,xmaPage,f)->		

	dataWidget;

/**
 * Create expressions for fieldflags explicit defined for xma widget in a 
 * model-element of the type XMAWidgetGrayLogic. 
 */	
XMAWidget createGrayLogicExpressions(XMAWidgetGrayLogic xmaWidgetGrayLogic, Page page, Component xmadslComponent):	

	// TODO: check if the xma-widget is mapped to a attribute and therefore
	// maybe some parts of graylogic has to be derived from the mapped attribute.
	let widget = xmaWidgetGrayLogic.xmaWidget:
		
	createExpressions(widget,xmaWidgetGrayLogic.fieldFlags,null);

/**
 * Create expressions defined in a logic block
 * This is done in several steps:
 *   1. collect all concerned GuiElements 
 *   2. determine the conditions for the default logic (for each flag of each GuiElement)
 *   3. create the expressions for the default logic
 *   4. append the expressions for the logic of case-blocks  
 */	
Void createLogicBlockExpressions(LogicBlock logicBlock, Page page, Component xmadslComponent, XMAPage xmaPage, XMAComponent xmaComp):
    let guiElementsUsedInLogic = logicBlock.collectAllGuiElementsInLogic():
    
    let variablesForConditionedLogic = logicBlock.conditionedLogic.collect(e|createXMAVariable(e.statusFlag,flex::type::VariableAccess::value,xmaComp,xmaPage,null)):
    putVariablesForConditionedLogic(logicBlock.conditionedLogic,variablesForConditionedLogic)->    
    
    
	guiElementsUsedInLogic.putDefaultConditions(logicBlock.conditionedLogic,xmaPage,xmaComp)->
    logicBlock.logicItem.createDefaultLogicItemExpression(page,xmadslComponent,xmaPage,xmaComp,logicBlock.conditionedLogic)->
    logicBlock.conditionedLogic.createCaseBlockExpressions(page,xmadslComponent,xmaPage,xmaComp);
    
Void putVariablesForConditionedLogic(List[ConditionedLogic] conditionedLogics, List[flex::VariableExpression] variables):
JAVA org.openxma.dsl.generator.helper.ExpressionExtension.putVariablesForConditionedLogic(java.util.List,java.util.List);
    
List[GuiElement] collectAllGuiElementsInLogic(LogicBlock logicBlock):
JAVA org.openxma.dsl.generator.helper.ExpressionExtension.collectAllGuiElementsInLogic(org.openxma.dsl.pom.model.LogicBlock);

Void createDefaultLogicItemExpression(LogicItem logicItem, Page page, Component xmadslComponent, XMAPage xmaPage, XMAComponent xmaComp, List[ConditionedLogic] conditionedLogicBlocks):
	let xmaWidgets = logicItem.guiElement.getGeneratedXMAWidgetsForGuiElement():
	xmaWidgets.createExpressions(logicItem.fieldFlags,null);	
    
Void createCaseBlockExpressions(ConditionedLogic conditionedLogic, Page page, Component xmadslComponent, XMAPage xmaPage, XMAComponent xmaComp):
	//let caseCondition = createCaseCondition(conditionedLogic,xmaPage,xmaComp):    
	conditionedLogic.logicItem.createCaseLogicItemExpression(xmaPage,page,xmadslComponent,conditionedLogic);		
	
Expression concatinateAllByOr(List[Expression] expressions):
JAVA org.openxma.dsl.generator.helper.ExpressionExtension.concatinateAllByOr(java.util.List);		
	
Expression createCaseCondition(ConditionedLogic conditionedLogic, XMAPage xmaPage, XMAComponent xmaComp):
    createXMAVariable(conditionedLogic.statusFlag,flex::type::VariableAccess::value,xmaComp,xmaPage,null);	

/**
 * Put default conditions
 */
Void putDefaultConditions(GuiElement guiElement, List[ConditionedLogic] conditionedLogicBlocks, XMAPage xmaPage, XMAComponent xmaComp):	

    /* visible */    
    let conditionedLogicVisible = conditionedLogicBlocks.select(e|e.logicItem.exists(e|e.guiElement == guiElement && e.fieldFlags.exists(f|VisibleFlag.isInstance(f)))):
    let variablesVisible = conditionedLogicVisible.collect(e|createXMAVariable(e.statusFlag,flex::type::VariableAccess::value,xmaComp,xmaPage,null)):
    /* enabled */    
    let conditionedLogicEnabled = conditionedLogicBlocks.select(e|e.logicItem.exists(e|e.guiElement == guiElement && e.fieldFlags.exists(f|EnabledFlag.isInstance(f)))):
    let variablesEnabled = conditionedLogicEnabled.collect(e|createXMAVariable(e.statusFlag,flex::type::VariableAccess::value,xmaComp,xmaPage,null)):
    /* editable */    
    let conditionedLogicEditable = conditionedLogicBlocks.select(e|e.logicItem.exists(e|e.guiElement == guiElement && e.fieldFlags.exists(f|EditableFlag.isInstance(f)))):
    let variablesEditable = conditionedLogicEditable.collect(e|createXMAVariable(e.statusFlag,flex::type::VariableAccess::value,xmaComp,xmaPage,null)):
    /* collapsed */    
    let conditionedLogicCollapsed = conditionedLogicBlocks.select(e|e.logicItem.exists(e|e.guiElement == guiElement && e.fieldFlags.exists(f|CollapsedFlag.isInstance(f)))):
    let variablesCollapsed = conditionedLogicCollapsed.collect(e|createXMAVariable(e.statusFlag,flex::type::VariableAccess::value,xmaComp,xmaPage,null)):    
    /* mandatory */    
    let conditionedLogicMandatory = conditionedLogicBlocks.select(e|e.logicItem.exists(e|e.guiElement == guiElement && e.fieldFlags.exists(f|MandatoryFlag.isInstance(f)))):
    let variablesMandatory = conditionedLogicMandatory.collect(e|createXMAVariable(e.statusFlag,flex::type::VariableAccess::value,xmaComp,xmaPage,null)):            
        
    // put to GuiElement
    guiElement.putDefaultCondition(variablesVisible,conditionedLogicVisible,VisibleFlag)->
    guiElement.putDefaultCondition(variablesEnabled,conditionedLogicEnabled,EnabledFlag)->    
    guiElement.putDefaultCondition(variablesEditable,conditionedLogicEnabled,EditableFlag)->
    guiElement.putDefaultCondition(variablesCollapsed,conditionedLogicCollapsed,CollapsedFlag)->
    guiElement.putDefaultCondition(variablesMandatory,conditionedLogicMandatory,MandatoryFlag)->          

	null;
	
Void removeDefaultConditions(GuiElement guiElement):
JAVA org.openxma.dsl.generator.helper.ExpressionExtension.removeDefaultConditions(org.openxma.dsl.pom.model.GuiElement);		
	
Void putDefaultCondition(GuiElement guiElement, List[flex::VariableExpression] variableExpression, List[ConditionedLogic] conditionedLogics, Object clazz):
JAVA org.openxma.dsl.generator.helper.ExpressionExtension.putDefaultCondition(org.openxma.dsl.pom.model.GuiElement,java.util.List,java.util.List,java.lang.Object);

flex::Expression getDefaultCondition(XMAWidget widget, Object clazz):
JAVA org.openxma.dsl.generator.helper.ExpressionExtension.getDefaultCondition(at.spardat.xma.guidesign.XMAWidget,java.lang.Object);	      
        
Void createCaseLogicItemExpression(LogicItem logicItem, XMAPage xmaPage, Page page, Component xmadslComponent, ConditionedLogic conditionedLogic):
	createLogicItemExpression(logicItem,page,xmadslComponent,conditionedLogic);
       
Void createLogicItemExpression(LogicItem logicItem, Page page, Component xmadslComponent, ConditionedLogic conditionedLogic):
	let xmaWidgets = logicItem.guiElement.getGeneratedXMAWidgetsForGuiElement():
	xmaWidgets.createExpressions(logicItem.fieldFlags,conditionedLogic);
	
flex::Expression concatenateLogicConditions(flex::Expression expr, Object defaultConditionsObj, Object flag, ConditionedLogic conditionedLogic, flex::Expression previousExpression,Boolean defaultValue):
JAVA org.openxma.dsl.generator.helper.ExpressionExtension.concatenateLogicConditions(at.spardat.xma.guidesign.flex.Expression,java.lang.Object,java.lang.Object,org.openxma.dsl.pom.model.ConditionedLogic,at.spardat.xma.guidesign.flex.Expression,java.lang.Boolean);	
	
/**
 * Create expressions for a widget and given fieldFlags
 */ 	
XMAWidget createExpressions(XMAWidget widget, List[FieldFlag] fieldFlags, ConditionedLogic conditionedLogic):
	
	let xmaPage = widget.getContainingXMAPage():
	let xmaComponent = xmaPage.getXMAComponent():
	
	let editableWidget = widget.castToIEditable():
	let canBeMandatoryWidget = widget.castToICanBeMandatory():	
	
	let enabledFlag = fieldFlags.typeSelect(EnabledFlag).first():
	let visibleFlag = fieldFlags.typeSelect(VisibleFlag).first():
				
	let xmaEnabledExpr = (enabledFlag != null) ? enabledFlag.createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,null):null:	
	let xmaVisibleExpr = (visibleFlag != null) ? visibleFlag.createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,null):null:
		
	let collapseGroup = widget.getCollapseGroupForWidget():
	
	// default conditions (derived from logic block)	
	let defaultConditions = widget.getDefaultConditions():      
	
	// This widget is part of a collapseGroup and therefore a collapseExpression can be applied
	(collapseGroup != null) 
		? (	let collapsedFlag = fieldFlags.typeSelect(CollapsedFlag).first():
			let xmaCollapsedExpr = (collapsedFlag != null) ? createCollapsedExpression(collapsedFlag,xmaComponent,xmaPage,null):null:
			(xmaCollapsedExpr != null)
				? collapseGroup.setExprCollapsed(concatenateLogicConditions(xmaCollapsedExpr,defaultConditions,CollapsedFlag,conditionedLogic,collapseGroup.exprCollapsed,false))								 
				: null )
		: null->		
	
	if (xmaEnabledExpr != null) then widget.setExprEnabled(concatenateLogicConditions(xmaEnabledExpr,defaultConditions,EnabledFlag,conditionedLogic,widget.exprEnabled,true))->
	if (xmaVisibleExpr != null) then widget.setExprVisible(concatenateLogicConditions(xmaVisibleExpr,defaultConditions,VisibleFlag,conditionedLogic,widget.exprVisible,true))->	
			
	if (editableWidget != null) then (
		let editableFlag = fieldFlags.typeSelect(EditableFlag).first():
		let xmaEditableExpr = (editableFlag != null) ? editableFlag.createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,null):null:		
		if (xmaEditableExpr != null) then editableWidget.setExprEditable(concatenateLogicConditions(xmaEditableExpr,defaultConditions,EditableFlag,conditionedLogic,editableWidget.exprEditable,true)))->
			
	if (canBeMandatoryWidget != null) then (
		let mandatoryFlag = fieldFlags.typeSelect(MandatoryFlag).first():
		let xmaMandatoryExpr = (mandatoryFlag != null) ? mandatoryFlag.createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,null):null:
		if (xmaMandatoryExpr != null) then canBeMandatoryWidget.setExprMandatory(concatenateLogicConditions(xmaMandatoryExpr,defaultConditions,MandatoryFlag,conditionedLogic,canBeMandatoryWidget.exprMandatory,false)))->								

	widget;		
	
Object getDefaultConditions(XMAWidget widget):
JAVA org.openxma.dsl.generator.helper.ExpressionExtension.getDefaultConditions(at.spardat.xma.guidesign.XMAWidget);
			
	
/*
 * Set the editable-flag for a widget
 */		
IFormaterAttachable setEditableFlagForWidget(IEditable widget, XMAComponent xmaComponent, XMAPage xmaPage, IField f):

// DataObjectVariable
	let dov = f.object:

	// Expressions defined in flags 
	let xmaEditableExpr = f.getEditableFlag().createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,dov):

	widget.setExprEditable(xmaEditableExpr)->
	widget;			

/*
 * Set the mandatory-flag for a widget
 */		
IFormaterAttachable setMandatoryFlagForWidget(flex::ICanBeMandatory widget, XMAComponent xmaComponent, XMAPage xmaPage, IField f):

	// DataObjectVariable
	let dov = f.object:

	// Expressions defined in flags 
	let xmaMandatoryExpr = f.getMandatoryFlag().createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,dov):
	let xmaRequiredExpr = f.getAttribute().attributProperties.typeSelect(RequiredFlag).first().createXMAExpressionFromAttributeFlag(xmaComponent,xmaPage,dov):	
	
	let expr = or(xmaRequiredExpr,xmaMandatoryExpr):	

	widget.setExprMandatory(expr)->
	widget;
	
			
EnabledFlag getEnabledFlag(IField f):
	null;
EnabledFlag getEnabledFlag(CustomizeableField f):
	f.fieldFlags.typeSelect(EnabledFlag).first();
	
VisibleFlag getVisibleFlag(IField f):
	null;
VisibleFlag getVisibleFlag(CustomizeableField f):
	f.fieldFlags.typeSelect(VisibleFlag).first();
	
CollapsedFlag getCollapseFlag(IField f):
	null;
CollapsedFlag getCollapseFlag(CustomizeableField f):
	f.fieldFlags.typeSelect(CollapsedFlag).first();
	
EditableFlag getEditableFlag(IField f):
	null;
EditableFlag getEditableFlag(CustomizeableField f):	
	f.fieldFlags.typeSelect(EditableFlag).first();
	
MandatoryFlag getMandatoryFlag(IField f):
	null;	
MandatoryFlag getMandatoryFlag(CustomizeableField f):
	f.fieldFlags.typeSelect(MandatoryFlag).first();
		
		
/*
 * Set the enabled-flag for a widget
 */	
XMAWidget setEnabledFlagForWidget(XMAWidget dataWidget, XMAComponent xmaComponent, XMAPage xmaPage, IField f):

	// DataObjectVariable
	let dov = f.object:
	
	// Expressions defined in flags 
	let enabledFlag = f.getEnabledFlag():
	let xmaEnabledExpr = (enabledFlag != null) ? enabledFlag.createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,dov):null:
	
	let readOnlyFlag = f.getAttribute().attributProperties.typeSelect(ReadOnlyFlag).first():
	let xmaReadOnlyExpr = (readOnlyFlag != null) ? readOnlyFlag.createXMAExpressionFromAttributeFlag(xmaComponent,xmaPage,dov):null:		
	
	let expr = and(not(xmaReadOnlyExpr),xmaEnabledExpr):
	
	dataWidget.setExprEnabled(expr)->	

dataWidget;

flex::Expression createCollapsedExpression(CollapsedFlag collapseFlag, XMAComponent xmaComponent, XMAPage xmaPage, DataObjectVariable dov) :
	let xmaCollapsedExprField = collapseFlag.createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,dov):
	(collapseFlag.availableSpecified == true) 
		? not(xmaCollapsedExprField) 
		: xmaCollapsedExprField;	

/*
 * VisibilityFlags (visible, collapsed)
 */
XMAWidget setVisibilityFlags(XMAWidget dataWidget, XMAComponent xmaComponent, XMAPage xmaPage, IField f, boolean isFieldWithSimpleLayout):

	// DataObjectVariable
	let dov = f.object:
		
	// Expressions defined in flags 
	let xmaVisibleExprField = f.getVisibleFlag().createXMAExpressionFromFieldFlag(xmaComponent,xmaPage,dov):
	let xmaCollapsedExprField = createCollapsedExpression(f.getCollapseFlag(),xmaComponent,xmaPage,dov):	
	let xmaAvailableExpr = f.getAttribute().attributProperties.typeSelect(AvailableFlag).first().createXMAExpressionFromAttributeFlag(xmaComponent,xmaPage,dov):			
		
	// Collapsed-flag only supported for simple layout
	if (isFieldWithSimpleLayout) then (

		let clonedXmaAvailableExpr = (xmaAvailableExpr != null) ? xmaAvailableExpr.cloneExpression():null:
		let expr = or(not(clonedXmaAvailableExpr),xmaCollapsedExprField):
		let collapseGroup = dataWidget.getCollapseGroupForWidget():				
					
		collapseGroup.setExprCollapsed(expr)
		)->
		
	// Visible-flag	
	dataWidget.setExprVisible(and(xmaAvailableExpr,xmaVisibleExprField))->
			
	dataWidget;
	
flex::CollapseGroup getCollapseGroupForWidget(XMAWidget widget):
JAVA org.openxma.dsl.generator.helper.FieldFlags.getCollapseGroupForWidget(at.spardat.xma.guidesign.XMAWidget);
	
/*
 * Create a xma-expression of the expression of a field-flag
 */	
flex::Expression createXMAExpressionFromFieldFlag(FieldFlag flag, XMAComponent comp, XMAPage page, DataObjectVariable dov):
	(flag.expression != null)
		? flag.expression.createXMAExpression(comp,page,dov)
		: null;

/*
 * Create a xma-expression of the expression of a attribute-flag
 */	
flex::Expression createXMAExpressionFromAttributeFlag(AttributeFlag flag, XMAComponent comp, XMAPage page, DataObjectVariable dov):
	(flag.expression != null)
		? flag.expression.createXMAExpression(comp,page,dov)
		: null;		






© 2015 - 2024 Weber Informatics LLC | Privacy Policy