private static int[] getCellsToGroup(CaptionSelection selection) {
    ArrayList<Integer> cells = new ArrayList<>();
    int[] selectedIndices = selection.getSelection();
    for(int i: selectedIndices) {
      if (!selection.getContainer().getGridLayoutManager().isGapCell(selection.getContainer(), selection.isRow(), i)) {
        cells.add(i);
      }
    }
    int[] result = new int[cells.size()];
    for(int i=0; i<cells.size(); i++) {
      result [i] = cells.get(i).intValue();
    }
    return result;
  }
private static int[] getCellsToGroup(CaptionSelection selection)