use of org.opennms.features.vaadin.dashboard.model.DashletSpec 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++;
}
}
}
}
Aggregations