Skip to content

Commit

Permalink
string resource model - do not use component
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Mar 16, 2022
1 parent a023420 commit 055a479
Show file tree
Hide file tree
Showing 49 changed files with 380 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public String getString(Enum<?> e) {
}

public StringResourceModel createStringResource(String resourceKey, IModel<?> model, Object... objects) {
return new StringResourceModel(resourceKey, this).setModel(model)
return new StringResourceModel(resourceKey).setModel(model)
.setDefaultValue(resourceKey)
.setParameters(objects);
}

public StringResourceModel createStringResource(String resourceKey, Object... objects) {
return new StringResourceModel(resourceKey, this).setModel(null)
return new StringResourceModel(resourceKey).setModel(null)
.setDefaultValue(resourceKey)
.setParameters(objects);
}
Expand All @@ -84,7 +84,7 @@ public StringResourceModel createStringResource(PolyString polystringKey, Object
// TODO later: use polystringKey.getKey()
resourceKey = polystringKey.getOrig();
}
return new StringResourceModel(resourceKey, this).setModel(null)
return new StringResourceModel(resourceKey).setModel(null)
.setDefaultValue(resourceKey)
.setParameters(objects);
}
Expand All @@ -95,7 +95,7 @@ public StringResourceModel createStringResource(PolyStringType polystringKey, Ob
// TODO later: use polystringKey.getKey()
resourceKey = polystringKey.getOrig();
}
return new StringResourceModel(resourceKey, this).setModel(null)
return new StringResourceModel(resourceKey).setModel(null)
.setDefaultValue(resourceKey)
.setParameters(objects);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,6 @@ protected List<ObjectTypes> getObjectTypesList() {

@Override
public StringResourceModel getTitle() {
return PageBase.createStringResourceStatic(TypedAssignablePanel.this, "TypedAssignablePanel.selectObjects");
return PageBase.createStringResourceStatic("TypedAssignablePanel.selectObjects");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ protected void onComponentTag(ComponentTag tag) {
password1.add(AttributeAppender.append("onfocus", "initPasswordValidation({\n"
+ "container: $('#progress-bar-container'),\n"
+ "hierarchy: {\n"
+ " '0': ['progress-bar-danger', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.veryWeak").getString() + "'],\n"
+ " '25': ['progress-bar-danger', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.weak").getString() + "'],\n"
+ " '50': ['progress-bar-warning', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.good").getString() + "'],\n"
+ " '75': ['progress-bar-success', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.strong").getString() + "'],\n"
+ " '100': ['progress-bar-success', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.veryStrong").getString() + "']\n"
+ " '0': ['progress-bar-danger', '" + PageBase.createStringResourceStatic("PasswordPanel.strength.veryWeak").getString() + "'],\n"
+ " '25': ['progress-bar-danger', '" + PageBase.createStringResourceStatic("PasswordPanel.strength.weak").getString() + "'],\n"
+ " '50': ['progress-bar-warning', '" + PageBase.createStringResourceStatic("PasswordPanel.strength.good").getString() + "'],\n"
+ " '75': ['progress-bar-success', '" + PageBase.createStringResourceStatic("PasswordPanel.strength.strong").getString() + "'],\n"
+ " '100': ['progress-bar-success', '" + PageBase.createStringResourceStatic("PasswordPanel.strength.veryStrong").getString() + "']\n"
+ "}\n"
+ "})"));
password1.setRequired(false);
Expand Down Expand Up @@ -192,7 +192,7 @@ protected void onUpdate(AjaxRequestTarget target) {
}

if (!Objects.equals(s1, s2)) {
return PageBase.createStringResourceStatic(null, "passwordPanel.error").getString();
return PageBase.createStringResourceStatic("passwordPanel.error").getString();
}
return "";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.evolveum.midpoint.model.api.validator.StringLimitationResult;

import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
Expand All @@ -22,7 +21,6 @@
import org.apache.wicket.model.Model;

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

