001/* 002 * Copyright (c) 2004-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 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.ecoinformatics.seek.ecogrid; 031 032import java.util.Vector; 033 034import javax.swing.table.AbstractTableModel; 035 036import org.apache.commons.logging.Log; 037import org.apache.commons.logging.LogFactory; 038 039/** 040 * This class will represent a table model for displaying service list 041 * 042 * @author Jing Tao 043 * 044 */ 045 046public class ServicesDisplayTableModel extends AbstractTableModel { 047 private Vector selectedServicesList = null; 048 private String[] headerLabel = null; 049 private Vector rowHeightFactor = new Vector(); 050 051 private static final int DEFAUTFACTOR = 1; 052 053 protected final static Log log; 054 static { 055 log = LogFactory 056 .getLog("org.ecoinformatics.seek.ecogrid.ServicesDisplayTableModel"); 057 } 058 059 /** 060 * Constructor for the table model 061 * 062 * @param selectedServiceList 063 * Vector real data 064 * @param headerLabel 065 * String[] label will be shown in header 066 */ 067 public ServicesDisplayTableModel(Vector selectedServiceList, 068 String[] headerLabel) { 069 this.selectedServicesList = selectedServiceList; 070 this.headerLabel = headerLabel; 071 generateRowHeightFactor(); 072 }// ServiceDisplayTableModel 073 074 /* 075 * Method to get height factor for a row(the number of doctype in one serive 076 */ 077 private void generateRowHeightFactor() { 078 if (selectedServicesList != null) { 079 int size = selectedServicesList.size(); 080 for (int i = 0; i < size; i++) { 081 SelectableEcoGridService service = (SelectableEcoGridService) selectedServicesList 082 .elementAt(i); 083 SelectableDocumentType[] typeList = service 084 .getSelectableDocumentTypeList(); 085 if (typeList != null && typeList.length > 0) { 086 rowHeightFactor.add(i, new Integer(typeList.length)); 087 } else { 088 rowHeightFactor.add(i, new Integer(DEFAUTFACTOR)); 089 } 090 }// for 091 }// if 092 }// generateRowHeightFactor 093 094 /** 095 * Method to get selected service list 096 * 097 * @return Vector 098 */ 099 public Vector getSelectedServicesList() { 100 return this.selectedServicesList; 101 } 102 103 /** 104 * Method to get row height factor 105 * 106 * @return Vector 107 */ 108 public Vector getRowHeightFactor() { 109 return rowHeightFactor; 110 } 111 112 /** 113 * Get the number of row 114 * 115 * @return int 116 */ 117 public int getRowCount() { 118 if (selectedServicesList != null) { 119 return selectedServicesList.size(); 120 } else { 121 return 0; 122 } 123 }// getRowCount 124 125 /** 126 * Get the number of column 127 * 128 * @return int 129 */ 130 public int getColumnCount() { 131 if (headerLabel != null) { 132 return headerLabel.length; 133 } else { 134 return 0; 135 } 136 }// getColumnCount 137 138 /** 139 * Get the header for given column number 140 * 141 * @param column 142 * int 143 * @return String 144 */ 145 public String getColumnName(int column) { 146 if (headerLabel != null) { 147 return headerLabel[column]; 148 } else { 149 return null; 150 } 151 }// getCoumnName 152 153 /** 154 * Method to get value 155 * 156 * @param rowIndex 157 * int 158 * @param columnIndex 159 * int 160 * @return Object 161 */ 162 public Object getValueAt(int rowIndex, int columnIndex) { 163 Object value = null; 164 try { 165 SelectableEcoGridService service = (SelectableEcoGridService) selectedServicesList 166 .elementAt(rowIndex); 167 String columnName = headerLabel[columnIndex]; 168 if (columnName != null) { 169 if (columnName.equals(ServicesDisplayPanel.SERVICENAMECOL)) { 170 value = service.getSelectableServiceName(); 171 } else if (columnName.equals(ServicesDisplayPanel.LOCATIONCOL)) { 172 value = service.getEndPoint(); 173 } else if (columnName 174 .equals(ServicesDisplayPanel.DOCUMENTTYPECOL)) { 175 value = service.getSelectableDocumentTypeList(); 176 } 177 }// if 178 }// try 179 catch (ArrayIndexOutOfBoundsException aioobe) { 180 value = null; 181 } catch (NullPointerException npe) { 182 value = null; 183 } catch (Exception e) { 184 value = null; 185 } 186 187 return value; 188 189 }// getValueAt 190 191 /** 192 * Return the Class for each column so that they can be rendered correctly. 193 */ 194 public Class getColumnClass(int c) { 195 Class currentClass = null; 196 try { 197 currentClass = this.getValueAt(0, c).getClass(); 198 } catch (NullPointerException npe) { 199 try { 200 currentClass = Class.forName("java.lang.String"); 201 } catch (ClassNotFoundException cnfe) { 202 log.debug("Error in getColumnClass ", cnfe); 203 } 204 } 205 return currentClass; 206 }// getColumnClass 207 208 /** 209 * Method for table editable 210 * 211 * @param row 212 * int 213 * @param column 214 * int 215 * @return boolean 216 */ 217 public boolean isCellEditable(int row, int column) { 218 return true; 219 } 220}// ServiceDisplayTableModel