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

extensions.Field.ext Maven / Gradle / Ivy

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

extension extensions::Expression;
extension extensions::Validation;
extension org::openxma::dsl::common::extensions::LogUtil;
extension extensions::XMAComponent;
extension org::openxma::xmadsl::Extensions;
				
/**
 * Creates all XMAConstraints for a Attribute and returns the created 
 * XMAConstraints in a List.
 */
List[flex::Constraint] createXMAConstraintsForAttribute(Attribute attribute, XMAComponent comp, XMAPage page):

	let xmaConstraints = (List[flex::Constraint]){}:	
	let additionalAttributeConstraints = attribute.attributProperties.typeSelect(AttributeValidationProperty).first().constraints:
	
	// 1. XMAConstraint for basic validator (which is defined by the type) 	
	let basicXmaConstraint = createXMAConstraintsForType(attribute.type,comp,page):
	(basicXmaConstraint != null) 
		? xmaConstraints.add(basicXmaConstraint)
		: null ->
			
	// 2. XMAConstraints for additional defined Constraints (which are defined by the attribute)
	if (additionalAttributeConstraints != null) then ( 		
		additionalAttributeConstraints.createXMAConstraintsFromXmadslConstraints(comp,page,xmaConstraints)
	)->
	
	xmaConstraints;
	
/**
 * Create a XMAConstraint from an openXMA-dsl-Constraint and adds the created
 * XMAConstraint to the list of XMAConstraints.
 */	
Void createXMAConstraintsFromXmadslConstraints(Constraint constraint, XMAComponent comp, XMAPage page, List[flex::Constraint] xmaConstraints):

    let xmaConstraint=constraint.createXMAConstraintsFromXmadslConstraint(comp,page):           
	xmaConstraints.add(xmaConstraint)->
	null;

/**
 * Create a XMAConstraint from an openXMA-dsl-Constraint
 */ 
flex::Constraint createXMAConstraintsFromXmadslConstraint(Constraint constraint, XMAComponent comp, XMAPage page):

	let xmaConstraint = constraint.validatorReference.createXMAConstraint(null, constraint.condition,comp,page):	
	xmaConstraint;	

// Create a list of all XMA-Constraints	
flex::Constraint createXMAConstraintsForType(DataTypeAndTypeParameter dataTypeAndTypeParameter, XMAComponent comp, XMAPage page):

	let validatorReference = dataTypeAndTypeParameter.getValidatorReferenceDefinition():
	let definitionStack = dataTypeAndTypeParameter.getDefinitionStack():
	
	// The validatorReference may be null e.g. for a enum type with a implicit Validator definition 
	let xmaConstraint = (validatorReference != null) ? validatorReference.createXMAConstraint(definitionStack,null,comp,page):null:

	xmaConstraint;	

flex::Constraint createXMAConstraint(ValidatorReference validatorReference, List[DataTypeAndTypeParameter] definitionStack, EqualityExpr expr, XMAComponent comp, XMAPage page):
	let constraint = new flex::Constraint:		
	let xmaValidator = createXMAValidator(validatorReference,definitionStack):
	let xmaExpression = (expr != null)?expr.createXMAExpression(comp,page,null):null:
		
	(xmaValidator != null)
		? (constraint.setValidator(xmaValidator)->
		   constraint.setCondition(xmaExpression)->	
		   constraint)
		
		: null
	;
	
guidesign::Validator createXMAValidator(ValidatorReference validatorReference, List[DataTypeAndTypeParameter] definitionStack):
JAVA org.openxma.dsl.generator.helper.ValidatorExtension.createXMAValidator(org.openxma.dsl.core.model.ValidatorReference, java.util.List);

boolean isFormatterAttachable(emf::EObject widget):	
JAVA org.openxma.dsl.generator.helper.Util.isFormatterAttachable(org.eclipse.emf.ecore.EObject);

// Cast to IFormaterAttachable
guidesign::IFormaterAttachable castToIFormaterAttachable(guidesign::XMAWidget widget):
JAVA org.openxma.dsl.generator.helper.Util.castToIFormaterAttachable(at.spardat.xma.guidesign.XMAWidget);

guidesign::flex::ICanBeMandatory castToICanBeMandatory(guidesign::XMAWidget widget):
JAVA org.openxma.dsl.generator.helper.Util.castToICanBeMandatory(at.spardat.xma.guidesign.XMAWidget);

// Cast to IEditable
guidesign::IEditable castToIEditable(guidesign::XMAWidget widget):
JAVA org.openxma.dsl.generator.helper.Util.castToIEditable(at.spardat.xma.guidesign.XMAWidget);

// Cast to XMAWidget
guidesign::XMAWidget castToXMAWidget(emf::EObject obj):
JAVA org.openxma.dsl.generator.helper.Util.castToXMAWidget(org.eclipse.emf.ecore.EObject);
	
