Skip to content

Commit

Permalink
reference search item popup improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Feb 3, 2022
1 parent b688363 commit d812a41
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public class GuiStyleConstants {
public static final String CLASS_START_MENU_ITEM = "fa fa-play";
public static final String CLASS_IMPORT_MENU_ITEM = "fa fa-download";
public static final String CLASS_NAVIGATE_ARROW = "fa fa-share";
public static final String CLASS_SELECTION_HAND = "fa fa-hand-o-up";

public static final String CLASS_BUTTON_TOGGLE_OFF = "btn-default";
public static final String CLASS_BUTTON_TOGGLE_ON = "btn-info";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<a wicket:id="editButton" class="btn btn-xs btn-default dropdown-toggle" style="margin-top: 5px; border: none !important;" data-toggle="dropdown">
<i class="fa fa-edit fa-lg"/>
</a>
<wicket:child />
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
~ Copyright (c) 2022 Evolveum
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:extend>
<a wicket:id="selectObjectButton" class="btn btn-xs btn-default dropdown-toggle" style="margin-top: 5px; border: none !important;" >
<i class="fa fa-hand-o-up fa-lg"/>
</a>
</wicket:extend>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
import java.util.List;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.model.LoadableModel;
Expand All @@ -29,12 +36,58 @@ public class ReferenceValueSearchPanel extends PopoverSearchPanel<ObjectReferenc
private static final long serialVersionUID = 1L;

private final PrismReferenceDefinition referenceDef;
private static final String ID_SELECT_OBJECT_BUTTON = "selectObjectButton";

public ReferenceValueSearchPanel(String id, IModel<ObjectReferenceType> model, PrismReferenceDefinition referenceDef) {
super(id, model);
this.referenceDef = referenceDef;
}

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

private <O extends ObjectType> void initLayout(){
setOutputMarkupId(true);

AjaxButton selectObject = new AjaxButton(ID_SELECT_OBJECT_BUTTON,
createStringResource("ReferenceValueSearchPopupPanel.selectObject")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
List<QName> supportedTypes = getSupportedTargetList();
if (CollectionUtils.isEmpty(supportedTypes)) {
supportedTypes = WebComponentUtil.createObjectTypeList();
}
ObjectBrowserPanel<O> objectBrowserPanel = new ObjectBrowserPanel<>(
getPageBase().getMainPopupBodyId(), null, supportedTypes, false, getPageBase(),
null) {
private static final long serialVersionUID = 1L;

@Override
protected void onSelectPerformed(AjaxRequestTarget target, O object) {
getPageBase().hideMainPopup(target);
if (ReferenceValueSearchPanel.this.getModel().getObject() == null) {
ReferenceValueSearchPanel.this.getModel().setObject(new ObjectReferenceType());
}
ReferenceValueSearchPanel.this.getModelObject().setOid(object.getOid());
ReferenceValueSearchPanel.this.getModelObject().setTargetName(object.getName());
ReferenceValueSearchPanel.this.getModelObject().setType(
object.asPrismObject().getComplexTypeDefinition().getTypeName());
target.add(ReferenceValueSearchPanel.this);
}
};

getPageBase().showMainPopup(objectBrowserPanel, target);
}
};
add(selectObject);
}

@Override
protected PopoverSearchPopupPanel createPopupPopoverPanel(String id) {
return new ReferenceValueSearchPopupPanel(id, ReferenceValueSearchPanel.this.getModel()) {
Expand All @@ -48,10 +101,7 @@ protected List<QName> getAllowedRelations() {

@Override
protected List<QName> getSupportedTargetList() {
if (referenceDef != null) {
return WebComponentUtil.createSupportedTargetTypeList(referenceDef.getTargetTypeName());
}
return Collections.singletonList(ObjectType.COMPLEX_TYPE);
return ReferenceValueSearchPanel.this.getSupportedTargetList();
}

@Override
Expand Down Expand Up @@ -82,6 +132,13 @@ protected String load() {
};
}

private List<QName> getSupportedTargetList() {
if (referenceDef != null) {
return WebComponentUtil.createSupportedTargetTypeList(referenceDef.getTargetTypeName());
}
return Collections.singletonList(ObjectType.COMPLEX_TYPE);
}

protected void referenceValueUpdated(ObjectReferenceType ort, AjaxRequestTarget target) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div>
<div>
<a wicket:id="confirmButton" class="btn btn-sm btn-default pull-right"/>
<a wicket:id="selectObject" class="btn btn-sm btn-default pull-right" style="margin-right: 5px;"/>
<!-- <a wicket:id="selectObject" class="btn btn-sm btn-default pull-right" style="margin-right: 5px;"/>-->
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,44 +163,6 @@ public boolean isEnabled() {
});
relation.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
relationContainer.add(relation);

AjaxButton selectObject = new AjaxButton(ID_SELECT_OBJECT_BUTTON,
createStringResource("ReferenceValueSearchPopupPanel.selectObject")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
List<QName> supportedTypes = getSupportedTargetList();
if (CollectionUtils.isEmpty(supportedTypes)) {
supportedTypes = WebComponentUtil.createObjectTypeList();
}
ObjectBrowserPanel<O> objectBrowserPanel = new ObjectBrowserPanel<>(
getPageBase().getMainPopupBodyId(), null, supportedTypes, false, getPageBase(),
null) {
private static final long serialVersionUID = 1L;

@Override
protected void onSelectPerformed(AjaxRequestTarget target, O object) {
getPageBase().hideMainPopup(target);
if (ReferenceValueSearchPopupPanel.this.getModel().getObject() == null) {
ReferenceValueSearchPopupPanel.this.getModel().setObject(new ObjectReferenceType());
}
ReferenceValueSearchPopupPanel.this.getModelObject().setOid(object.getOid());
ReferenceValueSearchPopupPanel.this.getModelObject().setTargetName(object.getName());
ReferenceValueSearchPopupPanel.this.getModelObject().setType(
object.asPrismObject().getComplexTypeDefinition().getTypeName());
target.add(oidField);
target.add(nameField);
target.add(type);
}
};

getPageBase().showMainPopup(objectBrowserPanel, target);
}
};
selectObject.add(new VisibleBehaviour(() -> getPageBase().getMainPopup().getContentComponent() == null));
midpointForm.add(selectObject);
}

private void updateModel(ObjectReferenceType ref, MidpointForm<?> midpointForm, AjaxRequestTarget target) {
Expand Down

0 comments on commit d812a41

Please sign in to comment.