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 VariableHistoryTableModel extends AbstractTableModel {
034: private static final long serialVersionUID = 5966543100431588652L;
035:
036: public static final String[] columnheader = { "Name", "Value" };
037: private Map<String, VariableHistory> variablevalues;
038:
039: public VariableHistoryTableModel(Map<String, VariableHistory> values) {
040: this .variablevalues = values;
041: }
042:
043: /* (non-Javadoc)
044: * @see javax.swing.table.TableModel#getColumnCount()
045: */
046: public int getColumnCount() {
047: return columnheader.length;
048: }
049:
050: /* (non-Javadoc)
051: * @see javax.swing.table.TableModel#getRowCount()
052: */
053: public int getRowCount() {
054: return this .variablevalues == null ? 0 : this .variablevalues
055: .keySet().size();
056: }
057:
058: /* (non-Javadoc)
059: * @see javax.swing.table.TableModel#getValueAt(int, int)
060: */
061: public Object getValueAt(int rowIndex, int columnIndex) {
062: switch (columnIndex) {
063: case 0:
064: String[] keys = (String[]) this .variablevalues.keySet()
065: .toArray(
066: new String[this .variablevalues.keySet()
067: .size()]);
068: Arrays.sort(keys);
069: return keys[rowIndex];
070:
071: case 1:
072: String variablename = (String) getValueAt(rowIndex, 0);
073: VariableHistory vh = variablevalues.get(variablename);
074: return vh;
075: }
076: return null;
077: }
078:
079: /* (non-Javadoc)
080: * @see javax.swing.table.AbstractTableModel#getColumnName(int)
081: */
082: public String getColumnName(int column) {
083: return columnheader[column];
084: }
085:
086: /* (non-Javadoc)
087: * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
088: */
089: public boolean isCellEditable(int rowIndex, int columnIndex) {
090: return false;
091: /*
092: if (columnIndex == 0) {
093: return false;
094: }
095: else {
096: return true;
097: }
098: */
099: }
100:
101: /* (non-Javadoc)
102: * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
103: */
104: public Class getColumnClass(int columnIndex) {
105: if (columnIndex == 1) {
106: return VariableHistory.class;
107: } else {
108: return String.class;
109: }
110: }
111: }
|