// Create compoundValidator for XMAWidget
guidesign::flex::CompoundValidator attachCompoundValidatorToWidget(emf::EObject widget, guidesign::ValidInState validInState):
JAVA org.openxma.dsl.generator.helper.Util.attachCompoundValidatorToWidget(org.eclipse.emf.ecore.EObject,at.spardat.xma.guidesign.ValidInState);	

// Access logger
//String log(String description):
//JAVA org.openxma.dsl.generator.helper.Util.log(java.lang.String);

ValidatorReference getFormat(IField f):
	null;
ValidatorReference getFormat(CustomizeableField f):
	f.format;
	
List[Constraint] getConstraints(IField f):
	null;
List[Constraint] getConstraints(CustomizeableField f):
	f.constraints;	
	

// Create and attach CompoundValidator to XMAWidget
XMAWidget createAndAttachCompoundValidator(XMAWidget widget, IField f): 

	let xmaPage = widget.getContainingXMAPage():
	let xmaComponent = xmaPage.getXMAComponent():
	let compoundValidator = widget.createAndAttachCompoundValidatorForAttribute(f.getAttribute(),xmaComponent,xmaPage):
	let constraints = f.getConstraints():
	let format = f.getFormat():

	if (constraints != null) 
		then compoundValidator.constraints.addAll(constraints.createXMAConstraintsFromXmadslConstraint(xmaComponent,xmaPage))->
	
	if (format != null)
		then compoundValidator.overrideFormatter(format)->		
	
	widget;

/*
 * Create a formatter and constraints for a text widget.
 *
 * This is intended to be used only for text fields which are not attached to
 * a attribute.
 */ 
XMAWidget createFormatterForText(XMAText text): 

	let xmaPage = text.getContainingXMAPage():
	let xmaComponent = xmaPage.getXMAComponent():
	let compoundValidator = text.createAndAttachTextFormatter(xmaComponent,xmaPage):
	let constraints = (compoundValidator != null) ? text.getConstraintsForTextField() : null : 
	
	(constraints != null) 
		? constraints.createXMAConstraintsFromXmadslConstraints(xmaComponent,xmaPage,compoundValidator.constraints)
		: null ->	

	text;	
	
// Create and attach CompoundValidator to XMAWidget
flex::CompoundValidator createAndAttachCompoundValidatorForAttribute(XMAWidget widget, Attribute attr, XMAComponent comp, XMAPage page): //List[flex::Constraint] constraints
	
	let xmaConstraints = (List[flex::Constraint]){}:
	let attributeFormatter = attr.attributProperties.typeSelect(AttributeValidationProperty).first().format:
	
	xmaConstraints.addAll(attr.createXMAConstraintsForAttribute(comp,page))->	
	
	// Create compoundValidator if possible
	(attributeFormatter != null || xmaConstraints.size>0) 
		? ( let compoundValidator = attachCompoundValidatorToWidget(widget, new ValidInState):					
			(attributeFormatter == null)		
				? (
					(xmaConstraints.size>0)
						? compoundValidator.setFormatter(xmaConstraints.get(0).validator)
						: null)
				: compoundValidator.overrideFormatter(attributeFormatter)->			
				
			compoundValidator.constraints.addAll(xmaConstraints)->				
			compoundValidator)
		: null;

/*
 * Create a default Validator which consists just of formatter which is
 * a StringValidator.
 */		
flex::CompoundValidator createAndAttachTextFormatter(XMAText text, XMAComponent comp, XMAPage page): 
JAVA org.openxma.dsl.generator.helper.ValidatorExtension.createAndAttachTextFormatter(at.spardat.xma.guidesign.XMAText, at.spardat.xma.guidesign.XMAComponent, at.spardat.xma.guidesign.XMAPage);

List getConstraintsForTextField(XMAText text):
JAVA org.openxma.dsl.generator.helper.ValidatorExtension.getConstraintsForTextField(at.spardat.xma.guidesign.XMAText);

guidesign::Validator overrideFormatter(flex::CompoundValidator cpv, ValidatorReference validatorReference):
JAVA org.openxma.dsl.generator.helper.ValidatorExtension.overrideFormatter(at.spardat.xma.guidesign.flex.CompoundValidator,org.openxma.dsl.core.model.ValidatorReference);
	
/**
 * Compose the default widget name for a field
 */	
String composeDefaultWidgetNameForField(IField f):
	composeDefaultWidgetNameForAttribute(f.object,f.getAttribute());	
	
/**
 * Compose the default widget name for a attribute
 */	
String composeDefaultWidgetNameForAttribute(DataObjectVariable dov, PresentableFeature feature):
JAVA org.openxma.dsl.pom.naming.PomNameProvider.composeDefaultWidgetNameForAttribute(org.openxma.dsl.pom.model.DataObjectVariable,org.openxma.dsl.dom.model.PresentableFeature);
		

	
	
		



			




© 2015 - 2024 Weber Informatics LLC | Privacy Policy