comparison src/org/tmatesoft/hg/internal/IterateControlMediator.java @ 312:f9f3e9b67ccc

Facilitate cancellation and progress reporting in changelog and manifest iterations
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 27 Sep 2011 05:29:12 +0200
parents
children 1ee452f31187
comparison
equal deleted inserted replaced
311:b9592e21176a 312:f9f3e9b67ccc
1 /*
2 * Copyright (c) 2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.internal;
18
19 import org.tmatesoft.hg.internal.Lifecycle.Callback;
20 import org.tmatesoft.hg.util.CancelSupport;
21 import org.tmatesoft.hg.util.CancelledException;
22
23 /**
24 *
25 * @author Artem Tikhomirov
26 * @author TMate Software Ltd.
27 */
28 public class IterateControlMediator {
29
30 private final CancelSupport src;
31 private Callback receiver;
32
33 public IterateControlMediator(CancelSupport source, Lifecycle.Callback target) {
34 assert target != null;
35 src = source;
36 receiver = target;
37 }
38
39 public boolean checkCancelled() {
40 if (src == null) {
41 return false;
42 }
43 try {
44 src.checkCancelled();
45 return false;
46 } catch (CancelledException ex) {
47 receiver.stop();
48 return true;
49 }
50 }
51
52 public void stop() {
53 receiver.stop();
54 }
55 }