Skip to content

Commit

Permalink
language picker , styles not finished
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Nov 4, 2019
1 parent 7ccd9fc commit 5b88ff5
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 35 deletions.
Expand Up @@ -798,7 +798,7 @@ private void initHeaderLayout(WebMarkupContainer container) {
container.add(rightMenu);

LocalePanel locale = new LocalePanel(ID_LOCALE);
locale.add(createUserStatusBehaviour(false));
// locale.add(createUserStatusBehaviour(false));
container.add(locale);
}

Expand Down
Expand Up @@ -17,14 +17,26 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<select wicket:id="select" class="selectpicker select-picker-sm pull-right" data-width="auto">
<!--<option data-icon="flag-gb">&nbsp;English</option>-->
<!--<option data-icon="flag-sk">&nbsp;Slovensky</option>-->
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<img wicket:id="localeIcon" />
</a>
<ul class="dropdown-menu pull-right" >
<li wicket:id="locales">
<img wicket:id="localeItemIcon" class="pull-left" style="margin-top: 5px !important;"></img>
<a wicket:id="localeLink" style="display: inline !important; padding: 3px 10px !important;">&nbsp;</a>
</li>
</ul>

<wicket:container wicket:id="options">
<option wicket:id="option">Option Label</option>
</wicket:container>
</select>


<!--<select wicket:id="select" class="selectpicker select-picker-sm pull-right" data-width="auto">-->
<!--&lt;!&ndash;<option data-icon="flag-gb">&nbsp;English</option>&ndash;&gt;-->
<!--&lt;!&ndash;<option data-icon="flag-sk">&nbsp;Slovensky</option>&ndash;&gt;-->

<!--<wicket:container wicket:id="options">-->
<!--<option wicket:id="option">Option Label</option>-->
<!--</wicket:container>-->
<!--</select>-->

<!--<ul wicket:id="locale" class="locales">-->
<!--<li wicket:id="locales" class="locale">-->
Expand Down
Expand Up @@ -9,21 +9,29 @@

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.page.self.component.DashboardSearchPanel;
import com.evolveum.midpoint.web.security.LocaleDescriptor;
import com.evolveum.midpoint.web.security.MidPointApplication;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.markup.html.form.select.IOptionRenderer;
import org.apache.wicket.extensions.markup.html.form.select.Select;
import org.apache.wicket.extensions.markup.html.form.select.SelectOption;
import org.apache.wicket.extensions.markup.html.form.select.SelectOptions;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
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.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.util.ListModel;

import java.util.ArrayList;
import java.util.Locale;

/**
Expand All @@ -33,51 +41,96 @@ public class LocalePanel extends Panel {

private static final Trace LOGGER = TraceManager.getTrace(LocalePanel.class);

private static final String ID_SELECT = "select";
private static final String ID_OPTIONS = "options";
private static final String ID_LOCALES = "locales";
private static final String ID_LOCALE_ICON = "localeIcon";
private static final String ID_LOCALE_LINK = "localeLink";
private static final String ID_LOCALE_ITEM_ICON = "localeItemIcon";

public LocalePanel(String id) {
super(id);

setRenderBodyOnly(true);

final IModel<LocaleDescriptor> model = new Model(getSelectedLocaleDescriptor());
Select<LocaleDescriptor> select = new Select<>(ID_SELECT, model);
select.add(new AjaxFormComponentUpdatingBehavior("change") {
Label image = new Label(ID_LOCALE_ICON);
image.add(AttributeModifier.replace("class", "flag-" + model.getObject().getFlag()));
image.setOutputMarkupId(true);
add(image);


// Select<LocaleDescriptor> select = new Select<>(ID_SELECT, model);
// select.add(new AjaxFormComponentUpdatingBehavior("change") {
//
// @Override
// protected void onUpdate(AjaxRequestTarget target) {
// changeLocale(target, model.getObject());
// }
// });
// select.setOutputMarkupId(true);
// add(select);

ListView<LocaleDescriptor> locales = new ListView<LocaleDescriptor>(ID_LOCALES,
Model.ofList(MidPointApplication.AVAILABLE_LOCALES)) {

private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
changeLocale(target, model.getObject());
}
});
select.setOutputMarkupId(true);
add(select);
SelectOptions<LocaleDescriptor> options = new SelectOptions<LocaleDescriptor>(ID_OPTIONS,
MidPointApplication.AVAILABLE_LOCALES,
new IOptionRenderer<LocaleDescriptor>() {
protected void populateItem(final ListItem<LocaleDescriptor> item) {
final Label image = new Label(ID_LOCALE_ITEM_ICON);
image.add(AttributeModifier.append("class", "flag-" + item.getModelObject().getFlag()));
image.setOutputMarkupId(true);
item.add(image);

final AjaxLink<String> localeLink = new AjaxLink<String>(ID_LOCALE_LINK) {

private static final long serialVersionUID = 1L;

@Override
public String getDisplayValue(LocaleDescriptor object) {
return object.getName();
public IModel<String> getBody() {
return Model.of(item.getModelObject().getName());
}

@Override
public IModel<LocaleDescriptor> getModel(LocaleDescriptor value) {
return new Model<>(value);
public void onClick(AjaxRequestTarget target) {
changeLocale(target, item.getModelObject());
}
}) {



@Override
protected SelectOption<LocaleDescriptor> newOption(String text, IModel<LocaleDescriptor> model) {
SelectOption option = super.newOption(text, model);
option.add(new AttributeModifier("data-icon", "flag-" + model.getObject().getFlag()));

return option;
};
localeLink.setOutputMarkupId(true);
item.add(localeLink);
}
};
select.add(options);
locales.setOutputMarkupId(true);
add(locales);


// SelectOptions<LocaleDescriptor> options = new SelectOptions<LocaleDescriptor>(ID_OPTIONS,
// MidPointApplication.AVAILABLE_LOCALES,
// new IOptionRenderer<LocaleDescriptor>() {
//
// @Override
// public String getDisplayValue(LocaleDescriptor object) {
// return "";//object.getName();
// }
//
// @Override
// public IModel<LocaleDescriptor> getModel(LocaleDescriptor value) {
// return new Model<>(value);
// }
// }) {
//
//
//
// @Override
// protected SelectOption<LocaleDescriptor> newOption(String text, IModel<LocaleDescriptor> model) {
// SelectOption option = super.newOption(text, model);
// option.add(new AttributeModifier("data-icon", "flag-" + model.getObject().getFlag()));
//
// return option;
// }
// };
// add(options);
}

private LocaleDescriptor getSelectedLocaleDescriptor() {
Expand All @@ -104,7 +157,7 @@ private LocaleDescriptor getSelectedLocaleDescriptor() {
public void renderHead(IHeaderResponse response) {
super.renderHead(response);

String selectId = get(ID_SELECT).getMarkupId();
String selectId = get(ID_LOCALE_ICON).getMarkupId();
response.render(OnDomReadyHeaderItem.forScript("$('#" + selectId + "').selectpicker({});"));
}

Expand Down
Expand Up @@ -71,6 +71,10 @@ div.wicket-aa-container {
}
}

ul.locale-dropdown{
left: -110px !important;
}

div.wicket-debug-buttons {
border: 1px solid #000000;
background-color: #ffffff;
Expand Down

0 comments on commit 5b88ff5

Please sign in to comment.