From dc18bfea7b6aaf956e33418cc321a9216bde3bab Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 6 Apr 2016 17:42:02 +0200 Subject: [PATCH 01/49] Refactoring Table, TableHeader and Detail Layout components - Add interfaces to reduce boiler plate code - Add generic to reuse code - Try to remove duplicate code Signed-off-by: SirWayne --- .../ui/artifacts/UploadArtifactView.java | 6 +- .../details/ArtifactDetailsLayout.java | 26 ++- .../artifacts/event/SoftwareModuleEvent.java | 41 ++--- .../footer/SMDeleteActionsLayout.java | 32 +--- .../UploadViewConfirmationWindowLayout.java | 82 ++------- .../SoftwareModuleAddUpdateWindow.java | 9 +- .../smtable/SoftwareModuleDetails.java | 96 ++--------- .../smtable/SoftwareModuleTable.java | 160 ++++-------------- .../smtable/SoftwareModuleTableHeader.java | 7 +- .../artifacts/state/ArtifactUploadState.java | 49 +++--- .../ui/common/ManagmentEntityState.java | 22 +++ .../AbstractConfirmationWindowLayout.java | 55 +++--- ...amedVersionedEntityTableDetailsLayout.java | 28 +++ .../AbstractTableDetailsLayout.java | 96 ++++++----- .../SoftwareModuleDetailsTable.java | 7 +- .../footer/AbstractDeleteActionsLayout.java | 109 ++++++------ .../ui/common/table/AbstractTable.java | 158 +++++++++++++++-- .../ui/common/table/BaseEntityEvent.java | 44 +++++ .../ui/common/table/BaseEntityEventType.java | 17 ++ .../common/tagdetails/AbstractTagToken.java | 28 ++- .../tagdetails/AbstractTargetTagToken.java | 5 +- .../tagdetails/DistributionTagToken.java | 34 +--- .../ui/common/tagdetails/TargetTagToken.java | 20 +-- .../ui/distributions/DistributionsView.java | 11 +- .../dstable/DistributionSetDetails.java | 131 ++++---------- .../dstable/DistributionSetTable.java | 158 +++++------------ .../dstable/DistributionSetTableHeader.java | 6 +- .../footer/DSDeleteActionsLayout.java | 32 +--- ...DistributionsConfirmationWindowLayout.java | 134 +++------------ .../smtable/SwModuleDetails.java | 91 ++-------- .../distributions/smtable/SwModuleTable.java | 137 +++++---------- .../smtable/SwModuleTableHeader.java | 7 +- .../state/ManageDistUIState.java | 16 +- .../hawkbit/ui/management/DeploymentView.java | 10 +- .../actionhistory/ActionHistoryComponent.java | 6 +- .../actionhistory/ActionHistoryTable.java | 8 +- .../DistributionAddUpdateWindowLayout.java | 7 +- .../dstable/DistributionDetails.java | 89 +--------- .../management/dstable/DistributionTable.java | 113 +++++-------- .../dstable/DistributionTableHeader.java | 6 +- .../event/DistributionTableEvent.java | 46 ++--- .../event/TargetAddUpdateWindowEvent.java | 33 +--- .../ui/management/event/TargetTableEvent.java | 64 +++---- .../management/footer/CountMessageLabel.java | 4 +- .../footer/DeleteActionsLayout.java | 7 +- .../ManangementConfirmationWindowLayout.java | 107 +++--------- .../management/state/ManagementUIState.java | 14 +- .../TargetAddUpdateWindowLayout.java | 7 +- .../management/targettable/TargetDetails.java | 91 +++------- .../management/targettable/TargetTable.java | 126 ++++---------- .../targettable/TargetTableHeader.java | 9 +- .../targettag/TargetTagFilterButtons.java | 3 +- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 77 +-------- 53 files changed, 934 insertions(+), 1747 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java index 54ba5cc8e..b07aa0276 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java @@ -15,12 +15,12 @@ import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout; import org.eclipse.hawkbit.ui.artifacts.event.ArtifactDetailsEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.footer.SMDeleteActionsLayout; import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleTableLayout; import org.eclipse.hawkbit.ui.artifacts.smtype.SMTypeFilterLayout; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.upload.UploadLayout; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -111,9 +111,9 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { - if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeSwTable(); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeSwTable(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java index 1bc9da65c..7c5d4153f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java @@ -24,6 +24,7 @@ import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.ConfirmationDialog; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIButton; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; @@ -110,8 +111,6 @@ public class ArtifactDetailsLayout extends VerticalLayout { private boolean fullWindowMode = false; - private UI ui; - private boolean readOnly = false; /** @@ -122,7 +121,6 @@ public class ArtifactDetailsLayout extends VerticalLayout { createComponents(); buildLayout(); eventBus.subscribe(this); - ui = UI.getCurrent(); if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); populateArtifactDetails(selectedSoftwareModule.getId(), HawkbitCommonUtil @@ -461,23 +459,23 @@ public class ArtifactDetailsLayout extends VerticalLayout { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent softwareModuleEvent) { - if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE) { - ui.access(() -> { - if (softwareModuleEvent.getSoftwareModule() != null) { - populateArtifactDetails(softwareModuleEvent.getSoftwareModule().getId(), - HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getSoftwareModule().getName(), - softwareModuleEvent.getSoftwareModule().getVersion())); + if (BaseEntityEventType.SELECTED_ENTITY == softwareModuleEvent.getEventType()) { + UI.getCurrent().access(() -> { + if (softwareModuleEvent.getEntity() != null) { + populateArtifactDetails(softwareModuleEvent.getEntity().getId(), + HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getEntity().getName(), + softwareModuleEvent.getEntity().getVersion())); } else { populateArtifactDetails(null, null); } }); } if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.ARTIFACTS_CHANGED) { - ui.access(() -> { - if (softwareModuleEvent.getSoftwareModule() != null) { - populateArtifactDetails(softwareModuleEvent.getSoftwareModule().getId(), - HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getSoftwareModule().getName(), - softwareModuleEvent.getSoftwareModule().getVersion())); + UI.getCurrent().access(() -> { + if (softwareModuleEvent.getEntity() != null) { + populateArtifactDetails(softwareModuleEvent.getEntity().getId(), + HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getEntity().getName(), + softwareModuleEvent.getEntity().getVersion())); } else { populateArtifactDetails(null, null); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java index 3d0897dcd..95770cb8f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java @@ -9,58 +9,53 @@ package org.eclipse.hawkbit.ui.artifacts.event; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; /** * Event to represent software add, update or delete. - * - * * */ -public class SoftwareModuleEvent { +public class SoftwareModuleEvent extends BaseEntityEvent { /** * Software module events in the Upload UI. - * - * * */ public enum SoftwareModuleEventType { - NEW_SOFTWARE_MODULE, UPDATED_SOFTWARE_MODULE, DELETE_SOFTWARE_MODULE, SELECTED_SOFTWARE_MODULE, MAXIMIZED, MINIMIZED, ARTIFACTS_CHANGED, ASSIGN_SOFTWARE_MODULE + ARTIFACTS_CHANGED, ASSIGN_SOFTWARE_MODULE } private SoftwareModuleEventType softwareModuleEventType; - private SoftwareModule softwareModule; + /** + * Creates software module event. + * + * @param entityEventType + * the event type + * @param softwareModule + * the module + */ + public SoftwareModuleEvent(final BaseEntityEventType entityEventType, final SoftwareModule softwareModule) { + super(entityEventType, softwareModule); + } /** * Creates software module event. * * @param softwareModuleEventType - * reference of {@link SoftwareModuleEventType} + * the event type * @param softwareModule - * reference of {@link SoftwareModule} + * the module */ public SoftwareModuleEvent(final SoftwareModuleEventType softwareModuleEventType, final SoftwareModule softwareModule) { - super(); + super(null, softwareModule); this.softwareModuleEventType = softwareModuleEventType; - this.softwareModule = softwareModule; } public SoftwareModuleEventType getSoftwareModuleEventType() { return softwareModuleEventType; } - public void setSoftwareModuleEventType(final SoftwareModuleEventType softwareModuleEventType) { - this.softwareModuleEventType = softwareModuleEventType; - } - - public SoftwareModule getSoftwareModule() { - return softwareModule; - } - - public void setSoftwareModule(final SoftwareModule softwareModule) { - this.softwareModule = softwareModule; - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java index 97451961c..a5cb5c8d0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java @@ -28,7 +28,6 @@ import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Component; -import com.vaadin.ui.Label; import com.vaadin.ui.Table; import com.vaadin.ui.Table.TableTransferable; import com.vaadin.ui.UI; @@ -191,7 +190,7 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - uploadViewConfirmationWindowLayout.init(); + uploadViewConfirmationWindowLayout.inittialize(); return uploadViewConfirmationWindowLayout; } @@ -201,33 +200,4 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { || !artifactUploadState.getSelectedDeleteSWModuleTypes().isEmpty(); } - @Override - protected boolean hasCountMessage() { - return false; - } - - @Override - protected Label getCountMessageLabel() { - return null; - } - - @Override - protected boolean hasBulkUploadPermission() { - return false; - } - - @Override - protected void showBulkUploadWindow() { - /** - * Bulk upload not supported .No implementation required. - */ - } - - @Override - protected void restoreBulkUploadStatusCount() { - /** - * Bulk upload not supported .No implementation required. - */ - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java index 49e9ab59f..e6284d5d6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java @@ -14,23 +14,17 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.annotation.PostConstruct; - import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.state.CustomFile; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.ConfirmationTab; -import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.data.Container; import com.vaadin.data.Item; @@ -39,8 +33,8 @@ import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Table.Align; -import com.vaadin.ui.themes.ValoTheme; /** * Abstract layout of confirm actions window. @@ -62,32 +56,12 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind private static final String DISCARD = "Discard"; - @Autowired - private I18N i18n; - @Autowired private transient SoftwareManagement softwareManagement; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ArtifactUploadState artifactUploadState; - /** - * Initialze the component. - */ - @PostConstruct - void init() { - super.inittialize(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.confirmwindow.layout. - * AbstractConfirmationWindowLayout# getConfimrationTabs() - */ @Override protected Map getConfimrationTabs() { final Map tabs = new HashMap<>(); @@ -116,26 +90,13 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind // Add the discard action column tab.getTable().addGeneratedColumn(SW_DISCARD_CHGS, (source, itemId, columnId) -> { - final Button deleteswIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + "redicon", true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deleteswIcon.setData(itemId); - deleteswIcon.setImmediate(true); - deleteswIcon.addClickListener(event -> discardSoftwareDelete(event, itemId, tab)); - return deleteswIcon; + final ClickListener clickListener = event -> discardSoftwareDelete(event, itemId, tab); + return createDiscardButton(itemId, clickListener); }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(SW_MODULE_NAME_MSG); - visibleColumnIds.add(SW_DISCARD_CHGS); - visibleColumnLabels.add(i18n.get("upload.swModuleTable.header")); - visibleColumnLabels.add(i18n.get("header.second.deletetarget.table")); - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(SW_MODULE_NAME_MSG, SW_DISCARD_CHGS); + tab.getTable().setColumnHeaders(i18n.get("upload.swModuleTable.header"), + i18n.get("header.second.deletetarget.table")); tab.getTable().setColumnExpandRatio(SW_MODULE_NAME_MSG, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -233,30 +194,14 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind // Add the discard action column tab.getTable().addGeneratedColumn(DISCARD, (source, itemId, columnId) -> { - final StringBuilder style = new StringBuilder(ValoTheme.BUTTON_TINY); - style.append(' '); - style.append("redicon"); - final Button deleteIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - style.toString(), true, FontAwesome.REPLY, SPUIButtonStyleSmallNoBorder.class); - deleteIcon.setData(itemId); - deleteIcon.setImmediate(true); - deleteIcon.addClickListener(event -> discardSoftwareTypeDelete( - (String) ((Button) event.getComponent()).getData(), itemId, tab)); - return deleteIcon; + final ClickListener clickListener = event -> discardSoftwareTypeDelete( + (String) ((Button) event.getComponent()).getData(), itemId, tab); + return createDiscardButton(itemId, clickListener); }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(SW_MODULE_TYPE_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.first.delete.swmodule.type.table")); - visibleColumnLabels.add(i18n.get("header.second.delete.swmodule.type.table")); - - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(SW_MODULE_TYPE_NAME, DISCARD); + tab.getTable().setColumnHeaders(i18n.get("header.first.delete.swmodule.type.table"), + i18n.get("header.second.delete.swmodule.type.table")); tab.getTable().setColumnExpandRatio(SW_MODULE_TYPE_NAME, 2); tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -264,9 +209,6 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind return tab; } - /** - * @return - */ private Container getSWModuleTypeTableContainer() { final IndexedContainer contactContainer = new IndexedContainer(); contactContainer.addContainerProperty(SW_MODULE_TYPE_NAME, String.class, ""); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index 7e05e8c63..cc08929bb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -13,8 +13,8 @@ import java.io.Serializable; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -282,8 +282,8 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { /* display success message */ uiNotifcation.displaySuccess(i18n.get("message.save.success", new Object[] { newBaseSoftwareModule.getName() + ":" + newBaseSoftwareModule.getVersion() })); - eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.NEW_SOFTWARE_MODULE, - newBaseSoftwareModule)); + eventBus.publish(this, + new SoftwareModuleEvent(BaseEntityEventType.NEW_ENTITY, newBaseSoftwareModule)); } // close the window closeThisWindow(); @@ -302,8 +302,7 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { uiNotifcation.displaySuccess(i18n.get("message.save.success", new Object[] { newSWModule.getName() + ":" + newSWModule.getVersion() })); - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.UPDATED_SOFTWARE_MODULE, newSWModule)); + eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.UPDATED_ENTITY, newSWModule)); } closeThisWindow(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java index dc6035089..397f0cf2b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java @@ -10,9 +10,8 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; -import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; +import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -36,7 +35,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class SoftwareModuleDetails extends AbstractTableDetailsLayout { +public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDetailsLayout { private static final long serialVersionUID = -4900381301076646366L; @@ -46,10 +45,6 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { @Autowired private ArtifactUploadState artifactUploadState; - private Long swModuleId; - - private SoftwareModule selectedSwModule; - @Override protected String getEditButtonId() { return SPUIComponetIdProvider.UPLOAD_SW_MODULE_EDIT_BUTTON; @@ -64,21 +59,24 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { @Override protected void onEdit(final ClickEvent event) { - final Window addSoftwareModule = softwareModuleAddUpdateWindow.createUpdateSoftwareModuleWindow(swModuleId); + final Window addSoftwareModule = softwareModuleAddUpdateWindow + .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId()); addSoftwareModule.setCaption(i18n.get("upload.caption.update.swmodule")); UI.getCurrent().addWindow(addSoftwareModule); addSoftwareModule.setVisible(Boolean.TRUE); } - private void populateDetails(final SoftwareModule swModule) { + @Override + protected void populateDetailsWidget() { String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY; - if (swModule != null) { - if (swModule.getType().getMaxAssignments() == Integer.MAX_VALUE) { + if (selectedBaseEntity != null) { + if (selectedBaseEntity.getType().getMaxAssignments() == Integer.MAX_VALUE) { maxAssign = i18n.get("label.multiAssign.type"); } else { maxAssign = i18n.get("label.singleAssign.type"); } - updateSoftwareModuleDetailsLayout(swModule.getType().getName(), swModule.getVendor(), maxAssign); + updateSoftwareModuleDetailsLayout(selectedBaseEntity.getType().getName(), selectedBaseEntity.getVendor(), + maxAssign); } else { updateSoftwareModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY, maxAssign); @@ -109,45 +107,6 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { } - private void populateLog(final SoftwareModule softwareModule) { - if (null != softwareModule) { - updateLogLayout(getLogLayout(), softwareModule.getLastModifiedAt(), softwareModule.getLastModifiedBy(), - softwareModule.getCreatedAt(), softwareModule.getCreatedBy(), i18n); - } else { - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - } - } - - public void setSwModuleId(final Long swModuleId) { - this.swModuleId = swModuleId; - } - - private void populateDetailsWidget(final SoftwareModule swModule) { - if (swModule != null) { - setSwModuleId(swModule.getId()); - setName(getDefaultCaption(), - HawkbitCommonUtil.getFormattedNameVersion(swModule.getName(), swModule.getVersion())); - populateDetails(swModule); - populateDescription(swModule); - populateLog(swModule); - } else { - setSwModuleId(null); - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); - populateDetails(null); - populateDescription(null); - populateLog(null); - } - } - - private void populateDescription(final SoftwareModule swModule) { - if (swModule != null) { - updateDescriptionLayout(i18n.get("label.description"), swModule.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } - } - - @Override protected String getDefaultCaption() { return i18n.get("upload.swModuleTable.header"); @@ -158,45 +117,14 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { return artifactUploadState.getSelectedBaseSoftwareModule().isPresent(); } - @Override protected Boolean onLoadIsTableMaximized() { return artifactUploadState.isSwModuleTableMaximized(); } - - @Override - protected void populateDetailsWidget() { - populateDetailsWidget(selectedSwModule); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent softwareModuleEvent) { - if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE - || softwareModuleEvent - .getSoftwareModuleEventType() == SoftwareModuleEventType.UPDATED_SOFTWARE_MODULE) { - ui.access(() -> { - /** - * softwareModuleEvent.getSoftwareModule() is null when table - * has no data. - */ - if (softwareModuleEvent.getSoftwareModule() != null) { - selectedSwModule = softwareModuleEvent.getSoftwareModule(); - populateData(true); - } else { - populateData(false); - } - }); - } else if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { - showLayout(); - } else if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { - hideLayout(); - } - } - - @Override - protected void clearDetails() { - populateDetailsWidget(null); + onBaseEntityEvent(softwareModuleEvent); } @Override @@ -204,7 +132,6 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { return permissionChecker.hasUpdateDistributionPermission(); } - @Override protected String getTabSheetId() { return null; @@ -214,4 +141,5 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { protected String getDetailsHeaderCaptionId() { return SPUIComponetIdProvider.TARGET_DETAILS_HEADER_LABEL_ID; } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index aea80476a..6164fa3bf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -8,29 +8,20 @@ */ package org.eclipse.hawkbit.ui.artifacts.smtable; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -39,7 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -58,45 +48,19 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class SoftwareModuleTable extends AbstractTable { +public class SoftwareModuleTable extends AbstractTable { private static final long serialVersionUID = 6469417305487144809L; - @Autowired - private I18N i18n; - @Autowired private ArtifactUploadState artifactUploadState; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient SoftwareManagement softwareManagement; @Autowired private UploadViewAcceptCriteria uploadViewAcceptCriteria; - /** - * Initialize the filter layout. - */ - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - setNoDataAvailable(); - } - - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SMFilterEvent filterEvent) { UI.getCurrent().access(() -> { @@ -150,74 +114,40 @@ public class SoftwareModuleTable extends AbstractTable { lqc.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); } - @Override - protected void addCustomGeneratedColumns() { - /* No generated columns */ - } - @Override protected boolean isFirstRowSelectedOnLoad() { return artifactUploadState.getSelectedSoftwareModules().isEmpty(); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.table.SPTable#getItemIdToSelect() - */ @Override protected Object getItemIdToSelect() { return artifactUploadState.getSelectedSoftwareModules(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.table.SPTable#isMaximized() - */ @Override protected boolean isMaximized() { return artifactUploadState.isSwModuleTableMaximized(); } - @SuppressWarnings("rawtypes") @Override - protected void onValueChange() { - eventBus.publish(this, UploadArtifactUIEvent.HIDE_DROP_HINTS); - @SuppressWarnings("unchecked") - final Set values = (Set) getValue(); - if (values != null && !values.isEmpty()) { - final Iterator iterator = values.iterator(); - Long value = null; - while (iterator.hasNext()) { - value = iterator.next(); - } - if (null != value) { - artifactUploadState.setSelectedBaseSwModuleId(value); - final SoftwareModule baseSoftwareModule = softwareManagement.findSoftwareModuleById(value); - artifactUploadState.setSelectedBaseSoftwareModule(baseSoftwareModule); - artifactUploadState.setSelectedSoftwareModules(values); - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE, baseSoftwareModule)); - } - } else { - artifactUploadState.setSelectedBaseSwModuleId(null); - artifactUploadState.setSelectedBaseSoftwareModule(null); - artifactUploadState.setSelectedSoftwareModules(Collections.emptySet()); - eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE, null)); - } + protected SoftwareModule findEntityByTableValue(final Long entityTableId) { + return softwareManagement.findSoftwareModuleById(entityTableId); + } + + @Override + protected ArtifactUploadState getManagmentEntityState() { + return artifactUploadState; + } + + @Override + protected void publishEntityAfterValueChange(final SoftwareModule lastSoftwareModule) { + artifactUploadState.setSelectedBaseSoftwareModule(lastSoftwareModule); + eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.SELECTED_ENTITY, lastSoftwareModule)); } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { - if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.NEW_SOFTWARE_MODULE) { - UI.getCurrent().access(() -> addSoftwareModule(event.getSoftwareModule())); - } + onBaseEntityEvent(event); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -227,51 +157,30 @@ public class SoftwareModuleTable extends AbstractTable { } } - /** - * Add new software module to table. - * - * @param swModule - * new software module - */ @SuppressWarnings("unchecked") - private void addSoftwareModule(final SoftwareModule swModule) { - final Object addItem = addItem(); - final Item item = getItem(addItem); - final String swNameVersion = HawkbitCommonUtil.concatStrings(":", swModule.getName(), swModule.getVersion()); + @Override + protected Item addEntity(final SoftwareModule baseEntity) { + final Item item = super.addEntity(baseEntity); + + final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), + baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); - item.getItemProperty("swId").setValue(swModule.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(swModule.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(swModule.getDescription()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(swModule.getVersion()); - item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(swModule.getName()); - item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(swModule.getVendor()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY).setValue(swModule.getCreatedBy()); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setValue(swModule.getLastModifiedBy()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(swModule.getCreatedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(swModule.getLastModifiedAt())); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); if (!artifactUploadState.getSelectedSoftwareModules().isEmpty()) { - artifactUploadState.getSelectedSoftwareModules().stream().forEach(swmNameId -> unselect(swmNameId)); + artifactUploadState.getSelectedSoftwareModules().stream().forEach(this::unselect); } - select(swModule.getId()); + select(baseEntity.getId()); + return item; + } @Override protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); + final List columnList = super.getTableVisibleColumns(); if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); } else { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); @@ -297,12 +206,9 @@ public class SoftwareModuleTable extends AbstractTable { }; } - private void setNoDataAvailable() { - final int containerSize = getContainerDataSource().size(); - if (containerSize == 0) { - artifactUploadState.setNoDataAvilableSoftwareModule(true); - } else { - artifactUploadState.setNoDataAvilableSoftwareModule(false); - } + @Override + protected void setDataAvailable(final boolean available) { + artifactUploadState.setNoDataAvilableSoftwareModule(!available); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java index 5f1c56636..16ef3154c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java @@ -10,10 +10,10 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -51,7 +51,6 @@ public class SoftwareModuleTableHeader extends AbstractTableHeader { } } - @Override protected String getHeaderCaption() { return i18n.get("upload.swModuleTable.header"); @@ -131,14 +130,14 @@ public class SoftwareModuleTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { artifactUploadState.setSwModuleTableMaximized(Boolean.TRUE); - eventbus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.MAXIMIZED, null)); + eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MAXIMIZED, null)); } @Override public void minimizeTable() { artifactUploadState.setSwModuleTableMaximized(Boolean.FALSE); - eventbus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.MINIMIZED, null)); + eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MINIMIZED, null)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java index a502b341c..b975ad1fd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java @@ -17,6 +17,7 @@ import java.util.Optional; import java.util.Set; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -29,7 +30,7 @@ import com.vaadin.spring.annotation.VaadinSessionScope; */ @VaadinSessionScope @SpringComponent -public class ArtifactUploadState implements Serializable { +public class ArtifactUploadState implements ManagmentEntityState, Serializable { private static final long serialVersionUID = 8273440375917450859L; @@ -88,29 +89,6 @@ public class ArtifactUploadState implements Serializable { return selectedBaseSwModuleId != null ? Optional.of(selectedBaseSwModuleId) : Optional.empty(); } - /** - * @param selectedBaseSwModuleId - * the selectedBaseSwModuleId to set - */ - public void setSelectedBaseSwModuleId(final Long selectedBaseSwModuleId) { - this.selectedBaseSwModuleId = selectedBaseSwModuleId; - } - - /** - * @return the selectedBaseSoftwareModule - */ - public Optional getSelectedBaseSoftwareModule() { - return selectedBaseSoftwareModule == null ? Optional.empty() : Optional.of(selectedBaseSoftwareModule); - } - - /** - * @param selectedBaseSoftwareModule - * the selectedBaseSoftwareModule to set - */ - public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) { - this.selectedBaseSoftwareModule = selectedBaseSoftwareModule; - } - /** * @return the baseSwModuleList */ @@ -125,12 +103,15 @@ public class ArtifactUploadState implements Serializable { return selectedSoftwareModules; } - /** - * @param selectedSoftwareModules - * the selectedSoftwareModules to set - */ - public void setSelectedSoftwareModules(final Set selectedSoftwareModules) { - this.selectedSoftwareModules = selectedSoftwareModules; + @Override + public void setLastSelectedEntity(final Long value) { + this.selectedBaseSwModuleId = value; + + } + + @Override + public void setSelectedEnitities(final Set values) { + this.selectedSoftwareModules = values; } /** @@ -197,4 +178,12 @@ public class ArtifactUploadState implements Serializable { this.noDataAvilableSoftwareModule = noDataAvilableSoftwareModule; } + public Optional getSelectedBaseSoftwareModule() { + return selectedBaseSoftwareModule == null ? Optional.empty() : Optional.of(selectedBaseSoftwareModule); + } + + public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) { + this.selectedBaseSoftwareModule = selectedBaseSoftwareModule; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java new file mode 100644 index 000000000..8b2318ace --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.common; + +import java.util.Set; + +/** + * + */ +public interface ManagmentEntityState { + + void setSelectedEnitities(Set values); + + void setLastSelectedEntity(T value); + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java index 8a89ee821..a737fabbf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java @@ -11,21 +11,29 @@ package org.eclipse.hawkbit.ui.common.confirmwindow.layout; import java.util.Map; import java.util.Map.Entry; -import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import javax.annotation.PostConstruct; +import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; +import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; + +import com.vaadin.server.FontAwesome; import com.vaadin.ui.Accordion; import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.ValoTheme; /** * Abstract layout of confirm actions window. * - * - * - * */ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { @@ -37,33 +45,25 @@ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { private String consolidatedMessage; - protected void inittialize() { - // Remove all components + @Autowired + protected I18N i18n; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + + @PostConstruct + public void inittialize() { removeAllComponents(); consolidatedMessage = ""; - - // create components again createComponents(); - - // Build layout. buildLayout(); } - /** - * Create accordion and add respective tabs. - */ private void createComponents() { - // create accordion createAccordian(); - - // create action message label createActionMessgaeLabel(); } - /** - * Create a message label to show the results of any actions which user does - * in the confirmation window. - */ private void createActionMessgaeLabel() { actionMessage = SPUIComponentProvider.getLabel("", null); actionMessage.addStyleName(SPUIStyleDefinitions.CONFIRM_WINDOW_INFO_BOX); @@ -138,4 +138,15 @@ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { public String getConsolidatedMessage() { return consolidatedMessage; } + + protected Button createDiscardButton(final Object itemId, final ClickListener clickListener) { + final Button deletesDsIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, + ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, + SPUIButtonStyleSmallNoBorder.class); + deletesDsIcon.setData(itemId); + deletesDsIcon.setImmediate(true); + deletesDsIcon.addClickListener(clickListener); + return deletesDsIcon; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java new file mode 100644 index 000000000..31fbe5996 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.common.detailslayout; + +import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; + +/** + * + * + */ +public abstract class AbstractNamedVersionedEntityTableDetailsLayout + extends AbstractTableDetailsLayout { + + private static final long serialVersionUID = 1L; + + @Override + protected String getName() { + return HawkbitCommonUtil.getFormattedNameVersion(selectedBaseEntity.getName(), selectedBaseEntity.getVersion()); + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 20a107ba6..02b1f0044 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -13,8 +13,12 @@ import java.util.Map; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; +import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -40,7 +44,7 @@ import com.vaadin.ui.VerticalLayout; * * */ -public abstract class AbstractTableDetailsLayout extends VerticalLayout { +public abstract class AbstractTableDetailsLayout extends VerticalLayout { private static final long serialVersionUID = 4862529368471627190L; @@ -53,7 +57,7 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { @Autowired protected SpPermissionChecker permissionChecker; - protected UI ui; + protected T selectedBaseEntity; private Label caption; @@ -74,13 +78,8 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { */ @PostConstruct protected void init() { - ui = UI.getCurrent(); createComponents(); buildLayout(); - /** - * On load of UI/Refresh details will be loaded based on the row - * selected in table. - */ restoreState(); eventBus.subscribe(this); } @@ -90,6 +89,18 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { eventBus.unsubscribe(this); } + protected void onBaseEntityEvent(final BaseEntityEvent baseEntityEvent) { + final BaseEntityEventType eventType = baseEntityEvent.getEventType(); + if (BaseEntityEventType.SELECTED_ENTITY == eventType + || BaseEntityEventType.UPDATED_ENTITY == eventType) { + UI.getCurrent().access(() -> populateData(baseEntityEvent.getEntity())); + } else if (BaseEntityEventType.MINIMIZED == eventType) { + UI.getCurrent().access(() -> setVisible(true)); + } else if (BaseEntityEventType.MAXIMIZED == eventType) { + UI.getCurrent().access(() -> setVisible(false)); + } + } + private void createComponents() { /** * Default caption is set.Reset on selecting table row. @@ -156,44 +167,29 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { private void restoreState() { if (onLoadIsTableRowSelected()) { - populateData(true); + populateData(null); + editButton.setEnabled(true); } if (onLoadIsTableMaximized()) { - /** - * If table is maximized hide details layout. - */ - hideLayout(); + setVisible(false); } } - protected void showLayout() { - setVisible(true); - } - - protected void hideLayout() { - setVisible(false); - } - /** * If no data in table (i,e no row selected),then disable the edit button. * If row is selected ,enable edit button. */ - protected void populateData(final Boolean isRowSelected) { - if (isRowSelected) { - populateDetailsWidget(); - enableEditButton(); + private void populateData(final T selectedBaseEntity) { + this.selectedBaseEntity = selectedBaseEntity; + editButton.setEnabled(selectedBaseEntity != null); + if (selectedBaseEntity == null) { + setName(getDefaultCaption(), StringUtils.EMPTY); } else { - disableEditButton(); - clearDetails(); + setName(getDefaultCaption(), getName()); } - } - - protected void enableEditButton() { - editButton.setEnabled(true); - } - - protected void disableEditButton() { - editButton.setEnabled(false); + populateLog(); + populateDescription(); + populateDetailsWidget(); } protected void updateLogLayout(final VerticalLayout changeLogLayout, final Long lastModifiedAt, @@ -297,13 +293,6 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { protected abstract String getTabSheetId(); - /** - * Populate details layout. - */ - protected abstract void populateDetailsWidget(); - - protected abstract void clearDetails(); - protected abstract Boolean hasEditPermission(); public VerticalLayout getDetailsLayout() { @@ -314,6 +303,31 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { return logLayout; } + private void populateLog() { + if (selectedBaseEntity == null) { + updateLogLayout(getLogLayout(), null, StringUtils.EMPTY, null, null, i18n); + return; + } + updateLogLayout(getLogLayout(), selectedBaseEntity.getLastModifiedAt(), selectedBaseEntity.getLastModifiedBy(), + selectedBaseEntity.getCreatedAt(), selectedBaseEntity.getCreatedBy(), i18n); + } + + private void populateDescription() { + if (selectedBaseEntity != null) { + updateDescriptionLayout(i18n.get("label.description"), selectedBaseEntity.getDescription()); + } else { + updateDescriptionLayout(i18n.get("label.description"), null); + } + } + + protected abstract void populateDetailsWidget(); + + protected Long getSelectedBaseEntityId() { + return selectedBaseEntity == null ? null : selectedBaseEntity.getId(); + } + protected abstract String getDetailsHeaderCaptionId(); + protected abstract String getName(); + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java index 40acb6581..c0ecf9869 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java @@ -16,12 +16,12 @@ import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; @@ -214,9 +214,8 @@ public class SoftwareModuleDetailsTable extends Table { .getItem(event.getButton().getId()).getItemProperty(SOFT_MODULE).getValue(), alreadyAssignedSwModules); final DistributionSet newDistributionSet = distributionSetManagement.unassignSoftwareModule(distributionSet, unAssignedSw); - manageDistUIState.setLastSelectedDistribution(newDistributionSet.getDistributionSetIdName()); - eventBus.publish(this, - new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, newDistributionSet)); + manageDistUIState.setLastSelectedEntity(newDistributionSet.getDistributionSetIdName()); + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, newDistributionSet)); eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION); uiNotification.displaySuccess(i18n.get("message.sw.unassigned", unAssignedSw.getName())); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index f3b8b72e7..0f5e2de32 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -182,40 +182,45 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme } protected void setUploadStatusButtonCaption(final Long count) { - if (null != bulkUploadStatusButton) { - bulkUploadStatusButton.setCaption("
" + count + "
"); + if (bulkUploadStatusButton == null) { + return; } + bulkUploadStatusButton.setCaption("
" + count + "
"); } protected void enableBulkUploadStatusButton() { - if (null != bulkUploadStatusButton) { - bulkUploadStatusButton.setVisible(true); + if (bulkUploadStatusButton == null) { + return; } + bulkUploadStatusButton.setVisible(true); } protected void updateUploadBtnIconToComplete() { - if (null != bulkUploadStatusButton) { - bulkUploadStatusButton.removeStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); - bulkUploadStatusButton.setIcon(FontAwesome.UPLOAD); + if (bulkUploadStatusButton == null) { + return; } + bulkUploadStatusButton.removeStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); + bulkUploadStatusButton.setIcon(FontAwesome.UPLOAD); } protected void updateUploadBtnIconToProgressIndicator() { - if (null != bulkUploadStatusButton) { - bulkUploadStatusButton.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); - bulkUploadStatusButton.setIcon(null); + if (bulkUploadStatusButton == null) { + return; } + bulkUploadStatusButton.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); + bulkUploadStatusButton.setIcon(null); } protected void actionButtonClicked() { - if (hasUnsavedActions()) { - unsavedActionsWindow = SPUIComponentProvider.getWindow(getUnsavedActionsWindowCaption(), - SPUIComponetIdProvider.SAVE_ACTIONS_POPUP, SPUIDefinitions.CONFIRMATION_WINDOW); - unsavedActionsWindow.addCloseListener(event -> unsavedActionsWindowClosed()); - unsavedActionsWindow.setContent(getUnsavedActionsWindowContent()); - unsavedActionsWindow.setId(SPUIComponetIdProvider.CONFIRMATION_POPUP_ID); - UI.getCurrent().addWindow(unsavedActionsWindow); + if (!hasUnsavedActions()) { + return; } + unsavedActionsWindow = SPUIComponentProvider.getWindow(getUnsavedActionsWindowCaption(), + SPUIComponetIdProvider.SAVE_ACTIONS_POPUP, SPUIDefinitions.CONFIRMATION_WINDOW); + unsavedActionsWindow.addCloseListener(event -> unsavedActionsWindowClosed()); + unsavedActionsWindow.setContent(getUnsavedActionsWindowContent()); + unsavedActionsWindow.setId(SPUIComponetIdProvider.CONFIRMATION_POPUP_ID); + UI.getCurrent().addWindow(unsavedActionsWindow); } /** @@ -225,22 +230,11 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme UI.getCurrent().removeWindow(unsavedActionsWindow); } - /* - * (non-Javadoc) - * - * @see com.vaadin.event.dd.DropHandler#getAcceptCriterion() - */ @Override public AcceptCriterion getAcceptCriterion() { return getDeleteLayoutAcceptCriteria(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.event.dd.DropHandler#drop(com.vaadin.event.dd. - * DragAndDropEvent) - */ @Override public void drop(final DragAndDropEvent event) { processDroppedComponent(event); @@ -287,6 +281,43 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme } } + /** + * Only in deployment view count message is displayed. + * + * @return + */ + protected boolean hasCountMessage() { + return false; + } + + /** + * + * @return the count message label + */ + protected Label getCountMessageLabel() { + return null; + } + + /** + * @return true if bulk upload is allowed and has required create + * permissions. + */ + protected boolean hasBulkUploadPermission() { + // can be overriden + return false; + } + + protected void showBulkUploadWindow() { + // can be overriden + } + + /** + * restore the upload status count. + */ + protected void restoreBulkUploadStatusCount() { + // can be overriden + } + /** * Check user has delete permission. * @@ -362,11 +393,6 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme */ protected abstract void restoreActionCount(); - /** - * restore the upload status count. - */ - protected abstract void restoreBulkUploadStatusCount(); - /** * This method will be called when unsaved actions window is closed. */ @@ -387,21 +413,4 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme */ protected abstract boolean hasUnsavedActions(); - /** - * Only in deployment view count message is displayed. - * - * @return - */ - protected abstract boolean hasCountMessage(); - - protected abstract Label getCountMessageLabel(); - - /** - * @return true if bulk upload is allowed and has required create - * permissions. - */ - protected abstract boolean hasBulkUploadPermission(); - - protected abstract void showBulkUploadWindow(); - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index ae6811ddb..c9487d467 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -9,29 +9,59 @@ package org.eclipse.hawkbit.ui.common.table; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Set; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.TableColumn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; +import com.google.gwt.thirdparty.guava.common.collect.Iterables; import com.vaadin.data.Container; +import com.vaadin.data.Item; import com.vaadin.event.dd.DropHandler; import com.vaadin.ui.Table; +import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; /** - * Parent class for table. - * - * + * Abstract table to handling entity * + * @param + * e is the entity class + * @param + * i is the id of the table */ -public abstract class AbstractTable extends Table { +public abstract class AbstractTable extends Table { private static final long serialVersionUID = 4856562746502217630L; + private static final Logger LOG = LoggerFactory.getLogger(AbstractTable.class); + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + + @Autowired + protected I18N i18n; + /** * Initialize the components. */ + @PostConstruct protected void init() { setStyleName("sp-table"); setSizeFull(); @@ -48,6 +78,52 @@ public abstract class AbstractTable extends Table { addValueChangeListener(event -> onValueChange()); selectRow(); setPageLength(SPUIDefinitions.PAGE_SIZE); + + setDataAvailable(getContainerDataSource().size() != 0); + eventBus.subscribe(this); + } + + @PreDestroy + protected void destroy() { + eventBus.unsubscribe(this); + } + + public static Set getTableValue(final Table table) { + @SuppressWarnings("unchecked") + Set values = (Set) table.getValue(); + if (values == null) { + values = Collections.emptySet(); + } + if (values.remove(null)) { + LOG.warn("Null values in table content. How could this happen?"); + } + return values; + } + + private void onValueChange() { + eventBus.publish(this, UploadArtifactUIEvent.HIDE_DROP_HINTS); + + // TODO Einzelwerte? + + final Set values = getTableValue(this); + + E entity = null; + + final I lastId = Iterables.getLast(values); + if (lastId != null) { + entity = findEntityByTableValue(lastId); + } + setManagementEntitiyStateValues(values, lastId); + publishEntityAfterValueChange(entity); + } + + protected void setManagementEntitiyStateValues(final Set values, final I lastId) { + final ManagmentEntityState managmentEntityState = getManagmentEntityState(); + if (managmentEntityState == null) { + return; + } + managmentEntityState.setLastSelectedEntity(lastId); + managmentEntityState.setSelectedEnitities(values); } private void setDefault() { @@ -118,6 +194,51 @@ public abstract class AbstractTable extends Table { selectRow(); } + /** + * Add new software module to table. + * + * @param baseEntity + * new software module + */ + protected Item addEntity(final E baseEntity) { + final Object addItem = addItem(); + final Item item = getItem(addItem); + updateEntity(baseEntity, item); + return item; + } + + @SuppressWarnings("unchecked") + protected void updateEntity(final E baseEntity, final Item item) { + item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(baseEntity.getName()); + item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(baseEntity.getId()); + item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(baseEntity.getDescription()); + item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY) + .setValue(HawkbitCommonUtil.getIMUser(baseEntity.getCreatedBy())); + item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) + .setValue(HawkbitCommonUtil.getIMUser(baseEntity.getLastModifiedBy())); + item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) + .setValue(SPDateTimeUtil.getFormattedDate(baseEntity.getCreatedAt())); + item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) + .setValue(SPDateTimeUtil.getFormattedDate(baseEntity.getLastModifiedAt())); + + } + + protected void onBaseEntityEvent(final BaseEntityEvent event) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { + UI.getCurrent().access(() -> applyMinTableSettings()); + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { + UI.getCurrent().access(() -> applyMaxTableSettings()); + } else if (BaseEntityEventType.NEW_ENTITY == event.getEventType()) { + UI.getCurrent().access(() -> addEntity(event.getEntity())); + } + } + + protected abstract E findEntityByTableValue(I lastSelectedId); + + protected abstract void publishEntityAfterValueChange(E selectedLastEntity); + + protected abstract ManagmentEntityState getManagmentEntityState(); + /** * Get Id of the table. * @@ -141,7 +262,9 @@ public abstract class AbstractTable extends Table { /** * Add any generated columns if required. */ - protected abstract void addCustomGeneratedColumns(); + protected void addCustomGeneratedColumns() { + // can be overriden + } /** * Check if first row should be selected by default on load. @@ -157,11 +280,6 @@ public abstract class AbstractTable extends Table { */ protected abstract Object getItemIdToSelect(); - /** - * On select of row. - */ - protected abstract void onValueChange(); - /** * Check if the table is maximized or minimized. * @@ -174,7 +292,23 @@ public abstract class AbstractTable extends Table { * * @return List list of visible columns */ - protected abstract List getTableVisibleColumns(); + protected List getTableVisibleColumns() { + final List columnList = new ArrayList<>(); + if (isMaximized()) { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); + columnList + .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); + columnList.add( + new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), + 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); + } else { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); + } + return columnList; + } /** * Get drop handler for the table. @@ -183,4 +317,6 @@ public abstract class AbstractTable extends Table { */ protected abstract DropHandler getTableDropHandler(); + protected abstract void setDataAvailable(boolean available); + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java new file mode 100644 index 000000000..b0b7551ac --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.common.table; + +import org.eclipse.hawkbit.repository.model.BaseEntity; + +/** + * Event to represent add, update or delete. + * + */ +public class BaseEntityEvent { + + private final BaseEntityEventType eventType; + + private final T entity; + + /** + * Base entity event + * + * @param eventType + * the event type + * @param entity + * the entity reference + */ + public BaseEntityEvent(final BaseEntityEventType eventType, final T entity) { + this.eventType = eventType; + this.entity = entity; + } + + public T getEntity() { + return entity; + } + + public BaseEntityEventType getEventType() { + return eventType; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java new file mode 100644 index 000000000..bfaf593fb --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.common.table; + +/** + * + * + */ +public enum BaseEntityEventType { + NEW_ENTITY, UPDATED_ENTITY, DELETE_ENTITY, SELECTED_ENTITY, MAXIMIZED, MINIMIZED; +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java index 4404e1f8a..30aeba925 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java @@ -17,6 +17,9 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -35,6 +38,7 @@ import com.vaadin.server.FontAwesome; import com.vaadin.shared.ui.combobox.FilteringMode; import com.vaadin.ui.Button; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; /** @@ -44,7 +48,7 @@ import com.vaadin.ui.themes.ValoTheme; * * */ -public abstract class AbstractTagToken implements Serializable { +public abstract class AbstractTagToken implements Serializable { private static final String COLOR_PROPERTY = "color"; @@ -59,7 +63,7 @@ public abstract class AbstractTagToken implements Serializable { protected final Map tokensAdded = new HashMap<>(); protected CssLayout tokenLayout = new CssLayout(); - + @Autowired protected SpPermissionChecker checker; @@ -71,23 +75,37 @@ public abstract class AbstractTagToken implements Serializable { @Autowired protected transient EventBus.SessionEventBus eventBus; - + @Autowired protected ManagementUIState managementUIState; + protected T selectedEntity; + @PostConstruct protected void init() { createTokenField(); checkIfTagAssignedIsAllowed(); eventBus.subscribe(this); } - @PreDestroy - void destroy() { + protected void destroy() { eventBus.unsubscribe(this); } + protected void onBaseEntityEvent(final BaseEntityEvent baseEntityEvent) { + if (BaseEntityEventType.SELECTED_ENTITY != baseEntityEvent.getEventType()) { + return; + } + UI.getCurrent().access(() -> { + final T entity = baseEntityEvent.getEntity(); + if (entity != null) { + selectedEntity = entity; + repopulateToken(); + } + }); + } + private void createTokenField() { final Container tokenContainer = createContainer(); tokenField = createTokenField(tokenContainer); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index c38a97228..ce9f101f3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.TargetTag; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -19,15 +20,13 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; /** * Abstract class for target tag token layout. */ -public abstract class AbstractTargetTagToken extends AbstractTagToken { +public abstract class AbstractTargetTagToken extends AbstractTagToken { private static final long serialVersionUID = 7772876588903171201L; @Autowired protected transient TagManagement tagManagement; - - @EventBusListenerMethod(scope = EventScope.SESSION) void onEventTargetTagCreated(final TargetTagCreatedBulkEvent event) { for (final TargetTag tag : event.getEntities()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index 9a245229b..178610c23 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -14,8 +14,6 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; @@ -26,7 +24,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +33,6 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.data.Item; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.UI; /** * Implementation of target/ds tag token layout. @@ -44,7 +40,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionTagToken extends AbstractTagToken { +public class DistributionTagToken extends AbstractTagToken { private static final long serialVersionUID = -8022738301736043396L; @Autowired @@ -53,8 +49,6 @@ public class DistributionTagToken extends AbstractTagToken { @Autowired private transient DistributionSetManagement distributionSetManagement; - private DistributionSet selectedDS; - // To Be Done : have to set this value based on view??? private static final Boolean NOTAGS_SELECTED = Boolean.FALSE; @@ -82,9 +76,9 @@ public class DistributionTagToken extends AbstractTagToken { private DistributionSetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final Set distributionList = new HashSet<>(); - distributionList.add(selectedDS.getId()); - final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, - tagNameSelected); + distributionList.add(selectedEntity.getId()); + final DistributionSetTagAssignmentResult result = distributionSetManagement + .toggleTagAssignment(distributionList, tagNameSelected); uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; } @@ -117,8 +111,8 @@ public class DistributionTagToken extends AbstractTagToken { @Override public void displayAlreadyAssignedTags() { removePreviouslyAddedTokens(); - if (selectedDS != null) { - for (final DistributionSetTag tag : selectedDS.getTags()) { + if (selectedEntity != null) { + for (final DistributionSetTag tag : selectedEntity.getTags()) { addNewToken(tag.getId()); } } @@ -134,15 +128,7 @@ public class DistributionTagToken extends AbstractTagToken { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent distributionTableEvent) { - if (distributionTableEvent.getDistributionComponentEvent() != DistributionComponentEvent.ON_VALUE_CHANGE) { - return; - } - UI.getCurrent().access(() -> { - if (distributionTableEvent.getDistributionSet() != null) { - selectedDS = distributionTableEvent.getDistributionSet(); - repopulateToken(); - } - }); + onBaseEntityEvent(distributionTableEvent); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -202,10 +188,4 @@ public class DistributionTagToken extends AbstractTagToken { return false; } - @Override - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index 376e7d905..6f03c5860 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +31,6 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.data.Item; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.UI; /** * Implementation of Target tag token. @@ -41,7 +39,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class TargetTagToken extends AbstractTargetTagToken { +public class TargetTagToken extends AbstractTargetTagToken { private static final long serialVersionUID = 7124887018280196721L; @@ -54,8 +52,6 @@ public class TargetTagToken extends AbstractTargetTagToken { @Autowired private transient TargetManagement targetManagement; - private Target selectedTarget; - @Override protected String getTagStyleName() { return "target-tag-"; @@ -80,7 +76,7 @@ public class TargetTagToken extends AbstractTargetTagToken { private TargetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final Set targetList = new HashSet<>(); - targetList.add(selectedTarget.getControllerId()); + targetList.add(selectedEntity.getControllerId()); final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected); uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; @@ -114,8 +110,8 @@ public class TargetTagToken extends AbstractTargetTagToken { @Override protected void displayAlreadyAssignedTags() { removePreviouslyAddedTokens(); - if (selectedTarget != null) { - for (final TargetTag tag : selectedTarget.getTags()) { + if (selectedEntity != null) { + for (final TargetTag tag : selectedEntity.getTags()) { addNewToken(tag.getId()); } } @@ -174,13 +170,7 @@ public class TargetTagToken extends AbstractTargetTagToken { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent targetTableEvent) { - if (targetTableEvent.getTargetComponentEvent() == TargetComponentEvent.SELECTED_TARGET - && targetTableEvent.getTarget() != null) { - UI.getCurrent().access(() -> { - selectedTarget = targetTableEvent.getTarget(); - repopulateToken(); - }); - } + onBaseEntityEvent(targetTableEvent); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java index 451a16ea7..ab41bc579 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java @@ -13,7 +13,7 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.disttype.DSTypeFilterLayout; import org.eclipse.hawkbit.ui.distributions.dstable.DistributionSetTableLayout; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; @@ -22,7 +22,6 @@ import org.eclipse.hawkbit.ui.distributions.smtable.SwModuleTableLayout; import org.eclipse.hawkbit.ui.distributions.smtype.DistSMTypeFilterLayout; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.UINotification; @@ -160,18 +159,18 @@ public class DistributionsView extends VerticalLayout implements View, BrowserWi @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent event) { - if (event.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeDistTable(); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeDistTable(); } } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { - if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeSwTable(); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeSwTable(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index 02916ae7c..64a9819bb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -21,7 +21,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; -import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; +import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.common.detailslayout.SoftwareModuleDetailsTable; import org.eclipse.hawkbit.ui.common.tagdetails.DistributionTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -31,7 +31,6 @@ import org.eclipse.hawkbit.ui.distributions.event.SoftwareModuleAssignmentDiscar import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.dstable.DistributionAddUpdateWindowLayout; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -58,7 +57,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class DistributionSetDetails extends AbstractTableDetailsLayout { +public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDetailsLayout { private static final long serialVersionUID = -4595004466943546669L; @@ -85,10 +84,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { private VerticalLayout tagsLayout; - private DistributionSet selectedDsModule; - - private Long dsId; - Map assignedSWModule = new HashMap<>(); /** @@ -106,28 +101,15 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { return tagsLayout; } - private void populateDetailsWidget(final DistributionSet ds) { - if (ds != null) { - setDsId(ds.getId()); - setName(getDefaultCaption(), HawkbitCommonUtil.getFormattedNameVersion(ds.getName(), ds.getVersion())); - populateDetails(ds); - populateDescription(ds); - populateLog(ds); - populteModule(ds); - populateTags(ds); - } else { - setDsId(null); - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); - populateDetails(null); - populateDescription(null); - populteModule(null); - populateTags(null); - populateLog(null); - } + @Override + protected void populateDetailsWidget() { + populateDetails(); + populateModule(); + populateTags(); } - private void populteModule(final DistributionSet distributionSet) { - softwareModuleTable.populateModule(distributionSet); + private void populateModule() { + softwareModuleTable.populateModule(selectedBaseEntity); showUnsavedAssignment(); } @@ -159,7 +141,7 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { assignedSWModule.put(softwareModule.getType().getName(), new StringBuilder().append("").append( getUnsavedAssigedSwModule(softwareModule.getName(), softwareModule.getVersion())) - .append("")); + .append("")); } } @@ -243,38 +225,22 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { return softwareLayout; } - private void populateTags(final DistributionSet ds) { + private void populateTags() { tagsLayout.removeAllComponents(); - if (null != ds) { + if (null != selectedBaseEntity) { tagsLayout.addComponent(distributionTagToken.getTokenField()); } } - private void populateLog(final DistributionSet ds) { - if (null != ds) { - updateLogLayout(getLogLayout(), ds.getLastModifiedAt(), ds.getLastModifiedBy(), ds.getCreatedAt(), - ds.getCreatedBy(), i18n); - } else { - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - } - } - - private void populateDetails(final DistributionSet ds) { - if (ds != null) { - updateDistributionSetDetailsLayout(ds.getType().getName(), ds.isRequiredMigrationStep()); + private void populateDetails() { + if (selectedBaseEntity != null) { + updateDistributionSetDetailsLayout(selectedBaseEntity.getType().getName(), + selectedBaseEntity.isRequiredMigrationStep()); } else { updateDistributionSetDetailsLayout(null, null); } } - private void populateDescription(final DistributionSet ds) { - if (ds != null) { - updateDescriptionLayout(i18n.get("label.description"), ds.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } - } - private void updateDistributionSetDetailsLayout(final String type, final Boolean isMigrationRequired) { final VerticalLayout detailsTabLayout = getDetailsLayout(); detailsTabLayout.removeAllComponents(); @@ -293,18 +259,10 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { } } - public Long getDsId() { - return dsId; - } - - public void setDsId(final Long dsId) { - this.dsId = dsId; - } - @Override protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); - distributionAddUpdateWindowLayout.populateValuesOfDistribution(getDsId()); + distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId()); newDistWindow.setCaption(i18n.get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); @@ -326,11 +284,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { return manageDistUIState.isDsTableMaximized(); } - @Override - protected void populateDetailsWidget() { - populateDetailsWidget(selectedDsModule); - } - @Override protected String getDefaultCaption() { return i18n.get("distribution.details.header"); @@ -345,11 +298,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); } - @Override - protected void clearDetails() { - populateDetailsWidget(null); - } - @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateDistributionPermission(); @@ -358,59 +306,40 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.ASSIGN_SOFTWARE_MODULE) { - ui.access(() -> updateSoftwareModule(event.getSoftwareModule())); + UI.getCurrent().access(() -> updateSoftwareModule(event.getEntity())); } } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent distributionTableEvent) { - if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.ON_VALUE_CHANGE - || distributionTableEvent - .getDistributionComponentEvent() == DistributionComponentEvent.EDIT_DISTRIBUTION) { - assignedSWModule.clear(); - ui.access(() -> { - /** - * distributionTableEvent.getDistributionSet() is null when - * table has no data. - */ - if (distributionTableEvent.getDistributionSet() != null) { - selectedDsModule = distributionTableEvent.getDistributionSet(); - populateData(true); - } else { - populateData(false); - } - }); - } else if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { - ui.access(() -> showLayout()); - } else if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { - ui.access(() -> hideLayout()); - } + onBaseEntityEvent(distributionTableEvent); } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleAssignmentDiscardEvent softwareModuleAssignmentDiscardEvent) { if (softwareModuleAssignmentDiscardEvent.getDistributionSetIdName() != null) { - ui.access(() -> { + UI.getCurrent().access(() -> { final DistributionSetIdName distIdName = softwareModuleAssignmentDiscardEvent .getDistributionSetIdName(); - if (distIdName.getId().equals(selectedDsModule.getId()) - && distIdName.getName().equals(selectedDsModule.getName())) { - selectedDsModule = distributionSetManagement - .findDistributionSetByIdWithDetails(selectedDsModule.getId()); - populteModule(selectedDsModule); + if (distIdName.getId().equals(getSelectedBaseEntityId()) + && distIdName.getName().equals(selectedBaseEntity.getName())) { + selectedBaseEntity = distributionSetManagement + .findDistributionSetByIdWithDetails(getSelectedBaseEntityId()); + populateModule(); } }); } } - + @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SaveActionWindowEvent saveActionWindowEvent) { if ((saveActionWindowEvent == SaveActionWindowEvent.SAVED_ASSIGNMENTS || saveActionWindowEvent == SaveActionWindowEvent.DISCARD_ALL_ASSIGNMENTS) - && selectedDsModule != null) { + && selectedBaseEntity != null) { assignedSWModule.clear(); - selectedDsModule = distributionSetManagement.findDistributionSetByIdWithDetails(selectedDsModule.getId()); - ui.access(() -> populteModule(selectedDsModule)); + selectedBaseEntity = distributionSetManagement + .findDistributionSetByIdWithDetails(getSelectedBaseEntityId()); + UI.getCurrent().access(() -> populateModule()); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 8d22f6782..51f30117a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -12,15 +12,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; @@ -33,17 +29,15 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -56,7 +50,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -77,7 +70,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionSetTable extends AbstractTable { +public class DistributionSetTable extends AbstractTable { private static final long serialVersionUID = -7731776093470487988L; @@ -86,18 +79,12 @@ public class DistributionSetTable extends AbstractTable { private static final List DISPLAY_DROP_HINT_EVENTS = new ArrayList<>( Arrays.asList(DragEvent.SOFTWAREMODULE_DRAG)); - @Autowired - private I18N i18n; - @Autowired private SpPermissionChecker permissionChecker; @Autowired private ManageDistUIState manageDistUIState; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient DistributionSetManagement distributionSetManagement; @@ -117,12 +104,9 @@ public class DistributionSetTable extends AbstractTable { * Initialize the component. */ @Override - @PostConstruct protected void init() { super.init(); addTableStyleGenerator(); - setNoDataAvailable(); - eventBus.subscribe(this); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -171,13 +155,6 @@ public class DistributionSetTable extends AbstractTable { Boolean.class, null, false, true); } - @Override - protected void addCustomGeneratedColumns() { - /** - * No generated columns. - */ - } - @Override protected boolean isFirstRowSelectedOnLoad() { return !manageDistUIState.getSelectedDistributions().isPresent() @@ -193,37 +170,19 @@ public class DistributionSetTable extends AbstractTable { } @Override - protected void onValueChange() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - @SuppressWarnings("unchecked") - final Set values = (Set) getValue(); - DistributionSetIdName value = null; - if (values != null && !values.isEmpty()) { - final Iterator iterator = values.iterator(); + protected DistributionSet findEntityByTableValue(final DistributionSetIdName entityTableId) { + return distributionSetManagement.findDistributionSetByIdWithDetails(entityTableId.getId()); + } - while (iterator.hasNext()) { - value = iterator.next(); - } - /** - * Adding null check to make to avoid NPE.Its weird that at times - * getValue returns null. - */ - if (null != value) { - manageDistUIState.setSelectedDistributions(values); - manageDistUIState.setLastSelectedDistribution(value); + @Override + protected ManageDistUIState getManagmentEntityState() { + return manageDistUIState; + } - final DistributionSet lastSelectedDistSet = distributionSetManagement - .findDistributionSetByIdWithDetails(value.getId()); - eventBus.publish(this, - new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, lastSelectedDistSet)); - } - } else { - manageDistUIState.setSelectedDistributions(null); - manageDistUIState.setLastSelectedDistribution(null); - eventBus.publish(this, new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, null)); - } + @Override + protected void publishEntityAfterValueChange(final DistributionSet distributionSet) { + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, distributionSet)); eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION); - } @Override @@ -233,7 +192,13 @@ public class DistributionSetTable extends AbstractTable { @Override protected List getTableVisibleColumns() { - return HawkbitCommonUtil.getTableVisibleColumns(isMaximized(), false, i18n); + final List columnList = super.getTableVisibleColumns(); + if (isMaximized()) { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); + } else { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2f)); + } + return columnList; } @Override @@ -331,10 +296,6 @@ public class DistributionSetTable extends AbstractTable { updateDropedDetails(distributionSetIdName, softwareModules); } - /** - * @param distId - * @param softwareModule - */ private void publishAssignEvent(final Long distId, final SoftwareModule softwareModule) { if (manageDistUIState.getLastSelectedDistribution().isPresent() && manageDistUIState.getLastSelectedDistribution().get().getId().equals(distId)) { @@ -343,11 +304,6 @@ public class DistributionSetTable extends AbstractTable { } } - /** - * @param map - * @param softwareModule - * @param softwareModuleIdName - */ private void handleFirmwareCase(final Map> map, final SoftwareModule softwareModule, final SoftwareModuleIdName softwareModuleIdName) { if (softwareModule.getType().getMaxAssignments() == 1) { @@ -361,11 +317,6 @@ public class DistributionSetTable extends AbstractTable { } } - /** - * @param map - * @param softwareModule - * @param softwareModuleIdName - */ private void handleSoftwareCase(final Map> map, final SoftwareModule softwareModule, final SoftwareModuleIdName softwareModuleIdName) { if (softwareModule.getType().getMaxAssignments() == Integer.MAX_VALUE) { @@ -475,37 +426,6 @@ public class DistributionSetTable extends AbstractTable { return true; } - /** - * Add new software module to table. - * - * @param swModule - * new software module - */ - @SuppressWarnings("unchecked") - private void addDistributionSet(final DistributionSet distributionSet) { - final Object addItem = addItem(); - final Item item = getItem(addItem); - - item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(distributionSet.getName()); - item.getItemProperty(SPUILabelDefinitions.DIST_ID).setValue(distributionSet.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(distributionSet.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(distributionSet.getDescription()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(distributionSet.getVersion()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY) - .setValue(HawkbitCommonUtil.getIMUser(distributionSet.getCreatedBy())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) - .setValue(HawkbitCommonUtil.getIMUser(distributionSet.getLastModifiedBy())); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_IS_DISTRIBUTION_COMPLETE).setValue(distributionSet.isComplete()); - if (manageDistUIState.getSelectedDistributions().isPresent()) { - manageDistUIState.getSelectedDistributions().get().stream().forEach(dsNameId -> unselect(dsNameId)); - } - select(distributionSet.getDistributionSetIdName()); - } - private void addTableStyleGenerator() { setCellStyleGenerator((source, itemId, propertyId) -> { if (propertyId == null) { @@ -525,13 +445,7 @@ public class DistributionSetTable extends AbstractTable { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent event) { - if (event.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.ADD_DISTRIBUTION) { - UI.getCurrent().access(() -> addDistributionSet(event.getDistributionSet())); - } + onBaseEntityEvent(event); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -556,21 +470,25 @@ public class DistributionSetTable extends AbstractTable { } } - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); + @Override + @SuppressWarnings("unchecked") + protected Item addEntity(final DistributionSet baseEntity) { + final Item item = super.addEntity(baseEntity); + item.getItemProperty(SPUILabelDefinitions.DIST_ID).setValue(baseEntity.getId()); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.VAR_IS_DISTRIBUTION_COMPLETE).setValue(baseEntity.isComplete()); + + if (manageDistUIState.getSelectedDistributions().isPresent()) { + manageDistUIState.getSelectedDistributions().get().stream().forEach(dsNameId -> unselect(dsNameId)); + } + select(baseEntity.getDistributionSetIdName()); + return item; } - private void setNoDataAvailable() { - final int containerSize = getContainerDataSource().size(); - if (containerSize == 0) { - manageDistUIState.setNoDataAvailableDist(true); - } else { - manageDistUIState.setNoDataAvailableDist(false); - } + @Override + protected void setDataAvailable(final boolean available) { + manageDistUIState.setNoDataAvailableDist(!available); + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java index 6ac4a1007..a42563505 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java @@ -9,12 +9,12 @@ package org.eclipse.hawkbit.ui.distributions.dstable; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.dstable.DistributionAddUpdateWindowLayout; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -125,13 +125,13 @@ public class DistributionSetTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { manageDistUIstate.setDsTableMaximized(Boolean.TRUE); - eventbus.publish(this, new DistributionTableEvent(DistributionComponentEvent.MAXIMIZED, null)); + eventbus.publish(this, new DistributionTableEvent(BaseEntityEventType.MAXIMIZED, null)); } @Override public void minimizeTable() { manageDistUIstate.setDsTableMaximized(Boolean.FALSE); - eventbus.publish(this, new DistributionTableEvent(DistributionComponentEvent.MINIMIZED, null)); + eventbus.publish(this, new DistributionTableEvent(BaseEntityEventType.MINIMIZED, null)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index 8b7d2ada0..ea33a2ea3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -37,7 +37,6 @@ import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Component; -import com.vaadin.ui.Label; import com.vaadin.ui.Table; import com.vaadin.ui.Table.TableTransferable; import com.vaadin.ui.UI; @@ -296,7 +295,7 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - distConfirmationWindowLayout.init(); + distConfirmationWindowLayout.inittialize(); return distConfirmationWindowLayout; } @@ -316,35 +315,6 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { return unSavedActionsTables || unSavedActionsTypes; } - @Override - protected boolean hasCountMessage() { - return false; - } - - @Override - protected Label getCountMessageLabel() { - return null; - } - - @Override - protected boolean hasBulkUploadPermission() { - return false; - } - - @Override - protected void showBulkUploadWindow() { - /** - * Bulk upload not supported No implementation required. - */ - } - - @Override - protected void restoreBulkUploadStatusCount() { - /** - * No implementation required.As no bulk upload in Distribution view. - */ - } - private DistributionSetType getCurrentDistributionSetType() { return systemManagement.getTenantMetadata().getDefaultDsType(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java index 2299054f3..a97c5786d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.distributions.footer; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -17,8 +16,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; - import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -32,13 +29,11 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -48,6 +43,7 @@ import com.vaadin.data.util.IndexedContainer; import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Table.Align; import com.vaadin.ui.themes.ValoTheme; @@ -83,12 +79,6 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW private ConfirmationTab assignmnetTab; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient DistributionSetManagement dsManagement; @@ -98,20 +88,6 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW @Autowired private ManageDistUIState manageDistUIState; - /** - * Initialze the component. - */ - @PostConstruct - public void init() { - super.inittialize(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.confirmwindow.layout. - * AbstractConfirmationWindowLayout# getConfimrationTabs() - */ @Override protected Map getConfimrationTabs() { final Map tabs = new HashMap<>(); @@ -161,26 +137,13 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW /* Add the discard action column */ tab.getTable().addGeneratedColumn(SW_DISCARD_CHGS, (source, itemId, columnId) -> { - final Button deleteswIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deleteswIcon.setData(itemId); - deleteswIcon.setImmediate(true); - deleteswIcon.addClickListener(event -> discardSoftwareDelete(event, itemId, tab)); - return deleteswIcon; + final ClickListener clickListener = event -> discardSoftwareDelete(event, itemId, tab); + return createDiscardButton(itemId, clickListener); }); - /* set the visible columns */ - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(SW_MODULE_NAME_MSG); - visibleColumnIds.add(SW_DISCARD_CHGS); - visibleColumnLabels.add(i18n.get("upload.swModuleTable.header")); - visibleColumnLabels.add(i18n.get("header.second.deletetarget.table")); - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(SW_MODULE_NAME_MSG, SW_DISCARD_CHGS); + tab.getTable().setColumnHeaders(i18n.get("upload.swModuleTable.header"), + i18n.get("header.second.deletetarget.table")); tab.getTable().setColumnExpandRatio(SW_MODULE_NAME_MSG, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -295,18 +258,9 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW return deleteIcon; }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(SW_MODULE_TYPE_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.first.delete.swmodule.type.table")); - visibleColumnLabels.add(i18n.get("header.second.delete.swmodule.type.table")); - - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(SW_MODULE_TYPE_NAME, DISCARD); + tab.getTable().setColumnHeaders(i18n.get("header.first.delete.swmodule.type.table"), + i18n.get("header.second.delete.swmodule.type.table")); tab.getTable().setColumnExpandRatio(SW_MODULE_TYPE_NAME, 2); tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -383,26 +337,14 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW /* Add the discard action column */ tab.getTable().addGeneratedColumn(DISCARD, (source, itemId, columnId) -> { - final Button deleteswIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deleteswIcon.setData(itemId); - deleteswIcon.setImmediate(true); - deleteswIcon.addClickListener(event -> discardDistDelete(event, itemId, tab)); - return deleteswIcon; + final ClickListener clickListener = event -> discardDistDelete(event, itemId, tab); + return createDiscardButton(itemId, clickListener); + }); - /* set the visible columns */ - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(DIST_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.one.deletedist.table")); - visibleColumnLabels.add(i18n.get("header.second.deletedist.table")); - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(DIST_NAME, DISCARD); + tab.getTable().setColumnHeaders(i18n.get("header.one.deletedist.table"), + i18n.get("header.second.deletedist.table")); tab.getTable().setColumnExpandRatio(DIST_NAME, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(DISCARD, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -495,30 +437,15 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW // Add the discard action column tab.getTable().addGeneratedColumn(DISCARD, (source, itemId, columnId) -> { - final StringBuilder style = new StringBuilder(ValoTheme.BUTTON_TINY); - style.append(' '); - style.append(SPUIStyleDefinitions.REDICON); - final Button deleteIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - style.toString(), true, FontAwesome.REPLY, SPUIButtonStyleSmallNoBorder.class); - deleteIcon.setData(itemId); - deleteIcon.setImmediate(true); - deleteIcon.addClickListener( - event -> discardDistTypeDelete((String) ((Button) event.getComponent()).getData(), itemId, tab)); - return deleteIcon; + final ClickListener clickListener = event -> discardDistTypeDelete( + (String) ((Button) event.getComponent()).getData(), itemId, tab); + return createDiscardButton(itemId, clickListener); + }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(DIST_SET_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.first.delete.dist.type.table")); - visibleColumnLabels.add(i18n.get("header.second.delete.dist.type.table")); - - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(DIST_SET_NAME, DISCARD); + tab.getTable().setColumnHeaders(i18n.get("header.first.delete.dist.type.table"), + i18n.get("header.second.delete.dist.type.table")); tab.getTable().setColumnExpandRatio(DIST_SET_NAME, 2); tab.getTable().setColumnExpandRatio(DISCARD, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -610,20 +537,9 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW return deleteIcon; }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(DIST_NAME); - visibleColumnIds.add(SOFTWARE_MODULE_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.dist.first.assignment.table")); - visibleColumnLabels.add(i18n.get("header.dist.second.assignment.table")); - visibleColumnLabels.add(i18n.get("header.third.assignment.table")); - - } - assignmnetTab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - assignmnetTab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + assignmnetTab.getTable().setVisibleColumns(DIST_NAME, SOFTWARE_MODULE_NAME, DISCARD); + assignmnetTab.getTable().setColumnHeaders(i18n.get("header.dist.first.assignment.table"), + i18n.get("header.dist.second.assignment.table"), i18n.get("header.third.assignment.table")); assignmnetTab.getTable().setColumnExpandRatio(DIST_NAME, 2); assignmnetTab.getTable().setColumnExpandRatio(SOFTWARE_MODULE_NAME, 2); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java index 7aa7d6f31..e1c39ee89 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java @@ -10,9 +10,8 @@ package org.eclipse.hawkbit.ui.distributions.smtable; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow; -import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; +import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -36,7 +35,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class SwModuleDetails extends AbstractTableDetailsLayout { +public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLayout { private static final long serialVersionUID = -1052279281066089812L; @@ -46,37 +45,15 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { @Autowired private ManageDistUIState manageDistUIState; - private Long swModuleId; - - private SoftwareModule selectedSwModule; - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent softwareModuleEvent) { - if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE - || softwareModuleEvent - .getSoftwareModuleEventType() == SoftwareModuleEventType.UPDATED_SOFTWARE_MODULE) { - ui.access(() -> { - /** - * softwareModuleEvent.getSoftwareModule() is null when table - * has no data. - */ - if (softwareModuleEvent.getSoftwareModule() != null) { - selectedSwModule = softwareModuleEvent.getSoftwareModule(); - populateData(true); - } else { - populateData(false); - } - }); - } else if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { - showLayout(); - } else if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { - hideLayout(); - } + onBaseEntityEvent(softwareModuleEvent); } @Override protected void onEdit(final ClickEvent event) { - final Window addSoftwareModule = softwareModuleAddUpdateWindow.createUpdateSoftwareModuleWindow(swModuleId); + final Window addSoftwareModule = softwareModuleAddUpdateWindow + .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId()); addSoftwareModule.setCaption(i18n.get("upload.caption.update.swmodule")); UI.getCurrent().addWindow(addSoftwareModule); addSoftwareModule.setVisible(Boolean.TRUE); @@ -109,16 +86,6 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { return manageDistUIState.isSwModuleTableMaximized(); } - @Override - protected void populateDetailsWidget() { - populateDetailsWidget(selectedSwModule); - } - - @Override - protected void clearDetails() { - populateDetailsWidget(null); - } - @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateDistributionPermission(); @@ -129,29 +96,22 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { return null; } - private void populateDetails(final SoftwareModule swModule) { + private void populateDetails() { String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY; - if (swModule != null) { - if (swModule.getType().getMaxAssignments() == Integer.MAX_VALUE) { + if (selectedBaseEntity != null) { + if (selectedBaseEntity.getType().getMaxAssignments() == Integer.MAX_VALUE) { maxAssign = i18n.get("label.multiAssign.type"); } else { maxAssign = i18n.get("label.singleAssign.type"); } - updateSwModuleDetailsLayout(swModule.getType().getName(), swModule.getVendor(), maxAssign); + updateSwModuleDetailsLayout(selectedBaseEntity.getType().getName(), selectedBaseEntity.getVendor(), + maxAssign); } else { updateSwModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY, maxAssign); } } - private void populateDescription(final SoftwareModule sw) { - if (sw != null) { - updateDescriptionLayout(i18n.get("label.description"), sw.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } - } - private void updateSwModuleDetailsLayout(final String type, final String vendor, final String maxAssign) { final VerticalLayout detailsTabLayout = getDetailsLayout(); @@ -176,34 +136,9 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { } - private void populateLog(final SoftwareModule softwareModule) { - if (null != softwareModule) { - updateLogLayout(getLogLayout(), softwareModule.getLastModifiedAt(), softwareModule.getLastModifiedBy(), - softwareModule.getCreatedAt(), softwareModule.getCreatedBy(), i18n); - } else { - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - } - } - - public void setSwModuleId(final Long swModuleId) { - this.swModuleId = swModuleId; - } - - private void populateDetailsWidget(final SoftwareModule swModule) { - if (swModule != null) { - setSwModuleId(swModule.getId()); - setName(getDefaultCaption(), - HawkbitCommonUtil.getFormattedNameVersion(swModule.getName(), swModule.getVersion())); - populateDetails(swModule); - populateDescription(swModule); - populateLog(swModule); - } else { - setSwModuleId(null); - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); - populateDetails(null); - populateDescription(null); - populateLog(null); - } + @Override + protected void populateDetailsWidget() { + populateDetails(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index 9218198b9..dac8d2ecf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -9,33 +9,26 @@ package org.eclipse.hawkbit.ui.distributions.smtable; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; -import org.eclipse.hawkbit.ui.distributions.event.DragEvent; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -45,7 +38,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -71,19 +63,13 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class SwModuleTable extends AbstractTable { +public class SwModuleTable extends AbstractTable { private static final long serialVersionUID = 6785314784507424750L; - @Autowired - private I18N i18n; - @Autowired private ManageDistUIState manageDistUIState; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient SoftwareManagement softwareManagement; @@ -97,21 +83,9 @@ public class SwModuleTable extends AbstractTable { * Initialize the filter layout. */ @Override - @PostConstruct protected void init() { super.init(); - eventBus.subscribe(this); styleTableOnDistSelection(); - setNoDataAvailable(); - } - - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); } /* All event Listeners */ @@ -148,13 +122,7 @@ public class SwModuleTable extends AbstractTable { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { - if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.NEW_SOFTWARE_MODULE) { - UI.getCurrent().access(() -> addSoftwareModule(event.getSoftwareModule())); - } + onBaseEntityEvent(event); } @Override @@ -237,52 +205,38 @@ public class SwModuleTable extends AbstractTable { return manageDistUIState.isSwModuleTableMaximized(); } - @SuppressWarnings("rawtypes") @Override - protected void onValueChange() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - @SuppressWarnings("unchecked") - final Set values = (Set) getValue(); - if (values != null && !values.isEmpty()) { - final Iterator iterator = values.iterator(); - Long value = null; - while (iterator.hasNext()) { - value = iterator.next(); - } - if (null != value) { - manageDistUIState.setSelectedBaseSwModuleId(value); - final SoftwareModule baseSoftwareModule = softwareManagement.findSoftwareModuleById(value); - manageDistUIState.setSelectedSoftwareModules(values); - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE, baseSoftwareModule)); - } - } else { - manageDistUIState.setSelectedBaseSwModuleId(null); - manageDistUIState.setSelectedSoftwareModules(Collections.emptySet()); - eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE, null)); - } + protected void publishEntityAfterValueChange(final SoftwareModule selectedLastEntity) { + eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity)); + } + + @Override + protected void setManagementEntitiyStateValues(final Set values, final Long lastId) { + manageDistUIState.setSelectedBaseSwModuleId(lastId); + manageDistUIState.setSelectedSoftwareModules(values); + } + + @Override + protected SoftwareModule findEntityByTableValue(final Long lastSelectedId) { + return softwareManagement.findSoftwareModuleById(lastSelectedId); + } + + @Override + protected ManagmentEntityState getManagmentEntityState() { + return null; } @Override protected List getTableVisibleColumns() { final List columnList = new ArrayList<>(); if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1F)); + columnList.addAll(super.getTableVisibleColumns()); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); } else { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.7F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); columnList.add(new TableColumn(SPUILabelDefinitions.ARTIFACT_ICON, "", 0.1F)); - } return columnList; } @@ -369,30 +323,24 @@ public class SwModuleTable extends AbstractTable { return name + "." + version; } + @Override @SuppressWarnings("unchecked") - private void addSoftwareModule(final SoftwareModule swModule) { - final Object addItem = addItem(); - final Item item = getItem(addItem); - final String swNameVersion = HawkbitCommonUtil.concatStrings(":", swModule.getName(), swModule.getVersion()); - item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); - item.getItemProperty("swId").setValue(swModule.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(swModule.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(swModule.getDescription()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(swModule.getVersion()); - item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(swModule.getName()); - item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(swModule.getVendor()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY).setValue(swModule.getCreatedBy()); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setValue(swModule.getLastModifiedBy()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(swModule.getCreatedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(swModule.getLastModifiedAt())); + protected Item addEntity(final SoftwareModule baseEntity) { + final Item item = super.addEntity(baseEntity); + + final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), + baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); + item.getItemProperty("swId").setValue(baseEntity.getId()); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); + item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).setValue(baseEntity.getType().getColour()); - item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).setValue(swModule.getType().getColour()); if (!manageDistUIState.getSelectedSoftwareModules().isEmpty()) { manageDistUIState.getSelectedSoftwareModules().stream().forEach(swmNameId -> unselect(swmNameId)); } - select(swModule.getId()); + select(baseEntity.getId()); + return item; } private void showArtifactDetailsWindow(final Long itemId, final String nameVersionStr) { @@ -431,13 +379,10 @@ public class SwModuleTable extends AbstractTable { UI.getCurrent().addWindow(atrifactDtlsWindow); } - private void setNoDataAvailable() { - final int conatinerSize = getContainerDataSource().size(); - if (conatinerSize == 0) { - manageDistUIState.setNoDataAvilableSwModule(true); - } else { - manageDistUIState.setNoDataAvilableSwModule(false); - } + @Override + protected void setDataAvailable(final boolean available) { + manageDistUIState.setNoDataAvilableSwModule(!available); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java index badbc1492..e02dffa8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java @@ -10,9 +10,9 @@ package org.eclipse.hawkbit.ui.distributions.smtable; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -37,7 +37,6 @@ public class SwModuleTableHeader extends AbstractTableHeader { private static final long serialVersionUID = 242961845006626297L; - @Autowired private ManageDistUIState manageDistUIState; @@ -123,14 +122,14 @@ public class SwModuleTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { manageDistUIState.setSwModuleTableMaximized(Boolean.TRUE); - eventbus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.MAXIMIZED, null)); + eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MAXIMIZED, null)); } @Override public void minimizeTable() { manageDistUIState.setSwModuleTableMaximized(Boolean.FALSE); - eventbus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.MINIMIZED, null)); + eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MINIMIZED, null)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java index ce31f649b..b3475cb8b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java @@ -18,6 +18,7 @@ import java.util.Set; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -30,7 +31,7 @@ import com.vaadin.spring.annotation.VaadinSessionScope; */ @SpringComponent @VaadinSessionScope -public class ManageDistUIState implements Serializable { +public class ManageDistUIState implements ManagmentEntityState, Serializable { private static final long serialVersionUID = -7569047247017742928L; @@ -111,16 +112,13 @@ public class ManageDistUIState implements Serializable { return lastSelectedDistribution == null ? Optional.empty() : Optional.of(lastSelectedDistribution); } - /** - * @param lastSelectedDistribution - * the lastSelectedDistribution to set - */ - public void setLastSelectedDistribution(final DistributionSetIdName lastSelectedDistribution) { - this.lastSelectedDistribution = lastSelectedDistribution; + @Override + public void setLastSelectedEntity(final DistributionSetIdName value) { + this.lastSelectedDistribution = value; } - public void setSelectedDistributions(final Set slectedDistributions) { - selectedDistributions = slectedDistributions; + public void setSelectedEnitities(final java.util.Set values) { + selectedDistributions = values; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java index 9069858aa..e260a3bf4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java @@ -12,6 +12,7 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.HawkbitUI; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.actionhistory.ActionHistoryComponent; import org.eclipse.hawkbit.ui.management.dstable.DistributionTableLayout; import org.eclipse.hawkbit.ui.management.dstag.DistributionTagLayout; @@ -108,19 +109,18 @@ public class DeploymentView extends VerticalLayout implements View, BrowserWindo @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent event) { - if (event.getDistributionComponentEvent() == DistributionTableEvent.DistributionComponentEvent.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeDistTable(); - } else if (event - .getDistributionComponentEvent() == DistributionTableEvent.DistributionComponentEvent.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeDistTable(); } } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent event) { - if (event.getTargetComponentEvent() == TargetTableEvent.TargetComponentEvent.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeTargetTable(); - } else if (event.getTargetComponentEvent() == TargetTableEvent.TargetComponentEvent.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeTargetTable(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryComponent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryComponent.java index 908c8c18f..25448fbe1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryComponent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryComponent.java @@ -12,8 +12,8 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventBus; @@ -62,9 +62,9 @@ public class ActionHistoryComponent extends VerticalLayout { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent targetUIEvent) { - if (targetUIEvent.getTargetComponentEvent() == TargetComponentEvent.SELECTED_TARGET) { + if (BaseEntityEventType.SELECTED_ENTITY == targetUIEvent.getEventType()) { setData(SPUIDefinitions.DATA_AVAILABLE); - UI.getCurrent().access(() -> populateActionHistoryDetails(targetUIEvent.getTarget())); + UI.getCurrent().access(() -> populateActionHistoryDetails(targetUIEvent.getEntity())); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java index 3f7b7eee5..834566f7e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java @@ -25,11 +25,11 @@ import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.ui.common.ConfirmationDialog; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.PinUnpinEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; @@ -855,11 +855,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { } private void updateTargetAndDsTable() { - /* - * Update the target status in the Target table and update the color - * settings for DS in DS table. - */ - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.EDIT_TARGET, target)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, target)); updateDistributionTableStyle(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index 9bbc1c05d..80c1b5700 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -23,10 +23,10 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; @@ -260,8 +260,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success", new Object[] { currentDS.getName(), currentDS.getVersion() })); // update table row+details layout - eventBus.publish(this, - new DistributionTableEvent(DistributionComponentEvent.EDIT_DISTRIBUTION, currentDS)); + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, currentDS)); } catch (final EntityAlreadyExistsException entityAlreadyExistsException) { LOG.error("Update distribution failed {}", entityAlreadyExistsException); notificationMessage.displayValidationError( @@ -307,7 +306,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { /* close the window */ closeThisWindow(); - eventBus.publish(this, new DistributionTableEvent(DistributionComponentEvent.ADD_DISTRIBUTION, newDist)); + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.NEW_ENTITY, newDist)); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java index a0de88fda..aedce157e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java @@ -9,14 +9,12 @@ package org.eclipse.hawkbit.ui.management.dstable; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; +import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.common.detailslayout.SoftwareModuleDetailsTable; import org.eclipse.hawkbit.ui.common.tagdetails.DistributionTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -36,11 +34,10 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class DistributionDetails extends AbstractTableDetailsLayout { +public class DistributionDetails extends AbstractNamedVersionedEntityTableDetailsLayout { private static final long serialVersionUID = 350360207334118826L; - @Autowired private ManagementUIState managementUIState; @@ -52,10 +49,6 @@ public class DistributionDetails extends AbstractTableDetailsLayout { private SoftwareModuleDetailsTable softwareModuleTable; - private Long dsId; - - private DistributionSet selectedDsModule; - @Override protected void init() { softwareModuleTable = new SoftwareModuleDetailsTable(); @@ -63,29 +56,9 @@ public class DistributionDetails extends AbstractTableDetailsLayout { super.init(); } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent distributionTableEvent) { - if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.ON_VALUE_CHANGE - || distributionTableEvent - .getDistributionComponentEvent() == DistributionComponentEvent.EDIT_DISTRIBUTION) { - ui.access(() -> { - /** - * distributionTableEvent.getDistributionSet() is null when - * table has no data. - */ - if (distributionTableEvent.getDistributionSet() != null) { - selectedDsModule = distributionTableEvent.getDistributionSet(); - populateData(true); - } else { - populateData(false); - } - }); - } else if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { - ui.access(() -> showLayout()); - } else if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { - ui.access(() -> hideLayout()); - } + onBaseEntityEvent(distributionTableEvent); } @Override @@ -105,7 +78,7 @@ public class DistributionDetails extends AbstractTableDetailsLayout { @Override protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); - distributionAddUpdateWindowLayout.populateValuesOfDistribution(getDsId()); + distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId()); newDistWindow.setCaption(i18n.get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); @@ -127,16 +100,6 @@ public class DistributionDetails extends AbstractTableDetailsLayout { return managementUIState.isDsTableMaximized(); } - @Override - protected void populateDetailsWidget() { - populateDetailsWidget(selectedDsModule); - } - - @Override - protected void clearDetails() { - populateDetailsWidget(null); - } - @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateDistributionPermission(); @@ -147,31 +110,11 @@ public class DistributionDetails extends AbstractTableDetailsLayout { return SPUIComponetIdProvider.DISTRIBUTION_DETAILS_TABSHEET; } - private void populateDetailsWidget(final DistributionSet dist) { - if (dist != null) { - setDsId(dist.getId()); - setName(getDefaultCaption(), HawkbitCommonUtil.getFormattedNameVersion(dist.getName(), dist.getVersion())); - populateDetails(dist); - populateDescription(dist); - populateLog(dist); - softwareModuleTable.populateModule(dist); - } else { - setDsId(null); - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); - populateDetails(null); - populateDescription(null); - softwareModuleTable.populateModule(null); - populateLog(null); - } - } + @Override + protected void populateDetailsWidget() { + softwareModuleTable.populateModule(selectedBaseEntity); + populateDetails(selectedBaseEntity); - private void populateLog(final DistributionSet ds) { - if (null != ds) { - updateLogLayout(getLogLayout(), ds.getLastModifiedAt(), ds.getLastModifiedBy(), ds.getCreatedAt(), - ds.getCreatedBy(), i18n); - } else { - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - } } private void populateDetails(final DistributionSet ds) { @@ -182,14 +125,6 @@ public class DistributionDetails extends AbstractTableDetailsLayout { } } - private void populateDescription(final DistributionSet ds) { - if (ds != null) { - updateDescriptionLayout(i18n.get("label.description"), ds.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } - } - private void updateDistributionDetailsLayout(final String type, final Boolean isMigrationRequired) { final VerticalLayout detailsTabLayout = getDetailsLayout(); detailsTabLayout.removeAllComponents(); @@ -221,14 +156,6 @@ public class DistributionDetails extends AbstractTableDetailsLayout { return tagsLayout; } - public Long getDsId() { - return dsId; - } - - public void setDsId(final Long dsId) { - this.dsId = dsId; - } - @Override protected String getDetailsHeaderCaptionId() { return SPUIComponetIdProvider.DISTRIBUTION_DETAILS_HEADER_LABEL_ID; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 6bcfb55ae..5e546b79a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -11,15 +11,12 @@ package org.eclipse.hawkbit.ui.management.dstable; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - +import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; @@ -29,9 +26,9 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; @@ -40,8 +37,6 @@ import org.eclipse.hawkbit.ui.management.event.PinUnpinEvent; import org.eclipse.hawkbit.ui.management.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -52,7 +47,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -76,22 +70,16 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionTable extends AbstractTable { +public class DistributionTable extends AbstractTable { private static final long serialVersionUID = -1928335256399519494L; - @Autowired - private I18N i18n; - @Autowired private SpPermissionChecker permissionChecker; @Autowired private UINotification notification; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ManagementUIState managementUIState; @@ -111,17 +99,9 @@ public class DistributionTable extends AbstractTable { private Button distributinPinnedBtn; @Override - @PostConstruct protected void init() { super.init(); - eventBus.subscribe(this); notAllowedMsg = i18n.get("message.action.not.allowed"); - setNoDataAvailable(); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); } /** @@ -151,13 +131,7 @@ public class DistributionTable extends AbstractTable { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent event) { - if (event.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.EDIT_DISTRIBUTION) { - UI.getCurrent().access(() -> updateDistributionInTable(event.getDistributionSet())); - } + onBaseEntityEvent(event); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -272,31 +246,18 @@ public class DistributionTable extends AbstractTable { } @Override - protected void onValueChange() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - final Set values = HawkbitCommonUtil.getSelectedDSDetails(this); - DistributionSetIdName value = null; - if (values != null && !values.isEmpty()) { - final Iterator iterator = values.iterator(); + protected DistributionSet findEntityByTableValue(final DistributionSetIdName lastSelectedId) { + return distributionSetManagement.findDistributionSetByIdWithDetails(lastSelectedId.getId()); + } - while (iterator.hasNext()) { - value = iterator.next(); - } - - if (null != value) { - managementUIState.setSelectedDsIdName(values); - managementUIState.setLastSelectedDsIdName(value); - final DistributionSet lastSelectedDistSet = distributionSetManagement - .findDistributionSetByIdWithDetails(value.getId()); - eventBus.publish(this, - new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, lastSelectedDistSet)); - } - } else { - managementUIState.setSelectedDsIdName(null); - managementUIState.setLastSelectedDsIdName(null); - eventBus.publish(this, new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, null)); - } + @Override + protected void publishEntityAfterValueChange(final DistributionSet selectedLastEntity) { + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity)); + } + @Override + protected ManagementUIState getManagmentEntityState() { + return managementUIState; } @Override @@ -306,7 +267,16 @@ public class DistributionTable extends AbstractTable { @Override protected List getTableVisibleColumns() { - return HawkbitCommonUtil.getTableVisibleColumns(isMaximized(), true, i18n); + final List columnList = new ArrayList<>(); + if (isMaximized()) { + columnList.addAll(super.getTableVisibleColumns()); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); + } else { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.7f)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2f)); + columnList.add(new TableColumn(SPUILabelDefinitions.PIN_COLUMN, StringUtils.EMPTY, 0.1f)); + } + return columnList; } @Override @@ -345,7 +315,7 @@ public class DistributionTable extends AbstractTable { private void assignDsTag(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails taregtDet = event.getTargetDetails(); final Table distTable = (Table) taregtDet.getTarget(); - final Set distsSelected = HawkbitCommonUtil.getSelectedDSDetails(distTable); + final Set distsSelected = getTableValue(distTable); final Set distList = new HashSet<>(); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); @@ -390,7 +360,7 @@ public class DistributionTable extends AbstractTable { private void assignTargetToDs(final DragAndDropEvent event) { final TableTransferable transferable = (TableTransferable) event.getTransferable(); final Table source = transferable.getSourceComponent(); - final Set targetsSelected = HawkbitCommonUtil.getSelectedTargetDetails(source); + final Set targetsSelected = getTableValue(source); final Set targetDetailsList = new HashSet<>(); if (!targetsSelected.contains(transferable.getData("itemId"))) { @@ -502,17 +472,14 @@ public class DistributionTable extends AbstractTable { private void updateDistributionInTable(final DistributionSet editedDs) { final Item item = getContainerDataSource() .getItem(new DistributionSetIdName(editedDs.getId(), editedDs.getName(), editedDs.getVersion())); - item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(editedDs.getName()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(editedDs.getVersion()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY) - .setValue(HawkbitCommonUtil.getIMUser(editedDs.getCreatedBy())); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(editedDs.getCreatedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) - .setValue(HawkbitCommonUtil.getIMUser(editedDs.getLastModifiedBy())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(editedDs.getLastModifiedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(editedDs.getDescription()); + updateEntity(editedDs, item); + + } + + @Override + protected void updateEntity(final DistributionSet baseEntity, final Item item) { + super.updateEntity(baseEntity, item); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); } private void restoreDistributionTableStyle() { @@ -703,12 +670,10 @@ public class DistributionTable extends AbstractTable { this.distributinPinnedBtn = distributinPinnedBtn; } - private void setNoDataAvailable() { - final int size = getContainerDataSource().size(); - if (size == 0) { - managementUIState.setNoDataAvailableDistribution(true); - } else { - managementUIState.setNoDataAvailableDistribution(false); - } + @Override + protected void setDataAvailable(final boolean available) { + managementUIState.setNoDataAvailableDistribution(!available); + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java index 6d4343878..2ccbac961 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.ui.management.dstable; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; @@ -127,13 +127,13 @@ public class DistributionTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { managementUIState.setDsTableMaximized(Boolean.TRUE); - eventbus.publish(this, new DistributionTableEvent(DistributionComponentEvent.MAXIMIZED, null)); + eventbus.publish(this, new DistributionTableEvent(BaseEntityEventType.MAXIMIZED, null)); } @Override public void minimizeTable() { managementUIState.setDsTableMaximized(Boolean.FALSE); - eventbus.publish(this, new DistributionTableEvent(DistributionComponentEvent.MINIMIZED, null)); + eventbus.publish(this, new DistributionTableEvent(BaseEntityEventType.MINIMIZED, null)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java index 7690bf109..14eeaf26e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java @@ -9,50 +9,26 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; /** * * * */ -public class DistributionTableEvent { +public class DistributionTableEvent extends BaseEntityEvent { /** - * - * + * Constructor. + * + * @param eventType + * the event type + * @param entity + * the distribution set */ - public enum DistributionComponentEvent { - ADD_DISTRIBUTION, EDIT_DISTRIBUTION, DELETE_DISTRIBUTION, ON_VALUE_CHANGE, MAXIMIZED, MINIMIZED - } - - private DistributionComponentEvent distributionComponentEvent; - - private DistributionSet distributionSet; - - /** - * @param distributionComponentEvent - * @param distributionSet - */ - public DistributionTableEvent(final DistributionComponentEvent distributionComponentEvent, - final DistributionSet distributionSet) { - this.distributionComponentEvent = distributionComponentEvent; - this.distributionSet = distributionSet; - } - - public DistributionComponentEvent getDistributionComponentEvent() { - return distributionComponentEvent; - } - - public void setDistributionComponentEvent(final DistributionComponentEvent distributionComponentEvent) { - this.distributionComponentEvent = distributionComponentEvent; - } - - public DistributionSet getDistributionSet() { - return distributionSet; - } - - public void setDistributionSet(final DistributionSet distributionSet) { - this.distributionSet = distributionSet; + public DistributionTableEvent(final BaseEntityEventType eventType, final DistributionSet entity) { + super(eventType, entity); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java index f1bc5d8ec..cf2661c60 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java @@ -9,7 +9,8 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; /** * @@ -17,34 +18,18 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentE * * */ -public class TargetAddUpdateWindowEvent { - - private final TargetComponentEvent targetComponentEvent; - - private final Target target; +public class TargetAddUpdateWindowEvent extends BaseEntityEvent { /** + * Constructor. + * * @param eventType * the event type - * @param target - * the target which has been created or modified + * @param entity + * the entity */ - public TargetAddUpdateWindowEvent(final TargetComponentEvent eventType, final Target target) { - this.targetComponentEvent = eventType; - this.target = target; + public TargetAddUpdateWindowEvent(final BaseEntityEventType eventType, final Target entity) { + super(eventType, entity); } - /** - * @return the targetComponentEvent - */ - public TargetComponentEvent getTargetComponentEvent() { - return targetComponentEvent; - } - - /** - * @return the target - */ - public Target getTarget() { - return target; - } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java index 1706361f0..04dd917a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java @@ -9,77 +9,51 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; /** * * * */ -public class TargetTableEvent { +public class TargetTableEvent extends BaseEntityEvent { /** * Target table components events. * */ public enum TargetComponentEvent { - REFRESH_TARGETS, EDIT_TARGET, DELETE_TARGET, SELECTED_TARGET, MAXIMIZED, MINIMIZED, SELLECT_ALL, BULK_TARGET_CREATED, BULK_UPLOAD_COMPLETED, BULK_TARGET_UPLOAD_STARTED, BULK_UPLOAD_PROCESS_STARTED + REFRESH_TARGETS, SELLECT_ALL, BULK_TARGET_CREATED, BULK_UPLOAD_COMPLETED, BULK_TARGET_UPLOAD_STARTED, BULK_UPLOAD_PROCESS_STARTED } private TargetComponentEvent targetComponentEvent; - private Target target; - - private TargetIdName targetIdName; + /** + * Constructor. + * + * @param eventType + * the event type. + * @param entity + * the entity + */ + public TargetTableEvent(final BaseEntityEventType eventType, final Target entity) { + super(eventType, entity); + } /** + * The component event. + * * @param targetComponentEvent + * the target component event. */ public TargetTableEvent(final TargetComponentEvent targetComponentEvent) { - super(); + super(null, null); this.targetComponentEvent = targetComponentEvent; } - /** - * @param targetComponentEvent - * @param target - */ - public TargetTableEvent(final TargetComponentEvent targetComponentEvent, final Target target) { - this(targetComponentEvent); - this.target = target; - } - - /** - * @param targetComponentEvent - * @param targetIdName - */ - public TargetTableEvent(final TargetComponentEvent targetComponentEvent, final TargetIdName targetIdName) { - this(targetComponentEvent); - this.targetIdName = targetIdName; - } - public TargetComponentEvent getTargetComponentEvent() { return targetComponentEvent; } - public void setTargetComponentEvent(final TargetComponentEvent targetComponentEvent) { - this.targetComponentEvent = targetComponentEvent; - } - - public Target getTarget() { - return target; - } - - public void setTarget(final Target target) { - this.target = target; - } - - public TargetIdName getTargetIdName() { - return targetIdName; - } - - public void setTargetIdName(final TargetIdName targetIdName) { - this.targetIdName = targetIdName; - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java index 7ff9f53e4..ed002defb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java @@ -95,8 +95,8 @@ public class CountMessageLabel extends Label { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent event) { - if (event.getTargetComponentEvent() == TargetTableEvent.TargetComponentEvent.SELLECT_ALL - || event.getTargetComponentEvent() == TargetComponentEvent.REFRESH_TARGETS) { + if (TargetTableEvent.TargetComponentEvent.SELLECT_ALL == event.getTargetComponentEvent() + || TargetComponentEvent.REFRESH_TARGETS == event.getTargetComponentEvent()) { displayTargetCountStatus(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index b8c5494a3..4a95df51a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -15,6 +15,7 @@ import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.management.event.BulkUploadPopupEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; @@ -211,7 +212,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - manangementConfirmationWindowLayout.init(); + manangementConfirmationWindowLayout.inittialize(); return manangementConfirmationWindowLayout; } @@ -257,7 +258,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } private void addInDeleteDistributionList(final Table sourceTable, final TableTransferable transferable) { - final Set distSelected = HawkbitCommonUtil.getSelectedDSDetails(sourceTable); + final Set distSelected = AbstractTable.getTableValue(sourceTable); final Set distributionIdNameSet = new HashSet<>(); if (!distSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { @@ -311,7 +312,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } private void addInDeleteTargetList(final Table sourceTable, final TableTransferable transferable) { - final Set targetSelected = HawkbitCommonUtil.getSelectedTargetDetails(sourceTable); + final Set targetSelected = AbstractTable.getTableValue(sourceTable); final Set targetIdNameSet = new HashSet<>(); if (!targetSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java index c0f681c7a..56e11a6fe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java @@ -19,8 +19,6 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; - import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; @@ -31,20 +29,15 @@ import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.ConfirmationTab; -import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.PinUnpinEvent; import org.eclipse.hawkbit.ui.management.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.management.footer.ActionTypeOptionGroupLayout.ActionTypeOption; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.data.Item; import com.vaadin.data.util.IndexedContainer; @@ -52,8 +45,8 @@ import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Table.Align; -import com.vaadin.ui.themes.ValoTheme; /** * Confirmation window for target/ds delete and assignment. @@ -79,12 +72,6 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin @Autowired private ManagementUIState managementUIState; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient TargetManagement targetManagement; @@ -99,14 +86,6 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin private ConfirmationTab assignmnetTab; - /** - * Initialze the component. - */ - @PostConstruct - public void init() { - super.inittialize(); - } - @Override protected Map getConfimrationTabs() { final Map tabs = new HashMap<>(); @@ -130,6 +109,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin assignmnetTab.getConfirmAll().setIcon(FontAwesome.SAVE); assignmnetTab.getConfirmAll().setCaption(i18n.get("button.assign.all")); assignmnetTab.getConfirmAll().addClickListener(event -> saveAllAssignments(assignmnetTab)); + assignmnetTab.getDiscardAll().setCaption(i18n.get(SPUILabelDefinitions.BUTTON_DISCARD_ALL)); assignmnetTab.getDiscardAll().setId(SPUIComponetIdProvider.DISCARD_ASSIGNMENT); assignmnetTab.getDiscardAll().addClickListener(event -> discardAllAssignments(assignmnetTab)); @@ -139,35 +119,17 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin // Add the discard action column assignmnetTab.getTable().addGeneratedColumn(DISCARD_CHANGES, (source, itemId, columnId) -> { - final StringBuilder style = new StringBuilder(ValoTheme.BUTTON_TINY); - style.append(' '); - style.append(SPUIStyleDefinitions.REDICON); - final Button deleteIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - style.toString(), true, FontAwesome.REPLY, SPUIButtonStyleSmallNoBorder.class); - deleteIcon.setData(itemId); - deleteIcon.setImmediate(true); - deleteIcon.addClickListener(event -> discardAssignment( - (TargetIdName) ((Button) event.getComponent()).getData(), assignmnetTab)); - return deleteIcon; + final ClickListener clickListener = event -> discardAssignment( + (TargetIdName) ((Button) event.getComponent()).getData(), assignmnetTab); + return createDiscardButton(itemId, clickListener); }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(TARGET_NAME); - visibleColumnIds.add(DISTRIBUTION_NAME); - visibleColumnIds.add(DISCARD_CHANGES); - visibleColumnLabels.add(i18n.get("header.first.assignment.table")); - visibleColumnLabels.add(i18n.get("header.second.assignment.table")); - visibleColumnLabels.add(i18n.get("header.third.assignment.table")); - } - assignmnetTab.getTable().setColumnExpandRatio(TARGET_NAME, 2); assignmnetTab.getTable().setColumnExpandRatio(DISTRIBUTION_NAME, 2); assignmnetTab.getTable().setColumnExpandRatio(DISCARD_CHANGES, 1); - assignmnetTab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - assignmnetTab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + assignmnetTab.getTable().setVisibleColumns(TARGET_NAME, DISTRIBUTION_NAME, DISCARD_CHANGES); + assignmnetTab.getTable().setColumnHeaders(i18n.get("header.first.assignment.table"), + i18n.get("header.second.assignment.table"), i18n.get("header.third.assignment.table")); assignmnetTab.getTable().setColumnAlignment(DISCARD_CHANGES, Align.CENTER); actionTypeOptionGroupLayout.selectDefaultOption(); @@ -326,27 +288,15 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin /* Add the discard action column */ tab.getTable().addGeneratedColumn(DISCARD_CHANGES, (source, itemId, columnId) -> { - final Button deletestargetIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deletestargetIcon.setData(itemId); - deletestargetIcon.setImmediate(true); - deletestargetIcon.addClickListener(event -> discardTargetDelete( - (TargetIdName) ((Button) event.getComponent()).getData(), itemId, tab)); - return deletestargetIcon; + final ClickListener clickListener = event -> discardTargetDelete( + (TargetIdName) ((Button) event.getComponent()).getData(), itemId, tab); + return createDiscardButton(itemId, clickListener); + }); - /* set the visible columns */ - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(TARGET_NAME); - visibleColumnIds.add(DISCARD_CHANGES); - visibleColumnLabels.add(i18n.get("header.first.deletetarget.table")); - visibleColumnLabels.add(i18n.get("header.second.deletetarget.table")); - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(TARGET_NAME, DISCARD_CHANGES); + tab.getTable().setColumnHeaders(i18n.get("header.first.deletetarget.table"), + i18n.get("header.second.deletetarget.table")); tab.getTable().setColumnExpandRatio(TARGET_NAME, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(DISCARD_CHANGES, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -371,30 +321,17 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin /* Add the discard action column */ tab.getTable().addGeneratedColumn(DISCARD_CHANGES, (source, itemId, columnId) -> { - final Button deletesDsIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deletesDsIcon.setData(itemId); - deletesDsIcon.setImmediate(true); - deletesDsIcon.addClickListener(event -> discardDSDelete( - (DistributionSetIdName) ((Button) event.getComponent()).getData(), itemId, tab)); - return deletesDsIcon; - }); + final ClickListener clickListener = event -> discardDSDelete( + (DistributionSetIdName) ((Button) event.getComponent()).getData(), itemId, tab); + return createDiscardButton(itemId, clickListener); - /* set the visible columns */ - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(DISTRIBUTION_NAME); - visibleColumnIds.add(DISCARD_CHANGES); - visibleColumnLabels.add(i18n.get("header.one.deletedist.table")); - visibleColumnLabels.add(i18n.get("header.second.deletedist.table")); - } + }); tab.getTable().setColumnExpandRatio(DISTRIBUTION_NAME, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(DISCARD_CHANGES, SPUIDefinitions.DISCARD_COLUMN_WIDTH); - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(DISTRIBUTION_NAME, DISCARD_CHANGES); + tab.getTable().setColumnHeaders(i18n.get("header.one.deletedist.table"), + i18n.get("header.second.deletedist.table")); tab.getTable().setColumnAlignment(DISCARD_CHANGES, Align.CENTER); return tab; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java index 3184bf923..73e2ed1a7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java @@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -31,7 +32,7 @@ import com.vaadin.spring.annotation.VaadinSessionScope; */ @VaadinSessionScope @SpringComponent -public class ManagementUIState implements Serializable { +public class ManagementUIState implements ManagmentEntityState, Serializable { private static final long serialVersionUID = 7301409196969723794L; @@ -266,12 +267,15 @@ public class ManagementUIState implements Serializable { return lastSelectedDsIdName; } - public void setLastSelectedDsIdName(final DistributionSetIdName lastSelectedDsIdName) { - this.lastSelectedDsIdName = lastSelectedDsIdName; + @Override + public void setLastSelectedEntity(final DistributionSetIdName value) { + this.lastSelectedDsIdName = value; } - public void setSelectedDsIdName(final Set selectedDsIdName) { - this.selectedDsIdName = selectedDsIdName; + @Override + public void setSelectedEnitities(final Set values) { + this.selectedDsIdName = values; + } public Optional> getSelectedDsIdName() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java index 48f0ad2bf..973d61857 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java @@ -14,11 +14,11 @@ import java.util.Set; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -56,6 +56,8 @@ import com.vaadin.ui.themes.ValoTheme; @SpringComponent @VaadinSessionScope public class TargetAddUpdateWindowLayout extends CustomComponent { + private static final long serialVersionUID = -6659290471705262389L; + @Autowired private I18N i18n; @@ -68,7 +70,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { @Autowired private transient UINotification uINotification; - private static final long serialVersionUID = -6659290471705262389L; private TextField controllerIDTextField; private TextField nameTextField; private TextArea descTextArea; @@ -218,7 +219,7 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { /* display success msg */ uINotification.displaySuccess(i18n.get("message.update.success", new Object[] { latestTarget.getName() })); // publishing through event bus - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.EDIT_TARGET, latestTarget)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, latestTarget)); /* close the window */ closeThisWindow(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java index 87854b22c..6105409bf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java @@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; import org.eclipse.hawkbit.ui.common.tagdetails.TargetTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -50,7 +49,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class TargetDetails extends AbstractTableDetailsLayout { +public class TargetDetails extends AbstractTableDetailsLayout { private static final long serialVersionUID = 4571732743399605843L; @@ -63,8 +62,6 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Autowired private TargetTagToken targetTagToken; - private Target selectedTarget = null; - private VerticalLayout assignedDistLayout; private VerticalLayout installedDistLayout; @@ -112,13 +109,14 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void onEdit(final ClickEvent event) { - if (selectedTarget != null) { - final Window newDistWindow = targetAddUpdateWindowLayout.getWindow(); - targetAddUpdateWindowLayout.populateValuesOfTarget(selectedTarget.getControllerId()); - newDistWindow.setCaption(i18n.get("caption.update.dist")); - UI.getCurrent().addWindow(newDistWindow); - newDistWindow.setVisible(Boolean.TRUE); + if (selectedBaseEntity == null) { + return; } + final Window newDistWindow = targetAddUpdateWindowLayout.getWindow(); + targetAddUpdateWindowLayout.populateValuesOfTarget(selectedBaseEntity.getControllerId()); + newDistWindow.setCaption(i18n.get("caption.update.dist")); + UI.getCurrent().addWindow(newDistWindow); + newDistWindow.setVisible(Boolean.TRUE); } @Override @@ -138,50 +136,24 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void populateDetailsWidget() { - if (selectedTarget != null) { - setName(getDefaultCaption(), selectedTarget.getName()); - } - populateDetailsWidget(selectedTarget); - } - - private void populateDetailsWidget(final Target target) { - if (target != null) { - setName(getDefaultCaption(), target.getName()); - updateDetailsLayout(target.getControllerId(), target.getTargetInfo().getAddress(), - target.getSecurityToken(), - SPDateTimeUtil.getFormattedDate(target.getTargetInfo().getLastTargetQuery())); - populateDescription(target); - populateDistributionDtls(installedDistLayout, target.getTargetInfo().getInstalledDistributionSet()); - populateDistributionDtls(assignedDistLayout, target.getAssignedDistributionSet()); - updateLogLayout(getLogLayout(), target.getLastModifiedAt(), target.getLastModifiedBy(), - target.getCreatedAt(), target.getCreatedBy(), i18n); - populateAttributes(target); + if (selectedBaseEntity != null) { + updateDetailsLayout(selectedBaseEntity.getControllerId(), selectedBaseEntity.getTargetInfo().getAddress(), + selectedBaseEntity.getSecurityToken(), + SPDateTimeUtil.getFormattedDate(selectedBaseEntity.getTargetInfo().getLastTargetQuery())); + populateDistributionDtls(installedDistLayout, + selectedBaseEntity.getTargetInfo().getInstalledDistributionSet()); + populateDistributionDtls(assignedDistLayout, selectedBaseEntity.getAssignedDistributionSet()); } else { - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); updateDetailsLayout(null, null, null, null); - populateDescription(null); populateDistributionDtls(installedDistLayout, null); populateDistributionDtls(assignedDistLayout, null); - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - populateAttributes(null); } + updateAttributesLayout(selectedBaseEntity); } - private void populateAttributes(final Target target) { - if (target != null) { - - updateAttributesLayout(target); - } else { - updateAttributesLayout(null); - } - } - - private void populateDescription(final Target target) { - if (target != null) { - updateDescriptionLayout(i18n.get("label.description"), target.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } + @Override + protected String getName() { + return selectedBaseEntity.getName(); } private void updateDetailsLayout(final String controllerId, final URI address, final String securityToken, @@ -262,11 +234,6 @@ public class TargetDetails extends AbstractTableDetailsLayout { return SPUIComponentProvider.createNameValueLabel(labelName + " : ", swModule.getName(), swModule.getVersion()); } - @Override - protected void clearDetails() { - populateDetailsWidget(null); - } - @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateTargetPermission(); @@ -274,25 +241,7 @@ public class TargetDetails extends AbstractTableDetailsLayout { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent targetTableEvent) { - // Get the event type - final TargetComponentEvent event = targetTableEvent.getTargetComponentEvent(); - - if (event == TargetComponentEvent.SELECTED_TARGET || event == TargetComponentEvent.EDIT_TARGET) { - UI.getCurrent().access(() -> { - // If selected or edited, populate the fresh details. - if (targetTableEvent.getTarget() != null) { - selectedTarget = targetTableEvent.getTarget(); - } else { - selectedTarget = null; - } - populateData(selectedTarget != null); - - }); - } else if (event == TargetComponentEvent.MINIMIZED) { - UI.getCurrent().access(() -> showLayout()); - } else if (event == TargetComponentEvent.MAXIMIZED) { - UI.getCurrent().access(() -> hideLayout()); - } + onBaseEntityEvent(targetTableEvent); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 6884e8906..559169f2e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -18,9 +18,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; @@ -34,7 +31,9 @@ import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.filter.FilterExpression; import org.eclipse.hawkbit.ui.filter.Filters; import org.eclipse.hawkbit.ui.filter.target.CustomTargetFilter; @@ -53,7 +52,6 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentE import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.management.state.TargetTableFilters; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -69,7 +67,6 @@ import org.springframework.data.domain.Sort; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -102,7 +99,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class TargetTable extends AbstractTable implements Handler { +public class TargetTable extends AbstractTable implements Handler { private static final Logger LOG = LoggerFactory.getLogger(TargetTable.class); private static final String TARGET_PINNED = "targetPinned"; @@ -116,9 +113,6 @@ public class TargetTable extends AbstractTable implements Handler { @Autowired private transient TargetManagement targetManagement; - @Autowired - private I18N i18n; - @Autowired private ManagementUIState managementUIState; @@ -128,9 +122,6 @@ public class TargetTable extends AbstractTable implements Handler { @Autowired private UINotification notification; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ManagementViewAcceptCriteria managementViewAcceptCriteria; @@ -141,19 +132,11 @@ public class TargetTable extends AbstractTable implements Handler { private ShortcutAction actionUnSelectAll; @Override - @PostConstruct protected void init() { super.init(); addActionHandler(this); actionSelectAll = new ShortcutAction(i18n.get("action.target.table.selectall")); actionUnSelectAll = new ShortcutAction(i18n.get("action.target.table.clear")); - eventBus.subscribe(this); - setNoDataAvailable(); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); } /** @@ -199,9 +182,10 @@ public class TargetTable extends AbstractTable implements Handler { @EventBusListenerMethod(scope = EventScope.SESSION) void addOrEditEvent(final TargetAddUpdateWindowEvent targetUIEvent) { - if (targetUIEvent.getTargetComponentEvent() == TargetComponentEvent.EDIT_TARGET) { - UI.getCurrent().access(() -> updateTarget(targetUIEvent.getTarget())); + if (BaseEntityEventType.UPDATED_ENTITY != targetUIEvent.getEventType()) { + return; } + UI.getCurrent().access(() -> updateTarget(targetUIEvent.getEntity())); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -239,33 +223,14 @@ public class TargetTable extends AbstractTable implements Handler { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent event) { - if (event.getTargetComponentEvent() == TargetComponentEvent.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getTargetComponentEvent() == TargetComponentEvent.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getTargetComponentEvent() == TargetComponentEvent.EDIT_TARGET) { - UI.getCurrent().access(() -> updateTarget(event.getTarget())); - } + onBaseEntityEvent(event); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.table.AbstractTable#getTableId() - */ @Override protected String getTableId() { return SPUIComponetIdProvider.TARGET_TABLE_ID; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.table.AbstractTable#createContainer( - * ) - */ @Override protected Container createContainer() { // ADD all the filters to the query config @@ -311,12 +276,6 @@ public class TargetTable extends AbstractTable implements Handler { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.table.AbstractTable# - * addCustomGeneratedColumns () - */ @Override protected void addCustomGeneratedColumns() { addGeneratedColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, @@ -340,22 +299,24 @@ public class TargetTable extends AbstractTable implements Handler { } @Override - protected void onValueChange() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - @SuppressWarnings("unchecked") - final Set values = HawkbitCommonUtil.getSelectedTargetDetails(this); - if (values != null && !values.isEmpty()) { - final TargetIdName lastSelectedItem = getLastSelectedItem(values); - managementUIState.setSelectedTargetIdName(values); - managementUIState.setLastSelectedTargetIdName(lastSelectedItem); - final Target target = targetManagement - .findTargetByControllerIDWithDetails(lastSelectedItem.getControllerId()); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.SELECTED_TARGET, target)); - } else { - managementUIState.setSelectedTargetIdName(null); - managementUIState.setLastSelectedTargetIdName(null); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.SELECTED_TARGET, (Target) null)); - } + protected void publishEntityAfterValueChange(final Target selectedLastEntity) { + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity)); + } + + @Override + protected Target findEntityByTableValue(final TargetIdName lastSelectedId) { + return targetManagement.findTargetByControllerIDWithDetails(lastSelectedId.getControllerId()); + } + + @Override + protected void setManagementEntitiyStateValues(final Set values, final TargetIdName lastId) { + managementUIState.setSelectedTargetIdName(values); + managementUIState.setLastSelectedTargetIdName(lastId); + } + + @Override + protected ManagmentEntityState getManagmentEntityState() { + return null; } @Override @@ -365,30 +326,15 @@ public class TargetTable extends AbstractTable implements Handler { @Override protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); - if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1f)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1f)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2f)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8f)); + final List columnList = super.getTableVisibleColumns(); + if (!isMaximized()) { columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_POLL_TIME, "", 0.0f)); columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, "", 0.0f)); } return columnList; + } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.table.AbstractTable#getTableDropHandler() - */ @Override protected DropHandler getTableDropHandler() { return new DropHandler() { @@ -630,7 +576,7 @@ public class TargetTable extends AbstractTable implements Handler { private void tagAssignment(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails taregtDet = event.getTargetDetails(); final Table targetTable = (Table) taregtDet.getTarget(); - final Set targetSelected = HawkbitCommonUtil.getSelectedTargetDetails(targetTable); + final Set targetSelected = getTableValue(targetTable); final Set targetList = new HashSet<>(); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); final Object targetItemId = dropData.getItemIdOver(); @@ -688,7 +634,7 @@ public class TargetTable extends AbstractTable implements Handler { private static Set getDraggedDistributionSet(final TableTransferable transferable, final Table source) { - final Set distSelected = HawkbitCommonUtil.getSelectedDSDetails(source); + final Set distSelected = getTableValue(source); final Set distributionIdSet = new HashSet<>(); if (!distSelected.contains(transferable.getData(ITEMID))) { distributionIdSet.add((DistributionSetIdName) transferable.getData(ITEMID)); @@ -962,7 +908,7 @@ public class TargetTable extends AbstractTable implements Handler { refreshTargets(); } if (lastSelectedTarget != null) { - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.SELECTED_TARGET, lastSelectedTarget)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, lastSelectedTarget)); } } @@ -1042,13 +988,9 @@ public class TargetTable extends AbstractTable implements Handler { setValue(null); } - private void setNoDataAvailable() { - final int tableSize = getContainerDataSource().size(); - if (tableSize == 0) { - managementUIState.setNoDataAvilableTarget(true); - } else { - managementUIState.setNoDataAvilableTarget(false); - } + @Override + protected void setDataAvailable(final boolean available) { + managementUIState.setNoDataAvilableTarget(!available); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index 5ad6e3c28..cb00c2338 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -12,7 +12,9 @@ import java.util.HashSet; import java.util.Set; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.BulkUploadPopupEvent; @@ -254,13 +256,13 @@ public class TargetTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { managementUIState.setTargetTableMaximized(Boolean.TRUE); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.MAXIMIZED)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.MAXIMIZED,null)); } @Override public void minimizeTable() { managementUIState.setTargetTableMaximized(Boolean.FALSE); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.MINIMIZED)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.MINIMIZED,null)); } @Override @@ -377,8 +379,7 @@ public class TargetTableHeader extends AbstractTableHeader { } private Set getDropppedDistributionDetails(final TableTransferable transferable) { - final Set distSelected = HawkbitCommonUtil - .getSelectedDSDetails(transferable.getSourceComponent()); + final Set distSelected = AbstractTable.getTableValue(transferable.getSourceComponent()); final Set distributionIdSet = new HashSet<>(); if (!distSelected.contains(transferable.getData("itemId"))) { distributionIdSet.add((DistributionSetIdName) transferable.getData("itemId")); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 54f4c382b..c60ab37ca 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -22,6 +22,7 @@ import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.ManagementViewAcceptCriteria; @@ -217,7 +218,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { final TableTransferable transferable = (TableTransferable) event.getTransferable(); final Table source = transferable.getSourceComponent(); - final Set targetSelected = HawkbitCommonUtil.getSelectedTargetDetails(source); + final Set targetSelected = AbstractTable.getTableValue(source); final Set targetList = new HashSet<>(); if (transferable.getData(ITEMID) != null) { if (!targetSelected.contains(transferable.getData(ITEMID))) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 3abd73592..2552fcf9a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -14,29 +14,23 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.im.authentication.UserPrincipal; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; -import org.eclipse.hawkbit.ui.management.dstable.DistributionTable; -import org.eclipse.hawkbit.ui.management.targettable.TargetTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.userdetails.UserDetails; @@ -878,8 +872,8 @@ public final class HawkbitCommonUtil { * I18N * @return message */ - public static String createAssignmentMessage(final String tagName, final AssignmentResult result, - final I18N i18n) { + public static String createAssignmentMessage(final String tagName, + final AssignmentResult result, final I18N i18n) { final StringBuilder formMsg = new StringBuilder(); final int assignedCount = result.getAssigned(); final int alreadyAssignedCount = result.getAlreadyAssigned(); @@ -959,43 +953,6 @@ public final class HawkbitCommonUtil { lqc.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); } - /** - * Get visible columns in table. - * - * @param isMaximized - * true if table is maximized - * @param isShowPinColumn - * if true pin column will be displayed. - * @param i18n - * I18N - * @return List list of columns to be displayed. - */ - public static List getTableVisibleColumns(final Boolean isMaximized, final Boolean isShowPinColumn, - final I18N i18n) { - final List columnList = new ArrayList<>(); - if (isMaximized) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get(HEADER_NAME), 0.2f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get(HEADER_VERSION), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1f)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1f)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2f)); - } else if (isShowPinColumn) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get(HEADER_NAME), 0.7f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get(HEADER_VERSION), 0.2f)); - columnList.add(new TableColumn(SPUILabelDefinitions.PIN_COLUMN, SP_STRING_EMPTY, 0.1f)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get(HEADER_NAME), 0.8f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get(HEADER_VERSION), 0.2f)); - } - return columnList; - - } - /** * Reset the software module table rows highlight css. * @@ -1102,36 +1059,6 @@ public final class HawkbitCommonUtil { return DELETE_TAG_DROP_REMOVE_SCRIPT; } - /** - * Get the details of selected rows of {@link TargetTable}. - * - * @param sourceTable - * @return set of {@link TargetIdName} - */ - public static Set getSelectedTargetDetails(final Table sourceTable) { - Set targetSelected = null; - if (sourceTable.getValue() != null) { - targetSelected = new LinkedHashSet<>((Set) sourceTable.getValue()); - targetSelected.remove(null); - } - return targetSelected; - } - - /** - * Get the details of selected rows of {@link DistributionTable}. - * - * @param sourceTable - * @return set of {@link DistributionSetIdName} - */ - public static Set getSelectedDSDetails(final Table sourceTable) { - Set distSelected = null; - if (sourceTable.getValue() != null) { - distSelected = new LinkedHashSet<>((Set) sourceTable.getValue()); - distSelected.remove(null); - } - return distSelected; - } - /** * * Add target table container properties. From e09ff4a716bd83bd9c91c12b610da5e1f80798ee Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 10:32:59 +0200 Subject: [PATCH 02/49] Refactor TableHeader Signed-off-by: SirWayne --- .../smtable/SoftwareModuleTable.java | 1 - .../ui/common/table/AbstractTable.java | 30 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 6164fa3bf..4f668ee8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -182,7 +182,6 @@ public class SoftwareModuleTable extends AbstractTable { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); } return columnList; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index c9487d467..be77cfaf2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -94,7 +94,7 @@ public abstract class AbstractTable extends Table { if (values == null) { values = Collections.emptySet(); } - if (values.remove(null)) { + if (values.contains(null)) { LOG.warn("Null values in table content. How could this happen?"); } return values; @@ -103,14 +103,12 @@ public abstract class AbstractTable extends Table { private void onValueChange() { eventBus.publish(this, UploadArtifactUIEvent.HIDE_DROP_HINTS); - // TODO Einzelwerte? - final Set values = getTableValue(this); E entity = null; - - final I lastId = Iterables.getLast(values); - if (lastId != null) { + I lastId = null; + if (!values.isEmpty()) { + lastId = Iterables.getLast(values); entity = findEntityByTableValue(lastId); } setManagementEntitiyStateValues(values, lastId); @@ -294,19 +292,17 @@ public abstract class AbstractTable extends Table { */ protected List getTableVisibleColumns() { final List columnList = new ArrayList<>(); - if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); - } else { + if (!isMaximized()) { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); + return columnList; } + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); + columnList.add( + new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); return columnList; } From 927ef461b9abc7941132323dfed172f98e7b5493 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 12:01:08 +0200 Subject: [PATCH 03/49] Update Distribution Set in table Signed-off-by: SirWayne --- .../hawkbit/ui/management/dstable/DistributionTable.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 5e546b79a..44574fb3a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -132,6 +132,11 @@ public class DistributionTable extends AbstractTable updateDistributionInTable(event.getEntity())); + } @EventBusListenerMethod(scope = EventScope.SESSION) From 6f2383b07723e3e6302be8f6dafe4ee5f018f0f7 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 12:23:56 +0200 Subject: [PATCH 04/49] Add Javadoc Signed-off-by: SirWayne --- .../hawkbit/ui/common/ManagmentEntityState.java | 15 ++++++++++++++- .../detailslayout/AbstractTableDetailsLayout.java | 11 ++++++++--- .../ui/common/table/BaseEntityEventType.java | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java index 8b2318ace..ecc378ad7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java @@ -11,12 +11,25 @@ package org.eclipse.hawkbit.ui.common; import java.util.Set; /** - * + * Interface for all entity states UI to show the details to a entity. */ public interface ManagmentEntityState { + /** + * The selected entities for the detail. + * + * @param values + * the selected entities. + * + */ void setSelectedEnitities(Set values); + /** + * The last selected value. + * + * @param value + * the value + */ void setLastSelectedEntity(T value); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 02b1f0044..334eee90f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -41,7 +41,7 @@ import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; /** - * + * Abstract Layout to show the entity details. * */ public abstract class AbstractTableDetailsLayout extends VerticalLayout { @@ -89,10 +89,15 @@ public abstract class AbstractTableDetailsLayout extends eventBus.unsubscribe(this); } + /** + * Default implementation to handle a entity event. + * + * @param baseEntityEvent + * the event + */ protected void onBaseEntityEvent(final BaseEntityEvent baseEntityEvent) { final BaseEntityEventType eventType = baseEntityEvent.getEventType(); - if (BaseEntityEventType.SELECTED_ENTITY == eventType - || BaseEntityEventType.UPDATED_ENTITY == eventType) { + if (BaseEntityEventType.SELECTED_ENTITY == eventType || BaseEntityEventType.UPDATED_ENTITY == eventType) { UI.getCurrent().access(() -> populateData(baseEntityEvent.getEntity())); } else if (BaseEntityEventType.MINIMIZED == eventType) { UI.getCurrent().access(() -> setVisible(true)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java index bfaf593fb..d9f7f544c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.common.table; /** - * + * Types of the entity event. * */ public enum BaseEntityEventType { From fdee1528850a69a3b8b3f3273755867cfb4fe8d4 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 12:42:50 +0200 Subject: [PATCH 05/49] Fix typo Signed-off-by: SirWayne --- .../hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java | 2 +- .../confirmwindow/layout/AbstractConfirmationWindowLayout.java | 2 +- .../hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java | 2 +- .../hawkbit/ui/management/footer/DeleteActionsLayout.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java index a5cb5c8d0..ee2fc356f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java @@ -190,7 +190,7 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - uploadViewConfirmationWindowLayout.inittialize(); + uploadViewConfirmationWindowLayout.initialize(); return uploadViewConfirmationWindowLayout; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java index a737fabbf..bc5de63ff 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java @@ -52,7 +52,7 @@ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { protected transient EventBus.SessionEventBus eventBus; @PostConstruct - public void inittialize() { + public void initialize() { removeAllComponents(); consolidatedMessage = ""; createComponents(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index ea33a2ea3..dba8155db 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -295,7 +295,7 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - distConfirmationWindowLayout.inittialize(); + distConfirmationWindowLayout.initialize(); return distConfirmationWindowLayout; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 4a95df51a..678a5704f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -212,7 +212,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - manangementConfirmationWindowLayout.inittialize(); + manangementConfirmationWindowLayout.initialize(); return manangementConfirmationWindowLayout; } From c069b904b21a7dc5fbb1a975458e332b16367a1c Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 13:00:39 +0200 Subject: [PATCH 06/49] Use Optional.ofNullable instead of a if statement Signed-off-by: SirWayne --- .../hawkbit/ui/artifacts/state/ArtifactUploadState.java | 4 ++-- .../AbstractNamedVersionedEntityTableDetailsLayout.java | 1 - .../hawkbit/ui/distributions/state/ManageDistUIState.java | 6 +++--- .../hawkbit/ui/management/state/ManagementUIState.java | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java index b975ad1fd..d387ff105 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java @@ -86,7 +86,7 @@ public class ArtifactUploadState implements ManagmentEntityState, Serializ * @return the selectedBaseSwModuleId */ public Optional getSelectedBaseSwModuleId() { - return selectedBaseSwModuleId != null ? Optional.of(selectedBaseSwModuleId) : Optional.empty(); + return Optional.ofNullable(selectedBaseSwModuleId); } /** @@ -179,7 +179,7 @@ public class ArtifactUploadState implements ManagmentEntityState, Serializ } public Optional getSelectedBaseSoftwareModule() { - return selectedBaseSoftwareModule == null ? Optional.empty() : Optional.of(selectedBaseSoftwareModule); + return Optional.ofNullable(selectedBaseSoftwareModule); } public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java index 31fbe5996..19bfb324e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java @@ -24,5 +24,4 @@ public abstract class AbstractNamedVersionedEntityTableDetailsLayout> getSelectedDistributions() { - return selectedDistributions == null ? Optional.empty() : Optional.of(selectedDistributions); + return Optional.ofNullable(selectedDistributions); } /** * @return the lastSelectedDistribution */ public Optional getLastSelectedDistribution() { - return lastSelectedDistribution == null ? Optional.empty() : Optional.of(lastSelectedDistribution); + return Optional.ofNullable(lastSelectedDistribution); } @Override @@ -139,7 +139,7 @@ public class ManageDistUIState implements ManagmentEntityState getSelectedBaseSwModuleId() { - return selectedBaseSwModuleId != null ? Optional.of(selectedBaseSwModuleId) : Optional.empty(); + return Optional.ofNullable(selectedBaseSwModuleId); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java index 73e2ed1a7..653075735 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java @@ -171,7 +171,7 @@ public class ManagementUIState implements ManagmentEntityState> getSelectedTargetIdName() { - return selectedTargetIdName == null ? Optional.empty() : Optional.of(selectedTargetIdName); + return Optional.ofNullable(selectedTargetIdName); } public void setSelectedTargetIdName(final Set selectedTargetIdName) { @@ -279,7 +279,7 @@ public class ManagementUIState implements ManagmentEntityState> getSelectedDsIdName() { - return selectedDsIdName == null ? Optional.empty() : Optional.of(selectedDsIdName); + return Optional.ofNullable(selectedDsIdName); } /** From 15702cb5c98d62f9fd1f5ed38cae35a8171af31f Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 13:11:16 +0200 Subject: [PATCH 07/49] Improve javadoc Signed-off-by: SirWayne --- .../hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index 0f5e2de32..615760a1c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -282,9 +282,8 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme } /** - * Only in deployment view count message is displayed. * - * @return + * @return true if the count label is displayed false ist not displayed */ protected boolean hasCountMessage() { return false; From 27118e293945e03c8f28b84a155a53d5edd03a7f Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 13:23:08 +0200 Subject: [PATCH 08/49] fix typo Signed-off-by: SirWayne --- .../hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index 615760a1c..75bd43447 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -283,7 +283,7 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme /** * - * @return true if the count label is displayed false ist not displayed + * @return true if the count label is displayed false is not displayed */ protected boolean hasCountMessage() { return false; From 5e0f07b8527f5c9776052c27ef4901cee56794f5 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 14:12:26 +0200 Subject: [PATCH 09/49] Add new abstract table to reduce the visible columns and add entity code Signed-off-by: SirWayne --- .../smtable/SoftwareModuleTable.java | 14 +++--- .../table/AbstractNamedVersionTable.java | 47 +++++++++++++++++++ .../ui/common/table/AbstractTable.java | 7 ++- .../dstable/DistributionSetTable.java | 7 ++- .../distributions/smtable/SwModuleTable.java | 19 ++++---- .../management/dstable/DistributionTable.java | 26 ++++------ 6 files changed, 81 insertions(+), 39 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 4f668ee8e..1ef4b8f7a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; -import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -48,7 +48,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class SoftwareModuleTable extends AbstractTable { +public class SoftwareModuleTable extends AbstractNamedVersionTable { private static final long serialVersionUID = 6469417305487144809L; @@ -165,7 +165,7 @@ public class SoftwareModuleTable extends AbstractTable { final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); if (!artifactUploadState.getSelectedSoftwareModules().isEmpty()) { artifactUploadState.getSelectedSoftwareModules().stream().forEach(this::unselect); @@ -178,12 +178,10 @@ public class SoftwareModuleTable extends AbstractTable { @Override protected List getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); - if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); + if (!isMaximized()) { + return columnList; } + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); return columnList; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java new file mode 100644 index 000000000..64460bc1c --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.common.table; + +import java.util.List; + +import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.TableColumn; + +import com.vaadin.data.Item; + +/** + * Abstract table to handling {@link NamedVersionedEntity} + * + * @param + * e is the entity class + * @param + * i is the id of the table + */ +public abstract class AbstractNamedVersionTable extends AbstractTable { + + private static final long serialVersionUID = 780050712209750719L; + + @Override + protected List getTableVisibleColumns() { + final List columnList = super.getTableVisibleColumns(); + final float versionColumnSize = isMaximized() ? 0.1f : 0.2f; + columnList + .add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), versionColumnSize)); + return columnList; + } + + @SuppressWarnings("unchecked") + @Override + protected void updateEntity(final E baseEntity, final Item item) { + super.updateEntity(baseEntity, item); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index be77cfaf2..5aea8914f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -293,7 +293,8 @@ public abstract class AbstractTable extends Table { protected List getTableVisibleColumns() { final List columnList = new ArrayList<>(); if (!isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), + getColumnNameMinimizedSize())); return columnList; } columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); @@ -306,6 +307,10 @@ public abstract class AbstractTable extends Table { return columnList; } + protected float getColumnNameMinimizedSize() { + return 0.8F; + } + /** * Get drop handler for the table. * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 51f30117a..c49a89368 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -28,7 +28,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; -import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; @@ -70,7 +70,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionSetTable extends AbstractTable { +public class DistributionSetTable extends AbstractNamedVersionTable { private static final long serialVersionUID = -7731776093470487988L; @@ -475,11 +475,10 @@ public class DistributionSetTable extends AbstractTable unselect(dsNameId)); + manageDistUIState.getSelectedDistributions().get().stream().forEach(this::unselect); } select(baseEntity.getDistributionSetIdName()); return item; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index dac8d2ecf..9c02f1d8a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.distributions.smtable; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,7 +19,7 @@ import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.common.ManagmentEntityState; -import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; @@ -63,7 +62,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class SwModuleTable extends AbstractTable { +public class SwModuleTable extends AbstractNamedVersionTable { private static final long serialVersionUID = 6785314784507424750L; @@ -228,19 +227,20 @@ public class SwModuleTable extends AbstractTable { @Override protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); + final List columnList = super.getTableVisibleColumns(); if (isMaximized()) { - columnList.addAll(super.getTableVisibleColumns()); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1f)); } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.7F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); columnList.add(new TableColumn(SPUILabelDefinitions.ARTIFACT_ICON, "", 0.1F)); } return columnList; } + @Override + protected float getColumnNameMinimizedSize() { + return 0.7F; + } + @Override protected DropHandler getTableDropHandler() { return new DropHandler() { @@ -332,12 +332,11 @@ public class SwModuleTable extends AbstractTable { baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); item.getItemProperty("swId").setValue(baseEntity.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).setValue(baseEntity.getType().getColour()); if (!manageDistUIState.getSelectedSoftwareModules().isEmpty()) { - manageDistUIState.getSelectedSoftwareModules().stream().forEach(swmNameId -> unselect(swmNameId)); + manageDistUIState.getSelectedSoftwareModules().stream().forEach(this::unselect); } select(baseEntity.getId()); return item; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 44574fb3a..4ba164bde 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -25,7 +25,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; -import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; @@ -70,7 +70,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionTable extends AbstractTable { +public class DistributionTable extends AbstractNamedVersionTable { private static final long serialVersionUID = -1928335256399519494L; @@ -272,18 +272,19 @@ public class DistributionTable extends AbstractTable getTableVisibleColumns() { - final List columnList = new ArrayList<>(); + final List columnList = super.getTableVisibleColumns(); if (isMaximized()) { - columnList.addAll(super.getTableVisibleColumns()); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.7f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2f)); - columnList.add(new TableColumn(SPUILabelDefinitions.PIN_COLUMN, StringUtils.EMPTY, 0.1f)); + return columnList; } + columnList.add(new TableColumn(SPUILabelDefinitions.PIN_COLUMN, StringUtils.EMPTY, 0.1f)); return columnList; } + @Override + protected float getColumnNameMinimizedSize() { + return 0.7F; + } + @Override protected DropHandler getTableDropHandler() { return new DropHandler() { @@ -478,13 +479,6 @@ public class DistributionTable extends AbstractTable Date: Thu, 7 Apr 2016 14:13:27 +0200 Subject: [PATCH 10/49] Remove full qualified pakcage Signed-off-by: SirWayne --- .../hawkbit/ui/distributions/state/ManageDistUIState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java index 11a0a0ff2..a68a42e00 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java @@ -117,7 +117,7 @@ public class ManageDistUIState implements ManagmentEntityState values) { + public void setSelectedEnitities(final Set values) { selectedDistributions = values; } From 08e0dc4b3db62941e96cb5a3f52322afdd075350 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 14:16:43 +0200 Subject: [PATCH 11/49] Add new abstract table to reduce the visible columns and add entity code Signed-off-by: SirWayne --- .../distributions/dstable/DistributionSetTable.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index c49a89368..1cd89b30f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -42,7 +42,6 @@ import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; -import org.eclipse.hawkbit.ui.utils.TableColumn; import org.eclipse.hawkbit.ui.utils.UINotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -190,17 +189,6 @@ public class DistributionSetTable extends AbstractNamedVersionTable getTableVisibleColumns() { - final List columnList = super.getTableVisibleColumns(); - if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2f)); - } - return columnList; - } - @Override protected DropHandler getTableDropHandler() { return new DropHandler() { From 4e2fd2befdf833fb94b4c79fa6c7e2a766d8b817 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 14:33:51 +0200 Subject: [PATCH 12/49] Add missing TargetTagDeletedEvent Signed-off-by: SirWayne --- .../main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java index 12bcaacbc..842cfcab5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java @@ -21,6 +21,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; +import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; /** * The default hawkbit event provider. @@ -34,6 +35,7 @@ public class HawkbitEventProvider implements UIEventProvider { SINGLE_EVENTS.add(TargetTagCreatedBulkEvent.class); SINGLE_EVENTS.add(DistributionSetTagCreatedBulkEvent.class); SINGLE_EVENTS.add(DistributionSetTagDeletedEvent.class); + SINGLE_EVENTS.add(TargetTagDeletedEvent.class); SINGLE_EVENTS.add(DistributionSetTagUpdateEvent.class); SINGLE_EVENTS.add(RolloutGroupChangeEvent.class); SINGLE_EVENTS.add(RolloutChangeEvent.class); From 929916165253b7f11ee072d7eb83069ece848e2b Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 7 Apr 2016 14:43:05 +0200 Subject: [PATCH 13/49] Added anonymous download section as part of authentication configuration section Signed-off-by: Jonathan Philip Knoblauch --- .../AuthenticationConfigurationView.java | 20 ++- .../DownloadAnonymousConfigurationView.java | 119 ------------------ .../TenantConfigurationDashboardView.java | 4 - ...wnloadAuthenticationConfigurationItem.java | 86 +++++++++++++ 4 files changed, 105 insertions(+), 124 deletions(-) delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java index d00223f5a..f3c42552e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; +import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.AnonymousDownloadAuthenticationConfigurationItem; import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.AuthenticationConfigurationItem; import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.CertificateAuthenticationConfigurationItem; import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.GatewaySecurityTokenAuthenticationConfigurationItem; @@ -52,12 +53,17 @@ public class AuthenticationConfigurationView extends BaseConfigurationView @Autowired private GatewaySecurityTokenAuthenticationConfigurationItem gatewaySecurityTokenAuthenticationConfigurationItem; + @Autowired + private AnonymousDownloadAuthenticationConfigurationItem anonymousDownloadAuthenticationConfigurationItem; + private CheckBox gatewaySecTokenCheckBox; private CheckBox targetSecTokenCheckBox; private CheckBox certificateAuthCheckbox; + private CheckBox downloadAnonymousCheckBox; + /** * Initialize Authentication Configuration layout. */ @@ -77,7 +83,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView headerDisSetType.addStyleName("config-panel-header"); vLayout.addComponent(headerDisSetType); - final GridLayout gridLayout = new GridLayout(2, 3); + final GridLayout gridLayout = new GridLayout(2, 4); gridLayout.setSpacing(true); gridLayout.setImmediate(true); gridLayout.setColumnExpandRatio(1, 1.0F); @@ -105,6 +111,13 @@ public class AuthenticationConfigurationView extends BaseConfigurationView gridLayout.addComponent(gatewaySecTokenCheckBox, 0, 2); gridLayout.addComponent(gatewaySecurityTokenAuthenticationConfigurationItem, 1, 2); + downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); + downloadAnonymousCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); + downloadAnonymousCheckBox.addValueChangeListener(this); + anonymousDownloadAuthenticationConfigurationItem.addChangeListener(this); + gridLayout.addComponent(downloadAnonymousCheckBox, 0, 3); + gridLayout.addComponent(anonymousDownloadAuthenticationConfigurationItem, 1, 3); + vLayout.addComponent(gridLayout); rootPanel.setContent(vLayout); setCompositionRoot(rootPanel); @@ -115,6 +128,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView certificateAuthenticationConfigurationItem.save(); targetSecurityTokenAuthenticationConfigurationItem.save(); gatewaySecurityTokenAuthenticationConfigurationItem.save(); + anonymousDownloadAuthenticationConfigurationItem.save(); } @Override @@ -122,9 +136,11 @@ public class AuthenticationConfigurationView extends BaseConfigurationView certificateAuthenticationConfigurationItem.undo(); targetSecurityTokenAuthenticationConfigurationItem.undo(); gatewaySecurityTokenAuthenticationConfigurationItem.undo(); + anonymousDownloadAuthenticationConfigurationItem.undo(); certificateAuthCheckbox.setValue(certificateAuthenticationConfigurationItem.isConfigEnabled()); targetSecTokenCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); gatewaySecTokenCheckBox.setValue(gatewaySecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); + downloadAnonymousCheckBox.setValue(anonymousDownloadAuthenticationConfigurationItem.isConfigEnabled()); } @Override @@ -150,6 +166,8 @@ public class AuthenticationConfigurationView extends BaseConfigurationView configurationItem = targetSecurityTokenAuthenticationConfigurationItem; } else if (checkBox == certificateAuthCheckbox) { configurationItem = certificateAuthenticationConfigurationItem; + } else if (checkBox == downloadAnonymousCheckBox) { + configurationItem = anonymousDownloadAuthenticationConfigurationItem; } else { return; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java deleted file mode 100644 index e008e03f2..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.tenantconfiguration; - -import javax.annotation.PostConstruct; - -import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; -import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; -import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.springframework.beans.factory.annotation.Autowired; - -import com.vaadin.spring.annotation.SpringComponent; -import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Panel; -import com.vaadin.ui.VerticalLayout; - -/** - * View to enable anonymous download. - */ -@SpringComponent -@ViewScope -public class DownloadAnonymousConfigurationView extends BaseConfigurationView - implements ConfigurationItem.ConfigurationItemChangeListener { - - private static final String DIST_CHECKBOX_STYLE = "dist-checkbox-style"; - - private static final long serialVersionUID = 1L; - - @Autowired - private I18N i18n; - - @Autowired - private transient TenantConfigurationManagement tenantConfigurationManagement; - - boolean anonymousDownloadEnabled; - - private CheckBox downloadAnonymousCheckBox; - - /** - * Initialize Default Download Anonymous layout. - */ - @PostConstruct - public void init() { - - final TenantConfigurationValue value = tenantConfigurationManagement - .getConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class); - anonymousDownloadEnabled = value.getValue(); - - final Panel rootPanel = new Panel(); - rootPanel.setSizeFull(); - rootPanel.addStyleName("config-panel"); - - final VerticalLayout vLayout = new VerticalLayout(); - vLayout.setMargin(true); - vLayout.setSizeFull(); - - final Label headerDisSetType = new Label(i18n.get("enonymous.download.title")); - headerDisSetType.addStyleName("config-panel-header"); - vLayout.addComponent(headerDisSetType); - - final GridLayout gridLayout = new GridLayout(2, 1); - gridLayout.setSpacing(true); - gridLayout.setImmediate(true); - gridLayout.setColumnExpandRatio(1, 1.0F); - gridLayout.setSizeFull(); - - downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); - downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled); - downloadAnonymousCheckBox.addValueChangeListener(event -> configurationHasChanged()); - downloadAnonymousCheckBox.setId(SPUIComponetIdProvider.SYSTEM_CONFIGURATION_ANONYMOUS_DOWNLOAD_CHECKBOX); - - gridLayout.addComponent(downloadAnonymousCheckBox); - - final Label configurationLabel = SPUIComponentProvider.getLabel(i18n.get("enonymous.download.label"), - SPUILabelDefinitions.SP_LABEL_SIMPLE); - gridLayout.addComponent(configurationLabel); - gridLayout.setComponentAlignment(configurationLabel, Alignment.MIDDLE_LEFT); - - vLayout.addComponent(gridLayout); - - rootPanel.setContent(vLayout); - setCompositionRoot(rootPanel); - } - - @Override - public void configurationHasChanged() { - anonymousDownloadEnabled = downloadAnonymousCheckBox.getValue(); - notifyConfigurationChanged(); - } - - @Override - public void save() { - tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, - downloadAnonymousCheckBox.getValue()); - } - - @Override - public void undo() { - final TenantConfigurationValue value = tenantConfigurationManagement - .getConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class); - anonymousDownloadEnabled = value.getValue(); - downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled); - } - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java index cada6d167..d021254bc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java @@ -55,9 +55,6 @@ public class TenantConfigurationDashboardView extends CustomComponent implements @Autowired private PollingConfigurationView pollingConfigurationView; - @Autowired - private DownloadAnonymousConfigurationView downloadAnonymousConfigurationView; - @Autowired private I18N i18n; @@ -80,7 +77,6 @@ public class TenantConfigurationDashboardView extends CustomComponent implements configurationViews.add(defaultDistributionSetTypeLayout); configurationViews.add(authenticationConfigurationView); configurationViews.add(pollingConfigurationView); - configurationViews.add(downloadAnonymousConfigurationView); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java new file mode 100644 index 000000000..3c5a95df1 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.tenantconfiguration.authentication; + +import javax.annotation.PostConstruct; + +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.springframework.beans.factory.annotation.Autowired; + +import com.vaadin.spring.annotation.SpringComponent; +import com.vaadin.spring.annotation.ViewScope; + +/** + * This class represents the UI item for the anonymous download by in the + * authentication configuration view. + */ +@SpringComponent +@ViewScope +public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAuthenticationTenantConfigurationItem { + + private static final long serialVersionUID = 1L; + + private boolean configurationEnabled = false; + private boolean configurationEnabledChange = false; + + @Autowired + private I18N i18n; + + @Autowired + public AnonymousDownloadAuthenticationConfigurationItem( + final TenantConfigurationManagement tenantConfigurationManagement) { + super(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, tenantConfigurationManagement); + } + + @PostConstruct + public void init() { + + super.init(i18n.get("enonymous.download.label")); + configurationEnabled = isConfigEnabled(); + + } + + @Override + public void configEnable() { + + if (!configurationEnabled) { + configurationEnabledChange = true; + } + configurationEnabled = true; + } + + @Override + public void configDisable() { + if (configurationEnabled) { + configurationEnabledChange = true; + } + configurationEnabled = false; + } + + @Override + public void save() { + if (!configurationEnabledChange) { + return; + } + getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled); + + } + + @Override + public void undo() { + + configurationEnabledChange = false; + configurationEnabled = getTenantConfigurationManagement() + .getConfigurationValue(getConfigurationKey(), Boolean.class).getValue(); + + } + +} From 7281c0e84e24d09e15228b972e0cf1edb055224b Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 7 Apr 2016 15:25:31 +0200 Subject: [PATCH 14/49] Added description for anonymous download checkbox Signed-off-by: Jonathan Philip Knoblauch --- .../AnonymousDownloadAuthenticationConfigurationItem.java | 2 +- hawkbit-ui/src/main/resources/messages.properties | 3 +-- hawkbit-ui/src/main/resources/messages_de.properties | 4 ++-- hawkbit-ui/src/main/resources/messages_en.properties | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java index 3c5a95df1..b1da8e0ee 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java @@ -43,7 +43,7 @@ public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAu @PostConstruct public void init() { - super.init(i18n.get("enonymous.download.label")); + super.init(i18n.get("label.configuration.anonymous.download")); configurationEnabled = isConfigEnabled(); } diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index ebdcfa76f..d2e36dd2d 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -161,6 +161,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token +label.configuration.anonymous.download = Allow targets to download anonymous label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox @@ -401,8 +402,6 @@ configuration.polling.title=Polling Configuration configuration.polling.time=Polling Time configuration.polling.overduetime=Polling Overdue Time configuration.polling.custom.value=use a custom value -enonymous.download.title=Anonymous download -enonymous.download.label=Allow anonymous download. If you enable this option the download server will accept anonymous download requests. #Calendar calendar.year=year diff --git a/hawkbit-ui/src/main/resources/messages_de.properties b/hawkbit-ui/src/main/resources/messages_de.properties index 47cb36f31..98ac9edb3 100644 --- a/hawkbit-ui/src/main/resources/messages_de.properties +++ b/hawkbit-ui/src/main/resources/messages_de.properties @@ -159,6 +159,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token +label.configuration.anonymous.download = Allow targets to download anonymous label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox @@ -389,8 +390,7 @@ configuration.defaultdistributionset.select.label=Wahl des default Distribution configuration.savebutton.tooltip=Konfigurationen speichern configuration.cancellbutton.tooltip=Konfigurationen zur�cksetzen configuration.authentication.title=Authentifikationseinstellungen -enonymous.download.title=Anonymes herunterladen -enonymous.download.label=Erlaube anonymes herunterladen. When diese option aktivert ist, wird der download server anonyme download anfragen erlauben. + #Calendar calendar.year=Jahr calendar.years=Jahre diff --git a/hawkbit-ui/src/main/resources/messages_en.properties b/hawkbit-ui/src/main/resources/messages_en.properties index 50c04ad46..d6b4b1088 100644 --- a/hawkbit-ui/src/main/resources/messages_en.properties +++ b/hawkbit-ui/src/main/resources/messages_en.properties @@ -160,6 +160,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token +label.configuration.anonymous.download = Allow targets to download anonymous label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox @@ -383,8 +384,6 @@ configuration.authentication.title=Authentication Configuration controller.polling.title=Polling Configuration controller.polling.time=Polling Time controller.polling.overduetime=Polling Overdue Time -enonymous.download.title=Anonymous download -enonymous.download.label=Allow anonymous download. If you enable this option the download server will accept anonymous download requests. #Calendar calendar.year=year From d815aaf12c28a12f3478c99c55ea7b30cf9842ae Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 7 Apr 2016 15:58:25 +0200 Subject: [PATCH 15/49] Added id to anonymous download checkbox Signed-off-by: Jonathan Philip Knoblauch --- .../ui/tenantconfiguration/AuthenticationConfigurationView.java | 1 + 1 file changed, 1 insertion(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java index f3c42552e..616acaf3f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java @@ -112,6 +112,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView gridLayout.addComponent(gatewaySecurityTokenAuthenticationConfigurationItem, 1, 2); downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); + downloadAnonymousCheckBox.setId("downloadanonymouscheckbox"); downloadAnonymousCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); downloadAnonymousCheckBox.addValueChangeListener(this); anonymousDownloadAuthenticationConfigurationItem.addChangeListener(this); From 1e28acb1704d0394550a9db1e65570ec3bed361a Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 8 Apr 2016 08:16:47 +0200 Subject: [PATCH 16/49] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 461e12e81..0a9b0b4c6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ https://hawkbit.eu-gb.mybluemix.net/UI/ # Compile, Run and Getting Started -We are not providing an off the shelf installation ready hawkBit update server. However, we recommend to check out the [Example Application](examples/hawkbit-example-app) for a runtime ready Spring Boot based update server that is empowered by hawkBit. +We are not providing an off the shelf installation ready hawkBit update server. However, we recommend to check out the [Example Application](examples/hawkbit-example-app) for a runtime ready Spring Boot based update server that is empowered by hawkBit. In addition we have [guide](https://github.com/eclipse/hawkbit/wiki/Run-hawkBit) for setting up a complete landscape. #### Clone and build hawkBit ``` From a021630c0491fefc8d8c312116958fa4e5c58f65 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 10:12:16 +0200 Subject: [PATCH 17/49] Remove empty lines Signed-off-by: SirWayne --- .../hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java | 1 - .../hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java | 1 - .../eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java | 1 - .../confirmwindow/layout/AbstractConfirmationWindowLayout.java | 1 - 4 files changed, 4 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java index 397f0cf2b..d839be40d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java @@ -141,5 +141,4 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta protected String getDetailsHeaderCaptionId() { return SPUIComponetIdProvider.TARGET_DETAILS_HEADER_LABEL_ID; } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 1ef4b8f7a..f101c94a7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -206,6 +206,5 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable, Serializ public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) { this.selectedBaseSoftwareModule = selectedBaseSoftwareModule; } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java index bc5de63ff..f4fe21425 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java @@ -148,5 +148,4 @@ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { deletesDsIcon.addClickListener(clickListener); return deletesDsIcon; } - } From 3070dcfc3d99d1361bf4e788c3aa0d1d30052114 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 15:01:26 +0200 Subject: [PATCH 18/49] Modify scope of protected attributes to private. Create getter/setter to access the the attribute. see clean code Protected variables should be avoided because: http://programmers.stackexchange.com/questions/162643/why-is-clean-code-suggesting-avoiding-protected-variables Signed-off-by: SirWayne --- .../smtable/SoftwareModuleDetails.java | 30 ++++---- ...amedVersionedEntityTableDetailsLayout.java | 3 +- .../AbstractTableDetailsLayout.java | 30 ++++++-- .../dstable/DistributionSetDetails.java | 58 +++++++------- .../smtable/SwModuleDetails.java | 30 ++++---- .../dstable/DistributionDetails.java | 30 ++++---- .../management/targettable/TargetDetails.java | 76 +++++++++---------- 7 files changed, 135 insertions(+), 122 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java index d839be40d..9d535f7f5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java @@ -52,16 +52,16 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @Override protected void onEdit(final ClickEvent event) { final Window addSoftwareModule = softwareModuleAddUpdateWindow .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId()); - addSoftwareModule.setCaption(i18n.get("upload.caption.update.swmodule")); + addSoftwareModule.setCaption(getI18n().get("upload.caption.update.swmodule")); UI.getCurrent().addWindow(addSoftwareModule); addSoftwareModule.setVisible(Boolean.TRUE); } @@ -69,14 +69,14 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @Override protected void populateDetailsWidget() { String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY; - if (selectedBaseEntity != null) { - if (selectedBaseEntity.getType().getMaxAssignments() == Integer.MAX_VALUE) { - maxAssign = i18n.get("label.multiAssign.type"); + if (getSelectedBaseEntity() != null) { + if (getSelectedBaseEntity().getType().getMaxAssignments() == Integer.MAX_VALUE) { + maxAssign = getI18n().get("label.multiAssign.type"); } else { - maxAssign = i18n.get("label.singleAssign.type"); + maxAssign = getI18n().get("label.singleAssign.type"); } - updateSoftwareModuleDetailsLayout(selectedBaseEntity.getType().getName(), selectedBaseEntity.getVendor(), - maxAssign); + updateSoftwareModuleDetailsLayout(getSelectedBaseEntity().getType().getName(), + getSelectedBaseEntity().getVendor(), maxAssign); } else { updateSoftwareModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY, maxAssign); @@ -88,19 +88,19 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta detailsTabLayout.removeAllComponents(); - final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.vendor"), + final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.vendor"), HawkbitCommonUtil.trimAndNullIfEmpty(vendor) == null ? "" : vendor); vendorLabel.setId(SPUIComponetIdProvider.DETAILS_VENDOR_LABEL_ID); detailsTabLayout.addComponent(vendorLabel); if (type != null) { - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.type"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"), type); typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID); detailsTabLayout.addComponent(typeLabel); } - final Label assignLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.assigned.type"), + final Label assignLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.assigned.type"), HawkbitCommonUtil.trimAndNullIfEmpty(maxAssign) == null ? "" : maxAssign); assignLabel.setId(SPUIComponetIdProvider.SWM_DTLS_MAX_ASSIGN); detailsTabLayout.addComponent(assignLabel); @@ -109,7 +109,7 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @Override protected String getDefaultCaption() { - return i18n.get("upload.swModuleTable.header"); + return getI18n().get("upload.swModuleTable.header"); } @Override @@ -129,7 +129,7 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateDistributionPermission(); + return getPermissionChecker().hasUpdateDistributionPermission(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java index 19bfb324e..3ccbb8ad7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java @@ -22,6 +22,7 @@ public abstract class AbstractNamedVersionedEntityTableDetailsLayout extends private static final long serialVersionUID = 4862529368471627190L; @Autowired - protected I18N i18n; + private I18N i18n; @Autowired - protected transient EventBus.SessionEventBus eventBus; + private transient EventBus.SessionEventBus eventBus; @Autowired - protected SpPermissionChecker permissionChecker; + private SpPermissionChecker permissionChecker; - protected T selectedBaseEntity; + private T selectedBaseEntity; private Label caption; @@ -89,6 +89,26 @@ public abstract class AbstractTableDetailsLayout extends eventBus.unsubscribe(this); } + protected SpPermissionChecker getPermissionChecker() { + return permissionChecker; + } + + protected EventBus.SessionEventBus getEventBus() { + return eventBus; + } + + protected I18N getI18n() { + return i18n; + } + + protected T getSelectedBaseEntity() { + return selectedBaseEntity; + } + + public void setSelectedBaseEntity(final T selectedBaseEntity) { + this.selectedBaseEntity = selectedBaseEntity; + } + /** * Default implementation to handle a entity event. * @@ -118,7 +138,7 @@ public abstract class AbstractTableDetailsLayout extends editButton = SPUIComponentProvider.getButton("", "", "", null, false, FontAwesome.PENCIL_SQUARE_O, SPUIButtonStyleSmallNoBorder.class); editButton.setId(getEditButtonId()); - editButton.addClickListener(event -> onEdit(event)); + editButton.addClickListener(this::onEdit); editButton.setEnabled(false); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index 64a9819bb..a1d1ffcfe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -92,7 +92,8 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet @Override protected void init() { softwareModuleTable = new SoftwareModuleDetailsTable(); - softwareModuleTable.init(i18n, true, permissionChecker, distributionSetManagement, eventBus, manageDistUIState); + softwareModuleTable.init(getI18n(), true, getPermissionChecker(), distributionSetManagement, getEventBus(), + manageDistUIState); super.init(); } @@ -109,7 +110,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet } private void populateModule() { - softwareModuleTable.populateModule(selectedBaseEntity); + softwareModuleTable.populateModule(getSelectedBaseEntity()); showUnsavedAssignment(); } @@ -157,12 +158,8 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet } } - /** - * @param item - * @param entry - */ private void assignSoftModuleButton(final Item item, final Map.Entry entry) { - if (permissionChecker.hasUpdateDistributionPermission() && distributionSetManagement + if (getPermissionChecker().hasUpdateDistributionPermission() && distributionSetManagement .findDistributionSetById(manageDistUIState.getLastSelectedDistribution().get().getId()) .getAssignedTargets().isEmpty()) { final Button reassignSoftModule = SPUIComponentProvider.getButton(entry.getKey(), "", "", "", true, @@ -227,15 +224,16 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet private void populateTags() { tagsLayout.removeAllComponents(); - if (null != selectedBaseEntity) { - tagsLayout.addComponent(distributionTagToken.getTokenField()); + if (getSelectedBaseEntity() == null) { + return; } + tagsLayout.addComponent(distributionTagToken.getTokenField()); } private void populateDetails() { - if (selectedBaseEntity != null) { - updateDistributionSetDetailsLayout(selectedBaseEntity.getType().getName(), - selectedBaseEntity.isRequiredMigrationStep()); + if (getSelectedBaseEntity() != null) { + updateDistributionSetDetailsLayout(getSelectedBaseEntity().getType().getName(), + getSelectedBaseEntity().isRequiredMigrationStep()); } else { updateDistributionSetDetailsLayout(null, null); } @@ -246,16 +244,16 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet detailsTabLayout.removeAllComponents(); if (type != null) { - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.type"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"), type); typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID); detailsTabLayout.addComponent(typeLabel); } if (isMigrationRequired != null) { - detailsTabLayout.addComponent( - SPUIComponentProvider.createNameValueLabel(i18n.get("checkbox.dist.migration.required"), - isMigrationRequired.equals(Boolean.TRUE) ? i18n.get("label.yes") : i18n.get("label.no"))); + detailsTabLayout.addComponent(SPUIComponentProvider.createNameValueLabel( + getI18n().get("checkbox.dist.migration.required"), + isMigrationRequired.equals(Boolean.TRUE) ? getI18n().get("label.yes") : getI18n().get("label.no"))); } } @@ -263,7 +261,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId()); - newDistWindow.setCaption(i18n.get("caption.update.dist")); + newDistWindow.setCaption(getI18n().get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); } @@ -286,21 +284,21 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet @Override protected String getDefaultCaption() { - return i18n.get("distribution.details.header"); + return getI18n().get("distribution.details.header"); } @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createSoftwareModuleTab(), i18n.get("caption.softwares.distdetail.tab"), null); - detailsTab.addTab(createTagsLayout(), i18n.get("caption.tags.tab"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createSoftwareModuleTab(), getI18n().get("caption.softwares.distdetail.tab"), null); + detailsTab.addTab(createTagsLayout(), getI18n().get("caption.tags.tab"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateDistributionPermission(); + return getPermissionChecker().hasUpdateDistributionPermission(); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -322,9 +320,9 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet final DistributionSetIdName distIdName = softwareModuleAssignmentDiscardEvent .getDistributionSetIdName(); if (distIdName.getId().equals(getSelectedBaseEntityId()) - && distIdName.getName().equals(selectedBaseEntity.getName())) { - selectedBaseEntity = distributionSetManagement - .findDistributionSetByIdWithDetails(getSelectedBaseEntityId()); + && distIdName.getName().equals(getSelectedBaseEntity().getName())) { + setSelectedBaseEntity( + distributionSetManagement.findDistributionSetByIdWithDetails(getSelectedBaseEntityId())); populateModule(); } }); @@ -335,10 +333,10 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet void onEvent(final SaveActionWindowEvent saveActionWindowEvent) { if ((saveActionWindowEvent == SaveActionWindowEvent.SAVED_ASSIGNMENTS || saveActionWindowEvent == SaveActionWindowEvent.DISCARD_ALL_ASSIGNMENTS) - && selectedBaseEntity != null) { + && getSelectedBaseEntity() != null) { assignedSWModule.clear(); - selectedBaseEntity = distributionSetManagement - .findDistributionSetByIdWithDetails(getSelectedBaseEntityId()); + setSelectedBaseEntity( + distributionSetManagement.findDistributionSetByIdWithDetails(getSelectedBaseEntityId())); UI.getCurrent().access(() -> populateModule()); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java index e1c39ee89..8774c9e08 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java @@ -54,7 +54,7 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay protected void onEdit(final ClickEvent event) { final Window addSoftwareModule = softwareModuleAddUpdateWindow .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId()); - addSoftwareModule.setCaption(i18n.get("upload.caption.update.swmodule")); + addSoftwareModule.setCaption(getI18n().get("upload.caption.update.swmodule")); UI.getCurrent().addWindow(addSoftwareModule); addSoftwareModule.setVisible(Boolean.TRUE); } @@ -66,14 +66,14 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @Override protected String getDefaultCaption() { - return i18n.get("upload.swModuleTable.header"); + return getI18n().get("upload.swModuleTable.header"); } @Override @@ -88,7 +88,7 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateDistributionPermission(); + return getPermissionChecker().hasUpdateDistributionPermission(); } @Override @@ -98,14 +98,14 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay private void populateDetails() { String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY; - if (selectedBaseEntity != null) { - if (selectedBaseEntity.getType().getMaxAssignments() == Integer.MAX_VALUE) { - maxAssign = i18n.get("label.multiAssign.type"); + if (getSelectedBaseEntity() != null) { + if (getSelectedBaseEntity().getType().getMaxAssignments() == Integer.MAX_VALUE) { + maxAssign = getI18n().get("label.multiAssign.type"); } else { - maxAssign = i18n.get("label.singleAssign.type"); + maxAssign = getI18n().get("label.singleAssign.type"); } - updateSwModuleDetailsLayout(selectedBaseEntity.getType().getName(), selectedBaseEntity.getVendor(), - maxAssign); + updateSwModuleDetailsLayout(getSelectedBaseEntity().getType().getName(), + getSelectedBaseEntity().getVendor(), maxAssign); } else { updateSwModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY, maxAssign); @@ -117,19 +117,19 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay final VerticalLayout detailsTabLayout = getDetailsLayout(); detailsTabLayout.removeAllComponents(); - final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.vendor"), + final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.vendor"), HawkbitCommonUtil.trimAndNullIfEmpty(vendor) == null ? "" : vendor); vendorLabel.setId(SPUIComponetIdProvider.DETAILS_VENDOR_LABEL_ID); detailsTabLayout.addComponent(vendorLabel); if (type != null) { - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.type"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"), type); typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID); detailsTabLayout.addComponent(typeLabel); } - final Label assignLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.assigned.type"), + final Label assignLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.assigned.type"), HawkbitCommonUtil.trimAndNullIfEmpty(maxAssign) == null ? "" : maxAssign); assignLabel.setId(SPUIComponetIdProvider.SWM_DTLS_MAX_ASSIGN); detailsTabLayout.addComponent(assignLabel); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java index aedce157e..81151b076 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java @@ -52,7 +52,7 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail @Override protected void init() { softwareModuleTable = new SoftwareModuleDetailsTable(); - softwareModuleTable.init(i18n, false, permissionChecker, null, null, null); + softwareModuleTable.init(getI18n(), false, getPermissionChecker(), null, null, null); super.init(); } @@ -63,23 +63,23 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail @Override protected String getDefaultCaption() { - return i18n.get("distribution.details.header"); + return getI18n().get("distribution.details.header"); } @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createSoftwareModuleTab(), i18n.get("caption.softwares.distdetail.tab"), null); - detailsTab.addTab(createTagsLayout(), i18n.get("caption.tags.tab"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createSoftwareModuleTab(), getI18n().get("caption.softwares.distdetail.tab"), null); + detailsTab.addTab(createTagsLayout(), getI18n().get("caption.tags.tab"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @Override protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId()); - newDistWindow.setCaption(i18n.get("caption.update.dist")); + newDistWindow.setCaption(getI18n().get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); } @@ -102,7 +102,7 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateDistributionPermission(); + return getPermissionChecker().hasUpdateDistributionPermission(); } @Override @@ -112,8 +112,8 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail @Override protected void populateDetailsWidget() { - softwareModuleTable.populateModule(selectedBaseEntity); - populateDetails(selectedBaseEntity); + softwareModuleTable.populateModule(getSelectedBaseEntity()); + populateDetails(getSelectedBaseEntity()); } @@ -130,16 +130,16 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail detailsTabLayout.removeAllComponents(); if (type != null) { - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.type"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"), type); typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID); detailsTabLayout.addComponent(typeLabel); } if (isMigrationRequired != null) { - detailsTabLayout.addComponent( - SPUIComponentProvider.createNameValueLabel(i18n.get("checkbox.dist.migration.required"), - isMigrationRequired.equals(Boolean.TRUE) ? i18n.get("label.yes") : i18n.get("label.no"))); + detailsTabLayout.addComponent(SPUIComponentProvider.createNameValueLabel( + getI18n().get("checkbox.dist.migration.required"), + isMigrationRequired.equals(Boolean.TRUE) ? getI18n().get("label.yes") : getI18n().get("label.no"))); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java index 6105409bf..8ab4f8b0d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java @@ -43,9 +43,6 @@ import com.vaadin.ui.themes.ValoTheme; /** * Target details layout. - * - * - * */ @SpringComponent @ViewScope @@ -65,9 +62,6 @@ public class TargetDetails extends AbstractTableDetailsLayout { private VerticalLayout assignedDistLayout; private VerticalLayout installedDistLayout; - /** - * Initialize the Target details. - */ @Override public void init() { super.init(); @@ -76,18 +70,18 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected String getDefaultCaption() { - return i18n.get("target.details.header"); + return getI18n().get("target.details.header"); } @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createAttributesLayout(), i18n.get("caption.attributes.tab"), null); - detailsTab.addTab(createAssignedDistLayout(), i18n.get("header.target.assigned"), null); - detailsTab.addTab(createInstalledDistLayout(), i18n.get("header.target.installed"), null); - detailsTab.addTab(createTagsLayout(), i18n.get("caption.tags.tab"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createAttributesLayout(), getI18n().get("caption.attributes.tab"), null); + detailsTab.addTab(createAssignedDistLayout(), getI18n().get("header.target.assigned"), null); + detailsTab.addTab(createInstalledDistLayout(), getI18n().get("header.target.installed"), null); + detailsTab.addTab(createTagsLayout(), getI18n().get("caption.tags.tab"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @@ -109,12 +103,12 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void onEdit(final ClickEvent event) { - if (selectedBaseEntity == null) { + if (getSelectedBaseEntity() == null) { return; } final Window newDistWindow = targetAddUpdateWindowLayout.getWindow(); - targetAddUpdateWindowLayout.populateValuesOfTarget(selectedBaseEntity.getControllerId()); - newDistWindow.setCaption(i18n.get("caption.update.dist")); + targetAddUpdateWindowLayout.populateValuesOfTarget(getSelectedBaseEntity().getControllerId()); + newDistWindow.setCaption(getI18n().get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); } @@ -136,24 +130,24 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void populateDetailsWidget() { - if (selectedBaseEntity != null) { - updateDetailsLayout(selectedBaseEntity.getControllerId(), selectedBaseEntity.getTargetInfo().getAddress(), - selectedBaseEntity.getSecurityToken(), - SPDateTimeUtil.getFormattedDate(selectedBaseEntity.getTargetInfo().getLastTargetQuery())); + if (getSelectedBaseEntity() != null) { + updateDetailsLayout(getSelectedBaseEntity().getControllerId(), + getSelectedBaseEntity().getTargetInfo().getAddress(), getSelectedBaseEntity().getSecurityToken(), + SPDateTimeUtil.getFormattedDate(getSelectedBaseEntity().getTargetInfo().getLastTargetQuery())); populateDistributionDtls(installedDistLayout, - selectedBaseEntity.getTargetInfo().getInstalledDistributionSet()); - populateDistributionDtls(assignedDistLayout, selectedBaseEntity.getAssignedDistributionSet()); + getSelectedBaseEntity().getTargetInfo().getInstalledDistributionSet()); + populateDistributionDtls(assignedDistLayout, getSelectedBaseEntity().getAssignedDistributionSet()); } else { updateDetailsLayout(null, null, null, null); populateDistributionDtls(installedDistLayout, null); populateDistributionDtls(assignedDistLayout, null); } - updateAttributesLayout(selectedBaseEntity); + updateAttributesLayout(getSelectedBaseEntity()); } @Override protected String getName() { - return selectedBaseEntity.getName(); + return getSelectedBaseEntity().getName(); } private void updateDetailsLayout(final String controllerId, final URI address, final String securityToken, @@ -161,17 +155,18 @@ public class TargetDetails extends AbstractTableDetailsLayout { final VerticalLayout detailsTabLayout = getDetailsLayout(); detailsTabLayout.removeAllComponents(); - final Label controllerLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.target.id"), + final Label controllerLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.target.id"), HawkbitCommonUtil.trimAndNullIfEmpty(controllerId) == null ? "" : controllerId); controllerLabel.setId(SPUIComponetIdProvider.TARGET_CONTROLLER_ID); detailsTabLayout.addComponent(controllerLabel); - final Label lastPollDtLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.target.lastpolldate"), + final Label lastPollDtLabel = SPUIComponentProvider.createNameValueLabel( + getI18n().get("label.target.lastpolldate"), HawkbitCommonUtil.trimAndNullIfEmpty(lastQueryDate) == null ? "" : lastQueryDate); lastPollDtLabel.setId(SPUIComponetIdProvider.TARGET_LAST_QUERY_DT); detailsTabLayout.addComponent(lastPollDtLabel); - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.ip"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.ip"), address == null ? StringUtils.EMPTY : address.toString()); typeLabel.setId(SPUIComponetIdProvider.TARGET_IP_ADDRESS); detailsTabLayout.addComponent(typeLabel); @@ -187,7 +182,7 @@ public class TargetDetails extends AbstractTableDetailsLayout { final HorizontalLayout securityTokenLayout = new HorizontalLayout(); final Label securityTableLbl = new Label( - SPUIComponentProvider.getBoldHTMLText(i18n.get("label.target.security.token")), ContentMode.HTML); + SPUIComponentProvider.getBoldHTMLText(getI18n().get("label.target.security.token")), ContentMode.HTML); securityTableLbl.addStyleName(SPUIDefinitions.TEXT_STYLE); securityTableLbl.addStyleName("label-style"); @@ -207,18 +202,17 @@ public class TargetDetails extends AbstractTableDetailsLayout { private void populateDistributionDtls(final VerticalLayout layout, final DistributionSet distributionSet) { layout.removeAllComponents(); - if (distributionSet != null) { - // Display distribution set name - layout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.name"), - distributionSet.getName())); - - layout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.version"), - distributionSet.getVersion())); - - /* Module info */ - distributionSet.getModules() - .forEach(module -> layout.addComponent(getSWModlabel(module.getType().getName(), module))); + if (distributionSet == null) { + return; } + layout.addComponent(SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.name"), + distributionSet.getName())); + + layout.addComponent(SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.version"), + distributionSet.getVersion())); + + distributionSet.getModules() + .forEach(module -> layout.addComponent(getSWModlabel(module.getType().getName(), module))); } /** @@ -236,7 +230,7 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateTargetPermission(); + return getPermissionChecker().hasUpdateTargetPermission(); } @EventBusListenerMethod(scope = EventScope.SESSION) From b26cde62df32c0d8fb7306f1d24b89e944ad89a5 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 15:35:59 +0200 Subject: [PATCH 19/49] Use for float uppercase F Signed-off-by: SirWayne --- .../hawkbit/ui/common/table/AbstractTable.java | 2 +- .../ui/distributions/smtable/SwModuleTable.java | 2 +- .../ui/management/dstable/DistributionTable.java | 15 +-------------- .../ui/management/targettable/TargetTable.java | 4 ++-- 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 5aea8914f..eb1951d27 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -66,7 +66,7 @@ public abstract class AbstractTable extends Table { setStyleName("sp-table"); setSizeFull(); setImmediate(true); - setHeight(100.0f, Unit.PERCENTAGE); + setHeight(100.0F, Unit.PERCENTAGE); addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES); addStyleName(ValoTheme.TABLE_SMALL); setSortEnabled(false); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index 9c02f1d8a..a9a4562ce 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -229,7 +229,7 @@ public class SwModuleTable extends AbstractNamedVersionTable getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1f)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); } else { columnList.add(new TableColumn(SPUILabelDefinitions.ARTIFACT_ICON, "", 0.1F)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 4ba164bde..1b856277e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -173,24 +173,11 @@ public class DistributionTable extends AbstractNamedVersionTable queryConfiguration = prepareQueryConfigFilters(); @@ -276,7 +263,7 @@ public class DistributionTable extends AbstractNamedVersionTable implements protected List getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); if (!isMaximized()) { - columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_POLL_TIME, "", 0.0f)); - columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, "", 0.0f)); + columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_POLL_TIME, "", 0.0F)); + columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, "", 0.0F)); } return columnList; From 7731b549c327227277ca686d542f8d77936196e1 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 16:03:29 +0200 Subject: [PATCH 20/49] Use for float uppercase F Signed-off-by: SirWayne --- .../hawkbit/ui/common/table/AbstractNamedVersionTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java index 64460bc1c..3e215f77c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java @@ -31,7 +31,7 @@ public abstract class AbstractNamedVersionTable getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); - final float versionColumnSize = isMaximized() ? 0.1f : 0.2f; + final float versionColumnSize = isMaximized() ? 0.1F : 0.2F; columnList .add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), versionColumnSize)); return columnList; From 313751a3fd38ea1469fe7838bbc8f35a513f1bbb Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 16:05:38 +0200 Subject: [PATCH 21/49] fix typo Signed-off-by: SirWayne --- .../ui/common/detailslayout/AbstractTableDetailsLayout.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 615cba33f..969436904 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -110,7 +110,7 @@ public abstract class AbstractTableDetailsLayout extends } /** - * Default implementation to handle a entity event. + * Default implementation to handle an entity event. * * @param baseEntityEvent * the event @@ -127,9 +127,6 @@ public abstract class AbstractTableDetailsLayout extends } private void createComponents() { - /** - * Default caption is set.Reset on selecting table row. - */ caption = createHeaderCaption(); caption.setImmediate(true); caption.setContentMode(ContentMode.HTML); @@ -152,7 +149,6 @@ public abstract class AbstractTableDetailsLayout extends } private void buildLayout() { - final HorizontalLayout nameEditLayout = new HorizontalLayout(); nameEditLayout.setWidth(100.0f, Unit.PERCENTAGE); nameEditLayout.addComponent(caption); From 40478dd6752f2dbbccdf3f10952439aad165c06b Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Fri, 8 Apr 2016 17:15:15 +0200 Subject: [PATCH 22/49] Refactoring after review - changed label sentence - remove I18N to parent class - remove empty lines - set variable for configurationEnabledChange directly Signed-off-by: Jonathan Philip Knoblauch --- ...AuthenticationTenantConfigurationItem.java | 7 ++++++- ...wnloadAuthenticationConfigurationItem.java | 20 +++---------------- ...ficateAuthenticationConfigurationItem.java | 6 +----- ...yTokenAuthenticationConfigurationItem.java | 5 +---- ...yTokenAuthenticationConfigurationItem.java | 6 +----- .../src/main/resources/messages.properties | 2 +- .../src/main/resources/messages_de.properties | 2 +- .../src/main/resources/messages_en.properties | 2 +- 8 files changed, 15 insertions(+), 35 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java index 0907ebf9e..4f222f080 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java @@ -14,7 +14,9 @@ import java.util.List; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; +import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.ui.VerticalLayout; @@ -30,6 +32,9 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay private static final long serialVersionUID = 1L; + @Autowired + private I18N i18n; + private final TenantConfigurationKey configurationKey; private final transient TenantConfigurationManagement tenantConfigurationManagement; @@ -53,7 +58,7 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay */ protected void init(final String labelText) { setImmediate(true); - addComponent(SPUIComponentProvider.getLabel(labelText, SPUILabelDefinitions.SP_LABEL_SIMPLE)); + addComponent(SPUIComponentProvider.getLabel(i18n.get(labelText), SPUILabelDefinitions.SP_LABEL_SIMPLE)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java index b1da8e0ee..1180eba64 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java @@ -12,7 +12,6 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; -import org.eclipse.hawkbit.ui.utils.I18N; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -31,9 +30,6 @@ public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAu private boolean configurationEnabled = false; private boolean configurationEnabledChange = false; - @Autowired - private I18N i18n; - @Autowired public AnonymousDownloadAuthenticationConfigurationItem( final TenantConfigurationManagement tenantConfigurationManagement) { @@ -42,26 +38,19 @@ public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAu @PostConstruct public void init() { - - super.init(i18n.get("label.configuration.anonymous.download")); + super.init("label.configuration.anonymous.download"); configurationEnabled = isConfigEnabled(); - } @Override public void configEnable() { - - if (!configurationEnabled) { - configurationEnabledChange = true; - } + configurationEnabledChange = !configurationEnabled; configurationEnabled = true; } @Override public void configDisable() { - if (configurationEnabled) { - configurationEnabledChange = true; - } + configurationEnabledChange = configurationEnabled; configurationEnabled = false; } @@ -71,16 +60,13 @@ public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAu return; } getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled); - } @Override public void undo() { - configurationEnabledChange = false; configurationEnabled = getTenantConfigurationManagement() .getConfigurationValue(getConfigurationKey(), Boolean.class).getValue(); - } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java index b17d9596f..438917072 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java @@ -13,7 +13,6 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; @@ -35,9 +34,6 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti private static final long serialVersionUID = 1L; - @Autowired - private I18N i18n; - private boolean configurationEnabled = false; private boolean configurationEnabledChange = false; private boolean configurationCaRootAuthorityChanged = false; @@ -60,7 +56,7 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti */ @PostConstruct public void init() { - super.init(i18n.get("label.configuration.auth.header")); + super.init("label.configuration.auth.header"); configurationEnabled = isConfigEnabled(); detailLayout = new VerticalLayout(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java index 757460809..3fa87538c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java @@ -15,7 +15,6 @@ import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmall; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; @@ -41,8 +40,6 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac @Autowired private transient SecurityTokenGenerator securityTokenGenerator; - @Autowired - private I18N i18n; private TextField gatewayTokenNameTextField; @@ -72,7 +69,7 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac @PostConstruct public void init() { - super.init(i18n.get("label.configuration.auth.gatewaytoken")); + super.init("label.configuration.auth.gatewaytoken"); configurationEnabled = isConfigEnabled(); detailLayout = new VerticalLayout(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java index 641982d73..9ca82e7ea 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java @@ -12,7 +12,6 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; -import org.eclipse.hawkbit.ui.utils.I18N; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -28,9 +27,6 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract private static final long serialVersionUID = 1L; - @Autowired - private I18N i18n; - private boolean configurationEnabled = false; private boolean configurationEnabledChange = false; @@ -49,7 +45,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract */ @PostConstruct public void init() { - super.init(i18n.get("label.configuration.auth.targettoken")); + super.init("label.configuration.auth.targettoken"); configurationEnabled = isConfigEnabled(); } diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index d2e36dd2d..25dabd354 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -161,7 +161,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token -label.configuration.anonymous.download = Allow targets to download anonymous +label.configuration.anonymous.download = Allow targets to download artifacts without security credentials label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox diff --git a/hawkbit-ui/src/main/resources/messages_de.properties b/hawkbit-ui/src/main/resources/messages_de.properties index 98ac9edb3..39661e3c9 100644 --- a/hawkbit-ui/src/main/resources/messages_de.properties +++ b/hawkbit-ui/src/main/resources/messages_de.properties @@ -159,7 +159,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token -label.configuration.anonymous.download = Allow targets to download anonymous +label.configuration.anonymous.download = Allow targets to download artifacts without security credentials label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox diff --git a/hawkbit-ui/src/main/resources/messages_en.properties b/hawkbit-ui/src/main/resources/messages_en.properties index d6b4b1088..23df35ad2 100644 --- a/hawkbit-ui/src/main/resources/messages_en.properties +++ b/hawkbit-ui/src/main/resources/messages_en.properties @@ -160,7 +160,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token -label.configuration.anonymous.download = Allow targets to download anonymous +label.configuration.anonymous.download = Allow targets to download artifacts without security credentials label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox From b3efcff49ec30233f27c87b7afb396917298cfd8 Mon Sep 17 00:00:00 2001 From: Asharani Date: Mon, 11 Apr 2016 11:21:46 +0530 Subject: [PATCH 23/49] Add documentation for client side debugging Signed-off-by: Asharani --- hawkbit-ui/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 hawkbit-ui/README.md diff --git a/hawkbit-ui/README.md b/hawkbit-ui/README.md new file mode 100644 index 000000000..f8e020648 --- /dev/null +++ b/hawkbit-ui/README.md @@ -0,0 +1,34 @@ +# hawkBit User Interface + +The application with user interface to create and manage rollouts. + +## Debugging client-side code +### Debug usings SuperDevMode +The SuperDevMode can be used to debug client side code without any browser plugin. + +#### Using SuperDevMode with chrome : + +- Add required maven dependencies + - Add vaadin-client-compiler dependency + - Add jetty dependencies (version : 8.1x) +- Set redirect property in the AppWidgetSet.gwt.xml module descriptor as follows + - < set-configuration-property name="devModeRedirectEnabled" value="true" /> +- Create launch configuration for the SuperDevMode + - The main class to execute should be com.google.gwt.dev.codeserver.CodeServer. + - Add fully-qualified class name of widgetset (org.eclipse.hawkbit.ui.AppWidgetSet) as parameter +- Enable debug in chrome + - Chrome inspector window ▸ Click on settings icon ▸ Scripts ▸ Enable source maps option +- Run the SuperDevMode Code Server with the launch configuration created above +- Open http://localhost:8080/UI/?debug .Click on "SuperDev" button in debug console (Alternatively can directly add ?superdevmode parameter to URL) +- Widgetset is compiled and you can see the java code files loaded in 'Chrome inspector window ▸ Source tab' + + +#### Using SuperDevMode with Eclipse : + +- Install the plugin from http://sdbg.github.io/p2 +- Start the server and Super Dev Mode as mentioned above +- Create a new launch configuration in Eclipse + - Type is "Launch Chrome" + - http://localhost:8080/UI/?superdevmode +- Launch the new configuration in debug mode +- Now breakpoints in eclipse can be set \ No newline at end of file From 2bf328402cbcb57fbbafc060a2947be4f1d63e6b Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Mon, 11 Apr 2016 12:41:16 +0200 Subject: [PATCH 24/49] Send DMF message only in case of DMF sim. Signed-off-by: Kai Zimmermann --- .../org/eclipse/hawkbit/simulator/SimulationController.java | 5 ++++- .../java/org/eclipse/hawkbit/simulator/SimulatorStartup.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java index 426860d8b..649d88477 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java @@ -86,7 +86,10 @@ public class SimulationController { final String deviceId = name + i; repository.add(deviceFactory.createSimulatedDevice(deviceId, tenant, protocol, pollDelay, new URL(endpoint), gatewayToken)); - spSenderService.createOrUpdateThing(tenant, deviceId); + + if (protocol == Protocol.DMF_AMQP) { + spSenderService.createOrUpdateThing(tenant, deviceId); + } } return ResponseEntity.ok("Updated " + amount + " DMF connected targets!"); diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java index 60f3055bd..b772bae1f 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.simulator; import java.net.MalformedURLException; import java.net.URL; +import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol; import org.eclipse.hawkbit.simulator.amqp.SpSenderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +53,9 @@ public class SimulatorStartup implements ApplicationListener Date: Mon, 11 Apr 2016 15:05:02 +0200 Subject: [PATCH 25/49] Fix null handling for all drag and drop table Signed-off-by: SirWayne --- .../footer/SMDeleteActionsLayout.java | 13 ++-- .../ui/common/table/AbstractTable.java | 25 +++++++ .../dstable/DistributionSetTable.java | 13 ++-- .../footer/DSDeleteActionsLayout.java | 21 ++---- .../management/dstable/DistributionTable.java | 14 ++-- .../event/DistributionTagDropEvent.java | 21 +++--- .../footer/DeleteActionsLayout.java | 69 ++++++++----------- .../management/targettable/TargetTable.java | 11 +-- .../targettable/TargetTableHeader.java | 12 +--- .../targettag/TargetTagFilterButtons.java | 39 +++++------ 10 files changed, 105 insertions(+), 133 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java index ee2fc356f..4cb28c2c3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java @@ -8,16 +8,15 @@ */ package org.eclipse.hawkbit.ui.artifacts.footer; -import java.util.HashSet; import java.util.Set; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -155,13 +154,9 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { private void addToDeleteList(final Table sourceTable, final TableTransferable transferable) { @SuppressWarnings("unchecked") - final Set swModuleSelected = (Set) sourceTable.getValue(); - final Set swModuleIdNameSet = new HashSet<>(); - if (!swModuleSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - swModuleIdNameSet.add((Long) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - swModuleIdNameSet.addAll(swModuleSelected); - } + final AbstractTable swTable = (AbstractTable) sourceTable; + final Set swModuleIdNameSet = swTable.getDeletedEntityByTransferable(transferable); + swModuleIdNameSet.forEach(id -> { final String swModuleName = (String) sourceTable.getContainerDataSource().getItem(id) .getItemProperty(SPUILabelDefinitions.NAME_VERSION).getValue(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index eb1951d27..0737f42c8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ui.common.table; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -231,6 +232,30 @@ public abstract class AbstractTable extends Table { } } + /** + * Return the entity which should be deleted by a transferable + * + * @param transferable + * the table transferable + * @return set of entities id which will deleted + */ + @SuppressWarnings("unchecked") + public Set getDeletedEntityByTransferable(final TableTransferable transferable) { + final Set selectedEntities = (Set) getTableValue(this); + final Set ids = new HashSet<>(); + final Object tranferableData = transferable.getData(SPUIDefinitions.ITEMID); + if (tranferableData == null) { + return ids; + } + + if (!selectedEntities.contains(tranferableData)) { + ids.add((I) tranferableData); + } else { + ids.addAll(selectedEntities); + } + return ids; + } + protected abstract E findEntityByTableValue(I lastSelectedId); protected abstract void publishEntityAfterValueChange(E selectedLastEntity); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 1cd89b30f..b5d614243 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -29,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; @@ -208,17 +209,11 @@ public class DistributionSetTable extends AbstractNamedVersionTable softwareModuleSelected = (Set) source.getValue(); - final Set softwareModulesIdList = new HashSet<>(); - - if (!softwareModuleSelected.contains(transferable.getData("itemId"))) { - softwareModulesIdList.add((Long) transferable.getData("itemId")); - } else { - softwareModulesIdList.addAll(softwareModuleSelected); - } + final AbstractTable source = (AbstractTable) transferable.getSourceComponent(); + final Set softwareModulesIdList = source.getDeletedEntityByTransferable(transferable); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index dba8155db..5bc1627a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; @@ -188,13 +189,8 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { private void addInDeleteDistributionList(final Table sourceTable, final TableTransferable transferable) { @SuppressWarnings("unchecked") - final Set distSelected = (Set) sourceTable.getValue(); - final Set distributionIdNameSet = new HashSet<>(); - if (!distSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - distributionIdNameSet.add((DistributionSetIdName) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - distributionIdNameSet.addAll(distSelected); - } + final AbstractTable table = (AbstractTable) sourceTable; + final Set distributionIdNameSet = table.getDeletedEntityByTransferable(transferable); /* * Flags to identify whether all dropped distributions are already in * the deleted list (or) some distributions are already in the deleted @@ -224,15 +220,10 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { } private void addToSWDeleteList(final Table sourceTable, final TableTransferable transferable) { - @SuppressWarnings("unchecked") - final Set swModuleSelected = (Set) sourceTable.getValue(); - final Set swModuleIdNameSet = new HashSet<>(); - if (!swModuleSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - swModuleIdNameSet.add((Long) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - swModuleIdNameSet.addAll(swModuleSelected); - } + final AbstractTable swTable = (AbstractTable) sourceTable; + final Set swModuleIdNameSet = swTable.getDeletedEntityByTransferable(transferable); + swModuleIdNameSet.forEach(id -> { final String swModuleName = (String) sourceTable.getContainerDataSource().getItem(id) .getItemProperty(SPUILabelDefinitions.NAME_VERSION).getValue(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 1b856277e..0df1b0ea5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -26,6 +26,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; @@ -350,17 +351,12 @@ public class DistributionTable extends AbstractNamedVersionTable targetsSelected = getTableValue(source); - final Set targetDetailsList = new HashSet<>(); - - if (!targetsSelected.contains(transferable.getData("itemId"))) { - targetDetailsList.add((TargetIdName) transferable.getData("itemId")); - } else { - targetDetailsList.addAll(targetsSelected); - } + final AbstractTable source = (AbstractTable) transferable + .getSourceComponent(); + final Set targetDetailsList = source.getDeletedEntityByTransferable(transferable); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java index 5b1e09282..97ba7ea6c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.event; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -17,6 +16,7 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.management.state.DistributionTableFilters; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; @@ -127,28 +127,25 @@ public class DistributionTagDropEvent implements DropHandler { return true; } + @SuppressWarnings("unchecked") private void processDistributionDrop(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails(); final TableTransferable transferable = (TableTransferable) event.getTransferable(); - final Table source = transferable.getSourceComponent(); + final AbstractTable source = (AbstractTable) transferable + .getSourceComponent(); - @SuppressWarnings("unchecked") - final Set distSelected = (Set) source.getValue(); - final Set distributionList = new HashSet<>(); - if (!distSelected.contains(transferable.getData(ITEMID))) { - distributionList.add(((DistributionSetIdName) transferable.getData(ITEMID)).getId()); - } else { - distributionList.addAll(distSelected.stream().map(t -> t.getId()).collect(Collectors.toList())); - } + final Set distSelected = source.getDeletedEntityByTransferable(transferable); + final Set distributionList = distSelected.stream().map(entity -> entity.getId()) + .collect(Collectors.toSet()); final String distTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS); final List tagsClickedList = distFilterParameters.getDistSetTags(); - final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, - distTagName); + final DistributionSetTagAssignmentResult result = distributionSetManagement + .toggleTagAssignment(distributionList, distTagName); notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n)); if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 678a5704f..0466e6076 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.footer; -import java.util.HashSet; import java.util.Set; import org.eclipse.hawkbit.repository.TagManagement; @@ -257,15 +256,10 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } } + @SuppressWarnings("unchecked") private void addInDeleteDistributionList(final Table sourceTable, final TableTransferable transferable) { - final Set distSelected = AbstractTable.getTableValue(sourceTable); - final Set distributionIdNameSet = new HashSet<>(); - - if (!distSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - distributionIdNameSet.add((DistributionSetIdName) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - distributionIdNameSet.addAll(distSelected); - } + final AbstractTable distTable = (AbstractTable) sourceTable; + final Set distributionIdNameSet = distTable.getDeletedEntityByTransferable(transferable); final DistributionSetIdName dsInBulkUpload = managementUIState.getTargetTableFilters().getBulkUpload() .getDsNameAndVersion(); @@ -273,31 +267,31 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { distributionIdNameSet.remove(dsInBulkUpload); } - if (!distributionIdNameSet.isEmpty()) { - + if (distributionIdNameSet.isEmpty()) { + return; + } + /* + * Flags to identify whether all dropped distributions are already in + * the deleted list (or) some distributions are already in the deleted + * distribution list. + */ + final int existingDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); + managementUIState.getDeletedDistributionList().addAll(distributionIdNameSet); + final int newDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); + if (newDeletedDistributionsSize == existingDeletedDistributionsSize) { /* - * Flags to identify whether all dropped distributions are already - * in the deleted list (or) some distributions are already in the - * deleted distribution list. + * No new distributions are added, all distributions dropped now are + * already available in the delete list. Hence display warning + * message accordingly. */ - final int existingDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); - managementUIState.getDeletedDistributionList().addAll(distributionIdNameSet); - final int newDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); - if (newDeletedDistributionsSize == existingDeletedDistributionsSize) { - /* - * No new distributions are added, all distributions dropped now - * are already available in the delete list. Hence display - * warning message accordingly. - */ - notification.displayValidationError(i18n.get("message.targets.already.deleted")); - } else if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { - /* - * Not the all distributions dropped now are added to the delete - * list. There are some distributions are already there in the - * delete list. Hence display warning message accordingly. - */ - notification.displayValidationError(i18n.get("message.dist.deleted.pending")); - } + notification.displayValidationError(i18n.get("message.targets.already.deleted")); + } else if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { + /* + * Not the all distributions dropped now are added to the delete + * list. There are some distributions are already there in the + * delete list. Hence display warning message accordingly. + */ + notification.displayValidationError(i18n.get("message.dist.deleted.pending")); } } @@ -311,15 +305,10 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { return false; } + @SuppressWarnings("unchecked") private void addInDeleteTargetList(final Table sourceTable, final TableTransferable transferable) { - final Set targetSelected = AbstractTable.getTableValue(sourceTable); - - final Set targetIdNameSet = new HashSet<>(); - if (!targetSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - targetIdNameSet.add((TargetIdName) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - targetIdNameSet.addAll(targetSelected); - } + final AbstractTable targetTable = (AbstractTable) sourceTable; + final Set targetIdNameSet = targetTable.getDeletedEntityByTransferable(transferable); /* * Flags to identify whether all dropped targets are already in the diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index e73bf2e4a..1307e27d3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -632,16 +632,11 @@ public class TargetTable extends AbstractTable implements return true; } + @SuppressWarnings("unchecked") private static Set getDraggedDistributionSet(final TableTransferable transferable, final Table source) { - final Set distSelected = getTableValue(source); - final Set distributionIdSet = new HashSet<>(); - if (!distSelected.contains(transferable.getData(ITEMID))) { - distributionIdSet.add((DistributionSetIdName) transferable.getData(ITEMID)); - } else { - distributionIdSet.addAll(distSelected); - } - return distributionIdSet; + final AbstractTable distTable = (AbstractTable) source; + return distTable.getDeletedEntityByTransferable(transferable); } private Boolean validateDragAndDropWrapper(final Component compsource) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index cb00c2338..158d57878 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -378,16 +378,10 @@ public class TargetTableHeader extends AbstractTableHeader { return isValid; } + @SuppressWarnings("unchecked") private Set getDropppedDistributionDetails(final TableTransferable transferable) { - final Set distSelected = AbstractTable.getTableValue(transferable.getSourceComponent()); - final Set distributionIdSet = new HashSet<>(); - if (!distSelected.contains(transferable.getData("itemId"))) { - distributionIdSet.add((DistributionSetIdName) transferable.getData("itemId")); - } else { - distributionIdSet.addAll(distSelected); - } - - return distributionIdSet; + final AbstractTable distTable = (AbstractTable) transferable.getSourceComponent(); + return distTable.getDeletedEntityByTransferable(transferable); } private void addFilterTextField(final DistributionSetIdName distributionSetIdName) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index c60ab37ca..671d332de 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.targettag; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -212,36 +211,32 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { return true; } + @SuppressWarnings("unchecked") private void processTargetDrop(final DragAndDropEvent event) { - final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails(); final TableTransferable transferable = (TableTransferable) event.getTransferable(); - final Table source = transferable.getSourceComponent(); + final AbstractTable targetTable = (AbstractTable) transferable + .getSourceComponent(); - final Set targetSelected = AbstractTable.getTableValue(source); - final Set targetList = new HashSet<>(); - if (transferable.getData(ITEMID) != null) { - if (!targetSelected.contains(transferable.getData(ITEMID))) { - targetList.add(((TargetIdName) transferable.getData(ITEMID)).getControllerId()); - } else { - targetList.addAll(targetSelected.stream().map(t -> t.getControllerId()).collect(Collectors.toList())); - } + final Set targetSelected = targetTable.getDeletedEntityByTransferable(transferable); + final Set targetList = targetSelected.stream().map(t -> t.getControllerId()) + .collect(Collectors.toSet()); - final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), - SPUIDefinitions.TARGET_TAG_ID_PREFIXS); + final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), + SPUIDefinitions.TARGET_TAG_ID_PREFIXS); - final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); + final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); - final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); - notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(targTagName, result, i18n)); + final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); + notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(targTagName, result, i18n)); - if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { - eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); - } - if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty() && tagsClickedList.contains(targTagName)) { - eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); - } + if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { + eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); } + if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty() && tagsClickedList.contains(targTagName)) { + eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); + } + } private boolean validateIfSourceisTargetTable(final Table source) { From c4fd082098b01228cd0e719cd94743ac87b594bc Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 09:39:07 +0200 Subject: [PATCH 26/49] fix the lookup of artifacts with the same lookup key, e.g. SHA1 hash if multiple artifacts with key exists for different software modules Signed-off-by: Michael Hirsch --- .../amqp/AmqpMessageHandlerService.java | 14 +++-- .../repository/ControllerManagement.java | 27 +++++++++ .../specifications/ActionSpecifications.java | 60 +++++++++++++++++++ 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 41e70f91f..e05ddf71d 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -166,6 +166,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService { final LocalArtifact localArtifact = findLocalArtifactByFileResource(fileResource); if (localArtifact == null) { + LOG.info("target {} requested file resource which does not exists to download", + secruityToken.getControllerId(), fileResource); throw new EntityNotFoundException(); } @@ -175,10 +177,14 @@ public class AmqpMessageHandlerService extends BaseAmqpService { // assigned to this controller. Otherwise no controllerId is set = // anonymous download if (secruityToken.getControllerId() != null) { - final Action action = controllerManagement.getActionForDownloadByTargetAndSoftwareModule( - secruityToken.getControllerId(), localArtifact.getSoftwareModule()); - LOG.info("Found action for download authentication request action: {}, resource: {}", action, - secruityToken.getFileResource()); + LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", + secruityToken.getControllerId(), localArtifact); + if (!controllerManagement.hasTargetArtifactAssigned(secruityToken.getControllerId(), localArtifact)) { + LOG.info("target {} tried to download artifact {} which is not assigned to the target"); + throw new EntityNotFoundException(); + } + LOG.info("download security check for target {} and artifact {} granted", + secruityToken.getControllerId(), localArtifact); } final Artifact artifact = convertDbArtifact(artifactManagement.loadLocalArtifactBinary(localArtifact)); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 0bb94bd72..9510ae899 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -28,12 +28,14 @@ import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionStatus_; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.Target_; import org.eclipse.hawkbit.repository.model.TenantConfiguration; +import org.eclipse.hawkbit.repository.specifications.ActionSpecifications; import org.eclipse.hawkbit.security.HawkbitSecurityProperties; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.hibernate.validator.constraints.NotEmpty; @@ -166,6 +168,31 @@ public class ControllerManagement { return action.get(0); } + /** + * Checks if a given target has currently or has even been assigned to the + * given artifact through the action history list. This can e.g. indicate if + * a target is allowed to download a given artifact because it has currently + * assigned or had ever been assigned to the target and so it's visible to a + * specific target e.g. for downloading. + * + * @param targetId + * the ID of the target to check + * @param localArtifact + * the artifact to verify if the given target had even been + * assigned to + * @return {@code true} if the given target has currently or had ever a + * relation to the given artifact through the action history, + * otherwise {@code false} + */ + public boolean hasTargetArtifactAssigned(@NotNull final String targetId, + @NotNull final LocalArtifact localArtifact) { + final Target target = targetRepository.findByControllerId(targetId); + if (target == null) { + return false; + } + return actionRepository.count(ActionSpecifications.hasTargetArtifactAssigned(target, localArtifact)) > 0; + } + /** * Refreshes the time of the last time the controller has been connected to * the server. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java new file mode 100644 index 000000000..ef8c97e22 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.specifications; + +import javax.persistence.criteria.Join; +import javax.persistence.criteria.ListJoin; +import javax.persistence.criteria.SetJoin; + +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action_; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSet_; +import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.LocalArtifact_; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModule_; +import org.eclipse.hawkbit.repository.model.Target; +import org.springframework.data.jpa.domain.Specification; + +/** + * Utility class for {@link Action}s {@link Specification}s. The class provides + * Spring Data JPQL Specifications. + * + */ +public class ActionSpecifications { + + private ActionSpecifications() { + // utility class + } + + /** + * Specification which joins all necessary tables to retrieve the dependency + * between a target and a local file assignment through the assigen action + * of the target. All actions are included, not only active actions. + * + * @param target + * the target to verfiy if the given artifact is currently + * assigned or had been assigned + * @param localArtifact + * the local artifact to check wherever the target had ever been + * assigned + * @return a specification to use with spring JPA + */ + public static Specification hasTargetArtifactAssigned(final Target target, + final LocalArtifact localArtifact) { + return (actionRoot, query, cb) -> { + final Join dsJoin = actionRoot.join(Action_.distributionSet); + final SetJoin modulesJoin = dsJoin.join(DistributionSet_.modules); + final ListJoin artifactsJoin = modulesJoin.join(SoftwareModule_.artifacts); + return cb.and(cb.equal(artifactsJoin.get(LocalArtifact_.id), localArtifact.getId()), + cb.equal(actionRoot.get(Action_.target), target)); + }; + } +} From 0b5286299c7a2453a635f8a7d64eac33cb99d46d Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 10:03:19 +0200 Subject: [PATCH 27/49] fix unit tests after changing the lookup way Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 930ca02ad..0faa0a8a6 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -313,11 +313,9 @@ public class AmqpMessageHandlerServiceTest { // mock final LocalArtifact localArtifactMock = mock(LocalArtifact.class); - final Action actionMock = mock(Action.class); final DbArtifact dbArtifactMock = mock(DbArtifact.class); when(artifactManagementMock.findFirstLocalArtifactsBySHA1(anyString())).thenReturn(localArtifactMock); - when(controllerManagementMock.getActionForDownloadByTargetAndSoftwareModule(anyObject(), anyObject())) - .thenReturn(actionMock); + when(controllerManagementMock.hasTargetArtifactAssigned(anyObject(), anyObject())).thenReturn(true); when(artifactManagementMock.loadLocalArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock); when(dbArtifactMock.getArtifactId()).thenReturn("artifactId"); when(dbArtifactMock.getSize()).thenReturn(1L); From b11a0bac5db51e38685d77ca15669e4042069ba4 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 12:18:59 +0200 Subject: [PATCH 28/49] reduce method cyclomatic complexity by extracting security check into own method Signed-off-by: Michael Hirsch --- .../amqp/AmqpMessageHandlerService.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index e05ddf71d..47807cd4d 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -171,21 +171,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { throw new EntityNotFoundException(); } - // check action for this download purposes, the method will throw an - // EntityNotFoundException in case the controller is not allowed to - // download this file because it's not assigned to an action and not - // assigned to this controller. Otherwise no controllerId is set = - // anonymous download - if (secruityToken.getControllerId() != null) { - LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", - secruityToken.getControllerId(), localArtifact); - if (!controllerManagement.hasTargetArtifactAssigned(secruityToken.getControllerId(), localArtifact)) { - LOG.info("target {} tried to download artifact {} which is not assigned to the target"); - throw new EntityNotFoundException(); - } - LOG.info("download security check for target {} and artifact {} granted", - secruityToken.getControllerId(), localArtifact); - } + checkIfArtifactIsAssignedToTarget(secruityToken, localArtifact); final Artifact artifact = convertDbArtifact(artifactManagement.loadLocalArtifactBinary(localArtifact)); if (artifact == null) { @@ -219,6 +205,25 @@ public class AmqpMessageHandlerService extends BaseAmqpService { return getMessageConverter().toMessage(authentificationResponse, messageProperties); } + private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, + final LocalArtifact localArtifact) { + // check action for this download purposes, the method will throw an + // EntityNotFoundException in case the controller is not allowed to + // download this file because it's not assigned to an action and not + // assigned to this controller. Otherwise no controllerId is set = + // anonymous download + if (secruityToken.getControllerId() != null) { + LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", + secruityToken.getControllerId(), localArtifact); + if (!controllerManagement.hasTargetArtifactAssigned(secruityToken.getControllerId(), localArtifact)) { + LOG.info("target {} tried to download artifact {} which is not assigned to the target"); + throw new EntityNotFoundException(); + } + LOG.info("download security check for target {} and artifact {} granted", secruityToken.getControllerId(), + localArtifact); + } + } + private LocalArtifact findLocalArtifactByFileResource(final FileResource fileResource) { if (fileResource.getSha1() != null) { return artifactManagement.findFirstLocalArtifactsBySHA1(fileResource.getSha1()); From d91922dc048cb3119561135ff60f0e9da8f24997 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 12 Apr 2016 13:37:07 +0200 Subject: [PATCH 29/49] Update the entity before call the super method Signed-off-by: SirWayne --- .../smtable/SoftwareModuleTable.java | 59 ++++++++----------- .../table/AbstractNamedVersionTable.java | 2 +- .../dstable/DistributionSetTable.java | 12 ++-- .../distributions/smtable/SwModuleTable.java | 20 ++++--- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index f101c94a7..237634398 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -9,7 +9,6 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -25,7 +24,6 @@ import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.TableColumn; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; @@ -44,6 +42,8 @@ import com.vaadin.ui.UI; /** * Header of Software module table. + * + * * */ @SpringComponent @@ -129,22 +129,6 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable getTableVisibleColumns() { - final List columnList = super.getTableVisibleColumns(); - if (!isMaximized()) { - return columnList; - } - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); - return columnList; + protected void updateEntity(final SoftwareModule baseEntity, final Item item) { + final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), + baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); + item.getItemProperty("swId").setValue(baseEntity.getId()); + item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); + super.updateEntity(baseEntity, item); } @Override @@ -203,6 +180,22 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable Date: Tue, 12 Apr 2016 13:42:57 +0200 Subject: [PATCH 30/49] Update the entity before call the super method Signed-off-by: SirWayne --- .../smtable/SoftwareModuleTable.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 237634398..478438891 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -24,6 +25,7 @@ import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.TableColumn; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; @@ -42,8 +44,6 @@ import com.vaadin.ui.UI; /** * Header of Software module table. - * - * * */ @SpringComponent @@ -129,6 +129,22 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable getTableVisibleColumns() { + final List columnList = super.getTableVisibleColumns(); + if (!isMaximized()) { + return columnList; + } + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); + return columnList; + } + @Override protected DropHandler getTableDropHandler() { return new DropHandler() { @@ -180,22 +207,6 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable Date: Tue, 12 Apr 2016 14:35:59 +0200 Subject: [PATCH 31/49] source code improvements Signed-off-by: Michael Hirsch --- .../amqp/AmqpMessageHandlerService.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 47807cd4d..994ef244a 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -205,23 +205,32 @@ public class AmqpMessageHandlerService extends BaseAmqpService { return getMessageConverter().toMessage(authentificationResponse, messageProperties); } + /** + * check action for this download purposes, the method will throw an + * EntityNotFoundException in case the controller is not allowed to download + * this file because it's not assigned to an action and not assigned to this + * controller. Otherwise no controllerId is set = anonymous download + * + * @param secruityToken + * the security token which holds the target ID to check on + * @param localArtifact + * the local artifact to verify if the given target is allowed to + * download this artifact + */ private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, final LocalArtifact localArtifact) { - // check action for this download purposes, the method will throw an - // EntityNotFoundException in case the controller is not allowed to - // download this file because it's not assigned to an action and not - // assigned to this controller. Otherwise no controllerId is set = - // anonymous download - if (secruityToken.getControllerId() != null) { - LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", - secruityToken.getControllerId(), localArtifact); - if (!controllerManagement.hasTargetArtifactAssigned(secruityToken.getControllerId(), localArtifact)) { - LOG.info("target {} tried to download artifact {} which is not assigned to the target"); - throw new EntityNotFoundException(); - } - LOG.info("download security check for target {} and artifact {} granted", secruityToken.getControllerId(), - localArtifact); + final String controllerId = secruityToken.getControllerId(); + if (controllerId == null) { + LOG.info("anonymous download no authentication check for artifact {}", localArtifact); + return; } + LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", + controllerId, localArtifact); + if (!controllerManagement.hasTargetArtifactAssigned(controllerId, localArtifact)) { + LOG.info("target {} tried to download artifact {} which is not assigned to the target"); + throw new EntityNotFoundException(); + } + LOG.info("download security check for target {} and artifact {} granted", controllerId, localArtifact); } private LocalArtifact findLocalArtifactByFileResource(final FileResource fileResource) { From cc8c6743415be5b01cd80cffd8da669611acd547 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 15:47:21 +0200 Subject: [PATCH 32/49] correct usage of logging, missing parameters Signed-off-by: Michael Hirsch --- .../org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 994ef244a..2ee0a0f45 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -227,7 +227,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService { LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", controllerId, localArtifact); if (!controllerManagement.hasTargetArtifactAssigned(controllerId, localArtifact)) { - LOG.info("target {} tried to download artifact {} which is not assigned to the target"); + LOG.info("target {} tried to download artifact {} which is not assigned to the target", controllerId, + localArtifact); throw new EntityNotFoundException(); } LOG.info("download security check for target {} and artifact {} granted", controllerId, localArtifact); From 30e8230b8aaa55e1e3834c1d9eeed019454d5f99 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 15:48:19 +0200 Subject: [PATCH 33/49] correct usage of logging, missing parameters Signed-off-by: Michael Hirsch --- .../org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 2ee0a0f45..447a8ffca 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -166,7 +166,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { final LocalArtifact localArtifact = findLocalArtifactByFileResource(fileResource); if (localArtifact == null) { - LOG.info("target {} requested file resource which does not exists to download", + LOG.info("target {} requested file resource {} which does not exists to download", secruityToken.getControllerId(), fileResource); throw new EntityNotFoundException(); } From d903be57b7a9913c29db8e8729efa88f5fab4666 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 15:50:48 +0200 Subject: [PATCH 34/49] use correct mock parameters to ensure test Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 0faa0a8a6..19a7be3bc 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -315,7 +315,8 @@ public class AmqpMessageHandlerServiceTest { final LocalArtifact localArtifactMock = mock(LocalArtifact.class); final DbArtifact dbArtifactMock = mock(DbArtifact.class); when(artifactManagementMock.findFirstLocalArtifactsBySHA1(anyString())).thenReturn(localArtifactMock); - when(controllerManagementMock.hasTargetArtifactAssigned(anyObject(), anyObject())).thenReturn(true); + when(controllerManagementMock.hasTargetArtifactAssigned(securityToken.getControllerId(), localArtifactMock)) + .thenReturn(true); when(artifactManagementMock.loadLocalArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock); when(dbArtifactMock.getArtifactId()).thenReturn("artifactId"); when(dbArtifactMock.getSize()).thenReturn(1L); From d704ef99fd1a3ee0f8152f933ee7c9f8ed610901 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 16:22:43 +0200 Subject: [PATCH 35/49] source code hygiene, better method naming and variable naming Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/repository/ControllerManagement.java | 2 +- .../repository/specifications/ActionSpecifications.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 9510ae899..dc097a7e3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -190,7 +190,7 @@ public class ControllerManagement { if (target == null) { return false; } - return actionRepository.count(ActionSpecifications.hasTargetArtifactAssigned(target, localArtifact)) > 0; + return actionRepository.count(ActionSpecifications.hasTargetAssignedArtifact(target, localArtifact)) > 0; } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java index ef8c97e22..1ac3afb67 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java @@ -47,14 +47,14 @@ public class ActionSpecifications { * assigned * @return a specification to use with spring JPA */ - public static Specification hasTargetArtifactAssigned(final Target target, + public static Specification hasTargetAssignedArtifact(final Target target, final LocalArtifact localArtifact) { - return (actionRoot, query, cb) -> { + return (actionRoot, query, criteriaBuilder) -> { final Join dsJoin = actionRoot.join(Action_.distributionSet); final SetJoin modulesJoin = dsJoin.join(DistributionSet_.modules); final ListJoin artifactsJoin = modulesJoin.join(SoftwareModule_.artifacts); - return cb.and(cb.equal(artifactsJoin.get(LocalArtifact_.id), localArtifact.getId()), - cb.equal(actionRoot.get(Action_.target), target)); + return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(LocalArtifact_.id), localArtifact.getId()), + criteriaBuilder.equal(actionRoot.get(Action_.target), target)); }; } } From 67fd24e66846a6f4d7e02a805a72773572ef07d4 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Wed, 13 Apr 2016 12:46:30 +0530 Subject: [PATCH 36/49] Rollout management issues Signed-off-by: venu1278 --- .../client/CustomObjectRendererConnector.java | 25 + .../client/LinkRendererConnector.java | 29 - .../client/renderers/CustomObject.java | 39 + .../renderers/CustomObjectRenederer.java | 52 + .../client/renderers/LinkRenderer.java | 42 - .../renderers/CustomObjectRenderer.java | 42 + .../renderers/LinkRenderer.java | 37 - .../ui/rollout/rollout/ProxyRollout.java | 194 +-- .../ui/rollout/rollout/RolloutBeanQuery.java | 4 +- .../ui/rollout/rollout/RolloutListGrid.java | 1116 +++++++++-------- .../rolloutgroup/ProxyRolloutGroup.java | 11 + .../rolloutgroup/RolloutGroupBeanQuery.java | 3 + .../rolloutgroup/RolloutGroupListGrid.java | 624 ++++----- .../themes/hawkbit/customstyles/rollout.scss | 18 +- 14 files changed, 1232 insertions(+), 1004 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java new file mode 100644 index 000000000..b209ab82c --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java @@ -0,0 +1,25 @@ +package org.eclipse.hawkbit.ui.customrenderers.client; + +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; + +import com.google.web.bindery.event.shared.HandlerRegistration; +import com.vaadin.client.connectors.ClickableRendererConnector; +import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; +import com.vaadin.shared.ui.Connect; + +import elemental.json.JsonObject; + +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer.class) +public class CustomObjectRendererConnector extends ClickableRendererConnector { + private static final long serialVersionUID = 7734682321931830566L; + + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer) super.getRenderer(); + } + + @Override + protected HandlerRegistration addClickHandler( + RendererClickHandler handler) { + return getRenderer().addClickHandler(handler); + } +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java deleted file mode 100644 index bc48d64d7..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.customrenderers.client; - -import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; - -import com.vaadin.client.connectors.ButtonRendererConnector; -import com.vaadin.shared.ui.Connect; - -/** - * - * A connector for {@link LinkRenderer}. - * - */ -@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer.class) -public class LinkRendererConnector extends ButtonRendererConnector { - private static final long serialVersionUID = 7987417436367399331L; - - @Override - public org.eclipse.hawkbit.ui.customrenderers.client.renderers.LinkRenderer getRenderer() { - return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.LinkRenderer) super.getRenderer(); - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java new file mode 100644 index 000000000..85b5d9404 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java @@ -0,0 +1,39 @@ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import java.io.Serializable; + +public class CustomObject implements Serializable { + private static final long serialVersionUID = -5018181529953620263L; + + private String name; + + private String status; + + public CustomObject(){ + + } + + public CustomObject(String name, String status) { + super(); + this.name = name; + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getStatus() { + return status; + } + + + public void setStatus(String status) { + this.status = status; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java new file mode 100644 index 000000000..a6a527f2a --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java @@ -0,0 +1,52 @@ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import com.google.gwt.core.shared.GWT; +import com.vaadin.client.renderers.ClickableRenderer; +import com.vaadin.client.ui.VButton; +import com.vaadin.client.widget.grid.RendererCellReference; + +public class CustomObjectRenederer extends ClickableRenderer { + + @Override + public VButton createWidget() { + VButton b = GWT.create(VButton.class); + b.addClickHandler(this); + b.setStylePrimaryName("v-nativebutton"); + return b; + } + + @Override + public void render(RendererCellReference cell, CustomObject text, VButton button) { + final String creating = "CREATING"; + button.setText(text.getName()); + applystyle(button); + // this is to allow the button to disappear, if the text is null + button.setVisible(text.getName() != null); + button.getElement().setId(new StringBuilder("link").append(".").append(text.getName()).toString()); + /* + * checking Rollout Status for applying button style. If Rollout status + * is not "CREATING", then the Rollout button is applying hyperlink + * style + */ + final boolean isStatusCreate = text.getStatus() != null && creating.equalsIgnoreCase(text.getStatus()); + if (isStatusCreate) { + button.addStyleName(getStyle("boldhide")); + button.setEnabled(false); + } else { + button.setEnabled(true); + } + } + + private void applystyle(VButton button) { + button.setStyleName(VButton.CLASSNAME); + button.addStyleName(getStyle("borderless")); + button.addStyleName(getStyle("small")); + button.addStyleName(getStyle("on-focus-no-border")); + button.addStyleName(getStyle("link")); + } + + private String getStyle(final String style) { + return new StringBuilder(style).append(" ").append(VButton.CLASSNAME).append("-").append(style).toString(); + } + +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java deleted file mode 100644 index 0abe4044b..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.customrenderers.client.renderers; - -import com.google.gwt.user.client.ui.Button; -import com.vaadin.client.renderers.ButtonRenderer; -import com.vaadin.client.ui.VButton; -import com.vaadin.client.widget.grid.RendererCellReference; - -/** - * - * Renders link with provided text. - * - */ -public class LinkRenderer extends ButtonRenderer { - @Override - public void render(RendererCellReference cell, String text, Button button) { - button.setText(text); - applystyle(button); - // this is to allow the button to disappear, if the text is null - button.setVisible(text != null); - button.getElement().setId(new StringBuilder("link").append(".").append(text).toString()); - } - - private void applystyle(Button button) { - button.setStyleName(VButton.CLASSNAME); - button.addStyleName(getStyle("borderless")); - button.addStyleName(getStyle("small")); - button.addStyleName(getStyle("on-focus-no-border")); - button.addStyleName(getStyle("link")); - } - - private String getStyle(final String style) { - return new StringBuilder(style).append(" ").append(VButton.CLASSNAME).append("-").append(style).toString(); - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java new file mode 100644 index 000000000..c2a7606a3 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java @@ -0,0 +1,42 @@ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; + +import com.vaadin.ui.renderers.ClickableRenderer; + +import elemental.json.JsonValue; + +public class CustomObjectRenderer extends ClickableRenderer { + + /** + * + */ + private static final long serialVersionUID = -8754180585906263554L; + + /** + * Creates a new image renderer. + */ + public CustomObjectRenderer() { + super(CustomObject.class, null); + } + + public CustomObjectRenderer(Class presentationType) { + super(presentationType); + } + + /** + * Creates a new image renderer and adds the given click listener to it. + * + * @param listener + * the click listener to register + */ + public CustomObjectRenderer(RendererClickListener listener) { + this(); + addClickListener(listener); + } + + @Override + public JsonValue encode(CustomObject resource) { + return super.encode(resource, CustomObject.class); + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java deleted file mode 100644 index d913ca380..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.customrenderers.renderers; - -import com.vaadin.ui.renderers.ButtonRenderer; - -/** - * - * Renders link with provided text. - * - */ -public class LinkRenderer extends ButtonRenderer { - private static final long serialVersionUID = -1242995370043404892L; - - /** - * Intialise link renderer. - */ - public LinkRenderer() { - super(); - } - - /** - * Intialise link renderer with {@link RendererClickListener} - * - * @param listener - * RendererClickListener - */ - public LinkRenderer(RendererClickListener listener) { - super(listener); - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index b1309f8b9..36cb7ddee 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; import com.vaadin.server.FontAwesome; @@ -18,113 +19,122 @@ import com.vaadin.server.FontAwesome; */ public class ProxyRollout extends Rollout { - private static final long serialVersionUID = 4539849939617681918L; + private static final long serialVersionUID = 4539849939617681918L; - private String distributionSetNameVersion; + private String distributionSetNameVersion; - private String createdDate; + private String createdDate; - private String modifiedDate; + private String modifiedDate; - private Long numberOfGroups; + private Long numberOfGroups; - private Boolean isActionRecieved = Boolean.FALSE; + private Boolean isActionRecieved = Boolean.FALSE; - private String totalTargetsCount; - - /** - * @return the distributionSetNameVersion - */ - public String getDistributionSetNameVersion() { - return distributionSetNameVersion; - } + private String totalTargetsCount; - /** - * @param distributionSetNameVersion - * the distributionSetNameVersion to set - */ - public void setDistributionSetNameVersion(final String distributionSetNameVersion) { - this.distributionSetNameVersion = distributionSetNameVersion; - } + private CustomObject customObject; - /** - * @return the numberOfGroups - */ - public Long getNumberOfGroups() { - return numberOfGroups; - } + public CustomObject getCustomObject() { + return customObject; + } - /** - * @param numberOfGroups - * the numberOfGroups to set - */ - public void setNumberOfGroups(final Long numberOfGroups) { - this.numberOfGroups = numberOfGroups; - } + public void setCustomObject(CustomObject customObject) { + this.customObject = customObject; + } - /** - * @return the createdDate - */ - public String getCreatedDate() { - return createdDate; - } + /** + * @return the distributionSetNameVersion + */ + public String getDistributionSetNameVersion() { + return distributionSetNameVersion; + } - /** - * @param createdDate - * the createdDate to set - */ - public void setCreatedDate(final String createdDate) { - this.createdDate = createdDate; - } + /** + * @param distributionSetNameVersion + * the distributionSetNameVersion to set + */ + public void setDistributionSetNameVersion(final String distributionSetNameVersion) { + this.distributionSetNameVersion = distributionSetNameVersion; + } - /** - * @return the modifiedDate - */ - public String getModifiedDate() { - return modifiedDate; - } + /** + * @return the numberOfGroups + */ + public Long getNumberOfGroups() { + return numberOfGroups; + } - /** - * @param modifiedDate - * the modifiedDate to set - */ - public void setModifiedDate(final String modifiedDate) { - this.modifiedDate = modifiedDate; - } + /** + * @param numberOfGroups + * the numberOfGroups to set + */ + public void setNumberOfGroups(final Long numberOfGroups) { + this.numberOfGroups = numberOfGroups; + } - /** - * @return the isActionRecieved - */ - public Boolean getIsActionRecieved() { - return isActionRecieved; - } + /** + * @return the createdDate + */ + public String getCreatedDate() { + return createdDate; + } - /** - * @param isActionRecieved - * the isActionRecieved to set - */ - public void setIsActionRecieved(final Boolean isActionRecieved) { - this.isActionRecieved = isActionRecieved; - } + /** + * @param createdDate + * the createdDate to set + */ + public void setCreatedDate(final String createdDate) { + this.createdDate = createdDate; + } - /** - * @return the totalTargetsCount - */ - public String getTotalTargetsCount() { - return totalTargetsCount; - } + /** + * @return the modifiedDate + */ + public String getModifiedDate() { + return modifiedDate; + } + + /** + * @param modifiedDate + * the modifiedDate to set + */ + public void setModifiedDate(final String modifiedDate) { + this.modifiedDate = modifiedDate; + } + + /** + * @return the isActionRecieved + */ + public Boolean getIsActionRecieved() { + return isActionRecieved; + } + + /** + * @param isActionRecieved + * the isActionRecieved to set + */ + public void setIsActionRecieved(final Boolean isActionRecieved) { + this.isActionRecieved = isActionRecieved; + } + + /** + * @return the totalTargetsCount + */ + public String getTotalTargetsCount() { + return totalTargetsCount; + } + + /** + * @param totalTargetsCount + * the totalTargetsCount to set + */ + public void setTotalTargetsCount(final String totalTargetsCount) { + this.totalTargetsCount = totalTargetsCount; + } + + public String getAction() { + return FontAwesome.CIRCLE_O.getHtml(); + } - /** - * @param totalTargetsCount - * the totalTargetsCount to set - */ - public void setTotalTargetsCount(final String totalTargetsCount) { - this.totalTargetsCount = totalTargetsCount; - } - - - public String getAction() { - return FontAwesome.CIRCLE_O.getHtml(); - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 5ab6f6a97..114d2e432 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -130,7 +131,8 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setForcedTime(rollout.getForcedTime()); proxyRollout.setId(rollout.getId()); proxyRollout.setStatus(rollout.getStatus()); - + proxyRollout.setCustomObject(new CustomObject(rollout.getName(), rollout.getStatus().toString())); + final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 9151f3932..6cf781c4b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -25,9 +25,10 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; -import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -58,6 +59,7 @@ import com.vaadin.server.AbstractClientConnector; import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; +import com.vaadin.ui.Button; import com.vaadin.ui.UI; import com.vaadin.ui.Window; import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; @@ -72,524 +74,598 @@ import com.vaadin.ui.renderers.HtmlRenderer; @ViewScope public class RolloutListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; - - private static final String UPDATE_OPTION = "Update"; - - private static final String RESUME_OPTION = "Resume"; - - private static final String PAUSE_OPTION = "Pause"; - - private static final String START_OPTION = "Start"; - - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private transient RolloutManagement rolloutManagement; - - @Autowired - private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; - - @Autowired - private UINotification uiNotification; - - @Autowired - private transient RolloutUIState rolloutUIState; - - @Autowired - private transient SpPermissionChecker permissionChecker; - - private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); - - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - switch (event) { - case FILTER_BY_TEXT: - case CREATE_ROLLOUT: - case UPDATE_ROLLOUT: - case SHOW_ROLLOUTS: - refreshGrid(); - break; - default: - return; - } - } - - /** - * Handles the RolloutChangeEvent to refresh the item in the grid. - * - * @param rolloutChangeEvent - * the event which contains the rollout which has been changed - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { - if (!rolloutUIState.isShowRollOuts()) { - return; - } - final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); - final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); - final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); - if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) - .setValue(Long.valueOf(rollout.getRolloutGroups().size())); - } - } - - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } - - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Integer.class, 0, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, - FontAwesome.CIRCLE_O.getHtml(), false, false); - - } - - @Override - protected void setColumnExpandRatio() { - getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - - setFrozenColumnCount(getColumns().size()); - } - - @Override - protected void setColumnHeaderNames() { - getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); - } - - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; - } - - @Override - protected void setColumnProperties() { - List columnList = new ArrayList<>(); - columnList.add(SPUILabelDefinitions.VAR_NAME); - columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ACTION); - - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } - - @Override - protected void setHiddenColumns() { - List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - - } - - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } - - @Override - protected void addColumnRenderes() { - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - - createRolloutStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); - - getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - getColumn(SPUILabelDefinitions.VAR_NAME).setRenderer(new LinkRenderer(event -> onClickOfRolloutName(event))); - } - - private void createRolloutStatusToFontMap() { - statusIconMap.put(RolloutStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutStatus.PAUSED, - new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); - statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); - statusIconMap.put(RolloutStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutStatus.STOPPED, - new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); - statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); - statusIconMap.put(RolloutStatus.ERROR_CREATING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.ERROR_STARTING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } - - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; - - @Override - public String getStyle(final CellReference cellReference) { - String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } - - private void onClickOfRolloutName(RendererClickEvent event) { - rolloutUIState.setRolloutId((long) event.getItemId()); - final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - rolloutUIState.setRolloutName(rolloutName); - String ds = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); - rolloutUIState.setRolloutDistributionSet(ds); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); - } - - private void onClickOfActionBtn(RendererClickEvent event) { - final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); - contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); - contextMenu.open(event.getClientX(), event.getClientY()); - } - - private ContextMenu createContextMenu(final Long rolloutId) { - final ContextMenu context = new ContextMenu(); - context.addItemClickListener(event -> menuItemClicked(event)); - final Item row = getContainerDataSource().getItem(rolloutId); - final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - - switch (rolloutStatus) { - case READY: - final ContextMenuItem startItem = context.addItem(START_OPTION); - startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); - break; - case RUNNING: - final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); - pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); - break; - case PAUSED: - final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); - resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); - break; - case STARTING: - case CREATING: - case ERROR_CREATING: - case ERROR_STARTING: - // do not provide any action on these statuses - return context; - default: - break; - } - getUpdateMenuItem(context, rolloutId); - return context; - } - - - private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { - // Add 'Update' option only if user has update permission - if (!permissionChecker.hasRolloutUpdatePermission()) { - return; - } - final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); - cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); - } - - private String convertRolloutStatusToString(final RolloutStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); - if (statusFontIcon == null) { - return null; - } - String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); - } - - private void menuItemClicked(final ContextMenuItemClickEvent event) { - final ContextMenuItem item = (ContextMenuItem) event.getSource(); - final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); - final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - switch (contextMenuData.getAction()) { - case PAUSE: - rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); - break; - case RESUME: - rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); - break; - case START: - rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); - uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); - break; - case UPDATE: - onUpdate(contextMenuData); - break; - default: - break; - } - } - - private void onUpdate(final ContextMenuData contextMenuData) { - addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); - final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); - addTargetWindow.setCaption(i18n.get("caption.update.rollout")); - UI.getCurrent().addWindow(addTargetWindow); - addTargetWindow.setVisible(Boolean.TRUE); - } - - private void refreshGrid() { - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } - - public final class FontIconGenerator extends PropertyValueGenerator { - - private static final long serialVersionUID = 2544026030795375748L; - private final FontAwesome fontIcon; - - public FontIconGenerator(FontAwesome icon) { - this.fontIcon = icon; - } - - @Override - public String getValue(Item item, Object itemId, Object propertyId) { - return fontIcon.getHtml(); - } - - @Override - public Class getType() { - return String.class; - } - } - - private String getDescription(CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (SPUILabelDefinitions.VAR_NAME.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } - - enum ACTION { - PAUSE, RESUME, START, UPDATE - } - - /** - * Represents data of context menu item. - * - */ - public static class ContextMenuData { - - private Long rolloutId; - - private ACTION action; - - /** - * Set rollout if and action. - * - * @param rolloutId - * id of rollout - * @param action - * user action {@link ACTION} - */ - public ContextMenuData(final Long rolloutId, final ACTION action) { - this.action = action; - this.rolloutId = rolloutId; - } - - /** - * @return the rolloutId - */ - public Long getRolloutId() { - return rolloutId; - } - - /** - * @param rolloutId - * the rolloutId to set - */ - public void setRolloutId(final Long rolloutId) { - this.rolloutId = rolloutId; - } - - /** - * @return the action - */ - public ACTION getAction() { - return action; - } - - /** - * @param action - * the action to set - */ - public void setAction(final ACTION action) { - this.action = action; - } - } - - /** - * - * Converter to convert {@link RolloutStatus} to string. - * - */ - class RolloutStatusConverter implements Converter { - - private static final long serialVersionUID = -1217685750825632678L; - - @Override - public RolloutStatus convertToModel(final String value, final Class targetType, - final Locale locale) { - return null; - } - - @Override - public String convertToPresentation(final RolloutStatus value, final Class targetType, - final Locale locale) { - return convertRolloutStatusToString(value); - } - - @Override - public Class getModelType() { - return RolloutStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } - - /** - * Converter to convert {@link TotalTargetCountStatus} to formatted string - * with status and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { - - private static final long serialVersionUID = -5794528427855153924L; - - @Override - public TotalTargetCountStatus convertToModel(String value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(TotalTargetCountStatus value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } - - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } + private static final long serialVersionUID = 4060904914954370524L; + + private static final String UPDATE_OPTION = "Update"; + + private static final String RESUME_OPTION = "Resume"; + + private static final String PAUSE_OPTION = "Pause"; + + private static final String START_OPTION = "Start"; + + @Autowired + private I18N i18n; + + @Autowired + private transient EventBus.SessionEventBus eventBus; + + @Autowired + private transient RolloutManagement rolloutManagement; + + @Autowired + private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; + + @Autowired + private UINotification uiNotification; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); + + @Override + @PostConstruct + protected void init() { + super.init(); + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + switch (event) { + case FILTER_BY_TEXT: + case CREATE_ROLLOUT: + case UPDATE_ROLLOUT: + case SHOW_ROLLOUTS: + refreshGrid(); + break; + default: + return; + } + } + + /** + * Handles the RolloutChangeEvent to refresh the item in the grid. + * + * @param rolloutChangeEvent + * the event which contains the rollout which has been changed + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { + if (!rolloutUIState.isShowRollOuts()) { + return; + } + final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); + final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); + item.getItemProperty("customObject").setValue(new CustomObject(rollout.getName(), rollout.getStatus().toString())); + final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); + /*if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + }*/ + final int groupsCreated = rollout.getRolloutGroupsCreated(); + if (groupsCreated != 0) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); + } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + } + + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, null, false, false); + // rolloutGridContainer.addContainerProperty("yes", Boolean.class, null, + // false, false); + // rolloutGridContainer.addContainerProperty("custom", + // CustomValue.class, + // null, false, false); + // rolloutGridContainer.addContainerProperty("buttonText", String.class, + // "", false, false); + + rolloutGridContainer.addContainerProperty("customObject", CustomObject.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, + FontAwesome.CIRCLE_O.getHtml(), false, false); + + } + + @Override + protected void setColumnExpandRatio() { + getColumn("customObject").setMinimumWidth(40); + getColumn("customObject").setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + + setFrozenColumnCount(getColumns().size()); + } + + @Override + protected void setColumnHeaderNames() { + // getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption("name"); + getColumn("customObject").setHeaderCaption("Name"); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); + } + + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; + } + + @Override + protected void setColumnProperties() { + List columnList = new ArrayList<>(); + // columnList.add("yes"); + columnList.add("customObject"); + // columnList.add(SPUILabelDefinitions.VAR_NAME); + columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ACTION); + + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + @Override + protected void setHiddenColumns() { + List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } + + @Override + protected void addColumnRenderes() { + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), + new TotalTargetGroupsConverter()); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + + createRolloutStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); + + getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); + + /////////////// + // getColumn("customObject").setRenderer(new CustomObjectRenderer(event + // -> onClickOfRolloutName(event))); + CustomObjectRenderer cor = new CustomObjectRenderer(CustomObject.class); + cor.addClickListener(event -> onClickOfRolloutName(event)); + getColumn("customObject").setRenderer(cor); + + /////////////////////// + + // getColumn("custom").setRenderer(new CheckboxRenderer()); + // getColumn("buttonText").setRenderer(new + // MyButtonRenderer(event->x())); + } + + private void createRolloutStatusToFontMap() { + statusIconMap.put(RolloutStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutStatus.PAUSED, + new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); + statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); + statusIconMap.put(RolloutStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutStatus.STOPPED, + new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); + statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); + statusIconMap.put(RolloutStatus.ERROR_CREATING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.ERROR_STARTING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + private void onClickOfRolloutName(RendererClickEvent event) { + rolloutUIState.setRolloutId((long) event.getItemId()); + + // final String rolloutName = + CustomObject customObject = (CustomObject) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty("customObject").getValue(); + rolloutUIState.setRolloutName(customObject.getName()); + String ds = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); + rolloutUIState.setRolloutDistributionSet(ds); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); + } + + private void onClickOfActionBtn(RendererClickEvent event) { + final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); + contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); + contextMenu.open(event.getClientX(), event.getClientY()); + } + + private ContextMenu createContextMenu(final Long rolloutId) { + final ContextMenu context = new ContextMenu(); + context.addItemClickListener(event -> menuItemClicked(event)); + final Item row = getContainerDataSource().getItem(rolloutId); + final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) + .getValue(); + + switch (rolloutStatus) { + case READY: + final ContextMenuItem startItem = context.addItem(START_OPTION); + startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); + break; + case RUNNING: + final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); + pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); + break; + case PAUSED: + final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); + resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); + break; + case STARTING: + case CREATING: + case ERROR_CREATING: + case ERROR_STARTING: + // do not provide any action on these statuses + return context; + default: + break; + } + getUpdateMenuItem(context, rolloutId); + return context; + } + + private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { + // Add 'Update' option only if user has update permission + if (!permissionChecker.hasRolloutUpdatePermission()) { + return; + } + final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); + cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); + } + + private String convertRolloutStatusToString(final RolloutStatus value) { + StatusFontIcon statusFontIcon = statusIconMap.get(value); + if (statusFontIcon == null) { + return null; + } + String codePoint = statusFontIcon.getFontIcon() != null + ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + } + + private void menuItemClicked(final ContextMenuItemClickEvent event) { + final ContextMenuItem item = (ContextMenuItem) event.getSource(); + final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); + final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); + final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + switch (contextMenuData.getAction()) { + case PAUSE: + rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); + break; + case RESUME: + rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); + break; + case START: + rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); + uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); + break; + case UPDATE: + onUpdate(contextMenuData); + break; + default: + break; + } + } + + private void onUpdate(final ContextMenuData contextMenuData) { + addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); + final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); + addTargetWindow.setCaption(i18n.get("caption.update.rollout")); + UI.getCurrent().addWindow(addTargetWindow); + addTargetWindow.setVisible(Boolean.TRUE); + } + + private void refreshGrid() { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + + public final class FontIconGenerator extends PropertyValueGenerator { + + private static final long serialVersionUID = 2544026030795375748L; + private final FontAwesome fontIcon; + + public FontIconGenerator(FontAwesome icon) { + this.fontIcon = icon; + } + + @Override + public String getValue(Item item, Object itemId, Object propertyId) { + return fontIcon.getHtml(); + } + + @Override + public Class getType() { + return String.class; + } + } + + private String getDescription(CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if ("customObject".equals(cell.getPropertyId())) { + return ((CustomObject) cell.getProperty().getValue()).getName(); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } + return null; + } + + enum ACTION { + PAUSE, RESUME, START, UPDATE + } + + /** + * Represents data of context menu item. + * + */ + public static class ContextMenuData { + + private Long rolloutId; + + private ACTION action; + + /** + * Set rollout if and action. + * + * @param rolloutId + * id of rollout + * @param action + * user action {@link ACTION} + */ + public ContextMenuData(final Long rolloutId, final ACTION action) { + this.action = action; + this.rolloutId = rolloutId; + } + + /** + * @return the rolloutId + */ + public Long getRolloutId() { + return rolloutId; + } + + /** + * @param rolloutId + * the rolloutId to set + */ + public void setRolloutId(final Long rolloutId) { + this.rolloutId = rolloutId; + } + + /** + * @return the action + */ + public ACTION getAction() { + return action; + } + + /** + * @param action + * the action to set + */ + public void setAction(final ACTION action) { + this.action = action; + } + } + + /** + * + * Converter to convert {@link RolloutStatus} to string. + * + */ + class RolloutStatusConverter implements Converter { + + private static final long serialVersionUID = -1217685750825632678L; + + @Override + public RolloutStatus convertToModel(final String value, final Class targetType, + final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutStatus value, final Class targetType, + final Locale locale) { + return convertRolloutStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + } + + /** + * Converter to convert {@link TotalTargetCountStatus} to formatted string + * with status and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { + + private static final long serialVersionUID = -5794528427855153924L; + + @Override + public TotalTargetCountStatus convertToModel(String value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(TotalTargetCountStatus value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } + + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + } + + /** + * + * Converter to convert 0 to empty , if total target groups is zero. + * + */ + + class TotalTargetGroupsConverter implements Converter { + + private static final long serialVersionUID = 6589305227035220369L; + + @Override + public Long convertToModel(String value, Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(Long value, Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + if (value == 0) { + return ""; + } + return value.toString(); + } + + @Override + public Class getModelType() { + return Long.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index bb802c123..3033ff02c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; /** * Proxy rollout group with suctome properties. @@ -39,6 +40,16 @@ public class ProxyRolloutGroup extends RolloutGroup { private Boolean isActionRecieved = Boolean.FALSE; private String totalTargetsCount; + + private CustomObject customObject; + + public CustomObject getCustomObject() { + return customObject; + } + + public void setCustomObject(CustomObject customObject) { + this.customObject = customObject; + } /** * @return the createdDate diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index 0dabb18fc..1902a7d9d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -15,6 +15,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -121,6 +122,8 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setSuccessCondition(rolloutGroup.getSuccessCondition()); proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); + + proxyRolloutGroup.setCustomObject(new CustomObject(rolloutGroup.getName(), null)); proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index 44d945efd..4fc023759 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -20,13 +20,15 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; import org.eclipse.hawkbit.repository.RolloutGroupManagement; +import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; -import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -47,6 +49,7 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.data.Container; import com.vaadin.data.Item; +import com.vaadin.data.util.GeneratedPropertyContainer; import com.vaadin.data.util.converter.Converter; import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; @@ -62,335 +65,392 @@ import com.vaadin.ui.renderers.HtmlRenderer; @SpringComponent @ViewScope public class RolloutGroupListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; + private static final long serialVersionUID = 4060904914954370524L; - @Autowired - private I18N i18n; + @Autowired + private I18N i18n; - @Autowired - private transient EventBus.SessionEventBus eventBus; + @Autowired + private transient EventBus.SessionEventBus eventBus; - @Autowired - private transient RolloutGroupManagement rolloutGroupManagement; + @Autowired + private transient RolloutGroupManagement rolloutGroupManagement; - @Autowired - private transient RolloutUIState rolloutUIState; + @Autowired + private transient RolloutManagement rolloutManagement; - @Autowired - private transient SpPermissionChecker permissionChecker; + @Autowired + private transient RolloutUIState rolloutUIState; - private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); + @Autowired + private transient SpPermissionChecker permissionChecker; - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } + private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } + private final String name = "name"; - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { - return; - } - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } + @Override + @PostConstruct + protected void init() { + super.init(); + eventBus.subscribe(this); + } - /** - * - * Handles the RolloutGroupChangeEvent to refresh the item in the grid. - * - * - * @param rolloutGroupChangeEvent - * the event which contains the rollout group which has been - * change - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { - if (!rolloutUIState.isShowRolloutGroups()) { - return; - } - final RolloutGroup rolloutGroup = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutGroup.getId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setValue(rolloutGroup.getTotalTargetCountStatus()); - } + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { + return; + } + getLazyQueryContainer().refresh(); + } - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, - false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, - String.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, - null, false, false); + /** + * + * Handles the RolloutGroupChangeEvent to refresh the item in the grid. + * + * + * @param rolloutGroupChangeEvent + * the event which contains the rollout group which has been + * change + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { + if (!rolloutUIState.isShowRolloutGroups()) { + return; + } + final RolloutGroup rolloutGroup = rolloutGroupManagement + .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); + final LazyQueryContainer rolloutContainer = getLazyQueryContainer(); + final Item item = rolloutContainer.getItem(rolloutGroup.getId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setValue(rolloutGroup.getTotalTargetCountStatus()); + item.getItemProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setValue(calculateFinishedPercentage(rolloutGroup)); + } - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, - false, false); + private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { + return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, + rolloutManagement.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); + } - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); + return new GeneratedPropertyContainer(new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf)); + } - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, - false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGroupGridContainer = getLazyQueryContainer(); + rolloutGroupGridContainer.addContainerProperty("customObject", CustomObject.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, + String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, + null, false, false); - } + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, + false, false); - @Override - protected void setColumnExpandRatio() { - getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(200); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + // addGeneratedProperties(); + } - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + /* + * private void addGeneratedProperties() { GeneratedPropertyContainer + * generatedPropertyContainer = (GeneratedPropertyContainer) + * getContainerDataSource(); // + * generatedPropertyContainer.addGeneratedProperty(SPUILabelDefinitions. + * VAR_NAME, // new PropertyValueGenerator() { // + * private static final long serialVersionUID = -9203261132281441831L; // + * // @Override // public CustomRollOutDetails getValue(Item item, Object + * itemId, Object // propertyId) { // CustomRollOutDetails + * customRollOutDetails = new // CustomRollOutDetails(); // + * customRollOutDetails.setRolloutName( // (String) // + * item.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue().toString() + * ); // return customRollOutDetails; // } // // @Override // public + * Class getType() { // return + * CustomRollOutDetails.class; // } // }); + * + * } + */ - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); + @Override + protected void setColumnExpandRatio() { + /*getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(200);*/ + + getColumn("customObject").setMinimumWidth(40); + getColumn("customObject").setMaximumWidth(200); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); - setFrozenColumnCount(7); - } + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); - @Override - protected void setColumnHeaderNames() { - getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) - .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) - .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) - .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - } + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; - } + setFrozenColumnCount(7); + } - @Override - protected void setColumnProperties() { - List columnList = new ArrayList<>(); - columnList.add(SPUILabelDefinitions.VAR_NAME); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } + @Override + protected void setColumnHeaderNames() { + //getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); + getColumn("customObject").setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + } - @Override - protected void addColumnRenderes() { - createRolloutGroupStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), - new RolloutGroupStatusConverter()); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - if (permissionChecker.hasRolloutTargetsReadPermission()) { - getColumn(SPUILabelDefinitions.VAR_NAME) - .setRenderer(new LinkRenderer(event -> onClickOfRolloutGroupName(event))); - } - } + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; + } - @Override - protected void setHiddenColumns() { - List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - } + @Override + protected void setColumnProperties() { + List columnList = new ArrayList<>(); + columnList.add("customObject"); + //columnList.add(SPUILabelDefinitions.VAR_NAME); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } + @Override + protected void addColumnRenderes() { + createRolloutGroupStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), + new RolloutGroupStatusConverter()); - private void onClickOfRolloutGroupName(RendererClickEvent event) { - rolloutUIState - .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); - } + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + if (permissionChecker.hasRolloutTargetsReadPermission()) { + /* + * getColumn(SPUILabelDefinitions.VAR_NAME) .setRenderer(new + * LinkRenderer(event -> onClickOfRolloutGroupName(event))); + */ + CustomObjectRenderer cor = new CustomObjectRenderer(CustomObject.class); + cor.addClickListener(event -> onClickOfRolloutGroupName(event)); + getColumn("customObject").setRenderer(cor); - private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); - if (statusFontIcon == null) { - return null; - } - String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + } + } - } + @Override + protected void setHiddenColumns() { + List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + } - private void createRolloutGroupStatusToFontMap() { - statusIconMap.put(RolloutGroupStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutGroupStatus.SCHEDULED, - new StatusFontIcon(FontAwesome.HOURGLASS_1, SPUIStyleDefinitions.STATUS_ICON_PENDING)); - statusIconMap.put(RolloutGroupStatus.RUNNING, - new StatusFontIcon(FontAwesome.ADJUST, SPUIStyleDefinitions.STATUS_ICON_YELLOW)); - statusIconMap.put(RolloutGroupStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutGroupStatus.ERROR, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } - private String getDescription(CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (SPUILabelDefinitions.VAR_NAME.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } + private void onClickOfRolloutGroupName(RendererClickEvent event) { + rolloutUIState + .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); + } - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; + private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { + StatusFontIcon statusFontIcon = statusIconMap.get(value); + if (statusFontIcon == null) { + return null; + } + String codePoint = statusFontIcon.getFontIcon() != null + ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); - @Override - public String getStyle(final CellReference cellReference) { - String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, - SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } + } - /** - * - * Converts {@link TotalTargetCountStatus} into formatted string with status - * and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { + private void createRolloutGroupStatusToFontMap() { + statusIconMap.put(RolloutGroupStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutGroupStatus.SCHEDULED, + new StatusFontIcon(FontAwesome.HOURGLASS_1, SPUIStyleDefinitions.STATUS_ICON_PENDING)); + statusIconMap.put(RolloutGroupStatus.RUNNING, + new StatusFontIcon(FontAwesome.ADJUST, SPUIStyleDefinitions.STATUS_ICON_YELLOW)); + statusIconMap.put(RolloutGroupStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutGroupStatus.ERROR, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } - private static final long serialVersionUID = -9205943894818450807L; + private String getDescription(CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if ("customObject".equals(cell.getPropertyId())) { + return ((CustomObject) cell.getProperty().getValue()).getName(); + // getNameToolTip(cell.getProperty().getValue().toString()); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } + return null; + } - @Override - public TotalTargetCountStatus convertToModel(String value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } + private String getNameToolTip(final String text) { + String[] nameList = text.split(":"); + if (nameList[0].equalsIgnoreCase(name)) { + return nameList[1]; + } + return ""; + } - @Override - public String convertToPresentation(TotalTargetCountStatus value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } + @Override + public String getStyle(final CellReference cellReference) { + String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, + SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } - @Override - public Class getPresentationType() { - return String.class; - } - } + private LazyQueryContainer getLazyQueryContainer() { + return ((LazyQueryContainer) (((GeneratedPropertyContainer) getContainerDataSource()).getWrappedContainer())); + } - /** - * - * Converts {@link RolloutGroupStatus} to string. - * - */ - class RolloutGroupStatusConverter implements Converter { + /** + * + * Converts {@link TotalTargetCountStatus} into formatted string with status + * and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { - private static final long serialVersionUID = 5448062736373292820L; + private static final long serialVersionUID = -9205943894818450807L; - @Override - public RolloutGroupStatus convertToModel(final String value, - final Class targetType, final Locale locale) { - return null; - } + @Override + public TotalTargetCountStatus convertToModel(String value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } - @Override - public String convertToPresentation(final RolloutGroupStatus value, final Class targetType, - final Locale locale) { - return convertRolloutGroupStatusToString(value); - } + @Override + public String convertToPresentation(TotalTargetCountStatus value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } - @Override - public Class getModelType() { - return RolloutGroupStatus.class; - } + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } - @Override - public Class getPresentationType() { - return String.class; - } + @Override + public Class getPresentationType() { + return String.class; + } + } - } + /** + * + * Converts {@link RolloutGroupStatus} to string. + * + */ + class RolloutGroupStatusConverter implements Converter { + + private static final long serialVersionUID = 5448062736373292820L; + + @Override + public RolloutGroupStatus convertToModel(final String value, + final Class targetType, final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutGroupStatus value, final Class targetType, + final Locale locale) { + return convertRolloutGroupStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutGroupStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } } diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss index 712e04ec1..b9049068e 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss @@ -19,20 +19,32 @@ } } + .v-context-menu .v-context-menu-item-basic-icon-container{ height:0px !important; width:0px !important; } - .v-context-menu, .v-context-menu .v-context-menu-item-basic{ + .v-context-menu .v-context-menu-item-basic{ background-color: #feffff !important; border-radius: 4px; + font-family : $app-font-family; + font-size : $app-text-font-size; + font-weight : normal; + font-style : normal; } + + .v-context-menu{ + background-color: #feffff !important; + border-radius: 4px; + } + .v-context-menu .v-context-menu-item-basic:focus, .v-context-menu .v-context-menu-item-basic-submenu:focus, .v-context-menu .v-context-menu-item-basic-open { @include valo-gradient($color: $hawkbit-primary-color); background-color: $hawkbit-primary-color !important; color: #e8eef3; + height: 30px; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.05); } @@ -77,5 +89,9 @@ border-left: $v-grid-border-size solid $widget-border-color ; } + .v-button-boldhide{ + text-decoration:none; + } + } \ No newline at end of file From b95b9c1ce6e52689fb68db0a64ffb0df0cde1a03 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 13 Apr 2016 14:20:27 +0200 Subject: [PATCH 37/49] Move @SuppressWarnings("unchecked") to the right line and remove unused attributes Signed-off-by: SirWayne --- .../ui/distributions/dstable/DistributionSetTable.java | 7 +------ .../ui/management/event/DistributionTagDropEvent.java | 4 +--- .../hawkbit/ui/management/footer/DeleteActionsLayout.java | 4 ++-- .../hawkbit/ui/management/targettable/TargetTable.java | 6 +++--- .../ui/management/targettable/TargetTableHeader.java | 3 +-- .../ui/management/targettag/TargetTagFilterButtons.java | 4 +--- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index b5d614243..4a7b74ece 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -209,9 +209,9 @@ public class DistributionSetTable extends AbstractNamedVersionTable source = (AbstractTable) transferable.getSourceComponent(); final Set softwareModulesIdList = source.getDeletedEntityByTransferable(transferable); @@ -224,11 +224,6 @@ public class DistributionSetTable extends AbstractNamedVersionTable softwareModulesIdList, final Item item) { final Long distId = (Long) item.getItemProperty("id").getValue(); final String distName = (String) item.getItemProperty("name").getValue(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java index 97ba7ea6c..2b6acbf68 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java @@ -68,8 +68,6 @@ public class DistributionTagDropEvent implements DropHandler { @Autowired private ManagementViewAcceptCriteria managementViewAcceptCriteria; - private static final String ITEMID = "itemId"; - @Override public void drop(final DragAndDropEvent event) { if (validate(event) && isNoTagAssigned(event)) { @@ -127,12 +125,12 @@ public class DistributionTagDropEvent implements DropHandler { return true; } - @SuppressWarnings("unchecked") private void processDistributionDrop(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails(); final TableTransferable transferable = (TableTransferable) event.getTransferable(); + @SuppressWarnings("unchecked") final AbstractTable source = (AbstractTable) transferable .getSourceComponent(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 0466e6076..7db48636b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -256,8 +256,8 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } } - @SuppressWarnings("unchecked") private void addInDeleteDistributionList(final Table sourceTable, final TableTransferable transferable) { + @SuppressWarnings("unchecked") final AbstractTable distTable = (AbstractTable) sourceTable; final Set distributionIdNameSet = distTable.getDeletedEntityByTransferable(transferable); @@ -305,8 +305,8 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { return false; } - @SuppressWarnings("unchecked") private void addInDeleteTargetList(final Table sourceTable, final TableTransferable transferable) { + @SuppressWarnings("unchecked") final AbstractTable targetTable = (AbstractTable) sourceTable; final Set targetIdNameSet = targetTable.getDeletedEntityByTransferable(transferable); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 1307e27d3..3b9c18952 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -107,7 +107,6 @@ public class TargetTable extends AbstractTable implements private static final long serialVersionUID = -2300392868806614568L; private static final int PROPERTY_DEPT = 3; - private static final String ITEMID = "itemId"; private static final String ACTION_NOT_ALLOWED_MSG = "message.action.not.allowed"; @Autowired @@ -632,9 +631,9 @@ public class TargetTable extends AbstractTable implements return true; } - @SuppressWarnings("unchecked") private static Set getDraggedDistributionSet(final TableTransferable transferable, final Table source) { + @SuppressWarnings("unchecked") final AbstractTable distTable = (AbstractTable) source; return distTable.getDeletedEntityByTransferable(transferable); } @@ -853,6 +852,7 @@ public class TargetTable extends AbstractTable implements eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.REFRESH_TARGETS)); } + @SuppressWarnings("unchecked") private void updateVisibleItemOnEvent(final TargetInfo targetInfo, final Target target, final TargetIdName targetIdName) { final LazyQueryContainer targetContainer = (LazyQueryContainer) getContainerDataSource(); @@ -875,8 +875,8 @@ public class TargetTable extends AbstractTable implements * @param targetInfoUpdateEvents * list of target info update event */ - @SuppressWarnings("unchecked") private void onTargetInfoUpdateEvents(final List targetInfoUpdateEvents) { + @SuppressWarnings("unchecked") final List visibleItemIds = (List) getVisibleItemIds(); boolean shoulTargetsUpdated = false; Target lastSelectedTarget = null; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index 158d57878..09c9bf499 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.targettable; -import java.util.HashSet; import java.util.Set; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; @@ -378,8 +377,8 @@ public class TargetTableHeader extends AbstractTableHeader { return isValid; } - @SuppressWarnings("unchecked") private Set getDropppedDistributionDetails(final TableTransferable transferable) { + @SuppressWarnings("unchecked") final AbstractTable distTable = (AbstractTable) transferable.getSourceComponent(); return distTable.getDeletedEntityByTransferable(transferable); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 671d332de..4d96a4b7a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -78,8 +78,6 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { @Autowired private transient TargetManagement targetManagement; - private static final String ITEMID = "itemId"; - TargetTagFilterButtonClick filterButtonClickBehaviour; /** @@ -211,10 +209,10 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { return true; } - @SuppressWarnings("unchecked") private void processTargetDrop(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails(); final TableTransferable transferable = (TableTransferable) event.getTransferable(); + @SuppressWarnings("unchecked") final AbstractTable targetTable = (AbstractTable) transferable .getSourceComponent(); From f70120d5461959e0fa7abc0bb4382e17885341f1 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 13 Apr 2016 15:36:14 +0200 Subject: [PATCH 38/49] Set the id after the update Signed-off-by: SirWayne --- .../hawkbit/ui/distributions/dstable/DistributionSetTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 4e6be369d..998cd1de2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -471,9 +471,9 @@ public class DistributionSetTable extends AbstractNamedVersionTable Date: Wed, 13 Apr 2016 15:47:08 +0200 Subject: [PATCH 39/49] Version should be set after id Signed-off-by: SirWayne --- .../hawkbit/ui/common/table/AbstractNamedVersionTable.java | 2 +- .../hawkbit/ui/distributions/dstable/DistributionSetTable.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java index b14c69a51..3e215f77c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java @@ -40,8 +40,8 @@ public abstract class AbstractNamedVersionTable Date: Wed, 13 Apr 2016 16:52:12 +0200 Subject: [PATCH 40/49] Refactoring: Extract some staff to private methods Signed-off-by: SirWayne --- .../footer/DeleteActionsLayout.java | 51 +++++++------------ .../targettag/TargetTagFilterButtons.java | 32 +++++++++--- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 7db48636b..5435a8f74 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -270,27 +270,20 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { if (distributionIdNameSet.isEmpty()) { return; } - /* - * Flags to identify whether all dropped distributions are already in - * the deleted list (or) some distributions are already in the deleted - * distribution list. - */ + checkDeletedDistributionSets(distributionIdNameSet); + } + + private void checkDeletedDistributionSets(final Set distributionIdNameSet) { final int existingDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); managementUIState.getDeletedDistributionList().addAll(distributionIdNameSet); final int newDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); + if (newDeletedDistributionsSize == existingDeletedDistributionsSize) { - /* - * No new distributions are added, all distributions dropped now are - * already available in the delete list. Hence display warning - * message accordingly. - */ notification.displayValidationError(i18n.get("message.targets.already.deleted")); - } else if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { - /* - * Not the all distributions dropped now are added to the delete - * list. There are some distributions are already there in the - * delete list. Hence display warning message accordingly. - */ + return; + } + + if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { notification.displayValidationError(i18n.get("message.dist.deleted.pending")); } } @@ -310,28 +303,22 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { final AbstractTable targetTable = (AbstractTable) sourceTable; final Set targetIdNameSet = targetTable.getDeletedEntityByTransferable(transferable); - /* - * Flags to identify whether all dropped targets are already in the - * deleted list (or) some target are already in the deleted distribution - * list. - */ + checkDeletedTargets(targetIdNameSet); + } + + private void checkDeletedTargets(final Set targetIdNameSet) { final int existingDeletedTargetsSize = managementUIState.getDeletedTargetList().size(); managementUIState.getDeletedTargetList().addAll(targetIdNameSet); final int newDeletedTargetsSize = managementUIState.getDeletedTargetList().size(); + if (newDeletedTargetsSize == existingDeletedTargetsSize) { - /* - * No new targets are added, all targets dropped now are already - * available in the delete list. Hence display warning message - * accordingly. - */ notification.displayValidationError(i18n.get("message.targets.already.deleted")); - } else if (newDeletedTargetsSize - existingDeletedTargetsSize != targetIdNameSet.size()) { - /* - * Not the all targets dropped now are added to the delete list. - * There are some targets are already there in the delete list. - * Hence display warning message accordingly. - */ + return; + } + + if (newDeletedTargetsSize - existingDeletedTargetsSize != targetIdNameSet.size()) { notification.displayValidationError(i18n.get("message.target.deleted.pending")); + return; } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 4d96a4b7a..4e5246703 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -223,18 +223,33 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), SPUIDefinitions.TARGET_TAG_ID_PREFIXS); - final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); - final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(targTagName, result, i18n)); - if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { - eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); - } - if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty() && tagsClickedList.contains(targTagName)) { - eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); - } + publishAssignTargetTagEvent(result); + publishUnAssignTargetTagEvent(targTagName, result); + + } + + private void publishUnAssignTargetTagEvent(final String targTagName, final TargetTagAssignmentResult result) { + final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); + final boolean isTargetTagUnAssigned = result.getUnassigned() >= 1 && !tagsClickedList.isEmpty() + && tagsClickedList.contains(targTagName); + + if (!isTargetTagUnAssigned) { + return; + } + eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); + } + + private void publishAssignTargetTagEvent(final TargetTagAssignmentResult result) { + final boolean isNewTargetTagAssigned = result.getAssigned() >= 1 + && managementUIState.getTargetTableFilters().isNoTagSelected(); + if (!isNewTargetTagAssigned) { + return; + } + eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); } private boolean validateIfSourceisTargetTable(final Table source) { @@ -281,6 +296,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { } } + @SuppressWarnings("unchecked") private void addNewTargetTag(final TargetTag newTargetTag) { final LazyQueryContainer targetTagContainer = (LazyQueryContainer) getContainerDataSource(); final Object addItem = targetTagContainer.addItem(); From 4b6a6a4a4aadad54e374601308d94f7ae78aaf0c Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 13 Apr 2016 17:37:55 +0200 Subject: [PATCH 41/49] Refactoring: Extract some staff to private methods and remove duplicated code Signed-off-by: SirWayne --- .../footer/DeleteActionsLayout.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 5435a8f74..ad537e626 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -278,14 +278,27 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { managementUIState.getDeletedDistributionList().addAll(distributionIdNameSet); final int newDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); - if (newDeletedDistributionsSize == existingDeletedDistributionsSize) { - notification.displayValidationError(i18n.get("message.targets.already.deleted")); + showAlreadyDeletedDistributionSetNotfication(existingDeletedDistributionsSize, newDeletedDistributionsSize, + "message.dists.already.deleted"); + showPendingDeletedNotifaction(distributionIdNameSet, existingDeletedDistributionsSize, + newDeletedDistributionsSize, "message.dist.deleted.pending"); + } + + private void showPendingDeletedNotifaction(final Set currentValues, final int existingDeletedSize, + final int newDeletedSize, final String messageKey) { + if (newDeletedSize - existingDeletedSize == currentValues.size()) { return; } + notification.displayValidationError(i18n.get(messageKey)); + } - if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { - notification.displayValidationError(i18n.get("message.dist.deleted.pending")); + private void showAlreadyDeletedDistributionSetNotfication(final int existingDeletedSize, final int newDeletedSize, + final String messageKey) { + + if (newDeletedSize != existingDeletedSize) { + return; } + notification.displayValidationError(i18n.get(messageKey)); } private boolean isDsInUseInBulkUpload(final Set distributionIdNameSet, @@ -311,15 +324,11 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { managementUIState.getDeletedTargetList().addAll(targetIdNameSet); final int newDeletedTargetsSize = managementUIState.getDeletedTargetList().size(); - if (newDeletedTargetsSize == existingDeletedTargetsSize) { - notification.displayValidationError(i18n.get("message.targets.already.deleted")); - return; - } + showAlreadyDeletedDistributionSetNotfication(existingDeletedTargetsSize, newDeletedTargetsSize, + "message.targets.already.deleted"); - if (newDeletedTargetsSize - existingDeletedTargetsSize != targetIdNameSet.size()) { - notification.displayValidationError(i18n.get("message.target.deleted.pending")); - return; - } + showPendingDeletedNotifaction(targetIdNameSet, existingDeletedTargetsSize, newDeletedTargetsSize, + "message.target.deleted.pending"); } private void updateActionCount() { From fc693f099451a69e48f5688d99474c337dddfc2f Mon Sep 17 00:00:00 2001 From: Asharani Murugesh Date: Thu, 14 Apr 2016 09:54:56 +0530 Subject: [PATCH 42/49] Corrected the typo as per review comment --- hawkbit-ui/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-ui/README.md b/hawkbit-ui/README.md index f8e020648..e1c7d8ffc 100644 --- a/hawkbit-ui/README.md +++ b/hawkbit-ui/README.md @@ -3,7 +3,7 @@ The application with user interface to create and manage rollouts. ## Debugging client-side code -### Debug usings SuperDevMode +### Debug using SuperDevMode The SuperDevMode can be used to debug client side code without any browser plugin. #### Using SuperDevMode with chrome : @@ -31,4 +31,4 @@ The SuperDevMode can be used to debug client side code without any browser plugi - Type is "Launch Chrome" - http://localhost:8080/UI/?superdevmode - Launch the new configuration in debug mode -- Now breakpoints in eclipse can be set \ No newline at end of file +- Now breakpoints in eclipse can be set From c8e88239c2201c9940999b5e21548ffaa3472904 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Thu, 14 Apr 2016 14:49:49 +0530 Subject: [PATCH 43/49] Rollout management issues Signed-off-by: venu1278 --- .../client/CustomObjectRendererConnector.java | 9 +++++++++ .../customrenderers/client/renderers/CustomObject.java | 8 ++++++++ .../client/renderers/CustomObjectRenederer.java | 8 ++++++++ .../customrenderers/renderers/CustomObjectRenderer.java | 9 +++++++++ 4 files changed, 34 insertions(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java index b209ab82c..c79e81924 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + package org.eclipse.hawkbit.ui.customrenderers.client; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java index 85b5d9404..f3a5c74c4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java @@ -1,3 +1,11 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ package org.eclipse.hawkbit.ui.customrenderers.client.renderers; import java.io.Serializable; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java index a6a527f2a..7931e9f84 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java @@ -1,3 +1,11 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ package org.eclipse.hawkbit.ui.customrenderers.client.renderers; import com.google.gwt.core.shared.GWT; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java index c2a7606a3..ae555f897 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + package org.eclipse.hawkbit.ui.customrenderers.renderers; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; From 2ca807916c0b5101dcb04396d0f5a2bf73f5043d Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 14 Apr 2016 13:32:24 +0200 Subject: [PATCH 44/49] fix lookup by filename and not by ID because the ID is unique and the filename exists multiple times Signed-off-by: Michael Hirsch --- .../repository/specifications/ActionSpecifications.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java index 1ac3afb67..62e7167f1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java @@ -53,7 +53,8 @@ public class ActionSpecifications { final Join dsJoin = actionRoot.join(Action_.distributionSet); final SetJoin modulesJoin = dsJoin.join(DistributionSet_.modules); final ListJoin artifactsJoin = modulesJoin.join(SoftwareModule_.artifacts); - return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(LocalArtifact_.id), localArtifact.getId()), + return criteriaBuilder.and( + criteriaBuilder.equal(artifactsJoin.get(LocalArtifact_.filename), localArtifact.getFilename()), criteriaBuilder.equal(actionRoot.get(Action_.target), target)); }; } From b9c389d8dbb93449b1a1a63e52f1b94ab175cbf9 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Fri, 15 Apr 2016 15:22:16 +0530 Subject: [PATCH 45/49] Rollout management issues Signed-off-by: venu1278 --- .../renderers/CustomObjectRenederer.java | 5 + .../renderers/CustomObjectRenderer.java | 20 +- .../ui/rollout/rollout/ProxyRollout.java | 2 +- .../ui/rollout/rollout/RolloutListGrid.java | 11 +- .../rolloutgroup/ProxyRolloutGroup.java | 316 +++++++++--------- 5 files changed, 187 insertions(+), 167 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java index 7931e9f84..262648178 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java @@ -13,6 +13,11 @@ import com.vaadin.client.renderers.ClickableRenderer; import com.vaadin.client.ui.VButton; import com.vaadin.client.widget.grid.RendererCellReference; +/** + * Renders button with provided CustomObject. + * Used to display button with link. + * + */ public class CustomObjectRenederer extends ClickableRenderer { @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java index ae555f897..02eca1bf9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java @@ -15,26 +15,36 @@ import com.vaadin.ui.renderers.ClickableRenderer; import elemental.json.JsonValue; +/** + * Renders button with provided CustomObject. + * Used to display button with link. + * + */ + public class CustomObjectRenderer extends ClickableRenderer { - /** - * - */ private static final long serialVersionUID = -8754180585906263554L; /** - * Creates a new image renderer. + * Creates a new custom object renderer. */ public CustomObjectRenderer() { super(CustomObject.class, null); } + + /** + * Initialize custom object renderer with {@link Class} + * + * @param presentationType + * Class + */ public CustomObjectRenderer(Class presentationType) { super(presentationType); } /** - * Creates a new image renderer and adds the given click listener to it. + * Creates a new custom object renderer and adds the given click listener to it. * * @param listener * the click listener to register diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 36cb7ddee..6649d7dcb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -14,7 +14,7 @@ import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; import com.vaadin.server.FontAwesome; /** - * Proxy rollout with suctome properties. + * Proxy rollout with custom properties. * */ public class ProxyRollout extends Rollout { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index f8da4b269..65f94aee6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -97,6 +97,10 @@ public class RolloutListGrid extends AbstractGrid { private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); + /** + * Handles the RolloutEvent to refresh Grid. + * + */ @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final RolloutEvent event) { switch (event) { @@ -419,6 +423,9 @@ public class RolloutListGrid extends AbstractGrid { ((LazyQueryContainer) getContainerDataSource()).refresh(); } + /** + * Generator to generate fontIcon by String. + */ public final class FontIconGenerator extends PropertyValueGenerator { private static final long serialVersionUID = 2544026030795375748L; @@ -585,11 +592,9 @@ public class RolloutListGrid extends AbstractGrid { } /** - * - * Converter to convert 0 to empty , if total target groups is zero. + * Converter to convert 0 to empty, if total target groups is zero. * */ - class TotalTargetGroupsConverter implements Converter { private static final long serialVersionUID = 6589305227035220369L; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index 3033ff02c..71fe2aa8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -12,36 +12,36 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; /** - * Proxy rollout group with suctome properties. + * Proxy rollout group with custom properties. * */ public class ProxyRolloutGroup extends RolloutGroup { - private static final long serialVersionUID = -2745056813306692356L; + private static final long serialVersionUID = -2745056813306692356L; - private String createdDate; + private String createdDate; - private String modifiedDate; + private String modifiedDate; - private String finishedPercentage; + private String finishedPercentage; - private Long runningTargetsCount; + private Long runningTargetsCount; - private Long scheduledTargetsCount; + private Long scheduledTargetsCount; - private Long cancelledTargetsCount; + private Long cancelledTargetsCount; - private Long errorTargetsCount; + private Long errorTargetsCount; - private Long finishedTargetsCount; + private Long finishedTargetsCount; - private Long notStartedTargetsCount; + private Long notStartedTargetsCount; - private Boolean isActionRecieved = Boolean.FALSE; + private Boolean isActionRecieved = Boolean.FALSE; - private String totalTargetsCount; - - private CustomObject customObject; + private String totalTargetsCount; + + private CustomObject customObject; public CustomObject getCustomObject() { return customObject; @@ -51,169 +51,169 @@ public class ProxyRolloutGroup extends RolloutGroup { this.customObject = customObject; } - /** - * @return the createdDate - */ - public String getCreatedDate() { - return createdDate; - } + /** + * @return the createdDate + */ + public String getCreatedDate() { + return createdDate; + } - /** - * @param createdDate - * the createdDate to set - */ - public void setCreatedDate(final String createdDate) { - this.createdDate = createdDate; - } + /** + * @param createdDate + * the createdDate to set + */ + public void setCreatedDate(final String createdDate) { + this.createdDate = createdDate; + } - /** - * @return the modifiedDate - */ - public String getModifiedDate() { - return modifiedDate; - } + /** + * @return the modifiedDate + */ + public String getModifiedDate() { + return modifiedDate; + } - /** - * @param modifiedDate - * the modifiedDate to set - */ - public void setModifiedDate(final String modifiedDate) { - this.modifiedDate = modifiedDate; - } + /** + * @param modifiedDate + * the modifiedDate to set + */ + public void setModifiedDate(final String modifiedDate) { + this.modifiedDate = modifiedDate; + } - /** - * @return the finishedPercentage - */ - public String getFinishedPercentage() { - return finishedPercentage; - } + /** + * @return the finishedPercentage + */ + public String getFinishedPercentage() { + return finishedPercentage; + } - /** - * @param finishedPercentage - * the finishedPercentage to set - */ - public void setFinishedPercentage(final String finishedPercentage) { - this.finishedPercentage = finishedPercentage; - } + /** + * @param finishedPercentage + * the finishedPercentage to set + */ + public void setFinishedPercentage(final String finishedPercentage) { + this.finishedPercentage = finishedPercentage; + } - /** - * @return the runningTargetsCount - */ - public Long getRunningTargetsCount() { - return runningTargetsCount; - } + /** + * @return the runningTargetsCount + */ + public Long getRunningTargetsCount() { + return runningTargetsCount; + } - /** - * @param runningTargetsCount - * the runningTargetsCount to set - */ - public void setRunningTargetsCount(final Long runningTargetsCount) { - this.runningTargetsCount = runningTargetsCount; - } + /** + * @param runningTargetsCount + * the runningTargetsCount to set + */ + public void setRunningTargetsCount(final Long runningTargetsCount) { + this.runningTargetsCount = runningTargetsCount; + } - /** - * @return the scheduledTargetsCount - */ - public Long getScheduledTargetsCount() { - return scheduledTargetsCount; - } + /** + * @return the scheduledTargetsCount + */ + public Long getScheduledTargetsCount() { + return scheduledTargetsCount; + } - /** - * @param scheduledTargetsCount - * the scheduledTargetsCount to set - */ - public void setScheduledTargetsCount(final Long scheduledTargetsCount) { - this.scheduledTargetsCount = scheduledTargetsCount; - } + /** + * @param scheduledTargetsCount + * the scheduledTargetsCount to set + */ + public void setScheduledTargetsCount(final Long scheduledTargetsCount) { + this.scheduledTargetsCount = scheduledTargetsCount; + } - /** - * @return the cancelledTargetsCount - */ - public Long getCancelledTargetsCount() { - return cancelledTargetsCount; - } + /** + * @return the cancelledTargetsCount + */ + public Long getCancelledTargetsCount() { + return cancelledTargetsCount; + } - /** - * @param cancelledTargetsCount - * the cancelledTargetsCount to set - */ - public void setCancelledTargetsCount(final Long cancelledTargetsCount) { - this.cancelledTargetsCount = cancelledTargetsCount; - } + /** + * @param cancelledTargetsCount + * the cancelledTargetsCount to set + */ + public void setCancelledTargetsCount(final Long cancelledTargetsCount) { + this.cancelledTargetsCount = cancelledTargetsCount; + } - /** - * @return the errorTargetsCount - */ - public Long getErrorTargetsCount() { - return errorTargetsCount; - } + /** + * @return the errorTargetsCount + */ + public Long getErrorTargetsCount() { + return errorTargetsCount; + } - /** - * @param errorTargetsCount - * the errorTargetsCount to set - */ - public void setErrorTargetsCount(final Long errorTargetsCount) { - this.errorTargetsCount = errorTargetsCount; - } + /** + * @param errorTargetsCount + * the errorTargetsCount to set + */ + public void setErrorTargetsCount(final Long errorTargetsCount) { + this.errorTargetsCount = errorTargetsCount; + } - /** - * @return the finishedTargetsCount - */ - public Long getFinishedTargetsCount() { - return finishedTargetsCount; - } + /** + * @return the finishedTargetsCount + */ + public Long getFinishedTargetsCount() { + return finishedTargetsCount; + } - /** - * @param finishedTargetsCount - * the finishedTargetsCount to set - */ - public void setFinishedTargetsCount(final Long finishedTargetsCount) { - this.finishedTargetsCount = finishedTargetsCount; - } + /** + * @param finishedTargetsCount + * the finishedTargetsCount to set + */ + public void setFinishedTargetsCount(final Long finishedTargetsCount) { + this.finishedTargetsCount = finishedTargetsCount; + } - /** - * @return the notStartedTargetsCount - */ - public Long getNotStartedTargetsCount() { - return notStartedTargetsCount; - } + /** + * @return the notStartedTargetsCount + */ + public Long getNotStartedTargetsCount() { + return notStartedTargetsCount; + } - /** - * @param notStartedTargetsCount - * the notStartedTargetsCount to set - */ - public void setNotStartedTargetsCount(final Long notStartedTargetsCount) { - this.notStartedTargetsCount = notStartedTargetsCount; - } + /** + * @param notStartedTargetsCount + * the notStartedTargetsCount to set + */ + public void setNotStartedTargetsCount(final Long notStartedTargetsCount) { + this.notStartedTargetsCount = notStartedTargetsCount; + } - /** - * @return the isActionRecieved - */ - public Boolean getIsActionRecieved() { - return isActionRecieved; - } + /** + * @return the isActionRecieved + */ + public Boolean getIsActionRecieved() { + return isActionRecieved; + } - /** - * @param isActionRecieved - * the isActionRecieved to set - */ - public void setIsActionRecieved(final Boolean isActionRecieved) { - this.isActionRecieved = isActionRecieved; - } + /** + * @param isActionRecieved + * the isActionRecieved to set + */ + public void setIsActionRecieved(final Boolean isActionRecieved) { + this.isActionRecieved = isActionRecieved; + } - /** - * @return the totalTargetsCount - */ - public String getTotalTargetsCount() { - return totalTargetsCount; - } + /** + * @return the totalTargetsCount + */ + public String getTotalTargetsCount() { + return totalTargetsCount; + } - /** - * @param totalTargetsCount - * the totalTargetsCount to set - */ - public void setTotalTargetsCount(final String totalTargetsCount) { - this.totalTargetsCount = totalTargetsCount; - } + /** + * @param totalTargetsCount + * the totalTargetsCount to set + */ + public void setTotalTargetsCount(final String totalTargetsCount) { + this.totalTargetsCount = totalTargetsCount; + } } From 878c5c869c0bccd7acccd92db7ec2d7e6f938bea Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Mon, 18 Apr 2016 07:54:38 +0200 Subject: [PATCH 46/49] adapt hawkBit user interface sentence Signed-off-by: Michael Hirsch --- hawkbit-ui/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/README.md b/hawkbit-ui/README.md index e1c7d8ffc..4bf9d67da 100644 --- a/hawkbit-ui/README.md +++ b/hawkbit-ui/README.md @@ -1,6 +1,6 @@ # hawkBit User Interface -The application with user interface to create and manage rollouts. +The hawkBit user interface is based on the Vaadin and Vaadin-Spring framework and allows to manage software updates and large scale roll-outs via a user interface. ## Debugging client-side code ### Debug using SuperDevMode From f290eb78e556cb4fa47a6c988bd72e62dd608d7c Mon Sep 17 00:00:00 2001 From: venu1278 Date: Mon, 18 Apr 2016 20:12:30 +0530 Subject: [PATCH 47/49] Rollout management issues Signed-off-by: venu1278 --- .../client/CustomObjectRendererConnector.java | 9 +- .../renderers/CustomObjectRenederer.java | 4 +- .../{CustomObject.java => RendererData.java} | 27 +- .../renderers/CustomObjectRenderer.java | 12 +- .../ui/rollout/rollout/ProxyRollout.java | 14 +- .../ui/rollout/rollout/RolloutBeanQuery.java | 287 +++++++++--------- .../ui/rollout/rollout/RolloutListGrid.java | 10 +- .../rolloutgroup/ProxyRolloutGroup.java | 14 +- .../rolloutgroup/RolloutGroupBeanQuery.java | 268 ++++++++-------- .../rolloutgroup/RolloutGroupListGrid.java | 6 +- 10 files changed, 336 insertions(+), 315 deletions(-) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/{CustomObject.java => RendererData.java} (68%) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java index c79e81924..321b8876e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.customrenderers.client; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import com.google.web.bindery.event.shared.HandlerRegistration; import com.vaadin.client.connectors.ClickableRendererConnector; @@ -17,9 +17,12 @@ import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; import com.vaadin.shared.ui.Connect; import elemental.json.JsonObject; - +/** + * A connector for {@link CustomObjectRenderer }. + * + */ @Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer.class) -public class CustomObjectRendererConnector extends ClickableRendererConnector { +public class CustomObjectRendererConnector extends ClickableRendererConnector { private static final long serialVersionUID = 7734682321931830566L; public org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer getRenderer() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java index 262648178..13d5887ca 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java @@ -18,7 +18,7 @@ import com.vaadin.client.widget.grid.RendererCellReference; * Used to display button with link. * */ -public class CustomObjectRenederer extends ClickableRenderer { +public class CustomObjectRenederer extends ClickableRenderer { @Override public VButton createWidget() { @@ -29,7 +29,7 @@ public class CustomObjectRenederer extends ClickableRenderer { +public class CustomObjectRenderer extends ClickableRenderer { private static final long serialVersionUID = -8754180585906263554L; @@ -29,7 +29,7 @@ public class CustomObjectRenderer extends ClickableRenderer { * Creates a new custom object renderer. */ public CustomObjectRenderer() { - super(CustomObject.class, null); + super(RendererData.class, null); } /** @@ -39,7 +39,7 @@ public class CustomObjectRenderer extends ClickableRenderer { * Class */ - public CustomObjectRenderer(Class presentationType) { + public CustomObjectRenderer(Class presentationType) { super(presentationType); } @@ -55,7 +55,7 @@ public class CustomObjectRenderer extends ClickableRenderer { } @Override - public JsonValue encode(CustomObject resource) { - return super.encode(resource, CustomObject.class); + public JsonValue encode(RendererData resource) { + return super.encode(resource, RendererData.class); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 6649d7dcb..c3e3d3896 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import com.vaadin.server.FontAwesome; @@ -33,14 +33,16 @@ public class ProxyRollout extends Rollout { private String totalTargetsCount; - private CustomObject customObject; + private RendererData rendererData; - public CustomObject getCustomObject() { - return customObject; + + + public RendererData getRendererData() { + return rendererData; } - public void setCustomObject(CustomObject customObject) { - this.customObject = customObject; + public void setRendererData(RendererData rendererData) { + this.rendererData = rendererData; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 114d2e432..9d915c80a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -40,164 +40,165 @@ import com.google.common.base.Strings; */ public class RolloutBeanQuery extends AbstractBeanQuery { - private static final long serialVersionUID = 4027879794344836185L; + private static final long serialVersionUID = 4027879794344836185L; - private final String searchText; + private final String searchText; - private Sort sort = new Sort(Direction.ASC, "createdAt"); + private Sort sort = new Sort(Direction.ASC, "createdAt"); - private transient RolloutManagement rolloutManagement; + private transient RolloutManagement rolloutManagement; - private transient TargetFilterQueryManagement filterQueryManagement; + private transient TargetFilterQueryManagement filterQueryManagement; - private transient RolloutUIState rolloutUIState; + private transient RolloutUIState rolloutUIState; - /** - * Parametric Constructor. - * - * @param definition - * as QueryDefinition - * @param queryConfig - * as Config - * @param sortIds - * as sort - * @param sortStates - * as Sort status - */ - public RolloutBeanQuery(final QueryDefinition definition, final Map queryConfig, - final Object[] sortIds, final boolean[] sortStates) { - super(definition, queryConfig, sortIds, sortStates); + /** + * Parametric Constructor. + * + * @param definition + * as QueryDefinition + * @param queryConfig + * as Config + * @param sortIds + * as sort + * @param sortStates + * as Sort status + */ + public RolloutBeanQuery(final QueryDefinition definition, final Map queryConfig, + final Object[] sortIds, final boolean[] sortStates) { + super(definition, queryConfig, sortIds, sortStates); - searchText = getSearchText(); + searchText = getSearchText(); - if (HawkbitCommonUtil.checkBolArray(sortStates)) { - // Initalize Sor - sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]); - // Add sort. - for (int targetId = 1; targetId < sortIds.length; targetId++) { - sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId])); - } - } - } + if (HawkbitCommonUtil.checkBolArray(sortStates)) { + // Initalize Sor + sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]); + // Add sort. + for (int targetId = 1; targetId < sortIds.length; targetId++) { + sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId])); + } + } + } - private String getSearchText() { - if (getRolloutUIState().getSearchText().isPresent()) { - return String.format("%%%s%%", getRolloutUIState().getSearchText().get()); - } - return null; - } + private String getSearchText() { + if (getRolloutUIState().getSearchText().isPresent()) { + return String.format("%%%s%%", getRolloutUIState().getSearchText().get()); + } + return null; + } - @Override - protected ProxyRollout constructBean() { - return new ProxyRollout(); - } + @Override + protected ProxyRollout constructBean() { + return new ProxyRollout(); + } - /* - * (non-Javadoc) - * - * @see - * org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#loadBeans(int, - * int) - */ - @Override - protected List loadBeans(final int startIndex, final int count) { - final Slice rolloutBeans; - if (Strings.isNullOrEmpty(searchText)) { - rolloutBeans = getRolloutManagement().findAllRolloutsWithDetailedStatus( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); - } else { - rolloutBeans = getRolloutManagement().findRolloutByFilters( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), - searchText); - } - return getProxyRolloutList(rolloutBeans); - } + /* + * (non-Javadoc) + * + * @see + * org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#loadBeans(int, + * int) + */ + @Override + protected List loadBeans(final int startIndex, final int count) { + final Slice rolloutBeans; + if (Strings.isNullOrEmpty(searchText)) { + rolloutBeans = getRolloutManagement().findAllRolloutsWithDetailedStatus( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + } else { + rolloutBeans = getRolloutManagement().findRolloutByFilters( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), + searchText); + } + return getProxyRolloutList(rolloutBeans); + } - private List getProxyRolloutList(final Slice rolloutBeans) { - final List proxyRolloutList = new ArrayList<>(); - for (final Rollout rollout : rolloutBeans) { - final ProxyRollout proxyRollout = new ProxyRollout(); - proxyRollout.setName(rollout.getName()); - proxyRollout.setDescription(rollout.getDescription()); - final DistributionSet distributionSet = rollout.getDistributionSet(); - proxyRollout.setDistributionSetNameVersion(HawkbitCommonUtil.getFormattedNameVersion( - distributionSet.getName(), distributionSet.getVersion())); - proxyRollout.setDistributionSet(distributionSet); - proxyRollout.setNumberOfGroups(Long.valueOf(rollout.getRolloutGroups().size())); - proxyRollout.setCreatedDate(SPDateTimeUtil.getFormattedDate(rollout.getCreatedAt())); - proxyRollout.setModifiedDate(SPDateTimeUtil.getFormattedDate(rollout.getLastModifiedAt())); - proxyRollout.setCreatedBy(HawkbitCommonUtil.getIMUser(rollout.getCreatedBy())); - proxyRollout.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rollout.getLastModifiedBy())); - proxyRollout.setForcedTime(rollout.getForcedTime()); - proxyRollout.setId(rollout.getId()); - proxyRollout.setStatus(rollout.getStatus()); - proxyRollout.setCustomObject(new CustomObject(rollout.getName(), rollout.getStatus().toString())); - - final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); - proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); - proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - - proxyRolloutList.add(proxyRollout); - } - return proxyRolloutList; - } + private List getProxyRolloutList(final Slice rolloutBeans) { + final List proxyRolloutList = new ArrayList<>(); + for (final Rollout rollout : rolloutBeans) { + final ProxyRollout proxyRollout = new ProxyRollout(); + proxyRollout.setName(rollout.getName()); + proxyRollout.setDescription(rollout.getDescription()); + final DistributionSet distributionSet = rollout.getDistributionSet(); + proxyRollout.setDistributionSetNameVersion( + HawkbitCommonUtil.getFormattedNameVersion(distributionSet.getName(), distributionSet.getVersion())); + proxyRollout.setDistributionSet(distributionSet); + proxyRollout.setNumberOfGroups(Long.valueOf(rollout.getRolloutGroups().size())); + proxyRollout.setCreatedDate(SPDateTimeUtil.getFormattedDate(rollout.getCreatedAt())); + proxyRollout.setModifiedDate(SPDateTimeUtil.getFormattedDate(rollout.getLastModifiedAt())); + proxyRollout.setCreatedBy(HawkbitCommonUtil.getIMUser(rollout.getCreatedBy())); + proxyRollout.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rollout.getLastModifiedBy())); + proxyRollout.setForcedTime(rollout.getForcedTime()); + proxyRollout.setId(rollout.getId()); + proxyRollout.setStatus(rollout.getStatus()); + proxyRollout.setRendererData(new RendererData(rollout.getName(), rollout.getStatus().toString())); - /* - * (non-Javadoc) - * - * @see - * org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#saveBeans(java - * .util.List, java.util.List, java.util.List) - */ - @Override - protected void saveBeans(final List arg0, final List arg1, final List arg2) { - /** - * CRUD operations on Target will be done through repository methods - */ - } + final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); + proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); + proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - /* - * (non-Javadoc) - * - * @see org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#size() - */ - @Override - public int size() { - int size = getRolloutManagement().countRolloutsAll().intValue(); - if (!Strings.isNullOrEmpty(searchText)) { - size = getRolloutManagement().countRolloutsAllByFilters(searchText).intValue(); - } - return size; - } + proxyRolloutList.add(proxyRollout); + } + return proxyRolloutList; + } - /** - * @return the rolloutManagement - */ - public RolloutManagement getRolloutManagement() { - if (null == rolloutManagement) { - rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class); - } - return rolloutManagement; - } + /* + * (non-Javadoc) + * + * @see + * org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#saveBeans(java + * .util.List, java.util.List, java.util.List) + */ + @Override + protected void saveBeans(final List arg0, final List arg1, + final List arg2) { + /** + * CRUD operations on Target will be done through repository methods + */ + } - /** - * @return the filterQueryManagement - */ - public TargetFilterQueryManagement getFilterQueryManagement() { - if (null == filterQueryManagement) { - filterQueryManagement = SpringContextHelper.getBean(TargetFilterQueryManagement.class); - } - return filterQueryManagement; - } + /* + * (non-Javadoc) + * + * @see org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#size() + */ + @Override + public int size() { + int size = getRolloutManagement().countRolloutsAll().intValue(); + if (!Strings.isNullOrEmpty(searchText)) { + size = getRolloutManagement().countRolloutsAllByFilters(searchText).intValue(); + } + return size; + } - /** - * @return the rolloutUIState - */ - public RolloutUIState getRolloutUIState() { - if (null == rolloutUIState) { - rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class); - } - return rolloutUIState; - } + /** + * @return the rolloutManagement + */ + public RolloutManagement getRolloutManagement() { + if (null == rolloutManagement) { + rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class); + } + return rolloutManagement; + } + + /** + * @return the filterQueryManagement + */ + public TargetFilterQueryManagement getFilterQueryManagement() { + if (null == filterQueryManagement) { + filterQueryManagement = SpringContextHelper.getBean(TargetFilterQueryManagement.class); + } + return filterQueryManagement; + } + + /** + * @return the rolloutUIState + */ + public RolloutUIState getRolloutUIState() { + if (null == rolloutUIState) { + rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class); + } + return rolloutUIState; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 65f94aee6..b6e828d6c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -22,7 +22,7 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; @@ -145,7 +145,7 @@ public class RolloutListGrid extends AbstractGrid { .setValue(Long.valueOf(rollout.getRolloutGroups().size())); } item.getItemProperty(customObject) - .setValue(new CustomObject(rollout.getName(), rollout.getStatus().toString())); + .setValue(new RendererData(rollout.getName(), rollout.getStatus().toString())); } @@ -160,7 +160,7 @@ public class RolloutListGrid extends AbstractGrid { protected void addContainerProperties() { final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(customObject, CustomObject.class, null, false, false); + rolloutGridContainer.addContainerProperty(customObject, RendererData.class, null, false, false); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, false); @@ -287,7 +287,7 @@ public class RolloutListGrid extends AbstractGrid { getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - CustomObjectRenderer customObjectRenderer = new CustomObjectRenderer(CustomObject.class); + CustomObjectRenderer customObjectRenderer = new CustomObjectRenderer(RendererData.class); customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); getColumn(customObject).setRenderer(customObjectRenderer); @@ -452,7 +452,7 @@ public class RolloutListGrid extends AbstractGrid { } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { return SPUILabelDefinitions.ACTION.toLowerCase(); } else if (customObject.equals(cell.getPropertyId())) { - return ((CustomObject) cell.getProperty().getValue()).getName(); + return ((RendererData) cell.getProperty().getValue()).getName(); } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index 71fe2aa8e..418ec5e40 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -9,10 +9,10 @@ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; /** - * Proxy rollout group with custom properties. + * Proxy rollout group with renderer properties. * */ public class ProxyRolloutGroup extends RolloutGroup { @@ -41,14 +41,14 @@ public class ProxyRolloutGroup extends RolloutGroup { private String totalTargetsCount; - private CustomObject customObject; + private RendererData rendererData; - public CustomObject getCustomObject() { - return customObject; + public RendererData getRendererData() { + return rendererData; } - public void setCustomObject(CustomObject customObject) { - this.customObject = customObject; + public void setRendererData(RendererData rendererData) { + this.rendererData = rendererData; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index 1902a7d9d..b025cb4bd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -15,7 +15,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -35,160 +35,160 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition; */ public class RolloutGroupBeanQuery extends AbstractBeanQuery { - private static final long serialVersionUID = 5342450502894318589L; + private static final long serialVersionUID = 5342450502894318589L; - private Sort sort = new Sort(Direction.ASC, "createdAt"); + private Sort sort = new Sort(Direction.ASC, "createdAt"); - private transient Page firstPageRolloutGroupSets = null; + private transient Page firstPageRolloutGroupSets = null; - private transient RolloutManagement rolloutManagement; + private transient RolloutManagement rolloutManagement; - private transient RolloutGroupManagement rolloutGroupManagement; + private transient RolloutGroupManagement rolloutGroupManagement; - private transient RolloutUIState rolloutUIState; + private transient RolloutUIState rolloutUIState; - private final Long rolloutId; + private final Long rolloutId; - /** - * Parametric Constructor. - * - * @param definition - * as QueryDefinition - * @param queryConfig - * as Config - * @param sortPropertyIds - * as sort - * @param sortStates - * as Sort status - */ - public RolloutGroupBeanQuery(final QueryDefinition definition, final Map queryConfig, - final Object[] sortPropertyIds, final boolean[] sortStates) { - super(definition, queryConfig, sortPropertyIds, sortStates); + /** + * Parametric Constructor. + * + * @param definition + * as QueryDefinition + * @param queryConfig + * as Config + * @param sortPropertyIds + * as sort + * @param sortStates + * as Sort status + */ + public RolloutGroupBeanQuery(final QueryDefinition definition, final Map queryConfig, + final Object[] sortPropertyIds, final boolean[] sortStates) { + super(definition, queryConfig, sortPropertyIds, sortStates); - rolloutId = getRolloutId(); + rolloutId = getRolloutId(); - if (HawkbitCommonUtil.checkBolArray(sortStates)) { - // Initalize Sor - sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]); - // Add sort. - for (int targetId = 1; targetId < sortPropertyIds.length; targetId++) { - sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, - (String) sortPropertyIds[targetId])); - } - } - } + if (HawkbitCommonUtil.checkBolArray(sortStates)) { + // Initalize Sor + sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]); + // Add sort. + for (int targetId = 1; targetId < sortPropertyIds.length; targetId++) { + sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, + (String) sortPropertyIds[targetId])); + } + } + } - /** - * @return - */ - private Long getRolloutId() { - return getRolloutUIState().getRolloutId().isPresent() ? getRolloutUIState().getRolloutId().get() : null; - } + /** + * @return + */ + private Long getRolloutId() { + return getRolloutUIState().getRolloutId().isPresent() ? getRolloutUIState().getRolloutId().get() : null; + } - @Override - protected ProxyRolloutGroup constructBean() { - return new ProxyRolloutGroup(); - } + @Override + protected ProxyRolloutGroup constructBean() { + return new ProxyRolloutGroup(); + } - @Override - protected List loadBeans(final int startIndex, final int count) { - List proxyRolloutGroupsList = new ArrayList<>(); - if (startIndex == 0 && firstPageRolloutGroupSets != null) { - proxyRolloutGroupsList = firstPageRolloutGroupSets.getContent(); - } else if (null != rolloutId) { - proxyRolloutGroupsList = getRolloutGroupManagement() - .findAllRolloutGroupsWithDetailedStatus(rolloutId, new PageRequest(startIndex / count, count)) - .getContent(); - } - return getProxyRolloutGroupList(proxyRolloutGroupsList); - } + @Override + protected List loadBeans(final int startIndex, final int count) { + List proxyRolloutGroupsList = new ArrayList<>(); + if (startIndex == 0 && firstPageRolloutGroupSets != null) { + proxyRolloutGroupsList = firstPageRolloutGroupSets.getContent(); + } else if (null != rolloutId) { + proxyRolloutGroupsList = getRolloutGroupManagement() + .findAllRolloutGroupsWithDetailedStatus(rolloutId, new PageRequest(startIndex / count, count)) + .getContent(); + } + return getProxyRolloutGroupList(proxyRolloutGroupsList); + } - private List getProxyRolloutGroupList(final List rolloutGroupBeans) { - final List proxyRolloutGroupsList = new ArrayList<>(); - for (final RolloutGroup rolloutGroup : rolloutGroupBeans) { - final ProxyRolloutGroup proxyRolloutGroup = new ProxyRolloutGroup(); - proxyRolloutGroup.setName(rolloutGroup.getName()); - proxyRolloutGroup.setDescription(rolloutGroup.getDescription()); - proxyRolloutGroup.setCreatedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getCreatedAt())); - proxyRolloutGroup.setModifiedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getLastModifiedAt())); - proxyRolloutGroup.setCreatedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getCreatedBy())); - proxyRolloutGroup.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getLastModifiedBy())); - proxyRolloutGroup.setId(rolloutGroup.getId()); - proxyRolloutGroup.setStatus(rolloutGroup.getStatus()); - proxyRolloutGroup.setErrorAction(rolloutGroup.getErrorAction()); - proxyRolloutGroup.setErrorActionExp(rolloutGroup.getErrorActionExp()); - proxyRolloutGroup.setErrorCondition(rolloutGroup.getErrorCondition()); - proxyRolloutGroup.setErrorConditionExp(rolloutGroup.getErrorConditionExp()); - proxyRolloutGroup.setSuccessCondition(rolloutGroup.getSuccessCondition()); - proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); - proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - - proxyRolloutGroup.setCustomObject(new CustomObject(rolloutGroup.getName(), null)); + private List getProxyRolloutGroupList(final List rolloutGroupBeans) { + final List proxyRolloutGroupsList = new ArrayList<>(); + for (final RolloutGroup rolloutGroup : rolloutGroupBeans) { + final ProxyRolloutGroup proxyRolloutGroup = new ProxyRolloutGroup(); + proxyRolloutGroup.setName(rolloutGroup.getName()); + proxyRolloutGroup.setDescription(rolloutGroup.getDescription()); + proxyRolloutGroup.setCreatedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getCreatedAt())); + proxyRolloutGroup.setModifiedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getLastModifiedAt())); + proxyRolloutGroup.setCreatedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getCreatedBy())); + proxyRolloutGroup.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getLastModifiedBy())); + proxyRolloutGroup.setId(rolloutGroup.getId()); + proxyRolloutGroup.setStatus(rolloutGroup.getStatus()); + proxyRolloutGroup.setErrorAction(rolloutGroup.getErrorAction()); + proxyRolloutGroup.setErrorActionExp(rolloutGroup.getErrorActionExp()); + proxyRolloutGroup.setErrorCondition(rolloutGroup.getErrorCondition()); + proxyRolloutGroup.setErrorConditionExp(rolloutGroup.getErrorConditionExp()); + proxyRolloutGroup.setSuccessCondition(rolloutGroup.getSuccessCondition()); + proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); + proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); - proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); + proxyRolloutGroup.setRendererData(new RendererData(rolloutGroup.getName(), null)); - proxyRolloutGroupsList.add(proxyRolloutGroup); - } - return proxyRolloutGroupsList; - } + proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); + proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); - private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { - return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, getRolloutManagement() - .getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); - } + proxyRolloutGroupsList.add(proxyRolloutGroup); + } + return proxyRolloutGroupsList; + } - @Override - protected void saveBeans(final List arg0, final List arg1, - final List arg2) { - /** - * CRUD operations be done through repository methods. - */ - } + private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { + return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, getRolloutManagement() + .getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); + } - @Override - public int size() { - long size = 0; - if (null != rolloutId) { - firstPageRolloutGroupSets = getRolloutGroupManagement().findAllRolloutGroupsWithDetailedStatus(rolloutId, - new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); - size = firstPageRolloutGroupSets.getTotalElements(); - } - if (size > Integer.MAX_VALUE) { - return Integer.MAX_VALUE; - } + @Override + protected void saveBeans(final List arg0, final List arg1, + final List arg2) { + /** + * CRUD operations be done through repository methods. + */ + } - return (int) size; - } + @Override + public int size() { + long size = 0; + if (null != rolloutId) { + firstPageRolloutGroupSets = getRolloutGroupManagement().findAllRolloutGroupsWithDetailedStatus(rolloutId, + new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); + size = firstPageRolloutGroupSets.getTotalElements(); + } + if (size > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } - /** - * @return the rolloutManagement - */ - public RolloutManagement getRolloutManagement() { - if (null == rolloutManagement) { - rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class); - } - return rolloutManagement; - } + return (int) size; + } - /** - * @return the rolloutManagement - */ - public RolloutGroupManagement getRolloutGroupManagement() { - if (null == rolloutGroupManagement) { - rolloutGroupManagement = SpringContextHelper.getBean(RolloutGroupManagement.class); - } - return rolloutGroupManagement; - } + /** + * @return the rolloutManagement + */ + public RolloutManagement getRolloutManagement() { + if (null == rolloutManagement) { + rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class); + } + return rolloutManagement; + } - /** - * @return the rolloutUIState - */ - public RolloutUIState getRolloutUIState() { - if (null == rolloutUIState) { - rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class); - } - return rolloutUIState; - } + /** + * @return the rolloutManagement + */ + public RolloutGroupManagement getRolloutGroupManagement() { + if (null == rolloutGroupManagement) { + rolloutGroupManagement = SpringContextHelper.getBean(RolloutGroupManagement.class); + } + return rolloutGroupManagement; + } + + /** + * @return the rolloutUIState + */ + public RolloutUIState getRolloutUIState() { + if (null == rolloutUIState) { + rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class); + } + return rolloutUIState; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index b8a799c41..3ccfb6d2d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; @@ -132,7 +132,7 @@ public class RolloutGroupListGrid extends AbstractGrid { final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGroupGridContainer.addContainerProperty(customObject, CustomObject.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(customObject, RendererData.class, null, false, false); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, false, false); @@ -286,7 +286,7 @@ public class RolloutGroupListGrid extends AbstractGrid { } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { return SPUILabelDefinitions.ACTION.toLowerCase(); } else if (customObject.equals(cell.getPropertyId())) { - return ((CustomObject) cell.getProperty().getValue()).getName(); + return ((RendererData) cell.getProperty().getValue()).getName(); } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); From 86e313fc291f0d153c699f3e8195233469288c4c Mon Sep 17 00:00:00 2001 From: venu1278 Date: Tue, 19 Apr 2016 14:47:31 +0530 Subject: [PATCH 48/49] Rollout management issues Signed-off-by: venu1278 --- ...nector.java => RolloutRendererConnector.java} | 10 +++++----- ...ObjectRenederer.java => RolloutRenderer.java} | 4 ++-- ...endererData.java => RolloutRendererData.java} | 6 +++--- ...mObjectRenderer.java => RolloutRenderer.java} | 16 ++++++++-------- .../hawkbit/ui/rollout/rollout/ProxyRollout.java | 9 ++++----- .../ui/rollout/rollout/RolloutBeanQuery.java | 4 ++-- .../ui/rollout/rollout/RolloutListGrid.java | 12 ++++++------ .../rollout/rolloutgroup/ProxyRolloutGroup.java | 8 ++++---- .../rolloutgroup/RolloutGroupBeanQuery.java | 4 ++-- .../rolloutgroup/RolloutGroupListGrid.java | 10 +++++----- 10 files changed, 41 insertions(+), 42 deletions(-) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/{CustomObjectRendererConnector.java => RolloutRendererConnector.java} (80%) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/{CustomObjectRenederer.java => RolloutRenderer.java} (91%) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/{RendererData.java => RolloutRendererData.java} (87%) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/{CustomObjectRenderer.java => RolloutRenderer.java} (73%) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java similarity index 80% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java index 321b8876e..2175dea29 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.customrenderers.client; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import com.google.web.bindery.event.shared.HandlerRegistration; import com.vaadin.client.connectors.ClickableRendererConnector; @@ -21,12 +21,12 @@ import elemental.json.JsonObject; * A connector for {@link CustomObjectRenderer }. * */ -@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer.class) -public class CustomObjectRendererConnector extends ClickableRendererConnector { +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer.class) +public class RolloutRendererConnector extends ClickableRendererConnector { private static final long serialVersionUID = 7734682321931830566L; - public org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer getRenderer() { - return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer) super.getRenderer(); + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRenderer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRenderer) super.getRenderer(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRenderer.java similarity index 91% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRenderer.java index 13d5887ca..da8fc2544 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRenderer.java @@ -18,7 +18,7 @@ import com.vaadin.client.widget.grid.RendererCellReference; * Used to display button with link. * */ -public class CustomObjectRenederer extends ClickableRenderer { +public class RolloutRenderer extends ClickableRenderer { @Override public VButton createWidget() { @@ -29,7 +29,7 @@ public class CustomObjectRenederer extends ClickableRenderer { +public class RolloutRenderer extends ClickableRenderer { private static final long serialVersionUID = -8754180585906263554L; /** * Creates a new custom object renderer. */ - public CustomObjectRenderer() { - super(RendererData.class, null); + public RolloutRenderer() { + super(RolloutRendererData.class, null); } /** @@ -39,7 +39,7 @@ public class CustomObjectRenderer extends ClickableRenderer { * Class */ - public CustomObjectRenderer(Class presentationType) { + public RolloutRenderer(Class presentationType) { super(presentationType); } @@ -49,13 +49,13 @@ public class CustomObjectRenderer extends ClickableRenderer { * @param listener * the click listener to register */ - public CustomObjectRenderer(RendererClickListener listener) { + public RolloutRenderer(RendererClickListener listener) { this(); addClickListener(listener); } @Override - public JsonValue encode(RendererData resource) { - return super.encode(resource, RendererData.class); + public JsonValue encode(RolloutRendererData resource) { + return super.encode(resource, RolloutRendererData.class); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index c3e3d3896..75c0f59cb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import com.vaadin.server.FontAwesome; @@ -33,15 +33,14 @@ public class ProxyRollout extends Rollout { private String totalTargetsCount; - private RendererData rendererData; + private RolloutRendererData rendererData; - - public RendererData getRendererData() { + public RolloutRendererData getRendererData() { return rendererData; } - public void setRendererData(RendererData rendererData) { + public void setRendererData(RolloutRendererData rendererData) { this.rendererData = rendererData; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 9d915c80a..aa98f6bf4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -131,7 +131,7 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setForcedTime(rollout.getForcedTime()); proxyRollout.setId(rollout.getId()); proxyRollout.setStatus(rollout.getStatus()); - proxyRollout.setRendererData(new RendererData(rollout.getName(), rollout.getStatus().toString())); + proxyRollout.setRendererData(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index b6e828d6c..4f9ba636f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -22,8 +22,8 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; -import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; +import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; @@ -145,7 +145,7 @@ public class RolloutListGrid extends AbstractGrid { .setValue(Long.valueOf(rollout.getRolloutGroups().size())); } item.getItemProperty(customObject) - .setValue(new RendererData(rollout.getName(), rollout.getStatus().toString())); + .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); } @@ -160,7 +160,7 @@ public class RolloutListGrid extends AbstractGrid { protected void addContainerProperties() { final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(customObject, RendererData.class, null, false, false); + rolloutGridContainer.addContainerProperty(customObject, RolloutRendererData.class, null, false, false); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, false); @@ -287,7 +287,7 @@ public class RolloutListGrid extends AbstractGrid { getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - CustomObjectRenderer customObjectRenderer = new CustomObjectRenderer(RendererData.class); + RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); getColumn(customObject).setRenderer(customObjectRenderer); @@ -452,7 +452,7 @@ public class RolloutListGrid extends AbstractGrid { } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { return SPUILabelDefinitions.ACTION.toLowerCase(); } else if (customObject.equals(cell.getPropertyId())) { - return ((RendererData) cell.getProperty().getValue()).getName(); + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index 418ec5e40..be1e09794 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; /** * Proxy rollout group with renderer properties. @@ -41,13 +41,13 @@ public class ProxyRolloutGroup extends RolloutGroup { private String totalTargetsCount; - private RendererData rendererData; + private RolloutRendererData rendererData; - public RendererData getRendererData() { + public RolloutRendererData getRendererData() { return rendererData; } - public void setRendererData(RendererData rendererData) { + public void setRendererData(RolloutRendererData rendererData) { this.rendererData = rendererData; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index b025cb4bd..0850164c9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -15,7 +15,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -123,7 +123,7 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - proxyRolloutGroup.setRendererData(new RendererData(rolloutGroup.getName(), null)); + proxyRolloutGroup.setRendererData(new RolloutRendererData(rolloutGroup.getName(), null)); proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index 3ccfb6d2d..da0a8271a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -23,8 +23,8 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; -import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; +import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; @@ -132,7 +132,7 @@ public class RolloutGroupListGrid extends AbstractGrid { final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGroupGridContainer.addContainerProperty(customObject, RendererData.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(customObject, RolloutRendererData.class, null, false, false); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, false, false); @@ -238,7 +238,7 @@ public class RolloutGroupListGrid extends AbstractGrid { getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), new TotalTargetCountStatusConverter()); if (permissionChecker.hasRolloutTargetsReadPermission()) { - getColumn(customObject).setRenderer(new CustomObjectRenderer(event -> onClickOfRolloutGroupName(event))); + getColumn(customObject).setRenderer(new RolloutRenderer(event -> onClickOfRolloutGroupName(event))); } } @@ -286,7 +286,7 @@ public class RolloutGroupListGrid extends AbstractGrid { } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { return SPUILabelDefinitions.ACTION.toLowerCase(); } else if (customObject.equals(cell.getPropertyId())) { - return ((RendererData) cell.getProperty().getValue()).getName(); + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); From d561ad99de28917a053b0ef2bd957a12d49407e0 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 21 Apr 2016 08:06:10 +0200 Subject: [PATCH 49/49] fix rollout renderer, using wrong itemd ID property naming Signed-off-by: Michael Hirsch --- .../ui/rollout/rollout/ProxyRollout.java | 10 +- .../ui/rollout/rollout/RolloutBeanQuery.java | 2 +- .../ui/rollout/rollout/RolloutListGrid.java | 1116 ++++++++--------- .../rolloutgroup/ProxyRolloutGroup.java | 10 +- .../rolloutgroup/RolloutGroupBeanQuery.java | 2 +- .../rolloutgroup/RolloutGroupListGrid.java | 553 ++++---- 6 files changed, 847 insertions(+), 846 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 75c0f59cb..6514ba2df 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -33,15 +33,15 @@ public class ProxyRollout extends Rollout { private String totalTargetsCount; - private RolloutRendererData rendererData; + private RolloutRendererData rolloutRendererData; - public RolloutRendererData getRendererData() { - return rendererData; + public RolloutRendererData getRolloutRendererData() { + return rolloutRendererData; } - public void setRendererData(RolloutRendererData rendererData) { - this.rendererData = rendererData; + public void setRolloutRendererData(RolloutRendererData rendererData) { + this.rolloutRendererData = rendererData; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index aa98f6bf4..34ae323da 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -131,7 +131,7 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setForcedTime(rollout.getForcedTime()); proxyRollout.setId(rollout.getId()); proxyRollout.setStatus(rollout.getStatus()); - proxyRollout.setRendererData(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); + proxyRollout.setRolloutRendererData(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 4f9ba636f..1bb0fd831 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -23,9 +23,9 @@ import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; -import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; +import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -68,562 +68,562 @@ import com.vaadin.ui.renderers.HtmlRenderer; @ViewScope public class RolloutListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; - - private static final String UPDATE_OPTION = "Update"; - - private static final String RESUME_OPTION = "Resume"; - - private static final String PAUSE_OPTION = "Pause"; - - private static final String START_OPTION = "Start"; - - private static final String customObject = "customObject"; - - @Autowired - private transient RolloutManagement rolloutManagement; - - @Autowired - private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; - - @Autowired - private UINotification uiNotification; - - @Autowired - private transient RolloutUIState rolloutUIState; - - @Autowired - private transient SpPermissionChecker permissionChecker; - - private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); - - /** - * Handles the RolloutEvent to refresh Grid. - * - */ - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - switch (event) { - case FILTER_BY_TEXT: - case CREATE_ROLLOUT: - case UPDATE_ROLLOUT: - case SHOW_ROLLOUTS: - refreshGrid(); - break; - default: - return; - } - } - - /** - * Handles the RolloutChangeEvent to refresh the item in the grid. - * - * @param rolloutChangeEvent - * the event which contains the rollout which has been changed - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { - if (!rolloutUIState.isShowRollOuts()) { - return; - } - final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); - final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); - final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); - final int groupsCreated = rollout.getRolloutGroupsCreated(); - if (groupsCreated != 0) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); - } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) - .setValue(Long.valueOf(rollout.getRolloutGroups().size())); - } - item.getItemProperty(customObject) - .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); - - } - - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } - - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(customObject, RolloutRendererData.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, - FontAwesome.CIRCLE_O.getHtml(), false, false); - - } - - @Override - protected void setColumnExpandRatio() { - - getColumn(customObject).setMinimumWidth(40); - getColumn(customObject).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - - setFrozenColumnCount(getColumns().size()); - } - - @Override - protected void setColumnHeaderNames() { - getColumn(customObject).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); - } - - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; - } - - @Override - protected void setColumnProperties() { - final List columnList = new ArrayList<>(); - columnList.add(customObject); - columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ACTION); - - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } - - @Override - protected void setHiddenColumns() { - final List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (final Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - - } - - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } - - @Override - protected void addColumnRenderes() { - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), - new TotalTargetGroupsConverter()); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - - createRolloutStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); - - getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - - RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); - customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); - getColumn(customObject).setRenderer(customObjectRenderer); - - } - - private void createRolloutStatusToFontMap() { - statusIconMap.put(RolloutStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutStatus.PAUSED, - new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); - statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); - statusIconMap.put(RolloutStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutStatus.STOPPED, - new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); - statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); - statusIconMap.put(RolloutStatus.ERROR_CREATING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.ERROR_STARTING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } - - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; - - @Override - public String getStyle(final CellReference cellReference) { - final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } - - private void onClickOfRolloutName(final RendererClickEvent event) { - rolloutUIState.setRolloutId((long) event.getItemId()); - final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - rolloutUIState.setRolloutName(rolloutName); - final String ds = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); - rolloutUIState.setRolloutDistributionSet(ds); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); - } - - private void onClickOfActionBtn(final RendererClickEvent event) { - final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); - contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); - contextMenu.open(event.getClientX(), event.getClientY()); - } - - private ContextMenu createContextMenu(final Long rolloutId) { - final ContextMenu context = new ContextMenu(); - context.addItemClickListener(event -> menuItemClicked(event)); - final Item row = getContainerDataSource().getItem(rolloutId); - final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - - switch (rolloutStatus) { - case READY: - final ContextMenuItem startItem = context.addItem(START_OPTION); - startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); - break; - case RUNNING: - final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); - pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); - break; - case PAUSED: - final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); - resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); - break; - case STARTING: - case CREATING: - case ERROR_CREATING: - case ERROR_STARTING: - // do not provide any action on these statuses - return context; - default: - break; - } - getUpdateMenuItem(context, rolloutId); - return context; - } - - private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { - // Add 'Update' option only if user has update permission - if (!permissionChecker.hasRolloutUpdatePermission()) { - return; - } - final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); - cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); - } - - private void menuItemClicked(final ContextMenuItemClickEvent event) { - final ContextMenuItem item = (ContextMenuItem) event.getSource(); - final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); - final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - switch (contextMenuData.getAction()) { - case PAUSE: - rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); - break; - case RESUME: - rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); - break; - case START: - rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); - uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); - break; - case UPDATE: - onUpdate(contextMenuData); - break; - default: - break; - } - } - - private void onUpdate(final ContextMenuData contextMenuData) { - addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); - final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); - addTargetWindow.setCaption(i18n.get("caption.update.rollout")); - UI.getCurrent().addWindow(addTargetWindow); - addTargetWindow.setVisible(Boolean.TRUE); - } - - private void refreshGrid() { - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } - - /** - * Generator to generate fontIcon by String. - */ - public final class FontIconGenerator extends PropertyValueGenerator { - - private static final long serialVersionUID = 2544026030795375748L; - private final FontAwesome fontIcon; - - public FontIconGenerator(final FontAwesome icon) { - this.fontIcon = icon; - } - - @Override - public String getValue(final Item item, final Object itemId, final Object propertyId) { - return fontIcon.getHtml(); - } - - @Override - public Class getType() { - return String.class; - } - } - - private String getDescription(final CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (customObject.equals(cell.getPropertyId())) { - return ((RolloutRendererData) cell.getProperty().getValue()).getName(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } - - enum ACTION { - PAUSE, RESUME, START, UPDATE - } - - /** - * Represents data of context menu item. - * - */ - public static class ContextMenuData { - - private Long rolloutId; - - private ACTION action; - - /** - * Set rollout if and action. - * - * @param rolloutId - * id of rollout - * @param action - * user action {@link ACTION} - */ - public ContextMenuData(final Long rolloutId, final ACTION action) { - this.action = action; - this.rolloutId = rolloutId; - } - - /** - * @return the rolloutId - */ - public Long getRolloutId() { - return rolloutId; - } - - /** - * @param rolloutId - * the rolloutId to set - */ - public void setRolloutId(final Long rolloutId) { - this.rolloutId = rolloutId; - } - - /** - * @return the action - */ - public ACTION getAction() { - return action; - } - - /** - * @param action - * the action to set - */ - public void setAction(final ACTION action) { - this.action = action; - } - } - - /** - * - * Converter to convert {@link RolloutStatus} to string. - * - */ - class RolloutStatusConverter implements Converter { - - private static final long serialVersionUID = -1217685750825632678L; - - @Override - public RolloutStatus convertToModel(final String value, final Class targetType, - final Locale locale) { - return null; - } - - @Override - public String convertToPresentation(final RolloutStatus value, final Class targetType, - final Locale locale) { - return convertRolloutStatusToString(value); - } - - @Override - public Class getModelType() { - return RolloutStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - private String convertRolloutStatusToString(final RolloutStatus value) { - final StatusFontIcon statusFontIcon = statusIconMap.get(value); - final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); - } - } - - /** - * Converter to convert {@link TotalTargetCountStatus} to formatted string - * with status and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { - - private static final long serialVersionUID = -5794528427855153924L; - - @Override - public TotalTargetCountStatus convertToModel(final String value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(final TotalTargetCountStatus value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } - - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } - - /** - * Converter to convert 0 to empty, if total target groups is zero. - * - */ - class TotalTargetGroupsConverter implements Converter { - - private static final long serialVersionUID = 6589305227035220369L; - - @Override - public Long convertToModel(String value, Class targetType, Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(Long value, Class targetType, Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - if (value == 0) { - return ""; - } - return value.toString(); - } - - @Override - public Class getModelType() { - return Long.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - } + private static final long serialVersionUID = 4060904914954370524L; + + private static final String UPDATE_OPTION = "Update"; + + private static final String RESUME_OPTION = "Resume"; + + private static final String PAUSE_OPTION = "Pause"; + + private static final String START_OPTION = "Start"; + + private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; + + @Autowired + private transient RolloutManagement rolloutManagement; + + @Autowired + private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; + + @Autowired + private UINotification uiNotification; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); + + /** + * Handles the RolloutEvent to refresh Grid. + * + */ + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + switch (event) { + case FILTER_BY_TEXT: + case CREATE_ROLLOUT: + case UPDATE_ROLLOUT: + case SHOW_ROLLOUTS: + refreshGrid(); + break; + default: + return; + } + } + + /** + * Handles the RolloutChangeEvent to refresh the item in the grid. + * + * @param rolloutChangeEvent + * the event which contains the rollout which has been changed + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { + if (!rolloutUIState.isShowRollOuts()) { + return; + } + final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); + final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); + final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); + final int groupsCreated = rollout.getRolloutGroupsCreated(); + if (groupsCreated != 0) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); + } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + } + item.getItemProperty(ROLLOUT_RENDERER_DATA) + .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); + + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGridContainer.addContainerProperty(ROLLOUT_RENDERER_DATA, RolloutRendererData.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, + FontAwesome.CIRCLE_O.getHtml(), false, false); + + } + + @Override + protected void setColumnExpandRatio() { + + getColumn(ROLLOUT_RENDERER_DATA).setMinimumWidth(40); + getColumn(ROLLOUT_RENDERER_DATA).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + + setFrozenColumnCount(getColumns().size()); + } + + @Override + protected void setColumnHeaderNames() { + getColumn(ROLLOUT_RENDERER_DATA).setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); + } + + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; + } + + @Override + protected void setColumnProperties() { + final List columnList = new ArrayList<>(); + columnList.add(ROLLOUT_RENDERER_DATA); + columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ACTION); + + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + @Override + protected void setHiddenColumns() { + final List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (final Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } + + @Override + protected void addColumnRenderes() { + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), + new TotalTargetGroupsConverter()); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + + createRolloutStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); + + getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); + + final RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); + customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); + getColumn(ROLLOUT_RENDERER_DATA).setRenderer(customObjectRenderer); + + } + + private void createRolloutStatusToFontMap() { + statusIconMap.put(RolloutStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutStatus.PAUSED, + new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); + statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); + statusIconMap.put(RolloutStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutStatus.STOPPED, + new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); + statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); + statusIconMap.put(RolloutStatus.ERROR_CREATING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.ERROR_STARTING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + private void onClickOfRolloutName(final RendererClickEvent event) { + rolloutUIState.setRolloutId((long) event.getItemId()); + final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + rolloutUIState.setRolloutName(rolloutName); + final String ds = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); + rolloutUIState.setRolloutDistributionSet(ds); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); + } + + private void onClickOfActionBtn(final RendererClickEvent event) { + final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); + contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); + contextMenu.open(event.getClientX(), event.getClientY()); + } + + private ContextMenu createContextMenu(final Long rolloutId) { + final ContextMenu context = new ContextMenu(); + context.addItemClickListener(event -> menuItemClicked(event)); + final Item row = getContainerDataSource().getItem(rolloutId); + final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) + .getValue(); + + switch (rolloutStatus) { + case READY: + final ContextMenuItem startItem = context.addItem(START_OPTION); + startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); + break; + case RUNNING: + final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); + pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); + break; + case PAUSED: + final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); + resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); + break; + case STARTING: + case CREATING: + case ERROR_CREATING: + case ERROR_STARTING: + // do not provide any action on these statuses + return context; + default: + break; + } + getUpdateMenuItem(context, rolloutId); + return context; + } + + private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { + // Add 'Update' option only if user has update permission + if (!permissionChecker.hasRolloutUpdatePermission()) { + return; + } + final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); + cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); + } + + private void menuItemClicked(final ContextMenuItemClickEvent event) { + final ContextMenuItem item = (ContextMenuItem) event.getSource(); + final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); + final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); + final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + switch (contextMenuData.getAction()) { + case PAUSE: + rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); + break; + case RESUME: + rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); + break; + case START: + rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); + uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); + break; + case UPDATE: + onUpdate(contextMenuData); + break; + default: + break; + } + } + + private void onUpdate(final ContextMenuData contextMenuData) { + addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); + final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); + addTargetWindow.setCaption(i18n.get("caption.update.rollout")); + UI.getCurrent().addWindow(addTargetWindow); + addTargetWindow.setVisible(Boolean.TRUE); + } + + private void refreshGrid() { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + + /** + * Generator to generate fontIcon by String. + */ + public final class FontIconGenerator extends PropertyValueGenerator { + + private static final long serialVersionUID = 2544026030795375748L; + private final FontAwesome fontIcon; + + public FontIconGenerator(final FontAwesome icon) { + this.fontIcon = icon; + } + + @Override + public String getValue(final Item item, final Object itemId, final Object propertyId) { + return fontIcon.getHtml(); + } + + @Override + public Class getType() { + return String.class; + } + } + + private String getDescription(final CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if (ROLLOUT_RENDERER_DATA.equals(cell.getPropertyId())) { + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } + return null; + } + + enum ACTION { + PAUSE, RESUME, START, UPDATE + } + + /** + * Represents data of context menu item. + * + */ + public static class ContextMenuData { + + private Long rolloutId; + + private ACTION action; + + /** + * Set rollout if and action. + * + * @param rolloutId + * id of rollout + * @param action + * user action {@link ACTION} + */ + public ContextMenuData(final Long rolloutId, final ACTION action) { + this.action = action; + this.rolloutId = rolloutId; + } + + /** + * @return the rolloutId + */ + public Long getRolloutId() { + return rolloutId; + } + + /** + * @param rolloutId + * the rolloutId to set + */ + public void setRolloutId(final Long rolloutId) { + this.rolloutId = rolloutId; + } + + /** + * @return the action + */ + public ACTION getAction() { + return action; + } + + /** + * @param action + * the action to set + */ + public void setAction(final ACTION action) { + this.action = action; + } + } + + /** + * + * Converter to convert {@link RolloutStatus} to string. + * + */ + class RolloutStatusConverter implements Converter { + + private static final long serialVersionUID = -1217685750825632678L; + + @Override + public RolloutStatus convertToModel(final String value, final Class targetType, + final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutStatus value, final Class targetType, + final Locale locale) { + return convertRolloutStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + private String convertRolloutStatusToString(final RolloutStatus value) { + final StatusFontIcon statusFontIcon = statusIconMap.get(value); + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + } + } + + /** + * Converter to convert {@link TotalTargetCountStatus} to formatted string + * with status and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { + + private static final long serialVersionUID = -5794528427855153924L; + + @Override + public TotalTargetCountStatus convertToModel(final String value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(final TotalTargetCountStatus value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } + + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + } + + /** + * Converter to convert 0 to empty, if total target groups is zero. + * + */ + class TotalTargetGroupsConverter implements Converter { + + private static final long serialVersionUID = 6589305227035220369L; + + @Override + public Long convertToModel(final String value, final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(final Long value, final Class targetType, + final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + if (value == 0) { + return ""; + } + return value.toString(); + } + + @Override + public Class getModelType() { + return Long.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index be1e09794..08f2c0a0b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -41,14 +41,14 @@ public class ProxyRolloutGroup extends RolloutGroup { private String totalTargetsCount; - private RolloutRendererData rendererData; + private RolloutRendererData rolloutRendererData; - public RolloutRendererData getRendererData() { - return rendererData; + public RolloutRendererData getRolloutRendererData() { + return rolloutRendererData; } - public void setRendererData(RolloutRendererData rendererData) { - this.rendererData = rendererData; + public void setRolloutRendererData(RolloutRendererData rendererData) { + this.rolloutRendererData = rendererData; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index 0850164c9..efc350dc4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -123,7 +123,7 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - proxyRolloutGroup.setRendererData(new RolloutRendererData(rolloutGroup.getName(), null)); + proxyRolloutGroup.setRolloutRendererData(new RolloutRendererData(rolloutGroup.getName(), null)); proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index da0a8271a..f09b02cfc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -24,9 +24,8 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; -import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; - +import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -60,329 +59,331 @@ import com.vaadin.ui.renderers.HtmlRenderer; @SpringComponent @ViewScope public class RolloutGroupListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; + private static final long serialVersionUID = 4060904914954370524L; - private static final String customObject = "customObject"; + private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; - @Autowired - private transient RolloutGroupManagement rolloutGroupManagement; + @Autowired + private transient RolloutGroupManagement rolloutGroupManagement; - @Autowired - private transient RolloutManagement rolloutManagement; + @Autowired + private transient RolloutManagement rolloutManagement; - @Autowired - private transient RolloutUIState rolloutUIState; + @Autowired + private transient RolloutUIState rolloutUIState; - @Autowired - private transient SpPermissionChecker permissionChecker; + @Autowired + private transient SpPermissionChecker permissionChecker; - private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); + private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { - return; - } - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { + return; + } + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } - /** - * - * Handles the RolloutGroupChangeEvent to refresh the item in the grid. - * - * - * @param rolloutGroupChangeEvent - * the event which contains the rollout group which has been - * change - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { - if (!rolloutUIState.isShowRolloutGroups()) { - return; - } - final RolloutGroup rolloutGroup = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutGroup.getId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setValue(rolloutGroup.getTotalTargetCountStatus()); - item.getItemProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) - .setValue(calculateFinishedPercentage(rolloutGroup)); - } + /** + * + * Handles the RolloutGroupChangeEvent to refresh the item in the grid. + * + * + * @param rolloutGroupChangeEvent + * the event which contains the rollout group which has been + * change + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { + if (!rolloutUIState.isShowRolloutGroups()) { + return; + } + final RolloutGroup rolloutGroup = rolloutGroupManagement + .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutGroup.getId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setValue(rolloutGroup.getTotalTargetCountStatus()); + item.getItemProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setValue(calculateFinishedPercentage(rolloutGroup)); + } - private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { - return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, - rolloutManagement.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); - } + private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { + return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, + rolloutManagement.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); + } - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGroupGridContainer.addContainerProperty(customObject, RolloutRendererData.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, - false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, - String.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, - null, false, false); + rolloutGroupGridContainer.addContainerProperty(ROLLOUT_RENDERER_DATA, RolloutRendererData.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, + String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, + null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, - false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, + false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, - false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); - } + } - @Override - protected void setColumnExpandRatio() { - getColumn(customObject).setMinimumWidth(40); - getColumn(customObject).setMaximumWidth(200); + @Override + protected void setColumnExpandRatio() { + getColumn(ROLLOUT_RENDERER_DATA).setMinimumWidth(40); + getColumn(ROLLOUT_RENDERER_DATA).setMaximumWidth(200); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - setFrozenColumnCount(7); - } + setFrozenColumnCount(7); + } - @Override - protected void setColumnHeaderNames() { - getColumn(customObject).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) - .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) - .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) - .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - } + @Override + protected void setColumnHeaderNames() { + getColumn(ROLLOUT_RENDERER_DATA).setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + } - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; - } + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; + } - @Override - protected void setColumnProperties() { - final List columnList = new ArrayList<>(); - columnList.add(customObject); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } + @Override + protected void setColumnProperties() { + final List columnList = new ArrayList<>(); + columnList.add(ROLLOUT_RENDERER_DATA); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } - @Override - protected void addColumnRenderes() { - createRolloutGroupStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), - new RolloutGroupStatusConverter()); + @Override + protected void addColumnRenderes() { + createRolloutGroupStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), + new RolloutGroupStatusConverter()); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - if (permissionChecker.hasRolloutTargetsReadPermission()) { - getColumn(customObject).setRenderer(new RolloutRenderer(event -> onClickOfRolloutGroupName(event))); - } - } + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + if (permissionChecker.hasRolloutTargetsReadPermission()) { + getColumn(ROLLOUT_RENDERER_DATA) + .setRenderer(new RolloutRenderer(event -> onClickOfRolloutGroupName(event))); + } + } - @Override - protected void setHiddenColumns() { - final List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (final Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - } + @Override + protected void setHiddenColumns() { + final List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (final Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + } - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } - private void onClickOfRolloutGroupName(final RendererClickEvent event) { - rolloutUIState - .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); - } + private void onClickOfRolloutGroupName(final RendererClickEvent event) { + rolloutUIState + .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); + } - private void createRolloutGroupStatusToFontMap() { - statusIconMap.put(RolloutGroupStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutGroupStatus.SCHEDULED, - new StatusFontIcon(FontAwesome.HOURGLASS_1, SPUIStyleDefinitions.STATUS_ICON_PENDING)); - statusIconMap.put(RolloutGroupStatus.RUNNING, - new StatusFontIcon(FontAwesome.ADJUST, SPUIStyleDefinitions.STATUS_ICON_YELLOW)); - statusIconMap.put(RolloutGroupStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutGroupStatus.ERROR, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } + private void createRolloutGroupStatusToFontMap() { + statusIconMap.put(RolloutGroupStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutGroupStatus.SCHEDULED, + new StatusFontIcon(FontAwesome.HOURGLASS_1, SPUIStyleDefinitions.STATUS_ICON_PENDING)); + statusIconMap.put(RolloutGroupStatus.RUNNING, + new StatusFontIcon(FontAwesome.ADJUST, SPUIStyleDefinitions.STATUS_ICON_YELLOW)); + statusIconMap.put(RolloutGroupStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutGroupStatus.ERROR, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } - private String getDescription(final CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (customObject.equals(cell.getPropertyId())) { - return ((RolloutRendererData) cell.getProperty().getValue()).getName(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } + private String getDescription(final CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if (ROLLOUT_RENDERER_DATA.equals(cell.getPropertyId())) { + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } + return null; + } - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; - @Override - public String getStyle(final CellReference cellReference) { - final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, - SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } + @Override + public String getStyle(final CellReference cellReference) { + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, + SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } - /** - * - * Converts {@link TotalTargetCountStatus} into formatted string with status - * and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { + /** + * + * Converts {@link TotalTargetCountStatus} into formatted string with status + * and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { - private static final long serialVersionUID = -9205943894818450807L; + private static final long serialVersionUID = -9205943894818450807L; - @Override - public TotalTargetCountStatus convertToModel(final String value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } + @Override + public TotalTargetCountStatus convertToModel(final String value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } - @Override - public String convertToPresentation(final TotalTargetCountStatus value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } + @Override + public String convertToPresentation(final TotalTargetCountStatus value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } - @Override - public Class getPresentationType() { - return String.class; - } - } + @Override + public Class getPresentationType() { + return String.class; + } + } - /** - * - * Converts {@link RolloutGroupStatus} to string. - * - */ - class RolloutGroupStatusConverter implements Converter { + /** + * + * Converts {@link RolloutGroupStatus} to string. + * + */ + class RolloutGroupStatusConverter implements Converter { - private static final long serialVersionUID = 5448062736373292820L; + private static final long serialVersionUID = 5448062736373292820L; - @Override - public RolloutGroupStatus convertToModel(final String value, - final Class targetType, final Locale locale) { - return null; - } + @Override + public RolloutGroupStatus convertToModel(final String value, + final Class targetType, final Locale locale) { + return null; + } - @Override - public String convertToPresentation(final RolloutGroupStatus value, final Class targetType, - final Locale locale) { - return convertRolloutGroupStatusToString(value); - } + @Override + public String convertToPresentation(final RolloutGroupStatus value, final Class targetType, + final Locale locale) { + return convertRolloutGroupStatusToString(value); + } - @Override - public Class getModelType() { - return RolloutGroupStatus.class; - } + @Override + public Class getModelType() { + return RolloutGroupStatus.class; + } - @Override - public Class getPresentationType() { - return String.class; - } + @Override + public Class getPresentationType() { + return String.class; + } - private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { - final StatusFontIcon statusFontIcon = statusIconMap.get(value); - final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { + final StatusFontIcon statusFontIcon = statusIconMap.get(value); + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); - } + } - } + } }