Bug 477957 - NPE in CellEdgeDetectUtil.getVertiCalCellEdge()

Change-Id: I80a46fd6cd37d1f08f6b1f0c2fdbc51e3cbd0bc9
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/ui/util/CellEdgeDetectUtil.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/ui/util/CellEdgeDetectUtil.java
index 8325869..dcdb0b8 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/ui/util/CellEdgeDetectUtil.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/ui/util/CellEdgeDetectUtil.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2013 Original authors and others.
+ * Copyright (c) 2012, 2013, 2015 Original authors and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -32,8 +32,7 @@
     public static int getColumnPositionToResize(ILayer layer, Point clickPoint) {
         int columnPosition = layer.getColumnPositionByX(clickPoint.x);
         if (columnPosition >= 0) {
-            switch (getHorizontalCellEdge(layer, clickPoint,
-                    DEFAULT_RESIZE_HANDLE_SIZE)) {
+            switch (getHorizontalCellEdge(layer, clickPoint, DEFAULT_RESIZE_HANDLE_SIZE)) {
                 case LEFT:
                     if (columnPosition == 1) {
                         // can't resize left edge of first column
@@ -55,8 +54,7 @@
     public static int getRowPositionToResize(ILayer layer, Point clickPt) {
         int rowPosition = layer.getRowPositionByY(clickPt.y);
         if (rowPosition >= 0) {
-            switch (getVerticalCellEdge(layer, clickPt,
-                    DEFAULT_RESIZE_HANDLE_SIZE)) {
+            switch (getVerticalCellEdge(layer, clickPt, DEFAULT_RESIZE_HANDLE_SIZE)) {
                 case TOP:
                     if (rowPosition == 1) {
                         // can't resize top edge of first row
@@ -79,8 +77,7 @@
      * @param clickPt
      *            usually the coordinates of a mouse click
      */
-    public static CellEdgeEnum getHorizontalCellEdge(Rectangle cellBounds,
-            Point clickPt) {
+    public static CellEdgeEnum getHorizontalCellEdge(Rectangle cellBounds, Point clickPt) {
         return getHorizontalCellEdge(cellBounds, clickPt, -1);
     }
 
@@ -88,8 +85,7 @@
         return getHorizontalCellEdge(layer, clickPt, -1);
     }
 
-    public static CellEdgeEnum getHorizontalCellEdge(ILayer layer,
-            Point clickPt, int handleWidth) {
+    public static CellEdgeEnum getHorizontalCellEdge(ILayer layer, Point clickPt, int handleWidth) {
         ILayerCell cell = layer.getCellByPosition(
                 layer.getColumnPositionByX(clickPt.x),
                 layer.getRowPositionByY(clickPt.y));
@@ -111,16 +107,20 @@
      *            distance from the edge to qualify as <i>close</i> to the cell
      *            edge
      */
-    public static CellEdgeEnum getHorizontalCellEdge(Rectangle cellBounds,
-            Point clickPt, int distanceFromEdge) {
+    public static CellEdgeEnum getHorizontalCellEdge(Rectangle cellBounds, Point clickPt, int distanceFromEdge) {
         if (distanceFromEdge < 0) {
             distanceFromEdge = cellBounds.width / 2;
         }
 
-        Rectangle left = new Rectangle(cellBounds.x, cellBounds.y,
-                distanceFromEdge, cellBounds.height);
-        Rectangle right = new Rectangle(cellBounds.x + cellBounds.width
-                - distanceFromEdge, cellBounds.y, distanceFromEdge,
+        Rectangle left = new Rectangle(
+                cellBounds.x,
+                cellBounds.y,
+                distanceFromEdge,
+                cellBounds.height);
+        Rectangle right = new Rectangle(
+                cellBounds.x + cellBounds.width - distanceFromEdge,
+                cellBounds.y,
+                distanceFromEdge,
                 cellBounds.height);
 
         if (left.contains(clickPt)) {
@@ -141,8 +141,7 @@
      * @param clickPt
      *            usually the coordinates of a mouse click
      */
-    public static CellEdgeEnum getVerticalCellEdge(Rectangle cellBounds,
-            Point clickPt) {
+    public static CellEdgeEnum getVerticalCellEdge(Rectangle cellBounds, Point clickPt) {
         return getVerticalCellEdge(cellBounds, clickPt, -1);
     }
 
@@ -150,27 +149,35 @@
         return getVerticalCellEdge(layer, clickPt, -1);
     }
 
-    public static CellEdgeEnum getVerticalCellEdge(ILayer layer, Point clickPt,
-            int handleHeight) {
+    public static CellEdgeEnum getVerticalCellEdge(ILayer layer, Point clickPt, int handleHeight) {
         ILayerCell cell = layer.getCellByPosition(
                 layer.getColumnPositionByX(clickPt.x),
                 layer.getRowPositionByY(clickPt.y));
-        return getVerticalCellEdge(cell.getBounds(), clickPt, handleHeight);
+
+        if (cell != null) {
+            return getVerticalCellEdge(cell.getBounds(), clickPt, handleHeight);
+        } else {
+            return CellEdgeEnum.NONE;
+        }
     }
 
     /**
      * @see CellEdgeDetectUtil#getHorizontalCellEdge(Rectangle, Point, int)
      */
-    private static CellEdgeEnum getVerticalCellEdge(Rectangle cellBounds,
-            Point clickPt, int distanceFromEdge) {
+    private static CellEdgeEnum getVerticalCellEdge(Rectangle cellBounds, Point clickPt, int distanceFromEdge) {
         if (distanceFromEdge < 0) {
             distanceFromEdge = cellBounds.height / 2;
         }
 
-        Rectangle top = new Rectangle(cellBounds.x, cellBounds.y,
-                cellBounds.width, distanceFromEdge);
-        Rectangle bottom = new Rectangle(cellBounds.x, cellBounds.y
-                + cellBounds.height - distanceFromEdge, cellBounds.width,
+        Rectangle top = new Rectangle(
+                cellBounds.x,
+                cellBounds.y,
+                cellBounds.width,
+                distanceFromEdge);
+        Rectangle bottom = new Rectangle(
+                cellBounds.x,
+                cellBounds.y + cellBounds.height - distanceFromEdge,
+                cellBounds.width,
                 distanceFromEdge);
 
         if (top.contains(clickPt)) {