private void moveLayer( int delta ) {
Layer selectedMapLayer = mapLayerTableViewer.getSelectedMapLayer();
if (selectedMapLayer == null)
return;
List<Layer> layersList = mapLayerTableViewer.getLayersList();
MapContent mapContent = pane.getMapContent();
int contextIndex = mapContent.layers().indexOf(selectedMapLayer);
int viewerIndex = layersList.indexOf(selectedMapLayer);
int newViewerIndex = viewerIndex + delta;
if (newViewerIndex < 0 || newViewerIndex > layersList.size() - 1) {
return;
}
/*
* MapLayerTable stores layers in the reverse order to
* DefaultMapContext (see comment in javadocs for this class)
*/
int newContextIndex = contextIndex - delta;
if (newContextIndex < 0 || newContextIndex > mapContent.layers().size() - 1) {
return;
}
if (contextIndex != newContextIndex) {
mapContent.moveLayer(contextIndex, newContextIndex);
pane.redraw();
Collections.swap(layersList, viewerIndex, newViewerIndex);
mapLayerTableViewer.refresh();
}