Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to get the notification when the figure is moved?
How to get the notification when the figure is moved? [message #167743] Thu, 10 February 2005 14:53 Go to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

Hi,

When user drag and move a figure in my diagram, I need to
get a notification message (possibly a listener method?) such
that I can update the location information of the figure in
another view.

Would someone please help on how to do it?

Thanks
SL
Re: How to get the notification when the figure is moved? [message #167780 is a reply to message #167743] Thu, 10 February 2005 20:40 Go to previous message
Eclipse UserFriend
Originally posted by: no.mail.please

1) In your model, you should provide such a method :
public void setLocation(Point newLocation) {
if (newLocation == null) {
throw new IllegalArgumentException();
}
location.setLocation(newLocation);
=====> firePropertyChange(LOCATION_PROP, null, location); <=====
}

2) Then, in your editpart, implement PropertyChangeListener :
class MyEditPart extends AbstractGraphicalEditPart
implements PropertyChangeListener

3) And register as a listener to the model (here, the PC support was
defined in the abstract class ModelElement which every model class
subclasses) :
/**
* Upon activation, attach to the model element as a property change
listener.
*/
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
}
}

4) Don't forget to unregister on deactivation :
/**
* Upon deactivation, detach from the model element as a property
change listener.
*/
public void deactivate() {
if (isActive()) {
super.deactivate();
((ModelElement) getModel()).removePropertyChangeListener(this);
}
}

5) Then, just implement the propertyChange method :
/* (non-Javadoc)
* @see
java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt) {
String prop = evt.getPropertyName();
if (Model.LOCATION_PROP.equals(prop)) {

.... do what you want here .........


}
}

That's it.

--
Arnaud
Previous Topic:NPE in DeferredUpdateManager when using SWT_AWT in a modal Dialog
Next Topic:Layer needed
Goto Forum:
  


Current Time: Fri Apr 26 11:43:45 GMT 2024

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

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

Back to the top