import java.util.Comparator;
import java.util.List;
public class DatasetEditorModelHeader extends BasicDataModelHeader implements DataModelHeader {
public DatasetEditorModelHeader(DatasetEditor datasetEditor, ResultSet resultSet) throws SQLException {
DBDataset dataset = datasetEditor.getDataset();
if (dataset != null) {
if (resultSet == null) {
DatasetColumnSetup columnSetup = datasetEditor.getState().getColumnSetup();
List<DatasetColumnState> columnStates = columnSetup.getColumnStates();
if (columnStates.size() != dataset.getColumns().size()) {
columnSetup.init(dataset);
}
int index = 0;
for (DatasetColumnState columnState : columnStates) {
DBColumn column = dataset.getColumn(columnState.getName());
ColumnInfo columnInfo = new DatasetEditorColumnInfo(column, index, column.getPosition());
addColumnInfo(columnInfo);
index++;
}
} else {
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
for (int i = 0; i < columnCount; i++) {
String name = metaData.getColumnName(i+1);
DBColumn column = dataset.getColumn(name);
ColumnInfo columnInfo = new DatasetEditorColumnInfo(column, i, i+1);
addColumnInfo(columnInfo);
}
}