Saturday, November 24, 2012

ADF : How to Implement Process Indicator ?

ADF : How to Implement Process Indicator ?














public class ProgressIndicatorBean {
    SimpleBoundedRangeModel _simpleBoundedRangeModel;
    private long pollInterval = -1;

    public ProgressIndicatorBean() {
    }

    public SimpleBoundedRangeModel getSimpleBoundedRangeModel() {
        if (_simpleBoundedRangeModel == null)
            _simpleBoundedRangeModel = new SimpleBoundedRangeModel();
        return _simpleBoundedRangeModel;
    }


    public void pollMe(PollEvent pollEvent) {
        if (_simpleBoundedRangeModel != null) {
            BindingContext bcntxt = BindingContext.getCurrent();
            BindingContainer bc = bcntxt.getCurrentBindingsEntry();
            OperationBinding op = bc.getOperationBinding("incrementCount");
            op.getParamsMap().put("input",
                                  _simpleBoundedRangeModel.getValue());
            op.execute();
            long value = (Long)op.getResult();
            if (value <= _simpleBoundedRangeModel.getMaximum()) {
                _simpleBoundedRangeModel.setValue(value);
            } else {
                pollInterval = -1;
                AdfFacesContextImpl.getCurrentInstance().addPartialTarget(pollEvent.getComponent());
            }

        }

    }

    public void setPollInterval(long pollInterval) {
        this.pollInterval = pollInterval;
    }

    public long getPollInterval() {
        return pollInterval;
    }

    public void startAction(ActionEvent actionEvent) {
        pollInterval = 200;
        _simpleBoundedRangeModel.start(actionEvent);
    }

    public void cancelAction(ActionEvent actionEvent) {
        pollInterval = -1;
        _simpleBoundedRangeModel.cancelProcess(actionEvent);
    }
}

---------------------------------------------------------------

public class SimpleBoundedRangeModel extends DefaultBoundedRangeModel {
    public SimpleBoundedRangeModel() {
        super(0, 100);
    }

    public void start(ActionEvent event) {
      setValue(1);
    }

    public void cancelProcess(ActionEvent event) {

        setValue(0);
        setMaximum(100);
    }


}