001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2007 Dennis Reil
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.izforge.izpack.installer;
023:
024: import java.util.Arrays;
025: import java.util.Map;
026:
027: import javax.swing.table.AbstractTableModel;
028:
029: /**
030: * @author Dennis Reil, <Dennis.Reil@reddot.de>
031: * @version $Id: $
032: */
033: public class ConditionHistoryTableModel extends AbstractTableModel {
034: private static final long serialVersionUID = 5966543100431588652L;
035:
036: public static final String[] columnheader = { "Id", "Value" };
037: private Map<String, ConditionHistory> conditionvalues;
038:
039: public ConditionHistoryTableModel(
040: Map<String, ConditionHistory> values) {
041: this .conditionvalues = values;
042: }
043:
044: /* (non-Javadoc)
045: * @see javax.swing.table.TableModel#getColumnCount()
046: */
047: public int getColumnCount() {
048: return columnheader.length;
049: }
050:
051: /* (non-Javadoc)
052: * @see javax.swing.table.TableModel#getRowCount()
053: */
054: public int getRowCount() {
055: return this .conditionvalues == null ? 0 : this .conditionvalues
056: .keySet().size();
057: }
058:
059: /* (non-Javadoc)
060: * @see javax.swing.table.TableModel#getValueAt(int, int)
061: */
062: public Object getValueAt(int rowIndex, int columnIndex) {
063: switch (columnIndex) {
064: case 0:
065: String[] keys = (String[]) this .conditionvalues.keySet()
066: .toArray(
067: new String[this .conditionvalues.keySet()
068: .size()]);
069: Arrays.sort(keys);
070: return keys[rowIndex];
071:
072: case 1:
073: String conditionid = (String) getValueAt(rowIndex, 0);
074: ConditionHistory ch = conditionvalues.get(conditionid);
075: return ch;
076: }
077: return null;
078: }
079:
080: /* (non-Javadoc)
081: * @see javax.swing.table.AbstractTableModel#getColumnName(int)
082: */
083: public String getColumnName(int column) {
084: return columnheader[column];
085: }
086:
087: /* (non-Javadoc)
088: * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
089: */
090: public boolean isCellEditable(int rowIndex, int columnIndex) {
091: return false;
092: }
093:
094: /* (non-Javadoc)
095: * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
096: */
097: public Class getColumnClass(int columnIndex) {
098: if (columnIndex == 1) {
099: return ConditionHistory.class;
100: } else {
101: return String.class;
102: }
103: }
104: }
|