Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 29, 2018
2 parents 842dcda + ec9fe3b commit ca3a0a9
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 75 deletions.
Expand Up @@ -760,7 +760,12 @@ public static <E extends Enum> DropDownChoicePanel createEnumPanel(Class clazz,

public static <E extends Enum> DropDownChoicePanel<E> createEnumPanel(Class<E> clazz, String id,
IModel<List<E>> choicesList, final IModel<E> model, final Component component, boolean allowNull) {
return new DropDownChoicePanel<>(id, model, choicesList,
return createEnumPanel(clazz, id, choicesList, model, component, allowNull, null);
}

public static <E extends Enum> DropDownChoicePanel<E> createEnumPanel(Class<E> clazz, String id,
IModel<List<E>> choicesList, final IModel<E> model, final Component component, boolean allowNull, String nullValidDisplayValue) {
return new DropDownChoicePanel<E>(id, model, choicesList,
new IChoiceRenderer<E>() {

private static final long serialVersionUID = 1L;
Expand All @@ -782,7 +787,16 @@ public Object getDisplayValue(E object) {
public String getIdValue(E object, int index) {
return Integer.toString(index);
}
}, allowNull);
}, allowNull){

private static final long serialVersionUID = 1L;

@Override
protected String getNullValidDisplayValue() {
return nullValidDisplayValue != null && StringUtils.isNotEmpty(nullValidDisplayValue.trim()) ?
nullValidDisplayValue : super.getNullValidDisplayValue();
}
};
}

public static DropDownChoicePanel createEnumPanel(final PrismPropertyDefinition def, String id,
Expand Down
Expand Up @@ -69,6 +69,7 @@ public class AbstractRoleAssignmentPanel extends AssignmentPanel {
private static final String ID_RELATION_CONTAINER = "relationContainer";
private static final String ID_SHOW_ALL_ASSIGNMENTS_BUTTON = "showAllAssignmentsButton";

private RelationTypes relationValue = null;

public AbstractRoleAssignmentPanel(String id, IModel<ContainerWrapper<AssignmentType>> assignmentContainerWrapperModel){
super(id, assignmentContainerWrapperModel);
Expand All @@ -91,7 +92,24 @@ public boolean isVisible() {
assignmentsContainer.addOrReplace(relationContainer);

DropDownChoicePanel<RelationTypes> relation = WebComponentUtil.createEnumPanel(RelationTypes.class, ID_RELATION,
WebComponentUtil.createReadonlyModelFromEnum(RelationTypes.class), Model.of(), this, true);
WebComponentUtil.createReadonlyModelFromEnum(RelationTypes.class),
new IModel<RelationTypes>() {
@Override
public RelationTypes getObject() {
return relationValue;
}

@Override
public void setObject(RelationTypes relationTypes) {
relationValue = relationTypes;
}

@Override
public void detach() {

}
}, this, true,
createStringResource("RelationTypes.ANY").getString());
relation.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -282,20 +300,7 @@ protected ObjectQuery createObjectQuery() {
}

private QName getRelation() {
DropDownChoicePanel<RelationTypes> relationPanel = getRelationPanel();
if (relationPanel == null) {
return PrismConstants.Q_ANY;
}

if (relationPanel.getModel() == null) {
return PrismConstants.Q_ANY;
}

if (relationPanel.getModel().getObject() == null) {
return PrismConstants.Q_ANY;
}

return relationPanel.getModel().getObject().getRelation();
return relationValue == null ? PrismConstants.Q_ANY : relationValue.getRelation();
}

@Override
Expand Down
Expand Up @@ -20,6 +20,7 @@

import com.evolveum.midpoint.web.component.prism.InputPanel;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;
Expand All @@ -37,19 +38,7 @@ public DropDownChoicePanel(String id, IModel<T> model, IModel<? extends List<? e
}

public DropDownChoicePanel(String id, IModel<T> model, IModel<? extends List<? extends T>> choices, boolean allowNull) {
super(id);

DropDownChoice<T> input = new DropDownChoice<T>(ID_INPUT, model, choices) {

private static final long serialVersionUID = 1L;

@Override
protected CharSequence getDefaultChoice(String selectedValue) {
return getString("DropDownChoicePanel.notDefined");
}
};
input.setNullValid(allowNull);
add(input);
this(id, model, choices, new ChoiceRenderer(), allowNull);
}

public DropDownChoicePanel(String id, IModel<T> model, IModel<? extends List<? extends T>> choices, IChoiceRenderer<T> renderer) {
Expand All @@ -64,9 +53,18 @@ public DropDownChoicePanel(String id, IModel<T> model, IModel<? extends List<? e

private static final long serialVersionUID = 1L;

@Override
@Override
protected CharSequence getDefaultChoice(String selectedValue) {
if (allowNull){
return super.getDefaultChoice(selectedValue);
} else {
return getString("DropDownChoicePanel.notDefined");
}
}

@Override
protected String getNullValidDisplayValue() {
return getString("DropDownChoicePanel.notDefined");
return DropDownChoicePanel.this.getNullValidDisplayValue();
}
};
input.setNullValid(allowNull);
Expand All @@ -81,4 +79,8 @@ public DropDownChoice<T> getBaseFormComponent() {
public IModel<T> getModel() {
return getBaseFormComponent().getModel();
}

protected String getNullValidDisplayValue() {
return getString("DropDownChoicePanel.notDefined");
}
}
Expand Up @@ -118,6 +118,7 @@ public class OrgMemberPanel extends AbstractRoleMemberPanel<OrgType> {
private static final String ID_DELETE_MANAGER = "deleteManager";
private static final String ID_EDIT_MANAGER = "editManager";

private RelationTypes relationValue = null;
private static final long serialVersionUID = 1L;

public OrgMemberPanel(String id, IModel<OrgType> model) {
Expand Down Expand Up @@ -175,10 +176,26 @@ protected void onUpdate(AjaxRequestTarget target) {
seachScrope.setOutputMarkupId(true);
form.add(seachScrope);

List<RelationTypes> relationTypes = new ArrayList<>(Arrays.asList(RelationTypes.values()));
DropDownChoicePanel<RelationTypes> relationSelector = new DropDownChoicePanel<>(ID_SEARCH_BY_RELATION,
Model.of(), Model.ofList(relationTypes),
new EnumChoiceRenderer<>(), true);
DropDownChoicePanel<RelationTypes> relationSelector = WebComponentUtil.createEnumPanel(RelationTypes.class, ID_SEARCH_BY_RELATION,
WebComponentUtil.createReadonlyModelFromEnum(RelationTypes.class),
new IModel<RelationTypes>() {
@Override
public RelationTypes getObject() {
return relationValue;
}

@Override
public void setObject(RelationTypes relationTypes) {
relationValue = relationTypes;
}

@Override
public void detach() {

}
}, this, true,
createStringResource("RelationTypes.ANY").getString());

relationSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
relationSelector.setOutputMarkupId(true);
relationSelector.setOutputMarkupPlaceholderTag(true);
Expand Down Expand Up @@ -684,13 +701,7 @@ protected ObjectQuery createContentQuery() {
q = q.type(searchType.getClassDefinition());
}

RelationTypes relation = getSelectedRelation();
QName relationValue = null;
if (relation == null){
relationValue = PrismConstants.Q_ANY;
} else {
relationValue = relation.getRelation();
}
QName relationValue = getSelectedRelation();
PrismReferenceValue ref = new PrismReferenceValue(oid);
ref.setRelation(relationValue);
ObjectQuery query;
Expand All @@ -707,9 +718,12 @@ protected ObjectQuery createContentQuery() {
return query;
}

private RelationTypes getSelectedRelation(){
DropDownChoicePanel<RelationTypes> relationSelector = (DropDownChoicePanel<RelationTypes>) getFormComponent().get(ID_SEARCH_BY_RELATION);
return relationSelector.getBaseFormComponent().getModelObject();
private QName getSelectedRelation(){
if (relationValue == null){
return PrismConstants.Q_ANY;
} else {
return relationValue.getRelation();
}
}

private ObjectQuery createQueryForMemberAction(QueryScope scope, QName orgRelation, boolean isFocus) {
Expand Down Expand Up @@ -818,15 +832,6 @@ protected Class getDefaultObjectType(){
return OBJECT_TYPES_DEFAULT.getClassDefinition();
}

private List<String> getRelationsLocalizedList(){
List<String> relationsList = new ArrayList<>();
relationsList.add(createStringResource("RelationTypes.ANY").getString());
for (RelationTypes relation : RelationTypes.values()){
relationsList.add(createStringResource(RelationTypes.class.getSimpleName() + "." + relation.name()).getString());
}
return relationsList;
}

@Override
protected boolean isRelationColumnVisible(){
return true;
Expand Down

0 comments on commit ca3a0a9

Please sign in to comment.