package View;
import Modele.EleveNote;
import Modele.FeuilleNote;
import Modele.Promotion;
import javax.swing.JOptionPane;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.Binding.SyncFailure;
import org.jdesktop.beansbinding.BindingListener;
import org.jdesktop.beansbinding.PropertyStateEvent;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
/**
*
* @author tiph
*/
public class FeuilleNoteView extends javax.swing.JPanel {
// feuille de note du panel
private FeuilleNote feuilleModel;
public FeuilleNote getFeuilleModel() {
return feuilleModel;
}
/**
* Creates new form FeuilleNoteView
*/
private void init() {
initComponents();
// create the binding from List to JTable
JTableBinding tb;
tb = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ_WRITE, feuilleModel.getNoteEleves(), table);
// define the properties to be used for the columns
BeanProperty nome = BeanProperty.create("eleve.nom");
BeanProperty prenome = BeanProperty.create("eleve.prenom");
BeanProperty notee = BeanProperty.create("note");
BeanProperty envoi = BeanProperty.create("envoie");
// configure how the properties map to columns
tb.addColumnBinding(nome).setColumnName("Nom").setEditable(false);
tb.addColumnBinding(prenome).setColumnName("Prénom").setEditable(false);
JTableBinding.ColumnBinding col_note = tb.addColumnBinding(notee);
col_note.setColumnName("Note");
col_note.setEditable(true);
col_note.setColumnClass(String.class);
// definie le validateur a utiliser par la vue pour valider les valeurs
col_note.setValidator(EleveNote.getNoteValidator());
// Listener pour ecouter les changement de valeur afin de gerer coté client le verification des valeur rentrer
col_note.addBindingListener(new BindingListener() {
@Override
public void bindingBecameBound(Binding binding) {
}
@Override
public void bindingBecameUnbound(Binding binding) {
}
@Override
public void syncFailed(Binding binding, SyncFailure failure) {
}
@Override
public void synced(Binding binding) {
}
@Override
public void sourceChanged(Binding binding, PropertyStateEvent event) {
}
@Override
public void targetChanged(Binding binding, PropertyStateEvent event) {
if (binding.getTargetValueForSource().failed()) {
JOptionPane.showMessageDialog(jScrollPane1, binding.getTargetValueForSource().getFailure().getValidationResult().getDescription(),
"Valeur incorrecte",
JOptionPane.ERROR_MESSAGE);
}
}
});
tb.addColumnBinding(envoi).setColumnName("A envoyer").setEditable(true).setColumnClass(Boolean.class);
// realize the binding
tb.bind();
}
public FeuilleNoteView(Promotion p) {
feuilleModel = new FeuilleNote(p);
init();
}
public FeuilleNoteView(String path) {
feuilleModel = new FeuilleNote(path);
init();
}
/**
* This method is called from within the constructor to initialize the
* form. WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
table = new javax.swing.JTable();
checkb_withnote = new javax.swing.JCheckBox();
jScrollPane1.setViewportView(table);
checkb_withnote.setText("avec une note");
checkb_withnote.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checkb_withnoteActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(checkb_withnote)
.addGap(20, 20, 20))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(checkb_withnote)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void checkb_withnoteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkb_withnoteActionPerformed
boolean isSelected;
for (int i = 0; i < table.getRowCount(); i++) {
if(table.getValueAt(i, 2) != null && !((String)table.getValueAt(i, 2)).isEmpty()){
table.setValueAt(checkb_withnote.isSelected(), i, 3);
}
}
}//GEN-LAST:event_checkb_withnoteActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox checkb_withnote;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable table;
// End of variables declaration//GEN-END:variables
}