Search in sources :

Example 6 with CollapsibleCriteria

use of org.opennms.features.topology.api.topo.CollapsibleCriteria in project opennms by OpenNMS.

the class SearchBox method collapseIfSuggMapEmpty.

private void collapseIfSuggMapEmpty(SearchResult searchResult, GraphContainer graphContainer) {
    // A special check for categories that were added then after re-login can't collapse
    boolean isDirty = false;
    Criteria[] criteria = graphContainer.getCriteria();
    for (Criteria criterion : criteria) {
        if (criterion instanceof CollapsibleCriteria) {
            if (((CollapsibleCriteria) criterion).getLabel().equals(searchResult.getLabel())) {
                ((CollapsibleCriteria) criterion).setCollapsed(!((CollapsibleCriteria) criterion).isCollapsed());
                isDirty = true;
            }
        }
    }
    if (isDirty) {
        graphContainer.redoLayout();
    }
}
Also used : CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) DefaultVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria)

Example 7 with CollapsibleCriteria

use of org.opennms.features.topology.api.topo.CollapsibleCriteria in project opennms by OpenNMS.

the class VertexHopGraphProviderTest method testCollapseEdges.

@Test
public void testCollapseEdges() {
    CollapsibleCriteria collapseMe = new CollapsibleCriteria() {

        @Override
        public void setCollapsed(boolean collapsed) {
        }

        @Override
        public boolean isCollapsed() {
            return true;
        }

        @Override
        public Set<VertexRef> getVertices() {
            Set<VertexRef> retval = new HashSet<>();
            retval.add(new DefaultVertexRef("nodes", "g2"));
            return retval;
        }

        @Override
        public String getNamespace() {
            return "nodes";
        }

        @Override
        public String getLabel() {
            return "Test Criteria";
        }

        @Override
        public String getId() {
            return "Test Criteria";
        }

        @Override
        public Vertex getCollapsedRepresentation() {
            return new AbstractVertex("category", "c");
        }
    };
    Set<Edge> edges = VertexHopGraphProvider.collapseEdges(new HashSet<Edge>(m_provider.getEdges()), new CollapsibleCriteria[] { collapseMe });
    for (Edge edge : edges) {
        assertEquals("nodes", edge.getNamespace());
        /*
			Here's the original list of edges

			.edge("e1", "g0", "g1").eLabel("edge1").eStyleName("edge")
			.edge("e2", "g0", "g2").eLabel("edge2").eStyleName("edge")
			.edge("e3", "g1", "v1").eLabel("edge3").eStyleName("edge")
			.edge("e4", "g1", "v2").eLabel("edge4").eStyleName("edge")
			.edge("e5", "g2", "v3").eLabel("edge5").eStyleName("edge")
			.edge("e6", "g2", "v4").eLabel("edge6").eStyleName("edge")
			*/
        if (edge.getId().equals("e1")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g0", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("g1", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedTarget-e2")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g0", edge.getSource().getVertex().getId());
            assertEquals("category", edge.getTarget().getVertex().getNamespace());
            assertEquals("c", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("e3")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g1", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v1", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("e4")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g1", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v2", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedSource-e5")) {
            assertEquals("category", edge.getSource().getVertex().getNamespace());
            assertEquals("c", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v3", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedSource-e6")) {
            assertEquals("category", edge.getSource().getVertex().getNamespace());
            assertEquals("c", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v4", edge.getTarget().getVertex().getId());
        } else {
            fail("Unexpected edge found: " + edge.toString());
        }
    }
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with CollapsibleCriteria

use of org.opennms.features.topology.api.topo.CollapsibleCriteria in project opennms by OpenNMS.

the class SavedHistory method getFocusVertices.

private static Set<VertexRef> getFocusVertices(GraphContainer graphContainer) {
    final Set<VertexRef> retVal = new HashSet<>();
    Criteria[] criterias = graphContainer.getCriteria();
    for (Criteria crit : criterias) {
        if (crit instanceof VertexHopGraphProvider.VertexHopCriteria && !(crit instanceof CollapsibleCriteria)) {
            retVal.addAll(((VertexHopGraphProvider.VertexHopCriteria) crit).getVertices());
        }
    }
    return retVal;
}
Also used : CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef) HashSet(java.util.HashSet)

Example 9 with CollapsibleCriteria

use of org.opennms.features.topology.api.topo.CollapsibleCriteria in project opennms by OpenNMS.

the class SearchBox method updateTokenFieldList.

private void updateTokenFieldList(GraphContainer graphContainer) {
    final List<SearchSuggestion> suggestions = Lists.newArrayList();
    final Criteria[] criterium = graphContainer.getCriteria();
    for (Criteria criteria : criterium) {
        try {
            CollapsibleCriteria crit = (CollapsibleCriteria) criteria;
            SearchSuggestion suggestion = new SearchSuggestion(crit.getNamespace(), crit.getId(), crit.getLabel());
            suggestion.setCollapsible(true);
            suggestion.setCollapsed(crit.isCollapsed());
            suggestions.add(suggestion);
            continue;
        } catch (ClassCastException e) {
        }
        try {
            VertexHopCriteria crit = (VertexHopCriteria) criteria;
            SearchSuggestion suggestion = new SearchSuggestion(crit.getNamespace(), crit.getId(), crit.getLabel());
            suggestions.add(suggestion);
            continue;
        } catch (ClassCastException e) {
        }
    }
    getState().setFocused(suggestions);
}
Also used : SearchSuggestion(org.opennms.features.topology.app.internal.gwt.client.SearchSuggestion) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) DefaultVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) DefaultVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria)

Example 10 with CollapsibleCriteria

use of org.opennms.features.topology.api.topo.CollapsibleCriteria in project opennms by OpenNMS.

the class CategorySearchProvider method onToggleCollapse.

@Override
public void onToggleCollapse(SearchResult searchResult, GraphContainer graphContainer) {
    CollapsibleCriteria criteria = getMatchingCriteria(graphContainer, searchResult.getId());
    if (criteria != null) {
        criteria.setCollapsed(!criteria.isCollapsed());
        graphContainer.redoLayout();
    }
}
Also used : CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria)

Aggregations

CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)11 HashSet (java.util.HashSet)5 VertexRef (org.opennms.features.topology.api.topo.VertexRef)5 Criteria (org.opennms.features.topology.api.topo.Criteria)4 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)4 Set (java.util.Set)2 Test (org.junit.Test)2 DefaultVertexHopCriteria (org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria)2 VertexHopCriteria (org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria)2 Edge (org.opennms.features.topology.api.topo.Edge)2 Vertex (org.opennms.features.topology.api.topo.Vertex)2 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 Graph (org.opennms.features.topology.api.Graph)1 SemanticZoomLevelCriteria (org.opennms.features.topology.api.support.SemanticZoomLevelCriteria)1 VertexHopGraphProvider (org.opennms.features.topology.api.support.VertexHopGraphProvider)1 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)1 RefComparator (org.opennms.features.topology.api.topo.RefComparator)1 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)1 SearchResult (org.opennms.features.topology.api.topo.SearchResult)1