Now all seems to work fine, I must to check it for possible bugs but I put
the code below, I hope it helps someone, someday, somewhere,...

public class FigMacmasAssociation extends FigAssociation {

   private PropertyChangeListener removeModelElementListener;

   public FigMacmasAssociation(){
   super();
   }

   public FigMacmasAssociation(Object edge, Layer lay){
   super(edge, lay);
   }

   public void updateListeners(Object oldOwner, Object newOwner) {

   Object obj = oldOwner;

   if(obj == null)
       obj=newOwner;

   if(removeModelElementListener!=null)
      Model.getPump
().removeModelEventListener(removeModelElementListener,obj);
   super.updateListeners(oldOwner, newOwner);
   addRemoveAssociationListener(newOwner);
   }

   protected void addRemoveAssociationListener(Object owner){
   //System.out.println("RAVNOCK metodo removeAssociationListener");

   removeModelElementListener=new PropertyChangeListener() {
              public void propertyChange(PropertyChangeEvent evt) {
                  //System.out.println("RAVNOCK metodo disparado");
                  if (evt instanceof RemoveAssociationEvent) {
                      // do what you want to do when this event is fired
                  //System.out.println("RAVNOCK evento disparado");

                  return;
                  }
              }
          };

   Model.getPump().addClassModelEventListener(removeModelElementListener,
Model.getMetaTypes().getModelElement(),(String []) null);
   }
}

2007/7/12, David Orejuela <[EMAIL PROTECTED]>:

Well, It's really confusing the method name, sorry. And sorry again, I'll
fix the second error: never removing the listener. :(

And to the last question:
When I add to my diagram a new association between my figs, I need that
new attributes are created inside them. So when the association is deleted,
I must delete the associations too. Then, when I create the association, I
listen for the delete, and when it happens I look for the attributes and
delete them, probably with the removeFromDiagramImpl method. (and also
remove the listener?).
I don't know other way to obtain this result, maybe it's wrong , or not?
some help?

Thanks.



2007/7/12, Michiel van der Wulp <[EMAIL PROTECTED]>:
>
>  Hi David,
>
> Just a guess: maybe you should add the constructor without parameters?
>
> What I wanted to remark:
> The intention of the updateListeners method is to remove and add
> listeners. This function is called many times. And your code keeps adding
> new listeners, without ever removing them...
>
> Also, your function removeAssociationListener() has the intention to ADD
> a listener, so you better name it addRemoveAssociationListener().
>
> Also, why would you want to listen to the removal of modelelements? You
> can use the removeFromDiagramImpl() method to do some cleaning up.
>
> Regards,
> Michiel
>
>
>
>
> ----- Original Message -----
>  *From:* David Orejuela <[EMAIL PROTECTED]>
> *To:* [email protected]
> *Sent:* Thursday, July 12, 2007 1:28 PM
> *Subject:* Re: [argouml-dev] ModelEventPump's property names
>
> I've override the updateListeners method with my new
> removeAssociationListener, that only registers the new event listener (at
> the moment it does nothig), to see if works fine and the code is executed
> when I delete an association.
>
> But there is a problem: now the associations aren't created!
> Someone knows why?
> The code is the following ( I have created my own associaton fig class
> FigMacmasAssociation)
>
> public class FigMacmasAssociation extends FigAssociation {
>
>     public FigMacmasAssociation(Object edge, Layer lay){
>     super(edge, lay);
>     }
>     public void updateListeners(Object oldOwner, Object newOwner) {
>     removeAssociationListener();
>     super.updateListeners (oldOwner, newOwner);
>     }
>
>     protected void removeAssociationListener(){
>
>     Model.getPump().addModelEventListener(new PropertyChangeListener() {
>
>                public void propertyChange(PropertyChangeEvent evt) {
>
>                    if (evt instanceof RemoveAssociationEvent) {
>                        // do what you want to do when this event is
> fired
>
>                    }
>                }
>            }, Model.getMetaTypes().getModelElement());
>     }
>
> }
>
> 2007/7/12, David Orejuela <[EMAIL PROTECTED] >:
> >
> > Very thanks for all the information, actually I'm working with it
> >
> > 2007/7/12, Michiel van der Wulp <[EMAIL PROTECTED]>:
> > >
> > >  Hi David,
> > >
> > > For the FigAssociation to receive other events, you may have to
> > > overrule the following method of FigAssociation:
> > >
> > >     public void updateListeners(Object oldOwner, Object newOwner) {
> > >         removeAllElementListeners();
> > >         if (newOwner != null) {
> > >             addElementListener(newOwner, new String[] {"isAbstract",
> > > "remove"});
> > >         }
> > >         /* No further listeners required in this case - the rest is
> > > handled
> > >          * by the notationProvider and sub-Figs. */
> > >     }
> > >
> > > Regards,
> > > Michiel
> > >
> > >
> > >
> > >  ----- Original Message -----
> > >  *From:* David Orejuela <[EMAIL PROTECTED]>
> > > *To:* [email protected]
> > > *Sent:* Thursday, July 12, 2007 9:05 AM
> > > *Subject:* Re: [argouml-dev] ModelEventPump's property names
> > >
> > > Hi Bogdan,
> > > I'm also interested in this topic but I want to capture a
> > > RemoveAssociationEvent from a FigAssociation class. I'm a newbie and I 
don't
> > > know what I must do, I have written a modelChangued method with code for
> > > this event, but this method is never executed. have I more to do to enable
> > > it ?
> > >
> > > 2007/7/11, Bogdan Ciprian Pistol <[EMAIL PROTECTED]>:
> > > >
> > > > Hello,
> > > >
> > > > I have some trouble understanding what are the valid property
> > > > names of
> > > > the ModelEventPump.
> > > >
> > > > Here is what I investigated so far (please notify me if I'm
> > > > wrong):
> > > >
> > > > The ModelEventPump notify it's listeners on only 4 kinds of events
> > > > changes:
> > > > DeleteInstanceEvent, AttributeChangeEvent, RemoveAssociationEvent
> > > > and
> > > > AddAssociationEvent.
> > > >
> > > > DeleteInstanceEvent uses the source UML element (the notifier) and
> > > > a
> > > > property name (a string)
> > > > that in some parts of ArgoUML is expected to be "remove" and in
> > > > other
> > > > parts it doesn't matter it's value, the only test done is if the
> > > > event
> > > > is instance of DeleteInstanceEvent.
> > > >
> > > > AttributeChangeEvent is initialized with the source UML element, a
> > > > property name, old and new values. The propery name can have very
> > > > different values like: "name", "isAbstract", "isActive",
> > > > "isRoot", "isLeaf", "isSpecification", "visibility",
> > > > "multiplicity",
> > > > "ownerScope", "changeability",
> > > > "targetScope" and maybe other values. (I extracted these values
> > > > while
> > > > debugging).
> > > >
> > > > RemoveAssociation and AddAssociation events (from the MDR
> > > > implementation source code) doesn't give me clues how should be
> > > > used
> > > > because the AssociationEvent (from MDR) has no source code or
> > > > javadoc.
> > > > The events are using AssociationEvent#getNewElement(),
> > > > AssociationEvent#getEndName(), AssociationEvent#getFixedElement(),
> > > > which I do not know what are doing.
> > > >
> > > > The main problem for me are the valid values for property names.
> > > >
> > > > Bogdan,
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > >  ------------------------------
> > >
> > > No virus found in this incoming message.
> > > Checked by AVG Free Edition.
> > > Version: 7.5.476 / Virus Database: 269.10.2/894 - Release Date:
> > > 10/07/2007 17:44
> > >
> > >
> >
>  ------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.476 / Virus Database: 269.10.2/894 - Release Date:
> 10/07/2007 17:44
>
>

Reply via email to