Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to update the name of a GraphicalEditor ?
How to update the name of a GraphicalEditor ? [message #178691] Thu, 21 April 2005 10:09 Go to next message
Eclipse UserFriend
Originally posted by: steph_poubelle.yahoo.fr

Here is my problem.

I get a tree view. I can open item of this tree view in a GraphicalEditor.
I also can change the name of an item in the tree view.
How can I update the name of the editor associated to the renamed item
when it is already opened ?

Thanks.

Stephane
Re: How to update the name of a GraphicalEditor ? [message #178735 is a reply to message #178691] Thu, 21 April 2005 20:35 Go to previous messageGo to next message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Hi,


Add this code to your model ( or in the common base class!)
============================================================
public class MyModel implements IPropertySource
{
public static final String PROPERTY_NAME_CHANGED = "name changed";
private PropertyChangeSupport listeners;

public void setName(String name)
{
String save = getName();

if (StringUtil.saveEquals(name, save))
return;

this.name=name;

firePropertyChange(PROPERTY_NAME_CHANGED, save, this.name);
}

public void addPropertyChangeListener(PropertyChangeListener listener)
{
listeners.addPropertyChangeListener(listener);
}

public void removePropertyChangeListener(PropertyChangeListener listener)
{
listeners.removePropertyChangeListener(listener);
}

public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
{
listeners.firePropertyChange(propertyName, oldValue, newValue);
}
}




Add the code to the Editor
============================================================ ================================

public class MyEditor extends GraphicalEditorWithPalette implements PropertyChangeListener
{
......

protected void initializeGraphicalViewer()
{
....
.
MyEditorInput myInput = (MyEditorInput)getEditorInput();
setPartName(myInput.getMyModel().getName());

myInput.getMyModel().addPropertyChangeListener(this);
}

public void dispose()
{
MyEditorInput myInput = (MyEditorInput)getEditorInput();
myInput.getMyModel().removePropertyChangeListener(this);

super.dispose();
}

public void propertyChange(PropertyChangeEvent ev)
{
if(ev.getPropertyName()==MyModel.PROPERTY_NAME_CHANGED)
setPartName((String)ev.getNewValue());
}
Re: How to update the name of a GraphicalEditor ? [message #178743 is a reply to message #178735] Thu, 21 April 2005 20:36 Go to previous message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Don't forget this:


public MyModel()
{
listeners = new PropertyChangeSupport(this);
}
Previous Topic:Creating complex figures
Next Topic:how to response model elements relation changes
Goto Forum:
  


Current Time: Thu Apr 25 08:48:01 GMT 2024

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

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

Back to the top