Iliad: Widget class initialization

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Iliad: Widget class initialization

Bèrto ëd Sèra
Hi!

I have a working rough prototype of the localization mechanism, but I
have a problem, the Widget class does not seem to be initialized,
which would be needed, since I'm using a class variable in
LocalizedWidget. The basic code is here at the bottom. I'm not
connected to the DB yet, so instead of storing the real UUIDs for data
retrieval I store a string and copy it over, just to verify that
things work. And they do, if you inspect a snippet like:

Ambaradan.Login initialize.
Ambaradan.Login new initialize localize: #register.

But on executing the app I get an
UndefinedObject(Object)>>doesNotUnderstand: #keysAndValuesDo:
(AnsiExcept.st:1556) error, which seems a clear symptom of a missing
class initialization. Is there a way I can force the initialization
from my bottom level (I can't seem to remember anything about it), or
should one ad it to the core code?

BTW, once it works I'll move this stuff to a more abstract system,
with the Ambaradan DB being just a possible case. I myself hate to be
forced to use this or that product, so I guess it is important to
deliver a generic system that can be used to plugin "some way of
localizing a string", rather than committing marriage to any solution.
The basic thing I like with this system is that messages should be
declared inside the widget that uses them, so we use just as much cash
as needed, and a coder does not have to walk a possibly very huge
table any time he needs to check something.

Berto

==================================================

Namespace current: Ambaradan [
  Iliad.Widget subclass: LocalizedWidget [
    <category: 'Ambaradan'>
    <comment: 'version 0.6.0.
               This abstract class implements the localization
mechanism for all widgets.
               A class variable holds a LookupTable of GUI messages ->
UUIDs, where the
               UUIDs are the keys to retrieve a profile from the
Ambaradan database.
               Class variables:
                 GuiStrings: LookupTable of associations in the form
aSelector -> aUuid, where
                             the Uuid can be used to identify all
existing translations of the
                             term from the distributed Ambaradan DB.
               Instance variables:
                 languageChoice:   an association aUuid -> aUuid,
describing a language/script couple.
                                   It is kept and checkd on every
operation, if it changes (i.e., the
                                   user has selected another GUI
language) localization must be
                                   recomputed, otherwise we use the
cached version.
                 localizedStrings: LookupTable of associations in the
form aSelector -> text, compiled
                                   evaluating the general message
UUIDs stored at class level against
                                   the current user.' >
    GuiStrings := nil.
    | languageChoice localizedStrings |

    LocalizedWidget class [
      initialize [
        "start the LookupTable where the uuids of the text strings
         used by the GUI will be stored. Subclasses take care of
         filing in their own set. This class variable is used to
         produce a localized instance variable (also a LookupTable)
         that instead of the UUID will contain and cache the actual
         text to be rendered."
        <category: 'initialization'>
        super initialize.
        GuiStrings := LookupTable new.
      ]

      guiAdd: anAssociation [
        "Register an association selector -> UUID. This is used by
         the subclasses to register a translatable selector. The
         associated UUID is used to retrieve the message from the DB."
        <category: 'accessing'>
        GuiStrings add: anAssociation.
      ]

      isAbstract [
        <category: 'testing'>
        ^true
      ]

    ]

    initialize [
        "Localize all entries in the class variable GuiStrings LookupTable
         according to the current GUI language."
        <category: 'initialization'>
        super initialize.
        languageChoice   := OrderedCollection new.
        languageChoice addAll: self currentGuiLanguage.
        localizedStrings := self guiLocalize.
    ]

    localize: aStringSelector [
      <category: 'localization'>
      "Return the current localization for a string."
      ^localizedStrings at: aStringSelector.
    ]

    guiLocalize [
      <category: 'localization'>
      "Compile a LookupTable of translated messages.
       This prototype version simply does a copy, the final version
       will load data from the database."
      | tmpLocalizedStrings |
      tmpLocalizedStrings := LookupTable new.
      GuiStrings keysAndValuesDo: [:key :value | tmpLocalizedStrings
at: key put: value].
      ^tmpLocalizedStrings.
    ]

    defaultLanguage [
      <category: 'session data'>
      "English -> English alphabet. Other values can be found
       consulting the ambaradan dictionary."
      | defaultCollection |
      defaultCollection := OrderedCollection new.
      defaultCollection add: 'd3cb9b56-7929-11de-b1a0-1b6f382237eb' ->
'd3be1be8-7929-11de-9453-23ab1b1f0512'.
      ^defaultCollection.
    ]

    currentGuiLanguage [
      "temporary hack, here will be loaded the values from the user's
preferences. They are used to
       produce the actual localization of the GUI strings."
      <category: 'session data'>
      ^nil ifNil: [^self defaultLanguage].
    ]

  ]
]

============================

and an example of derived widget (PageTemplate is a subclass of
Ambaradan.LocalizedWidget)

Namespace current: Ambaradan [
  Ambaradan.PageTemplate subclass: Login [


    Login class [

      initialize [
        "start the LookupTable where the uuids of the text strings
         used by the GUI will be stored. Subclasses take care of
         filing in their own set. This class variable is used to
         produce a localized instance variable (also a LookupTable)
         that instead of the UUID will contain and cache the actual
         text to be rendered."
        <category: 'initialization'>
        super initialize.
        self
          guiAdd: #username     -> 'username';
          guiAdd: #password     -> 'password';
          guiAdd: #loginButton  -> 'login';
          guiAdd: #register     -> 'Register new user';
          guiAdd: #lostPassword -> 'I lost my password!';
          guiAdd: #preferences  -> 'My preferences'.
      ]
    ]

    mainContent [
        ^[ :e |
            e h1: self localize: #register.
        ]
    ]

  ]
]
--
==============================
Constitution du 24 juin 1793 - Article 35. - Quand le gouvernement
viole les droits du peuple, l'insurrection est, pour le peuple et pour
chaque portion du peuple, le plus sacré des droits et le plus
indispensable des devoirs.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Iliad: Widget class initialization

Stefan Schmiedl
On Thu, 30 Jul 2009 14:04:26 +0300
Bèrto ëd Sèra <[hidden email]> wrote:

> Is there a way I can force the initialization
> from my bottom level (I can't seem to remember anything about it), or
> should one ad it to the core code?

In this case, you could just write

Iliad.Widget subclass: LocalizedWidget [

  GuiStrings := LookupTable new.
  ...

]

and it should work. At least it did with

Object subclass: SomeClass3 [

  SomeClassVar := LookupTable new.

  look [
    SomeClassVar inspect
  ]

]

SomeClass3 new look



s.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Fwd: Iliad: Widget class initialization

Bèrto ëd Sèra
sorry, I hit the wrong button and missed the list


---------- Forwarded message ----------
From: Bèrto ëd Sèra <[hidden email]>
Date: 2009/7/30
Subject: Re: [Help-smalltalk] Iliad: Widget class initialization
To: Stefan Schmiedl <[hidden email]>


Hi!

> In this case, you could just write
>
> Iliad.Widget subclass: LocalizedWidget [
>
>  GuiStrings := LookupTable new.
>  ...
>
> ]
It will definitely do. The reason I wasn't using it is that Paolo
Bonzini told me that if I do it won't be visible in brawsers, and it
looked like a problem for those who will be editing the code from
VisualGST. Or did I get Paolo wrong?

Berto

--
==============================
Constitution du 24 juin 1793 - Article 35. - Quand le gouvernement
viole les droits du peuple, l'insurrection est, pour le peuple et pour
chaque portion du peuple, le plus sacré des droits et le plus
indispensable des devoirs.



--
==============================
Constitution du 24 juin 1793 - Article 35. - Quand le gouvernement
viole les droits du peuple, l'insurrection est, pour le peuple et pour
chaque portion du peuple, le plus sacré des droits et le plus
indispensable des devoirs.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Iliad: Widget class initialization

Bèrto ëd Sèra
Hi!

One more problem. It looks like even Iliad.Application does not get
class initialization, so I have nowhere to call the initialization of
my widget classes. As a wild guess, I tried to overcome the problem by
adding a
  <start>
    AmbaradanApplication initialize.
  </start>
in my package.xml, but I obviously have no idea of how this thing
works, and I got no effect whatsoever. I'd rather not touch the Iliad
code, for obvious reasons... is there a practical way out?

Berto.

--
==============================
Constitution du 24 juin 1793 - Article 35. - Quand le gouvernement
viole les droits du peuple, l'insurrection est, pour le peuple et pour
chaque portion du peuple, le plus sacré des droits et le plus
indispensable des devoirs.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Iliad: Widget class initialization

Stefan Schmiedl
On Thu, 30 Jul 2009 17:30:02 +0300
Bèrto ëd Sèra <[hidden email]> wrote:

> Hi!
>
> One more problem. It looks like even Iliad.Application does not get
> class initialization, so I have nowhere to call the initialization of
> my widget classes.

If you have no place, make one:

  Object subclass: Thingie [
    Thingie class [
      initialize [
        super initialize.
        'class init' printNl
      ]
    ]
    initialize [
      'object init' printNl
    ]
  ]

  Eval [
    Thingie initialize
  ]

That's the way it is done in the Seaside packages, for example.

I wonder if that could/should be folded away by the loader,
since it is done automatically in the other Smalltalks I know.

s.



_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Iliad: Widget class initialization

Bèrto ëd Sèra
Hi!

>  Eval [
>    Thingie initialize
>  ]

THANKS!!!! That's not something I forgot, but rather something I never
knew :) It's a wonderful thing.

Berto

--
==============================
Constitution du 24 juin 1793 - Article 35. - Quand le gouvernement
viole les droits du peuple, l'insurrection est, pour le peuple et pour
chaque portion du peuple, le plus sacré des droits et le plus
indispensable des devoirs.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Iliad: Widget class initialization

Stefan Schmiedl
In reply to this post by Bèrto ëd Sèra
On Thu, 30 Jul 2009 16:35:27 +0300
Bèrto ëd Sèra <[hidden email]> wrote:

> >  GuiStrings := LookupTable new.
> >
> It will definitely do. The reason I wasn't using it is that Paolo
> Bonzini told me that if I do it won't be visible in brawsers, and it
> looked like a problem for those who will be editing the code from
> VisualGST. Or did I get Paolo wrong?

Ah, you mean the initialization value. Yes, you won't see it if
you do it that way, since the browsers (currently) only work on
methods.

Looking over my Smalltalk code I find that I tend to use lazy
initialization with class (instance) variables quite a lot.

s.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk