Shouldn't removing the actor also be done in a ChangeRequest?


This seems like a very puzzling thing to do... What are you trying
to accomplish?

Edward

At 10:34 AM 11/21/2003 -0800, Chad Berkley wrote:
hi,

I'm trying to remove and actor from the actorLibrary model, change it, then re-add it. For some reason, when it re-adds, you don't see the changes that were made.

Here's the code that I'm using:

List l = actorLibrary.entityList();
for(int i=0; i<l.size(); i++)
{  //look for the actor in the container.if it's there, remove it
  ComponentEntity ce = (ComponentEntity)l.get(i);
  if(ce.getName().equals(actor.getName()))
  {
    try
    {
      ce.setContainer(null); //remove the found entity
      StringWriter buffer = new StringWriter();
      ce.exportMoML(buffer, 1);
      ChangeRequest request = new MoMLChangeRequest(ce, actorLibrary,
        buffer.toString());
      actorLibrary.requestChange(request);
      break;
    }
    catch(Exception e)
    {
      throw new RuntimeException("Error removing existing actor from " +
        "container: " + e.getMessage());
    }
  }
}

actor.setContainer(actorLibrary);
StringWriter buffer = new StringWriter();
actor.exportMoML(buffer, 1);
ChangeRequest request = new MoMLChangeRequest(actor, actorLibrary,
  buffer.toString());
actorLibrary.requestChange(request);


When the ChangeRequest is made within the loop, it seems to *add* the actor to the library instead of remove it, even though I set the container to null. Vergil gives me an error when it hits the 2nd ChangeRequest saying that there is already an Entity with the same name in the model. If I remove the ChangeRequest within the loop, it appears to work (i.e. it does not give any error when it leaves the loop and resets the container) but it does not, in fact, update the model.


Any ideas?

thanks,
chad
--
-----------------------
Chad Berkley
National Center for
Ecological Analysis
and Synthesis (NCEAS)
[EMAIL PROTECTED]
-----------------------


---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]

------------ Edward A. Lee, Professor 518 Cory Hall, UC Berkeley, Berkeley, CA 94720 phone: 510-642-0455, fax: 510-642-2739 [EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal


---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]

Reply via email to