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.objectmanager.cache.browser; 031 032import java.awt.event.ActionEvent; 033import java.awt.event.ActionListener; 034import java.util.Vector; 035 036import javax.swing.BoxLayout; 037import javax.swing.JButton; 038import javax.swing.JPanel; 039import javax.swing.JScrollPane; 040import javax.swing.JTable; 041import javax.swing.table.DefaultTableModel; 042 043import org.kepler.gui.TabPane; 044import org.kepler.gui.TabPaneFactory; 045import org.kepler.objectmanager.cache.CacheManager; 046 047import ptolemy.actor.gui.TableauFrame; 048import ptolemy.kernel.util.IllegalActionException; 049import ptolemy.kernel.util.NameDuplicationException; 050import ptolemy.kernel.util.NamedObj; 051 052public class CacheViewerTabPane extends JPanel implements TabPane { 053 054 TableauFrame _frame; 055 String _tabName; 056 057 JButton _refreshButton; 058 JTable _cacheList; 059 060 public CacheViewerTabPane () {} 061 062 /* (non-Javadoc) 063 * @see org.kepler.gui.TabPane#getParentFrame() 064 */ 065 public TableauFrame getParentFrame() { 066 return _frame; 067 } 068 069 /* (non-Javadoc) 070 * @see org.kepler.gui.TabPane#setParentFrame(ptolemy.actor.gui.TableauFrame) 071 */ 072 public void setParentFrame(TableauFrame parent) { 073 _frame = parent; 074 } 075 076 /* (non-Javadoc) 077 * @see org.kepler.gui.TabPane#getTabName() 078 */ 079 public String getTabName() { 080 return _tabName; 081 } 082 083 public void setTabName(String name) { 084 _tabName = name; 085 } 086 087 /* (non-Javadoc) 088 * @see org.kepler.gui.TabPane#initializeTab() 089 */ 090 public void initializeTab() throws Exception { 091 setLayout( new BoxLayout(this, BoxLayout.Y_AXIS) ); 092 _refreshButton = new JButton("Refresh"); 093 _refreshButton.addActionListener(new RefreshButtonActionListener()); 094 add( _refreshButton ); 095 096 initCacheListTable(); 097 } 098 099 private void initCacheListTable() { 100 Vector<String> columnNames = new Vector<String>(); 101 columnNames.addElement("Name"); 102 columnNames.addElement("LSID"); 103 columnNames.addElement("Cache File"); 104 Vector<Vector<String>> data = new Vector<Vector<String>>(); 105 _cacheList = new JTable( new DefaultTableModel(data,columnNames) ); 106 JScrollPane cacheListSP = new JScrollPane(_cacheList); 107 add( cacheListSP ); 108 } 109 110 private class RefreshButtonActionListener implements ActionListener { 111 public void actionPerformed(ActionEvent ae) { 112 // System.out.println("Refresh"); 113 _cacheList.setModel(buildCacheList()); 114 } 115 } 116 117 private DefaultTableModel buildCacheList() { 118 Vector<String> columnNames = new Vector<String>(); 119 columnNames.addElement("Name"); 120 columnNames.addElement("LSID"); 121 columnNames.addElement("Cache File"); 122 Vector<Vector<String>> data = new Vector<Vector<String>>(); 123 try { 124 CacheManager cm = CacheManager.getInstance(); 125 cm.showDB(); 126 //data = cm.selectAllFiles(); 127 } catch (Exception e) { 128 System.out.println(e.toString()); 129 } 130 return new DefaultTableModel( data, columnNames ); 131 } 132 133 /** 134 * Query the database for all names, lsids and files. 135 * @return Vector<Vector<String>> 136 * A Vector containing three Vectors, names lsids files 137 * 138 public Vector<Vector<String>> selectAllFiles() { 139 Vector<Vector<String>> data = new Vector<Vector<String>>(); 140 int row = 0; 141 data.addElement( new Vector<String>(3) ); 142 data.elementAt(row).addElement("testname"); 143 data.elementAt(row).addElement("testlsid"); 144 data.elementAt(row).addElement("testfile"); 145 row++; 146 try { 147 ResultSet rs = selectAll.executeQuery(); 148 while (rs.next()) { 149 data.addElement( new Vector<String>(3) ); 150 data.elementAt(row).addElement( rs.getString("name") ); 151 data.elementAt(row).addElement( rs.getString("lsid") ); 152 data.elementAt(row).addElement( rs.getString("file") ); 153 row++; 154 } 155 } catch (Exception e) { 156 System.out.println(e.toString()); 157 } 158 return data; 159 } */ 160 161 /** 162 * A factory that creates the library panel for the editors. 163 * 164 *@author Aaron Schultz 165 */ 166 public static class Factory extends TabPaneFactory { 167 /** 168 * Create a factory with the given name and container. 169 * 170 *@param container 171 * The container. 172 *@param name 173 * The name of the entity. 174 *@exception IllegalActionException 175 * If the container is incompatible with this attribute. 176 *@exception NameDuplicationException 177 * If the name coincides with an attribute already in the 178 * container. 179 */ 180 public Factory(NamedObj container, String name) 181 throws IllegalActionException, NameDuplicationException { 182 super(container, name); 183 } 184 185 /** 186 * Create a library pane that displays the given library of actors. 187 * 188 * @return A new LibraryPaneTab that displays the library 189 */ 190 public TabPane createTabPane(TableauFrame parent) { 191 CacheViewerTabPane cv = new CacheViewerTabPane(); 192 cv.setTabName( this.getName() ); 193 return cv; 194 } 195 } 196 197 198 199}