blob: d6340840bbbceae41fc7028d3285e5257a085973 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*******************************************************************************
* Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.egit.ui.internal.components;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.core.op.ListRemoteOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.dialogs.CancelableFuture;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.URIish;
/**
* A {@link ListRemoteOperation} that is run asynchronously as a
* {@link CancelableFuture}.
*
* @param <T>
* result type
*/
public abstract class AsynchronousListOperation<T>
extends CancelableFuture<Collection<T>> {
private final Repository repository;
private final String uriText;
private ListRemoteOperation listOp;
/**
* Creates a new {@link AsynchronousListOperation}.
*
* @param repository
* local repository for which to run the operation
* @param uriText
* upstream URI
*/
public AsynchronousListOperation(Repository repository, String uriText) {
this.repository = repository;
this.uriText = uriText;
}
@Override
protected String getJobTitle() {
return MessageFormat.format(
UIText.AsynchronousRefProposalProvider_FetchingRemoteRefsMessage,
uriText);
}
@Override
protected void prepareRun() throws InvocationTargetException {
try {
listOp = new ListRemoteOperation(repository, new URIish(uriText),
Activator.getDefault().getPreferenceStore()
.getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT));
} catch (URISyntaxException e) {
throw new InvocationTargetException(e);
}
}
@Override
protected void run(IProgressMonitor monitor)
throws InterruptedException, InvocationTargetException {
listOp.run(monitor);
set(convert(listOp.getRemoteRefs()));
}
/**
* Transforms the {@link Ref}s obtained into the final objects. May just
* return the input if the generic type T is Ref, or may post-process the
* results as appropriate.
*
* @param refs
* obtained from the upstream repository
* @return final result
*/
protected abstract Collection<T> convert(Collection<Ref> refs);
@Override
protected void done() {
listOp = null;
}
}
|