/**
Expand Down Expand Up @@ -79,13 +77,13 @@ protected IModel<String> getHelpModel() {
private IModel<String> getRulesModel() {
List<String> rules = new ArrayList<>();
if (getModelObject().getMinOccurs() != null) {
rules.add(PageBase.createStringResourceStatic(null, "StringLimitationPanel.min", getModelObject().getMinOccurs()).getString());
rules.add(PageBase.createStringResourceStatic("StringLimitationPanel.min", getModelObject().getMinOccurs()).getString());
}
if (getModelObject().getMaxOccurs() != null) {
rules.add(PageBase.createStringResourceStatic(null, "StringLimitationPanel.max", getModelObject().getMaxOccurs()).getString());
rules.add(PageBase.createStringResourceStatic("StringLimitationPanel.max", getModelObject().getMaxOccurs()).getString());
}
if (Boolean.TRUE.equals(getModelObject().isMustBeFirst())) {
rules.add(PageBase.createStringResourceStatic(null, "StringLimitationPanel.mustBeFirst").getString());
rules.add(PageBase.createStringResourceStatic("StringLimitationPanel.mustBeFirst").getString());
}
StringBuilder sb = new StringBuilder("");
if (!rules.isEmpty()) {
Expand All @@ -94,7 +92,7 @@ private IModel<String> getRulesModel() {
if (i != (rules.size() - 1)) {
sb.append(",");
} else {
sb.append(" ").append(PageBase.createStringResourceStatic(null, "StringLimitationPanel.rules.and").getString());
sb.append(" ").append(PageBase.createStringResourceStatic("StringLimitationPanel.rules.and").getString());
}
}
sb.append(" ").append(rules.get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@

<div class="wicket-debug-buttons" wicket:id="debugBar">
<a wicket:id="clearCssCache">Clear css cache</a>

<a wicket:id="dumpPageTree">Dump page tree to console</a>
</div>
<div wicket:id="debugPanel" style="z-index: 10000;"/>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.evolveum.midpoint.gui.api.page;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
Expand Down Expand Up @@ -37,6 +39,7 @@
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.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.protocol.http.WebSession;
Expand Down Expand Up @@ -173,6 +176,7 @@ public abstract class PageBase extends WebPage implements ModelServiceLocator {
private static final String ID_FEEDBACK = "feedback";
private static final String ID_DEBUG_BAR = "debugBar";
private static final String ID_CLEAR_CACHE = "clearCssCache";
private static final String ID_DUMP_PAGE_TREE = "dumpPageTree";
private static final String ID_CART_BUTTON = "cartButton";
private static final String ID_CART_ITEMS_COUNT = "itemsCount";
private static final String ID_SIDEBAR_MENU = "sidebarMenu";
Expand Down Expand Up @@ -615,7 +619,7 @@ public boolean hasSubjectRoleRelation(String oid, List<QName> subjectRelations)

public static StringResourceModel createStringResourceStatic(Component component, Enum<?> e) {
String resourceKey = createEnumResourceKey(e);
return createStringResourceStatic(component, resourceKey);
return createStringResourceStatic(resourceKey);
}

public static String createEnumResourceKey(Enum<?> e) {
Expand Down Expand Up @@ -704,30 +708,22 @@ public String getObject() {
pageTitleReal.setRenderBodyOnly(true);
pageTitle.add(pageTitleReal);

IModel<List<Breadcrumb>> breadcrumbsModel = new IModel<>() {

private static final long serialVersionUID = 1L;

@Override
public List<Breadcrumb> getObject() {
return getBreadcrumbs();
}
};
IModel<List<Breadcrumb>> breadcrumbsModel = () -> getBreadcrumbs();

ListView<Breadcrumb> breadcrumbs = new ListView<>(ID_BREADCRUMB, breadcrumbsModel) {

private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<Breadcrumb> item) {
final Breadcrumb dto = item.getModelObject();
// final Breadcrumb dto = item.getModelObject();

AjaxLink<String> bcLink = new AjaxLink<>(ID_BC_LINK) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
redirectBackToBreadcrumb(dto);
redirectBackToBreadcrumb(item.getModelObject());
}
};
item.add(bcLink);
Expand All @@ -736,7 +732,7 @@ public void onClick(AjaxRequestTarget target) {

@Override
public boolean isEnabled() {
return dto.isUseLink();
return item.getModelObject().isUseLink();
}
});

Expand All @@ -746,21 +742,21 @@ public boolean isEnabled() {

@Override
public boolean isVisible() {
return dto.getIcon() != null && dto.getIcon().getObject() != null;
return item.getModelObject().getIcon() != null && item.getModelObject().getIcon().getObject() != null;
}
});
bcIcon.add(AttributeModifier.replace("class", dto.getIcon()));
bcIcon.add(AttributeModifier.replace("class", item.getModelObject().getIcon()));
bcLink.add(bcIcon);

Label bcName = new Label(ID_BC_NAME, dto.getLabel());
Label bcName = new Label(ID_BC_NAME, item.getModelObject().getLabel());
bcLink.add(bcName);

item.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
return dto.isVisible();
return item.getModelObject().isVisible();
}
});
}
Expand Down Expand Up @@ -1100,6 +1096,24 @@ public void onClick(AjaxRequestTarget target) {
}
};
debugBar.add(clearCache);

AjaxButton dumpPageTree = new AjaxButton(ID_DUMP_PAGE_TREE, createStringResource("PageBase.dumpPageTree")) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
dumpPageTree(target);
}
};
debugBar.add(dumpPageTree);
}

private void dumpPageTree(AjaxRequestTarget target) {
try (PrintWriter pw = new PrintWriter(System.out)) {
new PageStructureDump().dumpStructure(this, pw);
} catch (IOException ex) {
ex.printStackTrace();
}
}

protected void clearLessJsCache(AjaxRequestTarget target) {
Expand Down Expand Up @@ -1188,15 +1202,16 @@ private Label getHeaderTitle() {
}

public IModel<String> getPageTitleModel() {
return (IModel<String>) get(ID_TITLE).getDefaultModel();
String title = (String) get(ID_TITLE).getDefaultModel().getObject();
return Model.of(title);
}

public String getString(String resourceKey, Object... objects) {
return createStringResource(resourceKey, objects).getString();
}

public StringResourceModel createStringResource(String resourceKey, Object... objects) {
return new StringResourceModel(resourceKey, this).setModel(new Model<String>()).setDefaultValue(resourceKey)
return new StringResourceModel(resourceKey).setModel(new Model<String>()).setDefaultValue(resourceKey)
.setParameters(objects);
}

Expand All @@ -1210,7 +1225,7 @@ public StringResourceModel createStringResource(PolyString polystringKey, Object
if (polystringKey != null) {
resourceKey = localizationService.translate(polystringKey, WebComponentUtil.getCurrentLocale(), true);
}
return new StringResourceModel(resourceKey, this).setModel(new Model<String>()).setDefaultValue(resourceKey)
return new StringResourceModel(resourceKey).setModel(new Model<String>()).setDefaultValue(resourceKey)
.setParameters(objects);
}

Expand All @@ -1219,7 +1234,7 @@ public StringResourceModel createStringResource(PolyStringType polystringKey, Ob
if (polystringKey != null) {
resourceKey = localizationService.translate(PolyString.toPolyString(polystringKey), WebComponentUtil.getCurrentLocale(), true);
}
return new StringResourceModel(resourceKey, this).setModel(new Model<String>()).setDefaultValue(resourceKey)
return new StringResourceModel(resourceKey).setModel(new Model<String>()).setDefaultValue(resourceKey)
.setParameters(objects);
}

Expand All @@ -1229,9 +1244,9 @@ public StringResourceModel createStringResource(Enum<?> e) {
}

@NotNull
public static StringResourceModel createStringResourceStatic(Component component, String resourceKey,
public static StringResourceModel createStringResourceStatic(String resourceKey,
Object... objects) {
return new StringResourceModel(resourceKey, component).setModel(new Model<String>())
return new StringResourceModel(resourceKey).setModel(new Model<String>())
.setDefaultValue(resourceKey).setParameters(objects);
}

Expand Down

0 comments on commit 055a479

Please sign in to comment.