How to get the notification when the figure is moved? [message #167743] |
Thu, 10 February 2005 14:53 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03219 seconds