custom renderer
Signed-off-by: asharani-murugesh <asharani.murugesh@in.bosch.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<module>
|
||||
|
||||
<!-- Inherit DefaultWidgetSet -->
|
||||
<inherits name="com.vaadin.DefaultWidgetSet"/>
|
||||
|
||||
<inherits name="org.vaadin.alump.distributionbar.gwt.DistributionBarWidgetset" />
|
||||
|
||||
<inherits name="org.eclipse.hawkbit.ui.AppWidgetSet" />
|
||||
|
||||
<inherits name="org.vaadin.peter.contextmenu.ContextmenuWidgetset" />
|
||||
|
||||
<inherits name="org.vaadin.tokenfield.TokenfieldWidgetset" />
|
||||
|
||||
<inherits name="org.vaadin.hene.flexibleoptiongroup.widgetset.FlexibleOptionGroupWidgetset" />
|
||||
|
||||
<inherits name="org.eclipse.hawkbit.ui.distributionbar2.CustomRenderersWidgetSet" />
|
||||
</module>
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.eclipse.hawkbit.ui.distributionbar.client;
|
||||
|
||||
|
||||
import com.vaadin.client.connectors.AbstractRendererConnector;
|
||||
import com.vaadin.shared.ui.Connect;
|
||||
|
||||
@Connect(org.eclipse.hawkbit.ui.distributionbar.renderers.StringDistributionBarRenderer.class)
|
||||
public class StringDistributionBarRendererConnector extends
|
||||
AbstractRendererConnector<String> {
|
||||
|
||||
private static final long serialVersionUID = 7697966991925490786L;
|
||||
|
||||
@Override
|
||||
public org.eclipse.hawkbit.ui.distributionbar.client.renderers.StringDistributionBarRenderer getRenderer() {
|
||||
return (org.eclipse.hawkbit.ui.distributionbar.client.renderers.StringDistributionBarRenderer) super.getRenderer();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.eclipse.hawkbit.ui.distributionbar.client.renderers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.vaadin.alump.distributionbar.gwt.client.GwtDistributionBar;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.vaadin.client.renderers.WidgetRenderer;
|
||||
import com.vaadin.client.widget.grid.RendererCellReference;
|
||||
|
||||
public class StringDistributionBarRenderer extends WidgetRenderer<String, GwtDistributionBar> {
|
||||
|
||||
@Override
|
||||
public GwtDistributionBar createWidget() {
|
||||
return GWT.create(GwtDistributionBar.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RendererCellReference cell, String input, GwtDistributionBar widget) {
|
||||
if (null != input) {
|
||||
widget.setNumberOfParts(2);
|
||||
Map<String, Long> map = formatData(input);
|
||||
if (!map.isEmpty()) {
|
||||
final Long notStartedTargetsCount = map.keySet().contains("NOTSTARTED") ? map.get("NOTSTARTED") : 0L;
|
||||
final Long runningTargetsCount = map.keySet().contains("RUNNING") ? map.get("RUNNING") : 0L;
|
||||
final Long scheduledTargetsCount = map.keySet().contains("SCHEDULED") ? map.get("SCHEDULED") : 0L;
|
||||
final Long errorTargetsCount = map.keySet().contains("ERROR") ? map.get("ERROR") : 0L;
|
||||
final Long finishedTargetsCount = map.keySet().contains("FINISHED") ? map.get("FINISHED") : 0L;
|
||||
final Long cancelledTargetsCount = map.keySet().contains("CANCELLED") ? map.get("CANCELLED") : 0L;
|
||||
if (isNoTargets(errorTargetsCount, notStartedTargetsCount, runningTargetsCount, scheduledTargetsCount,
|
||||
finishedTargetsCount, cancelledTargetsCount)) {
|
||||
setBarPartSize(widget, "SCHEDULED".toLowerCase(), 0, 0);
|
||||
setBarPartSize(widget, "FINISHED".toString().toLowerCase(), 0, 1);
|
||||
|
||||
} else {
|
||||
widget.setNumberOfParts(6);
|
||||
setBarPartSize(widget, "NOTSTARTED".toString().toLowerCase(), notStartedTargetsCount.intValue(), 0);
|
||||
setBarPartSize(widget, "SCHEDULED".toString().toLowerCase(), scheduledTargetsCount.intValue(), 1);
|
||||
setBarPartSize(widget, "RUNNING".toLowerCase(), scheduledTargetsCount.intValue(), 2);
|
||||
setBarPartSize(widget, "ERROR".toLowerCase(), errorTargetsCount.intValue(), 3);
|
||||
setBarPartSize(widget, "FINISHED".toLowerCase(), finishedTargetsCount.intValue(), 4);
|
||||
setBarPartSize(widget, "CANCELLED".toLowerCase(), cancelledTargetsCount.intValue(), 5);
|
||||
}
|
||||
}
|
||||
widget.updateParts();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Long> formatData(String input) {
|
||||
Map<String, Long> details = new HashMap<>();
|
||||
String[] tempData = input.split(",");
|
||||
for (String statusWithCount : tempData) {
|
||||
String[] statusWithCountList = statusWithCount.split(":");
|
||||
details.put(statusWithCountList[0], new Long(statusWithCountList[1]));
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
private static boolean isNoTargets(Long errorTargetsCount, Long notStartedTargetsCount, Long runningTargetsCount,
|
||||
Long scheduledTargetsCount, Long finishedTargetsCount, Long cancelledTargetsCount) {
|
||||
if (errorTargetsCount == 0 && notStartedTargetsCount == 0 && runningTargetsCount == 0
|
||||
&& scheduledTargetsCount == 0 && finishedTargetsCount == 0 && cancelledTargetsCount == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setBarPartSize(final GwtDistributionBar bar, final String statusName, final int count,
|
||||
final int index) {
|
||||
bar.setPartSize(index, count);
|
||||
bar.setPartTooltip(index, statusName);
|
||||
// check thi:::
|
||||
bar.setPartStyleName(index, index, "status-bar-part-" + statusName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.eclipse.hawkbit.ui.distributionbar.renderers;
|
||||
|
||||
|
||||
import com.vaadin.ui.Grid.AbstractRenderer;
|
||||
|
||||
public class StringDistributionBarRenderer extends AbstractRenderer<String> {
|
||||
private static final long serialVersionUID = -4543220859821576209L;
|
||||
|
||||
/**
|
||||
* Creates a new text renderer
|
||||
*/
|
||||
public StringDistributionBarRenderer() {
|
||||
super(String.class, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user