Skip to content

Commit

Permalink
modifying of enable for prism container panel (MID-5739)
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 20, 2019
1 parent 8bfbb14 commit c700ef4
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
Expand Up @@ -99,7 +99,7 @@ protected void populateItem(ListItem<VW> item) {
.findValuePanelFactory(ItemPanel.this.getModelObject());

Component panel = createValuePanel(item, componentFactory, getVisibilityHandler());
panel.add(new EnableBehaviour(() -> !ItemPanel.this.getModelObject().isReadOnly()));
panel.add(getEnableBehaviourOfValuePanel(ItemPanel.this.getModelObject()));
createButtons(item);
}

Expand All @@ -109,6 +109,10 @@ protected void populateItem(ListItem<VW> item) {
customValuesPanel(values);
return values;
}

protected EnableBehaviour getEnableBehaviourOfValuePanel(IW iw) {
return new EnableBehaviour(() -> !iw.isReadOnly());
}

protected void customValuesPanel(ListView<VW> values) {
}
Expand Down
Expand Up @@ -24,6 +24,7 @@
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;

/**
* @author katka
Expand Down Expand Up @@ -52,7 +53,20 @@ public void onClick(AjaxRequestTarget target) {
addValue(target);
}
};
addButton.add(new VisibleBehaviour(() -> isAddButtonVisible()));
addButton.add(new VisibleEnableBehaviour() {

private static final long serialVersionUID = 1L;

@Override
public boolean isEnabled() {
return isAddButtonEnable();
}

@Override
public boolean isVisible() {
return isAddButtonVisible();
}
});
add(addButton);


Expand All @@ -79,6 +93,10 @@ private void addValue(AjaxRequestTarget target) {
private boolean isAddButtonVisible() {
return getModelObject() != null && getModelObject().isExpanded() && getModelObject().isMultiValue();
}

private boolean isAddButtonEnable() {
return getModelObject() != null && !getModelObject().isReadOnly();
}

@Override
protected Component createTitle(IModel<String> label) {
Expand Down
Expand Up @@ -105,6 +105,11 @@ protected Component createValuePanel(ListItem<PrismContainerValueWrapper<C>> ite

}

@Override
protected EnableBehaviour getEnableBehaviourOfValuePanel(PrismContainerWrapper<C> iw) {
return new EnableBehaviour(() -> true);
}

@Override
protected void customValuesPanel(ListView<PrismContainerValueWrapper<C>> values) {
values.add(new VisibleBehaviour(() -> getModelObject() != null && (getModelObject().isExpanded() || getModelObject().isSingleValue())));
Expand All @@ -114,5 +119,7 @@ protected void customValuesPanel(ListView<PrismContainerValueWrapper<C>> values)
protected void createButtons(ListItem<PrismContainerValueWrapper<C>> item) {
//nothing to do.. buttons are in the prism container panel header/ prism container value header
}



}
Expand Up @@ -48,6 +48,7 @@
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.component.util.EnableBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
Expand Down Expand Up @@ -406,7 +407,27 @@ public void onClick(AjaxRequestTarget target) {
}
};

addChildContainerButton.add(new VisibleBehaviour(() -> shouldBeButtonsShown() && getModelObject()!= null && getModelObject().isHeterogenous()));
addChildContainerButton.add(new VisibleEnableBehaviour() {

private static final long serialVersionUID = 1L;

@Override
public boolean isEnabled() {
if (getModelObject() != null) {
if(getModelObject().getParent() != null) {
return !getModelObject().getParent().isReadOnly();
} else {
return !getModelObject().isReadOnly();
}
}
return false;
}

@Override
public boolean isVisible() {
return shouldBeButtonsShown() && getModelObject()!= null && getModelObject().isHeterogenous();
}
});
addChildContainerButton.setOutputMarkupId(true);
addChildContainerButton.setOutputMarkupPlaceholderTag(true);
add(addChildContainerButton);
Expand Down Expand Up @@ -461,7 +482,27 @@ public void onClick(AjaxRequestTarget target) {
}
};

removeContainerButton.add(new VisibleBehaviour(() -> shouldBeButtonsShown()));
removeContainerButton.add(new VisibleEnableBehaviour() {

private static final long serialVersionUID = 1L;

@Override
public boolean isEnabled() {
if (getModelObject() != null) {
if(getModelObject().getParent() != null) {
return !getModelObject().getParent().isReadOnly();
} else {
return !getModelObject().isReadOnly();
}
}
return false;
}

@Override
public boolean isVisible() {
return shouldBeButtonsShown();
}
});
add(removeContainerButton);

}
Expand Down

0 comments on commit c700ef4

Please sign in to comment.