void () { myProject.getMessageBus().connect().subscribe(ServerConnectionListener.TOPIC, new ServerConnectionListener() { private final Set<ServerConnection<?>> myConnectionsToExpand = new HashSet<>(); @Override public void onConnectionCreated(@NotNull ServerConnection<?> connection) { RemoteServersServiceViewContributor contributor = findContributor(connection.getServer()); if (contributor != null) { myProject.getMessageBus().syncPublisher(ServiceEventListener.TOPIC) .handle(ServiceEventListener.ServiceEvent.createResetEvent(contributor.getClass())); } } @Override public void onConnectionStatusChanged(@NotNull ServerConnection<?> connection) { RemoteServer<?> server = connection.getServer(); RemoteServersServiceViewContributor contributor = findContributor(server); if (contributor != null) { myProject.getMessageBus().syncPublisher(ServiceEventListener.TOPIC) .handle(ServiceEventListener.ServiceEvent.createResetEvent(contributor.getClass())); updateServerContent(myServerToContent.get(server), connection); if (connection.getStatus() == ConnectionStatus.CONNECTED) { // connectionStatusChanged is also called for errors, don't initiate polling once again, IDEA-259400 if (Strings.areSameInstance(connection.getStatusText(), connection.getStatus().getPresentableText())) { // effectively, checks for no error myConnectionsToExpand.add(connection); pollDeployments(connection); } } else { myConnectionsToExpand.remove(connection); } } } @Override public void onDeploymentsChanged(@NotNull ServerConnection<?> connection) { RemoteServer<?> server = connection.getServer(); RemoteServersServiceViewContributor contributor = findContributor(server); if (contributor != null) { ServiceEventListener.ServiceEvent event = contributor.createDeploymentsChangedEvent(connection); boolean justConnected = myConnectionsToExpand.remove(connection); if (event == null && justConnected) { event = ServiceEventListener.ServiceEvent.createResetEvent(contributor.getClass()); } if (event != null) { myProject.getMessageBus().syncPublisher(ServiceEventListener.TOPIC).handle(event); } updateServerContent(myServerToContent.get(server), connection); if (justConnected) { RemoteServerNode serverNode = new RemoteServerNode(myProject, connection.getServer(), contributor); ServiceViewManager.getInstance(myProject).expand(serverNode, contributor.getClass()); } } } }); myProject.getMessageBus().connect().subscribe(RemoteServerListener.TOPIC, new RemoteServerListener() { @Override public void serverAdded(@NotNull RemoteServer<?> server) { RemoteServersServiceViewContributor contributor = findContributor(server); if (contributor != null) { myServerToContent.put(server, createMessagePanel()); myProject.getMessageBus().syncPublisher(ServiceEventListener.TOPIC) .handle(ServiceEventListener.ServiceEvent.createResetEvent(contributor.getClass())); } } @Override public void serverRemoved(@NotNull RemoteServer<?> server) { RemoteServersServiceViewContributor contributor = findContributor(server); if (contributor != null) { myProject.getMessageBus().syncPublisher(ServiceEventListener.TOPIC) .handle(ServiceEventListener.ServiceEvent.createResetEvent(contributor.getClass())); } myServerToContent.remove(server); } }); }