UINode node
)
{
int percentComplete = -1;
UIXProgress progressComponent =
(UIXProgress) NodeUtils.getUIComponent(context, node);
Object modelObject = progressComponent.getValue();
if (modelObject != null && modelObject instanceof BoundedRangeModel)
{
BoundedRangeModel model= (BoundedRangeModel) modelObject;
//pu: Though these are 'long' types, deal with it as double, so as to
// correctly compute percent for values towards the maximum of 'long'.
double value = model.getValue();
double maximum = model.getMaximum();
if (value < 0 || maximum < 0)
{
percentComplete = PERCENT_UNKNOWN;
}
else
{
//pu: Loss due to truncation is not a concern here.
percentComplete = (int)((value/maximum) * 100);
}
}
else
{
_LOG.warning("Invalid value. Defaulting component with id '" +
progressComponent.getId() +
"' to indeterminate mode");
//Just get this to indeterminate state indefinitely on this condition.
percentComplete = PERCENT_UNKNOWN;
}