Skip to content

Commit

Permalink
Merge branch 'xflord/add_missing_disabled' into 'main'
Browse files Browse the repository at this point in the history
fix: add missing setEnabled methods

See merge request perun/perun-idm/perun-wui!269
  • Loading branch information
Bc. Jakub Hejda committed Jan 2, 2024
2 parents 2c71ea7 + 2fb368d commit cb46344
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ListBox extends WidgetBox {
private final ListBoxValidator validator;
List<ExtendedTextBox> inputList;
Map<ExtendedTextBox, BlurHandler> handlers;
List<PerunButton> removeButtons;

public ListBox(PerunForm form, ApplicationFormItemData item, String lang) {
super(form, item, lang);
Expand All @@ -44,6 +45,19 @@ public ListBox(PerunForm form, ApplicationFormItemData item, String lang) {
}
}

@Override
public void setEnabled(boolean enabled) {
if (addButton != null) {
addButton.setEnabled(enabled);
}
for (PerunButton button : removeButtons) {
button.setEnabled(enabled);
}
for (ExtendedTextBox input : inputList) {
input.setEnabled(enabled);
}
}

@Override
public String getValue() {
StringBuilder value = new StringBuilder();
Expand Down Expand Up @@ -83,6 +97,7 @@ public boolean validateLocal() {
protected Widget initWidget() {
inputList = new ArrayList<>();
handlers = new HashMap<>();
removeButtons = new ArrayList<>();
return super.initWidget();
}

Expand Down Expand Up @@ -209,6 +224,7 @@ public void onLoadingStart() {
});
}
});
removeButtons.add(removeButton);
setupRemoveButton(removeButton);
hp.add(input);
hp.add(removeButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,28 @@ public class MapBox extends WidgetBox {
private final MapBoxValidator validator;
List<ExtendedTextBox> keys;
List<ExtendedTextBox> values;

List<PerunButton> removeButtons;
public MapBox(PerunForm form, ApplicationFormItemData item, String lang) {
super(form, item, lang);
this.validator = new MapBoxValidator();
}

@Override
public void setEnabled(boolean enabled) {
if (addButton != null) {
addButton.setEnabled(enabled);
}
for (PerunButton button : removeButtons) {
button.setEnabled(enabled);
}
for (ExtendedTextBox box : keys) {
box.setEnabled(enabled);
}
for (ExtendedTextBox box : values) {
box.setEnabled(enabled);
}
}

@Override
public String getValue() {
StringBuilder value = new StringBuilder();
Expand Down Expand Up @@ -100,6 +116,7 @@ public boolean validateLocal() {
protected Widget initWidget() {
keys = new ArrayList<>();
values = new ArrayList<>();
removeButtons = new ArrayList<>();
return super.initWidget();
}

Expand Down Expand Up @@ -213,6 +230,7 @@ public void onClick(ClickEvent event) {
validateLocal();
}
});
removeButtons.add(removeButton);
setupRemoveButton(removeButton);
hp.add(key);
hp.add(equals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Password extends PerunFormItemEditable {
public final static int MIN_LENGTH = 8;
public final static int MAX_LENGTH = 1024;
private final PasswordValidator validator;
private ExtendedPasswordTextBox passwordBox;
private ExtendedPasswordTextBox passwordConfirmBox;

private InputGroup widget;

Expand All @@ -53,23 +55,23 @@ protected Widget initWidget() {
InputGroupAddon addon = new InputGroupAddon();
addon.setIcon(IconType.KEY);

ExtendedPasswordTextBox box = new ExtendedPasswordTextBox();
box.setMaxLength(MAX_LENGTH);
box.addStyleName("passwordFormItemFirst");
box.setPlaceholder(getTranslation().enterPassword());
passwordBox = new ExtendedPasswordTextBox();
passwordBox.setMaxLength(MAX_LENGTH);
passwordBox.addStyleName("passwordFormItemFirst");
passwordBox.setPlaceholder(getTranslation().enterPassword());

ExtendedPasswordTextBox box2 = new ExtendedPasswordTextBox();
box2.setMaxLength(MAX_LENGTH);
box2.addStyleName("passwordFormItemLast");
box2.setPlaceholder(getTranslation().confirmPassword());
passwordConfirmBox = new ExtendedPasswordTextBox();
passwordConfirmBox.setMaxLength(MAX_LENGTH);
passwordConfirmBox.addStyleName("passwordFormItemLast");
passwordConfirmBox.setPlaceholder(getTranslation().confirmPassword());

if (getItemData().getFormItem().getRegex() != null) {
box.setRegex(getItemData().getFormItem().getRegex());
passwordBox.setRegex(getItemData().getFormItem().getRegex());
}

widget.add(addon);
widget.add(box);
widget.add(box2);
widget.add(passwordBox);
widget.add(passwordConfirmBox);

return widget;

Expand All @@ -90,6 +92,16 @@ public PerunFormItemValidator.Result getLastValidationResult() {
return validator.getLastResult();
}

@Override
public void setEnabled(boolean enabled) {
if (this.passwordBox != null) {
this.passwordBox.setEnabled(enabled);
}
if (this.passwordConfirmBox != null) {
this.passwordConfirmBox.setEnabled(enabled);
}
}

@Override
public boolean focus() {
getPassword().setFocus(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public PerunFormItemValidator.Result getLastValidationResult() {
return validator.getLastResult();
}

@Override
public void setEnabled(boolean enabled) {
for (Widget widget : getWidget()) {
if (widget instanceof Radio) {
Radio radio = (Radio) widget;
radio.setEnabled(enabled);
}
}
}

@Override
public boolean focus() {
for (Widget widget : getWidget()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ protected Widget initWidget() {

}

@Override
public void setEnabled(boolean enabled) {
if (getBox() != null) {
getBox().setEnabled(enabled);
}
}

@Override
public void validate(Events<Boolean> events) {
validator.validate(this, events);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.gwtbootstrap3.client.ui.constants.IconType;
import org.gwtbootstrap3.client.ui.html.Paragraph;


/**
* WidgetBox represent shared logic for ListBox and MapBox.
*
Expand All @@ -23,6 +24,8 @@
public class WidgetBox extends PerunFormItemEditable {

protected Widget widget;
protected PerunButton addButton;


public WidgetBox(PerunForm form, ApplicationFormItemData item, String lang) {
super(form, item, lang);
Expand Down Expand Up @@ -54,7 +57,7 @@ protected Widget initWidget() {
VerticalPanel vp = new VerticalPanel();
vp.setWidth("100%");
vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
PerunButton addButton = generateAddButton(vp);
addButton = generateAddButton(vp);
addButton.setIcon(IconType.PLUS);
addButton.setType(ButtonType.SUCCESS);
addButton.setMarginRight(40);
Expand Down

0 comments on commit cb46344

Please sign in to comment.