Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Sorting Nebula Grid Widget
Sorting Nebula Grid Widget [message #903336] Thu, 23 August 2012 04:18 Go to next message
zainab alhaidary is currently offline zainab alhaidary
Messages: 20
Registered: April 2012
Junior Member
hello every body Smile

I'm using the Nebula grid widget that has multiple columns, filling it with items by :

private Grid grid;

grid = new Grid(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE);

grid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

// banner, SWT.BORDER
grid.setHeaderVisible(true);
final GridColumn column = new GridColumn(grid,SWT.NONE);
column.setText("ID");
column.setWidth(100);
column.setSort(SWT.UP);
column.setTree(true);

// new ColumnViewerSorter(grid, column) {
// @Override
// protected int doCompare (Viewer viewer, Object e1, Object e2) {
// // compare the two items e1 and e2
// }
// };
GridColumn column2 = new GridColumn(grid,SWT.NONE);
column2.setText("project");
column2.setWidth(300);
// column2.setSummary(false);
GridColumn column3 = new GridColumn(grid,SWT.NONE);
column3.setText("Summary");
column3.setWidth(300);
// column3.setSort(SWT.UP|SWT.DOWN);

// column3.setSummary(false);
GridColumn column4 = new GridColumn(grid,SWT.NONE);
column4.setText("Creation date");
column4.setWidth(150);
// column4.setSummary(false);
GridColumn column5 = new GridColumn(grid,SWT.NONE);
column5.setText("Type");
column5.setWidth(100);
column5.setVisible(true);
GridColumn column6 = new GridColumn(grid,SWT.NONE);
column6.setText("State" +
"");
column6.setWidth(100);
column6.setVisible(true);
GridColumn column7 = new GridColumn(grid,SWT.NONE);
column7.setText("Assigned User");
column7.setWidth(100);
column7.setVisible(true);
GridColumn column8 = new GridColumn(grid,SWT.NONE);
column8.setText("Release");
column8.setWidth(100);
column8.setVisible(true);

GridColumn column9 = new GridColumn(grid,SWT.None);
column9.setWidth(100);
column9.setText("CR_type");
column9.setVisible(true);

GridColumn column10 = new GridColumn(grid,SWT.None);
column10.setWidth(100);
column10.setText("Severity");
column10.setVisible(true);

GridColumn column11 = new GridColumn(grid,SWT.None);
column11.setWidth(100);
column11.setText("DocID");
column11.setVisible(true);

GridColumn column12 = new GridColumn(grid,SWT.None);
column12.setWidth(100);
column12.setText("ReqID");
column12.setVisible(true);


GridColumn column13 = new GridColumn(grid,SWT.None);
column13.setWidth(100);
column13.setText("Customer Relevance");
column13.setVisible(true);

GridItem gridItem;
gridItem = new GridItem ( grid, SWT.NONE );


for(CR c :crs)
{
if(c.getType().equals("Change Request"))
{
gridItem = new GridItem ( grid, SWT.NONE );


try{
gridItem.setText(c.getCRID());
}catch(Exception e )
{
gridItem.setText("");
}
try{
gridItem.setText(1,c.getProject());
}catch(Exception e )
{
gridItem.setText(1,"");
}
try{
gridItem.setText(2,c.getSummary());
}catch(Exception e )
{
gridItem.setText(2,"");
}
try{
gridItem.setText(3,c.getCreationDate().toString()); //c.getCreationDate().toString()
}catch(Exception e )
{
gridItem.setText(3,"");
}
try{
gridItem.setText(4,c.getType());

}catch(Exception e )
{
gridItem.setText(4,"");
}

gridItem.setImage(ResourceManager.getPluginImage("com.amenity.workbench", "icons/workbench/general/query.png"));
try{
gridItem.setText(5,c.getState());
}catch(Exception e )
{
gridItem.setText(5,"");
}
try{
gridItem.setText(6,c.getAssignedUser());
}catch(Exception e )
{
gridItem.setText(6,"");
}
try{
gridItem.setText(7,c.getRelease().toString());
}catch(Exception e )
{
gridItem.setText(7,"");
}

try{
gridItem.setText(8,c.getCR_Type());
}catch(Exception e )
{
gridItem.setText(8,"");
}
try{
gridItem.setText(9,c.getSeverity());
}catch(Exception e )
{
gridItem.setText(9,"");
}
try{
gridItem.setText(10,c.getDocID());
}catch(Exception e )
{
gridItem.setText(10,"");
}
try{
gridItem.setText(11,c.getReqID());
}catch(Exception e )
{
gridItem.setText(11,"");
}
try{
gridItem.setText(12,c.getCustomerRelevant());
}catch(Exception e )
{
gridItem.setText(12,"");

}

Now I want to do sorting for these grid items by clicking on the header of the column. I have tried several methods like column.setSort(SWT.UP) but it didn't work.

Anyone knows how can I implement the sorting please ?


Thank You
Re: Sorting Nebula Grid Widget [message #903384 is a reply to message #903336] Thu, 23 August 2012 08:54 Go to previous messageGo to next message
Sharon Snyder is currently offline Sharon Snyder
Messages: 56
Registered: September 2010
Member

You need to set a comparator:
grid.setComparator(SomeClassYouCreated);

where "SomeClassYouCreated" extends ViewerComparator and knows how to compare the records.

column.setSort(SWT.UP/DOWN) sets the chevron.....it doesn't actually do a sort for you....your comparator class needs to do that.

Back in May I posted more details in this forum on what I did. I believe the link to the topic is: http://www.eclipse.org/forums/index.php/t/187183/

-Sharon
Re: Sorting Nebula Grid Widget [message #903387 is a reply to message #903384] Thu, 23 August 2012 09:01 Go to previous messageGo to next message
zainab alhaidary is currently offline zainab alhaidary
Messages: 20
Registered: April 2012
Junior Member
Thank You for you replay Sharon. I'm trying to implement it but there is no setComparator() method in Nebula grid. what do you suggest?


Kind Regards
Re: Sorting Nebula Grid Widget [message #903389 is a reply to message #903387] Thu, 23 August 2012 09:08 Go to previous message
Sharon Snyder is currently offline Sharon Snyder
Messages: 56
Registered: September 2010
Member

Ok, I'm using a viewer - which does have that method. Is there a reason why you are not using a viewer and setting your input values that way? You should be able to filter the data that gets displayed easily enough.

I have found that using viewers is much easier in the long run, and makes for a better separation of the data model from the viewer.

I guess your other choice would be to roll your own - and actually move the data around when you're setting the column sort direction.....I strongly recommend you change to using a viewer.

-Sharon
Previous Topic:CollapsibleButtons- Dont see buttons
Next Topic:VerifyListener
Goto Forum:
  


Current Time: Thu Apr 24 11:28:38 EDT 2014

Powered by FUDForum. Page generated in 0.02881 seconds