Search in sources :

Example 66 with VertexRef

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

the class HierarchyLayoutAlgorithm method updateLayout.

/**
 * Updates the current layout by extracting the containers graph and then perform a (x,y) tranformation
 * of all vertices.
 *
 * @param graph The container of the current graph. Contains all relevant information to perform the transformation
 *                       of the {@link Graph} by changing its {@link Layout}
 */
@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    // fully level aware. See NMS-8703
    if (isFullyLevelAware(graph)) {
        final HierarchyLayout<VertexRef, Edge> treeLayout = createTreeLayout(graph);
        applyLayoutPositions(graph.getDisplayVertices(), treeLayout, graphLayout);
    } else {
        // SEE NMS-8703
        LOG.warn("The selected graph is not fully level aware. Cannot layout hierarchical. Falling back to D3 Layout");
        new D3TopoLayoutAlgorithm().updateLayout(graph);
    }
}
Also used : Layout(org.opennms.features.topology.api.Layout) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 67 with VertexRef

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

the class TopologyMenuBar method updateMenu.

// Builds the menu
public void updateMenu(GraphContainer graphContainer, UI mainWindow, OperationManager operationManager) {
    final DefaultOperationContext operationContext = new DefaultOperationContext(mainWindow, graphContainer, OperationContext.DisplayLocation.MENUBAR);
    final ArrayList<VertexRef> targets = new ArrayList<>(graphContainer.getSelectionManager().getSelectedVertexRefs());
    // Clear menu
    removeItems();
    // Build new Menu
    MenuBuilder menuBuilder = new MenuBuilder();
    menuBuilder.setTopLevelMenuOrder(operationManager.getTopLevelMenuOrder());
    menuBuilder.setSubMenuGroupOrder(operationManager.getSubMenuGroupOrder());
    for (OperationServiceWrapper operationServiceWrapper : operationManager.getOperationWrappers()) {
        if (operationServiceWrapper.getMenuPosition() != null) {
            // if menu position is null, there is no place to put it
            org.opennms.features.topology.app.internal.menu.MenuItem item = new OperationMenuItem(operationServiceWrapper);
            menuBuilder.addMenuItem(item, operationServiceWrapper.getMenuPosition().split("\\|"));
        }
    }
    menuBuilder.apply(this, targets, operationContext, this::notifyMenuUpdateListener);
}
Also used : DefaultOperationContext(org.opennms.features.topology.app.internal.DefaultOperationContext) ArrayList(java.util.ArrayList) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 68 with VertexRef

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

the class IconSelectionOperation method execute.

@Override
public void execute(List<VertexRef> targets, OperationContext operationContext) {
    final AbstractVertex vertex = (AbstractVertex) targets.get(0);
    final String preSelectedIconId = operationContext.getGraphContainer().getIconManager().getSVGIconId(vertex);
    new IconSelectionDialog(preSelectedIconId).withOkAction(iconWindow -> {
        final IconManager iconManager = operationContext.getGraphContainer().getIconManager();
        final String newIconId = iconWindow.getSelectedIcon();
        String newIconKey = iconManager.setIconMapping(vertex, newIconId);
        if (newIconKey != null) {
            // We have to temporary update the icon key, otherwise the icon is not updated (redoLayout has no effect)
            vertex.setIconKey(newIconKey);
            // Redo the layout to apply new icon
            operationContext.getGraphContainer().setDirty(true);
            operationContext.getGraphContainer().redoLayout();
        }
    }).open();
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) List(java.util.List) IconSelectionDialog(org.opennms.features.topology.app.internal.ui.icons.IconSelectionDialog) Operation(org.opennms.features.topology.api.Operation) OperationContext(org.opennms.features.topology.api.OperationContext) IconManager(org.opennms.features.topology.api.IconManager) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) VertexRef(org.opennms.features.topology.api.topo.VertexRef) IconSelectionDialog(org.opennms.features.topology.app.internal.ui.icons.IconSelectionDialog) IconManager(org.opennms.features.topology.api.IconManager)

Example 69 with VertexRef

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

the class GraphUtils method renderGraphToFile.

