This Question is Possibly Answered

1 "correct" answer available (5 pts) 15 "helpful" answers available (3 pts)
3 Replies Last post: Oct 3, 2008 7:27 AM by Kamal

How to refer CalendarControl UI graphical child?

Oct 3, 2008 4:50 AM

Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008
Hi,

I have added Hbox in each day-cell in calendarcontrol through customCalendarcontrol UI
How can i refer this HBox?

Thanks
Varsha
Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
1. Re: How to refer CalendarControl UI graphical child? Oct 3, 2008 6:05 AM
You can always keep an array of these elements. Another way would be to start with the ControlUI and recursively iterate over the children. The first approach would be better though.
Click to view RajivGu's profile Level 6 RajivGu 82 posts since
Apr 2, 2008
2. Re: How to refer CalendarControl UI graphical child? Oct 3, 2008 6:29 AM
in response to: Kamal
Hi,

how to access Graphical Childrens of CalendarControlUI or Calendar.

{let cal:CalendarControl = {CalendarControl
                               day-proc =
                                   {proc {cc:CalendarControl, date:DateTime}:(#Graphic, bool)
                                       let constant info:DateTimeInfo = date.info
                                       let weekend?:bool = info.day-of-week >= 6
                                       
                                       {return
                                           {if weekend? then
                                               {HBox "Test",
                                                   background = "red"
                                               }
                                            else
                                               null
                                           },
                                           not weekend?
                                       }
                                   }
                           }
}
 
{value
        {for one-graphic in cal.child do
            {dump one-graphic}
            {type-switch one-graphic
             case c:CalendarControlUI do
                {dump c.child}
            }
        }
}


Above is a sample code where i m adding HBox to Calendar control and trying to iterate over the children of calendar


but i m getting the null value.Would you suggest the necessary changes to above code to iterate the child of Calendar.


Thanks


Rajiv.

Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
3. Re: How to refer CalendarControl UI graphical child? Oct 3, 2008 7:27 AM
in response to: RajivGu
Note that in your code

"{for one-graphic in cal.child do"

where "cal" is a CalendarControl.

Since the getter "child" could be null, you will get an error:

"Attempt to iterate over a container that might be null.".

You may use the following code instead:


{if-non-null child = cal.child then
    {for one-graphic in cal.child do
       ...
    }
}
 


However, the above code is not going to work either. Note that "child" here is a Layout, and it does not have the 'get' method or the 'for-loop-count' property nor a 'to-Iterator' method.

You should use "cal.graphical-children" to get the graphical children of a "Box".

The HBox, the original message referred, to is not a direct child of the CalendarControlUI. In my earlier response I said that you will have to do this search recursively. In fact, even after doing that you may not get the HBox as the HBox may not yet be created or added to the graphical hierarchy. This is because the default implementation of the CalendarControl does not create a UI unless it is needed. So unless you attach the CalendarControl to a graphical hierarchy, it will not create the user interface object for it.