Search in sources :

Example 1 with SetStatusToCriteria

use of org.opennms.features.topology.plugins.topo.bsm.simulate.SetStatusToCriteria in project opennms by OpenNMS.

the class SimulationModeReductionKeyInfoPanelItemProvider method createComponent.

private Component createComponent(ReductionKeyVertex vertex, GraphContainer container) {
    final FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(false);
    formLayout.setMargin(false);
    NativeSelect dropdown = new NativeSelect("Severity");
    dropdown.setMultiSelect(false);
    dropdown.setNewItemsAllowed(false);
    dropdown.setNullSelectionAllowed(true);
    dropdown.setImmediate(true);
    dropdown.setRequired(true);
    dropdown.addItems(Arrays.asList(Status.values()));
    SetStatusToCriteria setStatusTo = findCriteria(container, vertex);
    if (setStatusTo != null) {
        dropdown.setValue(setStatusTo.getStatus());
    } else {
        dropdown.setValue(null);
    }
    dropdown.addValueChangeListener(event -> {
        // The set of criteria may have changed since we last queried it above
        // do we issue try finding it again, instead of using the same existing object
        SetStatusToCriteria currentSetStatusTo = findCriteria(container, vertex);
        Status selectedStatus = (Status) dropdown.getValue();
        if (currentSetStatusTo != null) {
            currentSetStatusTo.setStatus(selectedStatus);
        } else {
            currentSetStatusTo = new SetStatusToCriteria(vertex.getReductionKey(), selectedStatus);
            container.addCriteria(currentSetStatusTo);
        }
        // Remove the current selection before redrawing the layout in order
        // to avoid centering on the current vertex
        container.getSelectionManager().setSelectedVertexRefs(Collections.emptyList());
        container.getSelectionManager().setSelectedEdgeRefs(Collections.emptyList());
        container.redoLayout();
    });
    formLayout.addComponent(dropdown);
    return formLayout;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Status(org.opennms.netmgt.bsm.service.model.Status) SetStatusToCriteria(org.opennms.features.topology.plugins.topo.bsm.simulate.SetStatusToCriteria) NativeSelect(com.vaadin.ui.NativeSelect)

Aggregations

FormLayout (com.vaadin.ui.FormLayout)1 NativeSelect (com.vaadin.ui.NativeSelect)1 SetStatusToCriteria (org.opennms.features.topology.plugins.topo.bsm.simulate.SetStatusToCriteria)1 Status (org.opennms.netmgt.bsm.service.model.Status)1