Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgAbstractCommand.java @ 215:41a778e3fd31
Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 17 May 2011 00:56:54 +0200 |
parents | |
children | d68dcb3b5f49 |
comparison
equal
deleted
inserted
replaced
214:4252faa556cd | 215:41a778e3fd31 |
---|---|
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.core; | |
18 | |
19 import org.tmatesoft.hg.util.CancelSupport; | |
20 import org.tmatesoft.hg.util.ProgressSupport; | |
21 | |
22 /** | |
23 * intentionally package-local, might be removed or refactored in future | |
24 * | |
25 * @author Artem Tikhomirov | |
26 * @author TMate Software Ltd. | |
27 */ | |
28 class HgAbstractCommand<T extends HgAbstractCommand<?>> implements ProgressSupport.Target<T>, CancelSupport.Target<T> { | |
29 private ProgressSupport progressHelper; | |
30 private CancelSupport cancelHelper; | |
31 | |
32 @SuppressWarnings("unchecked") | |
33 public T set(ProgressSupport ps) { | |
34 progressHelper = ps; | |
35 return (T) this; | |
36 } | |
37 | |
38 @SuppressWarnings("unchecked") | |
39 public T set(CancelSupport cs) { | |
40 cancelHelper = cs; | |
41 return (T) this; | |
42 } | |
43 | |
44 // shall not return null | |
45 protected ProgressSupport getProgressSupport(Object context) { | |
46 if (progressHelper != null) { | |
47 return progressHelper; | |
48 } | |
49 return ProgressSupport.Factory.get(context); | |
50 } | |
51 | |
52 // shall not return null | |
53 protected CancelSupport getCancelSupport(Object context) { | |
54 if (cancelHelper != null) { | |
55 return cancelHelper; | |
56 } | |
57 return CancelSupport.Factory.get(context); | |
58 } | |
59 | |
60 } |