Eclipse Plugin display data as table - eclipse

I'm writing an Eclipse plugin that calls a program and will display the resulting data an a table in a view.
I have successfully gotten data from the call, but have not been able to display it.
here is my code (edited for brevity)
static Vector results ;
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
try{
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IWorkbenchPage pg = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
ObjectWhereUsedInputDialog gtid = new ObjectWhereUsedInputDialog(window.getShell());
ArrayList<Object> input = gtid.openDialog();
CallProgram callPrg = new CallProgram();
String callPCML = "callPcml";
int idx = (input.size()-1);
AS400 as400 = (AS400) input.get(idx);
input.remove(idx);
results = callPrg.callProgram(as400, input);
ObjectWhereUsedResultTableView dlg = new ObjectWhereUsedResultTableView(results);
public void createPartControl(Composite parent) {
Table myTable = new Table (parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL );
myTable.setHeaderVisible (true);
myTable.setLinesVisible (true);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.heightHint = 200;
myTable.setLayoutData(data);
String[] titles = getColumns(myTable);
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (myTable, SWT.NONE);
column.setText (titles [i]);
}
if(data!=null){System.out.println("datag "+data.size());};
createTable(myTable, data);
for (int i=0; i<titles.length; i++) {
myTable.getColumn (i).pack ();
}
parent.layout(true);
parent.pack();
}
TableRow[] createTable(Table myTable, Vector<String> dataLines){
String[] columns = this.getColumns(myTable);
for (int i=0; i<columns.length; i++) {
TableColumn column = new TableColumn (myTable, SWT.NONE);
column.setText (columns[i]);
}
int dSize = dataLines==null||dataLines.isEmpty()?0:dataLines.size();
for(int i = 0;i<dSize;i++){
String[] elements = dataLines.get(i).split(",");
TableItem item = new TableItem (myTable, SWT.NONE);
for(int j = 0;j<elements.length;j++){
String itemStr = elements[j].isEmpty()?" ":elements[j];
item.setText(j,itemStr);
}
}

To show a view you must use IWorkbenchPage.showView:
ObjectWhereUsedResultTableView view = (ObjectWhereUsedResultTableView)pg.showView("the view id");
This will construct the view part using a no-argument public constructor:
public ObjectWhereUsedResultTableView()
{
...
}
You cannot pass arguments to the constructor.
To set data in the view you must add an extra method which you call after showing the view:
view.setData(data);
where setData is a method you write that updates the table with the data.
Note: You might find TableViewer easier to use than Table.

Related

NatTable filtering row header layer for dynamic list

When I use dynamic list for Nattable the filtering via filter header layer it does not work for me.
I want to be able to filter all columns. I have respective code for each column in the filter row configuration class and it works if the input is a static list.
Attached my code snippet:
public Control createPeopleTable(Composite parent) {
// create a new ConfigRegistry which will be needed for GlazedLists
configRegistry = new ConfigRegistry();
peopleTableColumns = PeopleTableColumnDefinition.getPeopleTableColumns();
final Map<String, String> propertyToLabelMap = new HashMap<>();
final String[] propertyNames = new String[peopleTableColumns.size()];
for (int i = 0; i < peopleTableColumns.size(); ++i) {
final PeopleTableColumnDefinition col = peopleTableColumns.get(i);
propertyNames[i] = col.getProperty();
propertyToLabelMap.put(propertyNames[i], col.getDisplayName());
}
columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
peopleList = new ArrayList<>();
eventList = GlazedLists.eventList(peopleList);
dynamicValues = GlazedLists.threadSafeList(eventList);
bodyLayerStack = new BodyLayerStack(dynamicValues, columnPropertyAccessor);
.....
IFilterStrategy<People> filterStrategy = new DefaultGlazedListsFilterStrategy<>(
bodyLayerStack.getFilterList(), columnPropertyAccessor, configRegistry);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
FilterRowHeaderComposite<People> filterRowHeaderLayer = new FilterRowHeaderComposite<>(filterStrategy,
sortHeaderLayer, bodyLayerStack.getBodyDataProvider(), configRegistry);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack,
bodyLayerStack.getSelectionLayer());
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider,
rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
natTable = new NatTable(parent, gridLayer, false);
.....
natTable.addConfiguration(new FilterRowConfiguration());
natTable.configure();
...
return natTable;
}
class FilterRowConfiguration extends AbstractRegistryConfiguration {
#Override
public void configureRegistry(IConfigRegistry configRegistry) {
// register the FilterRowTextCellEditor in the first column which
// immediately commits on key press
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new FilterRowTextCellEditor(),
DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX
+ PeopleTableColumnDefinition.Name.columnIndex());
.....
}
class BodyLayerStack extends AbstractLayerTransform {
private FilterList<People> filterList;
private final SelectionLayer selectionLayer;
private SortedList<People> sortedList;
private ViewportLayer viewportLayer;
public BodyLayerStack(EventList<People> values,
IColumnPropertyAccessor<People> columnPropertyAccessor) {
// use the SortedList constructor with 'null' for the Comparator
// because the Comparator
// will be set by configuration
sortedList = new SortedList<>(values, null);
// wrap the SortedList with the FilterList
filterList = new FilterList<>(sortedList);
peopleListDataProvider = new PeopleListDataProvider<>(filterList, columnPropertyAccessor);
bodyDataLayer = new DataLayer(peopleListDataProvider);
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(
bodyDataLayer);
for (int i = 0; i < peopleTableColumns.size(); i++) {
PeopleTableColumnDefinition peopleTableColumnDefinition = peopleTableColumns.get(i);
columnLabelAccumulator.registerColumnOverrides(i, peopleTableColumnDefinition.getTableLabel());
}
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
// layer for event handling of GlazedLists and PropertyChanges
GlazedListsEventLayer<People> glazedListsEventLayer = new GlazedListsEventLayer<>(bodyDataLayer,
filterList);
selectionLayer = new SelectionLayer(glazedListsEventLayer);
viewportLayer = new ViewportLayer(selectionLayer);
FreezeLayer freezeLayer = new FreezeLayer(selectionLayer);
compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, viewportLayer, selectionLayer);
setUnderlyingLayer(compositeFreezeLayer);
}
public SortedList<People> getSortedList() {
return sortedList;
}
public SelectionLayer getSelectionLayer() {
return this.selectionLayer;
}
public FilterList<People> getFilterList() {
return this.filterList;
}
public PeopleListDataProvider<People> getBodyDataProvider() {
return peopleListDataProvider;
}
}
public void setListOfPeople(List<People> listOfPeople) {
this.eventList.getReadWriteLock().writeLock().lock();
this.dynamicValues.getReadWriteLock().writeLock().lock();
try {
peopleList.clear();
eventList.clear();
dynamicValues.clear();
peopleList.addAll(listOfPeople);
eventList.addAll(listOfPeople);
dynamicValues.addAll(listOfPeople);
peopleListDataProvider.setPeopleList(peopleList);
} finally {
eventList.getReadWriteLock().writeLock().unlock();
dynamicValues.getReadWriteLock().writeLock().unlock();
}
}
It seems you haven't understood the principles of GlazedLists and Java object references.
First you don't have to call clear() and addAll() on all lists. The GlazedLists are views on the base list, so it should be enough to call on the EventList or a higher list like the FilterList.
Second mistake is that you set another list on the IDataProvider. And that list is not the FilterList. So actually you disable the filter as the FilterList is doing the filter magic. And setting the list is not necessary as you performed a list modification. So why changing it then?

