|
Re: How to set Text in a Shape ? [message #208600 is a reply to message #208591] |
Tue, 07 February 2006 16:06 |
Eclipse User |
|
|
|
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 #208642 is a reply to message #208617] |
Tue, 07 February 2006 18:31 |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03838 seconds