| Problems with a TableView - it's not showing... [message #662131] |
Tue, 29 March 2011 09:13  |
akoeck Messages: 62 Registered: December 2010 |
Member |
|
|
Hi in my Plug-In i want to use a TableViewer to show the content of a selected Table. Therefore I have created a View with a TableViewer inside.
But the View ist not showing, although I have added it to my perspective.
The provided area remains empty. I could add the view via the Open View Menu, but then the view is not showing the content of my tables. I also got the problem, how can I handle this if have no selected element, so that I create an empty table. This is the code of my view.
public class TableView extends ViewPart {
private TableViewer tableViewer;
private Table table;
private ITableData tableData;
/**
*
*/
public TableView() {
super();
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
GridLayout layout = new GridLayout(2, false);
parent.setLayout(layout);
createViewer(parent);
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/
@Override
public void setFocus() {
tableViewer.getControl().setFocus();
}
/**
*
* @param model
*/
public void setModel(Table model){
table = model;
}
private void createViewer(Composite parent){
tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.getTable().setLinesVisible(true);
tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
tableViewer.setLabelProvider(new TableDataLabelProvider());
tableViewer.setContentProvider(new TableDataContentProvider());
try {
tableData = new TableDataImpl(table);
configureTable();
tableViewer.setInput(tableData);
} catch (Exception e) {
String title = Messages.getString(
"TableDataEditor.ErrorInitializingEditor");
IStatus error = new Status(IStatus.ERROR, DataUIPlugin.PLUGIN_ID,
1, e.toString(), e);
ErrorDialog.openError(PlatformUI.getWorkbench().getDisplay()
.getActiveShell(), title, null, error);
e.printStackTrace();
}
}
private void configureTable(){
for(int i=0; i<tableData.getColumnCount(); ++i){
final TableViewerColumn viewerColumn =
new TableViewerColumn(tableViewer,SWT.NONE);
final TableColumn column = viewerColumn.getColumn();
column.setText(tableData.getColumnHeader(i));
column.setWidth(100);
column.setResizable(true);
column.pack();
}
tableViewer.getTable().pack();
}
}
I hope you can help me.
|
|
|