public CloseAllTabAction() {
super(ResourceBoundles.getResourceBundle().getString("@@tool.tab.closeAll"));
}
public void actionPerformed(ActionEvent e) {
ToolWindowTab selectedTab = null;
for (ToolWindowTab tab : toolWindow.getToolWindowTabs()) {
if (tab.isSelected()) {
selectedTab = tab;
continue;
}
tryToClose(tab);
}
tryToClose(selectedTab);
}
protected void tryToClose(ToolWindowTab tab) {
if (tab != null && tab.isCloseable()) {
ToolWindowTabEvent event = new ToolWindowTabEvent(this, ToolWindowTabEvent.ActionId.TAB_REMOVING,
toolWindow, tab);
for (ToolWindowListener listener : toolWindow.getToolWindowListeners()) {
boolean result = listener.toolWindowTabRemoving(event);
if (!result)
break;
}
toolWindow.removeToolWindowTab(tab);
}
}
}
});
toolWindow.addToolWindowListener(new ToolWindowListener() {
public void toolWindowTabAdded(ToolWindowTabEvent event) {
if (tabContainer.getComponentCount() == 0)
initTabs();
else
addTab(event.getToolWindowTab());
setPopupButtonVisibility();
}
public boolean toolWindowTabRemoving(ToolWindowTabEvent event) {
return true;
}
public void toolWindowTabRemoved(ToolWindowTabEvent event) {
ToolWindowTab nextTab = removeTab(event.getToolWindowTab());
if (event.getToolWindowTab().isSelected()) {
ToolWindowTab[] tabs = toolWindow.getToolWindowTabs();
if (tabs.length > 0) {
if (nextTab != null)
nextTab.setSelected(true);
else
tabs[0].setSelected(true);
}
}