AX 2012: SysOperation-Framework: Ein eigenes Attribut erstellen

Die Attribute des SysOperation-Frameworks sind über Klassen abgebildet, die von SysAttribute abgeleitet sind. Dadurch ist es relativ einfach möglich, sich eigene Attribute zu erstellen.
Im folgenden habe ich ein solches Attribute erstellt, mit Hilfe dessen ich die Hintergrundfarbe eines Controls im vom Framework generierten Dialog verändern kann.

Folgende Schritte sind dafür notwendig:

  1. Erstellen einer Klasse, welche von SysAttribute abgeleitet ist
    Dabei ist die Methode new() Dreh- und Angelpunkt der Logik, da man über die Parameter der new()-Methode die möglichen Parameter des Attributes festlegt. 
  2. Erweitern der Klasse SysOperationDataMemberInfo
    Hier wird vor allem die new()-Methode um den neuen Wert für die Hintergrundfarbe erweitert.
  3. Erweitern der Klasse SysOperationAttributedDataMemberInfo
    Hier wird das neue Attribut abgefragt und entsprechend berücksichtigt.
  4. Erweitern der Klasse SysOperationAutomaticUIBuilder
    In dieser Klasse wird das neue Attribut abgefragt und die Hintergrundfarbe dem Control zugewiesen.

Erstellen einer Klasse, welche von SysAttribute abgeleitet ist

class SysOperationBackroundAttribute extends SysAttribute
{
    int backGroundColor;
    #SysOperation
}

 

public int backGroundColor()
{
    return backGroundColor;
}

 

public void new(int _backGroundColor)
{
    super();
    backGroundColor = _backGroundColor;
}

 

Erweitern der Klasse SysOperationDataMemberInfo

Hinweis: Geänderten Code habe ich fett hervorgehoben.

abstract class SysOperationDataMemberInfo
{
    SysOperationDataContractInfo contractInfo;
    identifierName propertyName;
    str displayOrderKey;
    LabelType label;
    LabelType helpText;
    identifierName groupName;
    int propertyTypeId;
    Types propertyType;
    str key;
    boolean isCollection;
    AifCollectionTypeAttribute collectionAttr;
    boolean isQuery;
    boolean visible;
    boolean isInitialized;
    boolean timeZoneConversionRequired;
    int backgroundColor;  // Background-Color
}

 

// Background-Color
public int parmBackgroundColor(int _backgroundColor = backgroundColor)
{
    backgroundColor = _backgroundColor;
    return backgroundColor;
}

 

void new(
    SysOperationDataContractInfo _contractInfo,
    identifierName _propertyName,
    Types _propertyType,
    int _propertyTypeId,
    LabelType _label,
    LabelType _helpText,
    identifierName _groupName,
    str _displayOrderKey,
    int _backgroundColor = 0    // Background-Color
    )
{
    contractInfo = _contractInfo;
    propertyName = _propertyName;
    propertyTypeId = _propertyTypeId;
    propertyType = _propertyType;
    label = _label;
    helpText = _helpText;
    groupName = _groupName;
    displayOrderKey = _displayOrderKey;
    backgroundColor = _backgroundColor;   // Background-Color

    visible = true;
}

 

Erweitern der Klasse SysOperationAttributedDataMemberInfo

Hinweis: Geänderten Code habe ich fett hervorgehoben.

void new(
    SysOperationDataContractInfo _contractInfo,
    DictMethod _dictMethod
    )
{
    SysOperationGroupMemberAttribute    groupMemberAttribute;
    SysOperationDisplayOrderAttribute   displayOrderAttribute;
    SysOperationLabelAttribute          labelAttribute;
    SysOperationHelpTextAttribute       helpTextAttribute;
    SysOperationBackroundAttribute      colorAttribute; // Background-Color
    IdentifierName  groupMembership;
    str             displayOrder;
    LabelType       labelText;
    LabelType       helpString;
    MethodName      dictMethodName;
    Types           dictMethodReturnType;
    int             dictMethodReturnId;
    dictMethod = _dictMethod;
   
    if(dictMethod)
    {
        groupMemberAttribute = dictMethod.getAttribute(classStr(SysOperationGroupMemberAttribute));
        groupMembership = groupMemberAttribute ? groupMemberAttribute.groupName() : '';
        displayOrderAttribute = dictMethod.getAttribute(classStr(SysOperationDisplayOrderAttribute));
        displayOrder = displayOrderAttribute ? displayOrderAttribute.displayOrderKey() : '';
        labelAttribute = dictMethod.getAttribute(classStr(SysOperationLabelAttribute));
        labelText = labelAttribute ? labelAttribute.label() : '';
        helpTextAttribute = dictMethod.getAttribute(classStr(SysOperationHelpTextAttribute));
        helpString = helpTextAttribute ? helpTextAttribute.helpText() : '';

        // --> Background-Color
        colorAttribute = dictMethod.getAttribute(classStr(SysOperationBackroundAttribute));
        backGroundcolor = colorAttribute ? colorAttribute.backGroundColor() : 0;
        // <-- Background-Color


        dictMethodName = dictMethod.name();
        dictMethodReturnType = dictMethod.returnType();
        dictMethodReturnId = dictMethod.returnId();
    }
   
    // --> Background-Color
    super(_contractInfo, dictMethodName, dictMethodReturnType, dictMethodReturnId, labelText, helpString, groupMembership, displayOrder, backGroundcolor);
    //super(_contractInfo, dictMethodName, dictMethodReturnType, dictMethodReturnId, labelText, helpString, groupMembership, displayOrder);
    // <-- Background-Color

}

 

