diff --git a/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/RolloutView.java b/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/RolloutView.java index 604a3e358..24f34024a 100644 --- a/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/RolloutView.java +++ b/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/RolloutView.java @@ -318,26 +318,8 @@ public class RolloutView extends TableView { description.setMinLength(2); description.setWidthFull(); - actionType = new Select<>(); - actionType.setLabel(Constants.ACTION_TYPE); - actionType.setItems(MgmtActionType.values()); - actionType.setValue(MgmtActionType.FORCED); - final ComponentRenderer actionTypeRenderer = new ComponentRenderer<>(actionTypeO -> - switch (actionTypeO) { - case SOFT -> new Text(Constants.SOFT); - case FORCED -> new Text(Constants.FORCED); - case DOWNLOAD_ONLY -> new Text(Constants.DOWNLOAD_ONLY); - case TIMEFORCED -> forceTime; - }); - actionType.addValueChangeListener(e -> actionType.setRenderer(actionTypeRenderer)); - actionType.setItemLabelGenerator(startTypeO -> - switch (startTypeO) { - case SOFT -> Constants.SOFT; - case FORCED -> Constants.FORCED; - case DOWNLOAD_ONLY -> Constants.DOWNLOAD_ONLY; - case TIMEFORCED -> "Time Forced at " + (forceTime.isEmpty() ? "" : " " + forceTime.getValue()); - }); - actionType.setWidthFull(); + actionType = Utils.actionTypeControls(forceTime); + startType = new Select<>(); startType.setValue(StartType.MANUAL); startType.setLabel(Constants.START_TYPE); diff --git a/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/TargetView.java b/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/TargetView.java index 2d2663d6a..c485f1a87 100644 --- a/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/TargetView.java +++ b/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/TargetView.java @@ -40,7 +40,6 @@ import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.select.Select; -import com.vaadin.flow.component.Text; import com.vaadin.flow.component.textfield.TextArea; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.data.renderer.ComponentRenderer; @@ -370,26 +369,7 @@ public class TargetView extends TableView { distributionSetO.getName() + ":" + distributionSetO.getVersion()); distributionSet.setWidthFull(); - actionType = new Select<>(); - actionType.setLabel(Constants.ACTION_TYPE); - actionType.setItems(MgmtActionType.values()); - actionType.setValue(MgmtActionType.FORCED); - final ComponentRenderer actionTypeRenderer = new ComponentRenderer<>(actionTypeO -> - switch (actionTypeO) { - case SOFT -> new Text(Constants.SOFT); - case FORCED -> new Text(Constants.FORCED); - case DOWNLOAD_ONLY -> new Text(Constants.DOWNLOAD_ONLY); - case TIMEFORCED -> forceTime; - }); - actionType.addValueChangeListener(e -> actionType.setRenderer(actionTypeRenderer)); - actionType.setItemLabelGenerator(startTypeO -> - switch (startTypeO) { - case SOFT -> Constants.SOFT; - case FORCED -> Constants.FORCED; - case DOWNLOAD_ONLY -> Constants.DOWNLOAD_ONLY; - case TIMEFORCED -> "Time Forced at " + (forceTime.isEmpty() ? "" : " " + forceTime.getValue()); - }); - actionType.setWidthFull(); + actionType = Utils.actionTypeControls(forceTime); assign.setEnabled(false); addAssignClickListener(hawkbitClient, selectedTargets); diff --git a/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/util/Utils.java b/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/util/Utils.java index 42990993f..a23521d2d 100644 --- a/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/util/Utils.java +++ b/hawkbit-simple-ui/src/main/java/org/eclipse/hawkbit/ui/simple/view/util/Utils.java @@ -17,12 +17,16 @@ import java.util.concurrent.CompletionStage; import java.util.function.Consumer; import java.util.function.Function; +import org.eclipse.hawkbit.ui.simple.view.Constants; +import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType; + import com.vaadin.flow.component.Component; import com.vaadin.flow.component.HasValue; import com.vaadin.flow.component.Text; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.ButtonVariant; +import com.vaadin.flow.component.datetimepicker.DateTimePicker; import com.vaadin.flow.component.dialog.Dialog; import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.icon.VaadinIcon; @@ -30,9 +34,11 @@ import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.notification.NotificationVariant; import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.select.Select; import com.vaadin.flow.component.shared.Tooltip; import com.vaadin.flow.component.textfield.NumberField; import com.vaadin.flow.component.textfield.TextField; +import com.vaadin.flow.data.renderer.ComponentRenderer; import com.vaadin.flow.data.value.ValueChangeMode; import com.vaadin.flow.theme.lumo.LumoUtility; @@ -148,6 +154,31 @@ public class Utils { return component; } + public static Select actionTypeControls(DateTimePicker forceTime) { + + Select actionType = new Select<>(); + actionType.setLabel(Constants.ACTION_TYPE); + actionType.setItems(MgmtActionType.values()); + actionType.setValue(MgmtActionType.FORCED); + final ComponentRenderer actionTypeRenderer = new ComponentRenderer<>(actionTypeO -> + switch (actionTypeO) { + case SOFT -> new Text(Constants.SOFT); + case FORCED -> new Text(Constants.FORCED); + case DOWNLOAD_ONLY -> new Text(Constants.DOWNLOAD_ONLY); + case TIMEFORCED -> forceTime; + }); + actionType.addValueChangeListener(e -> actionType.setRenderer(actionTypeRenderer)); + actionType.setItemLabelGenerator(startTypeO -> + switch (startTypeO) { + case SOFT -> Constants.SOFT; + case FORCED -> Constants.FORCED; + case DOWNLOAD_ONLY -> Constants.DOWNLOAD_ONLY; + case TIMEFORCED -> "Time Forced at " + (forceTime.isEmpty() ? "" : " " + forceTime.getValue()); + }); + actionType.setWidthFull(); + return actionType; + } + public static class BaseDialog extends Dialog { protected final transient CompletableFuture result = new CompletableFuture<>();