bug4210 Refactored and renamed custom progress bar implementation, added

JavaDoc
This commit is contained in:
Benjamin Barth committed 2017-11-10 15:21:47 +01:00
1 parent e71fe46016
commit bc6b7e71e4
3 files changed
+106 -35

No files matched your search

@@ -0,0 +1,98 @@
package com.sap.sailing.gwt.ui.adminconsole;
import java.util.Objects;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Widget;
/**
* Custom widget implementation wrapping an HTML <code>progress</code> tag, providing static factory methods for
* {@link CustomProgressBar#determinate() determinate} and {@link CustomProgressBar#indeterminate() indeterminate}
* instances as well as getter and setter methods for the {@code max} and {@code value} attributes.
*/
public class CustomProgressBar extends Widget {
private static final String TAG = "progress", ATTR_MAX = "max", ATTR_VALUE = "value";
/**
* Creates a new {@link CustomProgressBar} instance in indeterminate state.
*
* @return the created {@link CustomProgressBar} instance
*/
public static CustomProgressBar indeterminate() {
return new CustomProgressBar();
}
/**
* Creates a new {@link CustomProgressBar} instance in determinate state with default {@code max} attribute.
*
* @return the created {@link CustomProgressBar} instance
*/
public static CustomProgressBar determinate() {
final CustomProgressBar progressBar = indeterminate();
progressBar.setValue(0.0d);
return progressBar;
}
/**
* Creates a new {@link CustomProgressBar} instance in determinate state with the provided {@code max} attribute.
*
* @param max
* numeric value for {@code max} attribute
* @return the created {@link CustomProgressBar} instance
*
* @see CustomProgressBar#determinate()
*/
public static CustomProgressBar determinate(double max) {
final CustomProgressBar progressBar = determinate();
progressBar.setMax(max);
return progressBar;
}
private CustomProgressBar() {
setElement(Document.get().createElement(TAG));
getElement().getStyle().setWidth(100, Unit.PCT);
getElement().getStyle().setHeight(2, Unit.EM);
}
/**
* @return numeric value of the {@link CustomProgressBar}'s {@code max} attribute
*/
public final double getMax() {
return this.getDoubleAttribute(ATTR_MAX);
}
/**
* @param max
* numeric value for the {@link CustomProgressBar}'s {@code max} attribute
*/
public final void setMax(double max) {
this.setDoubleAtrribute(ATTR_MAX, max);
}
/**
* @return numeric value of the {@link CustomProgressBar}'s {@code value} attribute
*/
public final double getValue() {
return this.getDoubleAttribute(ATTR_VALUE);
}
/**
* @param max
* numeric value for the {@link CustomProgressBar}'s {@code value} attribute
*/
public final void setValue(double value) {
this.setDoubleAtrribute(ATTR_VALUE, value);
}
private double getDoubleAttribute(String attrName) {
final String attrValue = getElement().getAttribute(attrName);
return (Objects.isNull(attrValue) || attrValue.isEmpty()) ? null : Double.parseDouble(attrValue);
}
private void setDoubleAtrribute(String attrName, double attrValue) {
getElement().setAttribute(attrName, Double.toString(attrValue));
}
}
@@ -1,22 +0,0 @@
package com.sap.sailing.gwt.ui.adminconsole;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Widget;
public class HTML5ProgressBar extends Widget {
private Element progress;
public HTML5ProgressBar() {
progress = DOM.createElement("progress");
progress.getStyle().setWidth(100, Unit.PCT);
progress.getStyle().setHeight(2, Unit.EM);
setElement(progress);
setPercent(0);
}
public void setPercent(int percent) {
progress.setAttribute("value", Double.toString(percent/100f));
}
}
@@ -20,6 +20,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.ScrollPanel;
@@ -27,7 +28,7 @@ import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sap.sailing.domain.common.DataImportProgress;
import com.sap.sailing.domain.common.MasterDataImportObjectCreationCount;
import com.sap.sailing.gwt.ui.adminconsole.HTML5ProgressBar;
import com.sap.sailing.gwt.ui.adminconsole.CustomProgressBar;
import com.sap.sailing.gwt.ui.client.EventsRefresher;
import com.sap.sailing.gwt.ui.client.LeaderboardGroupsRefresher;
import com.sap.sailing.gwt.ui.client.LeaderboardsRefresher;
@@ -124,12 +125,12 @@ public class MasterDataImportPanel extends VerticalPanel {
String[] groupNames = createLeaderBoardGroupNamesFromListBox();
final Label overallName = new Label(stringMessages.overallProgress() + ":");
this.add(overallName);
final HTML5ProgressBar overallProgressBar = new HTML5ProgressBar();
final CustomProgressBar overallProgressBar = CustomProgressBar.determinate();
overallProgressBar.ensureDebugId("overallProgressBar");
this.add(overallProgressBar);
final Label subProgressName = new Label();
this.add(subProgressName);
final HTML5ProgressBar subProgressBar = new HTML5ProgressBar();
final CustomProgressBar subProgressBar = CustomProgressBar.determinate();
this.add(subProgressBar);
if (groupNames.length >= 1) {
disableAllButtons();
@@ -182,12 +183,10 @@ public class MasterDataImportPanel extends VerticalPanel {
subProgressName, subProgressBar);
showCreationMessage(creationCount);
} else {
overallProgressBar.setPercent((int) (result
.getOverallProgressPct() * 100));
overallProgressBar.setValue(result.getOverallProgressPct());
subProgressName.setText(result.getCurrentSubProgress()
.getMessage(stringMessages));
subProgressBar.setPercent((int) (result
.getCurrentSubProgressPct() * 100));
subProgressBar.setValue(result.getCurrentSubProgressPct());
}
}
}
@@ -414,12 +413,8 @@ public class MasterDataImportPanel extends VerticalPanel {
changeButtonStateAccordingToApplicationState();
}
private void deleteProgressIndication(final Label overallName, final HTML5ProgressBar overallProgressBar,
final Label subProgressName, final HTML5ProgressBar subProgressBar) {
this.remove(overallProgressBar);
this.remove(subProgressBar);
this.remove(subProgressName);
this.remove(overallName);
private void deleteProgressIndication(IsWidget... widgetsToRemove) {
Arrays.asList(widgetsToRemove).forEach(this::remove);
}
}