aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpaturzo2014-01-27 03:25:12 (EST)
committerWim Jongman2014-02-05 13:28:24 (EST)
commit5f2bf6680da3bdf93cee8349c1d0bee54bded3cd (patch)
treea88c6800638fa23f61ed902ee28ea1b735ab60c9
parentf157196ec093fffe5e789189ed9450947b1c8d8b (diff)
downloadorg.eclipse.nebula-5f2bf6680da3bdf93cee8349c1d0bee54bded3cd.zip
org.eclipse.nebula-5f2bf6680da3bdf93cee8349c1d0bee54bded3cd.tar.gz
org.eclipse.nebula-5f2bf6680da3bdf93cee8349c1d0bee54bded3cd.tar.bz2
Bug 419928 - GridTableViewer and Grid performance improvementrefs/changes/24/21324/5
There is no more collection within the GridItem , this greatly improves the creation and management of data. Everything is based on DataVisualizer . This is a centralized component that is allowed to set and get information such as: what is my fonts? what is my background? what is my text ? I implemented three types of DataVisualizer : 1 ) ColumnRowBigDataVisualizer . This simply saves the data from column / row in Map < Integer , List Of T > 2 ) RowColumnBigDataVisualizer , as above, but save rows / columns 3 ) the real news, the AdaptedDataVisualizer that works as a LabelProvider . Thanks to AdaptedDataVisualizer Shot down the memory usage I fixed some bugs for memory leaks and improve performance of Grid OnPaint method .. A change that I could not give to you is the removal of the IsVisible method and the reimplementation of all the calculations of the first index to be seen, the performance increase greatly. Change-Id: Iff715098d98f865f5b22a82cf8f11a7690426e08 Signed-off-by: mpaturzo <caosmpz@yahoo.it>
-rw-r--r--examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithAdaptedDataVisualizer.java272
-rw-r--r--examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithColumnRowBigDataVisualizer.java234
-rw-r--r--examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithRowColumnBigDataVisualizer.java234
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/.classpath2
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/.settings/org.eclipse.jdt.core.prefs11
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/META-INF/MANIFEST.MF2
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/jface/gridviewer/GridTableViewer.java91
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/AdaptedDataVisualizer.java328
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/ColumnRowBigDataVisualizer.java358
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/DataVisualizer.java246
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/Grid.java203
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridItem.java277
-rw-r--r--widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/RowColumnBigDataVisualizer.java101
13 files changed, 2107 insertions, 252 deletions
diff --git a/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithAdaptedDataVisualizer.java b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithAdaptedDataVisualizer.java
new file mode 100644
index 0000000..28d5371
--- /dev/null
+++ b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithAdaptedDataVisualizer.java
@@ -0,0 +1,272 @@
+package org.eclipse.nebula.snippets.grid.viewer;
+
+/*******************************************************************************
+ * Copyright (c) 2006 Tom Schindl 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl - initial API and implementation
+ *******************************************************************************/
+
+
+import org.eclipse.jface.resource.FontRegistry;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnViewerEditor;
+import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+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.AdaptedDataVisualizer;
+import org.eclipse.nebula.widgets.grid.GridColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Example usage of none mandatory interfaces of ITableFontProvider and
+ * ITableColorProvider
+ *
+ * @author Tom Schindl <tom.schindl@bestsolution.at>
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ * Example with {@link AdaptedDataVisualizer}
+ */
+public class GridViewerSnippetWithAdaptedDataVisualizer {
+
+ private static final int NUM_COLUMNS = 1000;
+ private static final int NUM_MODELS = 1000;
+
+ private class MyContentProvider implements IStructuredContentProvider {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements(Object inputElement) {
+ return (MyModel[]) inputElement;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose() {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
+ * java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ }
+
+ public static boolean flag = true;
+
+ public class MyModel {
+ public int counter;
+
+ public MyModel(int counter) {
+ this.counter = counter;
+ }
+
+ @Override
+ public String toString() {
+ return "Item " + this.counter;
+ }
+ }
+
+ public class MyLabelProvider extends LabelProvider implements
+ ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ FontRegistry registry = new FontRegistry();
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ return "Column " + columnIndex + " => " + element.toString();
+ }
+
+ public Font getFont(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 0) {
+ return registry.getBold(Display.getCurrent().getSystemFont()
+ .getFontData()[0].getName());
+ }
+ return null;
+ }
+
+ public Color getBackground(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 0) {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+ }
+ return null;
+ }
+
+ public Color getForeground(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 1) {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+ }
+ return null;
+ }
+
+ }
+
+ /**
+ * Below myown AdaptedDataVisualizer
+ * @author Mirko Paturzo
+ *
+ */
+ private static class MyOwnDataVisualizer extends AdaptedDataVisualizer {
+ FontRegistry registry = new FontRegistry();
+
+ private final MyModel models[];
+
+ public MyOwnDataVisualizer(MyModel models[]) {
+ this.models = models;
+ }
+
+ @Override
+ public Image getImage(int row, int columnIndex) {
+ return null;
+ }
+
+ @Override
+ public String getText(int row, int columnIndex) {
+ return "Column " + columnIndex + " => " + models[row].toString();
+ }
+
+ @Override
+ public Font getFont(int row, int columnIndex) {
+ if ((models[row]).counter % 2 == 0) {
+ return registry.getBold(Display.getCurrent().getSystemFont()
+ .getFontData()[0].getName());
+ }
+ return null;
+ }
+
+ @Override
+ public Color getBackground(int row, int columnIndex) {
+ if ((models[row]).counter % 2 == 0) {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+ }
+ return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
+ }
+
+ @Override
+ public Color getForeground(int row, int columnIndex) {
+ if ((models[row]).counter % 2 == 1) {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+ }
+ return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
+ }
+ }
+
+ public GridViewerSnippetWithAdaptedDataVisualizer(Shell shell) {
+ MyModel[] models = createModel();
+ final GridTableViewer v = new GridTableViewer(new MyOwnDataVisualizer(models), shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ v.setLabelProvider(new MyLabelProvider());
+ v.setContentProvider(new MyContentProvider());
+ v.getGrid().setCellSelectionEnabled(true);
+
+ v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getGrid()), new TextCellEditor(v.getGrid()) });
+ v.setCellModifier(new ICellModifier() {
+
+ public boolean canModify(Object element, String property) {
+ return true;
+ }
+
+ public Object getValue(Object element, String property) {
+ return "Column " + property + " => " + element.toString();
+ }
+
+ public void modify(Object element, String property, Object value) {
+
+ }
+
+ });
+
+ v.setColumnProperties(new String[] {"1","2"});
+
+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
+ @Override
+ protected boolean isEditorActivationEvent(
+ ColumnViewerEditorActivationEvent event) {
+ return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
+ || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
+ || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
+ }
+ };
+
+ GridViewerEditor.create(v, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
+ | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
+ | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
+
+ for(int i = 0; i < NUM_COLUMNS; i++) {
+ createColumn(v, "Column " + i);
+ }
+
+ v.setInput(models);
+ v.getGrid().setLinesVisible(true);
+ v.getGrid().setHeaderVisible(true);
+ }
+
+ private void createColumn(final GridTableViewer v, String name) {
+ GridColumn column = new GridColumn(v.getGrid(), SWT.NONE);
+ column.setWidth(200);
+ column.setText(name);
+ }
+
+ private MyModel[] createModel() {
+ MyModel[] elements = new MyModel[NUM_MODELS];
+
+ for (int i = 0; i < NUM_MODELS; i++) {
+ elements[i] = new MyModel(i);
+ }
+
+ return elements;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Display display = new Display();
+
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ new GridViewerSnippetWithAdaptedDataVisualizer(shell);
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+
+ display.dispose();
+
+ }
+
+}
diff --git a/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithColumnRowBigDataVisualizer.java b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithColumnRowBigDataVisualizer.java
new file mode 100644
index 0000000..33ced32
--- /dev/null
+++ b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithColumnRowBigDataVisualizer.java
@@ -0,0 +1,234 @@
+package org.eclipse.nebula.snippets.grid.viewer;
+
+/*******************************************************************************
+ * Copyright (c) 2006 Tom Schindl 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl - initial API and implementation
+ *******************************************************************************/
+
+
+import org.eclipse.jface.resource.FontRegistry;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnViewerEditor;
+import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+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.GridColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Example usage of none mandatory interfaces of ITableFontProvider and
+ * ITableColorProvider
+ *
+ * @author Tom Schindl <tom.schindl@bestsolution.at>
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ * Original example, with something else (NUM_COLUMNS, NUM_MODELS)
+ * Using {@link ColumnRowBigDataVisualizer}
+ *
+ */
+public class GridViewerSnippetWithColumnRowBigDataVisualizer {
+
+ private static final int NUM_COLUMNS = 1000;
+ private static final int NUM_MODELS = 1000;
+
+ private class MyContentProvider implements IStructuredContentProvider {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+
+ public Object[] getElements(Object inputElement) {
+ return (MyModel[]) inputElement;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+
+ public void dispose() {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
+ * java.lang.Object, java.lang.Object)
+ */
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ }
+
+ public static boolean flag = true;
+
+ public class MyModel {
+ public int counter;
+
+ public MyModel(int counter) {
+ this.counter = counter;
+ }
+
+
+ public String toString() {
+ return "Item " + this.counter;
+ }
+ }
+
+ public class MyLabelProvider extends LabelProvider implements
+ ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ FontRegistry registry = new FontRegistry();
+
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+
+ public String getColumnText(Object element, int columnIndex) {
+ return "Column " + columnIndex + " => " + element.toString();
+ }
+
+
+ public Font getFont(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 0) {
+ return registry.getBold(Display.getCurrent().getSystemFont()
+ .getFontData()[0].getName());
+ }
+ return null;
+ }
+
+
+ public Color getBackground(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 0) {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+ }
+ return null;
+ }
+
+
+ public Color getForeground(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 1) {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+ }
+ return null;
+ }
+
+ }
+
+ public GridViewerSnippetWithColumnRowBigDataVisualizer(Shell shell) {
+ final GridTableViewer v = new GridTableViewer(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ v.setLabelProvider(new MyLabelProvider());
+ v.setContentProvider(new MyContentProvider());
+ v.getGrid().setCellSelectionEnabled(true);
+
+ v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getGrid()), new TextCellEditor(v.getGrid()) });
+ v.setCellModifier(new ICellModifier() {
+
+
+ public boolean canModify(Object element, String property) {
+ return true;
+ }
+
+
+ public Object getValue(Object element, String property) {
+ return "Column " + property + " => " + element.toString();
+ }
+
+
+ public void modify(Object element, String property, Object value) {
+
+ }
+
+ });
+
+ v.setColumnProperties(new String[] {"1","2"});
+
+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
+
+ protected boolean isEditorActivationEvent(
+ ColumnViewerEditorActivationEvent event) {
+ return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
+ || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
+ || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
+ }
+ };
+
+ GridViewerEditor.create(v, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
+ | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
+ | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
+
+ for(int i = 0; i < NUM_COLUMNS; i++) {
+ createColumn(v, "Column " + i);
+ }
+
+ MyModel[] model = createModel();
+ v.setInput(model);
+ v.getGrid().setLinesVisible(true);
+ v.getGrid().setHeaderVisible(true);
+ }
+
+ private void createColumn(final GridTableViewer v, String name) {
+ GridColumn column = new GridColumn(v.getGrid(), SWT.NONE);
+ column.setWidth(200);
+ column.setText(name);
+ }
+
+ private MyModel[] createModel() {
+ MyModel[] elements = new MyModel[NUM_MODELS];
+
+ for (int i = 0; i < NUM_MODELS; i++) {
+ elements[i] = new MyModel(i);
+ }
+
+ return elements;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Display display = new Display();
+
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ new GridViewerSnippetWithColumnRowBigDataVisualizer(shell);
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+
+ display.dispose();
+
+ }
+
+}
diff --git a/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithRowColumnBigDataVisualizer.java b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithRowColumnBigDataVisualizer.java
new file mode 100644
index 0000000..e6f6980
--- /dev/null
+++ b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetWithRowColumnBigDataVisualizer.java
@@ -0,0 +1,234 @@
+package org.eclipse.nebula.snippets.grid.viewer;
+
+/*******************************************************************************
+ * Copyright (c) 2006 Tom Schindl 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl - initial API and implementation
+ *******************************************************************************/
+
+
+import org.eclipse.jface.resource.FontRegistry;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnViewerEditor;
+import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+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.GridColumn;
+import org.eclipse.nebula.widgets.grid.RowColumnBigDataVisualizer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Example usage of none mandatory interfaces of ITableFontProvider and
+ * ITableColorProvider
+ *
+ * @author Tom Schindl <tom.schindl@bestsolution.at>
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ * Example with {@link RowColumnBigDataVisualizer}
+ *
+ */
+public class GridViewerSnippetWithRowColumnBigDataVisualizer {
+
+ private static final int NUM_COLUMNS = 1000;
+ private static final int NUM_MODELS = 1000;
+
+ private class MyContentProvider implements IStructuredContentProvider {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+
+ public Object[] getElements(Object inputElement) {
+ return (MyModel[]) inputElement;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+
+ public void dispose() {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
+ * java.lang.Object, java.lang.Object)
+ */
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ }
+
+ public static boolean flag = true;
+
+ public class MyModel {
+ public int counter;
+
+ public MyModel(int counter) {
+ this.counter = counter;
+ }
+
+
+ public String toString() {
+ return "Item " + this.counter;
+ }
+ }
+
+ public class MyLabelProvider extends LabelProvider implements
+ ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ FontRegistry registry = new FontRegistry();
+
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+
+ public String getColumnText(Object element, int columnIndex) {
+ return "Column " + columnIndex + " => " + element.toString();
+ }
+
+
+ public Font getFont(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 0) {
+ return registry.getBold(Display.getCurrent().getSystemFont()
+ .getFontData()[0].getName());
+ }
+ return null;
+ }
+
+
+ public Color getBackground(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 0) {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+ }
+ return null;
+ }
+
+
+ public Color getForeground(Object element, int columnIndex) {
+ if (((MyModel) element).counter % 2 == 1) {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+ }
+ return null;
+ }
+
+ }
+
+ public GridViewerSnippetWithRowColumnBigDataVisualizer(Shell shell) {
+ final GridTableViewer v = new GridTableViewer(new RowColumnBigDataVisualizer(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE), Display.getCurrent().getSystemColor(SWT.COLOR_BLACK), null), shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ v.setLabelProvider(new MyLabelProvider());
+ v.setContentProvider(new MyContentProvider());
+ v.getGrid().setCellSelectionEnabled(true);
+
+ v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getGrid()), new TextCellEditor(v.getGrid()) });
+ v.setCellModifier(new ICellModifier() {
+
+
+ public boolean canModify(Object element, String property) {
+ return true;
+ }
+
+
+ public Object getValue(Object element, String property) {
+ return "Column " + property + " => " + element.toString();
+ }
+
+
+ public void modify(Object element, String property, Object value) {
+
+ }
+
+ });
+
+ v.setColumnProperties(new String[] {"1","2"});
+
+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
+
+ protected boolean isEditorActivationEvent(
+ ColumnViewerEditorActivationEvent event) {
+ return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
+ || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
+ || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
+ }
+ };
+
+ GridViewerEditor.create(v, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
+ | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
+ | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
+
+ for(int i = 0; i < NUM_COLUMNS; i++) {
+ createColumn(v, "Column " + i);
+ }
+
+ MyModel[] model = createModel();
+ v.setInput(model);
+ v.getGrid().setLinesVisible(true);
+ v.getGrid().setHeaderVisible(true);
+ }
+
+ private void createColumn(final GridTableViewer v, String name) {
+ GridColumn column = new GridColumn(v.getGrid(), SWT.NONE);
+ column.setWidth(200);
+ column.setText(name);
+ }
+
+ private MyModel[] createModel() {
+ MyModel[] elements = new MyModel[NUM_MODELS];
+
+ for (int i = 0; i < NUM_MODELS; i++) {
+ elements[i] = new MyModel(i);
+ }
+
+ return elements;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Display display = new Display();
+
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ new GridViewerSnippetWithRowColumnBigDataVisualizer(shell);
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+
+ display.dispose();
+
+ }
+
+}
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/.classpath b/widgets/grid/org.eclipse.nebula.widgets.grid/.classpath
index ce73933..121e527 100644
--- a/widgets/grid/org.eclipse.nebula.widgets.grid/.classpath
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/.settings/org.eclipse.jdt.core.prefs b/widgets/grid/org.eclipse.nebula.widgets.grid/.settings/org.eclipse.jdt.core.prefs
index 1a7218d..1a1b490 100644
--- a/widgets/grid/org.eclipse.nebula.widgets.grid/.settings/org.eclipse.jdt.core.prefs
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/.settings/org.eclipse.jdt.core.prefs
@@ -1,15 +1,14 @@
-#Tue Mar 27 11:22:34 EDT 2007
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
@@ -21,4 +20,4 @@ org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/META-INF/MANIFEST.MF b/widgets/grid/org.eclipse.nebula.widgets.grid/META-INF/MANIFEST.MF
index 185be22..297566a 100644
--- a/widgets/grid/org.eclipse.nebula.widgets.grid/META-INF/MANIFEST.MF
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Nebula Grid
Bundle-SymbolicName: org.eclipse.nebula.widgets.grid
Bundle-Version: 1.0.0.qualifier
-Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.swt,
org.eclipse.jface;resolution:=optional
Export-Package: org.eclipse.nebula.jface.gridviewer,
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/jface/gridviewer/GridTableViewer.java b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/jface/gridviewer/GridTableViewer.java
index 894094c..c3823c0 100644
--- a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/jface/gridviewer/GridTableViewer.java
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/jface/gridviewer/GridTableViewer.java
@@ -8,6 +8,7 @@
* Contributors:
* rmcamara@us.ibm.com - initial API and implementation
* tom.schindl@bestsolution.at - various significant contributions
+ * mirko.paturzo@exeura.eu - improve performance
*******************************************************************************/
package org.eclipse.nebula.jface.gridviewer;
@@ -25,14 +26,15 @@ import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.viewers.ViewerRow;
import org.eclipse.nebula.jface.gridviewer.internal.CellSelection;
import org.eclipse.nebula.jface.gridviewer.internal.SelectionWithFocusRow;
+import org.eclipse.nebula.widgets.grid.DataVisualizer;
import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -51,10 +53,16 @@ import org.eclipse.swt.widgets.Widget;
* ITreeContentProvider} interface. Instead a {@link GridTreeViewer} should be
* used.
* <p>
+ *
+ * @author Unknown...
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ * Mirko modified improve performace and reduce used memory
+ * fix memory leak and slow disposed object
*/
public class GridTableViewer extends AbstractTableViewer {
/** This viewer's grid control. */
- private Grid grid;
+ private final Grid grid;
private GridViewerRow cachedRow;
@@ -91,6 +99,36 @@ public class GridTableViewer extends AbstractTableViewer {
* @param style
* the SWT style bits used to create the grid.
*/
+ public GridTableViewer(DataVisualizer dataVisualizer, Composite parent, int style) {
+ this(new Grid(dataVisualizer, parent, style));
+ }
+
+
+ /**
+ * Creates a grid viewer on a newly-created grid control under the given
+ * parent. The grid control is created using the SWT style bits
+ * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
+ * viewer has no input, no content provider, a default label provider, no
+ * sorter, and no filters.
+ *
+ * @param parent
+ * the parent control
+ */
+ public GridTableViewer(DataVisualizer dataVisualizer, Composite parent) {
+ this(dataVisualizer, parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ }
+
+ /**
+ * Creates a grid viewer on a newly-created grid control under the given
+ * parent. The grid control is created using the given SWT style bits. The
+ * viewer has no input, no content provider, a default label provider, no
+ * sorter, and no filters.
+ *
+ * @param parent
+ * the parent control
+ * @param style
+ * the SWT style bits used to create the grid.
+ */
public GridTableViewer(Composite parent, int style) {
this(new Grid(parent, style));
}
@@ -117,6 +155,7 @@ public class GridTableViewer extends AbstractTableViewer {
}
/** {@inheritDoc} */
+ @Override
protected ViewerRow internalCreateNewRowPart(int style, int rowIndex) {
GridItem item;
@@ -130,6 +169,7 @@ public class GridTableViewer extends AbstractTableViewer {
}
/** {@inheritDoc} */
+ @Override
protected ColumnViewerEditor createViewerEditor() {
return new GridViewerEditor(this,
new ColumnViewerEditorActivationStrategy(this),
@@ -137,81 +177,115 @@ public class GridTableViewer extends AbstractTableViewer {
}
/** {@inheritDoc} */
+ @Override
protected void doClear(int index) {
// TODO Fix when grid supports virtual
}
/** {@inheritDoc} */
+ @Override
protected void doClearAll() {
// TODO Fix when grid supports virtual
}
/** {@inheritDoc} */
+ @Override
protected void doSetItemCount(int count) {
// TODO Once grid supports virtual
}
/** {@inheritDoc} */
+ @Override
protected void doDeselectAll() {
grid.deselectAll();
}
/** {@inheritDoc} */
+ @Override
protected Widget doGetColumn(int index) {
return grid.getColumn(index);
}
/** {@inheritDoc} */
+ @Override
protected int doGetColumnCount() {
return grid.getColumnCount();
}
/** {@inheritDoc} */
+ @Override
protected Item doGetItem(int index) {
return grid.getItem(index);
}
/** {@inheritDoc} */
+ @Override
protected int doGetItemCount() {
return grid.getItemCount();
}
/** {@inheritDoc} */
+ @Override
protected Item[] doGetItems() {
return grid.getItems();
}
/** {@inheritDoc} */
+ @Override
protected Item[] doGetSelection() {
return grid.getSelection();
}
/** {@inheritDoc} */
+ @Override
protected int[] doGetSelectionIndices() {
return grid.getSelectionIndices();
}
/** {@inheritDoc} */
+ @Override
protected int doIndexOf(Item item) {
return grid.indexOf((GridItem) item);
}
/** {@inheritDoc} */
+ @Override
protected void doRemove(int[] indices) {
grid.remove(indices);
}
/** {@inheritDoc} */
+ @Override
protected void doRemove(int start, int end) {
grid.remove(start, end);
}
/** {@inheritDoc} */
+ @Override
protected void doRemoveAll() {
grid.removeAll();
}
+
+ /**
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.AbstractTableViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
+ * fix crossed reference for GC
+ */
+ @Override
+ protected void handleDispose(final DisposeEvent event)
+ {
+ super.handleDispose(event);
+
+ cachedRow = null;
+ rowHeaderLabelProvider = null;
+
+ getGrid().setRedraw(false);
+ getGrid().disposeAllItems();
+ getGrid().clearItems();
+ }
/** {@inheritDoc} */
+ @Override
protected void doSetSelection(Item[] items) {
GridItem[] items2 = new GridItem[items.length];
for (int i = 0; i < items.length; i++) {
@@ -222,31 +296,37 @@ public class GridTableViewer extends AbstractTableViewer {
}
/** {@inheritDoc} */
+ @Override
protected void doSetSelection(int[] indices) {
grid.setSelection(indices);
}
/** {@inheritDoc} */
+ @Override
protected void doShowItem(Item item) {
grid.showItem((GridItem) item);
}
/** {@inheritDoc} */
+ @Override
protected void doShowSelection() {
grid.showSelection();
}
/** {@inheritDoc} */
+ @Override
protected Item getItemAt(Point point) {
return grid.getItem(point);
}
/** {@inheritDoc} */
+ @Override
public Control getControl() {
return grid;
}
/** {@inheritDoc} */
+ @Override
protected ViewerRow getViewerRowFromItem(Widget item) {
if (cachedRow == null) {
cachedRow = new GridViewerRow((GridItem) item);
@@ -260,6 +340,7 @@ public class GridTableViewer extends AbstractTableViewer {
/**
* {@inheritDoc}
*/
+ @Override
protected void doResetItem(Item item) {
GridItem gridItem = (GridItem) item;
int columnCount = Math.max(1, grid.getColumnCount());
@@ -272,6 +353,7 @@ public class GridTableViewer extends AbstractTableViewer {
/**
* {@inheritDoc}
*/
+ @Override
protected void doSelect(int[] indices) {
grid.select(indices);
}
@@ -307,6 +389,7 @@ public class GridTableViewer extends AbstractTableViewer {
}
/** {@inheritDoc} */
+ @Override
protected void doUpdateItem(Widget widget, Object element, boolean fullMap) {
super.doUpdateItem(widget, element, fullMap);
updateRowHeader(widget);
@@ -355,6 +438,7 @@ public class GridTableViewer extends AbstractTableViewer {
/**
* {@inheritDoc}
*/
+ @Override
public void editElement(Object element, int column) {
try {
getControl().setRedraw(false);
@@ -378,6 +462,7 @@ public class GridTableViewer extends AbstractTableViewer {
/**
* {@inheritDoc}
*/
+ @Override
protected void setSelectionToWidget(ISelection selection, boolean reveal) {
if( ! grid.isCellSelectionEnabled() || !(selection instanceof CellSelection) ) {
super.setSelectionToWidget(selection, reveal);
@@ -433,6 +518,7 @@ public class GridTableViewer extends AbstractTableViewer {
/**
* {@inheritDoc}
*/
+ @Override
public ISelection getSelection() {
if (!grid.isCellSelectionEnabled()) {
IStructuredSelection selection = (IStructuredSelection) super
@@ -452,6 +538,7 @@ public class GridTableViewer extends AbstractTableViewer {
Point[] ps = grid.getCellSelection();
Arrays.sort(ps, new Comparator() {
+ @Override
public int compare(Object arg0, Object arg1) {
Point a = (Point) arg0;
Point b = (Point) arg1;
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/AdaptedDataVisualizer.java b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/AdaptedDataVisualizer.java
new file mode 100644
index 0000000..84ba584
--- /dev/null
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/AdaptedDataVisualizer.java
@@ -0,0 +1,328 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Mirko Paturzo (Exeura srl).
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mirko Paturzo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.grid;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * A basic implementation of the DataVisualizer interface. This class can be used
+ * to provide general visualization values for various aspects of the GridItem like
+ * background, font and text.
+ * Scope of this implementation: reduce memory usage by avoid duplication of
+ * visualization data like string, fonts, and others.
+ * In this example, DataVisualizer is customized on Object named MyModel: LabelProvider
+ * is not required.
+ *
+ *
+ * <pre>
+ * class MyOwnDataVisualizer extends AdaptedDataVisualizer {
+ * FontRegistry registry = new FontRegistry();
+ *
+ * private final MyModel models[];
+ *
+ * public MyOwnDataVisualizer(MyModel models[]) {
+ * this.models = models;
+ * }
+ *
+ * @Override
+ * public Image getImage(int row, int columnIndex) {
+ * return null;
+ * }
+ *
+ * @Override
+ * public String getText(int row, int columnIndex) {
+ * return "Column " + columnIndex + " => " + models[row].toString();
+ * }
+ *
+ * @Override
+ * public Font getFont(int row, int columnIndex) {
+ * if ((models[row]).counter % 2 == 0) {
+ * return registry.getBold(Display.getCurrent().getSystemFont()
+ * .getFontData()[0].getName());
+ * }
+ * return null;
+ * }
+ * }
+ * </pre>
+ *
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ */
+public class AdaptedDataVisualizer implements DataVisualizer{
+
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setBackground(int, int, org.eclipse.swt.graphics.Color)
+ */
+ @Override
+ public void setBackground(int row, int index, Color color) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setChecked(int, int, boolean)
+ */
+ @Override
+ public void setChecked(int row, int i, boolean checked) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setColumnSpan(int, int, int)
+ */
+ @Override
+ public void setColumnSpan(int row, int index, int span) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setRowSpan(int, int, int)
+ */
+ @Override
+ public void setRowSpan(int row, int index, int span) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setFont(int, int, org.eclipse.swt.graphics.Font)
+ */
+ @Override
+ public void setFont(int row, int index, Font font) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setForeground(int, int, org.eclipse.swt.graphics.Color)
+ */
+ @Override
+ public void setForeground(int row, int index, Color foreground) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setGrayed(int, int, boolean)
+ */
+ @Override
+ public void setGrayed(int row, int i, boolean grayed) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setImage(int, int, org.eclipse.swt.graphics.Image)
+ */
+ @Override
+ public void setImage(int row, int i, Image image) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setText(int, int, java.lang.String)
+ */
+ @Override
+ public void setText(int row, int i, String text) {
+ /**
+ * Is empty
+ */
+ }
+
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setCheckable(int, int, boolean)
+ */
+ @Override
+ public void setCheckable(int row, int index, boolean checked) {
+ /**
+ * Is empty
+ */
+ }
+
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setToolTipText(int, int, java.lang.String)
+ */
+ @Override
+ public void setToolTipText(int row, int index, String tooltip) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#removeIndex(int)
+ */
+ @Override
+ public void removeIndex(int row) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getBackground(int, int)
+ */
+ @Override
+ public Color getBackground(int row, int index) {
+ return getDefaultBackground();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getChecked(int, int)
+ */
+ @Override
+ public boolean getChecked(int row, int i) {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getColumnSpan(int, int)
+ */
+ @Override
+ public int getColumnSpan(int row, int index) {
+ return 0;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getRowSpan(int, int)
+ */
+ @Override
+ public int getRowSpan(int row, int index) {
+ return 0;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getFont(int, int)
+ */
+ @Override
+ public Font getFont(int row, int index) {
+ return getDefaultFont();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getForeground(int, int)
+ */
+ @Override
+ public Color getForeground(int row, int index) {
+ return getDefaultForeground();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getGrayed(int, int)
+ */
+ @Override
+ public boolean getGrayed(int row, int index) {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getImage(int, int)
+ */
+ @Override
+ public Image getImage(int row, int i) {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getText(int, int)
+ */
+ @Override
+ public String getText(int row, int i) {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getCheckable(int, int)
+ */
+ @Override
+ public boolean getCheckable(int row, int index) {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getToolTipText(int, int)
+ */
+ @Override
+ public String getToolTipText(int row, int index) {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#clearRow(int)
+ */
+ @Override
+ public void clearRow(int row) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#clearColumn(int)
+ */
+ @Override
+ public void clearColumn(int column) {
+ /**
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getDefaultBackground()
+ */
+ @Override
+ public Color getDefaultBackground() {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getDefaultForeground()
+ */
+ @Override
+ public Color getDefaultForeground() {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getDefaultFont()
+ */
+ @Override
+ public Font getDefaultFont() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#createAndGetChildenGridItemDataVisualizer()
+ */
+ @Override
+ public DataVisualizer createAndGetChildenGridItemDataVisualizer() {
+ throw new UnsupportedOperationException("GridItem Children dataVisualizer is not supported in AdaptedDataVisualizer");
+ }
+
+}
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/ColumnRowBigDataVisualizer.java b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/ColumnRowBigDataVisualizer.java
new file mode 100644
index 0000000..2bf7e89
--- /dev/null
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/ColumnRowBigDataVisualizer.java
@@ -0,0 +1,358 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Mirko Paturzo (Exeura srl).
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mirko Paturzo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.grid;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * This class can be used to provide general visualization values for various aspects
+ * of the GridItem like background, font and text. Your own subclass of this class
+ * could be used in combination with the JFace LabelProvider if you use the GridViewer.
+ * This dataVisualizer implementation replace the current paradigma of GridItem with
+ * memory less.
+ * This implementation is preferable in the case where there are more rows than columns.
+ *
+ * This datavisualizer kind is default for Grid.
+ *
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ */
+public class ColumnRowBigDataVisualizer implements DataVisualizer {
+
+ /**
+ * Create {@link ColumnRowBigDataVisualizer} with default value
+ * @param defaultBackground
+ * @param defaultForeground
+ * @param defaultFont
+ */
+ public ColumnRowBigDataVisualizer(Color defaultBackground, Color defaultForeground, Font defaultFont) {
+ this.defaultBackground = defaultBackground;
+ this.defaultForeground = defaultForeground;
+ this.defaultFont = defaultFont;
+ }
+
+ private final Map<Integer, List<Color>> backgrounds = new HashMap<Integer, List<Color>>();
+ private final Map<Integer, List<Color>> foregrounds = new HashMap<Integer, List<Color>>();
+ private final Map<Integer, List<Boolean>> checkables = new HashMap<Integer, List<Boolean>>();
+ private final Map<Integer, List<Boolean>> checkeds = new HashMap<Integer, List<Boolean>>();
+ private final Map<Integer, List<Boolean>> grayeds = new HashMap<Integer, List<Boolean>>();
+ private final Map<Integer, List<Integer>> columnSpans = new HashMap<Integer, List<Integer>>();
+ private final Map<Integer, List<Integer>> rowSpans = new HashMap<Integer, List<Integer>>();
+ private final Map<Integer, List<Font>> fonts = new HashMap<Integer, List<Font>>();
+ private final Map<Integer, List<Image>> images = new HashMap<Integer, List<Image>>();
+ private final Map<Integer, List<String>> texts = new HashMap<Integer, List<String>>();
+ private final Map<Integer, List<String>> toolTipTexts = new HashMap<Integer, List<String>>();
+
+ private final Color defaultBackground;
+ private final Color defaultForeground;
+ private final Font defaultFont;
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getDefaultBackground()
+ */
+ @Override
+ public Color getDefaultBackground() {
+ return defaultBackground;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getDefaultForeground()
+ */
+ @Override
+ public Color getDefaultForeground() {
+ return defaultForeground;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getDefaultFont()
+ */
+ @Override
+ public Font getDefaultFont() {
+ return defaultFont;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getBackground(int, int)
+ */
+ @Override
+ public Color getBackground(int row, int column) {
+ return getValueOrDefault(backgrounds, row, column, defaultBackground);
+ }
+
+ /**
+ * get value or default.. inverted index on {@link RowColumnBigDataVisualizer}
+ * @param map
+ * @param row
+ * @param column
+ * @param defaultValue
+ * @return T
+ */
+ protected <T> T getValueOrDefault(Map<Integer, List<T>> map, int row, int column, T defaultValue) {
+ List<T> list = map.get(column);
+ if(list == null)
+ return defaultValue;
+
+ if(row >= list.size())
+ return defaultValue;
+
+ T t = list.get(row);
+
+ if(t == null)
+ return defaultValue;
+
+ return t;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getChecked(int, int)
+ */
+ @Override
+ public boolean getChecked(int row, int column) {
+ return getValueOrDefault(checkeds, row, column, Boolean.FALSE);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getColumnSpan(int, int)
+ */
+ @Override
+ public int getColumnSpan(int row, int column) {
+ return getValueOrDefault(columnSpans, row, column, 0);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getRowSpan(int, int)
+ */
+ @Override
+ public int getRowSpan(int row, int column) {
+ return getValueOrDefault(rowSpans, row, column, 0);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getFont(int, int)
+ */
+ @Override
+ public Font getFont(int row, int column) {
+ return getValueOrDefault(fonts, row, column, defaultFont);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getForeground(int, int)
+ */
+ @Override
+ public Color getForeground(int row, int column) {
+ return getValueOrDefault(foregrounds, row, column, defaultForeground);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getGrayed(int, int)
+ */
+ @Override
+ public boolean getGrayed(int row, int column) {
+ return getValueOrDefault(grayeds, row,column, Boolean.FALSE);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getImage(int, int)
+ */
+ @Override
+ public Image getImage(int row, int column) {
+ return getValueOrDefault(images, row,column, null);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getText(int, int)
+ */
+ @Override
+ public String getText(int row, int column) {
+ return getValueOrDefault(texts, row, column, "");
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setBackground(int, int, org.eclipse.swt.graphics.Color)
+ */
+ @Override
+ public void setBackground(int row, int column, Color color) {
+ put(backgrounds, row, column, color);
+ }
+
+ /**
+ * put value on maps.. inverted index for {@link RowColumnBigDataVisualizer}
+ * @param map
+ * @param row
+ * @param column
+ * @param value
+ */
+ protected <T> void put(Map<Integer, List<T>> map, int row, int column,
+ T value) {
+ List<T> list = map.get(column);
+ if(list == null) {
+ list = new ArrayList<T>();
+ map.put(column, list);
+ }
+ while(row > list.size()) {
+ list.add(null);
+ }
+ if(list.size() > row) {
+ list.remove(row);
+ }
+ list.add(row, value);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setChecked(int, int, boolean)
+ */
+ @Override
+ public void setChecked(int row, int column, boolean checked) {
+ put(checkeds, row, column, checked);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setColumnSpan(int, int, int)
+ */
+ @Override
+ public void setColumnSpan(int row, int column, int span) {
+ put(columnSpans, row, column, span);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setRowSpan(int, int, int)
+ */
+ @Override
+ public void setRowSpan(int row, int column, int span) {
+ put(rowSpans, row, column, span);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setFont(int, int, org.eclipse.swt.graphics.Font)
+ */
+ @Override
+ public void setFont(int row, int column, Font font) {
+ put(fonts, row, column, font);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setForeground(int, int, org.eclipse.swt.graphics.Color)
+ */
+ @Override
+ public void setForeground(int row, int column, Color foreground) {
+ put(foregrounds, row, column, foreground);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setGrayed(int, int, boolean)
+ */
+ @Override
+ public void setGrayed(int row, int column, boolean grayed) {
+ put(grayeds, row, column, grayed);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setImage(int, int, org.eclipse.swt.graphics.Image)
+ */
+ @Override
+ public void setImage(int row, int column, Image image) {
+ put(images, row, column, image);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setText(int, int, java.lang.String)
+ */
+ @Override
+ public void setText(int row, int column, String text) {
+ put(texts, row, column, text);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getCheckable(int, int)
+ */
+ @Override
+ public boolean getCheckable(int row, int column) {
+ return getValueOrDefault(checkables, row,column, Boolean.TRUE);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setCheckable(int, int, boolean)
+ */
+ @Override
+ public void setCheckable(int row, int column, boolean checked) {
+ put(this.checkables, row, column, checked);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#getToolTipText(int, int)
+ */
+ @Override
+ public String getToolTipText(int row, int column) {
+ return getValueOrDefault(toolTipTexts, row,column, "");
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setToolTipText(int, int, java.lang.String)
+ */
+ @Override
+ public void setToolTipText(int row, int column, String tooltip) {
+ put(texts, row, column, tooltip);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#removeIndex(int)
+ */
+ @Override
+ public void removeIndex(int index) {
+ texts.remove(index);
+ toolTipTexts.remove(index);
+ foregrounds.remove(index);
+ backgrounds.remove(index);
+ images.remove(index);
+ fonts.remove(index);
+ rowSpans.remove(index);
+ columnSpans.remove(index);
+ grayeds.remove(index);
+ checkables.remove(index);
+ checkeds.remove(index);
+ }
+
+ /**
+ * In this implementation is too much expensive...
+ * Empty is Much better
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#clearRow(int)
+ */
+ @Override
+ public void clearRow(int row) {
+ /*
+ * Is empty
+ */
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#clearColumn(int)
+ */
+ @Override
+ public void clearColumn(int column) {
+ removeIndex(column);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.DataVisualizer#createAndGetChildenGridItemDataVisualizer()
+ */
+ @Override
+ public DataVisualizer createAndGetChildenGridItemDataVisualizer() {
+ return new ColumnRowBigDataVisualizer(defaultBackground, defaultForeground, defaultFont);
+ }
+
+}
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/DataVisualizer.java b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/DataVisualizer.java
new file mode 100644
index 0000000..8d50aa5
--- /dev/null
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/DataVisualizer.java
@@ -0,0 +1,246 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Mirko Paturzo (Exeura srl).
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mirko Paturzo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.grid;
+
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Creation of a paradigm for the management of GridItem data.
+ * Via interface DataVisualizer it's possible create the own datavisualization
+ * manager. Remove collections on {@link GridItem}, reduce memory leak risk
+ * and reduce memory usage.
+ *
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ */
+public interface DataVisualizer {
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @return {@link Color}
+ */
+ Color getBackground(int row, int index);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param i
+ * @return boolean
+ */
+ boolean getChecked(int row, int i);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @return int
+ */
+ int getColumnSpan(int row, int index);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @return int
+ */
+ int getRowSpan(int row, int index);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @return {@link Font}
+ */
+ Font getFont(int row, int index);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @return {@link Color}
+ */
+ Color getForeground(int row, int index);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @return boolean
+ */
+ boolean getGrayed(int row, int index);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param i
+ * @return {@link Image}
+ */
+ Image getImage(int row, int i);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param i
+ * @return {@link String}
+ */
+ String getText(int row, int i);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @param color
+ */
+ void setBackground(int row, int index, Color color);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param column
+ * @param checked
+ */
+ void setChecked(int row, int column, boolean checked);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @param span
+ */
+ void setColumnSpan(int row, int index, int span);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @param span
+ */
+ void setRowSpan(int row, int index, int span);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @param font
+ */
+ void setFont(int row, int index, Font font);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @param foreground
+ */
+ void setForeground(int row, int index, Color foreground);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param i
+ * @param grayed
+ */
+ void setGrayed(int row, int i, boolean grayed);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param i
+ * @param image
+ */
+ void setImage(int row, int i, Image image);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param i
+ * @param text
+ */
+ void setText(int row, int i, String text);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @return boolean
+ */
+ boolean getCheckable(int row, int index);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @param checked
+ */
+ void setCheckable(int row, int index, boolean checked);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @return String
+ */
+ String getToolTipText(int row, int index);
+
+ /**
+ * Method substitute GridItem method
+ * @param row
+ * @param index
+ * @param tooltip
+ */
+ void setToolTipText(int row, int index, String tooltip);
+
+ /**
+ * remove {@link Map} index (key)
+ * for {@link ColumnRowBigDataVisualizer} index is column
+ * for {@link RowColumnBigDataVisualizer} index is row
+ * @param index
+ */
+ void removeIndex(int index);
+
+ /**
+ * Clear rows dataVisualizer values
+ * @param row
+ */
+ void clearRow(int row);
+
+ /**
+ * Clear columns dataVisualizer values
+ * @param column
+ */
+ void clearColumn(int column);
+
+ /**
+ * @return default background
+ */
+ Color getDefaultBackground();
+
+ /**
+ * @return default foreground
+ */
+ Color getDefaultForeground();
+
+ /**
+ * @return default font
+ */
+ Font getDefaultFont();
+
+ /**
+ * @return GridItem children dataVisualizer.
+ */
+ DataVisualizer createAndGetChildenGridItemDataVisualizer();
+
+}
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 57748de..0998198 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
@@ -20,6 +20,7 @@
* Cosmin Ghita <cghita@ansis.eu> - bugfix in 323687
* Pinard-Legry Guilhaume <guilhaume_pl@yahoo.fr> - bugfix in 267057
* Thorsten Schenkel <thorsten.schenkel@compeople.de> - bugfix in 356803
+ * Mirko Paturzo <mirko.paturzo@exeura.eu> - improvement (bugfix in 419928)
*******************************************************************************/
package org.eclipse.nebula.widgets.grid;
@@ -77,6 +78,7 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TypedListener;
@@ -100,6 +102,10 @@ import org.eclipse.swt.widgets.TypedListener;
* </dl>
*
* @author chris.gross@us.ibm.com
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ * Mirko modified this widget for improve performace and reduce used memory
+ * fix memory leak and slow disposed object
*/
public class Grid extends Canvas
{
@@ -114,6 +120,13 @@ public class Grid extends Canvas
//TODO: Performance - need to cache top index
/**
+ * @return {@link DataVisualizer}
+ */
+ public DataVisualizer getDataVisualizer() {
+ return dataVisualizer;
+ }
+
+ /**
* Object holding the visible range
*/
public static class GridVisibleRange {
@@ -134,6 +147,17 @@ public class Grid extends Canvas
return columns;
}
}
+
+ /**
+ * Clear simply all GridItems
+ */
+ public void clearItems()
+ {
+ items.clear();
+ rootItems.clear();
+ deselectAll();
+ redraw();
+ }
/**
* Accessibility default action for column headers and column group headers.
@@ -220,17 +244,17 @@ public class Grid extends Canvas
/**
* All items in the table, not just root items.
*/
- private List items = new ArrayList();
+ private final List items = new ArrayList();
/**
* All root items.
*/
- private List rootItems = new ArrayList();
+ private final List rootItems = new ArrayList();
/**
* List of selected items.
*/
- private List selectedItems = new ArrayList();
+ private final List selectedItems = new ArrayList();
/**
* Reference to the item in focus.
@@ -239,8 +263,8 @@ public class Grid extends Canvas
private boolean cellSelectionEnabled = false;
- private List selectedCells = new ArrayList();
- private List selectedCellsBeforeRangeSelect = new ArrayList();
+ private final List selectedCells = new ArrayList();
+ private final List selectedCellsBeforeRangeSelect = new ArrayList();
private boolean cellDragSelectionOccuring = false;
private boolean cellRowDragSelectionOccuring = false;
@@ -256,7 +280,7 @@ public class Grid extends Canvas
private GridColumn focusColumn;
- private List selectedColumns = new ArrayList();
+ private final List selectedColumns = new ArrayList();
/**
* This is the column that the user last navigated to, but may not be the focusColumn because
@@ -271,12 +295,12 @@ public class Grid extends Canvas
/**
* List of table columns in creation/index order.
*/
- private List columns = new ArrayList();
+ private final List columns = new ArrayList();
/**
* List of the table columns in the order they are displayed.
*/
- private List displayOrderedColumns = new ArrayList();
+ private final List displayOrderedColumns = new ArrayList();
private GridColumnGroup[] columnGroups = new GridColumnGroup[0];
@@ -323,7 +347,7 @@ public class Grid extends Canvas
* Renderers the UI affordance identifying where the dragged column will be
* dropped.
*/
- private IRenderer dropPointRenderer = new DefaultDropPointRenderer();
+ private final IRenderer dropPointRenderer = new DefaultDropPointRenderer();
/**
* Renderer used to paint on top of an already painted row to denote focus.
@@ -572,7 +596,7 @@ public class Grid extends Canvas
*/
private GridToolTip inplaceToolTip;
- private GC sizingGC;
+ private final GC sizingGC;
private Color backgroundColor;
@@ -683,11 +707,14 @@ public class Grid extends Canvas
private GridItem insertMarkItem = null;
private GridColumn insertMarkColumn = null;
private boolean insertMarkBefore = false;
- private IRenderer insertMarkRenderer = new DefaultInsertMarkRenderer();
+ private final IRenderer insertMarkRenderer = new DefaultInsertMarkRenderer();
private boolean sizeOnEveryItemImageChange;
private boolean autoHeight = false;
private boolean autoWidth = true;
private boolean wordWrapRowHeader = false;
+
+ private final DataVisualizer dataVisualizer;
+
/**
* A range of rows in a <code>Grid</code>.
* <p>
@@ -724,12 +751,19 @@ public class Grid extends Canvas
newStyle |= SWT.DOUBLE_BUFFERED;
return newStyle;
}
+
+ /**
+ * Grid with generic DataVisualizer
+ */
+ public Grid(Composite parent, int style) {
+ this(new ColumnRowBigDataVisualizer(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE), Display.getCurrent().getSystemColor(SWT.COLOR_BLACK), null), parent, style);
+ }
/**
* Constructs a new instance of this class given its parent and a style
* value describing its behavior and appearance.
* <p>
- *
+ * @param dataVisualizer manage all data of grid and its items
* @param parent a composite control which will be the parent of the new
* instance (cannot be null)
* @param style the style of control to construct
@@ -745,9 +779,10 @@ public class Grid extends Canvas
* @see SWT#SINGLE
* @see SWT#MULTI
*/
- public Grid(Composite parent, int style)
+ public Grid(DataVisualizer dataVisualizer, Composite parent, int style)
{
super(parent, checkStyle(style));
+ this.dataVisualizer = dataVisualizer;
// initialize drag & drop support
setData("DEFAULT_DRAG_SOURCE_EFFECT", new GridDragSourceEffect(this));
@@ -818,7 +853,8 @@ public class Grid extends Canvas
/**
* {@inheritDoc}
*/
- public Color getBackground()
+ @Override
+ public Color getBackground()
{
checkWidget();
if (backgroundColor == null)
@@ -829,7 +865,8 @@ public class Grid extends Canvas
/**
* {@inheritDoc}
*/
- public void setBackground(Color color)
+ @Override
+ public void setBackground(Color color)
{
checkWidget();
backgroundColor = color;
@@ -939,7 +976,8 @@ public class Grid extends Canvas
/**
* {@inheritDoc}
*/
- public Point computeSize(int wHint, int hHint, boolean changed)
+ @Override
+ public Point computeSize(int wHint, int hHint, boolean changed)
{
checkWidget();
@@ -3191,14 +3229,16 @@ public class Grid extends Canvas
/**
* Removes all of the items from the receiver.
- *
+ *
* @throws org.eclipse.swt.SWTException
* <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that
* created the receiver</li>
* </ul>
+ * Call {@link Grid} disposeAllItems and clearItems.. Is faster
*/
+ @Deprecated
public void removeAll()
{
checkWidget();
@@ -3210,6 +3250,21 @@ public class Grid extends Canvas
deselectAll();
redraw();
}
+
+ /**
+ * All items needs to call the disposeOnly method
+ */
+ public void disposeAllItems()
+ {
+ checkWidget();
+
+ final GridItem[] items = getItems();
+ for (final GridItem gridItem : items)
+ {
+ gridItem.disposeOnly();
+ }
+ clearItems();
+ }
/**
* Removes the listener from the collection of listeners who will be
@@ -3551,10 +3606,12 @@ public class Grid extends Canvas
hScroll = scroll;
hScroll.addSelectionListener(new SelectionListener() {
+ @Override
public void widgetSelected(SelectionEvent e) {
onScrollSelection();
}
+ @Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
@@ -3588,10 +3645,12 @@ public class Grid extends Canvas
vScroll = scroll;
vScroll.addSelectionListener(new SelectionListener() {
+ @Override
public void widgetSelected(SelectionEvent e) {
onScrollSelection();
}
+ @Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
@@ -3782,7 +3841,7 @@ public class Grid extends Canvas
if (!cellSelectionEnabled)
{
selectedItems.clear();
- selectedItems.add((GridItem)items.get(index));
+ selectedItems.add(items.get(index));
redraw();
}
else
@@ -4382,7 +4441,7 @@ public class Grid extends Canvas
int groupHeight = 0;
for (int groupIndex = 0; groupIndex < columnGroups.length; groupIndex++)
{
- GridColumnGroup group = (GridColumnGroup) columnGroups[groupIndex];
+ GridColumnGroup group = columnGroups[groupIndex];
groupHeight = Math.max(group.getHeaderRenderer().computeSize(gc, SWT.DEFAULT,
SWT.DEFAULT, group).y,
groupHeight);
@@ -6174,7 +6233,7 @@ public class Grid extends Canvas
{
if (!selectedItems.contains(items.get(i)) && ((GridItem)items.get(i)).isVisible())
{
- selectedItems.add((GridItem)items.get(i));
+ selectedItems.add(items.get(i));
}
}
Rectangle clientArea = getClientArea();
@@ -6446,7 +6505,8 @@ public class Grid extends Canvas
{
disposeListener = new Listener()
{
- public void handleEvent(Event e)
+ @Override
+ public void handleEvent(Event e)
{
onDispose(e);
}
@@ -6455,7 +6515,8 @@ public class Grid extends Canvas
addPaintListener(new PaintListener()
{
- public void paintControl(PaintEvent e)
+ @Override
+ public void paintControl(PaintEvent e)
{
onPaint(e);
}
@@ -6463,7 +6524,8 @@ public class Grid extends Canvas
addListener(SWT.Resize, new Listener()
{
- public void handleEvent(Event e)
+ @Override
+ public void handleEvent(Event e)
{
onResize();
}
@@ -6473,7 +6535,8 @@ public class Grid extends Canvas
{
getVerticalBar().addListener(SWT.Selection, new Listener()
{
- public void handleEvent(Event e)
+ @Override
+ public void handleEvent(Event e)
{
onScrollSelection();
}
@@ -6484,7 +6547,8 @@ public class Grid extends Canvas
{
getHorizontalBar().addListener(SWT.Selection, new Listener()
{
- public void handleEvent(Event e)
+ @Override
+ public void handleEvent(Event e)
{
onScrollSelection();
}
@@ -6493,7 +6557,8 @@ public class Grid extends Canvas
addListener(SWT.KeyDown, new Listener()
{
- public void handleEvent(Event e)
+ @Override
+ public void handleEvent(Event e)
{
onKeyDown(e);
}
@@ -6501,7 +6566,8 @@ public class Grid extends Canvas
addTraverseListener(new TraverseListener()
{
- public void keyTraversed(TraverseEvent e)
+ @Override
+ public void keyTraversed(TraverseEvent e)
{
e.doit = true;
}
@@ -6509,17 +6575,20 @@ public class Grid extends Canvas
addMouseListener(new MouseListener()
{
- public void mouseDoubleClick(MouseEvent e)
+ @Override
+ public void mouseDoubleClick(MouseEvent e)
{
onMouseDoubleClick(e);
}
- public void mouseDown(MouseEvent e)
+ @Override
+ public void mouseDown(MouseEvent e)
{
onMouseDown(e);
}
- public void mouseUp(MouseEvent e)
+ @Override
+ public void mouseUp(MouseEvent e)
{
onMouseUp(e);
}
@@ -6527,7 +6596,8 @@ public class Grid extends Canvas
addMouseMoveListener(new MouseMoveListener()
{
- public void mouseMove(MouseEvent e)
+ @Override
+ public void mouseMove(MouseEvent e)
{
onMouseMove(e);
}
@@ -6535,29 +6605,34 @@ public class Grid extends Canvas
addMouseTrackListener(new MouseTrackListener()
{
- public void mouseEnter(MouseEvent e)
+ @Override
+ public void mouseEnter(MouseEvent e)
{
}
- public void mouseExit(MouseEvent e)
+ @Override
+ public void mouseExit(MouseEvent e)
{
onMouseExit(e);
}
- public void mouseHover(MouseEvent e)
+ @Override
+ public void mouseHover(MouseEvent e)
{
}
});
addFocusListener(new FocusListener()
{
- public void focusGained(FocusEvent e)
+ @Override
+ public void focusGained(FocusEvent e)
{
onFocusIn();
redraw();
}
- public void focusLost(FocusEvent e)
+ @Override
+ public void focusLost(FocusEvent e)
{
redraw();
}
@@ -6567,7 +6642,8 @@ public class Grid extends Canvas
// scroller
addListener(SWT.MouseWheel, new Listener()
{
- public void handleEvent(Event e)
+ @Override
+ public void handleEvent(Event e)
{
onMouseWheel(e);
}
@@ -9627,7 +9703,8 @@ public class Grid extends Canvas
/**
* {@inheritDoc}
*/
- public void setFont(Font font)
+ @Override
+ public void setFont(Font font)
{
super.setFont(font);
sizingGC.setFont(font);
@@ -9664,6 +9741,8 @@ public class Grid extends Canvas
setAutoWidth(false);
redraw();
}
+
+
/**
* Sets the number of items contained in the receiver.
@@ -9704,7 +9783,8 @@ public class Grid extends Canvas
final Accessible accessible = getAccessible();
accessible.addAccessibleListener(new AccessibleAdapter()
{
- public void getDescription(AccessibleEvent e)
+ @Override
+ public void getDescription(AccessibleEvent e)
{
int childID = e.childID;
if (childID >= 0 && childID < items.size())
@@ -9722,7 +9802,8 @@ public class Grid extends Canvas
}
}
- public void getName(AccessibleEvent e)
+ @Override
+ public void getName(AccessibleEvent e)
{
int childID = e.childID;
if (childID >= 0 && childID < items.size())
@@ -9739,8 +9820,8 @@ public class Grid extends Canvas
&& childID < items.size() + columns.size() + columnGroups.length)
{
// Name of the column group headers
- e.result = ((GridColumnGroup)columnGroups[childID - items.size()
- - columns.size()]).getText();
+ e.result = columnGroups[childID - items.size()
+ - columns.size()].getText();
}
else if (childID >= items.size() + columns.size() + columnGroups.length
&& childID < items.size() + columns.size() + columnGroups.length
@@ -9754,7 +9835,8 @@ public class Grid extends Canvas
accessible.addAccessibleControlListener(new AccessibleControlAdapter()
{
- public void getChildAtPoint(AccessibleControlEvent e)
+ @Override
+ public void getChildAtPoint(AccessibleControlEvent e)
{
Point location = toControl(e.x, e.y);
e.childID = ACC.CHILDID_SELF;
@@ -9819,7 +9901,8 @@ public class Grid extends Canvas
}
}
- public void getChildCount(AccessibleControlEvent e)
+ @Override
+ public void getChildCount(AccessibleControlEvent e)
{
if (e.childID == ACC.CHILDID_SELF)
{
@@ -9842,7 +9925,8 @@ public class Grid extends Canvas
}
}
- public void getChildren(AccessibleControlEvent e)
+ @Override
+ public void getChildren(AccessibleControlEvent e)
{
if (e.childID == ACC.CHILDID_SELF)
{
@@ -9882,7 +9966,8 @@ public class Grid extends Canvas
}
}
- public void getDefaultAction(AccessibleControlEvent e)
+ @Override
+ public void getDefaultAction(AccessibleControlEvent e)
{
int childID = e.childID;
if (childID >= 0 && childID < items.size())
@@ -9920,7 +10005,8 @@ public class Grid extends Canvas
}
}
- public void getLocation(AccessibleControlEvent e)
+ @Override
+ public void getLocation(AccessibleControlEvent e)
{
// location of parent
Rectangle location = getBounds();
@@ -10002,7 +10088,8 @@ public class Grid extends Canvas
}
}
- public void getRole(AccessibleControlEvent e)
+ @Override
+ public void getRole(AccessibleControlEvent e)
{
int childID = e.childID;
if (childID >= 0 && childID < items.size())
@@ -10044,7 +10131,8 @@ public class Grid extends Canvas
}
}
- public void getSelection(AccessibleControlEvent e)
+ @Override
+ public void getSelection(AccessibleControlEvent e)
{
e.childID = ACC.CHILDID_NONE;
if (selectedItems.size() == 1)
@@ -10068,7 +10156,8 @@ public class Grid extends Canvas
}
}
- public void getState(AccessibleControlEvent e)
+ @Override
+ public void getState(AccessibleControlEvent e)
{
int childID = e.childID;
if (childID >= 0 && childID < items.size())
@@ -10136,7 +10225,8 @@ public class Grid extends Canvas
}
}
- public void getValue(AccessibleControlEvent e)
+ @Override
+ public void getValue(AccessibleControlEvent e)
{
int childID = e.childID;
if (childID >= 0 && childID < items.size())
@@ -10152,7 +10242,8 @@ public class Grid extends Canvas
addListener(SWT.Selection, new Listener()
{
- public void handleEvent(Event event)
+ @Override
+ public void handleEvent(Event event)
{
if (selectedItems.size() > 0)
{
@@ -10163,7 +10254,8 @@ public class Grid extends Canvas
addTreeListener(new TreeListener()
{
- public void treeCollapsed(TreeEvent e)
+ @Override
+ public void treeCollapsed(TreeEvent e)
{
if (getFocusItem() != null)
{
@@ -10171,7 +10263,8 @@ public class Grid extends Canvas
}
}
- public void treeExpanded(TreeEvent e)
+ @Override
+ public void treeExpanded(TreeEvent e)
{
if (getFocusItem() != null)
{
@@ -10208,6 +10301,7 @@ public class Grid extends Canvas
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
+ @Override
public String getToolTipText() {
checkWidget();
return toolTipText;
@@ -10225,6 +10319,7 @@ public class Grid extends Canvas
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
+ @Override
public void setToolTipText(String string) {
checkWidget();
toolTipText = string;
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridItem.java b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridItem.java
index 41983ba..ff1d3b8 100644
--- a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridItem.java
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridItem.java
@@ -9,6 +9,7 @@
* chris.gross@us.ibm.com - initial API and implementation
* Claes Rosell<claes.rosell@solme.se> - rowspan in bug 272384
* Stefan Widmaier<stefan.widmaier@faktorzehn.de> - rowspan in 304797
+ * Mirko Paturzo <mirko.paturzo@exeura.eu> - improvement (bug in 419928)
*******************************************************************************/
package org.eclipse.nebula.widgets.grid;
@@ -46,51 +47,33 @@ import org.eclipse.swt.widgets.TypedListener;
* </dl>
*
* @author chris.gross@us.ibm.com
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ * Mirko removed all collections, improve dispose performance, reduce used memory
*/
public class GridItem extends Item {
/**
- * List of background colors for each column.
- */
- private ArrayList backgrounds = new ArrayList();
-
- /**
- * Lists of check states for each column.
- */
- private ArrayList checks = new ArrayList();
-
- /**
- * Lists of checkable states for each column.
- */
- private ArrayList checkable = new ArrayList();
-
- /**
* List of children.
*/
- private ArrayList children = new ArrayList();
-
- /**
- * List of column spaning.
- */
- private ArrayList columnSpans = new ArrayList();
-
- /**
- * List of row spaning.
- */
- private ArrayList rowSpans = new ArrayList();
+ private final ArrayList children = new ArrayList();
+
/**
* Default background color.
*/
+ @Deprecated
private Color defaultBackground;
/**
* Default font.
*/
+ @Deprecated
private Font defaultFont;
/**
* Default foreground color.
*/
+ @Deprecated
private Color defaultForeground;
/**
@@ -103,20 +86,6 @@ public class GridItem extends Item {
*/
private boolean expanded = false;
- /**
- * Lists of fonts for each column.
- */
- private ArrayList fonts = new ArrayList();
-
- /**
- * List of foreground colors for each column.
- */
- private ArrayList foregrounds = new ArrayList();
-
- /**
- * Lists of grayed (3rd check state) for each column.
- */
- private ArrayList grayeds = new ArrayList();
/**
* True if has children.
@@ -124,11 +93,6 @@ public class GridItem extends Item {
private boolean hasChildren = false;
/**
- * List of images for each column.
- */
- private ArrayList images = new ArrayList();
-
- /**
* Level of item in a tree.
*/
private int level = 0;
@@ -136,22 +100,13 @@ public class GridItem extends Item {
/**
* Parent grid instance.
*/
- private Grid parent;
+ private final Grid parent;
/**
* Parent item (if a child item).
*/
private GridItem parentItem;
- /**
- * List of text for each column.
- */
- private ArrayList texts = new ArrayList();
-
- /**
- * List of tooltips for each column.
- */
- private ArrayList tooltips = new ArrayList();
/**
* Is visible?
@@ -183,6 +138,11 @@ public class GridItem extends Item {
* been sent a SWT.SetData event.
*/
private boolean hasSetData = false;
+
+ /**
+ * Row GridItem index
+ */
+ private final int row;
/**
* Creates a new instance of this class and places the item at the end of
@@ -234,10 +194,10 @@ public class GridItem extends Item {
super(parent, style, index);
this.parent = parent;
+
+ dataVisualizer = parent.getDataVisualizer();
- init();
-
- parent.newItem(this, index, true);
+ row = parent.newItem(this, index, true);
parent.newRootItem(this, index);
}
@@ -264,6 +224,24 @@ public class GridItem extends Item {
public GridItem(GridItem parent, int style) {
this(parent, style, -1);
}
+
+
+ /**
+ * The dataVisualizer is used by gridItem children.
+ */
+ private DataVisualizer gridItemChildrenDataVisualizer;
+
+ /**
+ * @return GridItem children dataVisualizer.
+ */
+ protected DataVisualizer getGridItemChildrenDataVisualizer() {
+ if(gridItemChildrenDataVisualizer == null) {
+ gridItemChildrenDataVisualizer = parent.getDataVisualizer().createAndGetChildenGridItemDataVisualizer();
+ }
+ return gridItemChildrenDataVisualizer;
+ }
+
+
/**
* Creates a new instance of this class as a child node of the given Grid
@@ -292,14 +270,16 @@ public class GridItem extends Item {
parentItem = parent;
this.parent = parentItem.getParent();
-
- init();
+
+ dataVisualizer = this.parentItem.getGridItemChildrenDataVisualizer();
this.parent.newItem(this, index, false);
level = parentItem.getLevel() + 1;
parentItem.newItem(this, index);
+
+ row = parentItem.indexOf(this);
if (parent.isVisible() && parent.isExpanded()) {
setVisible(true);
@@ -311,6 +291,7 @@ public class GridItem extends Item {
/**
* {@inheritDoc}
*/
+ @Override
public void dispose() {
if (!parent.isDisposing()) {
parent.removeItem(this);
@@ -486,13 +467,9 @@ public class GridItem extends Item {
checkWidget();
handleVirtual();
+
+ return dataVisualizer.getBackground(row, index);
- Color c = (Color) backgrounds.get(index);
- // if (c == null)
- // {
- // c = getBackground();
- // }
- return c;
}
/**
@@ -592,7 +569,7 @@ public class GridItem extends Item {
*/
public boolean getChecked() {
checkWidget();
- return getChecked(0);
+ return dataVisualizer.getChecked(row, 0);
}
/**
@@ -614,11 +591,7 @@ public class GridItem extends Item {
handleVirtual();
- Boolean b = (Boolean) checks.get(index);
- if (b == null) {
- return false;
- }
- return b.booleanValue();
+ return dataVisualizer.getChecked(row, index);
}
/**
@@ -637,11 +610,7 @@ public class GridItem extends Item {
*/
public int getColumnSpan(int index) {
checkWidget();
- Integer i = (Integer) columnSpans.get(index);
- if (i == null) {
- return 0;
- }
- return i.intValue();
+ return dataVisualizer.getColumnSpan(row, index);
}
/**
@@ -660,14 +629,8 @@ public class GridItem extends Item {
*/
public int getRowSpan(int index) {
checkWidget();
- if (index >= 0 && index < rowSpans.size()) {
- Integer i = (Integer) rowSpans.get(index);
- if (i != null) {
- return i.intValue();
- }
- }
-
- return 0;
+
+ return dataVisualizer.getRowSpan(row, index);
}
/**
@@ -689,6 +652,8 @@ public class GridItem extends Item {
}
return defaultFont;
}
+
+ private final DataVisualizer dataVisualizer;
/**
* Returns the font that the receiver will use to paint textual information
@@ -710,11 +675,7 @@ public class GridItem extends Item {
handleVirtual();
- Font f = (Font) fonts.get(index);
- if (f == null) {
- f = getFont();
- }
- return f;
+ return dataVisualizer.getFont(row, index);
}
/**
@@ -755,11 +716,7 @@ public class GridItem extends Item {
handleVirtual();
- Color c = (Color) foregrounds.get(index);
- if (c == null) {
- c = getForeground();
- }
- return c;
+ return dataVisualizer.getForeground(row, index);
}
/**
@@ -801,11 +758,7 @@ public class GridItem extends Item {
handleVirtual();
- Boolean b = (Boolean) grayeds.get(index);
- if (b == null) {
- return false;
- }
- return b.booleanValue();
+ return dataVisualizer.getGrayed(row, index);
}
/**
@@ -821,9 +774,10 @@ public class GridItem extends Item {
/**
* {@inheritDoc}
*/
+ @Override
public Image getImage() {
checkWidget();
- return getImage(0);
+ return dataVisualizer.getImage(row, 0);
}
/**
@@ -846,7 +800,7 @@ public class GridItem extends Item {
handleVirtual();
- return (Image) images.get(index);
+ return dataVisualizer.getImage(row, index);
}
/**
@@ -1002,9 +956,10 @@ public class GridItem extends Item {
/**
* {@inheritDoc}
*/
+ @Override
public String getText() {
checkWidget();
- return getText(0);
+ return dataVisualizer.getText(row, 0);
}
/**
@@ -1027,13 +982,7 @@ public class GridItem extends Item {
handleVirtual();
- String s = (String) texts.get(index);
- // SWT TableItem returns empty if never set
- // so we return empty to ensure API compatibility
- if (s == null) {
- return "";
- }
- return s;
+ return dataVisualizer.getText(row, index);
}
/**
@@ -1129,7 +1078,7 @@ public class GridItem extends Item {
if (background != null && background.isDisposed()) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
- backgrounds.set(index, background);
+ dataVisualizer.setBackground(row, index, background);
parent.redraw();
}
@@ -1148,7 +1097,7 @@ public class GridItem extends Item {
*/
public void setChecked(boolean checked) {
checkWidget();
- setChecked(0, checked);
+ dataVisualizer.setChecked(row, 0, checked);
parent.redraw();
}
@@ -1169,7 +1118,7 @@ public class GridItem extends Item {
*/
public void setChecked(int index, boolean checked) {
checkWidget();
- checks.set(index, new Boolean(checked));
+ dataVisualizer.setChecked(row, index, checked);
parent.redraw();
}
@@ -1191,7 +1140,7 @@ public class GridItem extends Item {
*/
public void setColumnSpan(int index, int span) {
checkWidget();
- columnSpans.set(index, new Integer(span));
+ dataVisualizer.setColumnSpan(row, index, span);
parent.setHasSpanning(true);
parent.redraw();
}
@@ -1214,7 +1163,7 @@ public class GridItem extends Item {
*/
public void setRowSpan(int index, int span) {
checkWidget();
- rowSpans.set(index, new Integer(span));
+ dataVisualizer.setRowSpan(row, index, span);
parent.setHasSpanning(true);
parent.redraw();
}
@@ -1383,7 +1332,7 @@ public class GridItem extends Item {
if (font != null && font.isDisposed()) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
- fonts.set(index, font);
+ dataVisualizer.setFont(row,index,font);
parent.redraw();
}
@@ -1443,7 +1392,7 @@ public class GridItem extends Item {
if (foreground != null && foreground.isDisposed()) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
- foregrounds.set(index, foreground);
+ dataVisualizer.setForeground(row, index, foreground);
parent.redraw();
}
@@ -1464,7 +1413,7 @@ public class GridItem extends Item {
*/
public void setGrayed(boolean grayed) {
checkWidget();
- setGrayed(0, grayed);
+ dataVisualizer.setGrayed(row, 0, grayed);
parent.redraw();
}
@@ -1487,7 +1436,7 @@ public class GridItem extends Item {
*/
public void setGrayed(int index, boolean grayed) {
checkWidget();
- grayeds.set(index, new Boolean(grayed));
+ dataVisualizer.setGrayed(row, index, grayed);
parent.redraw();
}
@@ -1568,8 +1517,9 @@ public class GridItem extends Item {
/**
* {@inheritDoc}
*/
+ @Override
public void setImage(Image image) {
- setImage(0, image);
+ dataVisualizer.setImage(row, 0, image);
parent.redraw();
}
@@ -1597,7 +1547,7 @@ public class GridItem extends Item {
if (image != null && image.isDisposed()) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
- images.set(index, image);
+ dataVisualizer.setImage(row, index, image);
parent.imageSetOnItem(index, this);
@@ -1628,15 +1578,16 @@ public class GridItem extends Item {
if (text == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
- texts.set(index, text);
+ dataVisualizer.setText(row, index, text);
parent.redraw();
}
/**
* {@inheritDoc}
*/
+ @Override
public void setText(String string) {
- setText(0, string);
+ dataVisualizer.setText(row, 0, string);
parent.redraw();
}
@@ -1953,11 +1904,7 @@ public class GridItem extends Item {
if (!parent.getColumn(index).getCheckable())
return false;
- Boolean b = (Boolean) checkable.get(index);
- if (b == null) {
- return true;
- }
- return b.booleanValue();
+ return dataVisualizer.getCheckable(row, index);
}
/**
@@ -1980,7 +1927,7 @@ public class GridItem extends Item {
*/
public void setCheckable(int index, boolean checked) {
checkWidget();
- checkable.set(index, new Boolean(checked));
+ dataVisualizer.setCheckable(row, index, checked);
}
/**
@@ -2002,9 +1949,7 @@ public class GridItem extends Item {
handleVirtual();
- String s = (String) tooltips.get(index);
-
- return s;
+ return dataVisualizer.getToolTipText(row, index);
}
/**
@@ -2024,22 +1969,9 @@ public class GridItem extends Item {
*/
public void setToolTipText(int index, String tooltip) {
checkWidget();
- tooltips.set(index, tooltip);
+ dataVisualizer.setToolTipText(row, index, tooltip);
}
- private void init() {
- ensureSize(backgrounds);
- ensureSize(checks);
- ensureSize(checkable);
- ensureSize(fonts);
- ensureSize(foregrounds);
- ensureSize(grayeds);
- ensureSize(images);
- ensureSize(texts);
- ensureSize(columnSpans);
- ensureSize(rowSpans);
- ensureSize(tooltips);
- }
/**
* Notifies the item that a column has been removed.
@@ -2048,42 +1980,13 @@ public class GridItem extends Item {
* index of column removed.
*/
void columnRemoved(int index) {
- removeValue(index, backgrounds);
- removeValue(index, checks);
- removeValue(index, checkable);
- removeValue(index, fonts);
- removeValue(index, foregrounds);
- removeValue(index, grayeds);
- removeValue(index, images);
- removeValue(index, texts);
- removeValue(index, columnSpans);
- removeValue(index, rowSpans);
- removeValue(index, tooltips);
+ dataVisualizer.removeIndex(row);
}
void columnAdded(int index) {
- insertValue(index, backgrounds);
- insertValue(index, checks);
- insertValue(index, checkable);
- insertValue(index, fonts);
- insertValue(index, foregrounds);
- insertValue(index, grayeds);
- insertValue(index, images);
- insertValue(index, texts);
- insertValue(index, columnSpans);
- insertValue(index, rowSpans);
- insertValue(index, tooltips);
hasSetData = false;
}
- private void insertValue(int index, List list) {
- if (index == -1) {
- list.add(null);
- } else {
- list.add(index, null);
- }
- }
-
private void removeValue(int index, List list) {
if (list.size() > index) {
list.remove(index);
@@ -2122,17 +2025,6 @@ public class GridItem extends Item {
* recursively, and <code>false</code> otherwise
*/
void clear(boolean allChildren) {
- backgrounds.clear();
- checks.clear();
- checkable.clear();
- columnSpans.clear();
- rowSpans.clear();
- fonts.clear();
- foregrounds.clear();
- grayeds.clear();
- images.clear();
- texts.clear();
- tooltips.clear();
defaultForeground = null;
defaultBackground = null;
@@ -2151,6 +2043,15 @@ public class GridItem extends Item {
}
}
- init();
+ }
+
+ /**
+ * this method call only super.dispose, nothing else..
+ */
+ public void disposeOnly() {
+ for (int i = children.size() - 1; i >= 0; i--) {
+ ((GridItem) children.get(i)).disposeOnly();
+ }
+ super.dispose();
}
}
diff --git a/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/RowColumnBigDataVisualizer.java b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/RowColumnBigDataVisualizer.java
new file mode 100644
index 0000000..31f046f
--- /dev/null
+++ b/widgets/grid/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/RowColumnBigDataVisualizer.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Mirko Paturzo (Exeura srl).
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mirko Paturzo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+
+/**
+ * This class can be used to provide general visualization values for various aspects
+ * of the GridItem like background, font and text. Your own subclass of this class
+ * could be used in combination with the JFace LabelProvider if you use the GridViewer.
+ * This dataVisualizer implementation replace the current paradigma of GridItem with
+ * memory less.
+ * This implementation is preferable in the case where there are more columns than rows.
+ *
+ * @author Mirko Paturzo <mirko.paturzo@exeura.eu>
+ *
+ */
+public class RowColumnBigDataVisualizer extends ColumnRowBigDataVisualizer{
+
+
+ /**
+ * Create {@link RowColumnBigDataVisualizer} with default value
+ * @param defaultBackground
+ * @param defaultForeground
+ * @param defaultFont
+ */
+ public RowColumnBigDataVisualizer (Color defaultBackground, Color defaultForeground, Font defaultFont) {
+ super(defaultBackground, defaultForeground, defaultFont);
+ }
+
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.ColumnRowBigDataVisualizer#clearRow(int)
+ */
+ @Override
+ public void clearRow(int row) {
+ removeIndex(row);
+ }
+ /**
+ * put value on maps.. inverted index from {@link ColumnRowBigDataVisualizer}
+ * @param map
+ * @param row
+ * @param column
+ * @param value
+ */
+ @Override
+ protected <T> void put(Map<Integer, List<T>> map, int row, int column,
+ T value) {
+ List<T> list = map.get(column);
+ if(list == null) {
+ list = new ArrayList<T>();
+ map.put(column, list);
+ }
+ while(row > list.size()) {
+ list.add(null);
+ }
+ list.add(row, value);
+ }
+ /**
+ * get value or default.. inverted index on {@link ColumnRowBigDataVisualizer}
+ * @param map
+ * @param row
+ * @param column
+ * @param defaultValue
+ * @return T
+ */
+ @Override
+ protected <T> T getValueOrDefault(Map<Integer, List<T>> map, int row, int column, T defaultValue) {
+ List<T> list = map.get(column);
+ if(list == null)
+ return defaultValue;
+
+ T t = list.get(row);
+
+ if(t == null)
+ return defaultValue;
+
+ return t;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.grid.ColumnRowBigDataVisualizer#createAndGetChildenGridItemDataVisualizer()
+ */
+ @Override
+ public DataVisualizer createAndGetChildenGridItemDataVisualizer() {
+ return new RowColumnBigDataVisualizer(getDefaultBackground(), getDefaultForeground(), getDefaultFont());
+ }
+}