Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/LifecycleBridge.java @ 520:1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 21 Dec 2012 21:20:26 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
519:934037edbea0 | 520:1ee452f31187 |
---|---|
1 /* | |
2 * Copyright (c) 2012 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.util.CancelSupport; | |
20 import org.tmatesoft.hg.util.CancelledException; | |
21 import org.tmatesoft.hg.util.ProgressSupport; | |
22 | |
23 /** | |
24 * Bridge low-level life-cycle ({@link Lifecycle}) API with high-level one ({@link ProgressSupport} and {@link CancelSupport}). | |
25 * | |
26 * @author Artem Tikhomirov | |
27 * @author TMate Software Ltd. | |
28 */ | |
29 public class LifecycleBridge implements Lifecycle { | |
30 private final ProgressSupport progressHelper; | |
31 private final CancelSupport cancelSupport; | |
32 // may be null unless #start() is invoked | |
33 private Callback receiver; | |
34 private CancelledException cancellation; | |
35 | |
36 | |
37 public LifecycleBridge(ProgressSupport progress, CancelSupport cancel) { | |
38 progressHelper = progress; | |
39 cancelSupport = cancel; | |
40 } | |
41 | |
42 public void start(int count, Callback callback, Object token) { | |
43 receiver = callback; | |
44 if (progressHelper != null) { | |
45 progressHelper.start(count); | |
46 } | |
47 } | |
48 | |
49 public void finish(Object token) { | |
50 if (progressHelper != null) { | |
51 progressHelper.done(); | |
52 } | |
53 receiver = null; | |
54 } | |
55 | |
56 // XXX SHALL work without start/finish sequence because | |
57 // HgLogCommand invokes ChangesetTransformer#next directly (i.e. not from | |
58 // inside a library's #range() or similar) to process changesets in unnatural order. | |
59 public void nextStep() { | |
60 if (progressHelper != null) { | |
61 progressHelper.worked(1); | |
62 } | |
63 if (cancelSupport == null) { | |
64 return; | |
65 } | |
66 try { | |
67 cancelSupport.checkCancelled(); | |
68 } catch (CancelledException ex) { | |
69 if (receiver != null) { | |
70 receiver.stop(); | |
71 } | |
72 cancellation = ex; | |
73 } | |
74 } | |
75 | |
76 public void stop() { | |
77 if (receiver != null) { | |
78 receiver.stop(); | |
79 } | |
80 } | |
81 | |
82 /** | |
83 * @return <code>true</code> iff {@link CancelledException} was thrown and catched. Forced stop doesn't count | |
84 */ | |
85 public boolean isCancelled() { | |
86 return cancellation != null; | |
87 } | |
88 | |
89 public CancelledException getCancelOrigin() { | |
90 return cancellation; | |
91 } | |
92 } |