Hi

This is easy so long as by “I have a number-property” you mean that you have an 
actual Qooxdoo property in your root widget, for example if you have something 
like this in your root widget class:

qx.Class.define("my.RootWidget", {

  extend: qx.ui.core.Widget,

  

  properties: {

    numberValue: {

      init: 0,

      nullable: false,

      check: "Number",

      event: "changeNumberValue"

    }

  },

  members: {

    // ... snip ...

  }

});



You can then write code in RootWidget such as:
    var dlg = new my.MyDialog();

    this.bind("numberValue", dlg, "numberValue");


And

qx.Class.define("my.MyDialog", {

  extend: qx.ui.window.Window,

  

  properties: {

    numberValue: {

      init: 0,

      nullable: false,

      check: "Number",

      event: "changeNumberValue"

    }

  },

  

  construct: function() {

    this.base(arguments);



    var lbl = new qx.ui.basic.Label()

    this.bind("numberValue", lbl, "value", { 

      convert: function(data) { 

        return "" + data; 

      } 

    });

  }

});


This approach lets you hide the UI implementation of MyDialog from the 
RootWidget, so all your code is thinking about is the numberValue property 
itself.  If MyDialog pops up another dialog, just pass it on in the same way.

Of course if numberValue is not the only property it can become tiresome 
binding lots of variables just for them to be passed on to something else so 
you could refactor this as:
qx.Class.define("my.MyData", {

  extend: qx.core.Object,

  

  properties: {

    numberValue: {

      init: 0,

      nullable: false,

      event: "changeNumberValue"

    }

  }

});



qx.Class.define("my.RootWidget", {

  extend: qx.ui.core.Widget,

  

  properties: {

    myData: {

      init: null,

      nullable: true,

      check: "my.MyData",

      event: "changeMyData"

    }

  },

  

  construct: function() {

    var dlg = new my.MyDialog();

    this.bind("myData", dlg, "myData");

  },

  

  members: {

    // ... snip ...

  }

});


Then you can add values and methods by just amending MyData

Note that this is only possible if you use Qooxdoo properties – if you just 
declare a private member variable like the below code you cannot bind to it:

  members: {

    __numberValue: 0,

    // ... snip..

  }


John

On 06/01/2016, 11:15, "LoneSurvivor" <i...@nethelpers.de> wrote:

Hi John,

thanks for your answer. 
I'm not quite sure, if I understand you correctly. My problem is, that I
have a number-property in my root widget that holds some money-value. This
money-value should be shown in a few ddefault label-widgets that are added
to some deeper windows. You know, click a button, a window opens, there's
another button that opens a subwindow and then there is a label that shows
that money-value. 
And there are some more subwindows that opens on other buttons that maybe
also show that money-value.

So there are different places in different levels of hiearchy which must be
updated for the changed value. So should I bind those labels all together
with a label added to the root-widget that gets updated by the initial
changeEvent and the rest get's automatically updated by the bindings?

Thank you in advance
LoneSurvivor



--
View this message in context: 
http://qooxdoo.678.n2.nabble.com/Attaching-a-custom-event-to-an-existing-widget-tp7587908p7587918.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to