001/* A model for an attribute as a diva graph node. 002 003 Copyright (c) 1999-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 */ 027package ptolemy.vergil.kernel; 028 029import java.util.Iterator; 030 031import diva.util.NullIterator; 032import ptolemy.kernel.util.ChangeRequest; 033import ptolemy.kernel.util.Locatable; 034import ptolemy.kernel.util.NamedObj; 035import ptolemy.moml.MoMLChangeRequest; 036import ptolemy.vergil.basic.NamedObjNodeModel; 037 038////////////////////////////////////////////////////////////////////////// 039//// AttributeNodeModel 040 041/** 042 A model for an attribute as a diva graph node. 043 This is used for visible attributes. 044 045 @author Steve Neuendorffer and Edward A. Lee 046 @version $Id$ 047 @since Ptolemy II 2.0 048 @Pt.ProposedRating Red (yourname) 049 @Pt.AcceptedRating Red (reviewmoderator) 050 */ 051public class AttributeNodeModel extends NamedObjNodeModel { 052 /** Return a MoML String that will delete the given node from the 053 * Ptolemy model. 054 * @param node The node to be deleted. 055 * @return A valid MoML string. 056 */ 057 @Override 058 public String getDeleteNodeMoML(Object node) { 059 NamedObj attribute = ((Locatable) node).getContainer(); 060 return "<deleteProperty name=\"" + attribute.getName() + "\"/>\n"; 061 } 062 063 /** Return the graph parent of the given node. 064 * @param node The node, which is assumed to be an instance of Locatable. 065 * @return The container of the location's container, which should be 066 * the root of the graph. 067 */ 068 @Override 069 public Object getParent(Object node) { 070 return ((Locatable) node).getContainer().getContainer(); 071 } 072 073 /** Return an iterator over the edges coming into the given node. 074 * @param node The node. 075 * @return A NullIterator, since no edges are attached to attributes. 076 */ 077 @Override 078 public Iterator inEdges(Object node) { 079 return new NullIterator(); 080 } 081 082 /** Return an iterator over the edges coming out of the given node. 083 * @param node The node. 084 * @return A NullIterator, since no edges are attached to attributes. 085 */ 086 @Override 087 public Iterator outEdges(Object node) { 088 return new NullIterator(); 089 } 090 091 /** Remove the given node from the model. The node is assumed 092 * to be an instance of Locatable belonging to an attribute. 093 * The removal is accomplished by queueing a change request 094 * with the container. 095 * @param eventSource The source of the remove event (ignored). 096 * @param node The node. 097 */ 098 @Override 099 public void removeNode(final Object eventSource, final Object node) { 100 NamedObj attribute = ((Locatable) node).getContainer(); 101 NamedObj container = attribute.getContainer(); 102 ; 103 104 String moml = getDeleteNodeMoML(node); 105 106 // Note: The source is NOT the graph model. 107 ChangeRequest request = new MoMLChangeRequest(this, container, moml); 108 container.requestChange(request); 109 } 110}