Designing custom widget similar to CTabFolder.Designing view

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

Designing custom widget similar to CTabFolder.Designing view

Postby lqbweb » Sat Mar 06, 2010 11:58 am

Hello...

Im designing a kind of composite but with two bars, on the top and on the right side (each bar holding different buttons to make visible one composite or another).... My control is taking shape.... I have added a paintListener to repaint both bars of my control and to place some buttons on them. When I run my program all looks fine but not in the SWT Designer. Looks the screenshot.... I have attached the source code as well...

I understand that SWT Designer parser will not render all the components as you explained on this post: http://www.instantiations.com/forum/viewtopic.php?f=1&t=2594&p=10248&hilit=design+widget#p10248 but is there any way to make my own customized control being renderized at designing time, i would like to do a similar control to CTabFolder where you can drop objects on each folder and you can change between folders at designing time....

Thanks
Attachments
screenshot.jpg
screenshot.jpg (48.41 KiB) Viewed 310 times
CIComposite.java
(5.18 KiB) Downloaded 24 times
lqbweb
 
Posts: 4
Joined: Sat Mar 06, 2010 6:03 am

Re: Designing custom widget similar to CTabFolder.Designing view

Postby lqbweb » Sun Mar 07, 2010 6:01 am

testing and trying some things i've make work what i got until now of my control....

Look the .java above.... If I place on the constructor of the control the following lines:

UpperComposite.setBounds(new Rectangle(0,0,1,1));
RightComposite.setBounds(new Rectangle(0,0,1,1));

Then, the SWT Designer is able to parse correctly what there is on addPaintListener (setting again the right Bounds). looks a bug of the designer...

Another interesting thing i have discover is that if I create the buttons on the setter and later i place them on the correct position by the addPainListener, then the designer is not able to reder it correctly.... But if I create the buttons all together on the addPaintListener, then it works like a charm.

Im still working on my control... I think i will have to change the point of view of the widget design if I want to select different "custom tabs" at designing time...

I attach the code which gets working correctly (comparing with the upper one)
Attachments
CIComposite.java
(5.29 KiB) Downloaded 19 times
lqbweb
 
Posts: 4
Joined: Sat Mar 06, 2010 6:03 am

Re: Designing custom widget similar to CTabFolder.Designing view

Postby Eric Clayberg » Sun Mar 07, 2010 7:53 am

The basic problem here is the timing involved. Layout should not be done in a paint listener.

The way you have it coded, the layout is not correct until after the widget is first painted and therefore after we grab an image of it to use in the design view.

Layout should be done in the layout() method and a resize listener should be added.

Code: Select all
    addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            layout();
        }
    });
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: Designing custom widget similar to CTabFolder.Designing view

Postby lqbweb » Sun Mar 07, 2010 10:37 am

ok, i got it working but maybe not very clean.... Because I needed my layout function to be called with the parameter PaintEvent in order to get the PaintEvent.GC and draw some lines over it, i was forced to implement both functions, layout() and layout(PaintEvent e). This last one called from the PaintListener.

My layout() function looks something like:
public void layout(){ this.getChildren()[0].pack(true); }

What I assume which is not very clean, but i cant get any other way to make it work....

Another thing more interesting Eric. I think it's not implemented yet, but there is any way to capture the widgetSelection of any button, label, etc. at designing time? or maybe any trick else. In my case i need it to implement my own TabFolder.

Thanks very much for this awesome product....
Attachments
CIComposite.java
(5.47 KiB) Downloaded 19 times
lqbweb
 
Posts: 4
Joined: Sat Mar 06, 2010 6:03 am

Re: Designing custom widget similar to CTabFolder.Designing view

Postby Eric Clayberg » Sun Mar 07, 2010 12:05 pm

There are no live widgets in the design view, so there are no events to capture.

If you need a TabFolder, I would recommend using either TabFolder or CTabFolder. You could subclass CTabFolder and override its drawing code and still take advantage of the considerable amount of hard-coded design time support for TabFolders built into SWT Designer. If you are trying to create custom TabFolder that you intend to be fully editable in the design view (with children and switchable pages), you aren't going to get very far with your current approach.
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: Designing custom widget similar to CTabFolder.Designing view

Postby lqbweb » Sun Mar 07, 2010 5:06 pm

thanks Eric for your quick answer....

I have finally gave up on my previous control design in order to ride on your advise.

I have got it to import all the custom.*.java classes from the swt source into my project and by the way the CTabFolder as well. I needed to do that because this control is not designed to be subclassed so I couldnt override its code unless my extended control wasnt on the same package. Because the .jar from the eclipse libs which I was using should be encrypted with any kind of protection, i was not able to mix and split up the package code between the .jar (holding the original CTabFolder source) and my project source files (holding my extended control)... Anyway its working now.

I have done some tries modifying the drawTabArea function code from the CTabFolder (I always mean by overriding from an extended class) and althought changes made over it are reflected at running time, they are not at the designer (what i've done basically is just comment all the code from that function for a quick look)....

I will make some tries more and post them since any body else could be interested...

Thanks Eric
lqbweb
 
Posts: 4
Joined: Sat Mar 06, 2010 6:03 am

Re: Designing custom widget similar to CTabFolder.Designing view

Postby Eric Clayberg » Mon Mar 08, 2010 4:15 pm

OK.
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 SWT Designer

Who is online

Users browsing this forum: Google [Bot] and 2 guests