001 /*
002 * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003 *
004 * This file is part of the Java Data Mining Package (JDMP).
005 * See the NOTICE file distributed with this work for additional
006 * information regarding copyright ownership and licensing.
007 *
008 * JDMP is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation; either version 2
011 * of the License, or (at your option) any later version.
012 *
013 * JDMP is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU Lesser General Public License for more details.
017 *
018 * You should have received a copy of the GNU Lesser General Public
019 * License along with JDMP; if not, write to the
020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021 * Boston, MA 02110-1301 USA
022 */
023
024 package org.jdmp.gui.module;
025
026 import javax.swing.event.ListDataEvent;
027 import javax.swing.event.ListDataListener;
028 import javax.swing.table.AbstractTableModel;
029
030 import org.jdmp.core.module.HasModules;
031 import org.jdmp.core.module.Module;
032
033 public class ModuleListTableModel extends AbstractTableModel implements ListDataListener {
034 private static final long serialVersionUID = -1372599464095754625L;
035
036 public static final int ICONCOLUMN = 0;
037
038 public static final int LABELCOLUMN = 1;
039
040 public static final int ALGORITHMCOUNTCOLUMN = 2;
041
042 public static final int VARIABLECOUNTCOLUMN = 3;
043
044 public static final int MODULECOUNTCOLUMN = 4;
045
046 public static final int DATASETCOUNTCOLUMN = 5;
047
048 private HasModules iModules = null;
049
050 public ModuleListTableModel(HasModules iModules) {
051 this.iModules = iModules;
052 iModules.getModules().addListDataListener(this);
053 }
054
055 public int getRowCount() {
056 return iModules.getModules().getSize();
057 }
058
059 public int getColumnCount() {
060 return 6;
061 }
062
063 @Override
064 public String getColumnName(int columnIndex) {
065 switch (columnIndex) {
066 case ICONCOLUMN:
067 return "";
068 case LABELCOLUMN:
069 return "Label";
070 case VARIABLECOUNTCOLUMN:
071 return "VariableCount";
072 case MODULECOUNTCOLUMN:
073 return "ModuleCount";
074 case DATASETCOUNTCOLUMN:
075 return "DataSetCount";
076 case ALGORITHMCOUNTCOLUMN:
077 return "AlgorithmCount";
078 default:
079 return "unknown";
080
081 }
082 }
083
084 @Override
085 public Class<?> getColumnClass(int columnIndex) {
086 return Module.class;
087 }
088
089 public Object getValueAt(int rowIndex, int columnIndex) {
090 return iModules.getModules().getElementAt(rowIndex);
091 }
092
093 @Override
094 public void contentsChanged(ListDataEvent e) {
095 fireTableRowsUpdated(e.getIndex0(), e.getIndex1());
096 }
097
098 @Override
099 public void intervalAdded(ListDataEvent e) {
100 fireTableRowsInserted(e.getIndex0(), e.getIndex1());
101 }
102
103 @Override
104 public void intervalRemoved(ListDataEvent e) {
105 fireTableRowsDeleted(e.getIndex0(), e.getIndex1());
106 }
107
108 }