Skip to content

Commit

Permalink
more improvements + cleanups for wrappers. (visibility, assignment pa…
Browse files Browse the repository at this point in the history
…nel, ...)
  • Loading branch information
katkav committed May 7, 2019
1 parent 84c4d67 commit 81fc2f5
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 356 deletions.
Expand Up @@ -35,5 +35,7 @@ public interface ItemWrapperFactory<IW extends ItemWrapper, VW extends PrismValu
IW createWrapper(PrismContainerValueWrapper<?> parent, ItemDefinition<?> def, WrapperContext context) throws SchemaException;
IW createWrapper(Item childContainer, ItemStatus status, WrapperContext context) throws SchemaException;
VW createValueWrapper(IW parent, PV value, ValueStatus status, WrapperContext context) throws SchemaException;

boolean skipCreateWrapper(ItemDefinition<?> def);

}
Expand Up @@ -37,6 +37,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

/**
* @author katka
Expand Down Expand Up @@ -82,15 +83,21 @@ private IW createWrapper(PrismContainerValueWrapper<?> parent, I childItem, Item
itemWrapper.getValues().addAll((Collection) valueWrappers);
itemWrapper.setShowEmpty(context.isShowEmpty(), false);
itemWrapper.setReadOnly(context.isReadOnly());

setupWrapper(itemWrapper);

return itemWrapper;
}

protected abstract void setupWrapper(IW wrapper);

protected <ID extends ItemDefinition<I>> List<VW> createValuesWrapper(IW itemWrapper, I item, WrapperContext context) throws SchemaException {
List<VW> pvWrappers = new ArrayList<>();

ID definition = (ID) item.getDefinition();

if (item.isEmpty()) {
//TODO : prismContainer.isEmpty() interates and check is all prismcontainervalues are empty.. isn't it confusing?
if (item.isEmpty() && item.getValues().isEmpty()) {
if (shoudCreateEmptyValue(item, context)) {
PV prismValue = createNewValue(item);
VW valueWrapper = createValueWrapper(itemWrapper, prismValue, ValueStatus.ADDED, context);
Expand Down Expand Up @@ -149,6 +156,20 @@ public PrismContext getPrismContext() {
return prismContext;
}

@Override
public boolean skipCreateWrapper(ItemDefinition<?> def) {
if (def.isOperational()) {
LOGGER.trace("Skipping creating wrapper for {}, because it is operational.", def.getName());
return true;
}

if (SearchFilterType.COMPLEX_TYPE.equals(def.getTypeName())) {
LOGGER.trace("Skipping creating wrapper for search filter.", def.getName());
return true;
}

return false;
}


// @Override
Expand Down
Expand Up @@ -66,4 +66,9 @@ protected void addItemWrapper(ItemDefinition<?> def, PrismContainerValueWrapper<
wrappers.add(wrapper);
}

@Override
public boolean skipCreateWrapper(ItemDefinition<?> def) {
return false;
}

}
Expand Up @@ -147,5 +147,10 @@ public PrismContainerWrapper<C> createWrapper(Item childContainer, ItemStatus st
// TODO Auto-generated method stub
return null;
}

@Override
public boolean skipCreateWrapper(ItemDefinition<?> def) {
return false;
}

}
Expand Up @@ -107,9 +107,7 @@ protected List<? extends ItemDefinition> getItemDefinitions(PrismContainerWrappe
protected void addItemWrapper(ItemDefinition<?> def, PrismContainerValueWrapper<?> containerValueWrapper,
WrapperContext context, List<ItemWrapper<?,?,?,?>> wrappers) throws SchemaException {

if (skipCreateItem(def)) {
return;
}


ItemWrapperFactory<?, ?, ?> factory = registry.findWrapperFactory(def);
if (factory == null) {
Expand All @@ -118,7 +116,9 @@ protected void addItemWrapper(ItemDefinition<?> def, PrismContainerValueWrapper<
}

LOGGER.trace("Found factory {} for {}", factory, def);

if (factory.skipCreateWrapper(def)) {
return;
}

ItemWrapper<?,?,?,?> wrapper = factory.createWrapper(containerValueWrapper, def, context);

Expand Down Expand Up @@ -149,7 +149,7 @@ public PrismContainerValueWrapper<C> createContainerValueWrapper(PrismContainerW
}

protected boolean shouldBeExpanded(PrismContainerWrapper<C> parent, PrismContainerValue<C> value, WrapperContext context) {
if (value.isEmpty()) {
if (value.isEmpty()) {
return context.isShowEmpty() || containsEmphasizedItems(parent.getDefinitions());
}

Expand All @@ -166,17 +166,16 @@ private boolean containsEmphasizedItems(List<? extends ItemDefinition> definitio
return false;
}

protected boolean skipCreateItem(ItemDefinition<?> def) {
if (def.isOperational()) {
LOGGER.trace("Skipping creating wrapper for {}, because it is operational.", def.getName());
return true;
}

if (SearchFilterType.COMPLEX_TYPE.equals(def.getTypeName())) {
LOGGER.trace("Skipping creating wrapper for search filter.", def.getName());
return true;
@Override
protected void setupWrapper(PrismContainerWrapper<C> wrapper) {
boolean expanded = false;
for (PrismContainerValueWrapper<C> valueWrapper : wrapper.getValues()) {
if (valueWrapper.isExpanded()) {
expanded = true;
}
}

return false;
wrapper.setExpanded(expanded);
}

}
Expand Up @@ -79,4 +79,9 @@ public PrismPropertyValueWrapper<T> createValueWrapper(PrismPropertyWrapper<T> p
return valueWrapper;
}

@Override
protected void setupWrapper(PrismPropertyWrapper<T> wrapper) {

}

}
Expand Up @@ -93,4 +93,10 @@ protected boolean canCreateNewWrapper(ItemDefinition<?> def) {
return true;
}

@Override
protected void setupWrapper(PrismReferenceWrapper<R> wrapper) {
// TODO Auto-generated method stub

}

}
Expand Up @@ -20,13 +20,16 @@
import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.prism.ItemWrapper;
import com.evolveum.midpoint.gui.api.prism.ItemWrapperOld;
import com.evolveum.midpoint.gui.api.prism.PrismObjectWrapper;
import com.evolveum.midpoint.gui.impl.prism.ObjectWrapperOld;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.form.Form;
Expand Down Expand Up @@ -62,19 +65,17 @@ protected void onInitialize() {
}

protected void initLayout() {
Form form = new Form<>("form");
PrismPanel<SystemConfigurationType> panel = new PrismPanel<SystemConfigurationType>(ID_SYSTEM_CONFIG,
new ContainerWrapperListFromObjectWrapperModel(getModel(), getVisibleContainers()), null, form, itemWrapper -> getBasicTabVisibity(itemWrapper), getPageBase());
add(panel);
try {
Panel panel = getPageBase().initItemPanel(ID_SYSTEM_CONFIG, SystemConfigurationType.COMPLEX_TYPE, getModel(), itemWrapper -> getBasicTabVisibity(itemWrapper));
add(panel);
} catch (SchemaException e) {
LOGGER.error("Cannot create basic panel for system configuration.");
getSession().error("Cannot create basic panel for system configuration.");
}

}

private List<ItemPath> getVisibleContainers() {
List<ItemPath> paths = new ArrayList<>();
paths.addAll(Arrays.asList(ItemPath.EMPTY_PATH));
return paths;
}

private ItemVisibility getBasicTabVisibity(ItemWrapperOld itemWrapper) {
private ItemVisibility getBasicTabVisibity(ItemWrapper<?, ?, ?, ?> itemWrapper) {
if(itemWrapper.getPath().isSubPathOrEquivalent(ItemPath.create(ItemPath.EMPTY_PATH, SystemConfigurationType.F_DESCRIPTION)) || itemWrapper.getPath().isSubPathOrEquivalent(ItemPath.create(
ItemPath.EMPTY_PATH, SystemConfigurationType.F_GLOBAL_SECURITY_POLICY_REF))) {
return ItemVisibility.AUTO;
Expand Down
Expand Up @@ -47,4 +47,8 @@ public PrismContainerDefinition<?> getDef() {
return def;
}

public boolean isSelected() {
return selected;
}

}
Expand Up @@ -100,7 +100,7 @@ protected ListView<VW> createValuesPanel() {
protected void populateItem(ListItem<VW> item) {
GuiComponentFactory componentFactory = getPageBase().getRegistry().findValuePanelFactory(ItemPanel.this.getModelObject());

createValuePanel(item, componentFactory, null);
createValuePanel(item, componentFactory, visibilityHandler);
createButtons(item);
}

Expand Down
Expand Up @@ -96,12 +96,10 @@ public ItemWrapperImpl(@Nullable PrismContainerValueWrapper<?> parent, I item, I
this.newItem = item;
this.oldItem = (I) item.clone();
this.status = status;
// this.readonly = readonly;

}

protected <D extends ItemDelta<PV, ID>, O extends ObjectType> D getItemDelta(Class<O> objectClass, Class<D> deltaClass) throws SchemaException {
// D delta = (D) getPrismContext().deltaFor(objectClass).asItemDelta();
D delta = (D) createEmptyDelta(null);
for (VW value : values) {
value.addToDelta(delta);
Expand Down Expand Up @@ -132,7 +130,6 @@ public <D extends ItemDelta<PV, ID>> D getDelta(boolean absolute) throws SchemaE
return null;
}

// parent.applyDelta(delta);
LOGGER.trace("Returning delta {}", delta);
return delta;
}
Expand Down Expand Up @@ -240,26 +237,7 @@ public ExpressionType getFormComponentValidator() {
ID getItemDefinition() {
return newItem.getDefinition();
}
//OLD

/* (non-Javadoc)
* @see com.evolveum.midpoint.prism.Revivable#revive(com.evolveum.midpoint.prism.PrismContext)
*/
// @Override
// public void revive(PrismContext prismContext) throws SchemaException {
// if (item != null) {
// item.revive(prismContext);
// }
// if (item.getDefinition() != null) {
// item.getDefinition().revive(prismContext);
// }
// this.prismContext = prismContext;
//
// }

