Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to use a TableViewer?
How to use a TableViewer? [message #444952] Thu, 21 October 2004 21:11 Go to next message
Anima Gupta is currently offline Anima GuptaFriend
Messages: 44
Registered: July 2009
Member
Hi,

I am passing my results to the TableViewer as array of HashMaps - but
the table always display null - do I need to define anything else to get
that done? The keys in the HashMap match with the column names. I am
using a default ViewLabelProvider and a ViewContentProvider - I am
setting the model as a HashMap (tableViewer.setInput(new HashMap()) -
each element is a HashMap with 4 key-value pairs in it.

Is there anything else that needs to be defined for a TableViewer?

any ideas?

....
...

searchButton.addSelectionListener(new SelectionListener()
{
public void widgetSelected(SelectionEvent e)
{
SearchMovie s = new SearchMovie();
s.setSearchText(searchText.getText());
ArrayList movies = new ArrayList();
try {
movies = s.doSearch();
if (movies.size()==0){
MessageDialog.openInformation(e.display.getActiveShell(),
"Search Empty", "No Results found");
}
tableViewer.setInput(new HashMap());
tableViewer.add(movies.toArray());
} catch (Exception e1){
e1.printStackTrace();
}
}

public void widgetDefaultSelected(SelectionEvent e)
{

}
});

GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 4;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;

tableViewer = new TableViewer(parent, SWT.FULL_SELECTION
|SWT.BORDER);
tableViewer.setLabelProvider(new ViewLabelProvider());
tableViewer.setContentProvider(new ViewContentProvider());
tableViewer.setInput(new HashMap());
tableViewer.getControl().setLayoutData(gridData);

Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);

TableColumn movieIdColumn = new TableColumn(table, SWT.NONE);
movieIdColumn.setText("MOVIE_ID");
movieIdColumn.setWidth(25);

TableColumn movieNameColumn = new TableColumn(table, SWT.NONE);
movieNameColumn.setText("LABEL_DISPLAY_NAME");
movieNameColumn.setWidth(200);

TableColumn movieCountryColumn = new TableColumn(table, SWT.NONE);
movieCountryColumn.setText("COUNTRY_ID");
movieCountryColumn.setWidth(10);

TableColumn movieUPCColumn = new TableColumn(table, SWT.NONE);
movieUPCColumn.setText("MASTER_UPC");
movieUPCColumn.setWidth(50);

}
Re: How to use a TableViewer? [message #444954 is a reply to message #444952] Thu, 21 October 2004 23:19 Go to previous message
Anima Gupta is currently offline Anima GuptaFriend
Messages: 44
Registered: July 2009
Member
I did figure it out.

There is a need to define a ViewLabelProvider, which specifies actually
specifies how to get cell data for each row - I thought
ViewLabelProvider was just to display the column Text - but it really
means the column "data".

Anima.

Anima Gupta wrote:
> Hi,
>
> I am passing my results to the TableViewer as array of HashMaps - but
> the table always display null - do I need to define anything else to get
> that done? The keys in the HashMap match with the column names. I am
> using a default ViewLabelProvider and a ViewContentProvider - I am
> setting the model as a HashMap (tableViewer.setInput(new HashMap()) -
> each element is a HashMap with 4 key-value pairs in it.
>
> Is there anything else that needs to be defined for a TableViewer?
>
> any ideas?
>
> ...
> ..
>
> searchButton.addSelectionListener(new SelectionListener()
> {
> public void widgetSelected(SelectionEvent e)
> {
> SearchMovie s = new SearchMovie();
> s.setSearchText(searchText.getText());
> ArrayList movies = new ArrayList();
> try {
> movies = s.doSearch();
> if (movies.size()==0){
>
> MessageDialog.openInformation(e.display.getActiveShell(),
> "Search Empty", "No Results found");
> }
> tableViewer.setInput(new HashMap());
> tableViewer.add(movies.toArray());
> } catch (Exception e1){
> e1.printStackTrace();
> }
> }
>
> public void widgetDefaultSelected(SelectionEvent e)
> {
>
> }
> });
>
> GridData gridData = new GridData();
> gridData.verticalAlignment = GridData.FILL;
> gridData.horizontalSpan = 4;
> gridData.grabExcessHorizontalSpace = true;
> gridData.grabExcessVerticalSpace = true;
> gridData.horizontalAlignment = GridData.FILL;
>
> tableViewer = new TableViewer(parent, SWT.FULL_SELECTION
> |SWT.BORDER);
> tableViewer.setLabelProvider(new ViewLabelProvider());
> tableViewer.setContentProvider(new ViewContentProvider());
> tableViewer.setInput(new HashMap());
> tableViewer.getControl().setLayoutData(gridData);
>
> Table table = tableViewer.getTable();
> table.setHeaderVisible(true);
> table.setLinesVisible(true);
>
> TableColumn movieIdColumn = new TableColumn(table, SWT.NONE);
> movieIdColumn.setText("MOVIE_ID");
> movieIdColumn.setWidth(25);
>
> TableColumn movieNameColumn = new TableColumn(table, SWT.NONE);
> movieNameColumn.setText("LABEL_DISPLAY_NAME");
> movieNameColumn.setWidth(200);
>
> TableColumn movieCountryColumn = new TableColumn(table, SWT.NONE);
> movieCountryColumn.setText("COUNTRY_ID");
> movieCountryColumn.setWidth(10);
>
> TableColumn movieUPCColumn = new TableColumn(table, SWT.NONE);
> movieUPCColumn.setText("MASTER_UPC");
> movieUPCColumn.setWidth(50);
>
> }
>
Previous Topic:VI Editing Mode/Plug-In For Eclipse
Next Topic:java_swt on Mac OS X 10.2.8 menu bar
Goto Forum:
  


Current Time: Wed Oct 21 14:53:34 GMT 2020

Powered by FUDForum. Page generated in 0.02211 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top