ActionCallback (@NotNull Content content, boolean dispose) { ThreadingAssertions.assertEventDispatchThread(); int indexToBeRemoved = getIndexOfContent(content); if (indexToBeRemoved == -1) { return ActionCallback.REJECTED; } try { Content selection = mySelection.isEmpty() ? null : mySelection.get(mySelection.size() - 1); int selectedIndex = selection != null ? contents.indexOf(selection) : -1; if (!fireContentRemoveQuery(content, indexToBeRemoved) || !content.isValid()) { return ActionCallback.REJECTED; } boolean wasSelected = isSelected(content); if (wasSelected) { removeFromSelection(content); } int indexToSelect = -1; if (wasSelected) { int i = indexToBeRemoved - 1; if (i >= 0) { indexToSelect = i; } else if (getContentCount() > 1) { indexToSelect = 0; } } else if (selectedIndex > indexToBeRemoved) { indexToSelect = selectedIndex - 1; } mySelectionHistory.remove(content); myContentWithChangedComponent.remove(content); contents.remove(content); content.removePropertyChangeListener(this); fireContentRemoved(content, indexToBeRemoved); ((ContentImpl)content).setManager(null); if (dispose) { Disposer.dispose(content); } int newSize = contents.size(); if (newSize > 0) { if (indexToSelect > -1) { final Content toSelect = !mySelectionHistory.isEmpty() ? mySelectionHistory.get(0) : contents.get(indexToSelect); if (!isSelected(toSelect)) { if (myUI.isSingleSelection()) { ActionCallback result = new ActionCallback(); setSelectedContentCB(toSelect).notify(result); return result; } else { addSelectedContent(toSelect); } } } } else { mySelection.clear(); } return ActionCallback.DONE; } finally { if (ApplicationManager.getApplication().isDispatchThread() && !myDisposed && contents.isEmpty()) { // cleanup visibleComponent in TabbedPaneUI only if there is no content left, // otherwise immediate adding of a new content will lead to having visible two TabWrapper component at the same time. myUI.getComponent().updateUI(); //cleanup visibleComponent from Alloy...TabbedPaneUI } } }