Skip to content

Commit

Permalink
small improvements to item path panel, adding itempathpanel to genera…
Browse files Browse the repository at this point in the history
…ted forms, adding support for editing filters in forms..
  • Loading branch information
katkav committed Aug 6, 2018
1 parent a5710eb commit d6e4380
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 33 deletions.
Expand Up @@ -5,12 +5,19 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;

public class ItemPathDto implements Serializable{
private static final long serialVersionUID = 1L;

private QName objectType;
private QName objectType = FocusType.COMPLEX_TYPE;

private ItemPathDto parentPath;

Expand All @@ -22,10 +29,16 @@ public ItemPathDto() {
// TODO Auto-generated constructor stub
}

public ItemPathDto(ItemPathType itemPathType) {
if (itemPathType == null) {
return;
}
this.path = itemPathType.getItemPath();
}

public ItemPathDto(ItemPathDto parentPath) {
this.parentPath = parentPath;
this.path = parentPath.toItemPath();
// this.parent = parentPath.toItemPath();
}


Expand Down Expand Up @@ -73,6 +86,10 @@ public ItemPath toItemPath() {
return path;

}

public boolean isPathDefined() {
return (path != null && itemDef == null && parentPath == null);
}



Expand Down
Expand Up @@ -17,9 +17,18 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div wicket:id="namespace"/>
<div wicket:id="definition"/>
<a class="btn" wicket:id="plus"><label>+</label></a>
<a class="btn" wicket:id="minus"><label>-</label></a>
<div wicket:id="itemPath">
<div wicket:id="namespace"/>
<div wicket:id="definition"/>
<button wicket:id="plus" class="btn btn-box-tool" trigger="hover"><i class="fa fa-plus-circle"></i></button>
<button wicket:id="minus" class="btn btn-box-tool" trigger="hover"><i class="fa fa-minus-circle"></i></button>
</div>

<div wicket:id="itemPathContainer">
<div>
<span wicket:id="itemPathLabel"></span>
<a wicket:id="change" class="btn btn-primary btn-xs"></a>
</div>
</div>
</wicket:panel>
</html>
Expand Up @@ -9,6 +9,7 @@

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
Expand All @@ -21,38 +22,75 @@
import com.evolveum.midpoint.prism.Definition;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.input.QNameChoiceRenderer;
import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;

public class ItemPathPanel extends BasePanel<ItemPathDto> {

private static final long serialVersionUID = 1L;

private static final String ID_ITEM_PATH = "itemPath";
private static final String ID_NAMESPACE = "namespace";
private static final String ID_DEFINITION = "definition";

private static final String ID_ITEM_PATH_CONTAINER = "itemPathContainer";
private static final String ID_ITEM_PATH_LABEL = "itemPathLabel";
private static final String ID_CHANGE = "change";

private static final String ID_PLUS = "plus";
private static final String ID_MINUS = "minus";

public ItemPathPanel(String id, IModel<ItemPathDto> model, PageBase parent) {
public ItemPathPanel(String id, IModel<ItemPathDto> model) {
super(id, model);

setParent(parent);


}

@Override
protected void onInitialize() {
super.onInitialize();
initLayout();

}

public ItemPathPanel(String id, ItemPathDto model, PageBase parent) {
this(id, Model.of(model), parent);
public ItemPathPanel(String id, ItemPathDto model) {
this(id, Model.of(model));

}

public ItemPathPanel(String id, ItemPathType itemPath) {
this(id, Model.of(new ItemPathDto(itemPath)));

}

private void initLayout() {
initItemPathPanel();

initItemPathLabel();

setOutputMarkupId(true);
}

private void initItemPathPanel() {
WebMarkupContainer itemPathPanel = new WebMarkupContainer(ID_ITEM_PATH);
itemPathPanel.setOutputMarkupId(true);
add(itemPathPanel);
itemPathPanel.add(new VisibleEnableBehaviour() {

private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
return !getModelObject().isPathDefined();
}

});

ItemPathSegmentPanel itemDefPanel = new ItemPathSegmentPanel(ID_DEFINITION,
new AbstractReadOnlyModel<ItemPathDto>() {

Expand All @@ -70,7 +108,7 @@ protected Map<QName, Collection<ItemDefinition<?>>> getSchemaDefinitionMap() {
}
};
itemDefPanel.setOutputMarkupId(true);
add(itemDefPanel);
itemPathPanel.add(itemDefPanel);

AjaxButton plusButton = new AjaxButton(ID_PLUS) {
private static final long serialVersionUID = 1L;
Expand All @@ -94,20 +132,14 @@ public boolean isVisible() {
}
});
plusButton.setOutputMarkupId(true);
add(plusButton);
itemPathPanel.add(plusButton);

AjaxButton minusButton = new AjaxButton(ID_MINUS) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
ItemPathDto path = ItemPathPanel.this.getModelObject();
// ItemPathDto parent = null;
// if (path.getItemDef() == null){
// parent = path.getParentPath();
// } else {
// parent = path;
// }
refreshItemPathPanel(path, false, target);

}
Expand All @@ -121,7 +153,7 @@ public boolean isVisible() {
}
});
minusButton.setOutputMarkupId(true);
add(minusButton);
itemPathPanel.add(minusButton);

DropDownChoicePanel<QName> namespacePanel = new DropDownChoicePanel<>(ID_NAMESPACE,
new PropertyModel<>(getModel(), "objectType"),
Expand All @@ -147,11 +179,48 @@ public boolean isVisible() {
}
});
namespacePanel.setOutputMarkupId(true);
add(namespacePanel);
itemPathPanel.add(namespacePanel);
}

