Search in sources :

Example 1 with MarkerCluster

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.ui.MarkerCluster in project opennms by OpenNMS.

the class NodeMarkerClusterCallback method run.

@Override
public final void run(final MarkerClusterEvent event) {
    final StringBuilder sb = new StringBuilder();
    final MarkerCluster cluster = event.getMarkerCluster();
    final List<JSNodeMarker> markers = (List<JSNodeMarker>) cluster.getAllChildMarkers();
    LOG.fine("Clicked, processing " + markers.size() + " markers.");
    Collections.sort(markers, new NodeMarkerComparator());
    if (markers.size() == 1) {
        final JSNodeMarker marker = markers.get(0);
        sb.append("<div class=\"node-marker-single\">");
        sb.append(getPopupTextForMarker(marker));
        sb.append("</div>");
    } else {
        final StringBuilder nodeListBuilder = new StringBuilder();
        final StringBuilder nodeBuilder = new StringBuilder();
        int unacked = 0;
        final ListIterator<JSNodeMarker> iterator = markers.listIterator();
        while (iterator.hasNext()) {
            final JSNodeMarker marker = iterator.next();
            unacked += marker.getUnackedCount();
            nodeBuilder.append("<tr class=\"node-marker-" + marker.getSeverityLabel() + "\">");
            nodeBuilder.append("<td class=\"node-marker-label\">");
            nodeBuilder.append("<a class=\"node\" href=\"element/node.jsp?node=").append(marker.getNodeId()).append("\" " + TARGET_NONE + ">").append(marker.getNodeLabel()).append("</a>");
            nodeBuilder.append("</td>");
            nodeBuilder.append("<td class=\"node-marker-ipaddress\">");
            nodeBuilder.append(marker.getIpAddress());
            nodeBuilder.append("</td>");
            nodeBuilder.append("<td class=\"node-marker-severity severity " + marker.getSeverityLabel() + "\">");
            nodeBuilder.append("<a href=\"alarm/list.htm?sortby=id&acktype=unack&limit=20&filter=node%3D").append(marker.getNodeId()).append("\" " + TARGET_BLANK + ">").append(marker.getSeverityLabel()).append("</a>");
            nodeBuilder.append("</td>");
            nodeBuilder.append("</tr>");
            nodeListBuilder.append(marker.getNodeId());
            if (iterator.hasNext()) {
                nodeListBuilder.append(",");
            }
        }
        sb.append("<div class=\"node-marker-multiple\">");
        sb.append("<h2># of nodes: ").append(markers.size()).append(" ");
        sb.append("(").append(unacked).append(" Unacknowledged Alarms)");
        sb.append("</h2>");
        if (nodeListBuilder.length() > 0) {
            sb.append("<p><a " + TARGET_BLANK + " href=\"topology?provider=Enhanced+Linkd&focus-vertices=" + nodeListBuilder.toString() + "\">View in Topology Map</a>");
        }
        sb.append("<table class=\"node-marker-list\">").append(nodeBuilder).append("</table>");
        sb.append("</div>");
    }
    final PopupOptions options = new PopupOptions();
    options.setMaxWidth(500);
    options.setProperty("maxHeight", 250);
    options.setProperty("className", "node-marker-popup");
    final Popup popup = new Popup(options);
    popup.setContent(sb.toString());
    popup.setLatLng(cluster.getLatLng());
    /*
        final Element element = popup.getJSObject().cast();
        DomEvent.addListener(new AbstractDomEventCallback("keydown", null) {
            @Override protected void onEvent(final NativeEvent event) {
                VConsole.log("marker cluster popup keydown event");
            }
        }, element);
         */
    final Map map = new Map(cluster.getGroup().getMapObject());
    LOG.fine("current zoom: " + map.getZoom() + ", max zoom: " + map.getMaxZoom());
    if (map.getZoom() == map.getMaxZoom()) {
        LOG.fine("at max zoom, skipping popup");
    } else {
        PopupImpl.openOn(popup.getJSObject(), cluster.getGroup().getMapObject());
    }
}
Also used : Popup(org.discotools.gwt.leaflet.client.popup.Popup) List(java.util.List) PopupOptions(org.discotools.gwt.leaflet.client.popup.PopupOptions) MarkerCluster(org.opennms.features.vaadin.nodemaps.internal.gwt.client.ui.MarkerCluster) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) Map(org.opennms.features.vaadin.nodemaps.internal.gwt.client.Map)

Aggregations

List (java.util.List)1 Popup (org.discotools.gwt.leaflet.client.popup.Popup)1 PopupOptions (org.discotools.gwt.leaflet.client.popup.PopupOptions)1 JSNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)1 Map (org.opennms.features.vaadin.nodemaps.internal.gwt.client.Map)1 MarkerCluster (org.opennms.features.vaadin.nodemaps.internal.gwt.client.ui.MarkerCluster)1