When we write sapui5 code, we often need get the UI5 controls basic meta information: the property, aggregation, events, associations. It is not convenient in current Eclipse environment, as the normal process would be:
(In Eclipse use the F3 'Open Declaration' will jump to the embedded ui5 library file, but which only contain the function prototype, don't have the meta data information).
And another annoying thing is for the enumerable property: if developer want to know the available enum property value, he needs search it from the big whole source files. And find out which one is the property definition and which one is the reference. In Chrome debug window we can a better way: just type the property type in console, then it will list all the property, but it is still not convenient as we need switch often between different windows.
How to solve this problem? One solution is use the sapui5 itself to generate basic meta information file.
For each ui5 class, we can get the metadata by call getMetadata(), then from the metadata you can get all the information such as property, aggregation, event....
var meta = sap.m.Button.getMetadata()
var prop = meta.getAllProperties(), it looks like:
text: Object
If the property start by 'sap', then it may be a enumerable property. We can get the object by eval the string, then do the further check:
if all the value by key is string, then it is enumerable property, otherwise, like the 'sap.ui.core.CSSSize' it is a special type.
call the getParent() we can get the parent of one class. Then for all the class, we can easily build the hierarchy information.
With the available ui5 meta information, it is easy to build the files. I use a famous template http://handlebarsjs.com/ to do so.
//extends from: sap.ui.core.Control
sap.m.Button = function() {
var metadata = {
properties : {
"busy" : { type: "boolean" , defaultValue: false },
"busyIndicatorDelay": { type: "int" , defaultValue: 1000 },
"text" : { type: "string" , defaultValue: null },
"type" : { type: "sap.m.ButtonType" , defaultValue: "Default" }, // Default, Back, Accept, Reject, Transparent, Up, Unstyled, Emphasized
"width" : { type: "sap.ui.core.CSSSize", defaultValue: null },
"enabled" : { type: "boolean" , defaultValue: true },
"visible" : { type: "boolean" , defaultValue: true },
"icon" : { type: "sap.ui.core.URI" , defaultValue: null },
"iconFirst" : { type: "boolean" , defaultValue: true },
"activeIcon" : { type: "sap.ui.core.URI" , defaultValue: null },
"iconDensityAware" : { type: "boolean" , defaultValue: true },
},
aggregations : {
"tooltip" : { type: "sap.ui.core.TooltipBase", multiple: false, altTypes: "string" },
"customData" : { type: "sap.ui.core.CustomData" , multiple: true , singularName: "customData", },
"layoutData" : { type: "sap.ui.core.LayoutData" , multiple: false, singularName: "layoutData", },
},
events: {
"validationSuccess": {},
"validationError" : {},
"parseError" : {},
"formatError" : {},
"tap" : {},
"press" : {},
}
};
};
sap.ui.core.TextAlign = {
Begin : "Begin",
End : "End",
Left : "Left",
Right : "Right",
Center : "Center",
};
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
38 | |
19 | |
13 | |
13 | |
11 | |
10 | |
10 | |
10 | |
8 | |
8 |