Search in sources :

Example 1 with NodeMarker

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

the class NodeMapWidget method zoomToFit.

private void zoomToFit() {
    // zoom on first run
    if (m_firstUpdate) {
        LOG.info("NodeMapWidget.zoomToFit(): first update, zooming to bounds.");
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                if (m_firstUpdate) {
                    final List<JSNodeMarker> allMarkers = m_markerContainer.getAllMarkers();
                    if (allMarkers.size() == 0) {
                        LOG.info("NodeMapWidget.zoomToFit(): no bounds yet, skipping.");
                    } else {
                        final LatLngBounds bounds = new LatLngBounds();
                        for (final NodeMarker marker : allMarkers) {
                            LOG.info("NodeMapWidget.zoomToFit(): processing marker: " + marker);
                            final Coordinates coordinates = marker.getCoordinates();
                            if (coordinates == null) {
                                LOG.log(Level.WARNING, "NodeMapWidget.zoomToFit(): no coordinates found for marker! " + marker);
                            } else {
                                bounds.extend(JSNodeMarker.coordinatesToLatLng(coordinates));
                            }
                        }
                        LOG.info("NodeMapWidget.zoomToFit(): setting boundary to " + bounds.toBBoxString() + ".");
                        m_map.fitBounds(bounds);
                        m_firstUpdate = false;
                    }
                }
            }
        });
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) NodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker) Coordinates(org.opennms.features.vaadin.nodemaps.internal.gwt.client.Coordinates) LatLngBounds(org.discotools.gwt.leaflet.client.types.LatLngBounds) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with NodeMarker

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

the class MarkerContainer method getDisabledMarkers.

public List<JSNodeMarker> getDisabledMarkers() {
    final ArrayList<JSNodeMarker> markers = new ArrayList<>();
    final List<JSNodeMarker> existingMarkers = getMarkers();
    if (existingMarkers != null) {
        for (final NodeMarker marker : existingMarkers) {
            if (marker instanceof JSNodeMarker) {
                final JSNodeMarker m = (JSNodeMarker) marker;
                if (!m_filteredMarkers.contains(m)) {
                    markers.add(m);
                }
            }
        }
    }
    return Collections.unmodifiableList(markers);
}
Also used : JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) NodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker) ArrayList(java.util.ArrayList) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)

Example 3 with NodeMarker

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

the class SearchControl method initializeCellAutocompleteWidget.

private void initializeCellAutocompleteWidget() {
    final AbstractSafeHtmlRenderer<NodeMarker> renderer = new AbstractSafeHtmlRenderer<NodeMarker>() {

        @Override
        public SafeHtml render(final NodeMarker marker) {
            final SafeHtmlBuilder builder = new SafeHtmlBuilder();
            final String search = m_inputBox.getValue();
            builder.appendHtmlConstant("<div class=\"autocomplete-label\">");
            builder.appendHtmlConstant(marker.getNodeLabel());
            builder.appendHtmlConstant("</div>");
            String additionalSearchInfo = null;
            if (search != null && (search.contains(":") || search.contains("="))) {
                final String searchKey = search.replaceAll("[\\:\\=].*$", "").toLowerCase();
                LOG.info("searchKey = " + searchKey);
                final Map<String, String> props = marker.getProperties();
                if ("category".equals(searchKey) || "categories".equals(searchKey)) {
                    final String catString = props.get("categories");
                    if (catString != null) {
                        additionalSearchInfo = catString;
                    }
                }
                for (final Map.Entry<String, String> entry : props.entrySet()) {
                    final String key = entry.getKey().toLowerCase();
                    final Object value = entry.getValue();
                    if (key.equals(searchKey) && m_labels.containsKey(key)) {
                        additionalSearchInfo = m_labels.get(key) + ": " + value;
                        break;
                    }
                }
            }
            if (additionalSearchInfo != null) {
                builder.appendHtmlConstant("<div class=\"autocomplete-additional-info\">").appendHtmlConstant(additionalSearchInfo).appendHtmlConstant("</div>");
            }
            return builder.toSafeHtml();
        }
    };
    final AbstractSafeHtmlCell<NodeMarker> cell = new AbstractSafeHtmlCell<NodeMarker>(renderer, "keydown", "click", "dblclick", "touchstart") {

        @Override
        public void onBrowserEvent(final Context context, final com.google.gwt.dom.client.Element parent, final NodeMarker value, final NativeEvent event, final ValueUpdater<NodeMarker> valueUpdater) {
            LOG.info("SearchControl.AutocompleteCell.onBrowserEvent(): context = " + context + ", parent = " + parent + ", value = " + value + ", event = " + event);
            if (m_stateManager.handleAutocompleteEvent(event)) {
                super.onBrowserEvent(context, parent, value, event, valueUpdater);
            }
        }

        @Override
        protected void render(final Context context, final SafeHtml data, final SafeHtmlBuilder builder) {
            builder.appendHtmlConstant("<div class=\"autocomplete-entry\">");
            if (data != null) {
                builder.append(data);
            }
            builder.appendHtmlConstant("</div>");
        }
    };
    m_autoComplete = new CellList<NodeMarker>(cell);
    m_autoComplete.setSelectionModel(m_selectionModel);
    m_autoComplete.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION);
    m_autoComplete.setVisible(false);
    m_autoComplete.addStyleName("search-autocomplete");
    setIdIfMissing(m_autoComplete, "searchControl.autoComplete");
}
Also used : AbstractSafeHtmlRenderer(com.google.gwt.text.shared.AbstractSafeHtmlRenderer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Element(com.google.gwt.user.client.Element) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) NodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker) ValueUpdater(com.google.gwt.cell.client.ValueUpdater) AbstractSafeHtmlCell(com.google.gwt.cell.client.AbstractSafeHtmlCell) HashMap(java.util.HashMap) Map(java.util.Map) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 4 with NodeMarker

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

the class MarkerFilterImplTest method testEmptySearch.

@Test
public void testEmptySearch() {
    // empty searches should always match
    final WrappedMarkerFilterImpl filter = new WrappedMarkerFilterImpl(null, AlarmSeverity.NORMAL, m_eventManager, m_componentTracker);
    final NodeMarker marker = new SimpleNodeMarker();
    assertTrue(filter.matches(marker));
    filter.setSearchString("");
    assertTrue(filter.matches(marker));
    assertEquals(1, filter.getFilterUpdatedCalls());
}
Also used : SimpleNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.SimpleNodeMarker) NodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker) SimpleNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.SimpleNodeMarker) Test(org.junit.Test)

Aggregations

NodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker)4 JSNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)3 ArrayList (java.util.ArrayList)2 AbstractSafeHtmlCell (com.google.gwt.cell.client.AbstractSafeHtmlCell)1 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 AbstractSafeHtmlRenderer (com.google.gwt.text.shared.AbstractSafeHtmlRenderer)1 Element (com.google.gwt.user.client.Element)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 LatLngBounds (org.discotools.gwt.leaflet.client.types.LatLngBounds)1 Test (org.junit.Test)1 Coordinates (org.opennms.features.vaadin.nodemaps.internal.gwt.client.Coordinates)1 SimpleNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.SimpleNodeMarker)1