Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Migrate ILayerCell from underlying layer to top-level
Migrate ILayerCell from underlying layer to top-level [message #1258189] Thu, 27 February 2014 06:24 Go to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
Hey!

I'm trying to fire an EditCellCommand using the ILayerCell i can get by calling SelectionLayer.getCellByPosition(selLayer.getSelectionAnchor()....). The cell is bound to the selection layer, and when i fire the edit command, the editor will open up in the wrong place Sad We're using a custom cell editor implementation, so maybe there is something wrong too. When i manually add the offsets for column header and row header (+1 on positions), then the editor opens up in the correct cell. However +1 is not sooo future proof Wink

I saw that LayerUtil.convert* would do what i need but require a IUniqueIndexLayer, which the top level grid layer is not... Sad

the only idea i currently have is adding the column header row count to the row position and the row header column count to the column position. but this is also not bullet proof in case there is more transformation on top of the selection layer, or for some reason, the cell is not from the selection layer but an underlying one.

Any Ideas? Thanks!
Re: Migrate ILayerCell from underlying layer to top-level [message #1258197 is a reply to message #1258189] Thu, 27 February 2014 06:34 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
i double checked that passing a cell from a layer different than the grid layer will cause ICellEditor.calculateControlBounds(Rectangle bounds) to receive bounds that are not correct (off by the size of the other composite parts of the grid layer).
Re: Migrate ILayerCell from underlying layer to top-level [message #1258237 is a reply to message #1258197] Thu, 27 February 2014 07:33 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
uh oh - just found out that if viewport scrolling comes into play, things get way worse. editors are then offset to a completely off location...
Re: Migrate ILayerCell from underlying layer to top-level [message #1258271 is a reply to message #1258237] Thu, 27 February 2014 08:17 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
How about you are telling me for what use case you are trying to fire the command programmatically and show me the code how you try to execute it? I'm not able to tell you what's wrong with your explanations.
Re: Migrate ILayerCell from underlying layer to top-level [message #1258273 is a reply to message #1258271] Thu, 27 February 2014 08:20 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Oh, and if you want to edit a cell that is currently selected, why don't you use the EditSelectionCommand?
Re: Migrate ILayerCell from underlying layer to top-level [message #1258285 is a reply to message #1258271] Thu, 27 February 2014 08:32 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
We have a whole bunch of "old" editor framework that we are wrapping using a custom ICellEditor implementation. Basically it just creates a composite with some arbitrary editor controls on it. Bounds of the editor are calculated using the method i posted above. Now there is (use case one) a UI test framework which tries to programmatically open an editor for a cell. The test framework only has data layer indexes in hand, so what we do there is this:

@Override
    public BaseControl getAndCreateTableCellEditor(int rowIndex, int columnIndex) {
        DataLayer dataLayer = getLayer().getBodyLayer().getDataLayer();
        ILayerCell cell = dataLayer.getCellByPosition(columnIndex, rowIndex);
        if (cell == null) {
            throw new RuntimeException("No cell available at row=" + rowIndex + " column="
                    + columnIndex);
        }

        // skip re-sizing during programmatic editing
        NatTableCellEditor cellEditor = (NatTableCellEditor) natTable.getConfigRegistry()
                .getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT);
        try {
            cellEditor.setAutoResizeCell(false);
            natTable.doCommand(new EditCellCommand(natTable, natTable.getConfigRegistry(), cell));
        } finally {
            cellEditor.setAutoResizeCell(true);
        }

        // check if we could create an editor
        NatTableCellEditor activeEditor = (NatTableCellEditor) natTable.getActiveEditor();
        if (activeEditor == null) {
            throw new CellNotEditableException(rowIndex, columnIndex);
        }
        return editor;
    }


Firing this EditCellCommand with the cell from the data layer will somehow skip the offsetting required to take header layers into account (row and column headers), thus the editor will be opened a little too high, and a little too far on the left. I confirmed that the coordinates that are passed to calculacteBounds (by nattable itself) are off by that amount.

BTW, i solved the viewport issue, by always converting to selection layer positions, so only the cell/editor offset issue remains.
Re: Migrate ILayerCell from underlying layer to top-level [message #1258310 is a reply to message #1258285] Thu, 27 February 2014 08:57 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
The cell coordinates in NatTable are all using offsets. So if you are getting cell 1,1 of the body data layer, it will be 2,2 in a grid, because there is one row in the column header and one column in the row header. Using the method above, your code will never work in a grid composition.

Maybe this kind of code helps:
natTable.doCommand(new SelectCellCommand(getLayer().getBodyLayer().getSelectionLayer(), columnIndex, rowIndex, false, false));
natTable.doCommand(new EditSelectionCommand(natTable, natTable.getConfigRegistry()));
Re: Migrate ILayerCell from underlying layer to top-level [message #1258314 is a reply to message #1258310] Thu, 27 February 2014 09:00 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
Ah, thanks, this one is interesting - i will check whether that would be an alternative. There is no other way to get the correct positions? I currently manually add row/column counts of the header layers... Neutral
Re: Migrate ILayerCell from underlying layer to top-level [message #1258344 is a reply to message #1258314] Thu, 27 February 2014 09:33 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You can try to use the LayerUtil or try to execute localToUnderlyingXxx methods. That's what happens internally if a command is transported down the layer stack. It depends on what you are trying to do. Do you want to test a black box or do you want to create custom tests where you need to know internals? It looks like you want to test internals, so it more looks like a white box test. For what reason I'm not sure. If you want to test that a selection is performed on NatTable and then the editing is enabled, my snippet should be matching. But feel free to hurt your brain with NatTable internals Wink

You can have a look on how we are testing in NatTable (EditIntegrationTest) or you can try to read the article on testing applications with NatTable using SWTBot http://eclipse.org/nattable/documentation.php?page=articles
Re: Migrate ILayerCell from underlying layer to top-level [message #1258367 is a reply to message #1258344] Thu, 27 February 2014 10:03 Go to previous message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
Oh, no, actually we're doing UI tests to verify the logical functionality (and completeness) of the application. The table is "only" another widget that needs to be driven by the tests. This is done programmatically by running a small server inside the application that can control widgets. This server is sent commands like where to edit or fill out data, and then executes this more or less like the user would. (we're not using SWTBot for that Smile)

[Updated on: Thu, 27 February 2014 10:03]

Report message to a moderator

Previous Topic:Filter Row Search Icon
Next Topic:Registering an ImagePainter for a certain cell
Goto Forum:
  


Current Time: Fri Apr 19 16:46:41 GMT 2024

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

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

Back to the top