Results 1 to 2 of 2

Thread: [Answers] Meta Types

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    [Answers] Meta Types

    MetaDataBuilder API (for databases, tables and columns), v2.1 will include a graphical "Meta Type Editor" and support user defined meta types


      • Added a new MetaTypeEditor for projects. You create "Meta Types" (which are essentially class definitions) for Apps, Pages, Sections or FormItems using the "Meta Type Editor".
      • You can edit these "Meta Types" in either the "Projects" workspace or the "App" workspace.
      • The "Meta Type Editor" is a dialog similar in operation to the App Inspector as it stays on top of the UI as you are designing your App pages.
      • You can add/edit "Meta Types" and "Apply" the changes against your App as you design/develop it.
      • Each UI element: Apps, Pages, Sections or FormItems can have a list of "Meta Types" specified.
      • Unlike a "Class Editor" (or similar that you may be familiar with) this provides the ability to handle multiple inheritance of attributes and delegates in a scripting language independent manner.
      • These "Meta Types" are applied when an App is loaded.
      • If you are building Web and/or mobile Apps you then need to deploy your apps.
      • If you are building desktop apps the "Meta Types" are applied dynamically when the app is loaded.
      • "Meta Types" are stored in a new sub-directory called c:\lianja\metatypes and each file is named like this: projectname.metatypes.
      • You can override this name in the app settings on an app by app basis if required.
      • The default file name however will be projectname.metatypes if a project is open or appname.metatypes is no project is open.


    This adheres to the Lianja App Builder core philosophy of
    declarative device-independent UI building but provides the ability to inherit common appearance and behavior without needing to set individual attributes for each UI element, resulting in increased developer productivity and more rapid application development.



    Q:
    Is this similar to extend the standard app, page, section, form item attributes to include additional user defined attributes?
    A:
    You can do that already for a long time using addProperty(). This adds a new attribute and prefixes it with user_ internally.
    Any attributes that you set that are prefixed with user_ are user defined.



    In v2.1Beta6 I've added several new functions to simplify working with MetaData and MetaType key/value pairs. This representation can be used as an alternative to JSON format and is much smaller.

    Code:
    // create an object from a metadata string
    obj = metadata_decode("name=barry;company=Lianja")
    
    // encode a string from an object representing metadata
    str = metadata_encode( obj )
    
    // Create an object from a metadata string
    obj = metadata_decode("[type1]name=barry;backcolor=red;[type2]name=bill;backcolor=pink")
    
    // Extract the attributes for a given metatype in a metadata string
    str = metadata_findtype("type1", "[type1]name=barry;backcolor=red;[type2]name=bill;backcolor=pink")


    MetaTypeEditor which shows you the names of all attributes and their descriptions. There are some new methods for page, section, field and gadgets called setAttribute() and getAttribute() which provide access to all attributes as detailed in the MetaTypeEditor.



    These provide a powerful means of defining components (as MetaTypes) and then subclassing them in Pages, Sections and FormItems (Fields and Gadgets).
    MetaType Editor exposes and documents all attributes available for Pages, Sections and FormItems.

    So if you want to create your own builders, these attributes should be set using the new setAttribute(name, value) method on Pages, Sections or FormItems.
    All attributes are exposed now. You set then using setAttribute(name, value) and get them using getAttribute(name).



    All topics in [Answers] alphabetically: http://www.lianja.com/community/show...p?2717-Answers


  2. #2
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    I had some interesting USE CASE's to solve. Database MetaData proved to be the answer.
    For ease of use I created these in the Database MetaData Editor, but any way they are created and applied to the database would have obtained the same result. Alter table modify constraint metadata would do the same job.
    What I show below is the metadata I created.

    1) I had a caption for a field, nAcctBalance, that had to change based on the value of another field, lHasBalance
    I first accessed the MetaData Editor for the nAcctBalance field by doing to the Data section, selecting the table and then the field, and then selecting MetaData Editor from the "gear" menu for the fields dialog.
    Code:
    formitem.caption=[lHasBalance]Balance,Balance Not Used
    In the editor the 3 entries would be (showing | to indicate the sections):
    Code:
    formitem.section | lHasBalance | Balance,Balance Not Used
    2) the same field, nAcctBalance, which had to be made not Editable when lHasBalance was .T.
    Code:
    formitem.editable | lHasBalance |TRUE,FALSE
    Notice the use of oData-style .T. and .F.

    3) make the data of nAcctBalance invisible when Balance Not Used
    This could have been fancier, but works here:
    Code:
    formitem.dataForeColor | lHasBalance | Black,White
    Refreshing the app shows the MetaData effects.
    The beauty of this approach is that conditionals can't be used in the attribute inspector but can in Metadata.
    And it refreshes instantly (when lHasBalance is checked or unchecked), even when adding a record and changing the value of lHasBalance. No refresh is need for the conditionals to apply.
    This is astounding, really, beyond belief. I have focused on working with Metadata for 21 years and never dreamed of anything this powerful.
    In our VFP app, we end up writing methods to run on a Refresh to make these kinds of things happen. We can handle of number of things dynamically, but here we have the ability to use it for every attribute the object has.
    This is magic!



    Q:
    is possible to manipulate MetaType from code?
    for example add or modify?

    A:
    whether you can create or modify the metatype files created by the MetaType Editor programmatically the answer is no.
    MetaTypes created with the MetaType Editor and MetaDafa attached to databases, tables and columns are two completely different things.
    MetaTypes belong to the UI whereas
    MetaData belongs to data.



    In Lianja 3.4 as stated in the roadmap:

    • Added a graphical MetaData Editor for Database, Tables and Columns. Click the "Edit" icon in the ActionBar to show the MetaData Editor. You can find information on how to use MetaData here.



    MetaData and MetaTypes are two completely different things. MetaData system in Lianja is designed to reduce coding and simplify data design.




    All topics in [Answers] alphabetically: http://www.lianja.com/community/show...ll=1#post12352

    These answers are also systematized on the site "Lianja developer": https://lianjadeveloper.wordpress.com/category/meta-types/
    Last edited by josipradnik; 2017-12-18 at 00:43.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us