}
@Override
public void updateHosts(SortedSet<ServerGroup> groups, final int index) {
// validation
HtmlGenerator html = new HtmlGenerator();
if (groups == null || groups.isEmpty()) {
// no server/groups available ...
HTML blank = new HTML("There don't seem to be any servers configured on this system.");
container.clear();
container.add(blank);
return;
}
// initialization
assignColors(groups);
List<HostInfo> hosts = groups.first().getHosts();
this.hostSize = hosts.size();
this.visibleHosts = min(TopologyPresenter.VISIBLE_HOSTS_COLUMNS, hostSize);
this.hostIndex = index;
this.hostIndex = max(0, this.hostIndex);
this.hostIndex = min(this.hostIndex, this.hostSize - 1);
int endIndex = min(this.hostIndex + TopologyPresenter.VISIBLE_HOSTS_COLUMNS, hostSize);
// start table and add columns
html.startTable().appendHtmlConstant("<colgroup>");
int columnWidth = HOSTS_COLUMNS / (endIndex - this.hostIndex);
html.appendColumn(SERVER_GROUPS_COLUMN);
for (int i = this.hostIndex; i < endIndex; i++) {
html.appendColumn(columnWidth);
}
html.appendHtmlConstant("</colgroup>");
// first row contains host names
html.appendHtmlConstant("<thead><tr><th class='cellTableHeader'>Hosts →<br/>Groups ↓</th>");
for (int i = this.hostIndex; i < endIndex; i++) {
HostInfo host = hosts.get(i);
html.appendHost(host);
}
html.appendHtmlConstant("</tr></thead>");
// remaining rows contain server groups and server instances
html.appendHtmlConstant("<tbody>");
for (ServerGroup group : groups) {
for (int serverIndex = 0; serverIndex < group.maxServersPerHost; serverIndex++) {
html.appendHtmlConstant("<tr>");
if (serverIndex == 0) {
html.appendServerGroup(group);
}
for (int i = this.hostIndex; i < endIndex; i++) {
HostInfo host = hosts.get(i);
List<ServerInstance> servers = group.serversPerHost.get(host);
if (servers.isEmpty() || serverIndex >= servers.size()) {
html.emptyCell();
} else {
html.appendServer(group, host.getName(), servers.get(serverIndex));
}
}
html.appendHtmlConstant("</tr>");
}
}
html.appendHtmlConstant("</tbody>").endTable();
// create html panel and register events
HTMLPanel panel = html.createPanel();
for (String id : html.getLifecycleIds()) {
com.google.gwt.user.client.Element element = panel.getElementById(id);
if (element != null) {
DOM.setEventListener(element, lifecycleLinkListener);
DOM.sinkEvents(element, ONCLICK);
}