001/* 002 * Copyright (c) 2003-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-08-24 22:45:41 +0000 (Mon, 24 Aug 2015) $' 007 * '$Revision: 33631 $' 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.objectmanager.data; 031 032import java.awt.event.ActionEvent; 033import java.net.URL; 034 035import org.kepler.dataproxy.datasource.DataSourceInterface; 036 037import diva.graph.GraphController; 038import ptolemy.actor.gui.BrowserEffigy; 039import ptolemy.kernel.util.NamedObj; 040import ptolemy.util.MessageHandler; 041import ptolemy.vergil.actor.ActorInstanceController; 042import ptolemy.vergil.toolbox.FigureAction; 043import ptolemy.vergil.toolbox.MenuActionFactory; 044 045////////////////////////////////////////////////////////////////////////// 046//// DataSourceInstanceController 047/** 048 * This class provides a controller that overrides the default GetDocumentation 049 * actions for data sources and can transform data source documentation to HTML 050 * format before displaying it. 051 * <p> 052 * NOTE: There should be only one instance of this class associated with a given 053 * GraphController. This is because this controller listens for changes to the 054 * graph and re-renders the ports of any actor instance in the graph when the 055 * graph changes. If there is more than one instance, this rendering will be 056 * done twice, which can result in bugs like port labels appearing twice. 057 * 058 * @author Matthew Jones 059 * @version $Id: DataSourceInstanceController.java,v 1.1 2004/10/25 23:31:46 060 * jones Exp $ 061 * @since Ptolemy II 4.0 062 * @Pt.ProposedRating Red (mbj) 063 * @Pt.AcceptedRating Red (mbj) 064 */ 065public class DataSourceInstanceController extends ActorInstanceController { 066 067 /** 068 * Create an actor instance controller associated with the specified graph 069 * controller with full access. 070 * 071 * @param controller 072 * The associated graph controller. 073 */ 074 public DataSourceInstanceController(GraphController controller) { 075 this(controller, FULL); 076 } 077 078 /** 079 * Create an entity controller associated with the specified graph 080 * controller with the specified access. 081 * 082 * @param controller 083 * The associated graph controller. 084 */ 085 public DataSourceInstanceController(GraphController controller, 086 Access access) { 087 super(controller, access); 088 _menuFactory.addMenuItemFactory(new MenuActionFactory( 089 new GetDSDocumentationAction())); 090 } 091 092 // ///////////////////////////////////////////////////////////////// 093 // // protected variables //// 094 095 // ///////////////////////////////////////////////////////////////// 096 // // inner classes //// 097 098 /** 099 * This is an action that accesses the documentation for a Ptolemy object 100 * associated with a figure. Note that this base class does not put this 101 * action in a menu, since some derived classes will not want it. But by 102 * having it here, it is available to all derived classes. 103 */ 104 protected class GetDSDocumentationAction extends FigureAction { 105 106 public GetDSDocumentationAction() { 107 super("Get Metadata"); 108 } 109 110 public void actionPerformed(ActionEvent e) { 111 super.actionPerformed(e); 112 NamedObj target = getTarget(); 113 String className = target.getClass().getName(); 114 String docName = "doc.codeDoc." + className; 115 try { 116 URL toRead = null; 117 if (target instanceof DataSourceInterface) { 118 toRead = ((DataSourceInterface) target).getDocumentation(); 119 } else { 120 toRead = getClass().getClassLoader().getResource( 121 docName.replace('.', '/') + ".html"); 122 } 123 if (toRead != null) { 124 if (_configuration != null) { 125 boolean useBrowser = false; 126 String ref = toRead.getRef(); 127 if (ref != null) { 128 useBrowser = ref.equals("in_browser"); 129 } 130 if (useBrowser && (BrowserEffigy.staticFactory != null)) { 131 _configuration.openModel(toRead, toRead, toRead 132 .toExternalForm(), 133 BrowserEffigy.staticFactory); 134 } else { 135 _configuration.openModel(toRead, toRead, toRead 136 .toExternalForm()); 137 } 138 // HyperlinkEvent hle = new HyperlinkEvent(target, 139 // HyperlinkEvent.EventType.ACTIVATED, toRead, 140 // toRead.toExternalForm()); 141 // HTMLViewer htmlViewer = new HTMLViewer(); 142 // htmlViewer.hyperlinkUpdate(hle); 143 // _configuration.openModel(null, toRead, toRead 144 // .toExternalForm()); 145 } else { 146 MessageHandler.error("Cannot open documentation for " 147 + "data source " + className 148 + " without a configuration."); 149 } 150 } else { 151 MessageHandler.error("Cannot find documentation for " 152 + className + "\nSorry."); 153 } 154 } catch (Exception ex) { 155 MessageHandler.error("Cannot find documentation for " 156 + className + "\nSorry.", ex); 157 } 158 } 159 } 160}