Skip to content

Commit d3c010d

Browse files
committed
Fix: Error when trying to delete selected tab item
The selection is not cleared when a tab item has been deleted. When updating the widget, we then run into an unhandled exception because the item we try to select no longer exists.
1 parent 96d5cf1 commit d3c010d

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

org.eclipse.wb.rcp/src/org/eclipse/wb/internal/rcp/model/widgets/AbstractTabItemInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2023 Google, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -75,6 +75,7 @@ public void selecting(ObjectInfo object, boolean[] refreshFlag) throws Exception
7575
@Override
7676
public void before(ObjectInfo parent, ObjectInfo child) throws Exception {
7777
if (child == m_this) {
78+
getFolder().m_selectedItem = null;
7879
ControlInfo ourControl = getControl();
7980
if (ourControl != null) {
8081
ourControl.delete();

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/rcp/model/widgets/CTabFolderTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2023 Google, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -252,6 +252,35 @@ public void test_selecting() throws Exception {
252252
}
253253
}
254254

255+
/**
256+
* Test whether the selection is removed when the tab item is deleted.
257+
*
258+
* @see <a href=
259+
* "https://github.com/eclipse-windowbuilder/windowbuilder/issues/556">here</a>
260+
*/
261+
@Test
262+
public void test_deleteSelectedTabItem() throws Exception {
263+
CompositeInfo shell = parseComposite(
264+
"public class Test extends Shell {",
265+
" public Test() {",
266+
" setLayout(new FillLayout());",
267+
" CTabFolder tabFolder = new CTabFolder(this, SWT.NONE);",
268+
" CTabItem item_1 = new CTabItem(tabFolder, SWT.NONE);",
269+
" CTabItem item_2 = new CTabItem(tabFolder, SWT.NONE);",
270+
" }",
271+
"}");
272+
shell.refresh();
273+
CTabFolderInfo tabFolder = (CTabFolderInfo) shell.getChildrenControls().get(0);
274+
CTabItemInfo item_1 = tabFolder.getItems2().get(0);
275+
CTabItemInfo item_2 = tabFolder.getItems2().get(1);
276+
277+
item_2.doSelect();
278+
assertEquals(tabFolder.getSelectedItem(), item_2);
279+
280+
item_2.delete();
281+
assertEquals(tabFolder.getSelectedItem(), item_1);
282+
}
283+
255284
/**
256285
* We should show on design canvas only {@link ControlInfo}'s of expanded {@link CTabItemInfo}'s.
257286
*/

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/rcp/model/widgets/TabFolderTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2023 Google, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -256,6 +256,35 @@ public void test_selecting() throws Exception {
256256
}
257257
}
258258

259+
/**
260+
* Test whether the selection is removed when the tab item is deleted.
261+
*
262+
* @see <a href=
263+
* "https://github.com/eclipse-windowbuilder/windowbuilder/issues/556">here</a>
264+
*/
265+
@Test
266+
public void test_deleteSelectedTabItem() throws Exception {
267+
CompositeInfo shell = parseComposite(
268+
"public class Test extends Shell {",
269+
" public Test() {",
270+
" setLayout(new FillLayout());",
271+
" TabFolder tabFolder = new TabFolder(this, SWT.NONE);",
272+
" TabItem item_1 = new TabItem(tabFolder, SWT.NONE);",
273+
" TabItem item_2 = new TabItem(tabFolder, SWT.NONE);",
274+
" }",
275+
"}");
276+
shell.refresh();
277+
TabFolderInfo tabFolder = (TabFolderInfo) shell.getChildrenControls().get(0);
278+
TabItemInfo item_1 = tabFolder.getItems2().get(0);
279+
TabItemInfo item_2 = tabFolder.getItems2().get(1);
280+
281+
item_2.doSelect();
282+
assertEquals(tabFolder.getSelectedItem(), item_2);
283+
284+
item_2.delete();
285+
assertEquals(tabFolder.getSelectedItem(), item_1);
286+
}
287+
259288
/**
260289
* We should show on design canvas only {@link ControlInfo}'s of expanded {@link TabItemInfo}'s.
261290
*/

0 commit comments

Comments
 (0)