Skip to content

Commit

Permalink
more cleanup work, major changes:
Browse files Browse the repository at this point in the history
- extracting (abstract) PrismValuePanel from ItemPanel
- implement PrismPropertyValuePanel, PrismReferenceValuePanel and PrismContainerValuePanel with default panels
- introducing AbstractInputGuiComponentFactory - parent abstract factory for all InputPanel panels. add default behaviors, validators, etc.
  • Loading branch information
katkav committed Apr 24, 2020
1 parent 13f63d2 commit a42a7ab
Show file tree
Hide file tree
Showing 63 changed files with 1,748 additions and 849 deletions.
Expand Up @@ -11,6 +11,7 @@
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemVisibilityHandler;
import com.evolveum.midpoint.gui.impl.factory.panel.ItemRealValueModel;
import com.evolveum.midpoint.gui.impl.prism.panel.ItemHeaderPanel;
import com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings;
import com.evolveum.midpoint.gui.impl.prism.panel.PrismPropertyPanel;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyWrapper;
Expand All @@ -28,13 +29,12 @@ public class PasswordPropertyPanel extends PrismPropertyPanel<ProtectedStringTy

private static final String ID_PASSWORD_PANEL= "passwordPanel";

public PasswordPropertyPanel(String id, IModel<PrismPropertyWrapper<ProtectedStringType>> model, ItemHeaderPanel.ItemPanelSettings settings){
public PasswordPropertyPanel(String id, IModel<PrismPropertyWrapper<ProtectedStringType>> model, ItemPanelSettings settings){
super(id, model, settings);
}

@Override
protected Component createValuePanel(ListItem<PrismPropertyValueWrapper<ProtectedStringType>> item, GuiComponentFactory factory,
ItemVisibilityHandler visibilityHandler, ItemEditabilityHandler editabilityHandler) {
protected Component createValuePanel(ListItem<PrismPropertyValueWrapper<ProtectedStringType>> item) {

PasswordPanel passwordPanel = new PasswordPanel(ID_PASSWORD_PANEL, new ItemRealValueModel<>(item.getModel()),
getModelObject() != null && getModelObject().isReadOnly(),
Expand All @@ -58,9 +58,4 @@ protected void changePasswordPerformed(){

}

@Override
protected void createButtons(ListItem<PrismPropertyValueWrapper<ProtectedStringType>> item) {
//nothing to do
}

}
Expand Up @@ -13,6 +13,7 @@
import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;

import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.markup.html.panel.Panel;

import com.evolveum.midpoint.gui.impl.factory.panel.PrismPropertyPanelContext;
Expand All @@ -33,7 +34,7 @@ public GuiComponentRegistry getRegistry() {
@Override
public Panel createPanel(PrismPropertyPanelContext<T> panelCtx) {
Panel panel = getPanel(panelCtx);

panelCtx.getFeedback().setFilter(new ComponentFeedbackMessageFilter(panel));
return panel;
}

Expand All @@ -44,7 +45,5 @@ public Integer getOrder() {

protected abstract Panel getPanel(PrismPropertyPanelContext<T> panelCtx);

protected List<String> prepareAutoCompleteList(String input, LookupTableType lookupTable, LocalizationService localizationService) {
return WebComponentUtil.prepareAutoCompleteList(lookupTable, input, localizationService);
}

}
Expand Up @@ -16,6 +16,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.impl.prism.panel.ItemHeaderPanel;
import com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings;
import com.evolveum.midpoint.web.page.admin.PageAdminObjectDetails;

import com.evolveum.midpoint.web.page.admin.certification.*;
Expand Down Expand Up @@ -2678,7 +2679,6 @@ public void reloadShoppingCartIcon(AjaxRequestTarget target) {
public AsyncWebProcessManager getAsyncWebProcessManager() {
return MidPointApplication.get().getAsyncWebProcessManager();
}

@Override
public Locale getLocale() {
return getSession().getLocale();
Expand Down Expand Up @@ -2726,7 +2726,7 @@ private Class<?> getWrapperPanel(QName typeName) {
}


public <IW extends ItemWrapper> Panel initItemPanel(String panelId, QName typeName, IModel<IW> wrapperModel, ItemHeaderPanel.ItemPanelSettings itemPanelSettings) throws SchemaException{
public <IW extends ItemWrapper> Panel initItemPanel(String panelId, QName typeName, IModel<IW> wrapperModel, ItemPanelSettings itemPanelSettings) throws SchemaException{
Class<?> panelClass = getWrapperPanel(typeName);
if (panelClass == null) {
ErrorPanel errorPanel = new ErrorPanel(panelId, () -> "Cannot create panel for " + typeName);
Expand All @@ -2736,16 +2736,16 @@ public <IW extends ItemWrapper> Panel initItemPanel(String panelId, QName typeNa

Constructor<?> constructor;
try {
constructor = panelClass.getConstructor(String.class, IModel.class, ItemHeaderPanel.ItemPanelSettings.class);
constructor = panelClass.getConstructor(String.class, IModel.class, ItemPanelSettings.class);
Panel panel = (Panel) constructor.newInstance(panelId, wrapperModel, itemPanelSettings);
return panel;
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new SystemException("Cannot instantiate " + panelClass, e);
}
}

public <CVW extends PrismContainerValueWrapper<C>, C extends Containerable> Panel initContainerValuePanel(String id, IModel<CVW> model,
ItemHeaderPanel.ItemPanelSettings settings) {
public <C extends Containerable> Panel initContainerValuePanel(String id, IModel<PrismContainerValueWrapper<C>> model,
ItemPanelSettings settings) {
//TODO find from registry first
return new PrismContainerValuePanel<>(id, model, settings);
}
Expand Down
Expand Up @@ -12,8 +12,10 @@

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismValueWrapper;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismValue;
Expand All @@ -30,7 +32,7 @@
* @author katka
*
*/
public interface ItemWrapper<I extends Item<? extends PrismValue, ? extends ItemDefinition<I>>, VW extends PrismValueWrapper<?, ? extends PrismValue>> extends ItemDefinition<I>, Revivable, DebugDumpable, Serializable {
public interface ItemWrapper<I extends Item, VW extends PrismValueWrapper> extends ItemDefinition<I>, Revivable, DebugDumpable, Serializable {


String debugDump(int indent);
Expand Down Expand Up @@ -81,4 +83,8 @@ public interface ItemWrapper<I extends Item<? extends PrismValue, ? extends Item
ItemStatus getStatus();

boolean isEmpty();

void remove(VW valueWrapper, ModelServiceLocator locator) throws SchemaException;

<PV extends PrismValue> void add(PV newValueWrapper, ModelServiceLocator locator) throws SchemaException;
}
Expand Up @@ -88,6 +88,30 @@ public static <IW extends ItemWrapper, PV extends PrismValue, VW extends PrismVa
return newValueWrapper;
}

public static <IW extends ItemWrapper, PV extends PrismValue, VW extends PrismValueWrapper> VW createNewValueWrapper(IW itemWrapper, PV newValue, ModelServiceLocator modelServiceLocator) throws SchemaException {
LOGGER.debug("Adding value to {}", itemWrapper);




// if (!(itemWrapper instanceof PrismContainerWrapper)) {
// itemWrapper.getItem().add(newValue);
// }

Task task = modelServiceLocator.createSimpleTask(OPERATION_CREATE_NEW_VALUE);
OperationResult result = new OperationResult(OPERATION_CREATE_NEW_VALUE);

WrapperContext context = new WrapperContext(task, result);
context.setObjectStatus(itemWrapper.findObjectStatus());
context.setShowEmpty(true);
context.setCreateIfEmpty(true);

VW newValueWrapper = modelServiceLocator.createValueWrapper(itemWrapper, newValue, ValueStatus.ADDED, context);
result.recordSuccess();

return newValueWrapper;
}

public static <IW extends ItemWrapper> IW findItemWrapper(ItemWrapper<?,?> child, ItemPath absoluthPathToFind, Class<IW> wrapperClass) {
PrismObjectWrapper<?> taskWrapper = child.findObjectWrapper();
try {
Expand Down
Expand Up @@ -10,6 +10,9 @@

import com.evolveum.midpoint.gui.impl.prism.panel.ItemHeaderPanel;

import com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings;
import com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -65,7 +68,7 @@ protected void addBasicContainerValuePanel(String idPanel){
}

protected Panel getBasicContainerValuePanel(String idPanel){
ItemHeaderPanel.ItemPanelSettingsBuilder builder = new ItemHeaderPanel.ItemPanelSettingsBuilder()
ItemPanelSettingsBuilder builder = new ItemPanelSettingsBuilder()
.visibilityHandler(wrapper -> getBasicTabVisibity(wrapper))
.showOnTopLevel(true)
.editabilityHandler(wrapper -> getBasicTabEditability(wrapper));
Expand All @@ -74,7 +77,7 @@ protected Panel getBasicContainerValuePanel(String idPanel){
builder.mandatoryHandler(getMandatoryHandler());
}

ItemHeaderPanel.ItemPanelSettings settings = builder.build();
ItemPanelSettings settings = builder.build();
Panel containerValue = getPageBase().initContainerValuePanel(idPanel, getModel(), settings);
return containerValue;
}
Expand Down
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2020 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.factory.GuiComponentFactory;

import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry;

import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyWrapper;
import com.evolveum.midpoint.web.component.prism.InputPanel;

import com.evolveum.midpoint.web.component.util.EnableBehaviour;

import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LambdaModel;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* abstract factory for all InputPanel panels
* @param <T>
*/
public abstract class AbstractInputGuiComponentFactory<T> implements GuiComponentFactory<PrismPropertyPanelContext<T>> {

@Autowired private GuiComponentRegistry componentRegistry;

public GuiComponentRegistry getRegistry() {
return componentRegistry;
}

@Override
public Panel createPanel(PrismPropertyPanelContext<T> panelCtx) {
InputPanel panel = getPanel(panelCtx);

final List<FormComponent> formComponents = panel.getFormComponents();
for (FormComponent<T> formComponent : formComponents) {
PrismPropertyWrapper<T> propertyWrapper = panelCtx.unwrapWrapperModel();
IModel<String> label = LambdaModel.of(propertyWrapper::getDisplayName);
formComponent.setLabel(label);
formComponent.setRequired(panelCtx.isMandatory());

if (formComponent instanceof TextField) {
formComponent.add(new AttributeModifier("size", "42"));
}
formComponent.add(panelCtx.getAjaxEventBehavior());
formComponent.add(panelCtx.getVisibleEnableBehavior());
// formComponent.add(new EnableBehaviour(() -> getEditabilityHandler() == null ||
// getEditabilityHandler().isEditable(getModelObject())));
}

panel.getValidatableComponent().add(panelCtx.getExpressionValidator());

panelCtx.getFeedback().setFilter(new ComponentFeedbackMessageFilter(panel.getValidatableComponent()));


return panel;
}

@Override
public Integer getOrder() {
return Integer.MAX_VALUE;
}

protected abstract InputPanel getPanel(PrismPropertyPanelContext<T> panelCtx);
}
Expand Up @@ -9,13 +9,13 @@
import javax.annotation.PostConstruct;
import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.web.component.prism.InputPanel;

import org.apache.wicket.extensions.yui.calendar.DateTimeField;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.gui.api.factory.AbstractGuiComponentFactory;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
Expand All @@ -30,7 +30,7 @@
*
*/
@Component
public class DatePanelFactory extends AbstractGuiComponentFactory<XMLGregorianCalendar> {
public class DatePanelFactory extends AbstractInputGuiComponentFactory<XMLGregorianCalendar> {

private static final long serialVersionUID = 1L;

Expand All @@ -46,7 +46,7 @@ public <IW extends ItemWrapper> boolean match(IW wrapper) {
}

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

Form form = Form.findForm(panelCtx.getForm());
Expand Down
Expand Up @@ -11,15 +11,12 @@
import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import com.evolveum.midpoint.web.component.prism.InputPanel;

import org.apache.wicket.model.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.gui.api.factory.GuiComponentFactory;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
Expand All @@ -32,37 +29,32 @@
*
*/
@Component
public class DropDownChoicePanelFactory implements GuiComponentFactory<PrismPropertyPanelContext<QName>> {

private static final long serialVersionUID = 1L;
@Autowired GuiComponentRegistry registry;
public class DropDownChoicePanelFactory extends AbstractInputGuiComponentFactory<QName> {

@PostConstruct
public void register() {
registry.addToRegistry(this);
getRegistry().addToRegistry(this);
}

@Override
public <IW extends ItemWrapper> boolean match(IW wrapper) {
return AssignmentType.F_FOCUS_TYPE.equals(wrapper.getItemName()) || DOMUtil.XSD_QNAME.equals(wrapper.getTypeName());
}

@Override
public Panel createPanel(PrismPropertyPanelContext<QName> panelCtx) {
List<QName> typesList = null;
@Override
protected InputPanel getPanel(PrismPropertyPanelContext<QName> panelCtx) {
List<QName> typesList = WebComponentUtil.createObjectTypeList();
if (AssignmentType.F_FOCUS_TYPE.equals(panelCtx.getDefinitionName())){
typesList = WebComponentUtil.createFocusTypeList();
} else {
typesList = WebComponentUtil.createObjectTypeList();
}

DropDownChoicePanel<QName> typePanel = new DropDownChoicePanel<QName>(panelCtx.getComponentId(), (IModel<QName>) panelCtx.getRealValueModel(),
DropDownChoicePanel<QName> typePanel = new DropDownChoicePanel<QName>(panelCtx.getComponentId(), panelCtx.getRealValueModel(),
Model.ofList(typesList), new QNameObjectTypeChoiceRenderer(), true);
typePanel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
typePanel.setOutputMarkupId(true);
return typePanel;
}


@Override
public Integer getOrder() {
return 10000;
Expand Down

0 comments on commit a42a7ab

Please sign in to comment.