protected Dashboard getDefaultDashboard() {
Subject sessionSubject = UserSessionManager.getSessionSubject();
Resource resource = resourceComposite.getResource();
Dashboard dashboard = new Dashboard();
dashboard.setName(DASHBOARD_NAME_PREFIX + sessionSubject.getId() + "_" + resource.getId());
dashboard.setCategory(DashboardCategory.RESOURCE);
dashboard.setResource(resource);
dashboard.setColumns(2);
// TODO, add real portlets
// set leftmost column and let the rest be equally divided
dashboard.setColumnWidths("40%");
dashboard.getConfiguration().put(new PropertySimple(Dashboard.CFG_BACKGROUND, "transparent"));
//figure out which portlets to display and how
HashMap<String, String> resKeyNameMap = DashboardView.processPortletNameMapForResource(resourceComposite);
int colLeft = 0;
int colRight = 1;
int rowLeft = 0;
int rowRight = 0;
//Left Column
if (resKeyNameMap.containsKey(ResourceMetricsPortlet.KEY)) {//measurments top left if available
DashboardPortlet measurements = new DashboardPortlet(ResourceMetricsPortlet.NAME,
ResourceMetricsPortlet.KEY, 220);
dashboard.addPortlet(measurements, colLeft, rowLeft++);
resKeyNameMap.remove(ResourceMetricsPortlet.KEY);
}
// right Column(approx 60%. As larger more room to display table and N rows.)
if (resKeyNameMap.containsKey(ResourceAlertsPortlet.KEY)) {//alerts top right if available
DashboardPortlet alerts = new DashboardPortlet(ResourceAlertsPortlet.NAME, ResourceAlertsPortlet.KEY, 210);
dashboard.addPortlet(alerts, colRight, rowRight++);
resKeyNameMap.remove(ResourceAlertsPortlet.KEY);
}
if (resKeyNameMap.containsKey(ResourceEventsPortlet.KEY)) {//events if available
DashboardPortlet events = new DashboardPortlet(ResourceEventsPortlet.NAME, ResourceEventsPortlet.KEY, 210);
dashboard.addPortlet(events, colRight, rowRight++);
resKeyNameMap.remove(ResourceEventsPortlet.KEY);
}
if (resKeyNameMap.containsKey(ResourceOperationsPortlet.KEY)) {//operations if available
DashboardPortlet ops = new DashboardPortlet(ResourceOperationsPortlet.NAME, ResourceOperationsPortlet.KEY,
210);
dashboard.addPortlet(ops, colRight, rowRight++);
resKeyNameMap.remove(ResourceOperationsPortlet.KEY);
}
if (resKeyNameMap.containsKey(ResourceConfigurationUpdatesPortlet.KEY)) {//configuration if available
DashboardPortlet ops = new DashboardPortlet(ResourceConfigurationUpdatesPortlet.NAME,
ResourceConfigurationUpdatesPortlet.KEY, 210);
dashboard.addPortlet(ops, colRight, rowRight++);
resKeyNameMap.remove(ResourceConfigurationUpdatesPortlet.KEY);
}
//Fill out left column(typically smaller portlets) then alternate cols with remaining
boolean displayLeft = false;
for (String key : resKeyNameMap.keySet()) {
DashboardPortlet portlet = new DashboardPortlet(resKeyNameMap.get(key), key, 105);
if (rowLeft < 4) {
dashboard.addPortlet(portlet, colLeft, rowLeft++);
} else {//alternate
if (!displayLeft) {
dashboard.addPortlet(portlet, colRight, rowRight++);
} else {
dashboard.addPortlet(portlet, colLeft, rowLeft++);
}
//toggle
displayLeft = !displayLeft;
}
}