/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.directory.editors.update.updaters.collaborators;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.main.DirectoryItemNotFoundException;
import cli_fmw.utils.ErrorValue;
import clips.delegate.client.ClientLocal;
import clips.delegate.directory.simple.name.DirectoryName;
import clips.delegate.directory.simple.pathron.DirectoryPathron;
import clips.delegate.directory.simple.surname.DirectorySurname;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.table.AbstractTableModel;
/**
*
* @author lacoste
*/
public class TableModelPollingCollabData extends AbstractTableModel {
public static final int COLCOUNT = 2;
public static final int COL_COLLAB = 0;
public static final int COL_CLIENT = 1;
private HashMap<ColDataKey, ArrayList<ClientLocal>> map;
private ArrayList<ColDataKey> keyList;
DirectorySurname dirSurname;
DirectoryName dirName;
DirectoryPathron dirPathron;
public TableModelPollingCollabData(ArrayList<ColDataKey> keyList, HashMap<ColDataKey, ArrayList<ClientLocal>> map) throws ClipsException {
this.map = map;
this.keyList = keyList;
dirSurname = DirectoryLocator.getDirectory(DirectorySurname.class);
dirName = DirectoryLocator.getDirectory(DirectoryName.class);
dirPathron = DirectoryLocator.getDirectory(DirectoryPathron.class);
}
@Override
public int getRowCount() {
return keyList.size();
}
@Override
public int getColumnCount() {
return COLCOUNT;
}
@Override
public String getColumnName(int column) {
switch (column) {
case COL_COLLAB : return "Сотрудник";
case COL_CLIENT: return "Пациент";
default: throw new IllegalArgumentException("Некорректный номер столбца");
}
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
ColDataKey colData = keyList.get(rowIndex);
ArrayList<ClientLocal> clientList = map.get(colData);
switch (columnIndex) {
case COL_COLLAB: {
try {
String surName = dirSurname.getItemFromID(colData.surnameID).getTitle();
String name = dirName.getItemFromID(colData.nameID).getTitle();
String pathron = dirPathron.getItemFromID(colData.pathronID).getTitle();
return surName + " " + name + " " + pathron;
} catch (DirectoryItemNotFoundException ex) {
return new ErrorValue(ex);
}
}
case COL_CLIENT: {
if (clientList.size() == 0) {
return "Не найден";
} else if (clientList.size() == 1) {
return clientList.get(0).toString();
} else {
return "Более одного";
}
}
default: throw new IllegalArgumentException("Некорректный номер столбца");
}
}
}