Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Yan2019-03-13 18:38:43 +0000
committerXi Yan2019-03-15 19:58:04 +0000
commit2abccfe09575cf3baf431315f6275ad055f7f232 (patch)
tree944f829d75835cf530dc49e51d56c0608e76ff62
parentd167dd39e3533803e618b0bfdac2ba9b98b35e36 (diff)
downloadeclipse.platform.swt-2abccfe09575cf3baf431315f6275ad055f7f232.tar.gz
eclipse.platform.swt-2abccfe09575cf3baf431315f6275ad055f7f232.tar.xz
eclipse.platform.swt-2abccfe09575cf3baf431315f6275ad055f7f232.zip
Bug 545139 - Creating TableColumn after TableItem leeds to erase of
TableItem "strings" field Fix inconsistency in GTK where creating the first TableColumn after TableItems overwrites the cached text of TableItem. Change-Id: I65d1f760a9b05dadcc446ff1006d5122273f20c6 Signed-off-by: Xi Yan <xixiyan@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java9
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545139_TableColumnEraseString.java81
2 files changed, 87 insertions, 3 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
index a8850a2d64..fe2004a0ec 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
@@ -700,22 +700,25 @@ void createItem (TableColumn column, int index) {
for (int i=0; i<itemCount; i++) {
TableItem item = items [i];
if (item != null) {
+ // Bug 545139: For consistency, do not wipe out content of first TableColumn created after TableItem
+ boolean doNotModify;
Font [] cellFont = item.cellFont;
- if (cellFont != null) {
+ doNotModify = columnCount == 1 && cellFont != null && cellFont.length == columnCount;
+ if (cellFont != null && !doNotModify) {
Font [] temp = new Font [columnCount];
System.arraycopy (cellFont, 0, temp, 0, index);
System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1);
item.cellFont = temp;
}
String [] strings = item.strings;
- if (strings != null) {
+ doNotModify = columnCount == 1 && strings != null && strings.length == columnCount;
+ if (strings != null && !doNotModify) {
String [] temp = new String [columnCount];
System.arraycopy (strings, 0, temp, 0, index);
System.arraycopy (strings, index, temp, index+1, columnCount-index-1);
temp [index] = "";
item.strings = temp;
}
-
}
}
}
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545139_TableColumnEraseString.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545139_TableColumnEraseString.java
new file mode 100644
index 0000000000..c3f92d0cd0
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545139_TableColumnEraseString.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+
+public class Bug545139_TableColumnEraseString {
+
+ private static boolean COLUMN_BEFORE = false;
+ private static int NUM_ITEMS = 5;
+ private static int NUM_COLS = 5;
+
+ public static void main(String args[]) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout(2, false));
+ shell.setSize(500, 200);
+
+ Table table = new Table(shell, SWT.NONE);
+ table.setHeaderVisible(true);
+ TableColumn [] columns = new TableColumn [NUM_COLS];
+ if (COLUMN_BEFORE) {
+ for (int i = 0; i < NUM_COLS; i++) {
+ TableColumn col = new TableColumn(table, SWT.NONE);
+ col.setText("Column " + i);
+ columns [i] = col;
+ }
+ }
+
+ TableItem [] items = new TableItem [5];
+ for (int i = 0; i < NUM_ITEMS; i++) {
+ TableItem item = new TableItem(table, SWT.NONE);
+ String [] textArray = new String [NUM_COLS];
+ for (int col = 0; col < NUM_COLS; col++) {
+ textArray [col] = "Col " + col + " Item " + i;
+ }
+ item.setText(textArray);
+ items [i] = item;
+ }
+
+ if (!COLUMN_BEFORE) {
+ for (int i = 0; i < NUM_COLS; i++) {
+ TableColumn col = new TableColumn(table, SWT.NONE);
+ col.setText("Column " + i);
+ columns [i] = col;
+ }
+ }
+
+ for (int i = 0; i < NUM_ITEMS; i++) {
+ System.out.println(i + " --> " + items[i].getText());
+ }
+
+ for (TableColumn col : columns) {
+ col.pack();
+ }
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ }
+} \ No newline at end of file

Back to the top