001/* 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: barseghian $' 006 * '$Date: 2010-11-10 01:36:37 +0000 (Wed, 10 Nov 2010) $' 007 * '$Revision: 26278 $' 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 030 031 032/* The TOC is being used in the 033 * current version of the ReportViewer. 034 * 035 * ItemsOfInterestPanel implements TabPane, and is instantiated through the 036 * Kepler configuration.xml file. 037 * 038 * When the user employs the context menu in the Kepler Canvas Pane 039 * to 'add to report items list' the ports and parameters that they select 040 * are added to an ArrayList that is maintained by the 041 * ReportItemManager class in org.kepler.reporting.roml 042 * 043 * The ItemsOfInterestPanel gets a tree model from the ReportItemManager like this: 044 * TreeModel model = ReportItemManager.getInstance().getReportItems(_workflowId); 045 * and then feeds that model over to PTree (a Ptolemy class for creating JTrees 046 * from NamedObj's. PTree has some drag and drop support as well. 047 * TODO A new class needs to be created (that extends PTree), 048 * that is specific to the Reporting suite, rather than over-riding the 049 * Ptolemy class, as is now the case. 050 * 051 * @author leinfelder 052 */ 053 054 055 056package org.kepler.reporting.gui; 057 058import java.awt.GridLayout; 059 060import javax.swing.JList; 061import javax.swing.JPanel; 062import javax.swing.JScrollPane; 063import javax.swing.ListModel; 064 065import org.kepler.gui.TabPane; 066import org.kepler.gui.TabPaneFactory; 067import org.kepler.gui.state.ReportingStateChangeEvent; 068import org.kepler.gui.state.StateChangeEvent; 069import org.kepler.gui.state.StateChangeListener; 070import org.kepler.gui.state.StateChangeMonitor; 071import org.kepler.moml.NamedObjId; 072import org.kepler.objectmanager.lsid.KeplerLSID; 073import org.kepler.workflow.WorkflowManager; 074 075import ptolemy.actor.gui.PtolemyFrame; 076import ptolemy.actor.gui.TableauFrame; 077import ptolemy.kernel.util.IllegalActionException; 078import ptolemy.kernel.util.NameDuplicationException; 079import ptolemy.kernel.util.NamedObj; 080 081public class ReportViewerTOC extends JPanel implements TabPane, StateChangeListener { 082 083 private TableauFrame _frame; 084 private String _title; 085 private String _workflowId; 086 private ListModel items; 087 protected final static int PANEL_INSETS = 2; 088 089 public ReportViewerTOC(String title, String workflowId) { 090 super(new GridLayout(1, 1)); 091 _title = title; 092 _workflowId = workflowId; 093 } 094 095 /** 096 * Implementation of TabPane getName() 097 */ 098 public String getTabName() { 099 return _title; 100 } 101 102 /** 103 * Implementation of TabPane setParentFrame(TableauFrame) 104 */ 105 public void setParentFrame(TableauFrame parent) { 106 _frame = parent; 107 } 108 109 /** 110 * Implementation of getParentFrame getName() 111 */ 112 public TableauFrame getParentFrame() { 113 return _frame; 114 } 115 116 public void initializeTab() throws Exception { 117 StateChangeMonitor.getInstance().addStateChangeListener( 118 ReportingStateChangeEvent.REPORT_INSTANCE_CHANGED, 119 this); 120 121 //default is just what we have on open 122 NamedObj reference = ((PtolemyFrame)_frame).getModel(); 123 KeplerLSID lsid = NamedObjId.getIdFor(reference); 124 125 //model from the reportLayout 126 //TODO: figure out how to do this without swing in the data model 127 items = WorkflowManager.getInstance().getWorkflow(_frame, lsid).getReportLayout(_frame).getAllItemsAsListModel(); 128 129 renderTab(); 130 } 131 132 public void renderTab() throws Exception { 133 134 JList list = new JList(items); 135 JScrollPane scroll = new JScrollPane(list); 136 137 // add list to the panel 138 this.removeAll(); 139 this.add(scroll); 140 this.validate(); 141 142 } 143 144 public void handleStateChange(StateChangeEvent event) { 145 try { 146 NamedObj reference = ((PtolemyFrame)_frame).getModel(); 147 148 if (event instanceof ReportingStateChangeEvent) { 149 if (event.getChangedState().equals(ReportingStateChangeEvent.REPORT_INSTANCE_CHANGED)) { 150 if (event.getReference().equals(reference)) { 151 152 items = ((ReportingStateChangeEvent) event).getReportInstance().getAllItemsAsListModel(); 153 renderTab(); 154 } 155 } 156 } 157 } 158 catch (Exception e) { 159 e.printStackTrace(); 160 } 161 } 162 163 /** 164 * A factory that creates the library panel for the editors. 165 * 166 *@author aaron 167 */ 168 public static class Factory extends TabPaneFactory { 169 /** 170 * Create a factory with the given name and container. 171 * 172 *@param container 173 * The container. 174 *@param name 175 * The name of the entity. 176 *@exception IllegalActionException 177 * If the container is incompatible with this attribute. 178 *@exception NameDuplicationException 179 * If the name coincides with an attribute already in the 180 * container. 181 */ 182 public Factory(NamedObj container, String name) 183 throws IllegalActionException, NameDuplicationException { 184 super(container, name); 185 } 186 187 /** 188 * Create a library pane that displays the given library of actors. 189 * 190 * @return A new LibraryPaneTab that displays the library 191 */ 192 public TabPane createTabPane(TableauFrame parent) { 193 ReportViewerTOC ioip = new ReportViewerTOC(this.getName(), ((PtolemyFrame)parent).getModel().getName()); 194 return ioip; 195 } 196 } 197 198} 199