001/*
002 * Copyright (c) 2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: aschultz $'
006 * '$Date: 2010-12-23 19:01:04 +0000 (Thu, 23 Dec 2010) $' 
007 * '$Revision: 26600 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.kepler.gui.popups;
031
032import java.awt.Component;
033
034import javax.swing.JMenuItem;
035import javax.swing.tree.TreePath;
036
037import org.kepler.gui.ShowDocumentationAction;
038import org.kepler.gui.component.OpenCompositeAction;
039import org.kepler.gui.lsid.LibLsidViewerAction;
040import org.kepler.kar.KARFile;
041import org.kepler.objectmanager.library.LibIndex;
042import org.kepler.objectmanager.library.LibItem;
043import org.kepler.objectmanager.lsid.KeplerLSID;
044
045/**
046 * Subclass of LibraryPopup that handles Components that are contained within a
047 * KAR in the library.
048 * 
049 * @author Aaron Schultz
050 * 
051 */
052public class KARComponentPopup extends LibraryPopup {
053
054        private static final long serialVersionUID = 1404026700541313696L;
055
056        public KARComponentPopup(TreePath path, Component comp) {
057                super(path, comp);
058
059        }
060
061        public void initialize() {
062
063                Object obj = getSelectionPath().getLastPathComponent();
064                LibItem li = getInfo();
065                KeplerLSID lsid = li.getLsid();
066                
067                if (li.getType() == LibIndex.TYPE_COMPONENT) {
068
069                        // Open
070                        String className = li.getAttributeValue(LibIndex.ATT_CLASSNAME);
071                        String ceClassName = "ptolemy.kernel.CompositeEntity";
072                        boolean isComposite = false;
073                        try {
074                                isComposite = KARFile.isSubclass(ceClassName, className);
075
076                                if (isComposite) {
077                                        OpenCompositeAction oca = new OpenCompositeAction(getParentFrame());
078                                        oca.setLsidToOpen(lsid);
079                                        this.add(new JMenuItem(oca));
080                                }
081                        } catch (ClassNotFoundException e) {
082                                // ignore
083                        }
084
085                        // View Documentation
086                        ShowDocumentationAction sda = new ShowDocumentationAction(
087                                        getSelectionPath(), getParentFrame());
088                        sda.setPtolemyFrame(getParentFrame());
089                        sda.setLsidToView(lsid);
090                        this.add(new JMenuItem(sda));
091
092                        // View LSID
093                        LibLsidViewerAction lva = new LibLsidViewerAction(getParentFrame());
094                        lva.setLsidToView(lsid);
095                        this.add(new JMenuItem(lva));
096
097                } else if (getInfo().getType() == LibIndex.TYPE_NAMED_OBJ) {
098
099                        // View LSID
100                        LibLsidViewerAction lva = new LibLsidViewerAction(getParentFrame());
101                        lva.setLsidToView(lsid);
102                        this.add(new JMenuItem(lva));
103
104                } else if (getInfo().getType() == LibIndex.TYPE_OBJECT) {
105                        
106                        // Open Object in external editor
107                        // TODO
108                        
109                }
110
111        }
112}