DZone ForumsDZone Forums  

Go Back   DZone Forums > Community > Tools & IDEs > Eclipse
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
LinkBack Thread Tools Display Modes

Topic: Multiple selection in TableViewer
Old 05-16-2008, 01:15 AM   #1 (permalink)
Member
 
Join Date: Feb 2008
Posts: 22
Hi All,
I m using TableViewer class, in this class i want to select multiple items and when i give SWT.MULTI in its constructor it does not allows me to select multiple items...

plz help me out in selecting multiple items using tableviewer.

Thanks & Regards,
Jay.
jayjamba is offline   Reply /w Quote -


Old 05-16-2008, 01:51 AM   #2 (permalink)
Member
 
Join Date: May 2008
Posts: 5
Hi Jay ,

In order to have multiple selections of item in a TableViewer...the table object which you are passing on it...provide SWT.MULTI in its constrcutor rather on the TableViewer constructor.
Sample:
Table table = new Table(shell , SWT.MULTI)
TableViewer tabViewer = new TableViewer(table)

It will work.

Regards,
Vivek
vivekkhemka is offline   Reply /w Quote -


Old 05-16-2008, 02:25 AM   #3 (permalink)
Member
 
Join Date: Feb 2008
Posts: 22
hey..vivek ..thanks for reply..
I did what u suggested but in my case there are multiple columns and then i want to select multiple cells in it, so i added TableCursor to it, but it allows me to select single cell and not multiple cells..
jayjamba is offline   Reply /w Quote -


Old 05-16-2008, 02:43 AM   #4 (permalink)
Member
 
Join Date: May 2008
Posts: 5
I feel like at one point of time you will be selecting/ editing single cell only . by single cell what i mean is one table item column cell . still i feel i am clear about ur doubt.if u can send ur code ...may be i can help u out.

vivek
vivekkhemka is offline   Reply /w Quote -


Old 05-16-2008, 02:50 AM   #5 (permalink)
Member
 
Join Date: Feb 2008
Posts: 22
hi vivek..here goes my code..just hv a peep..


Table table = new Table(parent, SWT.MULTI);

final java.util.List<FileObject> fileList=new ArrayList<FileObject>();

final Button newPerson = new Button(parent, SWT.PUSH);

newPerson.setText("Create New Person");

for(int idx=0; idx<3; idx++)
{
TableColumn tc = new TableColumn(table, SWT.LEFT);
tc.setText("Col-"+ (idx+1));
tc.pack();
tc.setWidth(250);
table.showColumn(tc);
}


final TableViewer tv = new TableViewer(table);

tv.setContentProvider(new IStructuredContentProvider()
{
public Object[] getElements(Object inputElement)
{
return ((java.util.List) inputElement).toArray();
}
public void dispose() {}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
});

tv.setLabelProvider(new ITableLabelProvider()
{
public Image getColumnImage(Object element, int columnIndex)
{
return null;
}
public String getColumnText(Object element, int columnIndex)
{
if(element instanceof FileObject)
{
FileObject fileObj = (FileObject)element;
if (columnIndex < fileObj.getFileList().size())
return fileObj.getFileList().get(columnIndex).toString();
else
return null;
}
return null;
}
public void addListener(ILabelProviderListener listener) {}
public void dispose() {}
public boolean isLabelProperty(Object element, String property)
{
return false;
}
public void removeListener(ILabelProviderListener listener){}
});

tv.setInput(fileList);
newPerson.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent event)
{
if(tv.getTable().getItemCount() > 0)
{
tv.getTable().removeAll();
fileList.clear();
}

try
{
String[] files = fileStore.childNames(EFS.NONE, null);
int count = 0;
FileObject f = new FileObject();
for(String s:files)
{
count++;
f.getFileList().add(s);
if(count%6==0)
{
fileList.add(f);
tv.refresh();
f = null;
f = new FileObject();
}
}
fileList.add(f);
tv.refresh();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});

final TableCursor cursor = new TableCursor(tv.getTable(), SWT.NONE);





class FileObject
{
private java.util.List fileList;
FileObject()
{
fileList = new ArrayList();
}
public java.util.List getFileList()
{
return fileList;
}
}
jayjamba is offline   Reply /w Quote -


Old 05-19-2008, 12:39 AM   #6 (permalink)
Member
 
Join Date: Feb 2008
Posts: 22
Hi All,
below is the forum in which i found that TableViewer does not supports multiple selection, so i want you to suggest me, is there any other control like TableViewer which supports multiple selection of individual cells and perform all other functionalities as like TableViewer..plzz reply ASAP.

EclipseZone - Table and SWT.MULTI ...


Thanks & Regards,
Jay.
jayjamba is offline   Reply /w Quote -


Old 07-22-2008, 03:16 AM   #7 (permalink)
Member
 
Join Date: May 2008
Posts: 5
Hi Jay,

Sorry for too late reply dear...u can select more than one row in a tableViewer itself.
Create an object as Table as
Table table = toolkit.createTable(generalSection,SWT.SCROLL_LINE | SWT.MULTI | SWT.FULL_SELECTION);

and pass this table object to tableViewer.
your problem will get resolved.
And still if you face any problem...you can have my e-mail id so that i can be quick on reply.

Regards,
Vivek Khemka
vivek.khemka88@gmail.com
vivekkhemka is offline   Reply /w Quote -


Thread Tools
Display Modes



All times are GMT -5. The time now is 12:16 PM.