1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright (c) 1999-2001 by Sun Microsystems, Inc. 26 * All rights reserved. 27 */ 28 package com.sun.dhcpmgr.client; 29 30 import javax.swing.table.AbstractTableModel; 31 import java.util.Vector; 32 import java.util.Date; 33 34 import com.sun.dhcpmgr.ui.AutosizingTable; 35 import com.sun.dhcpmgr.ui.ExtendedCellRenderer; 36 import com.sun.dhcpmgr.data.IPAddress; 37 import com.sun.dhcpmgr.data.ActionError; 38 39 /* 40 * The model for the error table. 41 */ 42 class ErrorTableModel extends AbstractTableModel { 43 private String column0Label; 44 private Class column0Class; 45 private Vector rows; 46 47 public ErrorTableModel(String column0Label, Class column0Class) { 48 this.column0Label = column0Label; 49 this.column0Class = column0Class; 50 rows = new Vector(); 51 } 52 53 public int getRowCount() { 54 return rows.size(); 55 } 56 57 public int getColumnCount() { 58 return 2; 59 } 60 61 public Object getValueAt(int row, int column) { 62 Object [] ro = (Object [])rows.elementAt(row); 63 return ro[column]; 64 } 65 66 public Class getColumnClass(int column) { 67 if (column == 0) { 68 return column0Class; 69 } else { 70 return String.class; 71 } 72 } 73 74 public String getColumnName(int column) { 75 if (column == 0) { 76 return column0Label; 77 } else { 78 return ResourceStrings.getString("error_message"); 79 } 80 } 81 82 public void addError(Object o, String msg) { 83 Object [] row = new Object[] { o, msg }; 84 rows.addElement(row); 85 } 86 } 87 88 /** 89 * A table for displaying errors which occurred while acting on multiple 90 * objects. 91 */ 92 public class ErrorTable extends AutosizingTable { 93 ErrorTableModel model; 94 95 public ErrorTable(String column0Label, Class column0Class) { 96 super(); 97 model = new ErrorTableModel(column0Label, column0Class); 98 setModel(model); 99 ExtendedCellRenderer renderer = new ExtendedCellRenderer(); 100 setDefaultRenderer(Date.class, renderer); 101 setDefaultRenderer(IPAddress.class, renderer); 102 } 103 104 public ErrorTable(String column0Label) { 105 this(column0Label, String.class); 106 } 107 108 public void addError(Object o, String msg) { 109 model.addError(o, msg); 110 } 111 112 public void setErrors(ActionError [] errs) { 113 for (int i = 0; i < errs.length; ++i) { 114 model.addError(errs[i].getName(), 115 errs[i].getException().getMessage()); 116 } 117 } 118 119 public boolean isEmpty() { 120 return (model.getRowCount() == 0); 121 } 122 }