1 /*******************************************************************************
2 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org
.eclipse
.egit
.ui
.internal
.push
;
11 import java
.util
.SortedMap
;
12 import java
.util
.TreeMap
;
13 import java
.util
.Map
.Entry
;
15 import org
.eclipse
.egit
.core
.op
.PushOperationResult
;
16 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
17 import org
.eclipse
.jface
.viewers
.Viewer
;
18 import org
.eclipse
.jgit
.transport
.RemoteRefUpdate
;
19 import org
.eclipse
.jgit
.transport
.URIish
;
22 * Content provided for push result table viewer.
24 * Input of this provided must be {@link PushOperationResult} instance, while
25 * returned elements are instances of {@link RefUpdateElement}. Null input is
26 * allowed, resulting in no elements.
28 * @see PushOperationResult
29 * @see RefUpdateElement
31 class RefUpdateContentProvider
implements IStructuredContentProvider
{
32 public Object
[] getElements(final Object inputElement
) {
33 if (inputElement
== null)
34 return new RefUpdateElement
[0];
36 final PushOperationResult result
= (PushOperationResult
) inputElement
;
38 final SortedMap
<String
, String
> dstToSrc
= new TreeMap
<String
, String
>();
39 for (final URIish uri
: result
.getURIs()) {
40 if (result
.isSuccessfulConnection(uri
)) {
41 for (final RemoteRefUpdate rru
: result
.getPushResult(uri
)
43 dstToSrc
.put(rru
.getRemoteName(), rru
.getSrcRef());
44 // Assuming that each repository received the same ref updates,
45 // we need only one to get these ref names.
50 // Transforming PushOperationResult model to row-wise one.
51 final RefUpdateElement elements
[] = new RefUpdateElement
[dstToSrc
54 for (final Entry
<String
, String
> entry
: dstToSrc
.entrySet())
55 elements
[i
++] = new RefUpdateElement(result
, entry
.getValue(),
60 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
64 public void dispose() {