@Override
public DynamicForm getCustomSettingsForm() {
DynamicForm customSettingsForm = new DynamicForm();
EnhancedVLayout page = new EnhancedVLayout();
DynamicForm filterForm = new DynamicForm();
filterForm.setMargin(5);
final DashboardPortlet storedPortlet = this.portletWindow.getStoredPortlet();
final Configuration portletConfig = storedPortlet.getConfiguration();
// drift category selector
SelectItem categoryFilter = new SelectItem("Category", MSG.common_title_category());
categoryFilter.setWrapTitle(false);
categoryFilter.setWidth(200);
categoryFilter.setMultiple(true);
categoryFilter.setMultipleAppearance(MultipleAppearance.PICKLIST);
LinkedHashMap<String, String> categories = new LinkedHashMap<String, String>(3);
categories.put(DriftCategory.FILE_ADDED.name(), MSG.view_drift_category_fileAdded());
categories.put(DriftCategory.FILE_CHANGED.name(), MSG.view_drift_category_fileChanged());
categories.put(DriftCategory.FILE_REMOVED.name(), MSG.view_drift_category_fileRemoved());
//TODO icons?
/*
LinkedHashMap<String, String> priorityIcons = new LinkedHashMap<String, String>(3);
priorityIcons.put(AlertPriority.HIGH.name(), ImageManager.getAlertIcon(AlertPriority.HIGH));
priorityIcons.put(AlertPriority.MEDIUM.name(), ImageManager.getAlertIcon(AlertPriority.MEDIUM));
priorityIcons.put(AlertPriority.LOW.name(), ImageManager.getAlertIcon(AlertPriority.LOW));
*/
categoryFilter.setValueMap(categories);
//categoryFilter.setValueIcons(priorityIcons);
//reload current settings if they exist, otherwise enable all.
String currentValue = portletConfig.getSimple(DRIFT_CATEGORY).getStringValue();
if (currentValue.isEmpty() || currentValue.split(",").length == DriftCategory.values().length) {
categoryFilter.setValues(DriftCategory.names());
} else {
//spinder:3/4/11 doing this nonsense due to some weird smartgwt issue with SelectItem in VLayout.
if (currentValue.equalsIgnoreCase(DriftCategory.FILE_ADDED.name())) {
categoryFilter.setValues(DriftCategory.FILE_ADDED.name());
} else if (currentValue.equalsIgnoreCase(DriftCategory.FILE_CHANGED.name())) {
categoryFilter.setValues(DriftCategory.FILE_CHANGED.name());
} else if (currentValue.equalsIgnoreCase(DriftCategory.FILE_REMOVED.name())) {
categoryFilter.setValues(DriftCategory.FILE_REMOVED.name());
} else if (currentValue.equalsIgnoreCase(DriftCategory.FILE_ADDED.name() + ","
+ DriftCategory.FILE_CHANGED.name())) {
categoryFilter.setValues(DriftCategory.FILE_ADDED.name(), DriftCategory.FILE_CHANGED.name());
} else if (currentValue.equalsIgnoreCase(DriftCategory.FILE_ADDED.name() + ","
+ DriftCategory.FILE_REMOVED.name())) {
categoryFilter.setValues(DriftCategory.FILE_ADDED.name(), DriftCategory.FILE_REMOVED.name());
} else {
categoryFilter.setValues(DriftCategory.FILE_CHANGED.name(), DriftCategory.FILE_REMOVED.name());
}
}
final SelectItem driftCategorySelector = categoryFilter;
// result count selector
final SelectItem resultCountSelector = PortletConfigurationEditorComponent.getResultCountEditor(portletConfig);
// range selector
final CustomConfigMeasurementRangeEditor measurementRangeEditor = PortletConfigurationEditorComponent
.getMeasurementRangeEditor(portletConfig);
filterForm.setItems(driftCategorySelector, resultCountSelector);
//submit handler
customSettingsForm.addSubmitValuesHandler(new SubmitValuesHandler() {
@Override
public void onSubmitValues(SubmitValuesEvent event) {
// category
String selectedValue = driftCategorySelector.getValue().toString();
if ((selectedValue.trim().isEmpty())
|| (selectedValue.split(",").length == DriftCategory.values().length)) {
// no severity filter
selectedValue = Constant.ALERT_PRIORITY_DEFAULT;
}
portletConfig.put(new PropertySimple(DRIFT_CATEGORY, selectedValue));
// result count
selectedValue = resultCountSelector.getValue().toString();
if (selectedValue.trim().isEmpty()) {
selectedValue = Constant.RESULT_COUNT_DEFAULT;
}
portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, selectedValue));
// time range settings
saveMeasurementRangeEditorSettings(measurementRangeEditor, portletConfig);
// persist and reload portlet
storedPortlet.setConfiguration(portletConfig);
configure(portletWindow, storedPortlet);
//apply latest settings to the visible result set
refresh();
}
});
page.addMember(measurementRangeEditor);
page.addMember(filterForm);
customSettingsForm.addChild(page);
return customSettingsForm;
}