Search in sources :

Example 1 with Dashlet

use of org.opennms.features.vaadin.dashboard.model.Dashlet in project opennms by OpenNMS.

the class DashboardBody method setDashletSpecs.

/**
 * This method sets the {@link List} of {@link DashletSpec} instances.
 *
 * @param dashletSpecs the list of {@link DashletSpec} instances
 */
public void setDashletSpecs(List<DashletSpec> dashletSpecs) {
    m_displayDashlets = new HashMap<Component, DashletComponent>();
    int c = 0;
    List<DashletSpec> dashboardSuitableDashlets = new LinkedList<>();
    if (dashletSpecs.size() == 0) {
        return;
    } else {
        for (DashletSpec dashletSpec : dashletSpecs) {
            if (suitableForDashboard(dashletSpec)) {
                dashboardSuitableDashlets.add(dashletSpec);
            }
        }
    }
    if (dashboardSuitableDashlets.size() == 0) {
        return;
    }
    int columns = (int) Math.ceil(Math.sqrt(dashboardSuitableDashlets.size()));
    int rows = (int) Math.ceil((double) dashboardSuitableDashlets.size() / (double) columns);
    setColumns(columns);
    setRows(rows);
    int i = 0;
    removeAllComponents();
    for (int y = 0; y < rows; y++) {
        for (int x = 0; x < columns; x++) {
            if (i < dashboardSuitableDashlets.size()) {
                Dashlet dashlet = getDashletInstance(dashboardSuitableDashlets.get(i));
                DashletComponent dashletComponent = dashlet.getDashboardComponent();
                m_displayDashlets.put(dashletComponent.getComponent(), dashletComponent);
                dashletComponent.refresh();
                String caption = dashlet.getName();
                if (dashlet.getDashletSpec().getTitle() != null) {
                    if (!"".equals(dashlet.getDashletSpec().getTitle())) {
                        caption += ": " + "" + dashlet.getDashletSpec().getTitle();
                    }
                }
                addComponent(createPanel(dashletComponent.getComponent(), caption), x, y);
                i++;
            }
        }
    }
}
Also used : DashletComponent(org.opennms.features.vaadin.dashboard.model.DashletComponent) Dashlet(org.opennms.features.vaadin.dashboard.model.Dashlet) DashletSpec(org.opennms.features.vaadin.dashboard.model.DashletSpec) DashletComponent(org.opennms.features.vaadin.dashboard.model.DashletComponent) Component(com.vaadin.ui.Component) LinkedList(java.util.LinkedList)

Example 2 with Dashlet

use of org.opennms.features.vaadin.dashboard.model.Dashlet in project opennms by OpenNMS.

the class WallboardBody method getDashletInstance.

public Dashlet getDashletInstance(DashletSpec dashletSpec) {
    DashletSelector dashletSelector = ((DashletSelectorAccess) getUI()).getDashletSelector();
    Dashlet dashlet = dashletSelector.getDashletFactoryForName(dashletSpec.getDashletName()).newDashletInstance(dashletSpec);
    dashlet.getWallboardComponent().getComponent().setCaption(null);
    return dashlet;
}
Also used : DashletSelectorAccess(org.opennms.features.vaadin.dashboard.model.DashletSelectorAccess) DashletSelector(org.opennms.features.vaadin.dashboard.config.DashletSelector) Dashlet(org.opennms.features.vaadin.dashboard.model.Dashlet)

Example 3 with Dashlet

use of org.opennms.features.vaadin.dashboard.model.Dashlet in project opennms by OpenNMS.

the class WallboardBody method next.

private int next() {
    if (dashletSpecs.size() == 0) {
        return -1;
    }
    int oldIndex = index;
    while (true) {
        index++;
        if (index >= dashletSpecs.size()) {
            iteration++;
            index = 0;
        }
        if (index == oldIndex && dashletSpecs.size() > 1) {
            int minValue = Integer.MAX_VALUE, maxIndex = -1;
            for (Map.Entry<Integer, Integer> entry : priorityMap.entrySet()) {
                if (entry.getKey() != oldIndex && entry.getValue() < minValue) {
                    minValue = entry.getValue();
                    maxIndex = entry.getKey();
                }
            }
            if (maxIndex != -1) {
                index = maxIndex;
                priorityMap.put(index, 0);
            }
        }
        if (!priorityMap.containsKey(index)) {
            Dashlet dashlet = getDashletInstance(dashletSpecs.get(index));
            dashlet.getWallboardComponent().getComponent().addStyleName("wallboard");
            dashlets.put(index, dashlet);
            dashlets.get(index).getWallboardComponent().refresh();
            if (dashlets.get(index).isBoosted()) {
                priorityMap.put(index, Math.max(0, dashletSpecs.get(index).getPriority() - dashletSpecs.get(index).getBoostPriority()));
                durationMap.put(index, dashletSpecs.get(index).getDuration() + dashletSpecs.get(index).getBoostDuration());
            } else {
                priorityMap.put(index, dashletSpecs.get(index).getPriority());
                durationMap.put(index, dashletSpecs.get(index).getDuration());
            }
            oldPriorityMap.put(index, priorityMap.get(index));
            oldDurationMap.put(index, durationMap.get(index));
        }
        if (priorityMap.get(index) <= 0) {
            dashlets.get(index).getWallboardComponent().refresh();
            if (dashlets.get(index).isBoosted()) {
                priorityMap.put(index, Math.max(0, dashletSpecs.get(index).getPriority() - dashletSpecs.get(index).getBoostPriority()));
                durationMap.put(index, dashletSpecs.get(index).getDuration() + dashletSpecs.get(index).getBoostDuration());
            } else {
                priorityMap.put(index, Math.min(oldPriorityMap.get(index) + PRIORITY_DECREASE, dashletSpecs.get(index).getPriority()));
                durationMap.put(index, Math.max(oldDurationMap.get(index) - DURATION_DECREASE, dashletSpecs.get(index).getDuration()));
            }
            oldPriorityMap.put(index, priorityMap.get(index));
            oldDurationMap.put(index, durationMap.get(index));
            return index;
        } else {
            priorityMap.put(index, priorityMap.get(index) - 1);
        }
    }
}
Also used : Dashlet(org.opennms.features.vaadin.dashboard.model.Dashlet)

Aggregations

Dashlet (org.opennms.features.vaadin.dashboard.model.Dashlet)3 Component (com.vaadin.ui.Component)1 LinkedList (java.util.LinkedList)1 DashletSelector (org.opennms.features.vaadin.dashboard.config.DashletSelector)1 DashletComponent (org.opennms.features.vaadin.dashboard.model.DashletComponent)1 DashletSelectorAccess (org.opennms.features.vaadin.dashboard.model.DashletSelectorAccess)1 DashletSpec (org.opennms.features.vaadin.dashboard.model.DashletSpec)1