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