001/* A tableau to create execution choice frames. 002 * 003 * Copyright (c) 2012 The Regents of the University of California. 004 * All rights reserved. 005 * 006 * '$Author: crawl $' 007 * '$Date: 2015-08-24 22:45:41 +0000 (Mon, 24 Aug 2015) $' 008 * '$Revision: 33631 $' 009 * 010 * Permission is hereby granted, without written agreement and without 011 * license or royalty fees, to use, copy, modify, and distribute this 012 * software and its documentation for any purpose, provided that the above 013 * copyright notice and the following two paragraphs appear in all copies 014 * of this software. 015 * 016 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 017 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 018 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 019 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 020 * SUCH DAMAGE. 021 * 022 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 023 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 024 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 025 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 026 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 027 * ENHANCEMENTS, OR MODIFICATIONS. 028 * 029 */ 030package org.kepler.ddp.gui; 031 032import org.kepler.ddp.actor.ExecutionChoice; 033import org.kepler.gui.frame.MultiCompositeTableau; 034 035import ptolemy.actor.gui.Effigy; 036import ptolemy.actor.gui.PtolemyEffigy; 037import ptolemy.actor.gui.Tableau; 038import ptolemy.actor.gui.TableauFactory; 039import ptolemy.kernel.CompositeEntity; 040import ptolemy.kernel.util.IllegalActionException; 041import ptolemy.kernel.util.NameDuplicationException; 042import ptolemy.kernel.util.NamedObj; 043import ptolemy.moml.LibraryAttribute; 044import ptolemy.util.MessageHandler; 045 046/** An editor tableau for execution choice constructs. 047 * 048 * @author Daniel Crawl 049 * @version $Id: ExecutionChoiceGraphTableau.java 33631 2015-08-24 22:45:41Z crawl $ 050 * 051 */ 052public class ExecutionChoiceGraphTableau extends MultiCompositeTableau { 053 /** Create a new execution choice editor tableau with the specified container 054 * and name. 055 * @param container The container. 056 * @param name The name. 057 * @exception IllegalActionException If the model associated with 058 * the container effigy is not an instance of ExecutionChoice. 059 * @exception NameDuplicationException If the container already 060 * contains an object with the specified name. 061 */ 062 public ExecutionChoiceGraphTableau(PtolemyEffigy container, String name) 063 throws IllegalActionException, NameDuplicationException { 064 this(container, name, null); 065 } 066 067 /** Create a new execution choice editor tableau with the specified container, 068 * name, and default library. 069 * @param container The container. 070 * @param name The name. 071 * @param defaultLibrary The default library, or null to not specify one. 072 * @exception IllegalActionException If the model associated with 073 * the container effigy is not an instance of ExecutionChoice. 074 * @exception NameDuplicationException If the container already 075 * contains an object with the specified name. 076 */ 077 public ExecutionChoiceGraphTableau(PtolemyEffigy container, String name, 078 LibraryAttribute defaultLibrary) throws IllegalActionException, 079 NameDuplicationException { 080 super(container, name); 081 } 082 083 /** Add default choice sub-workflows to the ExecutionChoice before 084 * opening it. 085 */ 086 @Override 087 public void createGraphFrame(CompositeEntity model, LibraryAttribute defaultLibrary) { 088 089 // set the selected tab to the model for this tableau. 090 // if the model is not one of the tabs, then setSelectedTab() does nothing. 091 final PtolemyEffigy effigy = (PtolemyEffigy)getContainer(); 092 final ExecutionChoice choice = (ExecutionChoice) effigy.getModel(); 093 094 try { 095 choice.addDefaults(); 096 } catch(IllegalActionException | NameDuplicationException e) { 097 MessageHandler.error("Error adding default choices.", e); 098 return; 099 } 100 101 super.createGraphFrame(model, defaultLibrary); 102 103 } 104 105 /////////////////////////////////////////////////////////////////// 106 //// public inner classes //// 107 108 /** A factory that creates graph editing tableaux for Ptolemy models. 109 */ 110 public static class Factory extends TableauFactory { 111 /** Create an factory with the given name and container. 112 * @param container The container. 113 * @param name The name of the entity. 114 * @exception IllegalActionException If the container is incompatible 115 * with this attribute. 116 * @exception NameDuplicationException If the name coincides with 117 * an attribute already in the container. 118 */ 119 public Factory(NamedObj container, String name) 120 throws IllegalActionException, NameDuplicationException { 121 super(container, name); 122 } 123 124 /** Create an instance of ExecutionChoiceGraphTableau for the specified effigy, 125 * if it is an effigy for an instance of ExecutionChoice. 126 * @param effigy The effigy for a ExecutionChoice. 127 * @return A new ExecutionChoiceGraphTableau, if the effigy is a PtolemyEffigy 128 * that references a ExecutionChoice, or null otherwise. 129 * @exception Exception If an exception occurs when creating the 130 * tableau. 131 */ 132 @Override 133 public Tableau createTableau(Effigy effigy) throws Exception { 134 if (!(effigy instanceof PtolemyEffigy)) { 135 return null; 136 } 137 138 NamedObj model = ((PtolemyEffigy) effigy).getModel(); 139 140 if (model instanceof ExecutionChoice) { 141 // Check to see whether this factory contains a 142 // default library. 143 LibraryAttribute library = (LibraryAttribute) getAttribute( 144 "_library", LibraryAttribute.class); 145 146 ExecutionChoiceGraphTableau tableau = new ExecutionChoiceGraphTableau( 147 (PtolemyEffigy) effigy, effigy.uniqueName("tableau"), 148 library); 149 return tableau; 150 } else { 151 return null; 152 } 153 } 154 } 155}