Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » SWT widgets in Figures
SWT widgets in Figures [message #168426] Wed, 16 February 2005 00:21 Go to next message
Eclipse UserFriend
Originally posted by: freddie_nurke.hotmail.com

I have a GEF canvas that is covered, for the most part, in Labels, from
which I inherit for most of my Figures. I have one object that I'd like
to represent as an SWT composite enclosing some other UI. I think what
I need to do is get a hold of the FigureCanvas and use that as the
parent for the SWT control, which would be a field in my Figure. Is
that the correct approach? If so, how do I get from a Figure to the
FigureCanvas on which it's placed? If not, what's the recommended way
to do this? How should I account for the fact that I'm creating
interactive UI in my Figure, and therefore it's technically also part Part?
Re: SWT widgets in Figures [message #168485 is a reply to message #168426] Wed, 16 February 2005 13:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marcel.frei.gft.com

I'm a GEF newbie so this might not be the best solution.
Using swt is not the best solution because it will break the mvc pattern.
The solution I have isn't nice but it works.
First you create a attribute for your swt control in your model and a
method to set the control.
It might look like this:
public void createCombo(Composite parent, int style)

In this method you create the swt control.
Now you have to call the createCombo method in the editpart.
This is done in the EditPart according to the model.
I used the createFigure method to do it for me since the swt control is
somehow the figure. You have to pass along the canvas to the createCombo
method.
You can get the canvas like this: (Canvas)getViewer().getControl()

Now you see why it breaks the mvc pattern because your swt contol holds
the data and is also the graphical representation.

If you want to move the swt control you need a figure you can select.
So my createFigure looks like this:
protected IFigure createFigure() {
IFigure f = new RectangleFigure();

f.setOpaque(true); // non-transparent figure
getCastedModel().createCombo((Canvas)getViewer().getControl( ),SWT.DROP_DOWN);
return f;
}

If you'd use it like this you would see that you can move your
RectangleFigure but the swt combo stays at the same place.
So you have to call setBounds method of your swt control whenever you
change the location or size of your model.

Another problem you will encounter is when you delete your element on the
diagram. the swt contol will still be there. i created a deleteCommand for
the model with the swt control where i call the newly created
disposeSwtControl method of my model, where the dispose method of the swt
control is called.



Fred Nurke wrote:

> I have a GEF canvas that is covered, for the most part, in Labels, from
> which I inherit for most of my Figures. I have one object that I'd like
> to represent as an SWT composite enclosing some other UI. I think what
> I need to do is get a hold of the FigureCanvas and use that as the
> parent for the SWT control, which would be a field in my Figure. Is
> that the correct approach? If so, how do I get from a Figure to the
> FigureCanvas on which it's placed? If not, what's the recommended way
> to do this? How should I account for the fact that I'm creating
> interactive UI in my Figure, and therefore it's technically also part Part?
Re: SWT widgets in Figures [message #168493 is a reply to message #168426] Wed, 16 February 2005 13:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

The EditPart has access to the Canvas. getViewer().getControl()

"Fred Nurke" <freddie_nurke@hotmail.com> escreveu na mensagem
news:cuu3m7$1st$1@www.eclipse.org...
>I have a GEF canvas that is covered, for the most part, in Labels, from
>which I inherit for most of my Figures. I have one object that I'd like to
>represent as an SWT composite enclosing some other UI. I think what I need
>to do is get a hold of the FigureCanvas and use that as the parent for the
>SWT control, which would be a field in my Figure. Is that the correct
>approach? If so, how do I get from a Figure to the FigureCanvas on which
>it's placed? If not, what's the recommended way to do this? How should I
>account for the fact that I'm creating interactive UI in my Figure, and
>therefore it's technically also part Part?
Re: SWT widgets in Figures [message #168565 is a reply to message #168493] Wed, 16 February 2005 20:18 Go to previous message
Eclipse UserFriend
Originally posted by: freddie_nurke.hotmail.com

Perfect! Thanks, Randy. Since it's in the EditPart, I was prompted to
move the code to the Controller, which makes more sense in this
architecture anyway. That's exactly what I needed.
Previous Topic:label on connection with bendpoints not relocating
Next Topic:showing properties for a list of items
Goto Forum:
  


Current Time: Sat Apr 27 03:40:15 GMT 2024

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

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

Back to the top