want to create drop down list (Combo box viewer) in TreeColumn in SWT

I am using Tree and in this tree I have a five treecolumn. Also create two treeItem one is parent and other child, put their values in treecolumn by programatically. Now I need a dropdown List(Combobox) in each tree column(except first one) to view the list data. Currently getting only single value. Please see the below code to get tree item values editable in treecolumn.
private void editTreeTable(final Tree table){
final TreeEditor editor = new TreeEditor(table);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
table.addMouseListener(new MouseAdapter() {
#Override
public void mouseUp(final MouseEvent e) {
final Control oldEditor = editor.getEditor();
if (oldEditor != null) {
oldEditor.dispose();
}
final Point p = new Point(e.x, e.y);
final TreeItem item = table.getItem(p);
if (item == null) {
return;
}
for (int i = 1; i < table.getColumnCount(); ++i) {
if (item.getBounds(i).contains(p)) {
final int columnIndex = i;
// The control that will be the editor must be a
final Text newEditor = new Text(table, SWT.NONE);
newEditor.setText(item.getText(columnIndex ));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
final Text text = (Text) editor.getEditor();
editor.getItem().setText(columnIndex , text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, columnIndex );
}
}
}
});
}
Now find the below code to get the tree item value from API
private void createTestSuiteTable( final Tree table)
{
//Dispose all elements
TreeItem items[] = table.getItems();
for(int i=0;i<items.length;i++)
{
items[i].dispose();
}
TSGson tsGsons[] = TestSuiteAPIHandler.getInstance().getAllTestSuites();
boolean checked=false;
for (TSGson tsGson : tsGsons)
{
parentTestSuite = new TreeItem(table, SWT.NONE|SWT.MULTI);
parentTestSuite.setText(new String[] { "" +tsGson.tsName, "", "","","","" });
parentTestSuite.setData("EltType","TESTSUITE");
if(tsGson.tsTCLink==null)
continue;
for(TSTCGson tsTCGson : tsGson.tsTCLink)
{
TreeItem trtmTestcases = new TreeItem(parentTestSuite, SWT.NONE|SWT.MULTI);
trtmTestcases.setText(new String[] {tsTCGson.tcName,
tsTCGson.tcParams.get(0)!=null ?tsTCGson.tcParams.get(0).tcparamValue:"",
tsTCGson.tcParams.get(1)!=null ?tsTCGson.tcParams.get(1).tcparamValue:"",
tsTCGson.tcParams.get(2)!=null ?tsTCGson.tcParams.get(2).tcparamValue:"",
"local",
tsTCGson.tcParams.get(4)!=null ?tsTCGson.tcParams.get(4).tcparamValue:"" });
trtmTestcases.setData("EltType","TESTCASE");
table.setSelection(parentTestSuite);
if(checked)
{
trtmTestcases.setChecked(checked);
}
}
}
}
Find the below code for tree column creation in SWT
localHostTable = new Tree(composite_2,SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION | SWT.VIRTUAL);
localHostTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
localHostTable.setLinesVisible(true);
localHostTable.setHeaderVisible(true);
TreeColumn trclmnNewColumn_1 = new TreeColumn(localHostTable, SWT.NONE);
trclmnNewColumn_1.setWidth(113);
trclmnNewColumn_1.setText("TestSuite/TestCase");
TreeColumn trclmnColumn_5 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_5.setWidth(73);
trclmnColumn_5.setText("Exe_Platform");
TreeColumn trclmnColumn_6 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_6.setWidth(77);
trclmnColumn_6.setText("Exe_Type");
TreeColumn trclmnColumn_7 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_7.setWidth(85);
trclmnColumn_7.setText("Run_On");
TreeColumn trclmnColumn_8 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_8.setWidth(81);
trclmnColumn_8.setText("Thread-Count");
final TreeColumn trclmnColumn_9 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_9.setWidth(97);
trclmnColumn_9.setText("Column5");
please suggest
Since there's nothing in your question about Combo or CCombo controls, I can't help you troubleshoot an issue. I also am not going to write your code for you, but I can try to point you in the right direction with a short example.
Yes, i want the combo to always be visible.
You can still use a TreeEditor to accomplish this, and it will actually be simpler than the code snippet you posted with the MouseListener.
Create the CCombo (or Combo) as you would in any other situation, and use TreeEditor.setEditor(...) methods to specify that the CCombo control should be displayed in that cell:
// ...
final CCombo combo = new CCombo(tree, SWT.NONE);
final TreeEditor editor = new TreeEditor(tree);
editor.setEditor(combo, item, 1);
// ...
Full MCVE:
public class TreeComboBoxTest {
private final Display display;
private final Shell shell;
public TreeComboBoxTest() {
display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());
final Tree tree = new Tree(shell, SWT.BORDER | SWT.VIRTUAL | SWT.FULL_SELECTION);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
final TreeColumn column1 = new TreeColumn(tree, SWT.NONE);
column1.setWidth(75);
column1.setText("Column 1");
final TreeColumn column2 = new TreeColumn(tree, SWT.NONE);
column2.setWidth(75);
column2.setText("Column 2");
final TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText(0, "Hello");
final CCombo combo = new CCombo(tree, SWT.NONE);
combo.setItems(new String[] { "Item 1", "Item 2", "Item 3" });
final TreeEditor editor = new TreeEditor(tree);
editor.setEditor(combo, item, 1);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
// Optional, but allows you to get the current value by calling
// item.getText() instead of going through the TreeEditor and
// calling ((CCombo) editor.getEditor()).getText()
combo.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
item.setText(1, combo.getText());
}
});
}
public void run() {
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(final String... args) {
new TreeComboBoxTest().run();
}
}
Note the SelectionListener added to the CCombo. Even though you've used the TreeEditor, if you call item.getText(index), it will return an empty String because setText(...) has not been called. By calling setText(...) in the listener, you won't have to go through the TreeEditor to get the value.
So you can call item.getText(index) instead of ((CCombo) editor.getEditor()).getText().

