Skip to content

Commit

Permalink
polystring panel fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Aug 27, 2019
1 parent e66d88d commit 71c2ba3
Showing 1 changed file with 23 additions and 3 deletions.
Expand Up @@ -72,6 +72,7 @@ public class PolyStringEditorPanel extends BasePanel<PolyString>{
private static final String ID_REMOVE_LANGUAGE_BUTTON = "removeLanguageButton";

private boolean showFullData = false;
private final StringBuilder currentlySelectedLang = new StringBuilder();

public PolyStringEditorPanel(String id, IModel<PolyString> model){
super(id, model);
Expand Down Expand Up @@ -202,14 +203,26 @@ public void detach() {
keyValue.setOutputMarkupId(true);
fullDataContainer.add(keyValue);

IModel<String> langChoiceModel = Model.of();
WebMarkupContainer languageEditorContainer = new WebMarkupContainer(ID_LANGUAGE_EDITOR);
languageEditorContainer.setOutputMarkupId(true);
languageEditorContainer.add(new VisibleBehaviour(() -> CollectionUtils.isNotEmpty(getLanguageChoicesModel().getObject())));
fullDataContainer.add(languageEditorContainer);

final DropDownChoicePanel<String> languageChoicePanel = new DropDownChoicePanel<String>(ID_LANGUAGES_LIST, Model.of(),
final DropDownChoicePanel<String> languageChoicePanel = new DropDownChoicePanel<String>(ID_LANGUAGES_LIST, langChoiceModel,
getLanguageChoicesModel(), true);
languageChoicePanel.setOutputMarkupId(true);
languageChoicePanel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
languageChoicePanel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {
private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
removeLanguageValue(currentlySelectedLang.toString());
clearSelectedLanguageValue();
currentlySelectedLang.append(getLanguagesChoicePanel().getBaseFormComponent().getModelObject());
}
});
languageEditorContainer.add(languageChoicePanel);

final TextPanel<String> newLanguageValue = new TextPanel<String>(ID_VALUE_TO_ADD, Model.of());
Expand Down Expand Up @@ -249,6 +262,7 @@ public void onClick(AjaxRequestTarget target) {
newLanguageValue.getBaseFormComponent().getModelObject());
languageChoicePanel.getModel().setObject(null);
newLanguageValue.getBaseFormComponent().getModel().setObject(null);
clearSelectedLanguageValue();
target.add(PolyStringEditorPanel.this);
}
};
Expand Down Expand Up @@ -334,10 +348,12 @@ private IModel<List<String>> getLanguageChoicesModel(){
@Override
public List<String> getObject() {
List<String> allLanguagesList = new ArrayList<>();
String currentlySelectedLang = getLanguagesChoicePanel().getBaseFormComponent().getModel().getObject();
MidPointApplication.AVAILABLE_LOCALES.forEach(locale -> {
String localeValue = locale.getLocale().getLanguage();
if (!isPolyStringLangNotNull()) {
allLanguagesList.add(locale.getLocale().getLanguage());
} else if (!languageExists(locale.getLocale().getLanguage())){
allLanguagesList.add(localeValue);
} else if (!languageExists(localeValue) || localeValue.equals(currentlySelectedLang)){
allLanguagesList.add(locale.getLocale().getLanguage());
}
});
Expand Down Expand Up @@ -452,4 +468,8 @@ private String getLanguageValueByKey(String key){
private DropDownChoicePanel<String> getLanguagesChoicePanel(){
return (DropDownChoicePanel<String>)get(ID_FULL_DATA_CONTAINER).get(ID_LANGUAGE_EDITOR).get(ID_LANGUAGES_LIST);
}

private void clearSelectedLanguageValue(){
currentlySelectedLang.delete(0, currentlySelectedLang.length());
}
}

0 comments on commit 71c2ba3

Please sign in to comment.