/* * Copyright 2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.mlhc.imaging.client; import java.util.Arrays; import java.util.Iterator; import java.util.List; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.widgetideas.table.client.ClientTableModel; import com.google.gwt.widgetideas.table.client.TableModel; import com.mlhc.imaging.client.component.ExpertStoredImage; /** * A class to retrieve row data to be used in a table. */ public class ESITableModel extends ClientTableModel { /** * The row data. */ private List esiEntries; /** * * Constructor. * * @param rows * the data that this model feeds from */ public ESITableModel(List esiEntries) { this.esiEntries = esiEntries; } /** * @see ClientTableModel */ public Object getCell(int rowNum, int cellNum) { GWT.log("table model received request for " + "rowNum=" + rowNum + " cellNum=" + cellNum, null); // Get the row List ExpertStoredImage esi = getESI(rowNum); if (esi == null) { GWT.log("omg found null esi!", null); return null; } if (cellNum >= 5) { return null; } if (cellNum == 0) { // return esi.getSelected().toString(); return "test"; } else if (cellNum == 1) { // String[] sa = esi.getType().split("\\\\n"); // String stuff = ""; // for (Iterator i = Arrays.asList(sa).iterator(); i.hasNext();) { // stuff = stuff + "
" + i.next() + "
"; // } // return new HTML(stuff); return "test"; } else if (cellNum == 2) { return esi.getRemarks(); } else if (cellNum == 3) { return esi.getDateTime(); } else if (cellNum == 4) { return esi.getViewURL(); } else if (cellNum == 5) { return esi.getWebView().toString(); } else { return null; } } /** * @see TableModel */ public void onRowInserted(int beforeRow) { if (beforeRow <= esiEntries.size()) { // Insert new row esiEntries.add(beforeRow, null); } else { // Expand to fit row for (int i = esiEntries.size(); i <= beforeRow; i++) { esiEntries.add(null); } } } /** * @see TableModel */ public void onRowRemoved(int row) { if (row < esiEntries.size()) { esiEntries.remove(row); } } /** * @see TableModel */ public void onSetData(int row, int cell, Object data) { // Get the row list ExpertStoredImage esi = getESI(row); if (esi == null) { // Expand to fit row for (int i = esiEntries.size(); i <= row; i++) { esiEntries.add(null); } // Create the rowList esi = new ExpertStoredImage(); esiEntries.set(row, esi); } // // Enlarge the row as needed // for (int i = 6; i <= cell; i++) { // rowList.add(null); // } if (cell == 0) { String bool = (String) data; if ((bool.equals("true"))) { esi.setSelected(new Boolean(true)); } else { esi.setSelected(new Boolean(false)); } } else if (cell == 1) { esi.setType((String) data); } else if (cell == 2) { esi.setRemarks((String) data); } else if (cell == 3) { esi.setDateTime((String) data); } else if (cell == 4) { esi.setViewURL((String) data); } else if (cell == 5) { String bool = (String) data; if ((bool.equals("true"))) { esi.setWebView(new Boolean(true)); } else { esi.setWebView(new Boolean(false)); } } } /** * Get the list for a given row. * * @param rowIndex * the row index */ private ExpertStoredImage getESI(int rowIndex) { if (rowIndex >= esiEntries.size()) { return null; } ExpertStoredImage esi = (ExpertStoredImage) esiEntries.get(rowIndex); // GWT.log("path: " + esi.getPath(), null); return esi; } }