@Override protected VertexRef findSingleSelectedItem(GraphContainer container) { Collection<VertexRef> selectedVertexRefs = container.getSelectionManager().getSelectedVertexRefs(); if (selectedVertexRefs.size() == 1) { final VertexRef vertexRef = selectedVertexRefs.iterator().next(); Vertex vertex = container.getBaseTopology().getVertex(vertexRef); return vertex; } return null; } }
private GraphProvider getGraphProvider() { UI ui = UI.getCurrent(); if (ui instanceof WidgetContext) { return ((WidgetContext) ui).getGraphContainer().getBaseTopology(); } return null; }
@Override public void execute(List<VertexRef> targets, OperationContext operationContext) { if (operationContext != null && operationContext.getGraphContainer() != null) { try { operationContext.getGraphContainer().getBaseTopology().load(SFreeTopologyProvider.BARABASI_ALBERT); } catch (MalformedURLException e) { // TODO: Display the error in the UI LoggerFactory.getLogger(this.getClass()).error(e.getMessage(), e); } catch (JAXBException e) { // TODO: Display the error in the UI LoggerFactory.getLogger(this.getClass()).error(e.getMessage(), e); } operationContext.getGraphContainer().redoLayout(); } }
@Override public void execute(List<VertexRef> targets, OperationContext operationContext) { if (operationContext != null && operationContext.getGraphContainer() != null) { try { operationContext.getGraphContainer().getBaseTopology().load(SFreeTopologyProvider.ERDOS_RENIS); } catch (MalformedURLException e) { // TODO: Display the error in the UI LoggerFactory.getLogger(this.getClass()).error(e.getMessage(), e); } catch (JAXBException e) { // TODO: Display the error in the UI LoggerFactory.getLogger(this.getClass()).error(e.getMessage(), e); } operationContext.getGraphContainer().redoLayout(); } }
protected static Vertex getVertexItem(final OperationContext operationContext, final VertexRef target) { Vertex vertex = operationContext.getGraphContainer().getBaseTopology().getVertex(target, operationContext.getGraphContainer().getCriteria()); if (vertex == null) { LoggerFactory.getLogger(AbstractOperation.class).debug("Null vertex found for vertex reference: {}:{}", target.getNamespace(), target.getId()); return null; } else { return vertex; } }
@Override public void execute(List<VertexRef> targets, OperationContext operationContext) { GraphProvider graphProvider = operationContext.getGraphContainer().getBaseTopology(); Map<String, WrappedVertex> idMap = new HashMap<String, WrappedVertex>(); // first create all the vertices; List<WrappedVertex> vertices = new ArrayList<WrappedVertex>(); for(Vertex vertex : graphProvider.getVertices()) { WrappedVertex wrappedVertex = WrappedVertex.create(vertex); vertices.add(wrappedVertex); idMap.put(vertex.getId(), wrappedVertex); } // then set the parents for each for(Vertex vertex : graphProvider.getVertices()) { Vertex parent = graphProvider.getParent(vertex); if (parent != null) { WrappedVertex wrappedVertex = idMap.get(vertex.getId()); WrappedVertex wrappedParent = idMap.get(parent.getId()); wrappedVertex.parent = wrappedParent; } } // then create the edges List<WrappedEdge> edges = new ArrayList<WrappedEdge>(); for(Edge edge : graphProvider.getEdges()) { WrappedVertex wrappedSource = idMap.get(edge.getSource().getVertex().getId()); WrappedVertex wrappedTarget = idMap.get(edge.getTarget().getVertex().getId()); edges.add(new WrappedEdge(edge, wrappedSource, wrappedTarget)); } WrappedGraph graph = new WrappedGraph(graphProvider.getVertexNamespace(), vertices, edges); JAXB.marshal(graph, new File("/tmp/saved-graph.xml")); }
@Override public void execute(List<VertexRef> targets, OperationContext operationContext) { GraphProvider graphProvider = operationContext.getGraphContainer().getBaseTopology(); Map<String, WrappedVertex> idMap = new HashMap<String, WrappedVertex>(); // first create all the vertices; List<WrappedVertex> vertices = new ArrayList<WrappedVertex>(); for(Vertex vertex : graphProvider.getVertices()) { WrappedVertex wrappedVertex = WrappedVertex.create(vertex); vertices.add(wrappedVertex); idMap.put(vertex.getId(), wrappedVertex); } // then set the parents for each for(Vertex vertex : graphProvider.getVertices()) { Vertex parent = graphProvider.getParent(vertex); if (parent != null) { WrappedVertex wrappedVertex = idMap.get(vertex.getId()); WrappedVertex wrappedParent = idMap.get(parent.getId()); wrappedVertex.parent = wrappedParent; } } // then create the edges List<WrappedEdge> edges = new ArrayList<WrappedEdge>(); for(Edge edge : graphProvider.getEdges()) { WrappedVertex wrappedSource = idMap.get(edge.getSource().getVertex().getId()); WrappedVertex wrappedTarget = idMap.get(edge.getTarget().getVertex().getId()); edges.add(new WrappedEdge(edge, wrappedSource, wrappedTarget)); } WrappedGraph graph = new WrappedGraph(graphProvider.getVertexNamespace(), vertices, edges); JAXB.marshal(graph, new File("/tmp/saved-graph.xml")); }
@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"); port = 22; //portProperty == null ? -1 : (Integer) portProperty.getValue(); } } } operationContext.getMainWindow().addWindow(new AuthWindow(ipAddr, port)); return null; }