Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » delete row
delete row [message #1007517] Wed, 06 February 2013 10:07 Go to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 191
Registered: July 2009
Senior Member
Hi,

I want to delete a selected row in the table.
The selected row position is available from the selection layer.
bodyLayer.getSelectionLayer().getSelectedRowPositions()

My underlying data model is based on emf.

What is the best way to delete the row?
I am able to delete the object in the emf based model by the selected row index. But then I need to
redraw the natTable. And the redraw does not work well. Some times it redraws and some times all
table entries are invisible.

Is there a way to delete a row which better fits into the natTable concept?


Any hints are appreciated, Martin
Re: delete row [message #1007527 is a reply to message #1007517] Wed, 06 February 2013 10:33 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

I have to admit that getting familiar with EMF based data models for NatTable is still on my ToDo list.

I implemented a delete row functionality in a customer project. But there I used GlazedLists and the GlazedListsEventLayer, so removing an item from the eventList did the trick.
So far I created a DeleteRowCommand and the corresponding DeleteRowCommandHandler which I registered for the GridLayer. Determining the rows to delete I did similar to your approach.
Now the question is, why is the redraw behaving the way you describe it. And how do you redraw the NatTable? Do you call redraw()? Well this is not the way it would work. You will need to either fire a RowStructuralRefreshEvent (look at the GlazedListsEventLayer for an example) or call NatTable.refresh() which does a complete refresh.

You need to know that events in NatTable are fired the layer stack upwards. This means, if you would like to fire a RowStructuralRefreshEvent on deleting a row, you should think about registering the command handler to the data layer , so every other layer gets informed about the deleted row.

Hope that helps,
Dirk
Re: delete row [message #1007553 is a reply to message #1007517] Wed, 06 February 2013 12:44 Go to previous messageGo to next message
Thomas  Mäder is currently offline Thomas MäderFriend
Messages: 46
Registered: July 2009
Member
I would think that you are not sending the proper events up the layer stack (as Dirk F mentioned). Be aware that there seems to be a bug with deleted rows when you try to do precise notification, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=383056
Re: delete row [message #1007555 is a reply to message #1007527] Wed, 06 February 2013 12:55 Go to previous message
Martin Jacob is currently offline Martin JacobFriend
Messages: 191
Registered: July 2009
Senior Member
Hi Dirk,

the problem is solved in the following way:

1.) Delete the model objects in the EMF model.
2.) Listen to the EMF command stack and refresh the table

the code is:

1.)
btnDeleteRow.addSelectionListener(new SelectionListener() {

@Override
public void widgetSelected(SelectionEvent e) {
if (null != natTable && null != bodyLayer) {
System.out.println(this.getClass().toString() + ": widgetSelected");
BodyDataProvider lBdp = (BodyDataProvider) bodyLayer.getBodyDataLayer().getDataProvider();
CompoundCommand lCmd = new CompoundCommand();
for (Range lRange : bodyLayer.getSelectionLayer().getSelectedRowPositions()) {
for(int r = lRange.start; r < lRange.end; r++)
{
LineChart lLc = lBdp.getLineChart(r);
lCmd.append(DeleteCommand.create(editingDomain, lLc));
}
}
editingDomain.getCommandStack().execute(lCmd);

}
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub

}
});




2.)
protected void createCommandStackListener() {
addCommandStackListener(new CommandStackListener() {

@Override
public void commandStackChanged(EventObject event) {
if (null != natTable && natTable.isVisible()) {
System.out.println(this.getClass().toString() + ": commandStackChanged() " + event.getSource());
natTable.doCommand(new VisualRefreshCommand());
}
}
});
}

thanks, Martin

schrieb Dirk Fauth, Am 06.02.2013 11:33:
> Hi,
>
> I have to admit that getting familiar with EMF based data models for NatTable is still on my ToDo list.
>
> I implemented a delete row functionality in a customer project. But there I used GlazedLists and the
> GlazedListsEventLayer, so removing an item from the eventList did the trick.
> So far I created a DeleteRowCommand and the corresponding DeleteRowCommandHandler which I registered
> for the GridLayer. Determining the rows to delete I did similar to your approach.
> Now the question is, why is the redraw behaving the way you describe it. And how do you redraw the
> NatTable? Do you call redraw()? Well this is not the way it would work. You will need to either fire
> a RowStructuralRefreshEvent (look at the GlazedListsEventLayer for an example) or call
> NatTable.refresh() which does a complete refresh.
>
> You need to know that events in NatTable are fired the layer stack upwards. This means, if you would
> like to fire a RowStructuralRefreshEvent on deleting a row, you should think about registering the
> command handler to the data layer , so every other layer gets informed about the deleted row.
>
> Hope that helps,
> Dirk
Previous Topic:Version 1.0.0 release date?
Next Topic:EclipseCon?
Goto Forum:
  


Current Time: Tue Mar 19 09:11:32 GMT 2024

Powered by FUDForum. Page generated in 0.03773 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top