/**
* Create a default KPI.
*/
public CommandResponse actionCreateKPI(final Panel panel, final CommandRequest request) throws Exception {
// By now, make the panel work with a hard-coded KPI.
KPI kpi = DataDisplayerServices.lookup().getKPIManager().createKPI();
// Set the KPI's data provider
String initialProvider = request.getRequestObject().getParameter("initialProvider");
DataProvider provider = DataDisplayerServices.lookup().getDataProviderManager().getDataProviderByCode(initialProvider);
kpi.setDataProvider(provider);
// Set the KPI's data displayer
DataDisplayerType displayerType = DataDisplayerServices.lookup().getDataDisplayerManager().getDisplayerTypeByUid(BarChartDisplayerType.UID);
BarChartDisplayer displayer = (BarChartDisplayer) displayerType.createDataDisplayer();
displayer.setDefaultSettings();
displayer.setTitle(kpi.getDescription(LocaleManager.currentLocale()));
displayer.setDataProvider(provider);
kpi.setDataDisplayer(displayer);
kpi.setCode(null);
kpi.save(); // The KPI's id and code are auto-generated here.
// Set a default description
Locale locale = LocaleManager.currentLocale();
ResourceBundle i18n = localeManager.getBundle("org.jboss.dashboard.ui.panel.kpi.messages", locale);
kpi.setDescription(i18n.getString("kpiDriver.newKpi"), locale);
// Save the relationship between the panel and the KPI.
panel.getInstance().setParameterValue(DashboardHandler.KPI_CODE, kpi.getCode());
// Go to edit mode.
passKPItoUI(kpi);
return panelActionEditMode(panel, request);
}