001/* A representative of a ptolemy configuration model
002
003 Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026 */
027package ptolemy.actor.gui;
028
029import ptolemy.kernel.CompositeEntity;
030import ptolemy.kernel.util.IllegalActionException;
031import ptolemy.kernel.util.NameDuplicationException;
032import ptolemy.kernel.util.Workspace;
033
034///////////////////////////////////////////////////////////////////
035//// ConfigurationEffigy
036
037/**
038 An effigy for a Ptolemy II model.  This effigy allows views to be
039 easily created on the configuration that contains this effigy.
040
041 @author Steve Neuendorffer
042 @version $Id$
043 @since Ptolemy II 1.0
044 @Pt.ProposedRating Red (neuendor)
045 @Pt.AcceptedRating Red (neuendor)
046 */
047public class ConfigurationEffigy extends PtolemyEffigy {
048    /** Create a new effigy in the specified workspace with an empty string
049     *  for its name.
050     *  @param workspace The workspace for this effigy.
051     */
052    public ConfigurationEffigy(Workspace workspace) {
053        super(workspace);
054    }
055
056    /** Create a new effigy in the given directory with the given name.
057     *  @param container The directory that contains this effigy.
058     *  @param name The name of this effigy.
059     *  @exception IllegalActionException If the entity cannot be contained
060     *   by the proposed container.
061     *  @exception NameDuplicationException If the name coincides with
062     *   an entity already in the container.
063     */
064    public ConfigurationEffigy(CompositeEntity container, String name)
065            throws IllegalActionException, NameDuplicationException {
066        super(container, name);
067    }
068
069    ///////////////////////////////////////////////////////////////////
070    ////                         public methods                    ////
071
072    /** Specify the container, adding the entity to the list
073     *  of entities in the container.  If the container already contains
074     *  an entity with the same name, then throw an exception and do not make
075     *  any changes.  Similarly, if the container is not in the same
076     *  workspace as this entity, throw an exception.
077     *  If the entity is already contained by the container, do nothing.
078     *  If this entity already has a container, remove it
079     *  from that container first.  Otherwise, remove it from
080     *  the directory of the workspace, if it is present.
081     *  If the argument is null, then unlink the ports of the entity
082     *  from any relations and remove it from its container.
083     *  It is not added to the workspace directory, so this could result in
084     *  this entity being garbage collected.
085     *  Derived classes may override this method to constrain the container
086     *  to subclasses of CompositeEntity. This method is write-synchronized
087     *  to the workspace and increments its version number.
088     *  This class overrides the base class to additionally set the model
089     *  that this effigy views to be its toplevel container.
090     *  @param container The proposed container.
091     *  @exception IllegalActionException If the action would result in a
092     *   recursive containment structure, or if
093     *   this entity and container are not in the same workspace..
094     *  @exception NameDuplicationException If the name of this entity
095     *   collides with a name already in the container.
096     */
097    @Override
098    public void setContainer(CompositeEntity container)
099            throws IllegalActionException, NameDuplicationException {
100        super.setContainer(container);
101
102        if (container != null) {
103            setModel(container.toplevel());
104        }
105    }
106}