diff --git a/hawkbit-ui/pom.xml b/hawkbit-ui/pom.xml index 2c7e65638..e0bde576a 100644 --- a/hawkbit-ui/pom.xml +++ b/hawkbit-ui/pom.xml @@ -58,6 +58,24 @@ + + org.apache.maven.plugins + maven-jar-plugin + + + true + + true + true + + + CustomRenderers + 1 + org.eclipse.hawkbit.ui.customrenderers.CustomRendererWidgetSet + + + + @@ -153,8 +171,11 @@ com.vaadin vaadin-server - - + + com.vaadin + vaadin-client + + com.vaadin vaadin-push diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/AppWidgetSet.gwt.xml b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/AppWidgetSet.gwt.xml index 020ce7a77..c6ee9b5b5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/AppWidgetSet.gwt.xml +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/AppWidgetSet.gwt.xml @@ -16,15 +16,29 @@ - + + + + + + + + + + + + + + + + + + - - - - - - - diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java new file mode 100644 index 000000000..7cd276258 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.common.grid; + +import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; + +import com.vaadin.data.Container; +import com.vaadin.data.Container.Indexed; +import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Label; +import com.vaadin.ui.themes.ValoTheme; + +/** + * Abstract table class. + * + */ +public abstract class AbstractGrid extends Grid { + + private static final long serialVersionUID = 4856562746502217630L; + + /** + * Initialize the components. + */ + protected void init() { + setSizeFull(); + setImmediate(true); + setId(getGridId()); + setSelectionMode(SelectionMode.NONE); + setColumnReorderingAllowed(true); + addNewContainerDS(); + } + + public void addNewContainerDS() { + final Container container = createContainer(); + setContainerDataSource((Indexed) container); + addContainerProperties(); + setColumnExpandRatio(); + setColumnProperties(); + setColumnHeaderNames(); + addColumnRenderes(); + + CellDescriptionGenerator cellDescriptionGenerator = getDescriptionGenerator(); + if (getDescriptionGenerator() != null) { + setCellDescriptionGenerator(cellDescriptionGenerator); + } + + // Allow column hiding + for (Column c : getColumns()) { + c.setHidable(true); + } + setHiddenColumns(); + int size = 0; + if (container != null) { + size = container.size(); + } + if (size == 0) { + setData(SPUIDefinitions.NO_DATA); + } + } + + protected abstract Container createContainer(); + + protected abstract void addContainerProperties(); + + protected abstract void setColumnExpandRatio(); + + protected abstract void setColumnHeaderNames(); + + protected abstract String getGridId(); + + protected abstract void setColumnProperties(); + + protected abstract void addColumnRenderes(); + + protected abstract void setHiddenColumns(); + + protected abstract CellDescriptionGenerator getDescriptionGenerator(); +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridHeader.java similarity index 98% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableHeader.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridHeader.java index 38f59b270..282e08152 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridHeader.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.common.grid; import org.eclipse.hawkbit.ui.components.SPUIButton; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -26,10 +26,10 @@ import com.vaadin.ui.VerticalLayout; /** * - * Abstract table header. + * Abstract grid header. * */ -public abstract class AbstractSimpleTableHeader extends VerticalLayout { +public abstract class AbstractGridHeader extends VerticalLayout { private static final long serialVersionUID = -24429876573255519L; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridLayout.java similarity index 77% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableLayout.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridLayout.java index 560e4040e..98c14e698 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridLayout.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.common.grid; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -17,22 +17,23 @@ import com.vaadin.ui.VerticalLayout; /** * - * Abstract table layout class which builds layout with table - * {@link AbstractSimpleTable} and table header - * {@link AbstractSimpleTableHeader}. + * Abstract grid layout class which builds layout with grid + * {@link AbstractGrid} and table header + * {@link AbstractGridHeader}. * */ -public abstract class AbstractSimpleTableLayout extends VerticalLayout { +public abstract class AbstractGridLayout extends VerticalLayout { private static final long serialVersionUID = 8611248179949245460L; - private AbstractSimpleTableHeader tableHeader; + private AbstractGridHeader tableHeader; + + private AbstractGrid grid; - private AbstractSimpleTable table; - protected void init(final AbstractSimpleTableHeader tableHeader, final AbstractSimpleTable table) { + protected void init(final AbstractGridHeader tableHeader,final AbstractGrid grid) { this.tableHeader = tableHeader; - this.table = table; + this.grid = grid; buildLayout(); } @@ -50,9 +51,9 @@ public abstract class AbstractSimpleTableLayout extends VerticalLayout { tableHeaderLayout.addComponent(tableHeader); tableHeaderLayout.setComponentAlignment(tableHeader, Alignment.TOP_CENTER); - tableHeaderLayout.addComponent(table); - tableHeaderLayout.setComponentAlignment(table, Alignment.TOP_CENTER); - tableHeaderLayout.setExpandRatio(table, 1.0f); + tableHeaderLayout.addComponent(grid); + tableHeaderLayout.setComponentAlignment(grid, Alignment.TOP_CENTER); + tableHeaderLayout.setExpandRatio(grid, 1.0f); addComponent(tableHeaderLayout); @@ -66,10 +67,6 @@ public abstract class AbstractSimpleTableLayout extends VerticalLayout { } - /** - * @return - * - */ private HorizontalLayout createCountMessageComponent() { final HorizontalLayout rolloutGroupTargetsCountLayout = new HorizontalLayout(); final Label countMessageLabel = getCountMessageLabel(); @@ -84,9 +81,14 @@ public abstract class AbstractSimpleTableLayout extends VerticalLayout { /** * Only in rollout group targets view count message is displayed. * - * @return + * @return true if count message has to be displayed */ protected abstract boolean hasCountMessage(); + /** + * Get the count message label. + * + * @return count message + */ protected abstract Label getCountMessageLabel(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/CustomRendererWidgetSet.gwt.xml b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/CustomRendererWidgetSet.gwt.xml new file mode 100644 index 000000000..b61cbbb0f --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/CustomRendererWidgetSet.gwt.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlButtonRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlButtonRendererConnector.java new file mode 100644 index 000000000..3f2b23b54 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlButtonRendererConnector.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.customrenderers.client; + +import com.vaadin.client.connectors.ButtonRendererConnector; +import com.vaadin.shared.ui.Connect; + +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer.class) +public class HtmlButtonRendererConnector extends ButtonRendererConnector { + private static final long serialVersionUID = 7987417436367399331L; + + @Override + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlButtonRenderer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlButtonRenderer) super.getRenderer(); + } +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlLabelRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlLabelRendererConnector.java new file mode 100644 index 000000000..a64cd6bea --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlLabelRendererConnector.java @@ -0,0 +1,24 @@ +/** + * 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 com.vaadin.client.connectors.AbstractRendererConnector; +import com.vaadin.shared.ui.Connect; + +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer.class) +public class HtmlLabelRendererConnector extends AbstractRendererConnector { + + private static final long serialVersionUID = 7697966991925490786L; + + @Override + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlLabelRenderer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlLabelRenderer) super.getRenderer(); + } + +} 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 new file mode 100644 index 000000000..21cf7128e --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.customrenderers.client; + +import com.vaadin.client.connectors.ButtonRendererConnector; +import com.vaadin.shared.ui.Connect; + +@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(); + } +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlButtonRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlButtonRenderer.java new file mode 100644 index 000000000..45c8f4f0d --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlButtonRenderer.java @@ -0,0 +1,40 @@ +/** + * 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; + +public class HtmlButtonRenderer extends ButtonRenderer { + @Override + public void render(RendererCellReference cell, String text, Button button) { + if (text != null) { + button.setHTML(text); + } + applystyles(button); + // this is to allow the button to disappear, if the text is null + button.setVisible(text != null); + button.getElement().setId("rollout.action.button.id"); + } + + private void applystyles(Button button) { + button.setStyleName(VButton.CLASSNAME); + button.addStyleName(getStyle("tiny")); + button.addStyleName(getStyle("borderless")); + button.addStyleName(getStyle("icon-only")); + button.addStyleName(getStyle("button-no-border")); + } + + + 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/client/renderers/HtmlLabelRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlLabelRenderer.java new file mode 100644 index 000000000..a0ceb9532 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlLabelRenderer.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import java.util.HashMap; +import java.util.Map; + +import com.google.gwt.core.client.GWT; +import com.vaadin.client.renderers.WidgetRenderer; +import com.vaadin.client.ui.VLabel; +import com.vaadin.client.widget.grid.RendererCellReference; + +public class HtmlLabelRenderer extends WidgetRenderer { + + @Override + public VLabel createWidget() { + return GWT.create(VLabel.class); + } + + @Override + public void render(RendererCellReference cell, String input, VLabel label) { + Map map = formatInput(input); + String value = map.containsKey("value") ? map.get("value") : null; + String style = map.containsKey("style") ? map.get("style") : null; + String id = map.containsKey("id") ? map.get("id") : null; + + if (value != null) { + label.setHTML("&#x" + Integer.toHexString(Integer.parseInt(value)) + ";"); + } else { + label.setHTML(""); + } + applyStyle(label, style); + label.getElement().setId(id); + } + + private void applyStyle(VLabel label, String style) { + label.setStyleName(VLabel.CLASSNAME); + label.addStyleName(getStyle("small")); + label.addStyleName(getStyle("font-icon")); + if (style != null) { + label.addStyleName(getStyle(style)); + } + } + + private String getStyle(final String style) { + return new StringBuilder(style).append(" ").append(VLabel.CLASSNAME).append("-").append(style).toString(); + } + + private Map formatInput(String input) { + Map details = new HashMap<>(); + String[] tempData = input.split(","); + for (String statusWithCount : tempData) { + String[] statusWithCountList = statusWithCount.split(":"); + details.put(statusWithCountList[0], statusWithCountList[1]); + } + return details; + } + +} 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 new file mode 100644 index 000000000..535e71ef9 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java @@ -0,0 +1,37 @@ +/** + * 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; + +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/HtmlButtonRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlButtonRenderer.java new file mode 100644 index 000000000..f4dfd7f88 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlButtonRenderer.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + +import com.vaadin.ui.renderers.ButtonRenderer; + +public class HtmlButtonRenderer extends ButtonRenderer { + private static final long serialVersionUID = -1242995370043404892L; + public HtmlButtonRenderer() { + super(); + } + public HtmlButtonRenderer(RendererClickListener listener) { + super(listener); + } + +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlLabelRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlLabelRenderer.java new file mode 100644 index 000000000..a67e54bca --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlLabelRenderer.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + +import com.vaadin.ui.Grid.AbstractRenderer; + +public class HtmlLabelRenderer extends AbstractRenderer { + + private static final long serialVersionUID = -7675588068526774915L; + /** + * Creates a new text renderer + */ + public HtmlLabelRenderer() { + super(String.class, null); + } +} 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 new file mode 100644 index 000000000..010e8e615 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + +import com.vaadin.ui.renderers.ButtonRenderer; + +public class LinkRenderer extends ButtonRenderer { + private static final long serialVersionUID = -1242995370043404892L; + public LinkRenderer() { + super(); + } + public LinkRenderer(RendererClickListener listener) { + super(listener); + } + +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java index f8d53b1bf..44634618e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java @@ -527,7 +527,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { } else if (Action.Status.SCHEDULED == status) { label.setStyleName(statusIconPending); label.setDescription(i18n.get("label.scheduled")); - label.setValue(FontAwesome.BULLSEYE.getHtml()); + label.setValue(FontAwesome.HOURGLASS_1.getHtml()); } else { label.setDescription(""); label.setValue(""); @@ -578,7 +578,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { label.setContentMode(ContentMode.HTML); if (SPUIDefinitions.SCHEDULED.equals(activeValue)) { label.setDescription("Scheduled"); - label.setValue(FontAwesome.BULLSEYE.getHtml()); + label.setValue(FontAwesome.HOURGLASS_1.getHtml()); } else if (SPUIDefinitions.ACTIVE.equals(activeValue)) { label.setDescription("Active"); label.setStyleName("statusIconActive"); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTable.java deleted file mode 100644 index db0b468cc..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTable.java +++ /dev/null @@ -1,116 +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.rollout; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.TableColumn; - -import com.vaadin.data.Container; -import com.vaadin.ui.Table; -import com.vaadin.ui.themes.ValoTheme; - -/** - * Abstract table class. - * - */ -public abstract class AbstractSimpleTable extends Table { - - private static final long serialVersionUID = 4856562746502217630L; - - /** - * Initialize the components. - */ - protected void init() { - addStyleName("sp-table rollout-table"); - setSizeFull(); - setImmediate(true); - setHeight(100.0f, Unit.PERCENTAGE); - addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES); - addStyleName(ValoTheme.TABLE_SMALL); - setSortEnabled(false); - setId(getTableId()); - addCustomGeneratedColumns(); - addNewContainerDS(); - setColumnProperties(); - addValueChangeListener(event -> onValueChange()); - setPageLength(SPUIDefinitions.PAGE_SIZE); - setSelectable(false); - setColumnCollapsingAllowed(true); - setCollapsiblecolumns(); - } - - private void setColumnProperties() { - final List columnList = getTableVisibleColumns(); - final List columnIds = new ArrayList<>(); - for (final TableColumn column : columnList) { - setColumnHeader(column.getColumnPropertyId(), column.getColumnHeader()); - setColumnExpandRatio(column.getColumnPropertyId(), column.getExpandRatio()); - columnIds.add(column.getColumnPropertyId()); - } - setVisibleColumns(columnIds.toArray()); - } - - private void addNewContainerDS() { - final Container container = createContainer(); - addContainerProperties(container); - setContainerDataSource(container); - int size = 0; - if (container != null) { - size = container.size(); - } - if (size == 0) { - setData(SPUIDefinitions.NO_DATA); - } - } - - /** - * Based on table state (max/min) columns to be shown are returned. - * - * @return List list of visible columns - */ - protected abstract List getTableVisibleColumns(); - - /** - * Create container of the data to be displayed by the table. - */ - protected abstract Container createContainer(); - - /** - * Add container properties to the container passed in the reference. - * - * @param container - * reference of {@link Container} - */ - protected abstract void addContainerProperties(Container container); - - /** - * Get Id of the table. - * - * @return Id. - */ - protected abstract String getTableId(); - - /** - * On select of row. - */ - protected abstract void onValueChange(); - - /** - * Add any generated columns if required. - */ - protected abstract void addCustomGeneratedColumns(); - - /** - * Set list of columns collapsible. - */ - protected abstract void setCollapsiblecolumns(); -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarHelper.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarHelper.java new file mode 100644 index 000000000..c8b43cb6a --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarHelper.java @@ -0,0 +1,134 @@ +/** + * 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.rollout; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; +import org.vaadin.alump.distributionbar.gwt.client.GwtDistributionBar; + +/** + * Distribution bar helper to render distribution bar in grid. + * + */ +public final class DistributionBarHelper { + private static final int PARENT_SIZE_IN_PCT = 100; + private static final double MINIMUM_PART_SIZE = 10; + private static final String DISTRIBUTION_BAR_PART_MAIN_STYLE = GwtDistributionBar.CLASSNAME + "-part"; + private static final String DISTRIBUTION_BAR_PART_CLASSNAME_PREFIX = GwtDistributionBar.CLASSNAME + "-part-"; + private static final String DISTRIBUTION_BAR_PART_VALUE_CLASSNAME = GwtDistributionBar.CLASSNAME + "-value"; + private static final String UNINITIALIZED_VALUE_CLASSNAME = GwtDistributionBar.CLASSNAME + "-uninitizalized"; + + private DistributionBarHelper() { + } + + private static String getPartStyle(int partIndex, int noOfParts, String customStyle) { + StringBuilder mainStyle = new StringBuilder(); + StringBuilder styleName = new StringBuilder(GwtDistributionBar.CLASSNAME); + if (noOfParts == 1) { + styleName.append("-only"); + } else if (partIndex == 1) { + styleName.append("-left"); + } else if (partIndex == noOfParts) { + styleName.append("-right"); + } else { + styleName.append("-middle"); + } + mainStyle.append(styleName).append(" "); + mainStyle.append(DISTRIBUTION_BAR_PART_MAIN_STYLE).append(" "); + mainStyle.append(DISTRIBUTION_BAR_PART_CLASSNAME_PREFIX + partIndex); + if (customStyle != null) { + mainStyle.append(" ").append("status-bar-part-" + customStyle); + } + return mainStyle.toString(); + } + + private static String getPartWidth(Long value, Long totalValue, int noOfParts) { + final double minTotalSize = MINIMUM_PART_SIZE * noOfParts; + final double availableSize = PARENT_SIZE_IN_PCT - minTotalSize; + double val = MINIMUM_PART_SIZE + (double) value / totalValue * availableSize; + return String.format("%.3f", val) + "%"; + } + + private static String getPart(int partIndex, Status status, Long value, Long totalValue, int noOfParts) { + String partValue = status.toString().toLowerCase(); + // return "
" + value + + // "
"; + return "
" + value + "
"; + } + + public static String getDistributionBarAsHTMLString(Map statusTotalCountMap) { + StringBuilder htmlString = new StringBuilder(); + htmlString.append(getParentDivStart()); + Long totalValue = getTotalSizes(statusTotalCountMap); + Map statusMapWithNonZeroValues = getNonZeroStatusList(statusTotalCountMap); + + if (statusMapWithNonZeroValues.size() > 0) { + int partIndex = 1; + for (Map.Entry entry : statusMapWithNonZeroValues.entrySet()) { + if (entry.getValue() > 0) { + htmlString.append(getPart(partIndex, entry.getKey(), entry.getValue(), totalValue, + statusMapWithNonZeroValues.size())); + partIndex++; + } + } + } else { + return getUnintialisedBar(); + } + htmlString.append(getParentDivEnd()); + return htmlString.toString(); + } + + public static Map getNonZeroStatusList(Map statusTotalCountMap) { + return statusTotalCountMap.entrySet().stream().filter(p -> p.getValue() > 0) + .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue())); + } + + + public static String getTooltip(Map statusCountMap) { + Map nonZeroStatusCountMap = DistributionBarHelper.getNonZeroStatusList(statusCountMap); + StringBuilder tooltip = new StringBuilder(); + for (Entry entry : nonZeroStatusCountMap.entrySet()) { + tooltip.append(entry.getKey().toString().toLowerCase()).append(" : ").append(entry.getValue()) + .append("
"); + } + return tooltip.toString(); + } + + private static String getUnintialisedBar() { + return "
uninitialized
"; + } + + private static Long getTotalSizes(Map statusTotalCountMap) { + Long total = 0L; + for (Long value : statusTotalCountMap.values()) { + total = total + value; + } + return total; + } + + private static String getParentDivStart() { + return "
"; + } + + private static String getParentDivEnd() { + return "
"; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListTable.java deleted file mode 100644 index cf1a004d8..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListTable.java +++ /dev/null @@ -1,361 +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.rollout; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.PostConstruct; -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.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; -import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; -import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.TableColumn; -import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; -import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; -import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.alump.distributionbar.DistributionBar; -import org.vaadin.spring.events.EventBus; -import org.vaadin.spring.events.EventScope; -import org.vaadin.spring.events.annotation.EventBusListenerMethod; - -import com.vaadin.data.Container; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.server.FontAwesome; -import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.spring.annotation.SpringComponent; -import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.Button; -import com.vaadin.ui.Component; -import com.vaadin.ui.Label; -import com.vaadin.ui.themes.ValoTheme; - -/** - * Rollout Group Table in List view. - * - */ -@SpringComponent -@ViewScope -public class RolloutGroupListTable extends AbstractSimpleTable { - - private static final String IS_ACTION_RECIEVED = "isActionRecieved"; - - private static final long serialVersionUID = 1182656768844867443L; - - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private transient RolloutGroupManagement rolloutGroupManagement; - - @Autowired - private transient RolloutManagement rolloutManagement; - - @Autowired - private transient RolloutUIState rolloutUIState; - - @Autowired - private transient SpPermissionChecker permissionChecker; - - @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) { - if (event == RolloutEvent.SHOW_ROLLOUT_GROUPS) { - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } - } - - /** - * - * Handles the RolloutGroupChangeEvent to refresh the item in the table. - * - * - * @param rolloutGroupChangeEvent - * the event which contains the rollout group which has been - * change - */ - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { - final List visibleItemIds = (List) getVisibleItemIds(); - if (visibleItemIds.contains(rolloutGroupChangeEvent.getRolloutGroupId())) { - final RolloutGroup rolloutGroup = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); - final TotalTargetCountStatus totalTargetCountStatus = rolloutGroup.getTotalTargetCountStatus(); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutGroup.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_RUNNING).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_ERROR) - .setValue(totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_FINISHED).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_NOT_STARTED).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_CANCELLED).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_SCHEDULED).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)); - item.getItemProperty(IS_ACTION_RECIEVED) - .setValue(!(Boolean) item.getItemProperty(IS_ACTION_RECIEVED).getValue()); - } - } - - @Override - protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_GROUP_NAME, i18n.get("header.name"), 0.1f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_GROUP_STATUS, i18n.get("header.status"), 0.1f)); - columnList.add(new TableColumn(SPUIDefinitions.DETAIL_STATUS, i18n.get("header.detail.status"), 0.42f)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS, i18n.get("header.total.targets"), 0.08f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, - i18n.get("header.rolloutgroup.installed.percentage"), 0.1f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, - i18n.get("header.rolloutgroup.threshold.error"), 0.1f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_GROUP_THRESHOLD, - i18n.get("header.rolloutgroup.threshold"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.15f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_USER, i18n.get("header.createdBy"), 0.15f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.15f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.15f)); - return columnList; - } - - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } - - @Override - protected void addContainerProperties(final Container container) { - final LazyQueryContainer rolloutTableContainer = (LazyQueryContainer) container; - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_ID, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, - false, false); - rolloutTableContainer.addContainerProperty(SPUIDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, String.class, - null, false, false); - rolloutTableContainer.addContainerProperty(SPUIDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, null, - false, false); - - rolloutTableContainer.addContainerProperty(SPUIDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, false, - false); - - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); - - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_NOT_STARTED, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_RUNNING, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_SCHEDULED, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_ERROR, Long.class, 0L, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_FINISHED, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_CANCELLED, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(IS_ACTION_RECIEVED, Boolean.class, false, false, false); - - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - - } - - @Override - protected String getTableId() { - return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_TABLE_ID; - } - - @Override - protected void onValueChange() { - /** - * No implementation required. - */ - } - - @Override - protected void addCustomGeneratedColumns() { - addGeneratedColumn(SPUIDefinitions.ROLLOUT_GROUP_NAME, - (source, itemId, columnId) -> getRolloutNameLink(itemId)); - addGeneratedColumn(SPUIDefinitions.ROLLOUT_GROUP_STATUS, (source, itemId, columnId) -> getStatusLabel(itemId)); - addGeneratedColumn(SPUIDefinitions.DETAIL_STATUS, (source, itemId, columnId) -> getProgressBar(itemId)); - setColumnAlignment(SPUIDefinitions.ROLLOUT_GROUP_STATUS, Align.CENTER); - - } - - private Label getStatusLabel(final Object itemId) { - final Label statusLabel = new Label(); - statusLabel.setHeightUndefined(); - statusLabel.setContentMode(ContentMode.HTML); - setStatusIcon(itemId, statusLabel); - statusLabel.setDescription(getDescription(itemId)); - statusLabel.setSizeUndefined(); - addPropertyChangeListener(itemId, statusLabel); - return statusLabel; - } - - private void addPropertyChangeListener(final Object itemId, final Label statusLabel) { - final Property status = getContainerProperty(itemId, SPUILabelDefinitions.VAR_STATUS); - final Property.ValueChangeNotifier notifier = (Property.ValueChangeNotifier) status; - notifier.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(final com.vaadin.data.Property.ValueChangeEvent event) { - setStatusIcon(itemId, statusLabel); - } - }); - } - - private String getDescription(final Object itemId) { - final Item item = getItem(itemId); - if (item != null) { - final RolloutGroupStatus rolloutGroupStatus = (RolloutGroupStatus) item - .getItemProperty(SPUILabelDefinitions.VAR_STATUS).getValue(); - return rolloutGroupStatus.toString().toLowerCase(); - } - return null; - } - - private void setStatusIcon(final Object itemId, final Label statusLabel) { - final Item item = getItem(itemId); - if (item != null) { - final RolloutGroupStatus rolloutGroupStatus = (RolloutGroupStatus) item - .getItemProperty(SPUILabelDefinitions.VAR_STATUS).getValue(); - setRolloutStatusIcon(rolloutGroupStatus, statusLabel); - } - } - - private void setRolloutStatusIcon(final RolloutGroupStatus rolloutGroupStatus, final Label statusLabel) { - switch (rolloutGroupStatus) { - case FINISHED: - statusLabel.setValue(FontAwesome.CHECK_CIRCLE.getHtml()); - statusLabel.setStyleName("statusIconGreen"); - break; - case SCHEDULED: - statusLabel.setValue(FontAwesome.BULLSEYE.getHtml()); - statusLabel.setStyleName("statusIconBlue"); - break; - case RUNNING: - statusLabel.setValue(FontAwesome.ADJUST.getHtml()); - statusLabel.setStyleName("statusIconYellow"); - break; - case READY: - statusLabel.setValue(FontAwesome.DOT_CIRCLE_O.getHtml()); - statusLabel.setStyleName("statusIconLightBlue"); - break; - case ERROR: - statusLabel.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); - statusLabel.setStyleName("statusIconRed"); - break; - default: - break; - } - statusLabel.addStyleName(ValoTheme.LABEL_SMALL); - } - - private Component getRolloutNameLink(final Object itemId) { - final Item row = getItem(itemId); - final String rolloutGroupName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - if (permissionChecker.hasRolloutTargetsReadPermission()) { - final Button rolloutGroupNameLink = SPUIComponentProvider.getButton(getDetailLinkId(rolloutGroupName), - rolloutGroupName, SPUILabelDefinitions.SHOW_ROLLOUT_GROUP_DETAILS, null, false, null, - SPUIButtonStyleSmallNoBorder.class); - rolloutGroupNameLink.setData(rolloutGroupName); - rolloutGroupNameLink.addStyleName(ValoTheme.LINK_SMALL + " " + "on-focus-no-border link"); - rolloutGroupNameLink.addClickListener(event -> showRolloutGroups(itemId)); - return rolloutGroupNameLink; - } else { - final Label rolloutGroupNameLabel = new Label(); - rolloutGroupNameLabel.setHeightUndefined(); - rolloutGroupNameLabel.addStyleName(ValoTheme.LABEL_SMALL); - rolloutGroupNameLabel.setValue(rolloutGroupName); - return rolloutGroupNameLabel; - } - } - - private void showRolloutGroups(final Object itemId) { - rolloutUIState.setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) itemId)); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); - } - - private DistributionBar getProgressBar(final Object itemId) { - final DistributionBar bar = new DistributionBar(2); - bar.setSizeFull(); - bar.setZeroSizedVisible(false); - HawkbitCommonUtil.initialiseProgressBar(bar, getItem(itemId)); - addPropertyChangeListenerOnActionRecieved(itemId, bar); - return bar; - } - - private void addPropertyChangeListenerOnActionRecieved(final Object itemId, final DistributionBar bar) { - final Property status = getContainerProperty(itemId, IS_ACTION_RECIEVED); - final Property.ValueChangeNotifier notifier = (Property.ValueChangeNotifier) status; - notifier.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(final com.vaadin.data.Property.ValueChangeEvent event) { - HawkbitCommonUtil.initialiseProgressBar(bar, getItem(itemId)); - } - }); - } - - private static String getDetailLinkId(final String rolloutGroupName) { - return new StringBuilder(SPUIComponetIdProvider.ROLLOUT_GROUP_NAME_LINK_ID).append('.').append(rolloutGroupName) - .toString(); - } - - @Override - protected void setCollapsiblecolumns() { - setColumnCollapsed(SPUILabelDefinitions.VAR_CREATED_DATE, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_MODIFIED_DATE, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_CREATED_USER, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_MODIFIED_BY, true); - } - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListTable.java deleted file mode 100644 index bb037231b..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListTable.java +++ /dev/null @@ -1,231 +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.rollout; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; -import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; -import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.TableColumn; -import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; -import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; -import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; -import org.vaadin.spring.events.EventScope; -import org.vaadin.spring.events.annotation.EventBusListenerMethod; - -import com.vaadin.data.Container; -import com.vaadin.data.Item; -import com.vaadin.server.FontAwesome; -import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.spring.annotation.SpringComponent; -import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.Label; -import com.vaadin.ui.themes.ValoTheme; - -/** - * Rollout Group Targets Table in List view. - * - */ -@SpringComponent -@ViewScope -public class RolloutGroupTargetsListTable extends AbstractSimpleTable { - - private static final long serialVersionUID = 7984314603271801746L; - - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private transient RolloutUIState rolloutUIState; - - @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) { - if (event == RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS) { - ((LazyQueryContainer) getContainerDataSource()).refresh(); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS_COUNT); - } - } - - @Override - protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.15f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.15f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.15f)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.15f)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.15f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.15f)); - - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_TARGET_STATUS, i18n.get("header.status"), 0.1f)); - - return columnList; - } - - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutgrouBeanQueryFactory = new BeanQueryFactory<>( - RolloutGroupTargetsBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), - rolloutgrouBeanQueryFactory); - } - - @Override - protected void addContainerProperties(final Container container) { - final LazyQueryContainer rolloutGroupTargetTableContainer = (LazyQueryContainer) container; - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CONT_ID, String.class, "", false, - false); - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, - true); - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, Status.class, - Status.RETRIEVED, false, false); - - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_TARGET_STATUS, - TargetUpdateStatus.class, TargetUpdateStatus.UNKNOWN, false, false); - - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, - String.class, "", false, true); - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_BY, String.class, null, - false, true); - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, - null, false, true); - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, - false, true); - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, - null, false, true); - rolloutGroupTargetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, - true); - } - - @Override - protected String getTableId() { - - return SPUIComponetIdProvider.ROLLOUT_GROUP_TARGETS_LIST_TABLE_ID; - } - - @Override - protected void onValueChange() { - // No implementation required. - - } - - @Override - protected void addCustomGeneratedColumns() { - addGeneratedColumn(SPUILabelDefinitions.VAR_TARGET_STATUS, - (source, itemId, columnId) -> getStatusLabel(itemId)); - setColumnAlignment(SPUILabelDefinitions.VAR_TARGET_STATUS, Align.CENTER); - } - - @Override - protected void setCollapsiblecolumns() { - // No implementation required. - } - - private Label getStatusLabel(final Object itemId) { - final Label statusLabel = new Label(); - statusLabel.addStyleName(ValoTheme.LABEL_SMALL); - statusLabel.setHeightUndefined(); - statusLabel.setContentMode(ContentMode.HTML); - setStatusIcon(itemId, statusLabel); - statusLabel.setSizeUndefined(); - return statusLabel; - } - - private void setStatusIcon(final Object itemId, final Label statusLabel) { - final Item item = getItem(itemId); - final RolloutGroup rolloutGroup = rolloutUIState.getRolloutGroup().isPresent() - ? rolloutUIState.getRolloutGroup().get() : null; - if (item != null) { - final Status status = (Status) item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).getValue(); - if (status == null) { - if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { - statusLabel.setValue(FontAwesome.DOT_CIRCLE_O.getHtml()); - statusLabel.addStyleName("statusIconLightBlue"); - statusLabel.setDescription(RolloutGroupStatus.READY.toString().toLowerCase()); - } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { - statusLabel.setValue(FontAwesome.MINUS_CIRCLE.getHtml()); - statusLabel.addStyleName("statusIconBlue"); - - final String dsNameVersion = (String) item - .getItemProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER).getValue(); - statusLabel - .setDescription(i18n.get("message.dist.already.assigned", new Object[] { dsNameVersion })); - } - } else { - setRolloutStatusIcon(status, statusLabel); - statusLabel.setDescription(status.toString().toLowerCase()); - } - } - } - - private void setRolloutStatusIcon(final Status targetUpdateStatus, final Label statusLabel) { - switch (targetUpdateStatus) { - case ERROR: - statusLabel.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); - statusLabel.addStyleName("statusIconRed"); - break; - case SCHEDULED: - statusLabel.setValue(FontAwesome.BULLSEYE.getHtml()); - statusLabel.addStyleName("statusIconBlue"); - break; - case FINISHED: - statusLabel.setValue(FontAwesome.CHECK_CIRCLE.getHtml()); - statusLabel.addStyleName("statusIconGreen"); - break; - case RUNNING: - case RETRIEVED: - case WARNING: - case DOWNLOAD: - statusLabel.setValue(FontAwesome.ADJUST.getHtml()); - statusLabel.addStyleName("statusIconYellow"); - break; - case CANCELED: - statusLabel.setValue(FontAwesome.TIMES_CIRCLE.getHtml()); - statusLabel.addStyleName("statusIconGreen"); - break; - case CANCELING: - statusLabel.setValue(FontAwesome.TIMES_CIRCLE.getHtml()); - statusLabel.addStyleName("statusIconPending"); - break; - default: - break; - } - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListTable.java deleted file mode 100644 index 5b5602748..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListTable.java +++ /dev/null @@ -1,552 +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.rollout; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; -import org.eclipse.hawkbit.repository.RolloutManagement; -import org.eclipse.hawkbit.repository.SpPermissionChecker; -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.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; -import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; -import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.TableColumn; -import org.eclipse.hawkbit.ui.utils.UINotification; -import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; -import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; -import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.alump.distributionbar.DistributionBar; -import org.vaadin.peter.contextmenu.ContextMenu; -import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItem; -import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickEvent; -import org.vaadin.spring.events.EventBus; -import org.vaadin.spring.events.EventScope; -import org.vaadin.spring.events.annotation.EventBusListenerMethod; - -import com.vaadin.data.Container; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.server.FontAwesome; -import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.spring.annotation.SpringComponent; -import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Label; -import com.vaadin.ui.UI; -import com.vaadin.ui.Window; -import com.vaadin.ui.themes.ValoTheme; - -/** - * - * Rollout table in list view. - * - */ -@SpringComponent -@ViewScope -public class RolloutListTable extends AbstractSimpleTable { - - private static final String IS_ACTION_RECIEVED = "isActionRecieved"; - - private static final long serialVersionUID = 8141874975649180139L; - - @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; - - @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) { - if (event == RolloutEvent.FILTER_BY_TEXT || event == RolloutEvent.CREATE_ROLLOUT - || event == RolloutEvent.UPDATE_ROLLOUT || event == RolloutEvent.SHOW_ROLLOUTS) { - refreshTable(); - } - } - - /** - * Handles the RolloutChangeEvent to refresh the item in the table. - * - * @param rolloutChangeEvent - * the event which contains the rollout which has been changed - */ - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { - final List visibleItemIds = (List) getVisibleItemIds(); - if (visibleItemIds.contains(rolloutChangeEvent.getRolloutId())) { - final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); - final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); - - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_RUNNING).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_ERROR).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_FINISHED).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_NOT_STARTED).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_CANCELLED).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)); - item.getItemProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_SCHEDULED).setValue( - totalTargetCountStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)); - item.getItemProperty(IS_ACTION_RECIEVED).setValue( - !(Boolean) item.getItemProperty(IS_ACTION_RECIEVED).getValue()); - - final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); - if (null != rollout.getRolloutGroups() && groupCount != rollout.getRolloutGroups().size()) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue( - Long.valueOf(rollout.getRolloutGroups().size())); - } - } - } - - @Override - protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_NAME, i18n.get("header.name"), 0.225f)); - - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, i18n.get("header.distributionset"), - 0.225f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_STATUS, i18n.get("header.status"), 0.07f)); - columnList.add(new TableColumn(SPUIDefinitions.DETAIL_STATUS, i18n.get("header.detail.status"), 0.58f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, i18n.get("header.numberofgroups"), - 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS, i18n.get("header.total.targets"), 0.1f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_ACTION, i18n.get("upload.action"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_USER, i18n.get("header.createdBy"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.1f)); - return columnList; - } - - @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 Container container) { - final LazyQueryContainer rolloutTableContainer = (LazyQueryContainer) container; - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_ID, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, - false, false); - - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_TARGETFILTERQUERY, String.class, null, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); - - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Integer.class, 0, false, - false); - - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_NOT_STARTED, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_RUNNING, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_SCHEDULED, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_ERROR, Long.class, 0L, false, - false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_FINISHED, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_CANCELLED, Long.class, 0L, - false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - - } - - @Override - protected String getTableId() { - return SPUIComponetIdProvider.ROLLOUT_LIST_TABLE_ID; - } - - @Override - protected void onValueChange() { - /** - * No implementation required. - */ - } - - @Override - protected void addCustomGeneratedColumns() { - addGeneratedColumn(SPUIDefinitions.ROLLOUT_NAME, (source, itemId, columnId) -> getRolloutNameLink(itemId)); - addGeneratedColumn(SPUIDefinitions.ROLLOUT_STATUS, (source, itemId, columnId) -> getStatusLabel(itemId)); - addGeneratedColumn(SPUIDefinitions.DETAIL_STATUS, (source, itemId, columnId) -> getProgressBar(itemId)); - addGeneratedColumn(SPUIDefinitions.ROLLOUT_ACTION, (source, itemId, columnId) -> getActionButton(itemId)); - - setColumnAlignment(SPUIDefinitions.ROLLOUT_STATUS, Align.CENTER); - setColumnAlignment(SPUIDefinitions.DETAIL_STATUS, Align.CENTER); - setColumnAlignment(SPUIDefinitions.ROLLOUT_ACTION, Align.CENTER); - - } - - @Override - protected void setCollapsiblecolumns() { - setColumnCollapsed(SPUILabelDefinitions.VAR_CREATED_DATE, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_MODIFIED_DATE, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_CREATED_USER, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_MODIFIED_BY, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_DESC, true); - } - - private Button getActionButton(final Object itemId) { - final Item row = getItem(itemId); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - final Button actionButton = SPUIComponentProvider.getButton(getActionButtonId(rolloutName), "", - SPUILabelDefinitions.ACTION, ValoTheme.BUTTON_TINY + " ", true, FontAwesome.CIRCLE_O, - SPUIButtonStyleSmallNoBorder.class); - actionButton.setData(itemId); - actionButton.setHtmlContentAllowed(true); - actionButton.addClickListener(event -> onAction(event)); - addStatusPropertyChangeListener(itemId, actionButton); - - final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - enableDisableActions(rolloutStatus, actionButton); - return actionButton; - } - - private void enableDisableActions(final RolloutStatus rolloutStatus, final Button actionButton) { - final RolloutStatus[] statusList = new RolloutStatus[] { RolloutStatus.FINISHED, RolloutStatus.STARTING, - RolloutStatus.CREATING, RolloutStatus.ERROR_CREATING, RolloutStatus.ERROR_STARTING }; - if (Arrays.asList(statusList).contains(rolloutStatus)) { - actionButton.setEnabled(false); - } else { - actionButton.setEnabled(true); - } - } - - private void addStatusPropertyChangeListener(final Object itemId, final Button actionButton) { - final Property status = getContainerProperty(itemId, SPUILabelDefinitions.VAR_STATUS); - final Property.ValueChangeNotifier notifier = (Property.ValueChangeNotifier) status; - notifier.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(final com.vaadin.data.Property.ValueChangeEvent event) { - final Item row = getItem(itemId); - final RolloutStatus rolloutStatus = (RolloutStatus) row - .getItemProperty(SPUILabelDefinitions.VAR_STATUS).getValue(); - enableDisableActions(rolloutStatus, actionButton); - } - }); - } - - private ContextMenu createContextMenu(final Long rolloutId) { - final Item row = getItem(rolloutId); - final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - final ContextMenu context = new ContextMenu(); - context.addItemClickListener(event -> menuItemClicked(event)); - if (rolloutStatus == RolloutStatus.READY) { - final ContextMenuItem startItem = context.addItem("Start"); - startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); - } else if (rolloutStatus == RolloutStatus.RUNNING) { - final ContextMenuItem pauseItem = context.addItem("Pause"); - pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); - } else if (rolloutStatus == RolloutStatus.PAUSED) { - final ContextMenuItem resumeItem = context.addItem("Resume"); - resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); - } else if (rolloutStatus == RolloutStatus.STARTING || rolloutStatus == RolloutStatus.CREATING) { - return context; - } - if (permissionChecker.hasRolloutUpdatePermission()) { - final ContextMenuItem cancelItem = context.addItem("Update"); - cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); - } - return context; - } - - private void menuItemClicked(final ContextMenuItemClickEvent event) { - final ContextMenuItem item = (ContextMenuItem) event.getSource(); - final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); - final Item row = getItem(contextMenuData.getRolloutId()); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - - if (contextMenuData.getAction() == ACTION.PAUSE) { - rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); - } else if (contextMenuData.getAction() == ACTION.RESUME) { - rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); - } else if (contextMenuData.getAction() == ACTION.START) { - rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); - uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); - } else if (contextMenuData.getAction() == ACTION.UPDATE) { - 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 onAction(final ClickEvent event) { - final ContextMenu contextMenu = createContextMenu((Long) event.getButton().getData()); - contextMenu.setAsContextMenuOf(event.getButton()); - contextMenu.open(event.getClientX(), event.getClientY()); - } - - private Button getRolloutNameLink(final Object itemId) { - final Item row = getItem(itemId); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - final Button updateIcon = SPUIComponentProvider.getButton(getDetailLinkId(rolloutName), rolloutName, - SPUILabelDefinitions.SHOW_ROLLOUT_GROUP_DETAILS, null, false, null, SPUIButtonStyleSmallNoBorder.class); - updateIcon.setData(rolloutName); - updateIcon.addStyleName(ValoTheme.LINK_SMALL + " " + "on-focus-no-border link"); - updateIcon.addClickListener(event -> showRolloutGroups(itemId)); - return updateIcon; - } - - private void showRolloutGroups(final Object itemId) { - rolloutUIState.setRolloutId((long) itemId); - final String rolloutName = (String) getItem(itemId).getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - rolloutUIState.setRolloutName(rolloutName); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); - } - - private static String getActionButtonId(final String rollOutName) { - return new StringBuilder(SPUIComponetIdProvider.ROLLOUT_ACTION_BUTTON_ID).append('.').append(rollOutName) - .toString(); - } - - private static String getDetailLinkId(final String rollOutName) { - return new StringBuilder(SPUIComponetIdProvider.ROLLOUT_NAME_LINK_ID).append('.').append(rollOutName) - .toString(); - } - - private DistributionBar getProgressBar(final Object itemId) { - final DistributionBar bar = new DistributionBar(2); - bar.setId(SPUIComponetIdProvider.ROLLOUT_PROGRESS_BAR); - bar.setSizeFull(); - bar.setZeroSizedVisible(false); - HawkbitCommonUtil.initialiseProgressBar(bar, getItem(itemId)); - addPropertyChangeListenerOnActionRecieved(itemId, bar); - return bar; - } - - private void addPropertyChangeListenerOnActionRecieved(final Object itemId, final DistributionBar bar) { - final Property status = getContainerProperty(itemId, IS_ACTION_RECIEVED); - final Property.ValueChangeNotifier notifier = (Property.ValueChangeNotifier) status; - notifier.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(final com.vaadin.data.Property.ValueChangeEvent event) { - HawkbitCommonUtil.initialiseProgressBar(bar, getItem(itemId)); - } - }); - } - - private Label getStatusLabel(final Object itemId) { - final Label statusLabel = new Label(); - statusLabel.setHeightUndefined(); - statusLabel.setContentMode(ContentMode.HTML); - statusLabel.setId(getRolloutStatusId(itemId)); - setStatusIcon(itemId, statusLabel); - statusLabel.setSizeUndefined(); - addPropertyChangeListener(itemId, statusLabel); - return statusLabel; - } - - private void addPropertyChangeListener(final Object itemId, final Label statusLabel) { - final Property status = getContainerProperty(itemId, SPUILabelDefinitions.VAR_STATUS); - final Property.ValueChangeNotifier notifier = (Property.ValueChangeNotifier) status; - notifier.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(final com.vaadin.data.Property.ValueChangeEvent event) { - setStatusIcon(itemId, statusLabel); - } - }); - } - - private String getRolloutStatusId(final Object itemId) { - final String rolloutName = (String) getItem(itemId).getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - return new StringBuilder(SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID).append(".").append(rolloutName) - .toString(); - } - - private void setStatusIcon(final Object itemId, final Label statusLabel) { - final Item item = getItem(itemId); - if (item != null) { - final RolloutStatus rolloutStatus = (RolloutStatus) item.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - setRolloutStatusIcon(rolloutStatus, statusLabel); - } - } - - private void setRolloutStatusIcon(final RolloutStatus rolloutStatus, final Label statusLabel) { - statusLabel.setDescription(rolloutStatus.toString().toLowerCase()); - switch (rolloutStatus) { - case FINISHED: - statusLabel.setValue(FontAwesome.CHECK_CIRCLE.getHtml()); - statusLabel.setStyleName("statusIconGreen"); - break; - case PAUSED: - statusLabel.setValue(FontAwesome.PAUSE.getHtml()); - statusLabel.setStyleName("statusIconBlue"); - break; - case RUNNING: - statusLabel.setValue(null); - statusLabel.setStyleName("yellowSpinner"); - break; - case READY: - statusLabel.setValue(FontAwesome.DOT_CIRCLE_O.getHtml()); - statusLabel.setStyleName("statusIconLightBlue"); - break; - case STOPPED: - statusLabel.setValue(FontAwesome.STOP.getHtml()); - statusLabel.setStyleName("statusIconRed"); - break; - case CREATING: - statusLabel.setValue(null); - statusLabel.setStyleName("greySpinner"); - break; - case STARTING: - statusLabel.setValue(null); - statusLabel.setStyleName("blueSpinner"); - break; - case ERROR_CREATING: - statusLabel.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); - statusLabel.setStyleName("statusIconRed"); - statusLabel.setDescription(i18n.get("message.error.creating.rollout")); - break; - case ERROR_STARTING: - statusLabel.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); - statusLabel.setStyleName("statusIconRed"); - statusLabel.setDescription(i18n.get("message.error.starting.rollout")); - break; - default: - break; - } - statusLabel.addStyleName(ValoTheme.LABEL_SMALL); - } - - private void refreshTable() { - final LazyQueryContainer container = (LazyQueryContainer) getContainerDataSource(); - container.refresh(); - } - - 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; - } - - } - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java index 98e009dad..1d514c545 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java @@ -13,6 +13,9 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; +import org.eclipse.hawkbit.ui.rollout.rollout.RolloutListView; +import org.eclipse.hawkbit.ui.rollout.rolloutgroup.RolloutGroupsListView; +import org.eclipse.hawkbit.ui.rollout.rolloutgrouptargets.RolloutGroupTargetsListView; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventBus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java similarity index 99% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AddUpdateRolloutWindowLayout.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index d0cddfb19..507c39b7f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rollout; import java.text.SimpleDateFormat; import java.util.Date; @@ -646,7 +646,7 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { } private Container createDsComboContainer() { - final BeanQueryFactory distributionQF = new BeanQueryFactory<>(DistBeanQuery.class); + final BeanQueryFactory distributionQF = new BeanQueryFactory<>(DistributionBeanQuery.class); return new LazyQueryContainer(new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_DIST_ID_NAME), distributionQF); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java similarity index 96% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistBeanQuery.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java index 6226471ac..74daf89d8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rollout; import java.io.IOException; import java.io.ObjectInputStream; @@ -34,7 +34,7 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition; * Bean query for distribution set combo. * */ -public class DistBeanQuery extends AbstractBeanQuery { +public class DistributionBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = 5176481314404662215L; private Sort sort = new Sort(Direction.ASC, "name", "version"); @@ -53,7 +53,7 @@ public class DistBeanQuery extends AbstractBeanQuery { * @param sortStates * as Sort status */ - public DistBeanQuery(final QueryDefinition definition, final Map queryConfig, + public DistributionBeanQuery(final QueryDefinition definition, final Map queryConfig, final Object[] sortPropertyIds, final boolean[] sortStates) { super(definition, queryConfig, sortPropertyIds, sortStates); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java similarity index 53% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRollout.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 92f30293a..b1309f8b9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -6,10 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.model.Rollout; +import com.vaadin.server.FontAwesome; + /** * Proxy rollout with suctome properties. * @@ -26,22 +28,10 @@ public class ProxyRollout extends Rollout { private Long numberOfGroups; - private Long runningTargetsCount; - - private Long scheduledTargetsCount; - - private Long cancelledTargetsCount; - - private Long errorTargetsCount; - - private Long finishedTargetsCount; - - private Long notStartedTargetsCount; - private Boolean isActionRecieved = Boolean.FALSE; private String totalTargetsCount; - + /** * @return the distributionSetNameVersion */ @@ -102,81 +92,6 @@ public class ProxyRollout extends Rollout { this.modifiedDate = modifiedDate; } - /** - * @return the runningTargetsCount - */ - public Long getRunningTargetsCount() { - return runningTargetsCount; - } - - /** - * @param runningTargetsCount - * the runningTargetsCount to set - */ - public void setRunningTargetsCount(final Long runningTargetsCount) { - this.runningTargetsCount = runningTargetsCount; - } - - /** - * @return the scheduledTargetsCount - */ - public Long getScheduledTargetsCount() { - return scheduledTargetsCount; - } - - /** - * @param scheduledTargetsCount - * the scheduledTargetsCount to set - */ - public void setScheduledTargetsCount(final Long scheduledTargetsCount) { - this.scheduledTargetsCount = scheduledTargetsCount; - } - - /** - * @return the cancelledTargetsCount - */ - public Long getCancelledTargetsCount() { - return cancelledTargetsCount; - } - - /** - * @param cancelledTargetsCount - * the cancelledTargetsCount to set - */ - public void setCancelledTargetsCount(final Long cancelledTargetsCount) { - this.cancelledTargetsCount = cancelledTargetsCount; - } - - /** - * @return the errorTargetsCount - */ - public Long getErrorTargetsCount() { - return errorTargetsCount; - } - - /** - * @param errorTargetsCount - * the errorTargetsCount to set - */ - public void setErrorTargetsCount(final Long errorTargetsCount) { - this.errorTargetsCount = errorTargetsCount; - } - - /** - * @return the finishedTargetsCount - */ - public Long getFinishedTargetsCount() { - return finishedTargetsCount; - } - - /** - * @param finishedTargetsCount - * the finishedTargetsCount to set - */ - public void setFinishedTargetsCount(final Long finishedTargetsCount) { - this.finishedTargetsCount = finishedTargetsCount; - } - /** * @return the isActionRecieved */ @@ -192,21 +107,6 @@ public class ProxyRollout extends Rollout { this.isActionRecieved = isActionRecieved; } - /** - * @return the notStartedTargetsCount - */ - public Long getNotStartedTargetsCount() { - return notStartedTargetsCount; - } - - /** - * @param notStartedTargetsCount - * the notStartedTargetsCount to set - */ - public void setNotStartedTargetsCount(final Long notStartedTargetsCount) { - this.notStartedTargetsCount = notStartedTargetsCount; - } - /** * @return the totalTargetsCount */ @@ -221,4 +121,10 @@ public class ProxyRollout extends Rollout { 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/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java similarity index 87% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutBeanQuery.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 8dfdca4b5..5ab6f6a97 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rollout; import java.util.ArrayList; import java.util.List; @@ -132,23 +132,10 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setStatus(rollout.getStatus()); final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); - - proxyRollout.setRunningTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)); - proxyRollout.setErrorTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)); - proxyRollout.setCancelledTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)); - proxyRollout.setFinishedTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)); - proxyRollout.setScheduledTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)); - proxyRollout.setNotStartedTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)); - proxyRolloutList.add(proxyRollout); - + proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - + + proxyRolloutList.add(proxyRollout); } return proxyRolloutList; } 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 new file mode 100644 index 000000000..21c923a3a --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -0,0 +1,568 @@ +/** + * 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.rollout.rollout; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; +import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.SpPermissionChecker; +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.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.event.RolloutEvent; +import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.UINotification; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; +import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; +import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; +import org.vaadin.peter.contextmenu.ContextMenu; +import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItem; +import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickEvent; +import org.vaadin.spring.events.EventBus; +import org.vaadin.spring.events.EventScope; +import org.vaadin.spring.events.annotation.EventBusListenerMethod; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.PropertyValueGenerator; +import com.vaadin.data.util.converter.Converter; +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.UI; +import com.vaadin.ui.Window; +import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; +import com.vaadin.ui.renderers.HtmlRenderer; + +@SpringComponent +@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; + + @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) { + if (event == RolloutEvent.FILTER_BY_TEXT || event == RolloutEvent.CREATE_ROLLOUT + || event == RolloutEvent.UPDATE_ROLLOUT || event == RolloutEvent.SHOW_ROLLOUTS) { + refreshGrid(); + } + } + + /** + * 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()) { + 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 (null != item) { + 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 (null != rollout.getRolloutGroups() && 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()); + 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 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 Item row = getContainerDataSource().getItem(rolloutId); + final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) + .getValue(); + final ContextMenu context = new ContextMenu(); + context.addItemClickListener(event -> menuItemClicked(event)); + if (rolloutStatus == RolloutStatus.READY) { + final ContextMenuItem startItem = context.addItem(START_OPTION); + startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); + } else if (rolloutStatus == RolloutStatus.RUNNING) { + final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); + pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); + } else if (rolloutStatus == RolloutStatus.PAUSED) { + final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); + resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); + } else if (rolloutStatus == RolloutStatus.STARTING || rolloutStatus == RolloutStatus.CREATING) { + return context; + } + if (permissionChecker.hasRolloutUpdatePermission()) { + final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); + cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); + } + return context; + } + + private String convertRolloutStatusToString(final RolloutStatus value) { + String result = null; + switch (value) { + case FINISHED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.CHECK_CIRCLE.getCodepoint()), SPUIStyleDefinitions.STATUS_ICON_GREEN, + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case PAUSED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(Integer.toString(FontAwesome.PAUSE.getCodepoint()), + SPUIStyleDefinitions.STATUS_ICON_BLUE, SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case RUNNING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW, + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case READY: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), + SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE, SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case STOPPED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(Integer.toString(FontAwesome.STOP.getCodepoint()), + SPUIStyleDefinitions.STATUS_ICON_RED, SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case CREATING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY, + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case STARTING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE, + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case ERROR_CREATING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()), + SPUIStyleDefinitions.STATUS_ICON_RED, SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case ERROR_STARTING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()), + SPUIStyleDefinitions.STATUS_ICON_RED, SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + default: + break; + } + return result; + } + + 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(); + if (contextMenuData.getAction() == ACTION.PAUSE) { + rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); + } else if (contextMenuData.getAction() == ACTION.RESUME) { + rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); + } else if (contextMenuData.getAction() == ACTION.START) { + rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); + uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); + } else if (contextMenuData.getAction() == ACTION.UPDATE) { + 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()); + } else { + 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; + } + + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListHeader.java similarity index 96% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListHeader.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListHeader.java index 26bf021c4..b3043eb4a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListHeader.java @@ -6,11 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rollout; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.ui.common.grid.AbstractGridHeader; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; @@ -35,7 +36,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class RolloutListHeader extends AbstractSimpleTableHeader { +public class RolloutListHeader extends AbstractGridHeader { private static final long serialVersionUID = 2365400733081333174L; @Autowired diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListView.java similarity index 78% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListView.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListView.java index 462bfd081..84aba0aff 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListView.java @@ -6,10 +6,11 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rollout; import javax.annotation.PostConstruct; +import org.eclipse.hawkbit.ui.common.grid.AbstractGridLayout; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -23,7 +24,7 @@ import com.vaadin.ui.Label; */ @SpringComponent @ViewScope -public class RolloutListView extends AbstractSimpleTableLayout { +public class RolloutListView extends AbstractGridLayout { private static final long serialVersionUID = -2703552177439393208L; @@ -31,24 +32,21 @@ public class RolloutListView extends AbstractSimpleTableLayout { private RolloutListHeader rolloutListHeader; @Autowired - private RolloutListTable rolloutListTable; + private RolloutListGrid rolloutListGrid; @PostConstruct void init() { - super.init(rolloutListHeader, rolloutListTable); + super.init(rolloutListHeader, rolloutListGrid); } - @Override protected boolean hasCountMessage() { - return false; } - @Override protected Label getCountMessageLabel() { - + return null; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java similarity index 98% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRolloutGroup.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index da49d843a..bb802c123 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import org.eclipse.hawkbit.repository.model.RolloutGroup; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java similarity index 85% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupBeanQuery.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index 7d6a3a46f..0dabb18fc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import java.util.ArrayList; import java.util.List; @@ -15,7 +15,6 @@ 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.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -29,7 +28,8 @@ import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery; import org.vaadin.addons.lazyquerycontainer.QueryDefinition; /** - * @author gah6kor + * Simple implementation of generics bean query which dynamically loads a batch + * of {@link ProxyRolloutGroup} beans. * */ public class RolloutGroupBeanQuery extends AbstractBeanQuery { @@ -122,22 +122,8 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - final TotalTargetCountStatus totalTargetCountActionStatus = rolloutGroup.getTotalTargetCountStatus(); - - proxyRolloutGroup.setRunningTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)); - proxyRolloutGroup.setErrorTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)); - proxyRolloutGroup.setCancelledTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)); - proxyRolloutGroup.setFinishedTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)); - proxyRolloutGroup.setScheduledTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)); - proxyRolloutGroup.setNotStartedTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)); - proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); + proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); proxyRolloutGroupsList.add(proxyRolloutGroup); } 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 new file mode 100644 index 000000000..8c2fa398f --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -0,0 +1,392 @@ +/** + * 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.rollout.rolloutgroup; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.repository.RolloutGroupManagement; +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.renderers.HtmlLabelRenderer; +import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; +import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; +import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; +import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; +import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; +import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; +import org.vaadin.spring.events.EventBus; +import org.vaadin.spring.events.EventScope; +import org.vaadin.spring.events.annotation.EventBusListenerMethod; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.converter.Converter; +import com.vaadin.server.FontAwesome; +import com.vaadin.spring.annotation.SpringComponent; +import com.vaadin.spring.annotation.ViewScope; +import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; +import com.vaadin.ui.renderers.HtmlRenderer; + +@SpringComponent +@ViewScope +public class RolloutGroupListGrid extends AbstractGrid { + private static final long serialVersionUID = 4060904914954370524L; + + @Autowired + private I18N i18n; + + @Autowired + private transient EventBus.SessionEventBus eventBus; + + @Autowired + private transient RolloutGroupManagement rolloutGroupManagement; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + @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) { + if (event == RolloutEvent.SHOW_ROLLOUT_GROUPS) { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + } + + /** + * + * Handles the RolloutGroupChangeEvent to refresh the item in the grid. + * + * + * @param rolloutGroupChangeEvent + * the event which contains the rollout group which has been + * change + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { + if (rolloutUIState.isShowRolloutGroups()) { + final RolloutGroup rolloutGroup = rolloutGroupManagement + .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutGroup.getId()); + if (item != null) { + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setValue(rolloutGroup.getTotalTargetCountStatus()); + } + } + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, + String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, + null, false, false); + + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, + false, false); + + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + } + + @Override + protected void setColumnExpandRatio() { + getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(200); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + + setFrozenColumnCount(7); + } + + @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")); + } + + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; + } + + @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 addColumnRenderes() { + 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 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); + }; + + private void onClickOfRolloutGroupName(RendererClickEvent event) { + rolloutUIState + .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); + } + + private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { + String result = null; + switch (value) { + case FINISHED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.CHECK_CIRCLE.getCodepoint()), SPUIStyleDefinitions.STATUS_ICON_GREEN, + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + case SCHEDULED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.HOURGLASS_1.getCodepoint()), SPUIStyleDefinitions.STATUS_ICON_PENDING, + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + case RUNNING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.ADJUST.getCodepoint()), SPUIStyleDefinitions.STATUS_ICON_YELLOW, + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + case READY: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), + SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE, SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + case ERROR: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()), + SPUIStyleDefinitions.STATUS_ICON_RED, SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + default: + break; + } + return result; + + } + + 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()); + } else { + return null; + } + } + + 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.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 static final long serialVersionUID = -9205943894818450807L; + + @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; + } + } + + /** + * + * 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/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListHeader.java similarity index 96% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListHeader.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListHeader.java index 3c89518e1..45c16eeed 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListHeader.java @@ -6,11 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; +import org.eclipse.hawkbit.ui.common.grid.AbstractGridHeader; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -37,7 +38,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class RolloutGroupsListHeader extends AbstractSimpleTableHeader { +public class RolloutGroupsListHeader extends AbstractGridHeader { private static final long serialVersionUID = 5077741997839715209L; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListView.java similarity index 77% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListView.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListView.java index 0725da6ee..7d7561274 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListView.java @@ -6,10 +6,11 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import javax.annotation.PostConstruct; +import org.eclipse.hawkbit.ui.common.grid.AbstractGridLayout; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -22,7 +23,7 @@ import com.vaadin.ui.Label; */ @SpringComponent @ViewScope -public class RolloutGroupsListView extends AbstractSimpleTableLayout { +public class RolloutGroupsListView extends AbstractGridLayout { private static final long serialVersionUID = 7252345838154270259L; @@ -30,22 +31,20 @@ public class RolloutGroupsListView extends AbstractSimpleTableLayout { private RolloutGroupsListHeader rolloutGroupListHeader; @Autowired - private RolloutGroupListTable rolloutGroupListTable; + private RolloutGroupListGrid rolloutListGrid; @PostConstruct protected void init() { - super.init(rolloutGroupListHeader, rolloutGroupListTable); + super.init(rolloutGroupListHeader, rolloutListGrid); } @Override protected boolean hasCountMessage() { - return false; } @Override protected Label getCountMessageLabel() { - return null; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java similarity index 99% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsBeanQuery.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java index b4d78a4d5..d9c25d943 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rolloutgrouptargets; import java.util.ArrayList; import java.util.List; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsCountLabelMessage.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java similarity index 92% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsCountLabelMessage.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java index 9bc24c251..cc6cec189 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsCountLabelMessage.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rolloutgrouptargets; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -37,16 +37,13 @@ import com.vaadin.ui.Label; @ViewScope public class RolloutGroupTargetsCountLabelMessage extends Label { - /** - * - */ private static final long serialVersionUID = -3876685878918411453L; @Autowired private transient RolloutUIState rolloutUIState; @Autowired - private transient RolloutGroupTargetsListTable rolloutGroupTargetsListTable; + private transient RolloutGroupTargetsListGrid rolloutGroupTargetsListGrid; @Autowired private I18N i18n; @@ -93,7 +90,7 @@ public class RolloutGroupTargetsCountLabelMessage extends Label { } private void displayRolloutGroupTargetMessage() { - long totalTargetTableEnteries = rolloutGroupTargetsListTable.size(); + long totalTargetTableEnteries = rolloutGroupTargetsListGrid.getContainerDataSource().size(); if (rolloutUIState.getRolloutGroupTargetsTruncated() != null) { // set the icon setIcon(FontAwesome.INFO_CIRCLE); @@ -113,7 +110,7 @@ public class RolloutGroupTargetsCountLabelMessage extends Label { message.append(SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES); } else { message.append(i18n.get("label.filter.shown")); - message.append(rolloutGroupTargetsListTable.size()); + message.append(rolloutGroupTargetsListGrid.getContainerDataSource().size()); } message.append(HawkbitCommonUtil.SP_STRING_SPACE); setCaption(message.toString()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java new file mode 100644 index 000000000..bc76ef42b --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java @@ -0,0 +1,309 @@ +/** + * 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.rollout.rolloutgrouptargets; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; +import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; +import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; +import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; +import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; +import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; +import org.vaadin.spring.events.EventBus; +import org.vaadin.spring.events.EventScope; +import org.vaadin.spring.events.annotation.EventBusListenerMethod; + +import com.vaadin.data.Container; +import com.vaadin.data.util.converter.Converter; +import com.vaadin.server.FontAwesome; +import com.vaadin.spring.annotation.SpringComponent; +import com.vaadin.spring.annotation.ViewScope; + +@SpringComponent +@ViewScope +public class RolloutGroupTargetsListGrid extends AbstractGrid { + + private static final long serialVersionUID = -2244756637458984597L; + + @Autowired + private I18N i18n; + + @Autowired + private transient EventBus.SessionEventBus eventBus; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @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) { + if (event == RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS) { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS_COUNT); + } + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutgrouBeanQueryFactory = new BeanQueryFactory<>( + RolloutGroupTargetsBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), + rolloutgrouBeanQueryFactory); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGroupTargetGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, + true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, Status.class, + Status.RETRIEVED, false, false); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_BY, String.class, null, + false, true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, + null, false, true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, + false, true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, + null, false, true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, + true); + } + + @Override + protected void setColumnExpandRatio() { + getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(20); + getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(280); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(50); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(80); + + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setMaximumWidth(180); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setMinimumWidth(30); + + getColumn(SPUILabelDefinitions.VAR_CREATED_BY).setMaximumWidth(180); + getColumn(SPUILabelDefinitions.VAR_CREATED_BY).setMinimumWidth(50); + + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE).setMaximumWidth(180); + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE).setMinimumWidth(30); + + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setMaximumWidth(180); + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setMinimumWidth(50); + + setFrozenColumnCount(getColumns().size()); + + } + + @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_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_BY).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + } + + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_GROUP_TARGETS_LIST_GRID_ID; + } + + @Override + protected void setColumnProperties() { + List columnList = new ArrayList<>(); + columnList.add(SPUILabelDefinitions.VAR_NAME); + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_BY); + columnList.add(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + @Override + protected void addColumnRenderes() { + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new StatusConverter()); + } + + @Override + protected void setHiddenColumns() { + /** + * No hidden columns. + */ + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + }; + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + /** + * + * Converts {@link Status} into string with status icon details. + * + */ + private class StatusConverter implements Converter { + private static final long serialVersionUID = -7467206089699548808L; + + @Override + public Status convertToModel(final String value, final Class targetType, + final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final Status status, final Class targetType, + final Locale locale) { + if (status == null) { + // Actions are not created for targets when + // rollout's status + // is READY and when duplicate assignment is done. + // In these cases display a appropriate status with + // description + return getStatus(); + } else { + return processActionStatus(status); + } + } + + @Override + public Class getModelType() { + return Status.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } + + private String processActionStatus(final Status status) { + String result = null; + switch (status) { + case FINISHED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.CHECK_CIRCLE.getCodepoint()), "statusIconGreen", null); + break; + case SCHEDULED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.HOURGLASS_1.getCodepoint()), "statusIconPending", null); + break; + case RUNNING: + case RETRIEVED: + case WARNING: + case DOWNLOAD: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.ADJUST.getCodepoint()), "statusIconYellow", null); + break; + case CANCELING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.TIMES_CIRCLE.getCodepoint()), "statusIconPending", null); + break; + case CANCELED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.TIMES_CIRCLE.getCodepoint()), "statusIconGreen", null); + break; + case ERROR: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()), "statusIconRed", null); + break; + default: + break; + } + return result; + } + + private String getStatus() { + final RolloutGroup rolloutGroup = rolloutUIState.getRolloutGroup().isPresent() + ? rolloutUIState.getRolloutGroup().get() : null; + if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), "statusIconLightBlue", null); + } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.MINUS_CIRCLE.getCodepoint()), "statusIconBlue", null); + } else { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.QUESTION_CIRCLE.getCodepoint()), "statusIconBlue", null); + } + } + + private String getDescription(CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + if (null != cell.getProperty().getValue()) { + return cell.getProperty().getValue().toString().toLowerCase(); + + } else { + return getDescriptionWhenNoAction(); + } + } + return null; + } + + private String getDescriptionWhenNoAction() { + final RolloutGroup rolloutGroup = rolloutUIState.getRolloutGroup().isPresent() + ? rolloutUIState.getRolloutGroup().get() : null; + if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { + return RolloutGroupStatus.READY.toString().toLowerCase(); + } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { + String ds = rolloutUIState.getRolloutDistributionSet().isPresent() + ? rolloutUIState.getRolloutDistributionSet().get() : ""; + return i18n.get("message.dist.already.assigned", new Object[] { ds }); + } else { + return "unknown"; + } + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListHeader.java similarity index 96% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListHeader.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListHeader.java index 19a504384..a60b6c9e6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListHeader.java @@ -6,12 +6,13 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rolloutgrouptargets; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.ui.common.grid.AbstractGridHeader; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -38,7 +39,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class RolloutGroupTargetsListHeader extends AbstractSimpleTableHeader { +public class RolloutGroupTargetsListHeader extends AbstractGridHeader { private static final long serialVersionUID = 5613986489156507581L; @Autowired diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListView.java similarity index 79% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListView.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListView.java index 40b8f6eb7..672da2f29 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListView.java @@ -6,10 +6,11 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.ui.rollout; +package org.eclipse.hawkbit.ui.rollout.rolloutgrouptargets; import javax.annotation.PostConstruct; +import org.eclipse.hawkbit.ui.common.grid.AbstractGridLayout; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -21,7 +22,7 @@ import com.vaadin.ui.Label; */ @SpringComponent @ViewScope -public class RolloutGroupTargetsListView extends AbstractSimpleTableLayout { +public class RolloutGroupTargetsListView extends AbstractGridLayout { private static final long serialVersionUID = 26089134783467012L; @@ -29,28 +30,28 @@ public class RolloutGroupTargetsListView extends AbstractSimpleTableLayout { private RolloutGroupTargetsListHeader rolloutGroupTargetsListHeader; @Autowired - private RolloutGroupTargetsListTable rolloutGroupTargetsListTable; + private RolloutGroupTargetsCountLabelMessage rolloutGroupTargetsCountLabelMessage; @Autowired - private RolloutGroupTargetsCountLabelMessage rolloutGroupTargetsCountLabelMessage; + private RolloutGroupTargetsListGrid rolloutListGrid; /** * Initialization of Rollout group component. */ @PostConstruct protected void init() { - super.init(rolloutGroupTargetsListHeader, rolloutGroupTargetsListTable); + super.init(rolloutGroupTargetsListHeader, rolloutListGrid); } @Override protected boolean hasCountMessage() { - + return true; } - + @Override protected Label getCountMessageLabel() { - + return rolloutGroupTargetsCountLabelMessage; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/state/RolloutUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/state/RolloutUIState.java index 8dc5b1e17..0647e01bb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/state/RolloutUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/state/RolloutUIState.java @@ -44,6 +44,8 @@ public class RolloutUIState implements Serializable { private long rolloutGroupTargetsTotalCount; + private String rolloutDistributionSet; + /** * @return the searchText */ @@ -178,4 +180,20 @@ public class RolloutUIState implements Serializable { public void setRolloutGroupTargetsTotalCount(final long rolloutGroupTargetsTotalCount) { this.rolloutGroupTargetsTotalCount = rolloutGroupTargetsTotalCount; } + + /** + * @return rolloutDistributionSet + */ + public Optional getRolloutDistributionSet() { + return rolloutDistributionSet == null ? Optional.empty() : Optional.of(rolloutDistributionSet); + } + + /** + * + * @param rolloutDistributionSet + * the distribution set of the rollout + */ + public void setRolloutDistributionSet(String rolloutDistributionSet) { + this.rolloutDistributionSet = rolloutDistributionSet; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 47336dd34..e9e287fe3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.TimeZone; @@ -33,6 +34,7 @@ import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; import org.eclipse.hawkbit.ui.management.dstable.DistributionTable; import org.eclipse.hawkbit.ui.management.targettable.TargetTable; import org.slf4j.Logger; @@ -46,6 +48,7 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; import org.vaadin.alump.distributionbar.DistributionBar; +import com.google.common.base.Strings; import com.vaadin.data.Container; import com.vaadin.data.Item; import com.vaadin.server.Sizeable.Unit; @@ -1348,4 +1351,48 @@ public final class HawkbitCommonUtil { private static Long getStatusCount(final String propertName, final Item item) { return (Long) item.getItemProperty(propertName).getValue(); } + + /** + * Get the formatted string of status and target count details. + * + * @param details + * details of status and count + * @return String + */ + public static String getFormattedString(Map details) { + StringBuilder val = new StringBuilder(); + String finalVal = null; + if (null != details && !details.isEmpty()) { + for (Entry entry : details.entrySet()) { + val.append(entry.getKey()).append(":").append(entry.getValue()).append(","); + } + finalVal = val.substring(0, val.length() - 1); + } + return finalVal; + } + + /** + * Returns a formatted string as needed by label custom render .This string + * holds the properties of a status label. + * + * @param value + * label value + * @param style + * label style + * @param id + * label id + * @return + */ + public static String getStatusLabelDetailsInString(String value, String style, String id) { + StringBuilder val = new StringBuilder(); + if (!Strings.isNullOrEmpty(value)) { + val.append("value:").append(value).append(","); + } + if (!Strings.isNullOrEmpty(style)) { + val.append("style:").append(style).append(","); + } + val.append("id:").append(id); + return val.toString(); + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java index 56e76c123..c599ef0d0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java @@ -738,19 +738,19 @@ public final class SPUIComponetIdProvider { public static final String ROLLOUT_ADD_ICON_ID = "rollout.add.button.id"; /** - * Rollout list table id. + * Rollout list grid id. */ - public static final String ROLLOUT_LIST_TABLE_ID = "rollout.table.id"; + public static final String ROLLOUT_LIST_GRID_ID = "rollout.grid.id"; /** - * Rollout group list table id. + * Rollout group list grid id. */ - public static final String ROLLOUT_GROUP_LIST_TABLE_ID = "rollout.group.table.id"; + public static final String ROLLOUT_GROUP_LIST_GRID_ID = "rollout.group.grid.id"; /** - * Rollout group list table id. + * Rollout group list grid id. */ - public static final String ROLLOUT_GROUP_TARGETS_LIST_TABLE_ID = "rollout.group.targets.table.id"; + public static final String ROLLOUT_GROUP_TARGETS_LIST_GRID_ID = "rollout.group.targets.grid.id"; /** * Rollout delete button id. @@ -827,6 +827,11 @@ public final class SPUIComponetIdProvider { * Rollout status label id. */ public static final String ROLLOUT_STATUS_LABEL_ID = "rollout.status.id"; + + /** + * Rollout group status label id. + */ + public static final String ROLLOUT_GROUP_STATUS_LABEL_ID = "rollout.group.status.id"; /** * Rollout % or count option group id. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java index 1d3e97168..b29283ef8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java @@ -1001,20 +1001,6 @@ public final class SPUIDefinitions { */ public static final String ROLLOUT_GROUP_STARTED_DATE = "Started date"; - /** - * Rollout group started date column property. - */ - public static final String ROLLOUT_GROUP_ERROR_THRESHOLD = "errorConditionExp"; - - /** - * Rollout group started date column property. - */ - public static final String ROLLOUT_GROUP_THRESHOLD = "successConditionExp"; - - /** - * Rollout group installed percentage column property. - */ - public static final String ROLLOUT_GROUP_INSTALLED_PERCENTAGE = "finishedPercentage"; /** * Rollout group status column property. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java index f5848e650..937a53adc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java @@ -539,6 +539,27 @@ public final class SPUILabelDefinitions { * Total target coulmn property name. */ public static final String VAR_TOTAL_TARGETS = "totalTargetsCount"; + + + /** + * Total target count status coulmn property name. + */ + public static final String VAR_TOTAL_TARGETS_COUNT_STATUS = "totalTargetCountStatus"; + + /** + * Rollout group started date column property. + */ + public static final String ROLLOUT_GROUP_ERROR_THRESHOLD = "errorConditionExp"; + + /** + * Rollout group started date column property. + */ + public static final String ROLLOUT_GROUP_THRESHOLD = "successConditionExp"; + + /** + * Rollout group installed percentage column property. + */ + public static final String ROLLOUT_GROUP_INSTALLED_PERCENTAGE = "finishedPercentage"; /** * Constructor. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java index 0c12df4bd..c50135251 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java @@ -249,6 +249,51 @@ public final class SPUIStyleDefinitions { */ public static final String TARGET_FILTER_SEARCH_PROGRESS_INDICATOR_STYLE = "target-filter-spinner"; + /** + * Status icon style - red color. + */ + public static final String STATUS_ICON_RED = "statusIconRed"; + + /** + * Status icon style - green color. + */ + public static final String STATUS_ICON_GREEN = "statusIconGreen"; + + /** + * Status icon style - blue color. + */ + public static final String STATUS_ICON_BLUE = "statusIconBlue"; + + /** + * Status icon spinner style - yellow color. + */ + public static final String STATUS_SPINNER_YELLOW = "yellowSpinner"; + + /** + * Status icon style - light blue color. + */ + public static final String STATUS_ICON_LIGHT_BLUE = "statusIconLightBlue"; + + /** + * Status icon spinner style - grey color. + */ + public static final String STATUS_SPINNER_GREY = "greySpinner"; + + /** + * Status icon spinner style - blue color. + */ + public static final String STATUS_SPINNER_BLUE = "blueSpinner"; + + /** + * Status icon style - yellow color. + */ + public static final String STATUS_ICON_YELLOW = "statusIconYellow"; + + /** + * Status pending icon. + */ + public static final String STATUS_ICON_PENDING = "statusIconPending"; + /** * Constructor. */ diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss index 1a5fedba4..87ea5b0b9 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss @@ -276,4 +276,10 @@ .links { padding-left: 22px; } + + .font-icon{ + font-family:FontAwesome; + font-style:normal; + font-weight:normal; + } } 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 1c7714061..712e04ec1 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 @@ -56,5 +56,26 @@ } } + .v-grid-cell.centeralign { + text-align: center; + } + + .v-grid-cell { + font-size: $v-font-size--small !important; + height: 34px !important; + } + + .v-grid-row{ + height: 34px !important; + } + + .v-grid-cell.frozen{ + box-shadow: none !important; + } + + .v-grid-cell.frozen + th{ + border-left: $v-grid-border-size solid $widget-border-color ; + } + } \ No newline at end of file diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/statusprogressbar.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/statusprogressbar.scss index 867fa0151..423ef9084 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/statusprogressbar.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/statusprogressbar.scss @@ -50,15 +50,4 @@ } - &.alump-dbar-tooltip { - background-color: rgba(27, 54, 73, 0.9); - border-radius: 3px; - color: white; - z-index: 100; - padding: 3px; - font-size: 10px; - box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2); - -moz-box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2); - -webkit-box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2); - } } \ No newline at end of file diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/hawkbittheme.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/hawkbittheme.scss index 1c2235e5b..a344cb5ae 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/hawkbittheme.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/hawkbittheme.scss @@ -30,7 +30,13 @@ $v-selection-color: $app-selection-color; $v-app-background-color: $app-background-color; //Table header,body border colors are calculated based on this -$v-table-border-color: $widget-border-color; +$v-table-border-color: $widget-border-color ; + +$v-grid-border:$v-grid-border-size solid $widget-border-color ; +$v-grid-cell-vertical-border: 0px ; +$v-grid-cell-horizontal-border: 0px ; +$v-grid-cell-focused-border: 0px ; +$v-grid-cell-padding-horizontal:6px; @import '../valo/valo'; @import 'customstyles/table'; diff --git a/pom.xml b/pom.xml index fffce192a..2415b9935 100644 --- a/pom.xml +++ b/pom.xml @@ -382,6 +382,11 @@ vaadin-push ${vaadin.version} + + com.vaadin + vaadin-client + ${vaadin.version} + com.vaadin vaadin-themes