Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
policy rules: constraints editable panel
- Loading branch information
1 parent
85746ea
commit 6ea43e6
Showing
4 changed files
with
240 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
46 changes: 46 additions & 0 deletions
46
...n/java/com/evolveum/midpoint/web/component/form/multivalue/MultiValueExpandablePanel.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,46 @@ | ||
<!-- | ||
~ Copyright (c) 2010-2017 Evolveum | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
|
||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | ||
"http://www.w3.org/TR/html4/loose.dtd"> | ||
<html xmlns:wicket="http://wicket.apache.org"> | ||
<wicket:panel> | ||
|
||
<wicket:container wicket:id="repeater"> | ||
<div class="col-md-12"> | ||
<div class="box box-default collapsed-box"> | ||
<div class="box-header with-border"> | ||
<div class="box-title" wicket:id="boxTitle"/> | ||
|
||
<div class="box-tools pull-right"> | ||
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-chevron-down"></i> | ||
</button> | ||
<button wicket:id="removeButton" type="button" class="btn btn-box-tool" ><i class="fa fa-times-circle fa-lg text-danger"></i> | ||
</button> | ||
</div> | ||
</div> | ||
<div class="box-body" > | ||
<div wicket:id="attributeRepeater" class="row"> | ||
<div wicket:id="attributeLabel" class="col-md-4"/> | ||
<div wicket:id="attributeValue" class="col-md-8"/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</wicket:container> | ||
</wicket:panel> | ||
</html> |
154 changes: 154 additions & 0 deletions
154
...n/java/com/evolveum/midpoint/web/component/form/multivalue/MultiValueExpandablePanel.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,154 @@ | ||
/* | ||
* Copyright (c) 2010-2017 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.evolveum.midpoint.web.component.form.multivalue; | ||
|
||
import com.evolveum.midpoint.gui.api.component.BasePanel; | ||
import com.evolveum.midpoint.gui.api.util.WebComponentUtil; | ||
import com.evolveum.midpoint.prism.*; | ||
import com.evolveum.midpoint.prism.query.ObjectQuery; | ||
import com.evolveum.midpoint.web.component.AjaxButton; | ||
import com.evolveum.midpoint.web.component.input.TextPanel; | ||
import com.evolveum.midpoint.web.page.admin.configuration.component.ChooseTypePanel; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
import org.apache.wicket.Component; | ||
import org.apache.wicket.ajax.AjaxRequestTarget; | ||
import org.apache.wicket.markup.html.WebMarkupContainer; | ||
import org.apache.wicket.markup.html.basic.Label; | ||
import org.apache.wicket.markup.html.list.ListItem; | ||
import org.apache.wicket.markup.html.list.ListView; | ||
import org.apache.wicket.markup.html.panel.Panel; | ||
import org.apache.wicket.markup.repeater.RepeatingView; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.model.Model; | ||
import org.apache.wicket.model.PropertyModel; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by honchar. | ||
*/ | ||
public class MultiValueExpandablePanel <T extends Containerable> extends BasePanel<List<T>> { | ||
private static final String ID_REPEATER = "repeater"; | ||
private static final String ID_BOX_TITLE = "boxTitle"; | ||
private static final String ID_REMOVE_BUTTON = "removeButton"; | ||
private static final String ID_BOX_BODY = "boxBody"; | ||
private static final String ID_ATTRIBUTE_REPEATER = "attributeRepeater"; | ||
private static final String ID_ATTRIBUTE_LABEL = "attributeLabel"; | ||
private static final String ID_ATTRIBUTE_VALUE = "attributeValue"; | ||
|
||
public MultiValueExpandablePanel(String id, IModel<List<T>> model){ | ||
super(id, model); | ||
initLayout(); | ||
} | ||
|
||
private void initLayout(){ | ||
ListView repeater = new ListView<T>(ID_REPEATER, getModel()) { | ||
|
||
@Override | ||
protected void populateItem(final ListItem<T> listItem) { | ||
Label boxTitle = new Label(ID_BOX_TITLE, listItem.getModel().getObject().asPrismContainerValue().getPath().last()); | ||
listItem.add(boxTitle); | ||
|
||
AjaxButton removeRowButton = new AjaxButton(ID_REMOVE_BUTTON) { | ||
@Override | ||
public void onClick(AjaxRequestTarget ajaxRequestTarget) { | ||
} | ||
}; | ||
listItem.add(removeRowButton); | ||
|
||
T itemModel = listItem.getModelObject(); | ||
PrismContainerValue containerValue = itemModel.asPrismContainerValue(); | ||
|
||
List<Item> items = containerValue.getItems(); | ||
Map<ItemDefinition, Item> attributesDefinitionValueMap = new HashMap<>(); | ||
for (ItemDefinition itemDefinition : containerValue.getComplexTypeDefinition().getDefinitions()){ | ||
attributesDefinitionValueMap.put(itemDefinition, containerValue.findItem(itemDefinition.getName())); | ||
} | ||
|
||
RepeatingView attributesPanel = new RepeatingView(ID_ATTRIBUTE_REPEATER); | ||
for (ItemDefinition itemDefinition : attributesDefinitionValueMap.keySet()){ | ||
WebMarkupContainer attributePanelContainer = new WebMarkupContainer(attributesPanel.newChildId()); | ||
attributesPanel.add(attributePanelContainer); | ||
|
||
attributePanelContainer.add(new Label(ID_ATTRIBUTE_LABEL, Model.of(itemDefinition.getName().getLocalPart()))); | ||
|
||
Item item = attributesDefinitionValueMap.get(itemDefinition); | ||
IModel itemValueModel = item != null ? Model.of(item.getValue(0)) : null; | ||
attributePanelContainer.add(createTypedAttributePanel(ID_ATTRIBUTE_VALUE, | ||
getItemType(itemDefinition), itemValueModel, "value")); | ||
} | ||
listItem.add(attributesPanel); | ||
} | ||
}; | ||
|
||
add(repeater); | ||
|
||
} | ||
|
||
private Class getItemType(ItemDefinition itemDefinition){ | ||
Class type = WebComponentUtil.qnameToClass(itemDefinition.getPrismContext(), itemDefinition.getTypeName()); | ||
if (type == null){ | ||
type = itemDefinition.getPrismContext().getSchemaRegistry().determineClassForType(itemDefinition.getTypeName()); | ||
} | ||
if (type == null){ | ||
type = itemDefinition.getTypeClass(); | ||
} | ||
return type; | ||
} | ||
|
||
private Component createTypedAttributePanel(String componentId, Class type, IModel model, String expression) { | ||
Panel panel; | ||
if (type == null){ | ||
return new WebMarkupContainer(componentId); | ||
} | ||
if (type.isEnum()) { | ||
panel = WebComponentUtil.createEnumPanel(type, componentId, model != null ? new PropertyModel<>(model, expression) : null, this); | ||
} else if (ObjectReferenceType.class.isAssignableFrom(type)) { | ||
ObjectReferenceType ort = new ObjectReferenceType(); | ||
ort.setupReferenceValue((PrismReferenceValue) model.getObject()); | ||
panel = new ChooseTypePanel<AbstractRoleType>(componentId, ort) { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
|
||
@Override | ||
protected void executeCustomRemoveAction(AjaxRequestTarget target) { | ||
|
||
} | ||
|
||
@Override | ||
protected ObjectQuery getChooseQuery() { | ||
return new ObjectQuery(); | ||
} | ||
|
||
|
||
@Override | ||
public Class<AbstractRoleType> getObjectTypeClass() { | ||
return AbstractRoleType.class; | ||
} | ||
|
||
}; | ||
} else { | ||
panel = new TextPanel<>(componentId, Model.of(""), type); | ||
} | ||
|
||
panel.setOutputMarkupId(true); | ||
return panel; | ||
} | ||
|
||
} |
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