Hi there,

I'm working on a project management oriented java application using SWT on eclipse.

I'm using SWT Table, TableViewer, TableEditor to attribute working time to a user.

When the user does "Right Click -> View Project" on the project the program firstly fill the table with "0"s and access the database well, and then push the already attributed working time on this task onto the table (replacing the "0"s not desired). This works fine and does exactly what I want it to do. As you can see on this screenshot there is a concordance between the Database and my table.




The problem is, when I do "Right Click -> View Project" on another project, I want the new attributed working time to replace the former ones but it doesn't work. I mean, for a 2nd project I still see the 1st project attributed working times.

With a simple 'SOP' test, I clearly see that the new 'setText' row is reached but it seems to have no effect. But then I noticed that it has the effect to add new lines to my table, that are empty. This is probably due to the fact that my Text[] texte is an array and when I do texte = new Text(table2, SWT.NONE); it stacks up, generating the new empty lines. I still don't understand why these lines are empty.



Now, here's what the code looks like.

Java Code:
public void fillSubtasks(Task selectedTask) throws DbException
{
	table2.clearAll();

[COLOR="#9acd32"]// I generate items to put the name of the subtasks corresponding to a project
[/COLOR]		for (int j = 0; j < selectedTask.getSubTasksCount(); j++) {
			      new TableItem(table2, SWT.NONE);
			    }
[COLOR="#9acd32"]//I fill items with subtasks names
[/COLOR]		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();
[COLOR="#9acd32"]//I store the users registered in the software
[/COLOR]	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);
[COLOR="#9acd32"]//Fill with "0"s
[/COLOR]texte.setText("0");
[COLOR="#9acd32"]//Replace it if a contribution exists in the DB
[/COLOR]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++;
	}
What can I do to avoid that ?
Thanks in advance !