use of dna.dataStructures.Document in project dna by leifeld.
the class SqlConnection method getAllDocuments.
/*
class DocumentLoader implements Runnable {
ProgressMonitor progressMonitor;
ArrayList<Document> al;
public ArrayList<Document> DocumentLoader() {
al = new ArrayList<Document>();
run();
return al;
}
public void run() {
int count = 0;
try {
count = (int) executeQueryForObject("SELECT COUNT(*) FROM DOCUMENTS");
} catch (SQLException e1) {
e1.printStackTrace();
}
progressMonitor = new ProgressMonitor(Dna.dna.gui, "Importing documents and statements...", "", 0, count);
progressMonitor.setMillisToDecideToPopup(1);
try {
String myQuery = "SELECT * FROM DOCUMENTS";
PreparedStatement preStatement = (PreparedStatement) connection.prepareStatement(myQuery);
ResultSet result = preStatement.executeQuery();
int i = 0;
if (result.next()) {
do {
i++;
progressMonitor.setProgress(i);
if (progressMonitor.isCanceled()) {
break;
}
int id = result.getInt("ID");
long d = result.getLong("Date");
Date date = new Date(d);
Document document = new Document(
id,
result.getString("Title"),
result.getString("Text"),
result.getInt("Coder"),
result.getString("Author"),
result.getString("Source"),
result.getString("Section"),
result.getString("Notes"),
result.getString("Type"),
date
);
al.add(document);
} while (result.next());
}
result.close();
preStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}
Collections.sort(al);
}
}
*/
/**
* @return Array list of all documents in the SQL database.
*/
private ArrayList<Document> getAllDocuments() {
ArrayList<Document> al = new ArrayList<Document>();
try {
String myQuery = "SELECT * FROM DOCUMENTS";
PreparedStatement preStatement = (PreparedStatement) connection.prepareStatement(myQuery);
ResultSet result = preStatement.executeQuery();
if (result.next()) {
do {
int id = result.getInt("ID");
long d = result.getLong("Date");
Date date = new Date(d);
Document document = new Document(id, result.getString("Title"), result.getString("Text"), result.getInt("Coder"), result.getString("Author"), result.getString("Source"), result.getString("Section"), result.getString("Notes"), result.getString("Type"), date);
al.add(document);
} while (result.next());
}
result.close();
preStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}
Collections.sort(al);
return al;
}
use of dna.dataStructures.Document in project dna by leifeld.
the class DocumentTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
Document document = Dna.data.getDocuments().get(rowIndex);
switch(columnIndex) {
case 0:
document.setId((Integer) aValue);
break;
case 1:
document.setTitle((String) aValue);
break;
case 3:
document.setDate((Date) aValue);
break;
case 4:
document.setDate((Date) aValue);
break;
case 5:
document.setCoder(((Coder) aValue).getId());
break;
case 6:
document.setAuthor((String) aValue);
break;
case 7:
document.setSource((String) aValue);
break;
case 8:
document.setSection((String) aValue);
break;
case 9:
document.setType((String) aValue);
break;
case 10:
document.setNotes((String) aValue);
break;
}
TableModelEvent e = new TableModelEvent(this);
for (int i = 0, n = listeners.size(); i < n; i++) {
((TableModelListener) listeners.get(i)).tableChanged(e);
}
}
use of dna.dataStructures.Document in project dna by leifeld.
the class DocumentTableModel method getValueAt.
// get the value of a cell (rowIndex, columnIndex)
public Object getValueAt(int rowIndex, int columnIndex) {
Document document = Dna.data.getDocuments().get(rowIndex);
SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
switch(columnIndex) {
case 0:
return document.getId();
case 1:
return document.getTitle();
case 2:
return Dna.data.countStatementsPerDocument(document.getId());
case 3:
return document.getDate();
case 4:
return time.format(document.getDate());
case 5:
return Dna.data.getCoderById(document.getCoder());
case 6:
return document.getAuthor();
case 7:
return document.getSource();
case 8:
return document.getSection();
case 9:
return document.getType();
case 10:
return document.getNotes();
default:
return null;
}
}
Aggregations