Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Arbitrary boolean condition in Hilite setCriteria

    Hi Isomorphic,

    I saw the example http://www.smartclient.com/smartgwt/...ng_pre_defined and wanted to ask if the following is possible:
    Replace some of the conditions in
    Code:
    setCriteria(new AdvancedCriteria(OperatorId.AND, new Criterion[] {  
    	new Criterion("gdp", OperatorId.GREATER_THAN, 1000000),  
    	new Criterion("area", OperatorId.LESS_THAN, 500000)}));
    with methods returning a boolean value. I have a method boolean User.mayEdit(Record r, ...) and would like to use it here.
    Criterion does not have a constructor that takes a constant as 1st value, otherwise I could solve it using
    Code:
    ...
    new Criterion(true, OperatorId.EQUALS, User.mayEdit(Record r, ...))
    Is there some workaround (other than defining a fake field always returning true in my .ds.xml) to do this?

    Thank you & Best regards,
    Blama

    #2
    Hi Isomorphic,

    I'm reworking parts of my application for 6.1d. Testing it I found that exportClientData outputs CSS-text from getCellCSSText() - I'm pretty sure that this is not possible somehow else.
    I also saw that Hitlite-CSS is not only not exported as data, but also applied as styling in Excel-exports. Impressive.
    So next I want to replace my current getCellCSSText() with Hilites, where possible.

    Would the approach from #1 work in gereral? Would the Hilite class need some override method where I have the LsitGridRecord available in the method parameters?
    Or is it already there?

    My User.mayEdit() method is static and takes only the current ListGridRecord as parameter.

    Thank you & Best regards
    Blama

    Comment


      #3
      If you mean defining an always-true or always-false criterion, yes that should work, and would not require a new API or method override.

      Comment


        #4
        Hi Isomorphic,

        no, that is not what I meant.
        I meant that the Hilite evaluates a function that does not depend on row-values only (then it could be built as AdvancedCriteria).
        Example:
        Code:
        Datasource colums:
        tenant_ID: type:integer
        ID: type:integer
        Name: type:text
        fake_always_true: type:boolean, sqlStorageStrategy:singleCharYN, customSelectExpression:'Y'
        Hilite rule is: Look up if for this tenant only all-uppercase names or all names should be hilited.
        I have a static method that takes a ListGridRecord and uses the tenant_ID and the name to determine this in Java.

        Currently I'm calling this method in getCellCSSText(), but want to call it in a Hilite like this:
        myHilite.setCriteria(new Criterion("fake_always_true", OperatorId.EQUALS, User.shouldBeHilited(Record r, ...)) I assume that this is possible with some method override, because internally the Hilite will as well have the ListGridRecord available.
        I want to evaluate true/false here then on my own. Perhaps I'll need one Hilite subclass per different method I want to call.

        So my two questions are:
        • Is this possible? Which method should I override?
        • Is this also possible with Criteria as suggested in the example, and if so, do I need the fake_always_true column?
        Thank you and best regards
        Blama

        Comment


          #5
          Looking through the methods of Hilite in Eclipse it seems that the evaluation is not done there, as Hilite seems just to hold its properties and has no calculation methods.
          I also looked through ListGrid, but did not find a method name with "Hilite" in it that looked promising.

          Comment


            #6
            No, there is no method to override how a Hilite is applied, it must be done via criteria and thus would require a field definition.

            Comment


              #7
              OK, and is it somehow possible to have the Criteria take a static method with definition methodname(ListGridRecord r) as last argument?

              This would allow things that are either not possible with Criteria alone (evaluation of static context variables) or things that are way more easy done in code than in Criteria (procedural String manipulation in code+comparing vs declarative (RegEx?) Criteria or complicated nested And/Or Criteria).

              Best regards
              Blama

              Comment


                #8
                No, again, not possible.

                One of the primary points of Criteria is to provide a serializable definition of decision criteria that can be executed client or server and can be edited in a UI by a non-developer. Allowing programmatic criteria clashes badly with this.

                It potentially makes sense as a sponsorship to allow programmatic Hilite definitions, but the feature is not there now.

                Comment


                  #9
                  Hi Isomorphic,

                  I found this thread again by chance, but wanted to ask you about this anyway:
                  Does the feature "Boolean Dynamic Properties" you mention in this blog entry about 13.0 make this somehow possible?
                  I assume no, but perhaps it does, or perhaps there is now a quick win for you possible.

                  Best regards
                  Blama

                  Comment


                    #10
                    No. Boolean dynamic properties allow Boolean properties on components to be set dynamically based on criteria.

                    You are looking to inject an arbitrary function into criteria, not just more criteria into criteria. And it’s not on a component, but instead in the middle of a Hilite rule and/or its criteria. So totally unrelated.

                    Comment

                    Working...
                    X