001/* An object that can create a tableau for a model.
002
003 Copyright (c) 2006-2016 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 */
027
028package ptolemy.vergil.basic;
029
030import java.util.Iterator;
031
032import diva.graph.GraphController;
033import diva.gui.toolbox.MenuFactory;
034import ptolemy.kernel.util.Attribute;
035import ptolemy.kernel.util.IllegalActionException;
036import ptolemy.kernel.util.NameDuplicationException;
037import ptolemy.kernel.util.NamedObj;
038
039/**
040 * An object that can create a tableau for a model.
041 *
042 * <p>This class allows the configuration option "contextMenuFactory" to
043 * be passed via the moml configuration.
044 * A suitable MenuFactory is instantiated and returned by a call to the
045 * createContextMenuFactory() method.
046 *
047 * @author Matthew Brooke
048 * @Pt.ProposedRating Red (cxh)
049 * @Pt.AcceptedRating Red (cxh)
050 * @version $Id$
051 */
052public class ContextMenuFactoryCreator extends Attribute {
053
054    /** Create a context menu factory with the given name and container.
055     *  @param container The container.
056     *  @param name The name.
057     *  @exception IllegalActionException If the container is incompatible
058     *   with this attribute.
059     *  @exception NameDuplicationException If the name coincides with
060     *   an attribute already in the container.
061     */
062    public ContextMenuFactoryCreator(NamedObj container, String name)
063            throws IllegalActionException, NameDuplicationException {
064        super(container, name);
065    }
066
067    ///////////////////////////////////////////////////////////////////
068    ////                         public methods                    ////
069
070    /**
071     * Create the KeplerContextMenuFactory class and return it.
072     *
073     * @param controller The GraphController in which to search for
074     * a ContextMenuFactoryCreate attribute.
075     * @return a KeplerContextMenuFactory
076     */
077    public MenuFactory createContextMenuFactory(GraphController controller) {
078        MenuFactory kcmFactory = null;
079
080        Iterator factories = attributeList(ContextMenuFactoryCreator.class)
081                .iterator();
082
083        while (factories.hasNext() && kcmFactory == null) {
084            ContextMenuFactoryCreator factory = (ContextMenuFactoryCreator) factories
085                    .next();
086            kcmFactory = factory.createContextMenuFactory(controller);
087        }
088        return kcmFactory;
089    }
090}