001/* 002 * Copyright (c) 2012 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2014-08-06 23:09:13 +0000 (Wed, 06 Aug 2014) $' 007 * '$Revision: 32860 $' 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.awt.event.ActionEvent; 034 035import javax.swing.AbstractAction; 036import javax.swing.JMenuItem; 037import javax.swing.tree.TreePath; 038 039import org.kepler.gui.ConfigureNamedObjAction; 040import org.kepler.gui.ShowDocumentationAction; 041import org.kepler.gui.TabbedLookInsideAction; 042import org.kepler.gui.component.OpenCompositeAction; 043import org.kepler.gui.frame.TabbedKeplerGraphFrame; 044import org.kepler.moml.NamedObjId; 045import org.kepler.objectmanager.lsid.KeplerLSID; 046 047import ptolemy.actor.gui.PtolemyFrame; 048import ptolemy.kernel.ComponentEntity; 049import ptolemy.kernel.Relation; 050import ptolemy.kernel.util.NamedObj; 051import ptolemy.vergil.basic.BasicGraphFrame; 052 053/** 054 * Subclass of NoLiidLibraryPopup that handles Components that are contained within 055 * the workflow Outline view. 056 * 057 * @author Philippe Huynh 058 * 059 */ 060public class OutlineComponentPopup extends NoLiidLibraryPopup { 061 062 public OutlineComponentPopup(TreePath path, Component comp) { 063 super(path, comp); 064 065 } 066 067 @Override 068 public void initialize() { 069 070 final Object obj = getSelectionPath().getLastPathComponent(); 071 KeplerLSID lsid = null; 072 NamedObjId namedObjId = org.kepler.moml.NamedObjId.getIdAttributeFor((NamedObj) obj); 073 if(namedObjId != null) { 074 lsid = namedObjId.getId(); 075 } 076 077 final PtolemyFrame frame = getParentFrame(); 078 079 // Configure 080 // do not configure attributes, ports, relations, etc. 081 if (obj instanceof ComponentEntity) { 082 ConfigureNamedObjAction action = new ConfigureNamedObjAction("Configure", (NamedObj) obj, frame); 083 add(new JMenuItem(action)); 084 } 085 086 // if it's a composite, add Open menu item 087 if (obj instanceof ptolemy.kernel.CompositeEntity) { 088 OpenCompositeAction oca = new OpenCompositeAction(frame); 089 oca.setLsidToOpen(lsid); 090 oca.setNamedObjToOpen((NamedObj) obj); 091 this.add(new JMenuItem(oca)); 092 093 if(frame instanceof TabbedKeplerGraphFrame) { 094 TabbedLookInsideAction action = new TabbedLookInsideAction(frame); 095 action.setTarget((NamedObj) obj); 096 add(new JMenuItem(action)); 097 } 098 099 } 100 101 // View Documentation 102 // do not show documentation for attributes, ports, relations, etc. 103 if (obj instanceof ComponentEntity) { 104 ShowDocumentationAction sda = new ShowDocumentationAction( 105 getSelectionPath(), frame); 106 sda.setPtolemyFrame(frame); 107 this.add(new JMenuItem(sda)); 108 } 109 110 // Show On Canvas centers the canvas on the target 111 // do not show for relations 112 if(!(obj instanceof Relation)) { 113 AbstractAction action = new AbstractAction("Show On Canvas") { 114 @Override 115 public void actionPerformed(ActionEvent arg0) { 116 BasicGraphFrame.openComposite(frame, (NamedObj) obj); 117 } 118 }; 119 add(new JMenuItem(action)); 120 } 121 } 122}