Erweitern der Klasse SysOperationAutomaticUIBuilder

protected DialogField addDialogField(IdentifierName methodName, Object _dataContract = this.dataContractObject())
{
    FormBuildRealControl realControl;
    SysOperationDataContractInfo contractInfo;
    SysOperationDataMemberInfo memberInfo;
    DictType dictType;
    DictEnum dictEnum;
    DialogField dialogField;
    str label;
    str helpText;
    anytype propertyValue;
    int backgroundColor; // Background-Color

    contractInfo = this.dataContractInfo().getMemberObjectInfo(_dataContract);
    memberInfo = contractInfo.getMembers().lookup(methodName);

    label = memberInfo.parmLabel();
    helpText = memberInfo.parmHelpText();
    backgroundColor = memberInfo.parmBackgroundColor();

    // Not a supported data type
    if (!SysOperationAutomaticUIBuilder::isSupportedType(memberInfo))
    {
        return null;
    }

    // check visibility
    if (!memberInfo.parmVisible())
    {
        return null;
    }

    // Special processing for collection type
    if (memberInfo.parmIsCollection())
    {
        dialogField = this.addCollectionDialogField(memberInfo);
    }
    else if (memberInfo.parmPropertyType() == Types::UserType)
    {
        dictType = new DictType(memberInfo.parmPropertyTypeId());

        if (!label)
        {
            label = (dictType.label()) ? dictType.label() : methodName;
        }

        helpText = (helpText != '') ? helpText : dictType.help();

        // check if timezone offset required, doing a additional check for perf reasons,
        // so we do a call to memberInfo only if necessary
        propertyValue = memberInfo.getPropertyValue();
        if(dictType.baseType() == Types::UtcDateTime && memberInfo.isTimeZoneConversionRequired())
        {
            propertyValue = DateTimeUtil::applyTimeZoneOffset(propertyValue, DateTimeUtil::getUserPreferredTimeZone());
        }

        dialogField = dialog.addFieldValue( dictType.name(),
                                            propertyValue,
                                            label,
                                            helpText);
        // --> Background-Color
        if(backgroundColor)
        {
            dialogField.backgroundColor(backgroundColor);
            dialogField.fieldControl().colorScheme(2);

        }
        // <-- Background-Color

    }
    else if (memberInfo.parmPropertyType() == Types::Enum)
    {
        dictEnum = new DictEnum(memberInfo.parmPropertyTypeId());

        if (!label)
        {
            label = (dictEnum.label()) ? dictEnum.label() : methodName;
        }

        helpText = (helpText != '') ? helpText : dictEnum.help();
        dialogField = dialog.addFieldValue(dictEnum.name(),
            memberInfo.getPropertyValue(),
            label,
            helpText);
    }
    else
    {
        label = (label != '') ? label : methodName;

        // check if timezone offset required, doing a additional check for perf reasons,
        // so we do a call to memberInfo only if necessary. This is the non EDT case
        propertyValue = memberInfo.getPropertyValue();
        if(memberInfo.parmPropertyType() == Types::UtcDateTime && memberInfo.isTimeZoneConversionRequired())
        {
            propertyValue = DateTimeUtil::applyTimeZoneOffset(propertyValue, DateTimeUtil::getUserPreferredTimeZone());
        }


        dialogField = dialog.addFieldValue( strFmt('%1', memberInfo.parmPropertyType()),
                                            propertyValue,
                                            label,
                                            helpText);

        // For primitive type of real, we will set the decimal places to be the max supported for real in X++ i.e. 16. By default it is set to 2
        if(dialogField && memberInfo.parmPropertyType() == Types::Real)
        {
            realControl = dialogField.fieldControl();
            if(realControl)
            {
                realControl.noOfDecimals(#DefaultNoOfDecimal);
                realControl.minNoOfDecimals(#DefaultMinNoOfDecimal);
            }
        }
    }

    if (dialogField)
    {
        this.bindInfo().addDialogField(_dataContract, methodName, dialogField);
    }

    return dialogField;
}
 

 

Zu guter Letzt muss noch das Attribute in der gewünschten Accessor-Methode eingebunden werden (siehe Screenshot). 

Und so sieht das Ergebnis aus:

Dieser Beitrag bezieht sich auf die Version:
Dynamics AX 2012

Kommentar hinzufügen
 
 

 

 
 
 
Beiträge des aktuellen Monats
März 2024
MoDiMiDoFrSaSo
 123
45678910
11121314151617
18192021222324
25262728293031
 
© 2006-2024 Heinz Schweda | Impressum | Kontakt | English version | Mobile Version
Diese Webseite verwendet Cookies, um Benutzern einen besseren Service anzubieten. Wenn Sie weiterhin auf der Seite bleiben, stimmen Sie der Verwendung von Cookies zu.  Mehr dazu