how dynamically adjust size of controls in TitleAreaDialog

I have TitleAreaDialog that can have n numbers of Tree, each tree has its own composite. If I have just 2 trees the dialog looks great, but if number of trees grows the content of the trees are being truncated.
I think I missed something small..
Here is the code:
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
public class testTitleDialog extends TitleAreaDialog {
private static final String DIALOG_TITLE = "TITLE AREA DIALOG";
Composite area;
public testTitleDialog(Shell parentShell) {
super(parentShell);
}
#Override
public void create() {
super.create();
setTitle("TITLE WILL BE HERE");
}
#Override
protected Control createDialogArea(final Composite parent) {
this.area = (Composite) super.createDialogArea(parent);
parent.getShell().setText(DIALOG_TITLE);
Composite area = (Composite) super.createDialogArea(parent);
Composite contents = (Composite) super.createDialogArea(area);
contents.setLayout(new GridLayout());
contents.setLayoutData(new GridData(GridData.FILL_BOTH));
contents.addDisposeListener(new DisposeListener(){
public void widgetDisposed(DisposeEvent e) {
}
});
createMapperComposite(contents);
return this.dialogArea;
}
private void createMapperComposite(Composite composite) {
Composite main = new Composite(composite, SWT.NONE);
main.setLayout(new GridLayout());
main.setLayoutData(new GridData(GridData.FILL_BOTH));
treeMapper(main);
}
private Composite treeMapper(Composite main) {
SashForm sashForm = new SashForm(main, SWT.HORIZONTAL);
Composite composite = new Composite(sashForm, SWT.NONE);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setBackground(ColorConstants.white);
//i is number of trees
for (int i = 0; i < 10; i++) {
Label lbl = new Label(composite, SWT.NONE);
lbl.setText("Tree " + i);
// Add content to scrolled composite
Composite scrolledContent = new Composite(composite, SWT.NONE);
scrolledContent.setLayout(new GridLayout());
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
scrolledContent.setLayoutData(gridData);
final TreeViewer tree = new TreeViewer(scrolledContent);
for(int loopIndex0 = 0; loopIndex0 < 10; loopIndex0++) {
TreeItem treeItem0 = new TreeItem(tree.getTree(), 0);
treeItem0.setText("Level 0 Item "+ loopIndex0);
for(int loopIndex1 = 0; loopIndex1 < 10; loopIndex1++) {
TreeItem treeItem1 = new TreeItem(treeItem0, 0);
treeItem1.setText("Level 1 Item "+ loopIndex1);
for(int loopIndex2 = 0; loopIndex2 < 10; loopIndex2++) {
TreeItem treeItem2 = new TreeItem(treeItem1, 0);
treeItem2.setText("Level 2 Item "+ loopIndex2);
}
}
}
tree.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
}
new TreeViewer(sashForm);
return main;
}
#Override
protected boolean isResizable() {
return true;
}
#Override
protected void okPressed() {
super.okPressed();
}
public static void main(final String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
new testTitleDialog(shell).open();
}
}
You are not doing anything to deal with the dialog being too big from the display. You must use something like ScrolledComposite to deal with this:
#Override
protected Control createDialogArea(final Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
parent.getShell().setText(DIALOG_TITLE);
ScrolledComposite scrolled = new ScrolledComposite(area, SWT.V_SCROLL | SWT.H_SCROLL);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 500;
scrolled.setLayoutData(data);
scrolled.setExpandHorizontal(true);
scrolled.setExpandVertical(true);
createMapperComposite(scrolled);
return area;
}
private void createMapperComposite(ScrolledComposite composite) {
Composite main = new Composite(composite, SWT.NONE);
main.setLayout(new GridLayout());
main.setLayoutData(new GridData(GridData.FILL_BOTH));
treeMapper(main);
composite.setContent(main);
composite.setMinSize(main.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Note: You have to choose a height for the dialog (see data.heightHint = 500) to make this work.
Your code called super.createDialogArea three times - this must be called exactly once. You also returned this.dialogArea - you should return the value returned by super.createDialogArea.

AssertionFailedException while creating Commbobox in tableviewer

I am trying to make a combobox in table viewer in Eclipse SWT.pointing me in the right direction.I think I've done everything ok until now, problem is the combo box not display in the table,I got error this:
Error:
Block of Code is:
public void createPartControl(Composite parent) {
System.out.println("createPartControl call");
// For Testing
Composite tableComposite = new Composite(parent, SWT.NONE);
tableColumnLayout = new TableColumnLayout();
tableComposite.setLayout(tableColumnLayout);
tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
tableViewer = new TableViewer(tableComposite, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
// TODO viewer.setLabelProvider(new ViewLabelProvider());
table = tableViewer.getTable();
// Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
String[] titles = { "Threat Name", "Category Name", "Status",
"Priority", "Description", "Justification" };
for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmn = tableViewerColumn.getColumn();
tableColumnLayout.setColumnData(tblclmn, new ColumnPixelData(200,
true, true));
tblclmn.setText(titles[loopIndex]);
}
}
private void fillRows(String shortdesc, String categ, String descp) {
System.out.println("fillRows call from above method.");
TableColumn status_Name_Col = tableViewer.getTable().getColumn(2);
System.out.println("**************** status_Name_Col ************ "+ status_Name_Col);
tableViewerColumn.setLabelProvider(new ColumnLabelProvider()
{
#Override
public String getText(Object element)
{
Dummy p = (Dummy) element;
return p.getValue();
}
});
tableViewer.addSelectionChangedListener(new ISelectionChangedListener()
{
#Override
public void selectionChanged(SelectionChangedEvent selectionChangedEvent)
{
StructuredSelection selection = (StructuredSelection) selectionChangedEvent.getSelection();
System.out.println(((Dummy) selection.getFirstElement()).getValue());
}
});
List<Dummy> elements = new ArrayList<>();
for (int i = 0; i < Connection.Number_Of_Connection; i++) {
elements.add(new Dummy("First option"));
}
tableViewer.setInput(elements);
tableColumnLayout.setColumnData(status_Name_Col, new ColumnWeightData(1, true));
tableViewerColumn.setEditingSupport(new FirstValueEditingSupport(tableViewer));
}
The assertion message is pretty clear - you must set a label provider for each column in the table.
You don't show us where you are calling fillRows but setting the column label provider in that method looks wrong - set the label providers in your loop creating the columns.

SWT - Getting Selected Rows from Table

I am trying to write a method that will get the current selections from the table and create a ArrayList from the selections.
Method:
public void getPlotterSelection() {
selPrinters = new ArrayList<PrinterProfile>();
int[] row = table.getSelectionIndices();
Arrays.sort(row);
if (row.length > 0) {
for(int i = row.length-1; i >= 0; i--){
PrinterProfile pp = new PrinterProfile(aa.get(i).getPrinterName(), aa.get(i).getProfileName());
selPrinters.add(pp);
}
}
}
This is the error I am getting
ERROR: 16:16:49,503 - TcLogger$IC_LogListener.logging:?
org.eclipse.core.runtime - org.eclipse.ui - 0 - Unhandled event loop exception
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.SWT.error(SWT.java:3770)
at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:336)
at org.eclipse.swt.widgets.Table.getSelectionIndices(Table.java:2536)
etc .......
The problem is with this line of code
int[] row = table.getSelectionIndices();
Once again..
I am trying to get the user selected rows in the table and put them in a arraylist.
Edit Adding more code
//////////////////////////////////////////////////////////////////////////
// createDialogArea() //
//////////////////////////////////////////////////////////////////////////
protected Control createDialogArea(Composite parent) {
final Composite area = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.marginWidth = 15;
gridLayout.marginHeight = 10;
area.setLayout(gridLayout);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
area.setLayoutData(gridData);
checkingArray();
createCopyNumber(area);
createPlotterTable(area);
return area;
}
public void checkingArray() {
aa = abd.getPrintersArray();
}
//////////////////////////////////////////////////////////////////////////
// createPlotterTable() //
//////////////////////////////////////////////////////////////////////////
private void createPlotterTable(Composite parent) {
Composite composite = new Composite(parent, SWT.BORDER);
GridLayout gridLayout = new GridLayout(1, false);
composite.setLayout(gridLayout);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
composite.setLayoutData(gridData);
//gridData = new GridData(SWT.FILL, SWT.FILL, true, true );
table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn[] column = new TableColumn[2];
column[0] = new TableColumn(table, SWT.FILL);
column[0].setText("Printer Name");
column[0].setWidth(200);
column[1] = new TableColumn(table, SWT.FILL);
column[1].setText("Profile Name");
column[1].setWidth(200);
gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
table.setLayoutData(gridData);
fillTable(table);
table.setRedraw(true);
}
private void fillTable(Table table) {
table.setRedraw(false);
for(Iterator iterator = abd.getPrintersArray().iterator();iterator.hasNext();){
PrinterProfile printer = (PrinterProfile) iterator.next();
TableItem item = new TableItem(table, SWT.FILL);
int c = 0;
item.setText(c++, printer.getPrinterName());
item.setText(c++, printer.getProfileName());
}
table.setRedraw(true);
}
public void getPlotterSelection() {
selPrinters = new ArrayList<PrinterProfile>();
int[] row = table.getSelectionIndices();
Arrays.sort(row);
if (row.length > 0) {
for(int i = row.length-1; i >= 0; i--){
PrinterProfile pp = new PrinterProfile(aa.get(i).getPrinterName(), aa.get(i).getProfileName());
selPrinters.add(pp);
}
}
}
This is the button that calls the method
Button okButton = createButton(parent, IDialogConstants.OK_ID, "OK", true);
okButton.setEnabled(true);
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
getPlotterSelection();
}
});
I would suggest you to user Table viewer rather than Table. It makes your life easier. I see that you are showing table in a dialog. I guess your dialog is getting closed/disposed when you click OK before it get to getPlotterSelection() method.