Search in sources :

Example 6 with Document

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Document(dna.dataStructures.Document) Date(java.util.Date)

Example 7 with Document

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);
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener) Document(dna.dataStructures.Document)

Example 8 with Document

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;
    }
}
Also used : Document(dna.dataStructures.Document) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Document (dna.dataStructures.Document)8 SimpleDateFormat (java.text.SimpleDateFormat)4 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 Date (java.util.Date)3 File (java.io.File)2 DateFormat (java.text.DateFormat)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Attribute (org.jdom.Attribute)2 Element (org.jdom.Element)2 Format (org.jdom.output.Format)2 XMLOutputter (org.jdom.output.XMLOutputter)2 DocumentTableModel (dna.renderer.DocumentTableModel)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1