|
|
|
Re: delete row [message #1007555 is a reply to message #1007527] |
Wed, 06 February 2013 12:55 |
Martin Jacob 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
|
|
|
Powered by
FUDForum. Page generated in 0.03773 seconds