-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding input field with insight for icon css class and color
- Loading branch information
Showing
7 changed files
with
254 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...gui/src/main/java/com/evolveum/midpoint/gui/impl/component/input/IconColorInputPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2010-2024 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.gui.impl.component.input; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil; | ||
import com.evolveum.midpoint.gui.api.util.WebComponentUtil; | ||
|
||
import org.apache.commons.text.StringEscapeUtils; | ||
import org.apache.wicket.AttributeModifier; | ||
import org.apache.wicket.ajax.AjaxRequestTarget; | ||
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior; | ||
import org.apache.wicket.markup.html.WebMarkupContainer; | ||
import org.apache.wicket.markup.html.form.FormComponent; | ||
import org.apache.wicket.model.IModel; | ||
|
||
import com.evolveum.midpoint.web.component.prism.InputPanel; | ||
|
||
public abstract class IconColorInputPanel extends IconInputPanel { | ||
|
||
public IconColorInputPanel(String componentId, IModel<String> valueModel) { | ||
super(componentId, valueModel); | ||
} | ||
|
||
@Override | ||
protected void customProcessOfInsight(WebMarkupContainer insight) { | ||
insight.add(AttributeModifier.replace("style", () -> "color: " + getIconColor() + ";")); | ||
} | ||
|
||
private String getIconColor() { | ||
String color = getValueModel().getObject(); | ||
if (color == null) { | ||
return ""; | ||
} | ||
return GuiDisplayTypeUtil.removeStringAfterSemicolon(color); | ||
} | ||
|
||
protected String getCssIconClass() { | ||
return "fa fa-square"; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...dmin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/input/IconInputPanel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<!-- | ||
~ Copyright (c) 2022 Evolveum | ||
~ | ||
~ This work is dual-licensed under the Apache License 2.0 | ||
~ and European Union Public License. See LICENSE file for details. | ||
--> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:wicket="http://wicket.apache.org"> | ||
<body> | ||
<wicket:panel> | ||
<div class="input-group"> | ||
<div class="input-group-prepend"> | ||
<span class="input-group-text px-1"> | ||
<i wicket:id="insight"/> | ||
</span> | ||
</div> | ||
<div wicket:id="panel" class="flex-fill"/> | ||
</div> | ||
</wicket:panel> | ||
</body> | ||
</html> |
87 changes: 87 additions & 0 deletions
87
...dmin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/input/IconInputPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (C) 2010-2024 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.gui.impl.component.input; | ||
|
||
import com.evolveum.midpoint.web.component.prism.InputPanel; | ||
|
||
import org.apache.commons.text.StringEscapeUtils; | ||
import org.apache.wicket.AttributeModifier; | ||
import org.apache.wicket.ajax.AjaxRequestTarget; | ||
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior; | ||
import org.apache.wicket.markup.html.WebMarkupContainer; | ||
import org.apache.wicket.markup.html.form.FormComponent; | ||
import org.apache.wicket.model.IModel; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class IconInputPanel extends InputPanel { | ||
|
||
private final String ID_INSIGHT = "insight"; | ||
private final String ID_PANEL = "panel"; | ||
|
||
private final IModel<String> valueModel; | ||
|
||
public IconInputPanel(String componentId, IModel<String> valueModel) { | ||
super(componentId); | ||
this.valueModel = valueModel; | ||
} | ||
|
||
@Override | ||
protected void onInitialize() { | ||
super.onInitialize(); | ||
|
||
initLayout(); | ||
} | ||
|
||
protected abstract InputPanel createPanel(String idPanel); | ||
|
||
private void initLayout() { | ||
setOutputMarkupId(true); | ||
|
||
WebMarkupContainer insight = new WebMarkupContainer(ID_INSIGHT); | ||
insight.add(AttributeModifier.replace( | ||
"class", () -> "fa-fw " + getCssIconClass())); | ||
customProcessOfInsight(insight); | ||
insight.setOutputMarkupId(true); | ||
add(insight); | ||
|
||
InputPanel panel = createPanel(ID_PANEL); | ||
panel.setOutputMarkupId(true); | ||
panel.getBaseFormComponent().add(new OnChangeAjaxBehavior() { | ||
@Override | ||
protected void onUpdate(AjaxRequestTarget target) { | ||
target.add(IconInputPanel.this.get(ID_INSIGHT)); | ||
} | ||
}); | ||
add(panel); | ||
} | ||
|
||
protected void customProcessOfInsight(WebMarkupContainer insight) { | ||
} | ||
|
||
protected String getCssIconClass() { | ||
return (valueModel.getObject() == null ? "" : StringEscapeUtils.escapeHtml4(valueModel.getObject())); | ||
} | ||
|
||
@Override | ||
public FormComponent getBaseFormComponent() { | ||
InputPanel panel = (InputPanel) get(ID_PANEL); | ||
return panel == null ? null : panel.getBaseFormComponent(); | ||
} | ||
|
||
@Override | ||
public List<FormComponent> getFormComponents() { | ||
InputPanel panel = (InputPanel) get(ID_PANEL); | ||
return panel == null ? new ArrayList<>() : panel.getFormComponents(); | ||
} | ||
|
||
protected final IModel<String> getValueModel() { | ||
return valueModel; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/IconColorPanelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2010-2024 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.gui.impl.factory.panel; | ||
|
||
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper; | ||
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper; | ||
import com.evolveum.midpoint.gui.impl.component.input.IconColorInputPanel; | ||
import com.evolveum.midpoint.util.QNameUtil; | ||
import com.evolveum.midpoint.web.component.prism.InputPanel; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.IconType; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.Serializable; | ||
|
||
@Component | ||
public class IconColorPanelFactory extends TextPanelFactory<String> implements Serializable { | ||
|
||
@Override | ||
public <IW extends ItemWrapper<?, ?>, VW extends PrismValueWrapper<?>> boolean match(IW wrapper, VW valueWrapper) { | ||
if (wrapper.getParentContainerValue(IconType.class) == null) { | ||
return false; | ||
} | ||
return QNameUtil.match(wrapper.getItemName(), IconType.F_COLOR); | ||
} | ||
|
||
@Override | ||
protected InputPanel getPanel(PrismPropertyPanelContext<String> panelCtx) { | ||
return new IconColorInputPanel(panelCtx.getComponentId(), panelCtx.getRealValueModel()) { | ||
@Override | ||
protected InputPanel createPanel(String idPanel) { | ||
panelCtx.setComponentId(idPanel); | ||
return IconColorPanelFactory.super.getPanel(panelCtx); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Integer getOrder() { | ||
return 1000; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/IconCssClassPanelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2010-2024 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.gui.impl.factory.panel; | ||
|
||
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper; | ||
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper; | ||
import com.evolveum.midpoint.gui.impl.component.input.IconInputPanel; | ||
import com.evolveum.midpoint.util.QNameUtil; | ||
import com.evolveum.midpoint.web.component.prism.InputPanel; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.IconType; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.Serializable; | ||
|
||
@Component | ||
public class IconCssClassPanelFactory extends TextPanelFactory<String> implements Serializable { | ||
|
||
@Override | ||
public <IW extends ItemWrapper<?, ?>, VW extends PrismValueWrapper<?>> boolean match(IW wrapper, VW valueWrapper) { | ||
if (wrapper.getParentContainerValue(IconType.class) == null) { | ||
return false; | ||
} | ||
return QNameUtil.match(wrapper.getItemName(), IconType.F_CSS_CLASS); | ||
} | ||
|
||
@Override | ||
protected InputPanel getPanel(PrismPropertyPanelContext<String> panelCtx) { | ||
return new IconInputPanel(panelCtx.getComponentId(), panelCtx.getRealValueModel()) { | ||
@Override | ||
protected InputPanel createPanel(String idPanel) { | ||
panelCtx.setComponentId(idPanel); | ||
return IconCssClassPanelFactory.super.getPanel(panelCtx); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Integer getOrder() { | ||
return 1000; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters