Search in sources :

Example 1 with CoderRelation

use of dna.dataStructures.CoderRelation in project dna by leifeld.

the class CoderRelationTableModel method setValueAt.

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    CoderRelation cr = Dna.data.getCoderRelations().get(rowIndex);
    if (columnIndex == 0) {
        Dna.data.getCoderById(cr.getOtherCoder()).setName((String) aValue);
    } else if (columnIndex == 1) {
        Dna.data.getCoderRelations().get(rowIndex).setViewStatements((boolean) aValue);
        Dna.dna.sql.updateCoderRelationViewStatements(cr.getId(), (boolean) aValue);
    } else if (columnIndex == 2) {
        Dna.data.getCoderRelations().get(rowIndex).setEditStatements((boolean) aValue);
        Dna.dna.sql.updateCoderRelationEditStatements(cr.getId(), (boolean) aValue);
    } else if (columnIndex == 3) {
        Dna.data.getCoderRelations().get(rowIndex).setViewDocuments((boolean) aValue);
        Dna.dna.sql.updateCoderRelationViewDocuments(cr.getId(), (boolean) aValue);
    } else if (columnIndex == 4) {
        Dna.data.getCoderRelations().get(rowIndex).setEditDocuments((boolean) aValue);
        Dna.dna.sql.updateCoderRelationEditDocuments(cr.getId(), (boolean) aValue);
    }
    TableModelEvent e = new TableModelEvent(this);
    for (int i = 0, n = listeners.size(); i < n; i++) {
        ((TableModelListener) listeners.get(i)).tableChanged(e);
    }
    // fireTableCellUpdated(rowIndex, columnIndex);
    // update statement-related GUI parts
    Dna.gui.textPanel.paintStatements();
    Dna.gui.rightPanel.statementPanel.statementFilter.updateFilter();
    // update document-related GUI parts
    Dna.gui.documentPanel.documentFilter();
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener) CoderRelation(dna.dataStructures.CoderRelation)

Example 2 with CoderRelation

use of dna.dataStructures.CoderRelation in project dna by leifeld.

the class CoderRelationCellRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
    int modelRow = table.convertRowIndexToModel(row);
    CoderRelation cr = ((CoderRelationTableModel) table.getModel()).get(modelRow);
    if (column == 0) {
        int otherCoderId = cr.getOtherCoder();
        Coder otherCoder = Dna.data.getCoderById(otherCoderId);
        Color otherColor = otherCoder.getColor();
        @SuppressWarnings("serial") JButton colorButton = (new JButton() {

            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.setColor(otherColor);
                g.fillRect(2, 2, 12, 12);
            }
        });
        colorButton.setPreferredSize(new Dimension(12, 12));
        colorButton.setEnabled(false);
        panel.add(colorButton);
        String name = otherCoder.getName();
        int nameLength = name.length();
        if (nameLength > 14) {
            nameLength = 14 - 3;
            name = name.substring(0, nameLength);
            name = name + "...";
        }
        JLabel otherName = new JLabel(name);
        panel.add(otherName);
        otherName.setEnabled(false);
    } else if (column == 1) {
        boolean viewStatements = cr.isViewStatements();
        JCheckBox box = new JCheckBox();
        box.setSelected(viewStatements);
        if (Dna.data.getCoderById(Dna.data.getActiveCoder()).getPermissions().get("viewOthersStatements") == false) {
            box.setEnabled(false);
        }
        return box;
    } else if (column == 2) {
        boolean editStatements = cr.isEditStatements();
        JCheckBox box = new JCheckBox();
        box.setSelected(editStatements);
        if (Dna.data.getCoderById(Dna.data.getActiveCoder()).getPermissions().get("editOthersStatements") == false) {
            box.setEnabled(false);
        }
        return box;
    } else if (column == 3) {
        boolean viewDocuments = cr.isViewDocuments();
        JCheckBox box = new JCheckBox();
        box.setSelected(viewDocuments);
        if (Dna.data.getCoderById(Dna.data.getActiveCoder()).getPermissions().get("viewOthersDocuments") == false) {
            box.setEnabled(false);
        }
        return box;
    } else if (column == 4) {
        boolean editDocuments = cr.isEditDocuments();
        JCheckBox box = new JCheckBox();
        box.setSelected(editDocuments);
        if (Dna.data.getCoderById(Dna.data.getActiveCoder()).getPermissions().get("editOthersDocuments") == false) {
            box.setEnabled(false);
        }
        return box;
    }
    return panel;
}
Also used : JPanel(javax.swing.JPanel) Coder(dna.dataStructures.Coder) FlowLayout(java.awt.FlowLayout) Color(java.awt.Color) JButton(javax.swing.JButton) CoderRelation(dna.dataStructures.CoderRelation) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Graphics(java.awt.Graphics) JCheckBox(javax.swing.JCheckBox)

Example 3 with CoderRelation

use of dna.dataStructures.CoderRelation in project dna by leifeld.

the class SqlConnection method getAllCoderRelations.

/**
 * @return     Array list of all coder relations in the SQL database.
 */
private ArrayList<CoderRelation> getAllCoderRelations() {
    ArrayList<CoderRelation> al = new ArrayList<CoderRelation>();
    try {
        String myQuery = "SELECT * FROM CODERRELATIONS";
        PreparedStatement preStatement = (PreparedStatement) connection.prepareStatement(myQuery);
        ResultSet result = preStatement.executeQuery();
        if (result.next()) {
            do {
                int viewStatementsInt = result.getInt("viewStatements");
                int editStatementsInt = result.getInt("editStatements");
                int viewDocumentsInt = result.getInt("viewDocuments");
                int editDocumentsInt = result.getInt("editDocuments");
                boolean viewStatements, editStatements, viewDocuments, editDocuments;
                if (viewStatementsInt == 1) {
                    viewStatements = true;
                } else {
                    viewStatements = false;
                }
                if (editStatementsInt == 1) {
                    editStatements = true;
                } else {
                    editStatements = false;
                }
                if (viewDocumentsInt == 1) {
                    viewDocuments = true;
                } else {
                    viewDocuments = false;
                }
                if (editDocumentsInt == 1) {
                    editDocuments = true;
                } else {
                    editDocuments = false;
                }
                CoderRelation coderRelation = new CoderRelation(result.getInt("ID"), result.getInt("Coder"), result.getInt("OtherCoder"), viewStatements, editStatements, viewDocuments, editDocuments);
                al.add(coderRelation);
            } while (result.next());
        }
        result.close();
        preStatement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return al;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) CoderRelation(dna.dataStructures.CoderRelation) PreparedStatement(java.sql.PreparedStatement)

Aggregations

CoderRelation (dna.dataStructures.CoderRelation)3 Coder (dna.dataStructures.Coder)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 Graphics (java.awt.Graphics)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 TableModelEvent (javax.swing.event.TableModelEvent)1 TableModelListener (javax.swing.event.TableModelListener)1