From 1e9c0ec42a6f17e274d1e11bb2e2d69cdce7b221 Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 26 May 2020 17:28:37 +0200 Subject: [PATCH 01/19] search panel - default button, delete search item functionality --- .../web/component/search/SearchItemPanel.html | 2 +- .../web/component/search/SearchItemPanel.java | 8 +++--- .../web/component/search/SearchPanel.html | 6 ++--- .../web/component/search/SearchPanel.java | 27 ++++++++++--------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html index 08e5305f171..34d57e67321 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html @@ -14,7 +14,7 @@
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java index 4fc0f9cc8b6..dc9cddf5f2e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java @@ -458,10 +458,10 @@ private IModel createLabelModel() { private void deletePerformed(AjaxRequestTarget target) { SearchItem item = getModelObject(); - - Search search = item.getSearch(); - search.delete(item); - + ((SearchValue)item.getValue()).setValue(null); +// Search search = item.getSearch(); +// search.delete(item); +// SearchPanel panel = findParent(SearchPanel.class); panel.refreshSearchForm(target); panel.searchPerformed(target); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.html index b14c881d0c6..5fc23dabe7c 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.html @@ -34,9 +34,9 @@
- - - + + +
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.java index aea2cad7480..daeb06dc7cc 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.java @@ -18,6 +18,7 @@ import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.web.component.AjaxButton; import com.evolveum.midpoint.web.component.AjaxSubmitButton; +import com.evolveum.midpoint.web.component.form.Form; import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem; import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction; import com.evolveum.midpoint.web.component.menu.cog.MenuLinkPanel; @@ -39,7 +40,6 @@ import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.CheckBox; -import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextArea; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.list.ListItem; @@ -125,7 +125,7 @@ protected MoreDialogDto load() { } }; - Form form = new com.evolveum.midpoint.web.component.form.Form<>(ID_FORM); + Form form = new Form<>(ID_FORM); add(form); ListView> items = new ListView>(ID_ITEMS, @@ -169,17 +169,17 @@ public boolean isVisible() { more.setOutputMarkupId(true); moreGroup.add(more); - AjaxLink searchConfigurationButton = new AjaxLink(ID_SEARCH_CONFIGURATION) { - private static final long serialVersionUID = 1L; - - @Override - public void onClick(AjaxRequestTarget target) { - searchConfigurationPerformed(target); - } - }; - searchConfigurationButton.add(new VisibleBehaviour(() -> false)); - searchConfigurationButton.setOutputMarkupId(true); - form.add(searchConfigurationButton); +// AjaxLink searchConfigurationButton = new AjaxLink(ID_SEARCH_CONFIGURATION) { +// private static final long serialVersionUID = 1L; +// +// @Override +// public void onClick(AjaxRequestTarget target) { +// searchConfigurationPerformed(target); +// } +// }; +// searchConfigurationButton.add(new VisibleBehaviour(() -> false)); +// searchConfigurationButton.setOutputMarkupId(true); +// form.add(searchConfigurationButton); WebMarkupContainer searchContainer = new WebMarkupContainer(ID_SEARCH_CONTAINER); searchContainer.setOutputMarkupId(true); @@ -219,6 +219,7 @@ public boolean isVisible() { }); searchSimple.setOutputMarkupId(true); searchContainer.add(searchSimple); + form.setDefaultButton(searchSimple); WebMarkupContainer searchDropdown = new WebMarkupContainer(ID_SEARCH_DROPDOWN); searchDropdown.add(new VisibleEnableBehaviour() { From f1f8d264b059df303f157c8e0c6251aa74d51a2e Mon Sep 17 00:00:00 2001 From: kate Date: Wed, 27 May 2020 02:08:36 +0200 Subject: [PATCH 02/19] some changes for reference object search field --- .../component/search/ReferencePopupPanel.java | 2 +- .../web/component/search/SearchItemPanel.html | 13 +- .../web/component/search/SearchItemPanel.java | 178 ++++++++++-------- 3 files changed, 106 insertions(+), 87 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.java index 57ae0936b57..7b111e846bf 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.java @@ -78,7 +78,7 @@ public boolean isEnabled() { add(type); - if (getModelObject().getValue() != null && getModelObject().getValue().getRelation() == null){ + if (getModelObject() != null && getModelObject().getValue() != null && getModelObject().getValue().getRelation() == null){ getModelObject().getValue().setRelation(PrismConstants.Q_ANY); } List allowedRelations = new ArrayList(); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html index 34d57e67321..bb84444e8e5 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html @@ -29,19 +29,18 @@ - +
- - - - +
+
+
- - +
+
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java index dc9cddf5f2e..fa1faac57a8 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java @@ -28,9 +28,13 @@ import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour; import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; + import org.apache.commons.lang.StringUtils; import org.apache.wicket.Component; +import org.apache.wicket.ajax.AjaxEventBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.behavior.AttributeAppender; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; @@ -59,12 +63,12 @@ public class SearchItemPanel extends BasePanel>(false) { -// -// private static final long serialVersionUID = 1L; -// -// @Override -// protected SearchItemPopoverDto load() { -// return loadPopoverItems(); -// } -// }; + popoverModel = new LoadableModel>(false) { + + private static final long serialVersionUID = 1L; + + @Override + protected SearchItemPopoverDto load() { + return loadPopoverItems(); + } + }; // // AjaxLink mainButton = new AjaxLink(ID_MAIN_BUTTON) { // @@ -141,7 +145,7 @@ private void initLayout() { // } // }); // -// initPopover(); + initPopover(); WebMarkupContainer searchItemContainer = new WebMarkupContainer(ID_SEARCH_ITEM_CONTAINER); @@ -173,15 +177,24 @@ private void initSearchItemField(WebMarkupContainer searchItemContainer) { switch (item.getType()) { case REFERENCE: //TODO change probably to another component - searchItemField = new ValueChoosePanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value")){ - + searchItemField = new TextPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value")); + ((TextPanel)searchItemField).getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("focus") { private static final long serialVersionUID = 1L; @Override - public List getSupportedTypes() { - return WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName()); + protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) { + editPerformed(ajaxRequestTarget); } - }; + }); +// searchItemField = new ValueChoosePanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value")){ +// +// private static final long serialVersionUID = 1L; +// +// @Override +// public List getSupportedTypes() { +// return WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName()); +// } +// }; break; case BOOLEAN: choices = (IModel) createBooleanChoices(); @@ -235,55 +248,62 @@ private IModel getSearchItemValueModel(){ } return Model.of(item.getValue().getValue().toString()); } -// private SearchItemPopoverDto loadPopoverItems() { -// SearchItemPopoverDto dto = new SearchItemPopoverDto<>(); -// -// SearchItem item = getModelObject(); -// for (DisplayableValue value : item.getValues()) { -// //TODO : what if null reference -// DisplayableValue itemValue = new SearchValue(value.getValue(), value.getLabel()); -// dto.getValues().add(itemValue); -// } -// -// if (dto.getValues().isEmpty()) { -// dto.getValues().add(new SearchValue<>()); -// } -// -// return dto; -// } + private SearchItemPopoverDto loadPopoverItems() { + SearchItemPopoverDto dto = new SearchItemPopoverDto<>(); -// private void initPopover() { -// WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER); -// popover.setOutputMarkupId(true); -// add(popover); -// -// WebMarkupContainer popoverBody = new WebMarkupContainer(ID_POPOVER_BODY); -// popoverBody.setOutputMarkupId(true); -// popover.add(popoverBody); -// -// ListView> values = new ListView>(ID_VALUES, -// new PropertyModel<>(popoverModel, SearchItem.F_VALUES)) { -// -// private static final long serialVersionUID = 1L; -// -// @Override -// protected void populateItem(final ListItem> item) { -// item.add(AttributeModifier.replace("style", new IModel() { -// -// private static final long serialVersionUID = 1L; -// -// @Override -// public String getObject() { -// return item.getIndex() != 0 ? "margin-top: 5px;" : null; -// } -// })); -// -// SearchPopupPanel fragment = createPopoverFragment(item.getModel()); -// fragment.setRenderBodyOnly(true); -// item.add(fragment); -// } -// }; -// popoverBody.add(values); + SearchItem item = getModelObject(); + DisplayableValue itemValue = new SearchValue(item.getValue().getValue(), item.getValue().getLabel()); + dto.getValues().add(itemValue); + + if (dto.getValues().isEmpty()) { + dto.getValues().add(new SearchValue<>()); + } + + return dto; + } + + private void initPopover() { + WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER); + popover.setOutputMarkupId(true); + add(popover); + + WebMarkupContainer popoverBody = new WebMarkupContainer(ID_POPOVER_BODY); + popoverBody.setOutputMarkupId(true); + popover.add(popoverBody); + + + DisplayableValue val = SearchItemPanel.this.getModelObject().getValue(); + IModel> refModel = new IModel>() { + @Override + public DisplayableValue getObject() { + if (val.getValue() instanceof ObjectReferenceType){ + return val; + } else { + return null; + } + } + }; + SearchPopupPanel value = + (SearchPopupPanel) new ReferencePopupPanel(ID_VALUE, refModel) { + + private static final long serialVersionUID = 1L; + + @Override + protected List getAllowedRelations() { + if (SearchItemPanel.this.getModelObject().getAllowedRelations() != null) { + return SearchItemPanel.this.getModelObject().getAllowedRelations(); + } + return super.getAllowedRelations(); + } + + @Override + protected List getSupportedTargetList() { + return new ArrayList<>(); +// return WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) SearchItemPanel.this.getModelObject().getDefinition()).getTargetTypeName()); + } + }; + value.setRenderBodyOnly(true); + popoverBody.add(value); // // AjaxSubmitButton update = new AjaxSubmitButton(ID_UPDATE, createStringResource("SearchItemPanel.update")) { // @@ -306,7 +326,7 @@ private IModel getSearchItemValueModel(){ // } // }; // popoverBody.add(close); -// } + } // // private SearchPopupPanel createPopoverFragment(IModel> data) { //// SearchPopupPanel popup; @@ -443,18 +463,18 @@ private IModel createLabelModel() { // togglePopover(target); // } -// private void editPerformed(AjaxRequestTarget target) { -// LOG.debug("Edit performed"); -// -// popoverModel.reset(); -// target.add(get(createComponentPath(ID_POPOVER, ID_POPOVER_BODY))); -// togglePopover(target); -// } -// -// public void togglePopover(AjaxRequestTarget target) { -// SearchPanel panel = findParent(SearchPanel.class); -// panel.togglePopover(target, get(ID_MAIN_BUTTON), get(ID_POPOVER), 0); -// } + private void editPerformed(AjaxRequestTarget target) { + LOG.debug("Edit performed"); + + popoverModel.reset(); + target.add(get(createComponentPath(ID_POPOVER, ID_POPOVER_BODY))); + togglePopover(target); + } + + public void togglePopover(AjaxRequestTarget target) { + SearchPanel panel = findParent(SearchPanel.class); + panel.togglePopover(target, get(createComponentPath(ID_SEARCH_ITEM_CONTAINER, ID_SEARCH_ITEM_FIELD)), get(ID_POPOVER), 0); + } private void deletePerformed(AjaxRequestTarget target) { SearchItem item = getModelObject(); From c885310aa109428b604603e9894e28a58160a10d Mon Sep 17 00:00:00 2001 From: kate Date: Thu, 28 May 2020 02:30:33 +0200 Subject: [PATCH 03/19] reference object search field popup --- .../component/search/ReferencePopupPanel.html | 10 +- .../component/search/ReferencePopupPanel.java | 24 ++- .../midpoint/web/component/search/Search.java | 2 + .../web/component/search/SearchItemPanel.html | 22 +-- .../web/component/search/SearchItemPanel.java | 169 +++++++++++++----- .../web/component/search/SearchPanel.html | 1 - .../web/component/search/SearchPanel.java | 14 +- .../component/search/SearchPopupPanel.java | 4 + 8 files changed, 170 insertions(+), 76 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.html index a82b11bec6a..8948e32ea0b 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.html @@ -19,23 +19,19 @@
-
-
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.java index 7b111e846bf..9c4e2e70647 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/ReferencePopupPanel.java @@ -12,6 +12,9 @@ import javax.xml.namespace.QName; import com.evolveum.midpoint.prism.PrismConstants; +import com.evolveum.midpoint.web.component.AjaxButton; +import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour; + import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.markup.html.form.DropDownChoice; @@ -32,6 +35,7 @@ public class ReferencePopupPanel extends SearchPopupPanel { private static final String ID_OID = "oid"; private static final String ID_TYPE = "type"; private static final String ID_RELATION = "relation"; + private static final String ID_CONFIRM_BUTTON = "confirmButton"; // private List allowedRelations; @@ -60,6 +64,7 @@ protected void onUpdate(AjaxRequestTarget target) { } }); oidField.setOutputMarkupId(true); + oidField.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); add(oidField); DropDownChoice type = new DropDownChoice<>(ID_TYPE, new PropertyModel(getModel(), SearchValue.F_VALUE + ".type"), @@ -75,7 +80,7 @@ public boolean isEnabled() { return getSupportedTargetList().size() > 1; } }); - + type.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); add(type); if (getModelObject() != null && getModelObject().getValue() != null && getModelObject().getValue().getRelation() == null){ @@ -99,7 +104,24 @@ public boolean isEnabled() { return getAllowedRelations().size() > 1; } }); + relation.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); add(relation); + + AjaxButton confirm = new AjaxButton(ID_CONFIRM_BUTTON, createStringResource("Button.ok")) { + + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) { + confirmPerformed(target); + } + }; + add(confirm); + + } + + protected void confirmPerformed(AjaxRequestTarget target){ + } protected List getAllowedRelations() { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/Search.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/Search.java index 9e1d6daff7e..27af534923e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/Search.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/Search.java @@ -136,6 +136,8 @@ public SearchItem addItem(ItemDefinition def) { List supportedTargets = WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) def).getTargetTypeName()); if (supportedTargets.size() == 1) { ref.setType(supportedTargets.iterator().next()); + } else { + ref.setType(ObjectType.COMPLEX_TYPE); } if (itemToRemove.getAllowedValues() != null && itemToRemove.getAllowedValues().size() == 1) { ref.setRelation((QName) itemToRemove.getAllowedValues().iterator().next()); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html index bb84444e8e5..95d711af97f 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.html @@ -12,7 +12,12 @@
-
+ - - - - - - - - -
-
- - - - -
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java index fa1faac57a8..c9b34074638 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchItemPanel.java @@ -7,6 +7,27 @@ package com.evolveum.midpoint.web.component.search; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.xml.namespace.QName; + +import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; + +import org.apache.commons.lang.StringUtils; +import org.apache.wicket.Component; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.behavior.AttributeAppender; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.IChoiceRenderer; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.util.ListModel; + import com.evolveum.midpoint.gui.api.component.BasePanel; import com.evolveum.midpoint.gui.api.model.LoadableModel; import com.evolveum.midpoint.gui.api.page.PageBase; @@ -21,36 +42,15 @@ import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.web.component.AjaxSubmitButton; -import com.evolveum.midpoint.web.component.form.ValueChoosePanel; import com.evolveum.midpoint.web.component.input.DropDownChoicePanel; import com.evolveum.midpoint.web.component.input.TextPanel; import com.evolveum.midpoint.web.component.prism.InputPanel; +import com.evolveum.midpoint.web.component.util.EnableBehaviour; +import com.evolveum.midpoint.web.component.util.VisibleBehaviour; import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour; import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType; - import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; -import org.apache.commons.lang.StringUtils; -import org.apache.wicket.Component; -import org.apache.wicket.ajax.AjaxEventBehavior; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; -import org.apache.wicket.behavior.AttributeAppender; -import org.apache.wicket.markup.html.WebMarkupContainer; -import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.markup.html.form.IChoiceRenderer; -import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; -import org.apache.wicket.model.PropertyModel; -import org.apache.wicket.model.util.ListModel; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.xml.namespace.QName; - /** * @author Viliam Repan (lazyman) */ @@ -73,6 +73,7 @@ public class SearchItemPanel extends BasePanel> popoverModel; @@ -145,6 +146,7 @@ protected SearchItemPopoverDto load() { // } // }); // + setOutputMarkupId(true); initPopover(); @@ -158,6 +160,18 @@ protected SearchItemPopoverDto load() { initSearchItemField(searchItemContainer); + AjaxSubmitButton editButton = new AjaxSubmitButton(ID_EDIT_BUTTON) { + private static final long serialVersionUID = 1L; + + @Override + public void onSubmit(AjaxRequestTarget target) { + togglePopover(target); + } + }; + editButton.setOutputMarkupId(true); + editButton.add(new VisibleBehaviour(() -> SearchItem.Type.REFERENCE.equals(getModelObject().getType()))); + searchItemContainer.add(editButton); + AjaxSubmitButton removeButton = new AjaxSubmitButton(ID_REMOVE_BUTTON) { private static final long serialVersionUID = 1L; @@ -177,8 +191,42 @@ private void initSearchItemField(WebMarkupContainer searchItemContainer) { switch (item.getType()) { case REFERENCE: //TODO change probably to another component - searchItemField = new TextPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value")); - ((TextPanel)searchItemField).getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("focus") { + searchItemField = new TextPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"){ + private static final long serialVersionUID = 1L; + + @Override + public String getObject(){ + SearchItem searchItem = getModelObject(); + if (searchItem == null || searchItem.getValue() == null){ + return null; + } + ObjectReferenceType ref = (ObjectReferenceType) searchItem.getValue().getValue(); + if (ref == null){ + return null; + } + StringBuilder sb = new StringBuilder(); + if (StringUtils.isNotEmpty(ref.getOid())){ + sb.append(createStringResource("ReferencePopupPanel.oid").getString()); + sb.append(ref.getOid()); + } + if (ref.getRelation() != null){ + if (sb.length() > 0){ + sb.append("; "); + } + sb.append(createStringResource("ReferencePopupPanel.relation").getString()); + sb.append(ref.getRelation().getLocalPart()); + } + if (ref.getType() != null){ + if (sb.length() > 0){ + sb.append("; "); + } + sb.append(ref.getType().getLocalPart()); + } + return sb.toString(); + } + }); + ((TextPanel)searchItemField).getBaseFormComponent().add(new EnableBehaviour(() -> false)); + ((TextPanel)searchItemField).getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("focus") { private static final long serialVersionUID = 1L; @Override @@ -283,27 +331,40 @@ public DisplayableValue getObject() { } } }; - SearchPopupPanel value = - (SearchPopupPanel) new ReferencePopupPanel(ID_VALUE, refModel) { - - private static final long serialVersionUID = 1L; + if (getModelObject() != null && SearchItem.Type.REFERENCE.equals(getModelObject().getType())) { + SearchPopupPanel value = + (SearchPopupPanel) new ReferencePopupPanel(ID_VALUE, new PropertyModel<>(getModel(), "value")) { + + private static final long serialVersionUID = 1L; + + @Override + protected List getAllowedRelations() { + if (SearchItemPanel.this.getModelObject().getAllowedRelations() != null) { + return SearchItemPanel.this.getModelObject().getAllowedRelations(); + } + return super.getAllowedRelations(); + } - @Override - protected List getAllowedRelations() { - if (SearchItemPanel.this.getModelObject().getAllowedRelations() != null) { - return SearchItemPanel.this.getModelObject().getAllowedRelations(); + @Override + protected List getSupportedTargetList() { + ItemDefinition itemDef = SearchItemPanel.this.getModelObject().getDefinition(); + if (itemDef instanceof PrismReferenceDefinition) { + return WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) SearchItemPanel.this.getModelObject().getDefinition()).getTargetTypeName()); + } + return new ArrayList<>(); } - return super.getAllowedRelations(); - } - @Override - protected List getSupportedTargetList() { - return new ArrayList<>(); -// return WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) SearchItemPanel.this.getModelObject().getDefinition()).getTargetTypeName()); - } - }; - value.setRenderBodyOnly(true); - popoverBody.add(value); + @Override + protected void confirmPerformed(AjaxRequestTarget target) { + closeEditPopoverPerformed(target); + } + }; + value.setRenderBodyOnly(true); + popoverBody.add(value); + } else { + WebMarkupContainer value = new WebMarkupContainer(ID_VALUE); + popoverBody.add(value); + } // // AjaxSubmitButton update = new AjaxSubmitButton(ID_UPDATE, createStringResource("SearchItemPanel.update")) { // @@ -459,9 +520,9 @@ private IModel createLabelModel() { // return popoverModel; // } // -// private void closeEditPopoverPerformed(AjaxRequestTarget target) { -// togglePopover(target); -// } + private void closeEditPopoverPerformed(AjaxRequestTarget target) { + target.add(SearchItemPanel.this); + } private void editPerformed(AjaxRequestTarget target) { LOG.debug("Edit performed"); @@ -478,7 +539,21 @@ public void togglePopover(AjaxRequestTarget target) { private void deletePerformed(AjaxRequestTarget target) { SearchItem item = getModelObject(); - ((SearchValue)item.getValue()).setValue(null); +// if (SearchItem.Type.REFERENCE.equals(getModelObject().getType())){ +// ObjectReferenceType newVal = new ObjectReferenceType(); +// +// PrismReferenceDefinition def = (PrismReferenceDefinition) item.getDefinition(); +// List supportedTargets = WebComponentUtil.createSupportedTargetTypeList(def.getTargetTypeName()); +// if (supportedTargets.size() == 1) { +// newVal.setType(supportedTargets.iterator().next()); +// } else { +// newVal.setType(ObjectType.COMPLEX_TYPE); +// } +// newVal.setType(def.getTargetTypeName()); +// ((SearchValue)item.getValue()).setValue(newVal); +// } else { + ((SearchValue) item.getValue()).setValue(null); +// } // Search search = item.getSearch(); // search.delete(item); // diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.html index 5fc23dabe7c..fb4424142b8 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/search/SearchPanel.html @@ -7,7 +7,6 @@ -->
-