1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| public void fillSubtasks(Task selectedTask) throws DbException {
table2.clearAll();
// I generate items to put the name of the subtasks corresponding to a project
for (int j = 0; j < selectedTask.getSubTasksCount(); j++) {
new TableItem(table2, SWT.NONE);
}
// I fill items with subtasks names
items = table2.getItems();
final Task[] subtasktable = ModelMgr.getSubtasks(selectedTask);
for (int i = 0; i < selectedTask.getSubTasksCount(); i++) {
items[i].setText(subtasktable[i].getName());
}
DbTransaction tx = DbMgr.beginTransaction();
// I store the users registered in the software
final Collaborator[] collabs = DbMgr.getCollaborators(tx, 1, true, true);
DbMgr.commitTransaction(tx);
DbMgr.endTransaction(tx);
for (int i = 0; i < collabs.length; i++) {
for (int j = 0; j < selectedTask.getSubTasksCount(); j++) {
final int cit = i;
final int cjt = j;
tx = DbMgr.beginTransaction();
editor = new TableEditor(table2);
editor.grabHorizontal = true;
final Text texte = new Text(table2, SWT.NONE);
// Fill with "0"s
texte.setText("0");
// Replace it if a contribution exists in the DB
if (DbMgr.attributedTaskExists(tx, collabs[i], subtasktable[j]) != 0) {
texte.setText(String.valueOf(DbMgr.getAttributedTask(tx, collabs[cit].getLogin(), subtasktable[cjt])));
}
DbMgr.commitTransaction(tx);
DbMgr.endTransaction(tx);
texte.addModifyListener(new ModifyListener()
{
public void modifyText(ModifyEvent evt) {
System.out.println("text " + texte.getText());
try {
DbTransaction tx = DbMgr.beginTransaction();
DbMgr.getAttributedTask(tx, collabs[cit].getLogin(), subtasktable[cjt]);
DbMgr.updateAttributedTask(tx, collabs[cit].getLogin(), subtasktable[cjt], Integer.parseInt(texte.getText()));
DbMgr.commitTransaction(tx);
DbMgr.endTransaction(tx);
}
catch (DbException e) {
e.printStackTrace();
}
}
});
editor.setEditor(texte, items[j], i + 1);
}
}
k++;
} |
Partager