use of org.apache.wicket.util.visit.IVisitor in project midpoint by Evolveum.
the class ChangePasswordPanel method initLayout.
private void initLayout() {
WebMarkupContainer oldPasswordContainer = new WebMarkupContainer(ID_OLD_PASSWORD_CONTAINER);
oldPasswordContainer.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return isCheckOldPassword();
}
});
add(oldPasswordContainer);
PasswordTextField oldPasswordField = new PasswordTextField(ID_OLD_PASSWORD_FIELD, new PropertyModel<>(getModel(), MyPasswordsDto.F_OLD_PASSWORD));
oldPasswordField.setRequired(false);
oldPasswordContainer.add(oldPasswordField);
Label passwordLabel = new Label(ID_PASSWORD_LABEL, createStringResource("PageSelfCredentials.passwordLabel1"));
add(passwordLabel);
PasswordPanel passwordPanel = new PasswordPanel(ID_PASSWORD_PANEL, new PropertyModel<>(getModel(), MyPasswordsDto.F_PASSWORD), getModelObject().getFocus(), getPageBase()) {
@Override
protected <F extends FocusType> ValuePolicyType getValuePolicy(PrismObject<F> object) {
return getModelObject().getFocusPolicy();
}
@Override
protected void updatePasswordValidation(AjaxRequestTarget target) {
super.updatePasswordValidation(target);
limitationsByPolicyOid.clear();
getTable().visitChildren(PasswordPolicyValidationPanel.class, (IVisitor<PasswordPolicyValidationPanel, PasswordPolicyValidationPanel>) (panel, iVisit) -> {
panel.refreshValidationPopup(target);
});
}
};
passwordPanel.getBaseFormComponent().add(new AttributeModifier("autofocus", ""));
add(passwordPanel);
WebMarkupContainer accountContainer = new WebMarkupContainer(ID_ACCOUNTS_CONTAINER);
List<IColumn<PasswordAccountDto, String>> columns = initColumns();
ListDataProvider<PasswordAccountDto> provider = new ListDataProvider<>(this, new PropertyModel<>(getModel(), MyPasswordsDto.F_ACCOUNTS));
TablePanel accounts = new TablePanel(ID_ACCOUNTS_TABLE, provider, columns);
accounts.setItemsPerPage(30);
accounts.setShowPaging(false);
accountContainer.add(accounts);
accountContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return shouldShowPasswordPropagation();
}
});
add(accountContainer);
}
use of org.apache.wicket.util.visit.IVisitor in project midpoint by Evolveum.
the class ChangePasswordPanel method initColumns.
private List<IColumn<PasswordAccountDto, String>> initColumns() {
List<IColumn<PasswordAccountDto, String>> columns = new ArrayList<>();
columns.add(new CheckBoxColumn<>(Model.of(""), Selectable.F_SELECTED) {
@Override
protected IModel<Boolean> getEnabled(IModel<PasswordAccountDto> rowModel) {
return () -> {
PasswordAccountDto passwordAccountDto = rowModel.getObject();
if (!passwordAccountDto.isMidpoint() && !passwordAccountDto.isPasswordCapabilityEnabled()) {
passwordAccountDto.setSelected(false);
return false;
}
if (CredentialsPropagationUserControlType.ONLY_MAPPING.equals(getModelObject().getPropagation())) {
if (!passwordAccountDto.isMidpoint() && !passwordAccountDto.isPasswordOutbound()) {
passwordAccountDto.setSelected(false);
}
return false;
}
if (passwordAccountDto.isMidpoint() && CredentialsPropagationUserControlType.IDENTITY_MANAGER_MANDATORY.equals(getModelObject().getPropagation())) {
return false;
}
if (!passwordAccountDto.isMidpoint() && midpointAccountSelected.getObject() && passwordAccountDto.isPasswordOutbound()) {
passwordAccountDto.setSelected(true);
return false;
}
return true;
};
}
@Override
protected void processBehaviourOfCheckBox(IsolatedCheckBoxPanel check, IModel<PasswordAccountDto> rowModel) {
super.processBehaviourOfCheckBox(check, rowModel);
IModel<String> titleModel = () -> {
PasswordAccountDto passwordAccountDto = rowModel.getObject();
if (!getEnabled(rowModel).getObject()) {
String key;
if (!passwordAccountDto.isMidpoint() && !passwordAccountDto.isPasswordCapabilityEnabled()) {
key = "ChangePasswordPanel.legendMessage.no.password.capability";
} else {
key = "ChangePasswordPanel.legendMessage.policy";
}
return createStringResource(key).getString();
}
return "";
};
check.add(AttributeAppender.append("title", titleModel));
}
@Override
protected void onUpdateRow(AjaxRequestTarget target, DataTable table, IModel<PasswordAccountDto> rowModel, IModel<Boolean> selected) {
super.onUpdateRow(target, table, rowModel, selected);
if (rowModel.getObject().isMidpoint()) {
table.visitChildren(IsolatedCheckBoxPanel.class, (IVisitor<IsolatedCheckBoxPanel, IsolatedCheckBoxPanel>) (panel, iVisit) -> {
target.add(panel);
});
}
}
});
columns.add(new AbstractColumn<PasswordAccountDto, String>(createStringResource("ChangePasswordPanel.name")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<PasswordAccountDto>> item, String componentId, final IModel<PasswordAccountDto> rowModel) {
item.add(new Label(componentId, new IModel<>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
PasswordAccountDto dto = rowModel.getObject();
return dto.getDisplayName();
}
}));
}
});
columns.add(new AbstractColumn<PasswordAccountDto, String>(createStringResource("ChangePasswordPanel.resourceName")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<PasswordAccountDto>> item, String componentId, final IModel<PasswordAccountDto> rowModel) {
IModel<String> helpModel = () -> {
String title = "";
if (!rowModel.getObject().isMidpoint() && !rowModel.getObject().isPasswordCapabilityEnabled()) {
title = createStringResource("ChangePasswordPanel.legendMessage.no.password.capability").getString();
}
if (rowModel.getObject().isMaintenanceState()) {
title = title + (StringUtils.isEmpty(title) ? "" : " ") + createStringResource("ChangePasswordPanel.legendMessage.maintenance").getString();
}
return title;
};
item.add(new LabelWithHelpPanel(componentId, new IModel<>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
PasswordAccountDto dto = rowModel.getObject();
return dto.getResourceName();
}
}) {
@Override
protected IModel<String> getHelpModel() {
return helpModel;
}
});
}
});
IconColumn enabled = new IconColumn<PasswordAccountDto>(createStringResource("ChangePasswordPanel.enabled")) {
@Override
protected DisplayType getIconDisplayType(IModel<PasswordAccountDto> rowModel) {
String cssClass = "fa fa-question text-info";
String tooltip = "ActivationStatusType.null";
if (rowModel != null && rowModel.getObject() != null && rowModel.getObject().isEnabled() != null) {
if (rowModel.getObject().isEnabled()) {
cssClass = GuiStyleConstants.CLASS_APPROVAL_OUTCOME_ICON_APPROVED_COLORED;
tooltip = "ActivationStatusType.ENABLED";
} else {
cssClass = GuiStyleConstants.CLASS_APPROVAL_OUTCOME_ICON_REJECTED_COLORED;
tooltip = "ActivationStatusType.DISABLED";
}
}
return GuiDisplayTypeUtil.createDisplayType(cssClass + " fa-fw fa-lg", "", createStringResource(tooltip).getString());
}
@Override
public String getCssClass() {
return "col-lg-1";
}
};
columns.add(enabled);
columns.add(new AbstractColumn<PasswordAccountDto, String>(createStringResource("ChangePasswordPanel.passwordValidation")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<PasswordAccountDto>> cellItem, String componentId, IModel<PasswordAccountDto> rowModel) {
IModel<List<StringLimitationResult>> limitationsModel = () -> {
String policyOid = rowModel.getObject().getPasswordValuePolicyOid();
if (StringUtils.isEmpty(policyOid) || !getModelObject().getPasswordPolicies().containsKey(policyOid)) {
return new ArrayList<>();
}
if (limitationsByPolicyOid.containsKey(policyOid)) {
return limitationsByPolicyOid.get(policyOid);
}
ValuePolicyType policyType = getModelObject().getPasswordPolicies().get(policyOid);
PrismObject<? extends ObjectType> object = rowModel.getObject().getObject();
List<StringLimitationResult> limitations = getPasswordPanel().getLimitationsForActualPassword(policyType, object);
limitationsByPolicyOid.put(policyOid, limitations);
return limitations;
};
PasswordPolicyValidationPanel validationPanel = new PasswordPolicyValidationPanel(componentId, limitationsModel);
validationPanel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !limitationsModel.getObject().isEmpty();
}
});
cellItem.add(validationPanel);
}
@Override
public String getCssClass() {
return "col-lg-2";
}
});
columns.add(new AbstractColumn<PasswordAccountDto, String>(createStringResource("ChangePasswordPanel.propagationResult")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<PasswordAccountDto>> cellItem, String componentId, IModel<PasswordAccountDto> rowModel) {
LoadableModel<OperationResult> resultStatusModel = new LoadableModel<OperationResult>() {
@Override
protected OperationResult load() {
if (getModelObject().getProgress() == null || getModelObject().getProgress().getProgressReportActivities().isEmpty()) {
return null;
}
for (ProgressReportActivityDto progressActivity : getModelObject().getProgress().getProgressReportActivities()) {
if (rowModel.getObject().isSelected() && progressActivity.getStatus() != null && rowModel.getObject().isMidpoint() && (ProgressInformation.ActivityType.FOCUS_OPERATION.equals(progressActivity.getActivityType()) || (ProgressInformation.ActivityType.PROJECTOR.equals(progressActivity.getActivityType()) && !OperationResultStatusType.SUCCESS.equals(progressActivity.getStatus())))) {
return progressActivity.getOperationResult();
} else if (progressActivity.getStatus() != null && !rowModel.getObject().isMidpoint() && ProgressInformation.ActivityType.RESOURCE_OBJECT_OPERATION.equals(progressActivity.getActivityType()) && progressActivity.getResourceOperationResultList() != null && !progressActivity.getResourceOperationResultList().isEmpty()) {
String resourceOid = rowModel.getObject().getResourceOid();
if (StringUtils.isNotEmpty(resourceOid) && progressActivity.getResourceShadowDiscriminator() != null && resourceOid.equals(progressActivity.getResourceShadowDiscriminator().getResourceOid())) {
return progressActivity.getOperationResult();
}
}
}
return new OperationResult("Empty result");
}
};
ColumnResultPanel resultPanel = new ColumnResultPanel(componentId, resultStatusModel) {
@Override
protected boolean isProjectionResult() {
return !rowModel.getObject().isMidpoint();
}
@Override
protected DisplayType getDisplayForEmptyResult() {
String policyOid = rowModel.getObject().getPasswordValuePolicyOid();
if (StringUtils.isNotEmpty(policyOid) && ChangePasswordPanel.this.getModelObject().getPasswordPolicies().containsKey(policyOid)) {
if (limitationsByPolicyOid.get(policyOid) != null) {
var ref = new Object() {
boolean result = true;
};
limitationsByPolicyOid.get(policyOid).forEach((limit) -> {
if (ref.result && !limit.isSuccess()) {
ref.result = false;
}
});
if (!ref.result && rowModel.getObject().isSelected()) {
return GuiDisplayTypeUtil.createDisplayType("fa-fw fa fa-times-circle text-muted fa-lg", "", createStringResource("ChangePasswordPanel.result.validationError").getString());
}
}
}
return null;
}
};
resultPanel.setOutputMarkupId(true);
cellItem.add(resultPanel);
}
@Override
public String getCssClass() {
return "col-lg-2";
}
});
return columns;
}
use of org.apache.wicket.util.visit.IVisitor in project wicket by apache.
the class AutoLabelResolver method findRelatedComponent.
/**
* @param container
* @param id
* @return Component
*/
static Component findRelatedComponent(MarkupContainer container, final String id) {
// try the quick and easy route first
Component component = container.get(id);
if (component != null) {
return component;
}
// try the long way, search the hierarchy from the closest container up to the page
final Component[] searched = new Component[] { null };
while (container != null) {
component = container.visitChildren(Component.class, new IVisitor<Component, Component>() {
@Override
public void component(Component child, IVisit<Component> visit) {
if (child == searched[0]) {
// this container was already searched
visit.dontGoDeeper();
return;
}
if (id.equals(child.getId())) {
visit.stop(child);
return;
}
}
});
if (component != null) {
return component;
}
// remember the container so we dont search it again, and search the parent
searched[0] = container;
container = container.getParent();
}
return null;
}
use of org.apache.wicket.util.visit.IVisitor in project wicket by apache.
the class StatelessChecker method onBeforeRender.
/**
* @see org.apache.wicket.application.IComponentOnBeforeRenderListener#onBeforeRender(org.apache.wicket.Component)
*/
@Override
public void onBeforeRender(final Component component) {
if (mustCheck(component)) {
final IVisitor<Component, Component> visitor = new IVisitor<Component, Component>() {
@Override
public void component(final Component comp, final IVisit<Component> visit) {
if ((component instanceof Page) && mustCheck(comp)) {
// Do not go deeper, because this component will be
// checked by checker
// itself.
// Actually we could go deeper but that would mean we
// traverse it twice
// (for current component and for inspected one).
// We go deeper for Page because full tree will be
// inspected during
// isPageStateless call.
visit.dontGoDeeper();
} else if (!comp.isStateless()) {
visit.stop(comp);
} else {
// continue
}
}
};
if (component.isStateless() == false) {
StringList statefulBehaviors = new StringList();
for (Behavior b : component.getBehaviors()) {
if (b.getStatelessHint(component) == false) {
statefulBehaviors.add(Classes.name(b.getClass()));
}
}
String reason;
if (statefulBehaviors.size() == 0) {
reason = " Possible reason: no stateless hint";
} else {
reason = " Stateful behaviors: " + statefulBehaviors.join();
}
fail(new StatelessCheckFailureException(component, reason));
return;
}
if (component instanceof MarkupContainer) {
MarkupContainer container = ((MarkupContainer) component);
// Traverse children
final Object o = container.visitChildren(visitor);
if (o != null) {
fail(new StatelessCheckFailureException(container, " Offending component: " + o));
return;
}
}
if (component instanceof Page) {
final Page p = (Page) component;
if (!p.isBookmarkable()) {
fail(new StatelessCheckFailureException(p, " Only bookmarkable pages can be stateless"));
return;
}
if (!p.isPageStateless()) {
fail(new StatelessCheckFailureException(p, " for unknown reason"));
return;
}
}
}
}
use of org.apache.wicket.util.visit.IVisitor in project wicket by apache.
the class VisitorTest method testVisitParents.
/**
* https://issues.apache.org/jira/browse/WICKET-3805
*
* Visit parents with arbitrary type
*/
@Test
public void testVisitParents() {
TestContainer testContainer = new TestContainer();
IVisitor<MarkupContainer, MarkerInterface> visitor = new IVisitor<MarkupContainer, MarkerInterface>() {
@Override
public void component(MarkupContainer object, IVisit<MarkerInterface> visit) {
visit.stop((MarkerInterface) object);
}
};
MarkerInterface markedParent = testContainer.get("G:H").visitParents(MarkupContainer.class, visitor, new ClassVisitFilter(MarkerInterface.class));
assertEquals("G", markedParent.getId());
}
Aggregations