diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/settings/SnapshotDownloadModal.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/settings/SnapshotDownloadModal.java index f64005192a..ba8dd8a681 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/settings/SnapshotDownloadModal.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/settings/SnapshotDownloadModal.java @@ -13,7 +13,6 @@ package org.eclipse.kura.web.client.ui.settings; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Optional; @@ -31,7 +30,7 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; @@ -46,11 +45,6 @@ public class SnapshotDownloadModal extends Composite { private static final String SELECT_ALL_PIDS_SELECTION = "Select All Pids"; private static final String REMOVE_ALL_PIDS_SELECTION = "Remove All Pids"; - private static final List DEFAULT_PID_SELECTION = Arrays.asList("org.eclipse.kura.cloud.CloudService", - "org.eclipse.kura.internal.rest.provider.RestService", - "org.eclipse.kura.net.admin.FirewallConfigurationService", - "org.eclipse.kura.net.admin.NetworkConfigurationService", - "org.eclipse.kura.net.admin.ipv6.FirewallConfigurationServiceIPv6", "org.eclipse.kura.web.Console"); interface SnapshotDownloadModalUiBinder extends UiBinder { } @@ -60,7 +54,7 @@ interface SnapshotDownloadModalUiBinder extends UiBinder snapshotDownloadConsumer; public SnapshotDownloadModal() { @@ -79,16 +78,17 @@ public SnapshotDownloadModal() { initWidget(uiBinder.createAndBindUi(this)); this.pidSelectionScrollPanel.setVisible(false); - this.resetPidSelection.setVisible(false); + this.selectOrRemoveAllAnchor.setVisible(false); this.noPidSelectedError.setVisible(false); this.noPidSelectedError.setText("Please select at least one pid from the list"); + this.cancelButton.addClickHandler(this::onCancelClick); + } public void show(Consumer consumer) { this.snapshotDownloadConsumer = consumer; this.modal.setTitle(MSGS.deviceWiregraphDownloadModalTitle()); - this.downloadModalDescription.setText(MSGS.deviceWiregraphDownloadModalHint()); initWiregraphDownloadButtons(); this.modal.show(); } @@ -99,25 +99,47 @@ public void show(Consumer consumer, List availa this.modal.setTitle(MSGS.deviceSnapshotDownloadModalTitle()); this.downloadModalDescription.setText(MSGS.deviceSnapshotDownloadModalHint()); initSnapshotPidList(availablePids); + initSnapshotSelectAllAnchor(); initSnapshotScrollPanel(); initSnapshotDownloadButtons(); - initSnapshotResetAnchor(); this.modal.show(); } - private void initWiregraphDownloadButtons() { + /* + * Snapshot Download Inits + */ - this.downloadJson.addClickHandler(e -> { - this.modal.hide(); - this.snapshotDownloadConsumer.accept(new SnapshotDownloadOptions("JSON")); - }); + private void initSnapshotPidList(List snapshotConfigs) { - this.downloadXml.addClickHandler(e -> { - this.modal.hide(); - this.snapshotDownloadConsumer.accept(new SnapshotDownloadOptions("XML")); + this.pidPanel.clear(); + + List orderedPids = snapshotConfigs.stream().sorted().collect(Collectors.toList()); + orderedPids.forEach(pid -> { + CheckBox box = new CheckBox(pid); + box.setValue(true); + box.addClickHandler(this::onCheckboxClick); + this.pidPanel.add(box); }); } + private void initSnapshotSelectAllAnchor() { + if (this.anchorClickHandler != null) { + this.anchorClickHandler.removeHandler(); + } + this.areAllPidsSelected = true; + this.selectOrRemoveAllAnchor.setText(REMOVE_ALL_PIDS_SELECTION); + this.anchorClickHandler = this.selectOrRemoveAllAnchor.addClickHandler(this::selectOrRemoveAllSelection); + this.selectOrRemoveAllAnchor.setVisible(true); + } + + private void initSnapshotScrollPanel() { + this.pidSelectionScrollPanel.setAlwaysShowScrollBars(false); + this.pidSelectionScrollPanel.setHeight("350px"); + this.pidSelectionScrollPanel.clear(); + this.pidSelectionScrollPanel.add(pidPanel); + this.pidSelectionScrollPanel.setVisible(true); + } + private void initSnapshotDownloadButtons() { this.downloadJson.addClickHandler(e -> { if (isOnePidSelected()) { @@ -141,68 +163,41 @@ private void initSnapshotDownloadButtons() { }); } - private void initSnapshotResetAnchor() { - this.resetPidSelection.addClickHandler(event -> { + /* + * Wiregraph Snapshot Download Inits + */ - pidPanel.iterator().forEachRemaining(widget -> { - CheckBox checkBox = (CheckBox) widget; - checkBox.setValue(DEFAULT_PID_SELECTION.contains(checkBox.getText())); - }); - }); - } - - private void initSnapshotPidList(List snapshotConfigs) { - - this.pidPanel.clear(); + private void initWiregraphDownloadButtons() { - List orderedPids = snapshotConfigs.stream().sorted().collect(Collectors.toList()); - orderedPids.forEach(pid -> { - CheckBox box = new CheckBox(pid); - box.addClickHandler(this::hideErrorMessageOnSelection); - this.pidPanel.add(box); + this.downloadJson.addClickHandler(e -> { + this.modal.hide(); + this.snapshotDownloadConsumer.accept(new SnapshotDownloadOptions("JSON")); }); - CheckBox allChannelsButton = new CheckBox(SELECT_ALL_PIDS_SELECTION); - allChannelsButton.addValueChangeHandler(this::selectOrRemoveAllSelection); - allChannelsButton.addClickHandler(this::hideErrorMessageOnSelection); - this.pidPanel.insert(allChannelsButton, 0); - + this.downloadXml.addClickHandler(e -> { + this.modal.hide(); + this.snapshotDownloadConsumer.accept(new SnapshotDownloadOptions("XML")); + }); } - private void hideErrorMessageOnSelection(ClickEvent handler) { + /* + * Utils + */ + + private void onCheckboxClick(ClickEvent handler) { if (noPidSelectedError.isVisible()) { noPidSelectedError.setVisible(false); } - } - - private void selectOrRemoveAllSelection(ValueChangeEvent event) { - Iterator widgetIterator = pidPanel.iterator(); - - widgetIterator.forEachRemaining(widget -> { - - CheckBox checkBox = (CheckBox) widget; - checkBox.setValue(event.getValue()); - if (checkBox.getText().equals(SELECT_ALL_PIDS_SELECTION) - || checkBox.getText().equals(REMOVE_ALL_PIDS_SELECTION)) { + checkAllPidsSelected(); + updateSelectOrRemoveAllText(); - if (event.getValue().booleanValue()) { - checkBox.setText(REMOVE_ALL_PIDS_SELECTION); - } else { - checkBox.setText(SELECT_ALL_PIDS_SELECTION); - } - } - }); } - private void initSnapshotScrollPanel() { - this.pidSelectionScrollPanel.setAlwaysShowScrollBars(false); - this.pidSelectionScrollPanel.setHeight("350px"); - this.pidSelectionScrollPanel.clear(); - this.pidSelectionScrollPanel.add(pidPanel); - this.pidSelectionScrollPanel.setVisible(true); - - this.resetPidSelection.setVisible(true); + private void onCancelClick(ClickEvent handler) { + this.modal.hide(); + resetScrollPanel(); + this.noPidSelectedError.setVisible(false); } private Optional> getSelectedPids() { @@ -218,6 +213,12 @@ private Optional> getSelectedPids() { return selectedPids.isEmpty() ? Optional.empty() : Optional.of(selectedPids); } + private void selectOrRemoveAllSelection(ClickEvent handler) { + pidPanel.iterator().forEachRemaining(widget -> ((CheckBox) widget).setValue(!this.areAllPidsSelected)); + this.areAllPidsSelected = !this.areAllPidsSelected; + updateSelectOrRemoveAllText(); + } + private boolean isOnePidSelected() { boolean result = false; Iterator pidPanelIterator = this.pidPanel.iterator(); @@ -232,6 +233,26 @@ private boolean isOnePidSelected() { return result; } + private void checkAllPidsSelected() { + boolean areAllSelected = true; + Iterator pidPanelIterator = this.pidPanel.iterator(); + while (pidPanelIterator.hasNext()) { + if (!((CheckBox) pidPanelIterator.next()).getValue().booleanValue()) { + areAllSelected = false; + break; + } + } + this.areAllPidsSelected = areAllSelected; + } + + private void updateSelectOrRemoveAllText() { + if (this.areAllPidsSelected) { + this.selectOrRemoveAllAnchor.setText(REMOVE_ALL_PIDS_SELECTION); + } else { + this.selectOrRemoveAllAnchor.setText(SELECT_ALL_PIDS_SELECTION); + } + } + private void resetScrollPanel() { this.pidSelectionScrollPanel.setVerticalScrollPosition(0); this.pidSelectionScrollPanel.setHorizontalScrollPosition(0); diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/settings/SnapshotDownloadModal.ui.xml b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/settings/SnapshotDownloadModal.ui.xml index 64468e9a0b..e1e1a21347 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/settings/SnapshotDownloadModal.ui.xml +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/settings/SnapshotDownloadModal.ui.xml @@ -42,10 +42,11 @@ - + - + + diff --git a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties index 24b6853e58..7efef07770 100644 --- a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties +++ b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties @@ -307,13 +307,11 @@ deviceSnapshotId=Snapshot Id deviceSnapshotCreatedOn=Created On deviceSnapshotsNone=No Snapshots Available deviceSnapshotRollbackConfirm=Are you sure you want to rollback to a previous configuration? During the rollback operation, the device will disconnect and reconnect. If a timeout is encountered during the reload of the device configuration, please refresh it manually. -deviceSnapshotDownloadModalTitle=Download snapshot -deviceWiregraphDownloadModalTitle=Download wiregraph -deviceSnapshotDownloadModalHint=Chose the format and which service configurations will be included in the downloaded snapshot. -deviceWiregraphDownloadModalHint=Chose in which format the wiregraph will be downloaded. +deviceSnapshotDownloadModalTitle=Snapshot download +deviceWiregraphDownloadModalTitle=Wiregraph snapshot download +deviceSnapshotDownloadModalHint=Select pids of the service configurations that will be included in the downloaded snapshot. downloadSnapshotXmlButton=Download as XML downloadSnapshotJsonButton=Download as JSON -downloadSnapshotResetSelection=Reset selection to default netIntro=Select a Network Interface and configure it. DHCP Server and NAT can be configured only for interfaces enabled for LAN usage. When applying your changes, your connection to the gateway may be lost depending on your network configuration changes. netInterfaceName=Interface Name