Skip to content

Commit

Permalink
boolean wrapper + delta
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed Aug 24, 2022
1 parent 829458d commit 7fc3acd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@
package com.evolveum.midpoint.gui.impl.factory.panel;

import javax.annotation.PostConstruct;

import com.evolveum.midpoint.gui.api.component.form.ToggleCheckBoxPanel;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.web.component.input.TriStateComboPanel;
import com.evolveum.midpoint.web.component.prism.InputPanel;

/**
* @author katka
*/
@Component
public class ThreeStateComboPanelFactory extends AbstractInputGuiComponentFactory<Boolean> {
public class ToggleCheckBoxPanelFactory extends AbstractInputGuiComponentFactory<Boolean> {

@PostConstruct
public void register() {
Expand All @@ -33,6 +31,6 @@ public void register() {

@Override
protected InputPanel getPanel(PrismPropertyPanelContext<Boolean> panelCtx) {
return new TriStateComboPanel(panelCtx.getComponentId(), panelCtx.getRealValueModel());
return new ToggleCheckBoxPanel(panelCtx.getComponentId(), panelCtx.getRealValueModel());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2010-2022 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.wrapper;

import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper;
import com.evolveum.midpoint.gui.impl.prism.wrapper.BooleanWrapperImpl;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.QNameUtil;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class BooleanWrapperFactory extends PrismPropertyWrapperFactoryImpl<Boolean>{

@Override
public boolean match(ItemDefinition<?> def) {
return QNameUtil.match(DOMUtil.XSD_BOOLEAN, def.getTypeName()) ;
}

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

@Override
public int getOrder() {
return 1110;
}

@Override
protected PrismPropertyWrapper<Boolean> createWrapperInternal(PrismContainerValueWrapper<?> parent, PrismProperty<Boolean> item,
ItemStatus status, WrapperContext ctx) {
return new BooleanWrapperImpl(parent, item, status);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2010-2022 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.prism.wrapper;

import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.prism.ValueStatus;

import java.util.Collection;

public class BooleanWrapperImpl extends PrismPropertyWrapperImpl<Boolean> {
private static final long serialVersionUID = 1L;

public BooleanWrapperImpl(PrismContainerValueWrapper<?> parent, PrismProperty<Boolean> item, ItemStatus status) {
super(parent, item, status);
}

@Override
public <D extends ItemDelta<?, ?>> Collection<D> getDelta() throws SchemaException {
PrismPropertyValueWrapper<Boolean> valueWrapper = getValue();
if (noChangesToApply(valueWrapper)){
valueWrapper.setStatus(ValueStatus.DELETED);
}
return super.getDelta();
}

private boolean noChangesToApply(PrismPropertyValueWrapper<Boolean> valueWrapper) {
return valueWrapper != null && valueWrapper.getOldValue() != null && valueWrapper.getOldValue().getValue() == null
&& valueWrapper.getNewValue() != null && valueWrapper.getRealValue() != null && valueWrapper.getRealValue().equals(defaultValue());
}


}

0 comments on commit 7fc3acd

Please sign in to comment.