}
@Override
public void perform( IProgressMonitor monitor ) {
Layer target = (Layer) getDestination();
Collection<Layer> layers = toCollection(getData());
for( Layer layer : layers ) {
ViewerDropLocation location = getViewerLocation();
if (location == ViewerDropLocation.NONE) {
layer.setZorder(0);
continue;
}
if (Math.abs(layer.getZorder() - target.getZorder()) == 1) {
int tmp = layer.getZorder();
layer.setZorder(target.getZorder());
target.setZorder(tmp);
continue;
}
// Moving something AFTER a layer is the same as moving something BEFORE a layer.
// So we will use BEFORE as much as possible to prevent duplication here.
// This code will retrieve the layer before. Or the first one, if we are at the
// beginning of the list.
if (location == ViewerDropLocation.BEFORE) {
int i = target.getZorder();
if (layer.getZorder() > target.getZorder()) {
i++;
}
if (i > layer.getMap().getMapLayers().size()) {
layer.setZorder(layer.getMap().getMapLayers().size());
continue;
}
if (layer.equals(target)) {
continue;
}
layer.setZorder(i);
} else if (location == ViewerDropLocation.ON) {
int i = target.getZorder();
// if( layer.getZorder()>target.getZorder()){
// i--;
// }
if (layer.equals(target)) {
continue;
}
layer.setZorder(i);
} else {
int i = target.getZorder();
if (layer.getZorder() < target.getZorder()) {
i--;
}
if (i < 0)
i = 0;
layer.setZorder(i);