0
votes

I'm a newer in SWT and JFace, recently, I used JFace tableviewer in my project. And I need to delete items by a delete button. But it doesn't work if i refresh the tableviewer after deleting it. I want to know the reason.My code shows below:

btnDeleteConstraint.addSelectionListener(
          new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
          ISelection selection = tableViewer.getSelection();
          logger.debug("datatype selected");
          if (selection != null || selection instanceof 
          IStructuredSelection) {
            IStructuredSelection sel = (IStructuredSelection) selection;
            Iterator iterator = sel.iterator();
            while(iterator.hasNext()) {
                Object obj = iterator.next();
                tableViewer.remove(obj);
            }

            tableViewer.refresh();
        }

    }
});

And i use another method called update() to set input and refresh the table in the end:

public void update()
{
   tableViewer.setInput(DataTypeFactory.
   getInstance().getCastList(wizard.getSourceInfo().getDBType()));
   tableViewer.refresh();
 }
1

1 Answers

0
votes

When you call refresh the table is updated from your 'content provider' - so when you delete things you must update the data that your content provider returns in its getElements method.