Skip to content

Commit

Permalink
Allow changing the progress state from plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendel committed Oct 20, 2015
1 parent 2dec572 commit 918c1c6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
31 changes: 28 additions & 3 deletions BimServer/src/org/bimserver/servlets/DownloadServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,42 @@ public void service(HttpServletRequest request, HttpServletResponse response) th
final ProgressTopic progressTopic = getBimServer().getNotificationsManager().getProgressTopic(topicId);

ProgressReporter progressReporter = new ProgressReporter() {
private long lastMax;
private long lastProgress;
private int stage = 3;
private Date start = new Date();
private String title = "Downloading...";

@Override
public void update(long progress, long max) {
if (progressTopic != null) {
LongActionState ds = StoreFactory.eINSTANCE.createLongActionState();
ds.setStart(new Date());
ds.setStart(start);
ds.setState(progress == max ? ActionState.FINISHED : ActionState.STARTED);
ds.setTitle("Downloading...");
ds.setStage(3);
ds.setTitle(title);
ds.setStage(stage);
ds.setProgress((int) Math.round(100.0 * progress / max));

progressTopic.stageProgressUpdate(ds);

this.lastMax = max;
this.lastProgress = progress;
}
}

@Override
public void setTitle(String title) {
if (progressTopic != null) {
stage++;
this.title = title;
LongActionState ds = StoreFactory.eINSTANCE.createLongActionState();
ds.setStart(new Date());
ds.setState(lastProgress == lastMax ? ActionState.FINISHED : ActionState.STARTED);
ds.setTitle(title);
ds.setStage(stage);
ds.setProgress((int) Math.round(100.0 * lastProgress / lastMax));

progressTopic.stageProgressUpdate(ds);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
*****************************************************************************/

public interface ProgressReporter {
void update(long progress, long max);
}
void update(long progress, long max);
void setTitle(String stage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@ public void update(long progress, long max) {
} else {
progressReporter.update((long) (totalPerc * 1000), 1000);
}
}

@Override
public void setTitle(String stage) {
// TODO Auto-generated method stub

}
}

0 comments on commit 918c1c6

Please sign in to comment.