pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roger L. Whitcomb" <Roger.Whitc...@ingres.com>
Subject RE: Class loading question
Date Tue, 08 Feb 2011 16:52:29 GMT
The problem is that all my dialogs are based on a generic template with the changeable parts
contained inside the template structure.  But, logically the "DeleteTableDialog" (for instance)
"isa" GenericDialog, but physically (if you will), that is, the way the fields are arranged,
the GenericDialog is a wrapper that contains the Delete Table parts.  So, there is no problem
instantiating a GenericDialog object (and having GenericDialog implement Bindable).  I implemented
it that way yesterday and it worked fine.  However, the problem lies in instantiating a DeleteTableDialog....
 The outer part (that is, the top-level object in the BXML file) will still be a GenericDialog,
with the inside part being something different.  So, the logical structure of the superclass/subclass
relationship doesn't match the physical layout of the objects in the BXML and thus I never
get a DeleteTableDialog object that I can instantiate using Bindable.  Unless I end up duplicating
the generic parts in every dialog I create, which is really what I wanted to avoid.  And I
can't use <bxml:include...> because then I would need a parameterized include inside
the generic part to further include the specific parts.  But, it's possible I'm missing something
here.  Anyway, after banging my head against the wall for quite a while it just didn't look
like it was possible (without getting REALLY ugly).

~Roger Whitcomb

-----Original Message-----
From: Greg Brown [mailto:gk_brown@verizon.net]
Sent: Tue 2/8/2011 8:39 AM
To: user@pivot.apache.org
Subject: Re: Class loading question
It should be pretty straightforward. Just implement Bindable in your base dialog class, then
instantiate your concrete classes in markup.

On Feb 8, 2011, at 11:25 AM, Roger Whitcomb wrote:

> I definitely tried for many hours yesterday to figure out how to make what I have fit
into the Bindable mold and it just didn't work.  It's rather hard to explain what I've got,
but the "bind" scenario worked perfectly (with the patch for PIVOT-703) with very little code
while Bindable, as far as I could tell, was just not going to work with the way my dialogs
are organized.
> But, maybe there is a way to do it, I just haven't been able to figure it out.
> ~Roger Whitcomb
> On Feb 8, 2011, at 6:30 AM, Greg Brown wrote:
>> Bindable is definitely the preferred method here. I'd actually like to make bind()
private, since it is really more of a utility method for handling Bindables.
>> G
>> On Feb 7, 2011, at 9:57 AM, Roger L. Whitcomb wrote:
>>> Okay, I see what you mean:  I *think* I can get it to work implementing "Bindable".
 I had originally made the object in the BXML file a "Dialog" which was never getting into
my class.  So, I'm trying to read a "GenericDialog" in the BXML file, which should work as
you describe - I see the code in "readObject" that does the binding up the superclass chain.
 I'm having trouble, though, wrapping my mind around how to get the BXML code organized..
>>> But, I see a problem with just using "bind" (which is what I had in mind to begin
with):  in BXMLSerializer.bind(Object, Class) it calls "type.getDeclaredFields()" which specifically
gets the fields of the object EXCLUDING inherited fields.  In my case, the object is the subclass
object, but the annotated field is declared in the superclass.  Thus, the field never shows
up in the list and is never set.
>>> So, if I change this call to "type.getFields()" instead things start working.
 Unfortunately, this has the side-effect that non-public fields are no longer accessible.
 I'm thinking that the code in "bind" could be changed (maybe at the expense of some speed)
