How to access user defined methods of widget parent

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to access user defined methods of widget parent

bharath
I have a parent widget which extends Window class (qx.ui.window.Window) and this window now has couple of children (I have created the children by overriding createChildControlImpl).

Now I would like to access my methods in Parent class from one of the child classes. I don't want to create an object to call the methods, instead I would like to use getLayoutParent method to do this.

But when I can call getLayoutParent method from the child class, all I can access are the built-in methods, but I can't access any methods which I have created.

How can I get to do this ?

code Sample:

qx.Class.define("project.WrkAttrWindow",{

extend : qx.ui.window.Window,

construct: function() {
    this.base(arguments);
    this.__table = this._createChildControl("table");
},
members: {

__table:null

_createChildControlImpl : function(id)
{
  var control;
  switch(id)
  {
  case "table":
      control = new project.WrkAttrTable();
      this.add(control);
      break;
  }
 return control || this.base(arguments, id);
},

getPrjId:function() {
console.log(I want to call this function);
}
});

Child Widget

qx.Class.define("project.WrkAttrTable",{

extend: qx.ui.table.Table,

statics: {
    colKeys:["id","name","description"]
},

construct: function() {

    this.base(arguments);
          //some code here
    },

    members:
    {
       //call parent method from here
       this.getLayoutParent().getPrjId(); // does not work
    }
    });
Reply | Threaded
Open this post in threaded view
|

Re: How to access user defined methods of widget parent

Daniel Wagner
Administrator
Hi,

in your overridden _createChildControlImpl method, you use the public
"add" method. This is the API intended for children added from *outside*
the class, which inserts the child into the Window's children container.
All you have to do is replace this.add with this._add, then the child
control will be inserted into the Window itself and getLayoutParent will
work as expected.

Regards,
Daniel

On 24.09.2013 16:35, bharath wrote:

> I have a parent widget which extends Window class (qx.ui.window.Window) and
> this window now has couple of children (I have created the children by
> overriding *createChildControlImpl*).
>
> Now I would like to access my methods in Parent class from one of the child
> classes. I don't want to create an object to call the methods, instead I
> would like to use *getLayoutParent* method to do this.
>
> But when I can call *getLayoutParent* method from the child class, all I can
> access are the built-in methods, but I can't access any methods which I have
> created.
>
> How can I get to do this ?
>
> *code Sample:*
>
> qx.Class.define("project.WrkAttrWindow",{
>
> extend : qx.ui.window.Window,
>
> construct: function() {
>      this.base(arguments);
>      this.__table = this._createChildControl("table");
> },
> members: {
>
> __table:null
>
> _createChildControlImpl : function(id)
> {
>    var control;
>    switch(id)
>    {
>    case "table":
>        control = new project.WrkAttrTable();
>        this.add(control);
>        break;
>    }
>   return control || this.base(arguments, id);
> },
>
> getPrjId:function() {
> console.log(I want to call this function);
> }
> });
>
> *Child Widget*
>
> qx.Class.define("project.WrkAttrTable",{
>
> extend: qx.ui.table.Table,
>
> statics: {
>      colKeys:["id","name","description"]
> },
>
> construct: function() {
>
>      this.base(arguments);
>            //some code here
>      },
>
>      members:
>      {
>         //call parent method from here
>         this.getLayoutParent().getPrjId(); // does not work
>      }
>      });
>
>
>
> --
> View this message in context: http://qooxdoo.678.n2.nabble.com/How-to-access-user-defined-methods-of-widget-parent-tp7584648.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to access user defined methods of widget parent

bharath
Hi Daniel,

 Thanks for the suggestion. Now I am able to access the methods of the parent widget.

However, the layout of the window is not the same anymore when I use the protected add method. Is there any reason why is this happening ? In addition to _add method, do I need to call any other methods which can fix the layout issue.

For clear understanding, I'm attaching images of the window, when public add is used and protected add is used.

Window when public add is called Window when protected add is called


As you can see, on the right image there is no padding between the parent Window and the children (Toolbar and Table). I tried to set the padding property, but it does not help at all.

Any advice how can I get to fix this ?

Regards,
Bharath.
Reply | Threaded
Open this post in threaded view
|

Re: How to access user defined methods of widget parent

Alex Gölkel
Hi,

the window is not a flat widget, but it creates some sub widgets itself. One sub widget is the content container, where other child widgets are added to when calling the "add" method.
If such a child widget calls the getLayoutParent method, it'll get the content container, not the window.

To solve your problem, you could add a property "parentWindow" to the child widget, and set it when adding the child widget.

But I think the better way is to define an event in the child widget, which the window subscribes and add the logic to the event listener.

Regards
Alex