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();