001/* 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2012-07-07 00:17:06 +0000 (Sat, 07 Jul 2012) $' 007 * '$Revision: 30140 $' 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; 033import java.util.Vector; 034 035import javax.swing.JMenu; 036import javax.swing.JMenuItem; 037import javax.swing.JSeparator; 038import javax.swing.tree.TreePath; 039 040import org.kepler.gui.ShowDocumentationAction; 041import org.kepler.gui.component.OpenCompositeAction; 042import org.kepler.gui.component.ToggleLsidAction; 043import org.kepler.gui.lsid.LibLsidViewerAction; 044import org.kepler.kar.KARFile; 045import org.kepler.objectmanager.library.LibIndex; 046import org.kepler.objectmanager.library.LibItem; 047import org.kepler.objectmanager.lsid.KeplerLSID; 048 049/** 050 * Subclass of LibraryPopup that handles library items that are components and 051 * not inside of a KAR (i.e. components inside ontologies). 052 * 053 * @author Aaron Schultz 054 * 055 */ 056public class OntologyComponentPopup extends LibraryPopup { 057 058 public OntologyComponentPopup(TreePath path, Component comp) { 059 super(path, comp); 060 } 061 062 public void initialize() { 063 064 //Object obj = getSelectionPath().getLastPathComponent(); 065 066 LibItem li = getInfo(); 067 KeplerLSID lsid = li.getLsid(); 068 069 if(lsid != null) { 070 // LSID Toggle Menu 071 addLsidToggleMenu(lsid); 072 } 073 074 // Open 075 String className = li.getAttributeValue(LibIndex.ATT_CLASSNAME); 076 String filePath = li.getAttributeValue(LibIndex.ATT_XMLFILE); 077 if(className == null && filePath != null) { 078 className = "ptolemy.actor.TypedCompositeActor"; 079 } 080 String ceClassName = "ptolemy.kernel.CompositeEntity"; 081 boolean isComposite = false; 082 try { 083 isComposite = KARFile.isSubclass(ceClassName, className); 084 085 if (isComposite) { 086 OpenCompositeAction oca = new OpenCompositeAction(getParentFrame()); 087 oca.setLsidToOpen(lsid); 088 oca.setFilePath(filePath); 089 this.add(new JMenuItem(oca)); 090 } 091 } catch (ClassNotFoundException e) { 092 // ignore 093 } 094 095 // XXX for now do not add View Documentation for xml files 096 if(filePath == null) { 097 // View Documentation 098 ShowDocumentationAction sda = new ShowDocumentationAction( 099 getSelectionPath(), getParentFrame()); 100 sda.setPtolemyFrame(getParentFrame()); 101 sda.setLsidToView(lsid); 102 this.add(new JMenuItem(sda)); 103 } 104 105 if(lsid != null) { 106 // View LSID 107 LibLsidViewerAction lva = new LibLsidViewerAction(getParentFrame()); 108 lva.setLsidToView(lsid); 109 this.add(new JMenuItem(lva)); 110 } 111 } 112 113 /** 114 * It is possible that there is more than one LSID associated with this 115 * Library Item. Add a menu item that allows the user to toggle which LSID 116 * is currently the default LSID. If there is only one lsid associated with 117 * this item then we don't add the menu. 118 */ 119 private void addLsidToggleMenu(KeplerLSID lsid) { 120 121 JMenu jm = new JMenu(lsid.toString()); 122 Vector<KeplerLSID> lsids = getInfo().getLsids(); 123 if (lsids.size() > 1) { 124 for (KeplerLSID altLSID : lsids) { 125 JMenuItem jmi = new JMenuItem(altLSID.toString()); 126 ToggleLsidAction tla = new ToggleLsidAction(); 127 tla.setLiid(this.getLiid()); 128 jmi.addActionListener(tla); 129 jm.add(jmi); 130 } 131 this.add(jm); 132 this.add(new JSeparator()); 133 } 134 } 135}