001/* An action for editing documentation.
002
003 Copyright (c) 2006-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
027 */
028package ptolemy.vergil.basic;
029
030import java.awt.event.ActionEvent;
031import java.util.List;
032
033import ptolemy.kernel.util.NamedObj;
034import ptolemy.moml.MoMLChangeRequest;
035import ptolemy.vergil.toolbox.FigureAction;
036
037///////////////////////////////////////////////////////////////////
038//// RemoveCustomDocumentationAction
039
040/**
041 This class provides an action for removing instance-specific documentation.
042
043 @author Edward A. Lee
044 @version $Id$
045 @since Ptolemy II 5.2
046 @Pt.ProposedRating Red (eal)
047 @Pt.AcceptedRating Red (johnr)
048 */
049@SuppressWarnings("serial")
050public class RemoveCustomDocumentationAction extends FigureAction {
051
052    /** Construct an instance of this action. */
053    public RemoveCustomDocumentationAction() {
054        super("Remove Custom Documentation");
055    }
056
057    ///////////////////////////////////////////////////////////////////
058    ////                         public methods                    ////
059
060    /** Perform the action by issuing a change request to remove the
061     *  the first (and only?) DocAttribute contained by the target,
062     *  if any.
063     *  @param e The action event.
064     */
065    @Override
066    public void actionPerformed(ActionEvent e) {
067        super.actionPerformed(e);
068
069        final NamedObj target = getTarget();
070
071        // If the object does not contain an attribute of class
072        // DocAttribute, then do nothing. Otherwise, remove it.
073        if (target != null) {
074            List docAttributeList = target.attributeList(DocAttribute.class);
075            if (docAttributeList.size() != 0) {
076                // Remove the doc attribute.
077                String moml = "<deleteProperty name=\""
078                        + ((DocAttribute) docAttributeList.get(0)).getName()
079                        + "\"/>";
080                MoMLChangeRequest request = new MoMLChangeRequest(this, target,
081                        moml);
082                target.requestChange(request);
083            }
084        }
085    }
086}