|
Re: How to use a TableViewer? [message #444954 is a reply to message #444952] |
Thu, 21 October 2004 23:19 |
Anima Gupta 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);
>
> }
>
|
|
|
Powered by
FUDForum. Page generated in 0.03781 seconds