- Hlavní stránka
- Balíky
- Třídy
- Soubory

# src/cz/neubauer/tomas/hazardanalysis/model/tablemodels/ComponentTableModel.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.model.tablemodels;
    00005
    00006 import java.util.ArrayList;
    00007
    00008 import javax.swing.table.AbstractTableModel;
    00009
    00010 import cz.neubauer.tomas.hazardanalysis.model.components.Component;
    00011 import cz.neubauer.tomas.hazardanalysis.viewcontroller.administration.AdminFrame;
    00012
    00016 public class ComponentTableModel extends AbstractTableModel {
    00017
    00021         private static final long serialVersionUID = -4881938620896518947L;
    00022
    00023         private ArrayList<Component> data;
    00024
    00025         private AdminFrame owner;
    00026
    00027         private String[] columnNames = new String[] { "Název komponenty",
    00028                         "Umístění komponenty" };
    00029
    00030         public ComponentTableModel(AdminFrame owner, ArrayList<Component> data) {
    00031                 this.owner = owner;
    00032                 this.data = data;
    00033         }
    00034
    00035         /*
    00036          * (non-Javadoc)
    00037          *
    00038          * @see javax.swing.table.TableModel#getColumnCount()
    00039          */
    00040         @Override
    00041         public int getColumnCount() {
    00042                 return 2;
    00043         }
    00044
    00045         /*
    00046          * (non-Javadoc)
    00047          *
    00048          * @see javax.swing.table.TableModel#getRowCount()
    00049          */
    00050         @Override
    00051         public int getRowCount() {
    00052                 return data.size();
    00053         }
    00054
    00055         /*
    00056          * (non-Javadoc)
    00057          *
    00058          * @see javax.swing.table.TableModel#getValueAt(int, int)
    00059          */
    00060         @Override
    00061         public Object getValueAt(int rowIndex, int columnIndex) {
    00062                 Component currentComponent = data.get(rowIndex);
    00063                 switch (columnIndex) {
    00064                 case 0:
    00065                         return currentComponent.getName();
    00066                 case 1:
    00067                         return currentComponent.getLocation();
    00068                 default:
    00069                         return null;
    00070                 }
    00071         }
    00072
    00073         /*
    00074          * (non-Javadoc)
    00075          *
    00076          * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object,
    00077          *      int, int)
    00078          */
    00079         @Override
    00080         public void setValueAt(Object value, int rowIndex, int columnIndex) {
    00081                 Component currentComponent = data.get(rowIndex);
    00082                 switch (columnIndex) {
    00083                 case 0:
    00084                         currentComponent.setName((String) value);
    00085                         currentComponent.saveToDB(owner.getConnection());
    00086                         fireTableDataChanged();
    00087                         break;
    00088                 case 1:
    00089                         currentComponent.setLocation((String) value);
    00090                         currentComponent.saveToDB(owner.getConnection());
    00091                         fireTableDataChanged();
    00092                         break;
    00093                 default:
    00094                 }
    00095         }
    00096
    00097         /*
    00098          * (non-Javadoc)
    00099          *
    00100          * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
    00101          */
    00102         @Override
    00103         public boolean isCellEditable(int rowIndex, int columnIndex) {
    00104                 return columnIndex == 0 || columnIndex == 1;
    00105         }
    00106
    00107         /*
    00108          * (non-Javadoc)
    00109          *
    00110          * @see javax.swing.table.AbstractTableModel#getColumnName(int)
    00111          */
    00112         @Override
    00113         public String getColumnName(int column) {
    00114                 return columnNames[column];
    00115         }
    00116
    00117         public ArrayList<Component> getData() {
    00118                 return data;
    00119         }
    00120
    00121         public void setData(ArrayList<Component> data) {
    00122                 this.data = data;
    00123         }
    00124
    00125 }