Christian Boulanger <[EMAIL PROTECTED]> writes:

>> Not in the way it was done in 0.5 and 0.6 but in a much cleaner way ;-)
>>
>> You can define a mixin with the desired property and include the mixin 
>> at runtime into any class you want.
>>   
> but I forgot to ask: how is this done exactly? I haven't found any 
> example or documentation for this on the qooxdoo website.

You define a mixin almost identically to defining a class, except that you use
qx.Mixin.define() instead of qx.Class.define().  

A sample mixin that adds one property and one new method might look like this
_untested_ snippet:

  qx.Mixin.define("my.MDebug",
  {
    properties :
    {
      /**
       * The message type.  It must be either "warn" or "debug".
       */
      messageType :
      {
        check : function(value)
                {
                  return value === "warn" || value === "debug";
                }
      }
    },

    members :
    {
      /**
       * Add a message to the debug output.  The message will be either a debug
       * message or a warning message, depending upon the setting of the
       * messageType property.
       *
       * @type member
       *
       * @param message {String}
       *   The message to be displayed
       *
       * @return {void}
       */
      displayWarningMessage : function(param)
      {
        if (this.getMessageType() == "warn")
        {
          this.warn(param);
        }
        else
        {
          this.debug(param);
        }
      }
    }
  });

And then to add this mixin to your class, you either (a) use qx.Class.include
or (b) add an "include" property to your class configuration.

Option (a):

  qx.Class.include(my.TestClass, my.MDebug);

Option (b):

  qx.Class.define("my.TestClass",
  {
    include : [ my.MDebug ],

    properties : { ... },

    members : { ... }
  });

Option (a) is useful if you want the application to be able to choose whether
it wants the features available in a particular mixin, but don't need for them
to always be included in every application.

Option (b) is useful for dividing a large class up into multiple files where
you still always wanted all of the features in both the original class
definition and the mixins to be available.

I've never tried (b) but it's supposed to work.  Option (a) works well.  I use
it for the TreeVirtual mixins.

For additional documentation, look at qx.Mixin.

Christian, once you confirm that all of the above works as described and has
no typos, please feel free to add this description to the wiki.  Wikis and I
don't get along well, so I tend not to add stuff there but rather answer
questions here.

Derrell
    

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to