Skip to content

Commit

Permalink
draft for poly string panel
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Mar 20, 2019
1 parent c1353af commit c1c2846
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 1 deletion.
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<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 wicket:id="fullDataContainer">
<div class="row">
<div class="col-md-4"><wicket:message key="PolyStringEditorPanel.defaultLabel" /></div>
<div class="col-md-8" wicket:id="origValue"/>
</div>
<div class="row">
<div class="col-md-4"><wicket:message key="PolyStringEditorPanel.keyLabel" /></div>
<div class="col-md-8" wicket:id="keyValue"/>
</div>
<div wicket:id="languagesRepeater" class="row">
<div class="col-md-4" wicket:id="languageName" />
<div class="col-md-8" wicket:id="translation"/>
</div>
</div>
<div class="show-empty-button" wicket:id="showHideLanguages"/>

</wicket:panel>
</html>
@@ -0,0 +1,136 @@
/*
* 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.web.component.prism;

import com.evolveum.midpoint.gui.api.component.BasePanel;
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.prism.xml.ns._public.types_3.PolyStringTranslationArgumentType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import java.util.ArrayList;
import java.util.List;

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

private static final String ID_DEFAULT_VALUE_PANEL = "defaultValuePanel";
private static final String ID_FULL_DATA_CONTAINER = "fullDataContainer";
private static final String ID_ORIG_VALUE = "origValue";
private static final String ID_KEY_VALUE = "keyValue";
private static final String ID_LANGUAGES_REPEATER = "languagesRepeater";
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 boolean showFullData = false;

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

@Override
protected void onInitialize(){
initLayout();
}

private void initLayout(){
TextPanel<String> defaultValuePanel = new TextPanel<String>(ID_DEFAULT_VALUE_PANEL, Model.of(getDefaultPolyStringValue()));
defaultValuePanel.setOutputMarkupId(true);
defaultValuePanel.add(new VisibleBehaviour(() -> !showFullData));
add(defaultValuePanel);

WebMarkupContainer fullDataContainer = new WebMarkupContainer(ID_FULL_DATA_CONTAINER);
fullDataContainer.setOutputMarkupId(true);
fullDataContainer.add(new VisibleBehaviour(() -> showFullData));
add(fullDataContainer);

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

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

ListView<PolyStringTranslationArgumentType> languagesContainer =
new ListView<PolyStringTranslationArgumentType>(ID_LANGUAGES_REPEATER, Model.ofList(getTranslationArgumentList())) {
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<PolyStringTranslationArgumentType> listItem) {
Label languageName = new Label(ID_LANGUAGE_NAME, Model.of(listItem.getModelObject().getValue()));
languageName.setOutputMarkupId(true);
listItem.add(languageName);

//TODO what value do we need to display?
TextPanel<String> translation = new TextPanel<String>(ID_TRANSLATION, Model.of(listItem.getModelObject().getTranslation().toString()));
translation.setOutputMarkupId(true);
listItem.add(translation);

}
};
languagesContainer.setOutputMarkupId(true);
fullDataContainer.add(languagesContainer);


AjaxButton showHideLanguagesButton = new AjaxButton(ID_SHOW_HIDE_LANGUAGES, showFullData ? createStringResource("PolyStringEditorPanel.hideLanguages") :
createStringResource("PolyStringEditorPanel.showLanguages")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
showFullData = !showFullData;
target.add(PolyStringEditorPanel.this);
}
};
showHideLanguagesButton.setOutputMarkupId(true);
showHideLanguagesButton.add(AttributeAppender.append("style", "cursor: pointer;"));
add(showHideLanguagesButton);

}

private String getDefaultPolyStringValue(){
return "";
}

private String getKeyValue(){
return "";
}

private List<PolyStringTranslationArgumentType> getTranslationArgumentList(){
if (getModel() == null || getModelObject() == null || getModelObject().getTranslation() == null ||
getModelObject().getTranslation().getArgument() == null){
return new ArrayList<>();
}
return getModelObject().getTranslation().getArgument();
}

}
Expand Up @@ -4378,4 +4378,8 @@ operation.com.evolveum.midpoint.web.page.admin.configuration.InternalsThreadsPan
InternalsCountersPanel.thresholds=Thresholds
PageInternals.title.thresholds.counters=Thresholds counters
InternalsCountersPanel.reset.confirm.message=Do you really want to remove counters for {0} ({1})
InternalsCountersPanel.threshold.reset.button=Reset
InternalsCountersPanel.threshold.reset.button=Reset
PolyStringEditorPanel.defaultLabel=default
PolyStringEditorPanel.keyLabel=key
PolyStringEditorPanel.showLanguages=Show languages
PolyStringEditorPanel.hideLanguages=Hide languages

0 comments on commit c1c2846

Please sign in to comment.