use of org.opennms.features.topology.api.OperationContext in project opennms by OpenNMS.
the class GraphMLSearchProviderTest method canSearchAllSearchProviders.
@Test
public void canSearchAllSearchProviders() throws IOException, InvalidGraphException {
final GraphMLMetaTopologyProvider metaTopologyProvider = new GraphMLMetaTopologyProvider(new GraphMLServiceAccessor());
metaTopologyProvider.setTopologyLocation("target/test-classes/test-graph.xml");
metaTopologyProvider.reload();
Assert.assertNotNull(metaTopologyProvider.getDefaultGraphProvider());
List<SearchProvider> searchProviders = metaTopologyProvider.getGraphProviders().stream().map(eachProvider -> new GraphMLSearchProvider(metaTopologyProvider.getRawTopologyProvider(eachProvider.getNamespace()))).collect(Collectors.toList());
Assert.assertEquals(2, searchProviders.size());
DefaultTopologyService defaultTopologyService = new DefaultTopologyService();
defaultTopologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
graphContainer.setTopologyService(defaultTopologyService);
graphContainer.setMetaTopologyId(metaTopologyProvider.getId());
graphContainer.setSelectedNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
OperationContext operationContext = EasyMock.niceMock(OperationContext.class);
EasyMock.expect(operationContext.getGraphContainer()).andReturn(graphContainer).anyTimes();
OnmsServiceManager onmsServiceManager = EasyMock.niceMock(OnmsServiceManager.class);
EasyMock.expect(onmsServiceManager.getServices(SearchProvider.class, null, new Hashtable<>())).andReturn(searchProviders).anyTimes();
EasyMock.replay(onmsServiceManager, operationContext);
SearchBox searchBox = new SearchBox(onmsServiceManager, operationContext);
List<SearchSuggestion> results = searchBox.getQueryResults("North");
Assert.assertEquals(5, results.size());
}
use of org.opennms.features.topology.api.OperationContext 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.OperationContext in project opennms by OpenNMS.
the class TopologyContextMenu method updateMenu.
public void updateMenu(GraphContainer graphContainer, UI mainWindow, OperationManager operationManager, List<VertexRef> targets) {
final OperationContext operationContext = new DefaultOperationContext(mainWindow, graphContainer, OperationContext.DisplayLocation.CONTEXTMENU);
// Clear Menu
removeAllItems();
// Rebuild menu
MenuBuilder menuBuilder = new MenuBuilder();
for (OperationServiceWrapper operationServiceWrapper : operationManager.getOperationWrappers()) {
if (operationServiceWrapper.getContextMenuPosition() != null) {
MenuItem item = new OperationMenuItem(operationServiceWrapper);
menuBuilder.addMenuItem(item, operationServiceWrapper.getContextMenuPosition().isEmpty() ? null : operationServiceWrapper.getContextMenuPosition().split("\\|"));
}
}
addNavigateToItems(menuBuilder, targets, operationContext);
MenuBar menu = menuBuilder.build(targets, operationContext, this::notifyMenuUpdateListener);
addItems(menu);
}
use of org.opennms.features.topology.api.OperationContext 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();
}
Aggregations