/* (non-Javadoc)
* @see com.evolveum.midpoint.util.DebugDumpable#debugDump(int)
*/

@Override
public String debugDump(int indent) {
StringBuilder sb = DebugUtil.createIndentedStringBuilder(indent);
Expand Down Expand Up @@ -336,63 +314,6 @@ public List<VW> getValues() {
return values;
}


// @Override
// public void removeValue(ValueWrapperOld<PV> valueWrapper) throws SchemaException {
// List<ValueWrapperOld<PV>> values = getValues();
//
// switch (valueWrapper.getStatus()) {
// case ADDED:
// values.remove(valueWrapper);
// break;
// case DELETED:
// throw new SchemaException();
// case NOT_CHANGED:
// valueWrapper.setStatus(ValueStatus.DELETED);
// break;
// }
//
// int count = countUsableValues();
//
// if (count == 0 && !hasEmptyPlaceholder()) {
// addValue(true);
//
// }
// }
//
// private int countUsableValues() {
// int count = 0;
// for (ValueWrapperOld<PV> value : getValues()) {
// value.normalize(prismContext);
//
// if (ValueStatus.DELETED.equals(value.getStatus())) {
// continue;
// }
//
// if (ValueStatus.ADDED.equals(value.getStatus()) && !value.hasValueChanged()) {
// continue;
// }
//
// count++;
// }
// return count;
// }
//
// private boolean hasEmptyPlaceholder() {
// for (ValueWrapperOld<PV> value : getValues()) {
// value.normalize(prismContext);
// if (ValueStatus.ADDED.equals(value.getStatus()) && !value.hasValueChanged()) {
// return true;
// }
// }
//
// return false;
// }


/* (non-Javadoc)
* @see com.evolveum.midpoint.gui.api.prism.ItemWrapper#checkRequired(com.evolveum.midpoint.gui.api.page.PageBase)
*/
@Override
public boolean checkRequired(PageBase pageBase) {
return newItem.getDefinition().isMandatory();
Expand All @@ -408,23 +329,6 @@ public void setShowEmpty(boolean isShowEmpty, boolean recursive) {
this.showEmpty = isShowEmpty;
}

// protected boolean isVisible(ItemVisibilityHandler visibilityHandler) {
// if (visibilityHandler != null) {
// ItemVisibility visible = visibilityHandler.isVisible(this);
// if (visible != null) {
// switch (visible) {
// case VISIBLE:
// return true;
// case HIDDEN:
// return false;
// default:
// // automatic, go on ...
// }
// }
// }
// return isVisible();
// }

@Override
public boolean isVisible(ItemVisibilityHandler visibilityHandler) {

Expand Down Expand Up @@ -483,18 +387,6 @@ protected boolean isEmpty() {

return false;
}

// private boolean showEmptyCanReadAndModify(ID def) {
// return def.canRead() && isShowEmpty();// && def.canModify() && isShowEmpty();
// }
//
// private boolean showEmptyAndCanAdd(ID def) {
// return def.canAdd() && isShowEmpty();
// }
//
// private boolean emphasizedAndCanAdd(ID def) {
// return def.canAdd() && def.isEmphasized();
// }

ItemStatus getItemStatus() {
return status;
Expand Down
Expand Up @@ -109,8 +109,13 @@ protected void populateItem(ListItem<ContainersPopupDto> item) {
public void onClick(AjaxRequestTarget target) {
ListView<ContainersPopupDto> listView = (ListView<ContainersPopupDto>) ListContainersPopup.this.get(ID_CONTAINERS);
List<PrismContainerDefinition<?>> selected = new ArrayList<>();
listView.getModelObject().forEach(child -> selected.add(child.getDef()));
processSelectedChildren(target, selected);
listView.getModelObject().forEach(child -> {
if (child.isSelected()) {
selected.add(child.getDef());
}
processSelectedChildren(target, selected);
});

}
};
add(select);
Expand Down

0 comments on commit 81fc2f5

Please sign in to comment.