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);
}
}
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);
}
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();
}
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);
}
}
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;
}
Aggregations