SWT - table vs TableViewer

I am creating a new project using SWT. I will have 3 or 4 different tables in the project. I am new to SWT and I ask if I should use only Table or should there be a TableViewer .

I want to learn some good recommendations about when to use only Table , and when TableViewer is the best route.

  • What is the advantage of using TableViewer instead of Table ?
  • Should all tables have a TableViewer ?
  • If I work with data from a table, is Table best?

I just really want clarity to create a project. I am doing it right.

EDIT

I created the Tablemodel class that I use for my first table. But the createColumns method createColumns specialized for this particular table.

Is it possible to have a TableViewer class template?
Can I change the method for more convenient use for different tables?

Here is a fragment of the method:

 private void createColumns() { String[] titles = { "ItemId", "RevId", "PRL", "Dataset Name", "EC Markup" }; int[] bounds = { 150, 150, 100, 150, 100 }; TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0); col.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { if(element instanceof AplotDataModel.AplotDatasetData) return ((AplotDataModel.AplotDatasetData)element).getDataset().toString(); return super.getText(element); } }); col = createTableViewerColumn(titles[1], bounds[1], 1); col.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { if(element instanceof AplotDataModel.AplotDatasetData) return ((AplotDataModel.AplotDatasetData)element).getRev().toString(); return super.getText(element); } }); 
+7
source share
3 answers

In general, I would suggest a TableViewer . The viewer will take care of most of the things you have to do with Table . Removing and adding and moving items is easier, as well as customizing the display of items. Handling click events is very simple with the help of the viewer.

There are several cases where I would use a Table without a TableViewer . For example: When a table is used only to display a static set of elements that never change. In this case, a TableViewer may be slightly above the top.

However, you should keep in mind that your project can grow, and you may need these β€œsimple” tables to do more than just display static elements. In this case, you will have to replace the table with a viewer, which will work a lot.

So think twice before using a Table without a TableViewer .

+3
source

http://sunnyshekhar.blogspot.com/2013/04/creating-swt-table-below-i-will-try-to.html

Here I tried to explain how to create a table in swt. I believe that creating a table in swt is easier said than done. We have a lot of difficulties. The implementation is a little hard to understand. But we have many settings available in swt. It should also be noted that Swt is the layer above Os, so in Swt we use what Os ever provides us. Sometimes it’s difficult to create a checkbox and move it to the center of the cell. There are many similar problems that I encountered while creating the table, but you always have hacks or a workaround for them. In Swt, we have well-defined classes that, if u implement a lot of methods for playing with a table.

+1
source
0
source

All Articles