aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpaturzo2014-03-25 05:41:37 (EDT)
committermpaturzo2014-03-25 05:43:59 (EDT)
commit34512d5e3c99a5053d37e770faa0caef87dbeaa2 (patch)
tree34eaec1fdc5b1f4588b7797a2217ca8b3931af97
parent1f0e6e5bc912227c764b5c42b0e9900f69a09f30 (diff)
downloadorg.eclipse.nebula-34512d5e3c99a5053d37e770faa0caef87dbeaa2.zip
org.eclipse.nebula-34512d5e3c99a5053d37e770faa0caef87dbeaa2.tar.gz
org.eclipse.nebula-34512d5e3c99a5053d37e770faa0caef87dbeaa2.tar.bz2
Bug 421248 - Grid throws "Widget Disposed" when key-navigating afterrefs/changes/45/23845/2
removing an item while I was testing, I found other problems as nullpointer, indexoutofbound, illegal arguments and others. I've updated a snippet (GridViewerSnippetDisposePerformance) to perform some tests. Change-Id: I837ba25170e571c1bd209520863c36dda97ce505 Signed-off-by: mpaturzo <caosmpz@yahoo.it>
-rw-r--r--examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetDisposePerformance.java24
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/Grid.java15
2 files changed, 33 insertions, 6 deletions
diff --git a/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetDisposePerformance.java b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetDisposePerformance.java
index d8334ec..adf8610 100644
--- a/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetDisposePerformance.java
+++ b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetDisposePerformance.java
@@ -35,6 +35,7 @@ import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
+import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.nebula.widgets.grid.GridUtils;
@@ -44,6 +45,7 @@ import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
@@ -327,6 +329,28 @@ public class GridViewerSnippetDisposePerformance
shell.layout();
}
});
+ final Button manualDeselect = new Button(buttons, SWT.NONE);
+ manualDeselect.setText("Manual Deselect");
+ manualDeselect.addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mouseDown(MouseEvent e)
+ {
+ Grid grid = v.getGrid();
+ Point focus = grid.getFocusCell();
+ int[] selected = grid.getSelectionIndices();
+ grid.deselect(selected);
+ grid.remove(selected);
+ while (focus.y >= grid.getItemCount())
+ --focus.y;
+ if (focus.y >= 0)
+ {
+ grid.setFocusItem(grid.getItem(focus.y));
+ grid.setFocusColumn(grid.getColumn(focus.x));
+ grid.setCellSelection(focus);
+ }
+ }
+ });
final Button addColumn = new Button(buttons, SWT.NONE);
addColumn.setText("add column");
addColumn.addMouseListener(new MouseAdapter()
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/Grid.java b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/Grid.java
index 23c576d..21622bd 100644
--- a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/Grid.java
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/Grid.java
@@ -2059,7 +2059,7 @@ public class Grid extends Canvas {
}
else {
index = items.indexOf(item);
- if (index == 0) {
+ if (index <= 0) {
return null;
}
}
@@ -6782,13 +6782,16 @@ public class Grid extends Canvas {
//These two variables are used because the key navigation when the shift key is down is
//based, not off the focus item/column, but rather off the implied focus (i.e. where the
//keyboard has extended focus to).
- GridItem impliedFocusItem = focusItem;
- GridColumn impliedFocusColumn = focusColumn;
+ GridItem impliedFocusItem = (focusItem == null || focusItem.isDisposed()) ? null : focusItem;
+ GridColumn impliedFocusColumn = focusColumn.isDisposed() ? null : focusColumn;
if (cellSelectionEnabled && e.stateMask == SWT.MOD2) {
if (shiftSelectionAnchorColumn != null) {
- impliedFocusItem = shiftSelectionAnchorItem;
- impliedFocusColumn = shiftSelectionAnchorColumn;
+ if (shiftSelectionAnchorItem == null || shiftSelectionAnchorItem.isDisposed())
+ impliedFocusItem = focusItem;
+ else
+ impliedFocusItem = shiftSelectionAnchorItem;
+ impliedFocusColumn = shiftSelectionAnchorColumn.isDisposed() ? null : shiftSelectionAnchorColumn;
}
}
@@ -6885,7 +6888,7 @@ public class Grid extends Canvas {
}
if (impliedFocusColumn != null) {
- if (newSelection != null) {
+ if (newSelection != null && intendedFocusColumn != null) {
newColumnFocus = getVisibleColumn_DegradeLeft(newSelection, intendedFocusColumn);
}
else {