to iterate through the fields in the namespace that have ids and then call either "type.getDeclaredField()"
or if that fails "type.getField()" with the variable name and check the annotation.  This
would then make all fields, including all public superclass fields accessible..
>>> What do you think?
>>> Roger Whitcomb | Architect, Engineering | Roger.Whitcomb@ingres.com| Ingres |
500 Arguello Street | Suite 200 | Redwood City | CA | 94063 | USA  | +1 650-587-5596 | fax:
+1 650-587-5550
>>> From: Roger L. Whitcomb [mailto:Roger.Whitcomb@ingres.com] 
>>> Sent: Sunday, February 06, 2011 9:10 PM
>>> To: user@pivot.apache.org
>>> Subject: RE: Class loading question
>>> When you say "implement Bindable", does that mean the "initialize" method should
do the binding?  Or will it happen just by virtue of declaring "implements Bindable" and providing
a (possibly empty) "initialize" method?  I tried the latter and the binding still isn't happening.
>>> Roger Whitcomb | Architect, Engineering | Roger.Whitcomb@ingres.com| Ingres |
500 Arguello Street | Suite 200 | Redwood City | CA | 94063 | USA  | +1 650-587-5596 | fax:
+1 650-587-5550
>>> From: Greg Brown [mailto:gk_brown@verizon.net] 
>>> Sent: Sunday, February 06, 2011 4:07 PM
>>> To: user@pivot.apache.org
>>> Subject: Re: Class loading question
>>> Just checked - if you have your base GenericDialog class implement Bindable,
the annotated values should be bound correctly.
>>> On Feb 6, 2011, at 3:57 PM, Greg Brown wrote:
>>> If I understand you correctly, you are trying to bind to variables declared in
a base class - is that correct? I thought we had coded support for that. How are you performing
the bind? Are you using the bind() method or the Bindable interface?
>>> On Feb 6, 2011, at 3:12 PM, Roger L. Whitcomb wrote:
>>> Okay, I see what you're saying.  So, actually my problem is deeper than what
I thought:
>>> What I'm actually having trouble with (apart from the superficial question of
finding the resources, which I get now) is that I have a "GenericDialog" class with a bunch
of variables, and then a subclass "DeleteDialog extends GenericDialog".  In the GenericDialog
constructor (called via "super(String)" from DeleteDialog constructor), I want to load a generic
dialog template which has space for a subclass dialog part (which is named by the "String"
parameter).  The problem is that "this" in the GenericDialog constructor refers to the subclass
variable (as it should), so none of the @BXML annotations within GenericDialog itself get
filled in (because the only object I have is the subclass object).  Even making the variables
"protected" doesn't help.  So, is there any way to gracefully handle this situation?  Do you
need to see some code to see what I'm trying to do??  Thanks.
>>> Roger Whitcomb | Architect, Engineering | Roger.Whitcomb@ingres.com| Ingres |
500 Arguello Street | Suite 200 | Redwood City | CA | 94063 | USA  | +1 650-587-5596 | fax:
+1 650-587-5550
>>> From: Greg Brown [mailto:gk_brown@verizon.net] 
>>> Sent: Friday, February 04, 2011 11:34 PM
>>> To: user@pivot.apache.org
>>> Subject: Re: Class loading question
>>> I wish I hadn't introduced that version of BXMLSerializer#readObject().  :-)
 It seems to cause more confusion than anything else.
>>> Resources in Pivot behave the same as resource bundles in the JDK. If you use
the readObject(URL, Resources) signature rather than readObject(Class<?>, String) it
will probably make more sense. Apologies for the confusion.
>>> G
>>> On Feb 4, 2011, at 3:52 PM, Roger L. Whitcomb wrote:
>>> Hi all,
>>>                 Let me see if I can even ask this question intelligently:
>>> -          I've got a package hierarchy where my main program lives in package
"a.b.c".  In this directory I have Main.java, Main.json (with the resources) and some "g.bxml"
>>> -          In this main program I have a helper function that loads an object
from a "bxml" file and binds to whatever object you give it.  It uses a.b.c.Main as the class
and a.b.c.Main for the resources.
>>> -          There is a "Sheet1.java" that loads "sheet1.bxml" (all residing in
"a.b.c" package) and all works fine and the @BXML variables get set correctly.
>>> -          Now I introduce a "a.b.c.d" package and want to load a "dialog.bxml"
from this directory from "Dialog1.java" (a.b.c.d.Dialog class) using my same helper function
(from a.b.c.Main).  First off, using a name of "d/dialog.bxml" loads the file fine and I can
see it on screen, BUT none of my @BXML variables inside "a.b.c.d.Dialog" get set, and I get
no errors or exceptions.
>>> -          Fine - I'm thinking it's just a package problem, so I copy the helper
function into Dialog.java and try to use the same resources from "a.b.c.Main" and it starts
giving me "Can't find resource for base name a.b.c.d.Dialog, locale en_US" messages.  Okay,
so I have to move the resources into there too, which means more initialization, etc., etc.
>>> So, I guess my question is this:  what is the best way to organize the markup
files and resource file(s) in this package hierarchy?  And what is the "right" way to use
the class names to load resources and send to the BXMLSerializer so that my annotated variables
get set correctly?  Should I always pass the same class name to the serializer (and hence
put the resources and bxml files in the same directory(ies)) as the Java classes?  If I want
to put stuff in a common places (or places) where should that be?
>>> Am I making sense here or is more detail needed?  Thanks much!
>>> Roger Whitcomb
>>> Architect, Engineering
>>> Ingres Corporation
>>> roger.whitcomb@ingres.com
>>> PHONE +1 650.587.5596
>>> FAX +1 650.587.5550
>>> www.ingres.com
>>> This transmission is confidential and intended solely for the use of the recipient
named above. It may contain confidential, proprietary, or legally privileged information.
If you are not the intended recipient, you are hereby notified that any unauthorized review,
use, disclosure or distribution is strictly prohibited. If you have received this transmission
in error, please contact the sender by reply e-mail and delete the original transmission and
all copies from your system.

View raw message