Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed May 25, 2017
1 parent cef05d0 commit 6e3505a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
Expand Up @@ -19,6 +19,14 @@
import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.web.component.prism.ContainerStatus;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.page.admin.users.PageUser;
import com.evolveum.midpoint.web.page.self.PageSelfProfile;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -62,22 +70,22 @@ public class PasswordPanel extends InputPanel {
private boolean passwordInputVisble;

public PasswordPanel(String id, IModel<ProtectedStringType> model) {
this(id, model, false, false);
this(id, model, false);
}

public PasswordPanel(String id, IModel<ProtectedStringType> model, boolean isReadOnly, boolean showRemoveButton) {
public PasswordPanel(String id, IModel<ProtectedStringType> model, boolean isReadOnly) {
super(id);
this.passwordInputVisble = model.getObject() == null;
initLayout(model, isReadOnly, showRemoveButton);
initLayout(model, isReadOnly);
}

public PasswordPanel(String id, IModel<ProtectedStringType> model, boolean isReadOnly, boolean isInputVisible, boolean showRemoveButton) {
public PasswordPanel(String id, IModel<ProtectedStringType> model, boolean isReadOnly, boolean isInputVisible) {
super(id);
this.passwordInputVisble = isInputVisible;
initLayout(model, isReadOnly, showRemoveButton);
initLayout(model, isReadOnly);
}

private void initLayout(final IModel<ProtectedStringType> model, final boolean isReadOnly, boolean showRemoveButton) {
private void initLayout(final IModel<ProtectedStringType> model, final boolean isReadOnly) {
setOutputMarkupId(true);
final WebMarkupContainer inputContainer = new WebMarkupContainer(ID_INPUT_CONTAINER) {
@Override
Expand Down Expand Up @@ -165,7 +173,18 @@ public void onClick(AjaxRequestTarget target) {

@Override
public boolean isVisible() {
return showRemoveButton;
PageBase pageBase = (PageBase)getPage();
if (pageBase == null){
return false;
}
if (pageBase instanceof PageSelfProfile){
return false;
}
if (pageBase instanceof PageUser
&& model.getObject() != null && !model.getObject().isEmpty()){
return true;
}
return false;
}
});
removePassword.setBody(new ResourceModel("passwordPanel.passwordRemove"));
Expand Down
Expand Up @@ -440,18 +440,8 @@ private Panel createTypedInputComponent(String id) {
panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(valueWrapperModel, baseExpression));

} else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
boolean showRemovePasswordButton = true;
if (pageBase instanceof PageUser &&
((PageUser) pageBase).getObjectWrapper().getObject() != null &&
((PageUser) pageBase).getObjectWrapper().getObject().getOid() != null &&
((PageUser) pageBase).getObjectWrapper().getObject().getOid().equals(SecurityUtils.getPrincipalUser().getOid())) {
showRemovePasswordButton = false;
} else if (valueWrapperModel.getObject().getStatus() == ValueStatus.ADDED) {
// it has no sense to show remove button while adding a new value..
showRemovePasswordButton = false;
}
panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(valueWrapperModel, baseExpression),
valueWrapperModel.getObject().isReadonly(), showRemovePasswordButton);
valueWrapperModel.getObject().isReadonly());
} else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(valueWrapperModel, baseExpression));

Expand Down
Expand Up @@ -351,8 +351,7 @@ public boolean isVisible() {
private void createPasswordPanel(WebMarkupContainer staticRegistrationForm) {
// ProtectedStringType initialPassword = null;
PasswordPanel password = new PasswordPanel(ID_PASSWORD,
new PropertyModel<ProtectedStringType>(userModel, "credentials.password.value"), false, true,
false);
new PropertyModel<ProtectedStringType>(userModel, "credentials.password.value"), false, true);
password.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
password.getBaseFormComponent().setRequired(true);
staticRegistrationForm.add(password);
Expand Down

0 comments on commit 6e3505a

Please sign in to comment.