Define properties with initial value

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

Define properties with initial value

Szántai Péter
Hi,

I'm new with qooxdoo and want to define some classes with properties.
This is the first example i tried to wrote. It works but i have a feeling that this solution is against some conventions.
In the qooxdoo manual there isnt any example about how to initialize properties with Object types.

So i want to know how you solve the init value problem and may suggest some better solution for a  basic(no checks, just the basic get/set funtionality) _apply function.

qx.Class.define("custom.Box",
{
    extend : qx.ui.layout.BoxLayout,
   
   
    construct : function(){
        this.base(arguments);
       
        this.setTextBox(new qx.ui.form.TextField());
       
        this.add(this.textBox);
    },
   
    properties : {      
        textBox : {
            init : null,
            apply: "_applyText",
            check: "qx.ui.form.TextField"
        }
    },

    members : {
        _applyText : function(value, oldValue){
            this.textBox = value;
            return value;
        },
     }
}

Thanks for the help,

 Peter

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Define properties with initial value

Szántai Péter
Hi,

I'm new with qooxdoo and want to define some classes with properties.
This is the first example i tried to wrote. It works but i have a feeling that this solution is against some conventions.
In the qooxdoo manual there isnt any example about how to initialize properties with Object types.

So i want to know how you solve the init value problem and may suggest some better solution for a  basic(no checks, just the basic get/set functionality) _apply function.

qx.Class.define("custom.Box",
{
    extend : qx.ui.layout.BoxLayout,
   
   
    construct : function(){
        this.base(arguments);
       
        this.setTextBox(new qx.ui.form.TextField());
       
        this.add(this.textBox);
    },
   
    properties : {      
        textBox : {
            init : null,
            apply: "_applyText",
            check: "qx.ui.form.TextField"
        }
    },

    members : {
        _applyText : function(value, oldValue){
            this.textBox = value;
            return value;
        },
     }
}

Thanks for the help,

 Peter


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Define properties with initial value

Fabian Jakobs
Administrator
Hi Peter,

>
>
> I'm new with qooxdoo and want to define some classes with properties.
> This is the first example i tried to wrote. It works but i have a
> feeling that this solution is against some conventions.
> In the qooxdoo manual there isnt any example about how to initialize
> properties with Object types.
>
> So i want to know how you solve the init value problem and may suggest
> some better solution for a  basic(no checks, just the basic get/set
> functionality) _apply function.
This is how I would do it as well. Keep in mind that using reference
types like arrays, maps and objects in the "init" key of a property
definition will be shared by all instances because only the reference is
copied. You do exactly the right thing by initializing the property in
the constructor.

Best Fabian


>
>     qx.Class.define("custom.Box",
>     {
>         extend : qx.ui.layout.BoxLayout,
>        
>        
>         construct : function(){
>             this.base(arguments);
>            
>             this.setTextBox(new qx.ui.form.TextField());
>            
>             this.add(this.textBox);
>         },
>        
>         properties : {      
>             textBox : {
>                 init : null,
>                 apply: "_applyText",
>                 check: "qx.ui.form.TextField"
>             }
>         },
>
>         members : {
>             _applyText : function(value, oldValue){
>                 this.textBox = value;
>                 return value;
>             },
>          }
>     }
>
>
> Thanks for the help,
>
>  Peter
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> ------------------------------------------------------------------------
>
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>  


--
Fabian Jakobs
JavaScript Framework Developer

1&1 Internet AG
Brauerstraße 48
76135 Karlsruhe

Amtsgericht Montabaur HRB 6484

Vorstand: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas Gottschlich, Matthias Greve, Robert Hoffmann, Markus Huhn, Oliver Mauss, Achim Weiss
Aufsichtsratsvorsitzender: Michael Scheeren


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Define properties with initial value

Alexander Back
In reply to this post by Szántai Péter
Hi Péter,

welcome to the qooxdoo project!

Szántai Péter wrote:
> Hi,
>
> I'm new with qooxdoo and want to define some classes with properties.
> This is the first example i tried to wrote. It works but i have a feeling
> that this solution is against some conventions.
Indeed there is a better solution for your issue. You don't have to
write an own "_applyText" method at all. For every property in qooxdoo
there are setter and getter methods automatically created. So you only
have to write

--snip--
  construct : function(){
          this.base(arguments);

          this.initTextBox(new qx.ui.form.TextField());

          this.add(this.getTextBox());
      },

      properties : {
          textBox : {
              deferredInit : true,
              check: "qx.ui.form.TextField"
          }
--snip--

to achieve your goal. So you can leave your custom "_applyText" method
behind. With the use of the "deferredInit" key the reference types are
not shared between the instances. However this feature is only available
with the latest copy of the 0.7.x branch or trunk version.

> In the qooxdoo manual there isnt any example about how to initialize
> properties with Object types.
To get to know more about the power of properties just take a look at
the properties section in the online wiki documentation (
http://qooxdoo.org/documentation/0.7#properties )

cheers,
   Alex

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Define properties with initial value

Szántai Péter
2008/6/20 Alexander Back <[hidden email]>:
Hi Péter,

welcome to the qooxdoo project!

Szántai Péter wrote:
> Hi,
>
> I'm new with qooxdoo and want to define some classes with properties.
> This is the first example i tried to wrote. It works but i have a feeling
> that this solution is against some conventions.
Indeed there is a better solution for your issue. You don't have to
write an own "_applyText" method at all. For every property in qooxdoo
there are setter and getter methods automatically created. So you only
have to write

--snip--
 construct : function(){
         this.base(arguments);

         this.initTextBox(new qx.ui.form.TextField());

         this.add(this.getTextBox());
     },

     properties : {
         textBox : {
             deferredInit : true,
             check: "qx.ui.form.TextField"
         }
--snip--

to achieve your goal. So you can leave your custom "_applyText" method
behind. With the use of the "deferredInit" key the reference types are
not shared between the instances. However this feature is only available
with the latest copy of the 0.7.x branch or trunk version.

> In the qooxdoo manual there isnt any example about how to initialize
> properties with Object types.
To get to know more about the power of properties just take a look at
the properties section in the online wiki documentation (
http://qooxdoo.org/documentation/0.7#properties )

cheers,
  Alex

Many thanks for the fast answers, but i still got problems.
I get these errors when try to use my defined class.

1. The configuration key "deferredInit" of property "textBox" in class "custom.TextBox" is not allowed!
2.
this.initTextBox is not a function

So i'm totally clueless now, how to solve these problems. I can use the class as i defined first, and it seems to me it works correctly, but still a i wish to know how to use the initMyProperty() function. (I read the whole qooxdoo manual (
http://qooxdoo.org/documentation/0.7) not just the property part)
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Define properties with initial value

Alexander Back
Hi Péter,

Szántai Péter wrote:
> I get these errors when try to use my defined class.
>
> 1. The configuration key "deferredInit" of property "textBox" in class
> "custom.TextBox" is not allowed!
> 2. this.initTextBox is not a function
Which version of qooxdoo do you use? As I mentioned in my first mail the
"deferredInit" key is only available with the latest versions of the
"legacy_0_7_x" branch or the trunk. It is not available it the latest
0.7.3 release.

> So i'm totally clueless now, how to solve these problems. I can use the
> class as i defined first, and it seems to me it works correctly, but still a
> i wish to know how to use the initMyProperty() function. (I read the whole
> qooxdoo manual (http://qooxdoo.org/documentation/0.7<http://qooxdoo.org/documentation/0.7#properties>)
> not just the property part)
If you want to init a property with a complex type and do not want to
share the property between multiple instances you can use the following
code:

--snip--
construct : function()
{
   this.base(arguments);

   this.initTextBox(new qx.ui.form.TextField());
},


properties :
{
    textBox :
   {
      deferredInit : true,
      check : "qx.ui.form.TextField" // the check is not mandatory
    }
}
--snip--

cheers,
   Alex

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel