use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class TopologyContextMenu method addNavigateToItems.
// adds menu items for the "navigate to" operation
private static void addNavigateToItems(MenuBuilder menuBuilder, List<VertexRef> targets, OperationContext operationContext) {
if (!targets.isEmpty()) {
menuBuilder.createPath("Navigate To");
final GraphContainer graphContainer = operationContext.getGraphContainer();
// Find the vertices in other graphs that this vertex links to
final Collection<VertexRef> oppositeVertices = graphContainer.getTopologyServiceClient().getOppositeVertices(targets.get(0));
// Find all namespaces
final Set<String> targetNamespaces = oppositeVertices.stream().map(v -> v.getNamespace()).collect(Collectors.toSet());
// Find provider for namespaces and add menu entry
for (String eachTargetNamespace : targetNamespaces) {
// Find the graph provider for the target namespace
final GraphProvider targetGraphProvider = graphContainer.getTopologyServiceClient().getGraphProviders().stream().filter(g -> g.getNamespace().equals(eachTargetNamespace)).findFirst().orElse(null);
if (targetGraphProvider == null) {
LOG.warn("No graph provider found for namespace '{}'.", eachTargetNamespace);
continue;
}
NavigationMenuItem item = new NavigationMenuItem(targetGraphProvider, targets.get(0));
menuBuilder.addMenuItem(item, "Navigate To");
}
}
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class TopologyUI method init.
@Override
protected void init(final VaadinRequest request) {
// Register a cleanup
request.getService().addSessionDestroyListener((SessionDestroyListener) event -> m_widgetManager.removeUpdateListener(TopologyUI.this));
try {
m_headerHtml = getHeader(((VaadinServletRequest) request).getHttpServletRequest());
} catch (final Exception e) {
LOG.error("failed to get header HTML for request " + request.getPathInfo(), e.getCause());
}
//create VaadinApplicationContext
m_applicationContext = m_serviceManager.createApplicationContext(new VaadinApplicationContextCreator() {
@Override
public VaadinApplicationContext create(OnmsServiceManager manager) {
VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
context.setSessionId(request.getWrappedSession().getId());
context.setUiId(getUIId());
context.setUsername(request.getRemoteUser());
return context;
}
});
m_verticesUpdateManager = new OsgiVerticesUpdateManager(m_serviceManager, m_applicationContext);
m_serviceManager.getEventRegistry().addPossibleEventConsumer(this, m_applicationContext);
// Set the algorithm last so that the criteria and SZLs are
// in place before we run the layout algorithm.
m_graphContainer.setApplicationContext(m_applicationContext);
createLayouts();
// Set up an error handler for UI-level exceptions
setupErrorHandler();
// Add an auto refresh handler to the GraphContainer
setupAutoRefresher();
loadUserSettings();
// If no Topology Provider was selected (due to loadUserSettings(), fallback to default
if (Strings.isNullOrEmpty(m_graphContainer.getMetaTopologyId())) {
CheckedOperation defaultTopologySelectorOperation = getDefaultTopologySelectorOperation(m_bundlecontext);
// no default found, abort
Objects.requireNonNull(defaultTopologySelectorOperation, "No default GraphProvider found.");
defaultTopologySelectorOperation.execute(Lists.newArrayList(), new DefaultOperationContext(TopologyUI.this, m_graphContainer, DisplayLocation.MENUBAR));
}
// Add a request handler that parses incoming focusNode and szl query parameters
TopologyUIRequestHandler handler = new TopologyUIRequestHandler();
getSession().addRequestHandler(handler);
// deal with those in init case
handler.handleRequestParameter(request);
// Add the default criteria if we do not have already a criteria set
if (getWrappedVertexHopCriteria(m_graphContainer).isEmpty() && noAdditionalFocusCriteria()) {
List<Criteria> defaultCriteriaList = m_graphContainer.getTopologyServiceClient().getDefaults().getCriteria();
if (defaultCriteriaList != null) {
// set default
defaultCriteriaList.forEach(eachCriteria -> m_graphContainer.addCriteria(eachCriteria));
}
}
// We set the listeners at the end, to not fire them all the time when initializing the UI
setupListeners();
// We force a reload to trigger a fireGraphChanged()
m_graphContainer.setDirty(true);
m_graphContainer.redoLayout();
// Trigger a selectionChanged
m_selectionManager.selectionChanged(m_selectionManager);
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class BusinessServiceVertexInfoPanelItemProvider method createComponent.
private Component createComponent(AbstractBusinessServiceVertex ref, GraphContainer graphContainer) {
final FormLayout formLayout = new FormLayout();
formLayout.setSpacing(false);
formLayout.setMargin(false);
ref.accept(new BusinessServiceVertexVisitor<Void>() {
@Override
public Void visit(BusinessServiceVertex vertex) {
final BusinessService businessService = businessServiceManager.getBusinessServiceById(vertex.getServiceId());
formLayout.addComponent(createLabel("Reduce function", getReduceFunctionDescription(businessService.getReduceFunction())));
// Apply Reduce Function specific details
businessService.getReduceFunction().accept(new ReduceFunctionVisitor<Void>() {
@Override
public Void visit(HighestSeverity highestSeverity) {
return null;
}
@Override
public Void visit(HighestSeverityAbove highestSeverityAbove) {
return null;
}
@Override
public // Threshold is not very transparent, we add an Explain Button in these cases
Void visit(Threshold threshold) {
final Button explainButton = createButton("Explain", "Explain the Threshold function", FontAwesome.TABLE, (Button.ClickListener) event -> {
ThresholdExplanationWindow explainWindow = new ThresholdExplanationWindow(SimulationAwareStateMachineFactory.createSimulatedStateMachine(businessServiceManager, graphContainer.getCriteria()).explain(businessService, (Threshold) businessService.getReduceFunction()));
UI.getCurrent().addWindow(explainWindow);
});
explainButton.setStyleName(BaseTheme.BUTTON_LINK);
formLayout.addComponent(explainButton);
return null;
}
@Override
public Void visit(ExponentialPropagation exponentialPropagation) {
return null;
}
});
return null;
}
@Override
public Void visit(IpServiceVertex vertex) {
IpService ipService = businessServiceManager.getIpServiceById(vertex.getIpServiceId());
formLayout.addComponent(createLabel("Interface", ipService.getIpAddress()));
formLayout.addComponent(createLabel("Service", ipService.getServiceName()));
if (!ipService.getServiceName().equals(vertex.getLabel())) {
formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
}
return null;
}
@Override
public Void visit(ReductionKeyVertex vertex) {
formLayout.addComponent(createLabel("Reduction Key", vertex.getReductionKey()));
if (!vertex.getReductionKey().equals(vertex.getLabel())) {
formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
}
return null;
}
});
return formLayout;
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class GraphMLSearchProvider method onFocusSearchResult.
@Override
public void onFocusSearchResult(SearchResult searchResult, OperationContext operationContext) {
final GraphContainer graphContainer = operationContext.getGraphContainer();
final DefaultVertexRef vertexRef = new DefaultVertexRef(searchResult.getNamespace(), searchResult.getId(), searchResult.getLabel());
if (graphContainer.getTopologyServiceClient().getVertex(vertexRef) == null) {
// The vertex to add to focus is not in the current layer
// Find the GraphProvider it belongs to
Optional<GraphProvider> first = graphContainer.getTopologyServiceClient().getGraphProviders().stream().filter(eachProvider -> eachProvider.getNamespace().equals(searchResult.getNamespace())).findFirst();
// If there is a graph provider (which should) select it
if (first.isPresent() && first.get().getVertex(vertexRef) != null) {
graphContainer.selectTopologyProvider(first.get());
graphContainer.clearCriteria();
}
}
super.onFocusSearchResult(searchResult, operationContext);
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class SimulationModeOperation method execute.
@Override
public void execute(List<VertexRef> targets, OperationContext operationContext) {
final GraphContainer container = operationContext.getGraphContainer();
if (isChecked(operationContext.getGraphContainer())) {
container.removeCriteria(crit);
} else {
container.addCriteria(crit);
}
// Force a refresh to update the status
container.redoLayout();
}
Aggregations