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 4fc41a1 commit d983986
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
Expand Up @@ -120,8 +120,9 @@ 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) {
public AssignmentEditorPanel(String id, IModel<AssignmentEditorDto> model, boolean isReadOnly) {
super(id, model);

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

initLayout();
}
Expand Down Expand Up @@ -324,6 +326,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);
body.add(description);

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

@Override
Expand Down Expand Up @@ -401,14 +405,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);
activationBlock.add(administrativeStatus);

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

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

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

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

ListView<ACAttributeDto> attribute = new ListView<ACAttributeDto>(ID_ATTRIBUTE, attributesModel){
Expand Down
Expand Up @@ -84,9 +84,14 @@ 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);
initLayout(label, isReadOnly);
}

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

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

@Override
protected void populateItem(ListItem<AssignmentEditorDto> item) {
AssignmentEditorPanel editor = new AssignmentEditorPanel(ID_ROW, item.getModel());
AssignmentEditorPanel editor = new AssignmentEditorPanel(ID_ROW, item.getModel(), isReadOnly);
item.add(editor);
}
};
Expand Down
Expand Up @@ -131,4 +131,9 @@ private AttributeAppender prepareButtonCssClass(String cssClass){
* Override to provide custom action on change state event
* */
protected void onStateChanged(AjaxRequestTarget target, Boolean newValue){}

public void setPanelEnabled(boolean isEnabled){
get(ID_BUTTON_ONE).setEnabled(isEnabled);
get(ID_BUTTON_TWO).setEnabled(isEnabled);
}
}
Expand Up @@ -108,9 +108,8 @@ private void initLayout() {
WebMarkupContainer assignments = new WebMarkupContainer(ID_ASSIGNMENTS);
assignments.setOutputMarkupId(true);
add(assignments);

AssignmentTablePanel panel = new AssignmentTablePanel(ID_ASSIGNMENTS_PANEL,
createStringResource("FocusType.assignment"), assignmentsModel) {
createStringResource("FocusType.assignment"), assignmentsModel, ((ObjectWrapper)getObjectWrapperModel().getObject()).isReadonly()) {

@Override
protected void showAllAssignments(AjaxRequestTarget target) {
Expand Down
Expand Up @@ -185,4 +185,9 @@ private void setToDefault(){
public Class<T> getObjectTypeClass(){
return ChooseTypePanel.this.getModelObject().getType();
}

public void setPanelEnabled(boolean isEnabled){
get(ID_LINK_CHOOSE).setEnabled(isEnabled);
get(ID_LINK_REMOVE).setEnabled(isEnabled);
}
}

0 comments on commit d983986

Please sign in to comment.