Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to set Text in a Shape ?
How to set Text in a Shape ? [message #208591] Tue, 07 February 2006 11:20 Go to next message
Marcel Austenfeld is currently offline Marcel AustenfeldFriend
Messages: 160
Registered: July 2009
Senior Member
Hello

I've been experimenting with the GEF Shape Editor Example.
I want to have Text displayed in the Shape according
to the properties and when the properties have changed the
Text in the shape should have changed. Does anybody
know how i can realize this ?

Thanks in advance for any answer.
Re: How to set Text in a Shape ? [message #208600 is a reply to message #208591] Tue, 07 February 2006 16:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: guen.my-lounge.net

Marcel schrieb:
> Hello
>
> I've been experimenting with the GEF Shape Editor Example.
> I want to have Text displayed in the Shape according
> to the properties and when the properties have changed the
> Text in the shape should have changed. Does anybody
> know how i can realize this ?
>
> Thanks in advance for any answer.

Hi,

to get your figure connected to the eclipse property view try following
steps:

1. the model of the figure must implements IPropertySource

some code example:

public class ClassViewModel extends ModelPropertyChangeSupport
implements IPropertySource {

public static final String PROPERTY_NAME = "Name";
public static final String PROPERTY_NAME_ID = "name";
private String name;
private IPropertyDescriptor[] propertyDescriptor;
....
public Object getEditableValue() { return this; }

public IPropertyDescriptor[] getPropertyDescriptors() {
if ( this.propertyDescriptor == null ) {
this.propertyDescriptor = new IPropertyDescriptor[ 1 ];
this.propertyDescriptor[ 0 ] =
new TextPropertyDescriptor(
ClassViewModel.PROPERTY_NAME_ID,
ClassViewModel.PROPERTY_NAME );
}
return this.propertyDescriptor;
}

public Object getPropertyValue( Object id ) {
if ( id.equals( ClassViewModel.PROPERTY_NAME_ID ) )
return this.getName();
return null;
}

public boolean isPropertySet( Object id ) {
return true;
}

public void resetPropertyValue( Object id ) {}

public void setPropertyValue( Object id, Object value ) {
if ( id.equals( ClassViewModel.PROPERTY_NAME_ID ) ) {
this.setName( value.toString() );
this.firePropertyChange(
ClassViewModel.EVENT_PROPERTY_CHANGED,null,null);
}
}


2. the model must fire an event for the editpart to refresh visuals

some code example:

public class ClassEditPart extends AbstractGraphicalEditPart implements
PropertyChangeListener {

public void propertyChange( PropertyChangeEvent propertyChangeEvent ) {
if ( propertyChangeEvent.getPropertyName().equals(
ClassViewModel.EVENT_PROPERTY_CHANGED ) ) {
this.refreshVisuals();
}
}

protected void refreshVisuals() {
((ClassFigure)this.figure).setName(
(ClassViewModel)this.getModel()).getName() );
}


anyway, code code examples are on the folowing link
http://www13.plala.or.jp/observe/
even if i couldn't read the descriptions

Regards,
Christian
Re: How to set Text in a Shape ? [message #208617 is a reply to message #208600] Tue, 07 February 2006 18:05 Go to previous messageGo to next message
Marcel Austenfeld is currently offline Marcel AustenfeldFriend
Messages: 160
Registered: July 2009
Senior Member
I know this tutorial and it is by far the best description
how to implement a GEF Model(apart from the fact that i neither can read it). The refresh of the properties
works well but i can't get text in the Shapes of the
Shape Editor Example. I tried to adapt the code from the side without success.
Re: How to set Text in a Shape ? [message #208642 is a reply to message #208617] Tue, 07 February 2006 18:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: guen.my-lounge.net

Marcel schrieb:
> I know this tutorial and it is by far the best description
> how to implement a GEF Model(apart from the fact that i neither can read it). The refresh of the properties
> works well but i can't get text in the Shapes of the
> Shape Editor Example. I tried to adapt the code from the side without success.

try to give the figure a label for text


class ShapeEditPart ...

Label label = new Label();

protected IFigure createFigure() {
...
// add a label for text here
f.add( label );
...
}

protected void refreshVisuals() {
...
// set the text here
label.setText( (Model?)this.getModel.getText() );
...
}


hope that will help you
Re: How to set Text in a Shape ? [message #208693 is a reply to message #208642] Wed, 08 February 2006 08:11 Go to previous messageGo to next message
Marcel Austenfeld is currently offline Marcel AustenfeldFriend
Messages: 160
Registered: July 2009
Senior Member
I've tried that too but the Label didn't appear.
There is something missing. Maybe you can give me a hint !
Re: How to set Text in a Shape ? [message #208701 is a reply to message #208642] Wed, 08 February 2006 08:15 Go to previous messageGo to next message
Marcel Austenfeld is currently offline Marcel AustenfeldFriend
Messages: 160
Registered: July 2009
Senior Member
I was blind ! One Minute after i posted the previous message
i got the solution. I had to return the label and not the previous figure.... arrgggg.....
Thank you all for your help !
Re: How to set Text in a Shape ? [message #208726 is a reply to message #208642] Wed, 08 February 2006 10:40 Go to previous messageGo to next message
Marcel Austenfeld is currently offline Marcel AustenfeldFriend
Messages: 160
Registered: July 2009
Senior Member
I think i was a little bit to euphoric. Now i get
only the label because i return the label. But if i add the label to the figure it is not visible.
My question now is how i can make the label appear on the figure ?
Re: How to set Text in a Shape ? [message #208776 is a reply to message #208726] Wed, 08 February 2006 15:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ingo.koch[nospam].sap.com

You have to add a layout manager to the figure holding the label. e.g.
XYLayout

"Marcel" <marcel.au@web.de> wrote in message
news:960357.1139395257467.JavaMail.root@cp1.javalobby.org...
> I think i was a little bit to euphoric. Now i get
> only the label because i return the label. But if i add the label to the
figure it is not visible.
> My question now is how i can make the label appear on the figure ?
Re: How to set Text in a Shape ? [message #208791 is a reply to message #208776] Wed, 08 February 2006 16:30 Go to previous message
Marcel Austenfeld is currently offline Marcel AustenfeldFriend
Messages: 160
Registered: July 2009
Senior Member
Thanks all for the help !
Now it works.
Previous Topic:disable saving for GEF
Next Topic:model objects changing their identity
Goto Forum:
  


Current Time: Thu Apr 25 01:00:05 GMT 2024

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

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

Back to the top