public static void renderGraphToFile(Graph<VertexRef, Edge> jungGraph, File file) {
    final edu.uci.ics.jung.algorithms.layout.Layout<VertexRef, Edge> jungLayout = new KKLayout<>(jungGraph);
    // Size of the layout
    jungLayout.setSize(new Dimension(1800, 1800));
    final Set<VertexRef> roots = jungGraph.getVertices().stream().filter(v -> jungGraph.getInEdges(v).isEmpty()).collect(Collectors.toSet());
    VisualizationImageServer<VertexRef, Edge> vv = new VisualizationImageServer<>(jungLayout, jungLayout.getSize());
    // Viewing area size
    vv.setPreferredSize(new Dimension(2000, 2000));
    vv.getRenderContext().setVertexLabelTransformer(VertexRef::getLabel);
    vv.getRenderContext().setEdgeLabelTransformer(Edge::getLabel);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexRef -> {
        if (roots.contains(vertexRef)) {
            return Color.RED;
        }
        return Color.BLUE;
    });
    // Draw vertices according to in/out edge count. The more edges, the bigger the vertex
    vv.getRenderContext().setVertexShapeTransformer(vertexRef -> {
        Collection<Edge> inEdges = jungGraph.getInEdges(vertexRef);
        Collection<Edge> outEdges = jungGraph.getOutEdges(vertexRef);
        int edgeCount = inEdges.size() + outEdges.size();
        int widthHeight = (edgeCount / 4 + 1) * 20;
        return new Ellipse2D.Float(-1 * widthHeight / 2, -1 * widthHeight / 2, widthHeight, widthHeight);
    });
    // Create the buffered image
    BufferedImage image = (BufferedImage) vv.getImage(new Point2D.Double(vv.getGraphLayout().getSize().getWidth() / 2, vv.getGraphLayout().getSize().getHeight() / 2), new Dimension(vv.getGraphLayout().getSize()));
    // Render
    try {
        ImageIO.write(image, "png", file);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Color(java.awt.Color) Point2D(java.awt.geom.Point2D) BufferedImage(java.awt.image.BufferedImage) Edge(org.opennms.features.topology.api.topo.Edge) Collection(java.util.Collection) Set(java.util.Set) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Dimension(java.awt.Dimension) Ellipse2D(java.awt.geom.Ellipse2D) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) ImageIO(javax.imageio.ImageIO) Graph(edu.uci.ics.jung.graph.Graph) VertexRef(org.opennms.features.topology.api.topo.VertexRef) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Dimension(java.awt.Dimension) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 70 with VertexRef

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

the class SSHOperation method execute.

@Override
public Undoer execute(final List<VertexRef> targets, final OperationContext operationContext) {
    String ipAddr = "";
    int port = 22;
    if (targets != null) {
        for (final VertexRef target : targets) {
            final Item vertexItem = operationContext.getGraphContainer().getBaseTopology().getVertex(target, operationContext.getGraphContainer().getCriteria()).getItem();
            if (vertexItem != null) {
                final Property<String> ipAddrProperty = vertexItem.getItemProperty("ipAddr");
                ipAddr = ipAddrProperty == null ? "" : (String) ipAddrProperty.getValue();
                // Property portProperty = operationContext.getGraphContainer().getVertexItem(target).getItemProperty("port");
                // portProperty == null ? -1 : (Integer) portProperty.getValue();
                port = 22;
            }
        }
    }
    operationContext.getMainWindow().addWindow(new AuthWindow(ipAddr, port));
    return null;
}
Also used : Item(com.vaadin.data.Item) AuthWindow(org.opennms.features.topology.ssh.internal.AuthWindow) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

VertexRef (org.opennms.features.topology.api.topo.VertexRef)105 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)33 Vertex (org.opennms.features.topology.api.topo.Vertex)31 Point (org.opennms.features.topology.api.Point)23 Criteria (org.opennms.features.topology.api.topo.Criteria)22 Edge (org.opennms.features.topology.api.topo.Edge)22 Test (org.junit.Test)21 List (java.util.List)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)18 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 Map (java.util.Map)17 Status (org.opennms.features.topology.api.topo.Status)15 Collection (java.util.Collection)13 HashSet (java.util.HashSet)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 HashMap (java.util.HashMap)12 Layout (org.opennms.features.topology.api.Layout)12 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)12 Lists (com.google.common.collect.Lists)11