Desinger puts auto generated code in the wrong method

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

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

Desinger puts auto generated code in the wrong method

Postby kernahr5 » Tue Feb 03, 2004 10:07 am

Hi

I have a issue when using the designer on a new class that inherits from an abstract class that is a direct subclass of composite.

Composite
|
View (Abstract)
|
NewClass

The new class has two methods, a constructor

public TestView(Composite parent, int style)
{
super(parent, style);
}

and a standard createContents() method. which is public.

My problem is than when I use the designer to add widgets the code is placed in the constructor, and the create contents method is not displayed in the drop down box that specifies the method to use for the auto generated code.

However if I go to my source and move the auto generated code to the createContents method, then go back to the designer view. The createContents method is in the drop down list and any subsequent widgets added through the designer are placed in the correct method.

Does anyone know how to get round this so code start going in the createContents method by default

I'm running
Designer Product: SWT Designer
Designer Version: 1.2.3
Platform Product: IBM WebSphere Studio Application Developer
Platform Version: 5.1.1

Regards

Rob
kernahr5
 
Posts: 2
Joined: Tue Feb 03, 2004 9:48 am

Re: Desinger puts auto generated code in the wrong method

Postby Eric Clayberg » Tue Feb 03, 2004 10:45 am

kernahr5 wrote:Does anyone know how to get round this so code start going in the createContents method by default

The problem here is that the Designer can't read your mind in the absence of any other information. It's not putting the code in the "wrong" method, because there is no defined standard here. The createContents() method is used in some cases, but it a fairly weak convention at best.

When the Designer looks at a class, it tries to determine the default method in which to generate code. That method will generally be the one where the other existing widgets are generated. If there aren't any existing widgets, it will look to the method that defines the main container used for the layout. In the case of a Composite, that would be the constructor. Once you actually refactored the class to place the widget definitions into the createContents() method, it could identify that as the primary target method and place any new widgets there. Fortunately, the Designer does not force you into a specific pattern, and will allow you to refactor the code to make changes like this.
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

Postby kernahr5 » Tue Feb 03, 2004 10:58 am

Hi

I understand, and that seems sensible, however in our case it seems a good idea to list all the class methods in the drop down on the designer screen.

At least we know what causes it, and we can work round it.

Thanks for the quick response.

Kind Regards

Rob
kernahr5
 
Posts: 2
Joined: Tue Feb 03, 2004 9:48 am


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest