| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012 Ericsson |
| 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 | * Bernd Hufmann - Initial API and implementation |
| 11 | **********************************************************************/ |
| 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; |
| 13 | |
| 14 | import java.util.Iterator; |
| 15 | import java.util.List; |
| 16 | |
| 17 | import org.eclipse.core.commands.ExecutionException; |
| 18 | import org.eclipse.core.runtime.IProgressMonitor; |
| 19 | import org.eclipse.core.runtime.NullProgressMonitor; |
| 20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo; |
| 21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IUstProviderInfo; |
| 22 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
| 23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
| 24 | |
| 25 | /** |
| 26 | * <p> |
| 27 | * Implementation of the trace provider group. |
| 28 | * </p> |
| 29 | * |
| 30 | * @author Bernd Hufmann |
| 31 | */ |
| 32 | public class TraceProviderGroup extends TraceControlComponent { |
| 33 | // ------------------------------------------------------------------------ |
| 34 | // Constants |
| 35 | // ------------------------------------------------------------------------ |
| 36 | /** |
| 37 | * Path to icon file for this component. |
| 38 | */ |
| 39 | public static final String TRACE_PROVIDERS_ICON_FILE = "icons/obj16/providers.gif"; //$NON-NLS-1$ |
| 40 | |
| 41 | // ------------------------------------------------------------------------ |
| 42 | // Attributes |
| 43 | // ------------------------------------------------------------------------ |
| 44 | |
| 45 | // ------------------------------------------------------------------------ |
| 46 | // Constructors |
| 47 | // ------------------------------------------------------------------------ |
| 48 | /** |
| 49 | * Constructor |
| 50 | * @param name - the name of the component. |
| 51 | * @param parent - the parent of this component. |
| 52 | */ |
| 53 | public TraceProviderGroup(String name, ITraceControlComponent parent) { |
| 54 | super(name, parent); |
| 55 | setImage(TRACE_PROVIDERS_ICON_FILE); |
| 56 | } |
| 57 | |
| 58 | // ------------------------------------------------------------------------ |
| 59 | // Accessors |
| 60 | // ------------------------------------------------------------------------ |
| 61 | |
| 62 | // ------------------------------------------------------------------------ |
| 63 | // Operations |
| 64 | // ------------------------------------------------------------------------ |
| 65 | |
| 66 | /** |
| 67 | * Gets the provider information from the target node. |
| 68 | * @throws ExecutionException If the command fails |
| 69 | */ |
| 70 | public void getProviderFromNode() throws ExecutionException { |
| 71 | getProviderFromNode(new NullProgressMonitor()); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Gets the provider information from the target node. |
| 76 | * @param monitor - a progress monitor |
| 77 | * @throws ExecutionException If the command fails |
| 78 | */ |
| 79 | public void getProviderFromNode(IProgressMonitor monitor) throws ExecutionException { |
| 80 | |
| 81 | List<IBaseEventInfo> eventInfos = getControlService().getKernelProvider(monitor); |
| 82 | |
| 83 | if (!eventInfos.isEmpty()) { |
| 84 | KernelProviderComponent component = new KernelProviderComponent(Messages.TraceControl_KernelProviderDisplayName, this); |
| 85 | addChild(component); |
| 86 | component.setEventInfo(eventInfos); |
| 87 | } |
| 88 | |
| 89 | List<IUstProviderInfo> allProviders = getControlService().getUstProvider(monitor); |
| 90 | |
| 91 | for (Iterator<IUstProviderInfo> iterator = allProviders.iterator(); iterator.hasNext();) { |
| 92 | IUstProviderInfo ustProviderInfo = iterator.next(); |
| 93 | UstProviderComponent ustComponent = new UstProviderComponent(ustProviderInfo.getName(), this); |
| 94 | addChild(ustComponent); |
| 95 | ustComponent.setUstProvider(ustProviderInfo); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns whether the kernel provider is available or not |
| 101 | * @return <code>true</code> if kernel provide is available or <code>false</code> |
| 102 | */ |
| 103 | public boolean hasKernelProvider() { |
| 104 | List<ITraceControlComponent> kernelList = getChildren(KernelProviderComponent.class); |
| 105 | return !kernelList.isEmpty(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns if node supports filtering of events |
| 110 | * @return <code>true</code> if node supports filtering else <code>false</code> |
| 111 | */ |
| 112 | public boolean isEventFilteringSupported() { |
| 113 | return ((TargetNodeComponent)getParent()).isEventFilteringSupported(); |
| 114 | } |
| 115 | } |
| 116 | |