private int addCommunication(final AbstractCommunication communication) {
if(!showedCommunications.contains(communication)) {
showedCommunications.add(communication);
final Component component = communication.getComponent();
final ClosableTabComponent tab = communication.getTabComponent();
commTabs.addTab(communication.getJID(), component);
int index = commTabs.indexOfComponent(component);
if(index != showedCommunications.indexOf(communication)) {
throw new AssertionError("Tab-Comm Index consistency corrupted.");
}
commTabs.setTabComponentAt(index, tab);
tab.addCloseActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
hideCommunication(communication);
tab.removeCloseActionListener(this);
}
});
}
return showedCommunications.indexOf(communication);