On Tue, Dec 23, 2008 at 7:53 PM, David Hoffer <[email protected]> wrote:
> So its not a notification problem its a data access problem. I have looked
> at how the Tree control does this for single clicks but they made all the
> data & methods private so I can't use them.
>
> If you know a way to do this please advice.
Use the violator pattern. (I think--I've never seen "violator
pattern" defined, I've just seen it used and I assume it means what I
think it means.)
Suppose you have a library class:
package com.example.library;
public final class LibraryClass {
public void mungeSafely() {
if (!safe()) {
throw new UnsafeException("Not safe to munge!");
}
mungeDangerously();
}
private void mungeDangerously() {
// munge munge
}
}
And suppose you want to mungeDangerously() from outside LibraryClass.
You can do this:
package com.example.app;
public class LibraryUser {
public void tryToMungeDangerously(LibraryClass o) {
// you could implement this method as a violating JSNI method
// directly because it does nothing but delegate, but the extra
// method invocation is probably worth it if the surrounding code
// is non-trivial
mungeDangerously(o);
}
private static native void mungeDangerously(LibraryClass o) /*-{
// the doubled parens at the end of the next line are not a typo
// see the JSNI docs for details
o.com.example.library.LibraryClass::mungeDangerously()();
}-*/;
}
JSNI doesn't obey Java visibility rules, so you can violate them in a
controlled manner by writing JSNI methods like the one above. (Note,
I typed the above code directly into this email, so check the JSNI doc
that lukehashj pointed to if you run into trouble.)
I haven't looked at the code you're trying to reuse, so I have no idea
if the "violator pattern" really solves your problem or if it just
pushes the dirt around. Of course, this approach really is a
work-around, not a solution, but I find it a bit cleaner than
maintaining a parallel implementation while waiting for an
officially-sanctioned release of GWT that does what you want.
Ian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---