private void initItemPathLabel() {
WebMarkupContainer itemPathLabel = new WebMarkupContainer(ID_ITEM_PATH_CONTAINER);
itemPathLabel.setOutputMarkupId(true);
add(itemPathLabel);
itemPathLabel.add(new VisibleEnableBehaviour() {

private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
return getModelObject().isPathDefined();
}

});

TextPanel<ItemPath> textPanel = new TextPanel<>(ID_ITEM_PATH_LABEL, new PropertyModel<>(getModel(), "path"));
textPanel.setEnabled(false);
textPanel.setOutputMarkupId(true);
itemPathLabel.add(textPanel);

AjaxButton change = new AjaxButton(ID_CHANGE, createStringResource("ItemPathPanel.button.reset")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
ItemPathDto newPath = new ItemPathDto();
ItemPathPanel.this.getModel().setObject(newPath);
target.add(ItemPathPanel.this);
onUpdate(newPath);
}
};

change.setOutputMarkupId(true);
itemPathLabel.add(change);
}

private void refreshItemPathPanel(ItemPathDto itemPathDto, boolean isAdd, AjaxRequestTarget target) {
ItemPathSegmentPanel pathSegmentPanel = (ItemPathSegmentPanel) get(ID_DEFINITION);
ItemPathSegmentPanel pathSegmentPanel = (ItemPathSegmentPanel) get(createComponentPath(ID_ITEM_PATH, ID_DEFINITION));
if (isAdd && !pathSegmentPanel.validate()) {
return;
}
Expand All @@ -172,9 +241,11 @@ private void refreshItemPathPanel(ItemPathDto itemPathDto, boolean isAdd, AjaxRe
itemPathDto = resultingItem;
}
// pathSegmentPanel.refreshModel(itemPathDto);

this.getModel().setObject(itemPathDto);

target.add(this);
onUpdate(itemPathDto);
// target.add(pathSegmentPanel);

}
Expand All @@ -183,6 +254,8 @@ private void refreshItemPath(ItemPathDto itemPathDto, AjaxRequestTarget target)

this.getModel().setObject(itemPathDto);
target.add(this);

onUpdate(itemPathDto);
}

private Map<QName, Collection<ItemDefinition<?>>> initNamspaceDefinitionMap() {
Expand All @@ -206,5 +279,10 @@ private Map<QName, Collection<ItemDefinition<?>>> initNamspaceDefinitionMap() {
}
return schemaDefinitionsMap;
}


protected void onUpdate(ItemPathDto itemPathDto) {

}

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

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -131,5 +132,11 @@ public boolean validate() {

// return autocompletePanel.getBaseFormComponent().getModelObject() != null;
}

public Component getBaseFormComponent() {
return get(ID_DEFINITION);
}



}

0 comments on commit d6e4380

Please sign in to comment.