Skip to content

Commit

Permalink
MID-2742
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Mar 30, 2016
1 parent 83420d5 commit 221a50c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
Expand Up @@ -20,7 +20,6 @@
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.util.ItemPathUtil;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
Expand All @@ -34,9 +33,7 @@
import com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;

import java.util.ArrayList;
Expand Down Expand Up @@ -75,6 +72,7 @@ public class AssignmentEditorDto extends SelectableBean implements Comparable<As

private boolean showEmpty = false;
private boolean minimized = true;
private boolean editable = true;

private Boolean isOrgUnitManager = Boolean.FALSE;
private AssignmentType newAssignment;
Expand Down Expand Up @@ -102,6 +100,13 @@ public AssignmentEditorDto(UserDtoStatus status, AssignmentType assignment, Page
// ConstructionType construction = oldAssignment.getConstruction();
// newAssignment.setConstruction(construction.clone());
// }
List<Item> itemsList = newValue.getItems();
if (itemsList != null && itemsList.size() > 0){
Item item = itemsList.get(0);
if (item != null && item.getDefinition() != null) {
this.editable = item.getDefinition().canAdd() || item.getDefinition().canModify();
}
}

this.tenantRef = loadTenantOrgReference(assignment, assignment.getTenantRef());
this.orgRef = loadTenantOrgReference(assignment, assignment.getOrgRef());
Expand Down Expand Up @@ -378,7 +383,15 @@ public void setShowEmpty(boolean showEmpty) {
this.showEmpty = showEmpty;
}

public UserDtoStatus getStatus() {
public boolean isEditable() {
return editable;
}

public void setEditable(boolean editable) {
this.editable = editable;
}

public UserDtoStatus getStatus() {
return status;
}

Expand Down Expand Up @@ -571,6 +584,8 @@ public boolean equals(Object o) {
return false;
if (showEmpty != that.showEmpty)
return false;
if (editable != that.editable)
return false;
if (altName != null ? !altName.equals(that.altName) : that.altName != null)
return false;
if (attributes != null ? !attributes.equals(that.attributes) : that.attributes != null)
Expand Down
Expand Up @@ -120,9 +120,8 @@ public class AssignmentEditorPanel extends BasePanel<AssignmentEditorDto> {
private static final String ID_ERROR_ICON = "errorIcon";

private IModel<List<ACAttributeDto>> attributesModel;
private boolean isReadOnly;

public AssignmentEditorPanel(String id, IModel<AssignmentEditorDto> model, boolean isReadOnly) {
public AssignmentEditorPanel(String id, IModel<AssignmentEditorDto> model) {
super(id, model);

attributesModel = new LoadableModel<List<ACAttributeDto>>(false) {
Expand All @@ -131,7 +130,6 @@ protected List<ACAttributeDto> load() {
return loadAttributes();
}
};
this.isReadOnly = isReadOnly;

initLayout();
}
Expand Down Expand Up @@ -326,7 +324,7 @@ public void setObject(Date object) {
private void initBodyLayout(WebMarkupContainer body) {
TextArea description = new TextArea<>(ID_DESCRIPTION,
new PropertyModel<String>(getModel(), AssignmentEditorDto.F_DESCRIPTION));
description.setEnabled(!isReadOnly);
description.setEnabled(getModel().getObject().isEditable());
body.add(description);

WebMarkupContainer relationContainer = new WebMarkupContainer(ID_RELATION_CONTAINER);
Expand All @@ -352,7 +350,7 @@ public boolean isVisible() {
"AssignmentEditorPanel.member", "AssignmentEditorPanel.manager", null);
relation.setOutputMarkupId(true);
relation.setOutputMarkupPlaceholderTag(true);
relation.setPanelEnabled(!isReadOnly);
relation.setPanelEnabled(getModel().getObject().isEditable());
relation.add(new VisibleEnableBehaviour(){

@Override
Expand Down Expand Up @@ -405,17 +403,17 @@ public boolean isVisible() {
DropDownChoicePanel administrativeStatus = WebComponentUtil.createEnumPanel(ActivationStatusType.class, ID_ADMINISTRATIVE_STATUS,
new PropertyModel<ActivationStatusType>(getModel(), AssignmentEditorDto.F_ACTIVATION + "."
+ ActivationType.F_ADMINISTRATIVE_STATUS.getLocalPart()), this);
administrativeStatus.setEnabled(!isReadOnly);
administrativeStatus.setEnabled(getModel().getObject().isEditable());
activationBlock.add(administrativeStatus);

DateInput validFrom = new DateInput(ID_VALID_FROM, createDateModel(new PropertyModel<XMLGregorianCalendar>(getModel(),
AssignmentEditorDto.F_ACTIVATION + ".validFrom")));
validFrom.setEnabled(!isReadOnly);
validFrom.setEnabled(getModel().getObject().isEditable());
activationBlock.add(validFrom);

DateInput validTo = new DateInput(ID_VALID_TO, createDateModel(new PropertyModel<XMLGregorianCalendar>(getModel(),
AssignmentEditorDto.F_ACTIVATION + ".validTo")));
validTo.setEnabled(!isReadOnly);
validTo.setEnabled(getModel().getObject().isEditable());
activationBlock.add(validTo);
WebMarkupContainer targetContainer = new WebMarkupContainer(ID_TARGET_CONTAINER);
targetContainer.add(new VisibleEnableBehaviour() {
Expand Down Expand Up @@ -486,7 +484,7 @@ protected QName getSearchProperty() {
return OrgType.F_NAME;
}
};
tenantRef.setPanelEnabled(!isReadOnly);
tenantRef.setPanelEnabled(getModel().getObject().isEditable());
tenantRefContainer.add(tenantRef);
tenantRefContainer.add(new VisibleEnableBehaviour(){

Expand Down Expand Up @@ -533,7 +531,7 @@ protected QName getSearchProperty() {
}
};
tenantRefContainer.add(tenantRef);
tenantRef.setEnabled(!isReadOnly);
tenantRef.setEnabled(getModel().getObject().isEditable());
tenantRefContainer.add(new VisibleEnableBehaviour(){

@Override
Expand Down Expand Up @@ -584,7 +582,7 @@ public boolean isVisible() {
return AssignmentEditorDtoType.ACCOUNT_CONSTRUCTION.equals(dto.getType());
}
});
attributes.setEnabled(isReadOnly);
attributes.setEnabled(getModel().getObject().isEditable());
constructionContainer.add(attributes);

ListView<ACAttributeDto> attribute = new ListView<ACAttributeDto>(ID_ATTRIBUTE, attributesModel){
Expand Down
Expand Up @@ -85,14 +85,9 @@ public class AssignmentTablePanel<T extends ObjectType> extends BasePanel<List<A

public AssignmentTablePanel(String id, IModel<String> label,
IModel<List<AssignmentEditorDto>> assignmentModel) {
this(id, label, assignmentModel, false);
}

public AssignmentTablePanel(String id, IModel<String> label,
IModel<List<AssignmentEditorDto>> assignmentModel, boolean isReadOnly) {
super(id, assignmentModel);

initLayout(label, isReadOnly);
initLayout(label);
}

public List<AssignmentType> getAssignmentTypeList() {
Expand All @@ -107,7 +102,7 @@ private IModel<List<AssignmentEditorDto>> getAssignmentModel() {
return getModel();
}

private void initLayout(IModel<String> labelText, final boolean isReadOnly) {
private void initLayout(IModel<String> labelText) {
final WebMarkupContainer assignments = new WebMarkupContainer(ID_ASSIGNMENTS);
assignments.setOutputMarkupId(true);
add(assignments);
Expand All @@ -122,7 +117,7 @@ private void initLayout(IModel<String> labelText, final boolean isReadOnly) {

@Override
protected void populateItem(ListItem<AssignmentEditorDto> item) {
AssignmentEditorPanel editor = new AssignmentEditorPanel(ID_ROW, item.getModel(), isReadOnly);
AssignmentEditorPanel editor = new AssignmentEditorPanel(ID_ROW, item.getModel());
item.add(editor);
}
};
Expand Down
Expand Up @@ -109,7 +109,7 @@ private void initLayout() {
assignments.setOutputMarkupId(true);
add(assignments);
AssignmentTablePanel panel = new AssignmentTablePanel(ID_ASSIGNMENTS_PANEL,
createStringResource("FocusType.assignment"), assignmentsModel, ((ObjectWrapper)getObjectWrapperModel().getObject()).isReadonly()) {
createStringResource("FocusType.assignment"), assignmentsModel) {

@Override
protected void showAllAssignments(AjaxRequestTarget target) {
Expand Down

0 comments on commit 221a50c

Please sign in to comment.