Skip to content

Commit

Permalink
poly string panel factory
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Apr 30, 2019
1 parent d17393f commit 3a50085
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 40 deletions.
Expand Up @@ -3542,20 +3542,20 @@ public static void saveTask(PrismObject<TaskType> oldTask, OperationResult resul
result.recomputeStatus();
}

public static String getDisplayPolyStringValue(PolyStringType polyString, PageBase pageBase){
public static String getDisplayPolyStringValue(PolyString polyString, PageBase pageBase){
if (polyString == null){
return null;
}
if ((polyString.getTranslation() == null || StringUtils.isEmpty(polyString.getTranslation().getKey())) &&
(polyString.getLang() == null || polyString.getLang().getLang() == null || polyString.getLang().getLang().isEmpty())){
(polyString.getLang() == null || polyString.getLang() == null || polyString.getLang().isEmpty())){
return polyString.getOrig();
}
if (polyString.getLang() != null && polyString.getLang().getLang() != null && !polyString.getLang().getLang().isEmpty()){
if (polyString.getLang() != null && polyString.getLang() != null && !polyString.getLang().isEmpty()){
//check if it's really selected by user or configured through sysconfig locale
String currentLocale = getCurrentLocale().getLanguage();
for (String language : polyString.getLang().getLang().keySet()){
for (String language : polyString.getLang().keySet()){
if (currentLocale.equals(language)){
return polyString.getLang().getLang().get(language);
return polyString.getLang().get(language);
}
}
}
Expand Down
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.gui.impl.factory;

import com.evolveum.midpoint.gui.api.factory.AbstractGuiComponentFactory;
import com.evolveum.midpoint.gui.api.prism.ItemWrapper;
import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.web.component.prism.PolyStringEditorPanel;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.wicket.markup.html.panel.Panel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
* Created by honchar
*/
@Component
public class PolyStringEditorPanelFactory extends AbstractGuiComponentFactory<PolyString> {

private static final long serialVersionUID = 1L;

@Autowired
GuiComponentRegistry registry;

@PostConstruct
public void register() {
registry.addToRegistry(this);
}
@Override
public <IW extends ItemWrapper> boolean match(IW wrapper) {
return PolyStringType.COMPLEX_TYPE.equals(wrapper.getTypeName());
}

@Override
protected Panel getPanel(PrismPropertyPanelContext<PolyString> panelCtx) {
PolyStringEditorPanel panel = new PolyStringEditorPanel(panelCtx.getComponentId(), panelCtx.getRealValueModel());

return panel;
}

}
Expand Up @@ -17,28 +17,23 @@

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div class="row">
<div wicket:id="defaultValuePanel"/>
</div>
<div class="row" wicket:id="fullDataContainer">
<div wicket:id="defaultValuePanel"/>
<div wicket:id="fullDataContainer">
<div class="row">
<div class="col-md-3"><wicket:message key="PolyStringEditorPanel.defaultLabel" /></div>
<div class="col-md-8" wicket:id="origValue"/>
<div class="col-md-9" wicket:id="origValue"/>
</div>
<div class="row">
<div class="col-md-3"><wicket:message key="PolyStringEditorPanel.keyLabel" /></div>
<div class="col-md-8" wicket:id="keyValue"/>
<div class="col-md-9" wicket:id="keyValue"/>
</div>
<div wicket:id="languagesRepeater" class="row">
<div class="col-md-3" wicket:id="languageName" />
<div class="col-md-8" wicket:id="translation"/>
</div>
<div class="row">
<button wicket:id="addLanguageButton" wicket:message="title:PolyStringEditorPanel.addLanguage"
class="btn btn-box-tool pull-left" trigger="hover"><i class="fa fa-plus-circle"></i></button>
<div class="col-md-9" wicket:id="translation"/>
</div>
<div wicket:id="addLanguage" class="show-empty-button" />
</div>
<div class="row show-empty-button" wicket:id="showHideLanguages"/>
<div class="show-empty-button" wicket:id="showHideLanguages"/>

</wicket:panel>
</html>
Expand Up @@ -22,14 +22,9 @@
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringLangType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationArgumentType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
Expand All @@ -42,12 +37,11 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Created by honchar
*/
public class PolyStringEditorPanel extends BasePanel<PolyStringType>{
public class PolyStringEditorPanel extends BasePanel<PolyString>{
private static final long serialVersionUID = 1L;

private static final String ID_DEFAULT_VALUE_PANEL = "defaultValuePanel";
Expand All @@ -58,11 +52,11 @@ public class PolyStringEditorPanel extends BasePanel<PolyStringType>{
private static final String ID_LANGUAGE_NAME = "languageName";
private static final String ID_TRANSLATION = "translation";
private static final String ID_SHOW_HIDE_LANGUAGES = "showHideLanguages";
private static final String ID_ADD_LANGUAGE_BUTTON = "addLanguageButton";
private static final String ID_ADD_LANGUAGE = "addLanguage";

private boolean showFullData = false;

public PolyStringEditorPanel(String id, IModel<PolyStringType> model){
public PolyStringEditorPanel(String id, IModel<PolyString> model){
super(id, model);
}

Expand All @@ -77,7 +71,7 @@ private void initLayout(){

TextPanel<String> defaultValuePanel = new TextPanel<String>(ID_DEFAULT_VALUE_PANEL, Model.of(getDefaultPolyStringValue()));
defaultValuePanel.setOutputMarkupId(true);
defaultValuePanel.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
defaultValuePanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
defaultValuePanel.add(new VisibleBehaviour(() -> !showFullData));
add(defaultValuePanel);

Expand All @@ -87,16 +81,16 @@ private void initLayout(){
add(fullDataContainer);

TextPanel<String> origValue = new TextPanel<String>(ID_ORIG_VALUE, Model.of(getDefaultPolyStringValue()));
origValue.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
origValue.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
origValue.setOutputMarkupId(true);
fullDataContainer.add(origValue);

TextPanel<String> keyValue = new TextPanel<String>(ID_KEY_VALUE, Model.of(getKeyValue()));
keyValue.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
keyValue.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
keyValue.setOutputMarkupId(true);
fullDataContainer.add(keyValue);

Map<String, String> languagesMap = getModelObject() != null && getModelObject().getLang() != null ? getModelObject().getLang().getLang() : new HashMap<>();
Map<String, String> languagesMap = getModelObject() != null && getModelObject().getLang() != null ? getModelObject().getLang() : new HashMap<>();
ListView<String> languagesContainer =
new ListView<String>(ID_LANGUAGES_REPEATER, getLanguagesListModel()) {
private static final long serialVersionUID = 1L;
Expand All @@ -105,8 +99,7 @@ private void initLayout(){
protected void populateItem(ListItem<String> listItem) {
if (StringUtils.isEmpty(listItem.getModelObject())){
TextPanel<String> languageName = new TextPanel<String>(ID_LANGUAGE_NAME, Model.of(listItem.getModelObject()));
languageName.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
languageName.setOutputMarkupId(true);
languageName.getBaseFormComponent().setOutputMarkupId(true);
listItem.add(languageName);
} else {
Label languageName = new Label(ID_LANGUAGE_NAME, Model.of(listItem.getModelObject()));
Expand All @@ -115,7 +108,7 @@ protected void populateItem(ListItem<String> listItem) {
}

TextPanel<String> translation = new TextPanel<String>(ID_TRANSLATION, Model.of(languagesMap.get(listItem.getModelObject())));
translation.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
translation.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
translation.setOutputMarkupId(true);
listItem.add(translation);

Expand All @@ -124,14 +117,16 @@ protected void populateItem(ListItem<String> listItem) {
languagesContainer.setOutputMarkupId(true);
fullDataContainer.add(languagesContainer);

AjaxLink addLanguageButton = new AjaxLink(ID_ADD_LANGUAGE_BUTTON) {
AjaxButton addLanguageButton = new AjaxButton(ID_ADD_LANGUAGE, createStringResource("PolyStringEditorPanel.addLanguage")) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
addNewLanguagePerformed(target);
}
};
addLanguageButton.add(AttributeAppender.append("style", "cursor: pointer;"));
addLanguageButton.setOutputMarkupId(true);
fullDataContainer.add(addLanguageButton);

AjaxButton showHideLanguagesButton = new AjaxButton(ID_SHOW_HIDE_LANGUAGES, new LoadableModel<String>() {
Expand Down Expand Up @@ -173,20 +168,17 @@ private LoadableModel<List<String>> getLanguagesListModel(){

@Override
protected List<String> load() {
Map<String, String> languagesMap = getModelObject() != null && getModelObject().getLang() != null ? getModelObject().getLang().getLang() : new HashMap<>();
Map<String, String> languagesMap = getModelObject() != null && getModelObject().getLang() != null ? getModelObject().getLang() : new HashMap<>();
return new ArrayList<>(languagesMap.keySet());
}
};
}

private void addNewLanguagePerformed(AjaxRequestTarget target){
if (getModelObject().getLang() == null){
getModelObject().setLang(new PolyStringLangType());
}
if (getModelObject().getLang().getLang() == null){
getModelObject().getLang().setLang(new HashMap<String, String>());
getModelObject().setLang(new HashMap<String, String>());
}
getModelObject().getLang().getLang().put("", "");
getModelObject().getLang().put("", "");
target.add(PolyStringEditorPanel.this);

}
Expand Down

0 comments on commit 3a50085

Please sign in to comment.