Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
421 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
27 changes: 27 additions & 0 deletions
27
...n-gui/src/main/java/com/evolveum/midpoint/web/component/prism/DynamicFieldGroupPanel.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,27 @@ | ||
<!-- | ||
~ 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> | ||
<html xmlns:wicket="http://wicket.apache.org"> | ||
<wicket:panel> | ||
<div class="prism-header" wicket:id="header"/> | ||
<div class="prism-properties"> | ||
<div> | ||
<div class="row prism-property" wicket:id="property"/> | ||
</div> | ||
</div> | ||
</wicket:panel> | ||
</html> |
165 changes: 165 additions & 0 deletions
165
...n-gui/src/main/java/com/evolveum/midpoint/web/component/prism/DynamicFieldGroupPanel.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,165 @@ | ||
package com.evolveum.midpoint.web.component.prism; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.xml.bind.JAXBElement; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.wicket.RestartResponseException; | ||
import org.apache.wicket.markup.html.basic.Label; | ||
import org.apache.wicket.markup.repeater.RepeatingView; | ||
import org.apache.wicket.model.Model; | ||
|
||
import com.evolveum.midpoint.gui.api.component.BasePanel; | ||
import com.evolveum.midpoint.gui.api.page.PageBase; | ||
import com.evolveum.midpoint.prism.Item; | ||
import com.evolveum.midpoint.prism.ItemDefinitionImpl; | ||
import com.evolveum.midpoint.prism.PrismContainer; | ||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.prism.xml.XsdTypeMapper; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import com.evolveum.midpoint.web.component.form.Form; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractFormItemType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.FormDefinitionType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.FormFieldGroupType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.FormFieldType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.FormItemDisplayType; | ||
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType; | ||
|
||
public class DynamicFieldGroupPanel extends BasePanel{ | ||
|
||
private static final transient Trace LOGGER = TraceManager.getTrace(DynamicFieldGroupPanel.class); | ||
|
||
private static final String ID_PROPERTY = "property"; | ||
private static final String ID_HEADER = "header"; | ||
|
||
private static final String ID_SUB_FIELD_GROUP = "subFieldGroup"; | ||
|
||
public DynamicFieldGroupPanel(String id, String groupName, ObjectWrapper objectWrapper, List<AbstractFormItemType> formItems, Form mainForm, PageBase parentPage) { | ||
super(id); | ||
setParent(parentPage); | ||
initLayout(groupName, objectWrapper, formItems, mainForm); | ||
} | ||
|
||
public DynamicFieldGroupPanel(String id, ObjectWrapper objectWrapper, FormDefinitionType formDefinition, Form mainForm, PageBase parentPage) { | ||
super(id); | ||
setParent(parentPage); | ||
String groupName = "Basic"; | ||
if (formDefinition.getDisplay() != null) { | ||
groupName = formDefinition.getDisplay().getLabel(); | ||
} | ||
initLayout(groupName, objectWrapper, getFormItems(formDefinition.getFormItem()), mainForm); | ||
} | ||
|
||
private void initLayout(String groupName, ObjectWrapper objectWrapper, List<AbstractFormItemType> formItems, Form mainForm) { | ||
|
||
Label header = new Label(ID_HEADER, groupName); | ||
add(header); | ||
|
||
RepeatingView itemView = new RepeatingView(ID_PROPERTY); | ||
add(itemView); | ||
|
||
int i = 0; | ||
for (AbstractFormItemType formItem : formItems) { | ||
|
||
if (formItem instanceof FormFieldGroupType) { | ||
DynamicFieldGroupPanel dynamicFieldGroupPanel = new DynamicFieldGroupPanel(itemView.newChildId(), formItem.getName(), objectWrapper, getFormItems(((FormFieldGroupType) formItem).getFormItem()), mainForm, getPageBase()); | ||
dynamicFieldGroupPanel.setOutputMarkupId(true); | ||
itemView.add(dynamicFieldGroupPanel); | ||
continue; | ||
} | ||
|
||
ItemWrapper itemWrapper = createItemWrapper(formItem, objectWrapper, !(i% 2 == 0)); | ||
|
||
|
||
applyFormDefinition(itemWrapper, formItem); | ||
|
||
if (itemWrapper instanceof ContainerWrapper) { | ||
PrismContainerPanel containerPanel = new PrismContainerPanel(itemView.newChildId(), | ||
Model.of((ContainerWrapper)itemWrapper), true, mainForm, getPageBase()); | ||
containerPanel.setOutputMarkupId(true); | ||
itemView.add(containerPanel); | ||
|
||
} else { | ||
|
||
PrismPropertyPanel propertyPanel = new PrismPropertyPanel(itemView.newChildId(), | ||
Model.of(itemWrapper), mainForm, getPageBase()); | ||
propertyPanel.setOutputMarkupId(true); | ||
itemView.add(propertyPanel); | ||
} | ||
|
||
i++; | ||
|
||
} | ||
} | ||
|
||
private ItemWrapper createItemWrapper(AbstractFormItemType formField, ObjectWrapper objectWrapper, boolean isStriped) { | ||
ItemPathType itemPathType = formField.getRef(); | ||
|
||
if (itemPathType == null) { | ||
getSession().error("Bad form item definition. It has to contain reference to the real attribute"); | ||
LOGGER.error("Bad form item definition. It has to contain reference to the real attribute"); | ||
throw new RestartResponseException(getPageBase()); | ||
} | ||
|
||
ItemPath path = itemPathType.getItemPath(); | ||
|
||
ItemWrapper itemWrapper = null; | ||
Item item = objectWrapper.getObject().findItem(path); | ||
if (item instanceof PrismContainer) { | ||
itemWrapper = objectWrapper.findContainerWrapper(path); | ||
} else { | ||
itemWrapper = objectWrapper.findPropertyWrapper(path); | ||
} | ||
|
||
if (itemWrapper == null) { | ||
getSession().error("Bad form item definition. No attribute with path: " + path + " was found"); | ||
LOGGER.error("Bad form item definition. No attribute with path: " + path + " was found"); | ||
throw new RestartResponseException(getPageBase()); | ||
} | ||
itemWrapper.setStripe(isStriped); | ||
|
||
return itemWrapper; | ||
|
||
} | ||
|
||
private void applyFormDefinition(ItemWrapper itemWrapper, AbstractFormItemType formField) { | ||
|
||
FormItemDisplayType displayType = formField.getDisplay(); | ||
|
||
if (displayType == null) { | ||
return; | ||
} | ||
|
||
ItemDefinitionImpl itemDef = (ItemDefinitionImpl) itemWrapper.getItemDefinition(); | ||
if (StringUtils.isNotEmpty(displayType.getLabel())) { | ||
itemDef.setDisplayName(displayType.getLabel()); | ||
} | ||
|
||
if (StringUtils.isNotEmpty(displayType.getHelp())) { | ||
itemDef.setHelp(displayType.getHelp()); | ||
} | ||
|
||
if (StringUtils.isNotEmpty(displayType.getMaxOccurs())) { | ||
itemDef.setMaxOccurs(XsdTypeMapper.multiplicityToInteger(displayType.getMaxOccurs())); | ||
} | ||
|
||
if (StringUtils.isNotEmpty(displayType.getMinOccurs())) { | ||
itemDef.setMinOccurs(XsdTypeMapper.multiplicityToInteger(displayType.getMinOccurs())); | ||
} | ||
|
||
} | ||
|
||
private List<AbstractFormItemType> getFormItems(List<JAXBElement<? extends AbstractFormItemType>> formItems) { | ||
List<AbstractFormItemType> items = new ArrayList<>(); | ||
for (JAXBElement<? extends AbstractFormItemType> formItem : formItems) { | ||
AbstractFormItemType item = formItem.getValue(); | ||
items.add(item); | ||
} | ||
return items; | ||
} | ||
|
||
|
||
} |
22 changes: 22 additions & 0 deletions
22
gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/DynamicFormPanel.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,22 @@ | ||
<!-- | ||
~ Copyright (c) 2010-2016 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> | ||
<html xmlns:wicket="http://wicket.apache.org"> | ||
<wicket:panel> | ||
<div wicket:id="formFields"/> | ||
</wicket:panel> | ||
</html> |
Oops, something went wrong.