control: Base code for profile dialog window
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / dialogs / ConnectionContentProvider.java
1 /**********************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Patrick-Jeffrey Pollo Guilbert, William Enright,
11 * William Tri-Khiem Truong - Initial API and implementation
12 **********************************************************************/
13
14 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs;
15
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.List;
19
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;
24
25 /**
26 * TODO document
27 *
28 */
29 public final class ConnectionContentProvider implements ITreeContentProvider {
30 private static final Object[] NO_CHILDREN = {};
31
32 @Override
33 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
34 }
35
36 @Override
37 public void dispose() {
38 }
39
40 @Override
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());
46 }
47 return children.toArray();
48 }
49
50 @Override
51 public Object[] getChildren(Object parentElement) {
52 if (parentElement instanceof IRemoteConnectionType) {
53 return getConnections((IRemoteConnectionType) parentElement);
54 }
55 return NO_CHILDREN;
56 }
57
58 static IRemoteConnection[] getConnections(IRemoteConnectionType parentElement) {
59 List<IRemoteConnection> connectionList = parentElement.getConnections();
60 IRemoteConnection[] result = connectionList.toArray(new IRemoteConnection[connectionList.size()]);
61 Arrays.sort(result);
62 return result;
63 }
64
65 @Override
66 public Object getParent(Object element) {
67 if (element instanceof IRemoteConnection) {
68 return ((IRemoteConnection) element).getConnectionType();
69 }
70 return null;
71 }
72
73 @Override
74 public boolean hasChildren(Object element) {
75 return getChildren(element).length > 0;
76 }
77
78 }
This page took 0.032359 seconds and 5 git commands to generate.