1 /**********************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick-Jeffrey Pollo Guilbert, William Enright,
11 * William Tri-Khiem Truong - Initial API and implementation
12 **********************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Arrays
;
18 import java
.util
.List
;
20 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
21 import org
.eclipse
.jface
.viewers
.Viewer
;
22 import org
.eclipse
.remote
.core
.IRemoteConnection
;
23 import org
.eclipse
.remote
.core
.IRemoteConnectionType
;
29 public final class ConnectionContentProvider
implements ITreeContentProvider
{
30 private static final Object
[] NO_CHILDREN
= {};
33 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
37 public void dispose() {
41 public Object
[] getElements(Object inputElement
) {
42 List
<Object
> children
= new ArrayList
<>();
43 if (inputElement
instanceof IRemoteConnectionType
) {
44 IRemoteConnectionType irc
= (IRemoteConnectionType
) inputElement
;
45 children
.addAll(irc
.getRemoteServicesManager().getAllRemoteConnections());
47 return children
.toArray();
51 public Object
[] getChildren(Object parentElement
) {
52 if (parentElement
instanceof IRemoteConnectionType
) {
53 return getConnections((IRemoteConnectionType
) parentElement
);
58 static IRemoteConnection
[] getConnections(IRemoteConnectionType parentElement
) {
59 List
<IRemoteConnection
> connectionList
= parentElement
.getConnections();
60 IRemoteConnection
[] result
= connectionList
.toArray(new IRemoteConnection
[connectionList
.size()]);
66 public Object
getParent(Object element
) {
67 if (element
instanceof IRemoteConnection
) {
68 return ((IRemoteConnection
) element
).getConnectionType();
74 public boolean hasChildren(Object element
) {
75 return getChildren(element
).length
> 0;