Factory initialization

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Factory initialization

Postby JimVanDam » Sat Jan 20, 2007 9:41 am

I am trying to initialize a factory class in the constructor of my testpanel. The factory is used later on when creating components, but it looks like the initialize call is not executed in the designer.
Is there any way to verify that it gets called by the designer through debug code or logger calls?
Code: Select all
public TestSB() {
  super();
  Factory.initialize();
  initComponents();
}

I suspect the code is not executed, because when I repeat the code inside the Factory.initialize in another part of the code, it does work.
Factory.initialize() is a public static operation.

Regards,

Jim
JimVanDam
 
Posts: 4
Joined: Sat Jan 20, 2007 4:49 am

Re: Factory initialization

Postby Eric Clayberg » Sat Jan 20, 2007 12:49 pm

Is TestSB the class you are opening in Designer or a class being used as custom panel within another class you are opening with Designer?

Designer does not instantiate the class currently being edited (the class is parsed rather than instantiated), so it's constructor would never be called. No instance of the edited class exists at design time.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Factory initialization

Postby JimVanDam » Sat Jan 20, 2007 1:22 pm

Eric Clayberg wrote:Designer does not instantiate the class currently being edited (the class is parsed rather than instantiated), so it's constructor would never be called.

Ok, thx for the quick reply. I need to put it in initComponents then? What would be the best way to debug my custom code in combination with designer?
I tried to find some documentation on the features/prerequisites for the parser, but besides a lot of comments about it being very good :) I could not find much. I agree with those comments, but I would feel more comfortable knowing a bit more what it can and cannot do and how it works, so I can adapt my generated code towards designer support.

Thx,
Jim

P.S. Compliments on the JGoodies form support
JimVanDam
 
Posts: 4
Joined: Sat Jan 20, 2007 4:49 am

Re: Factory initialization

Postby Eric Clayberg » Sun Jan 21, 2007 9:50 am

The Designer parser will parse any code generated by itself or any other GUI builder. It can also handle most hand-written and refactored code. It can also parse code that uses static widget factories as well as the JGoodies instance-based factory. The latest build also adds limited support for other instance-based factories that follow the JGoodies model.

The parser only looks at GUI creation code and will ignore any other code in the class that is not directly related to either the instantiation of a GUI component or setting a property on a GUI component. Code like your Factory.initialize() call will always be ignored. Rather than externally initializing your factory, you should have it initialize itself either in a static section (for a static factory) or in its constructor or getInstance() method (for an instance factory).
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Factory initialization

Postby JimVanDam » Sun Jan 21, 2007 10:13 am

Eric Clayberg wrote:Rather than externally initializing your factory, you should have it initialize itself either in a static section or in its getInstance() method.

Ok, I understand the rationale and will try to adhere, but even the getInstance call does not seem to work out. I can not have it initialize itself, because I need to add arguments to the call later on. I also tried a JGoodies similar call like
Code: Select all
Factory.getInstance().createLabel("jLabel1.text")

but, to no avail. I sent a small example with all the alternatives I tried to wb_support. Hope you can help me out.

Regards,
Jim
JimVanDam
 
Posts: 4
Joined: Sat Jan 20, 2007 4:49 am

Re: Factory initialization

Postby Eric Clayberg » Sun Jan 21, 2007 10:25 am

You need to be using the latest build for your instance-based factory code to work.

Designer has built-in (hard coded) knowledge of the JGoodies DefaultComponentFactory class. This class was not handled via any general factory support.

The latest build generalizes this a bit so that instance based factories that follow the same pattern as used by the JGoodies DefaultComponentFactory class will also work.

The invocation code must look like Factory.getInstance().createSomeWidget("arg1", "arg2", "etc").
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest