aae75a13c1efb200d2de650e25cbcfe9e8a38426
java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/IPBlocklistTableWrapper.java
| ... | ... | @@ -6,12 +6,15 @@ import java.util.HashMap; |
| 6 | 6 | import java.util.List; |
| 7 | 7 | import java.util.Map.Entry; |
| 8 | 8 | |
| 9 | +import com.google.gwt.event.dom.client.ClickEvent; |
|
| 10 | +import com.google.gwt.event.dom.client.ClickHandler; |
|
| 9 | 11 | import com.google.gwt.user.cellview.client.AbstractCellTable; |
| 10 | 12 | import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler; |
| 11 | 13 | import com.google.gwt.user.client.Command; |
| 12 | 14 | import com.google.gwt.user.client.rpc.AsyncCallback; |
| 13 | 15 | import com.google.gwt.user.client.ui.Button; |
| 14 | -import com.google.gwt.user.client.ui.CheckBox; |
|
| 16 | +import com.google.gwt.user.client.ui.HasVerticalAlignment; |
|
| 17 | +import com.google.gwt.user.client.ui.HorizontalPanel; |
|
| 15 | 18 | import com.google.gwt.user.client.ui.Label; |
| 16 | 19 | import com.sap.sailing.gwt.ui.client.SailingServiceWriteAsync; |
| 17 | 20 | import com.sap.sailing.gwt.ui.client.StringMessages; |
| ... | ... | @@ -23,6 +26,7 @@ import com.sap.sse.gwt.client.panels.LabeledAbstractFilterablePanel; |
| 23 | 26 | import com.sap.sse.security.shared.HasPermissions; |
| 24 | 27 | import com.sap.sse.security.ui.client.UserService; |
| 25 | 28 | import com.sap.sse.security.ui.client.component.AccessControlledButtonPanel; |
| 29 | +import com.sap.sse.security.ui.client.component.SelectedElementsCountingButton; |
|
| 26 | 30 | |
| 27 | 31 | abstract class IPBlocklistTableWrapper |
| 28 | 32 | extends TableWrapper<IpToTimedLockDTO, RefreshableSelectionModel<IpToTimedLockDTO>> { |
| ... | ... | @@ -53,15 +57,27 @@ abstract class IPBlocklistTableWrapper |
| 53 | 57 | this.securedDomainType = securedDomainType; |
| 54 | 58 | this.userService = userService; |
| 55 | 59 | this.errorMessageOnDataFailureString = errorMessageOnDataFailureString; |
| 60 | + this.filterField = composeFilterField(); |
|
| 56 | 61 | this.asWidget().ensureDebugId("wrappedTable"); |
| 57 | 62 | this.table.ensureDebugId("cellTable"); |
| 58 | - filterField = composeFilterField(); |
|
| 59 | - mainPanel.insert(filterField.asWidget(), 0); |
|
| 60 | - mainPanel.insert(composeButtonPanel(), 1); |
|
| 61 | - configureColumns(); |
|
| 63 | + configureDataColumns(); |
|
| 64 | + setButtonsAndFilterOnMainPanel(); |
|
| 62 | 65 | loadDataAndPopulateTable(); |
| 63 | 66 | } |
| 64 | 67 | |
| 68 | + private void setButtonsAndFilterOnMainPanel() { |
|
| 69 | + final HorizontalPanel searchPanel = new HorizontalPanel(); |
|
| 70 | + searchPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); |
|
| 71 | + searchPanel.setSpacing(5); |
|
| 72 | + final Label label = new Label(getStringMessages().filterIpAddresses() + ": "); |
|
| 73 | + searchPanel.add(label); |
|
| 74 | + searchPanel.add(filterField.getTextBox()); |
|
| 75 | + // inserted with indices to put them above the table |
|
| 76 | + mainPanel.insert(searchPanel, 0); |
|
| 77 | + mainPanel.insert(composeButtonPanel(), 1); |
|
| 78 | + mainPanel.setSpacing(5); |
|
| 79 | + } |
|
| 80 | + |
|
| 65 | 81 | private AccessControlledButtonPanel composeButtonPanel() { |
| 66 | 82 | final AccessControlledButtonPanel buttonPanel = new AccessControlledButtonPanel(userService, securedDomainType); |
| 67 | 83 | final Button refreshbutton = buttonPanel.addAction(getStringMessages().refresh(), () -> true, new Command() { |
| ... | ... | @@ -71,25 +87,27 @@ abstract class IPBlocklistTableWrapper |
| 71 | 87 | } |
| 72 | 88 | }); |
| 73 | 89 | refreshbutton.ensureDebugId("refreshButton"); |
| 74 | - final Button unlockbutton = buttonPanel.addAction(getStringMessages().unlock(), () -> true, new Command() { |
|
| 75 | - @Override |
|
| 76 | - public void execute() { |
|
| 77 | - for (IpToTimedLockDTO e : getSelectionModel().getSelectedSet()) { |
|
| 78 | - unlockIP(e.ip, new AsyncCallback<Void>() { |
|
| 79 | - @Override |
|
| 80 | - public void onFailure(Throwable caught) { |
|
| 81 | - errorReporter.reportError(errorMessageOnDataFailureString); |
|
| 82 | - } |
|
| 90 | + final Button unlockButton = new SelectedElementsCountingButton<IpToTimedLockDTO>(getStringMessages().unlock(), |
|
| 91 | + getSelectionModel(), new ClickHandler() { |
|
| 92 | + @Override |
|
| 93 | + public void onClick(ClickEvent event) { |
|
| 94 | + for (IpToTimedLockDTO e : getSelectionModel().getSelectedSet()) { |
|
| 95 | + unlockIP(e.ip, new AsyncCallback<Void>() { |
|
| 96 | + @Override |
|
| 97 | + public void onFailure(Throwable caught) { |
|
| 98 | + errorReporter.reportError(errorMessageOnDataFailureString); |
|
| 99 | + } |
|
| 83 | 100 | |
| 84 | - @Override |
|
| 85 | - public void onSuccess(Void result) { |
|
| 86 | - filterField.remove(e); |
|
| 101 | + @Override |
|
| 102 | + public void onSuccess(Void result) { |
|
| 103 | + filterField.remove(e); |
|
| 104 | + } |
|
| 105 | + }); |
|
| 87 | 106 | } |
| 88 | - }); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - }); |
|
| 92 | - unlockbutton.ensureDebugId("unlockButton"); |
|
| 107 | + } |
|
| 108 | + }); |
|
| 109 | + unlockButton.ensureDebugId("unlockButton"); |
|
| 110 | + buttonPanel.insertWidgetAtPosition(unlockButton, 1); |
|
| 93 | 111 | return buttonPanel; |
| 94 | 112 | } |
| 95 | 113 | |
| ... | ... | @@ -116,7 +134,7 @@ abstract class IPBlocklistTableWrapper |
| 116 | 134 | fetchData(dataInitializationCallback); |
| 117 | 135 | } |
| 118 | 136 | |
| 119 | - private void configureColumns() { |
|
| 137 | + private void configureDataColumns() { |
|
| 120 | 138 | final ListHandler<IpToTimedLockDTO> columnListHandler = getColumnSortHandler(); |
| 121 | 139 | addColumn(record -> record.ip, getStringMessages().ipAddress()); |
| 122 | 140 | final Comparator<IpToTimedLockDTO> expiryComparator = (o1, o2) -> { |
| ... | ... | @@ -133,7 +151,7 @@ abstract class IPBlocklistTableWrapper |
| 133 | 151 | getStringMessages()) { |
| 134 | 152 | @Override |
| 135 | 153 | public Iterable<String> getSearchableStrings(IpToTimedLockDTO dto) { |
| 136 | - List<String> string = new ArrayList<String>(); |
|
| 154 | + final List<String> string = new ArrayList<String>(); |
|
| 137 | 155 | string.add(dto.ip); |
| 138 | 156 | return string; |
| 139 | 157 | } |
| ... | ... | @@ -143,8 +161,6 @@ abstract class IPBlocklistTableWrapper |
| 143 | 161 | return table; |
| 144 | 162 | } |
| 145 | 163 | }; |
| 146 | - final CheckBox filterCheckbox = new CheckBox(getStringMessages().filterIpAddresses()); |
|
| 147 | - filterCheckbox.addValueChangeHandler(checked -> filterField.filter()); |
|
| 148 | 164 | registerSelectionModelOnNewDataProvider(filterField.getAllListDataProvider()); |
| 149 | 165 | return filterField; |
| 150 | 166 | } |
java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/IpToTimedLockDTO.java
| ... | ... | @@ -1,8 +1,9 @@ |
| 1 | 1 | package com.sap.sailing.gwt.ui.adminconsole; |
| 2 | 2 | |
| 3 | 3 | import com.sap.sse.common.TimedLock; |
| 4 | +import com.sap.sse.common.Named; |
|
| 4 | 5 | |
| 5 | -public class IpToTimedLockDTO { |
|
| 6 | +public class IpToTimedLockDTO implements Named { |
|
| 6 | 7 | public final String ip; |
| 7 | 8 | public final TimedLock timedLock; |
| 8 | 9 | |
| ... | ... | @@ -11,4 +12,9 @@ public class IpToTimedLockDTO { |
| 11 | 12 | this.timedLock = timedLock; |
| 12 | 13 | } |
| 13 | 14 | |
| 15 | + @Override |
|
| 16 | + public String getName() { |
|
| 17 | + return "IpToTimedLockDTO"; |
|
| 18 | + } |
|
| 19 | + |
|
| 14 | 20 | } |