private AccountDAO accountDAO;
@Override
public LoadOptionsResult execute(LoadOptionsAction action,
ExecutionContext context) throws ActionException {
UserConfigHolder configHolder = new UserConfigHolder();
HAccount account =
accountDAO.findById(authenticatedAccount.getId(), true);
Map<String, HAccountOption> options = account.getEditorOptions();
HashMap<String, HAccountOption> filteredOptions =
new HashMap<String, HAccountOption>();
for (Entry<String, HAccountOption> entry : options.entrySet()) {
// filter config according to prefix
if (action.getPrefixes() != null && !action.getPrefixes().isEmpty()) {
for (String prefix : action.getPrefixes()) {
if (entry.getKey().startsWith(prefix)) {
filteredOptions.put(entry.getKey(), entry.getValue());
}
}
} else {
filteredOptions.put(entry.getKey(), entry.getValue());
}
}
if (filteredOptions.containsKey(UserOptions.DisplayButtons
.getPersistentName())) {
configHolder.setDisplayButtons(filteredOptions.get(
UserOptions.DisplayButtons.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.EnterSavesApproved
.getPersistentName())) {
configHolder.setEnterSavesApproved(filteredOptions.get(
UserOptions.EnterSavesApproved.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.Navigation
.getPersistentName())) {
configHolder.setNavOption(NavOption.valueOf(filteredOptions.get(
UserOptions.Navigation.getPersistentName()).getValue()));
}
if (filteredOptions.containsKey(UserOptions.EditorPageSize
.getPersistentName())) {
configHolder.setEditorPageSize(filteredOptions.get(
UserOptions.EditorPageSize.getPersistentName())
.getValueAsInt());
}
if (filteredOptions.containsKey(UserOptions.ShowErrors
.getPersistentName())) {
configHolder.setShowError(filteredOptions.get(
UserOptions.ShowErrors.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.Themes.getPersistentName())) {
configHolder.setDisplayTheme(ThemesOption.valueOf(filteredOptions
.get(UserOptions.Themes.getPersistentName()).getValue()));
}
if (filteredOptions.containsKey(UserOptions.UseCodeMirrorEditor
.getPersistentName())) {
configHolder.setUseCodeMirrorEditor(filteredOptions.get(
UserOptions.UseCodeMirrorEditor.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.TransMemoryDisplayMode
.getPersistentName())) {
configHolder.setTMDisplayMode(DiffMode.valueOf(filteredOptions.get(
UserOptions.TransMemoryDisplayMode.getPersistentName())
.getValue()));
}
if (filteredOptions.containsKey(UserOptions.DisplayTransMemory
.getPersistentName())) {
configHolder.setShowTMPanel(filteredOptions.get(
UserOptions.DisplayTransMemory.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.DisplayGlossary
.getPersistentName())) {
configHolder.setShowGlossaryPanel(filteredOptions.get(
UserOptions.DisplayGlossary.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.SelectedReferenceLang
.getPersistentName())) {
configHolder.setSelectedReferenceForSourceLang(filteredOptions.get(
UserOptions.SelectedReferenceLang.getPersistentName())
.getValue());
}
if (filteredOptions
.containsKey(UserOptions.ShowOptionalTransUnitDetails
.getPersistentName())) {
configHolder.setShowOptionalTransUnitDetails(filteredOptions.get(
UserOptions.ShowOptionalTransUnitDetails
.getPersistentName()).getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.TranslatedMessageFilter
.getPersistentName())) {
configHolder.setFilterByTranslated(filteredOptions.get(
UserOptions.TranslatedMessageFilter.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.FuzzyMessageFilter
.getPersistentName())) {
configHolder.setFilterByFuzzy(filteredOptions.get(
UserOptions.FuzzyMessageFilter.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.UntranslatedMessageFilter
.getPersistentName())) {
configHolder.setFilterByUntranslated(filteredOptions.get(
UserOptions.UntranslatedMessageFilter.getPersistentName())
.getValueAsBoolean());
}
if (filteredOptions.containsKey(UserOptions.DocumentListPageSize
.getPersistentName())) {
configHolder.setDocumentListPageSize(filteredOptions.get(
UserOptions.DocumentListPageSize.getPersistentName())
.getValueAsInt());
}
if (filteredOptions.containsKey(UserOptions.ShowSaveApprovedWarning
.getPersistentName())) {
configHolder.setShowSaveApprovedWarning(filteredOptions.get(
UserOptions.ShowSaveApprovedWarning.getPersistentName())
.getValueAsBoolean());
}
return new LoadOptionsResult(configHolder.getState());
}