Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Custom factory creates unwanted SWT widgets(I've registered a static custom factory method in SWT designer but it creates 2 widgets rather than 1)
Custom factory creates unwanted SWT widgets [message #792980] Tue, 07 February 2012 16:25 Go to next message
Eclipse UserFriend
I've created a static widget factory and have added the factory method to the palette in SWT Designer.

When I try to use it to add a widget to a SectionPart, by dragging the factoryMethod icon from the palette to the GUI design pane then overtyping the name of the widget, I get 2 widgets, 1 correctly formed one created using the factory method and a 2nd anonymous one created with default arguments.

I've noticed that if I don't change the name of the widget I just get the factory created widget, but of course it has the wrong name.

Can anyone tell me what I'm doing wrong?

I've just installed the latest windowbuilder and it still happens.


The code I get looks like this:

...
Label lblNewlabel = PhilsLabelFactory.createLabel(container, Messages.MultiColumnEditorSectionPart_lblNewlabel_text);
new Label(container, SWT.NONE);
...

the factory looks like this:

...
package phil.example.layout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;

public final class PhilsLabelFactory {
/**
* @wbp.factory
* @wbp.factory.parameter.source text "default"
*/
public static Label createLabel(Composite parent, String text) {
Label label = new Label(parent, SWT.NONE);
label.setText(text);
return label;
}
/**
* @wbp.factory
*/
public static Button createButton(Composite parent) {
Button button = new Button(parent, SWT.CHECK);
return button;
}
}
...


Thanks
Phil

[Updated on: Tue, 07 February 2012 17:55] by Moderator

Report message to a moderator

Re: Custom factory creates unwanted SWT widgets [message #793051 is a reply to message #792980] Tue, 07 February 2012 18:06 Go to previous messageGo to next message
Eclipse UserFriend
It would useful to see a complete test case. Depending on the layout manager you are using and where you dropped the widget, those results could be entirely expected. The second, blank Label looks like a simple spacer widget used in a GridLayout.

If you create a panel using absolute layout, do you see the same thing happen (e.g., two widgets created)?
Re: Custom factory creates unwanted SWT widgets [message #793079 is a reply to message #793051] Tue, 07 February 2012 18:57 Go to previous message
Eclipse UserFriend
Thanks Eric, you're spot on.

It was the first time that I'd tried out factory methods and assumed I was doing something wrong.

P.I.C.N.I.C.
Previous Topic:Error: Could not find or load main class
Next Topic:No WindowBuilder Pro Folder in New Wizard
Goto Forum:
  


Current Time: Tue Feb 11 01:54:02 GMT 2025

Powered by FUDForum. Page generated in 0.05761 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top