| 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.List; |
| 15 | |
| 16 | import org.eclipse.core.commands.ExecutionException; |
| 17 | import org.eclipse.core.runtime.IProgressMonitor; |
| 18 | import org.eclipse.core.runtime.NullProgressMonitor; |
| 19 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
| 20 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages; |
| 21 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo; |
| 22 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
| 23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement; |
| 24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType; |
| 25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel; |
| 26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceEventPropertySource; |
| 27 | import org.eclipse.swt.graphics.Image; |
| 28 | import org.eclipse.ui.views.properties.IPropertySource; |
| 29 | |
| 30 | |
| 31 | /** |
| 32 | * <b><u>TraceEventComponent</u></b> |
| 33 | * <p> |
| 34 | * Implementation of the trace channel component. |
| 35 | * </p> |
| 36 | */ |
| 37 | public class TraceEventComponent extends TraceControlComponent { |
| 38 | // ------------------------------------------------------------------------ |
| 39 | // Constants |
| 40 | // ------------------------------------------------------------------------ |
| 41 | /** |
| 42 | * Path to icon file for this component (enabled state). |
| 43 | */ |
| 44 | public static final String TRACE_EVENT_ICON_FILE_ENABLED = "icons/obj16/event_enabled.gif"; //$NON-NLS-1$ |
| 45 | /** |
| 46 | * Path to icon file for this component (disabled state). |
| 47 | */ |
| 48 | public static final String TRACE_EVENT_ICON_FILE_DISABLED = "icons/obj16/event_disabled.gif"; //$NON-NLS-1$ |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | // Attributes |
| 52 | // ------------------------------------------------------------------------ |
| 53 | /** |
| 54 | * The event information. |
| 55 | */ |
| 56 | protected IEventInfo fEventInfo = null; |
| 57 | /** |
| 58 | * The image to be displayed when in disabled state. |
| 59 | */ |
| 60 | private Image fDisabledImage = null; |
| 61 | |
| 62 | // ------------------------------------------------------------------------ |
| 63 | // Constructors |
| 64 | // ------------------------------------------------------------------------ |
| 65 | /** |
| 66 | * Constructor |
| 67 | * @param name - the name of the component. |
| 68 | * @param parent - the parent of this component. |
| 69 | */ |
| 70 | public TraceEventComponent(String name, ITraceControlComponent parent) { |
| 71 | super(name, parent); |
| 72 | setImage(TRACE_EVENT_ICON_FILE_ENABLED); |
| 73 | setToolTip(Messages.TraceControl_EventDisplayName); |
| 74 | fEventInfo = new EventInfo(name); |
| 75 | fDisabledImage = Activator.getDefault().loadIcon(TRACE_EVENT_ICON_FILE_DISABLED); |
| 76 | } |
| 77 | |
| 78 | // ------------------------------------------------------------------------ |
| 79 | // Accessors |
| 80 | // ------------------------------------------------------------------------ |
| 81 | /* |
| 82 | * (non-Javadoc) |
| 83 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage() |
| 84 | */ |
| 85 | @Override |
| 86 | public Image getImage() { |
| 87 | if (fEventInfo.getState() == TraceEnablement.DISABLED) { |
| 88 | return fDisabledImage; |
| 89 | } |
| 90 | return super.getImage(); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Sets the event information. |
| 95 | * @param eventInfo - the event information to set. |
| 96 | */ |
| 97 | public void setEventInfo(IEventInfo eventInfo) { |
| 98 | fEventInfo = eventInfo; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @return the trace event type |
| 103 | */ |
| 104 | public TraceEventType getEventType() { |
| 105 | return fEventInfo.getEventType(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Sets the trace event type to the given type |
| 110 | * @param type - type to set |
| 111 | */ |
| 112 | public void setEventType(TraceEventType type) { |
| 113 | fEventInfo.setEventType(type); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Sets the trace event type to the type specified by the given name. |
| 118 | * @param type - event type name |
| 119 | */ |
| 120 | public void setEventType(String typeName) { |
| 121 | fEventInfo.setEventType(typeName); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @return the event state (enabled or disabled). |
| 126 | */ |
| 127 | public TraceEnablement getState() { |
| 128 | return fEventInfo.getState(); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Sets the event state (enablement) to the given value. |
| 133 | * @param state - state to set. |
| 134 | */ |
| 135 | public void setState(TraceEnablement state) { |
| 136 | fEventInfo.setState(state); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Sets the event state (enablement) to the value specified by the given name. |
| 141 | * @param stateName - state to set. |
| 142 | */ |
| 143 | public void setState(String stateName) { |
| 144 | fEventInfo.setState(stateName); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * @return the trace event log level |
| 149 | */ |
| 150 | public TraceLogLevel getLogLevel() { |
| 151 | return fEventInfo.getLogLevel(); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Sets the trace event log level to the given level |
| 156 | * @param level - event log level to set |
| 157 | */ |
| 158 | public void setLogLevel(TraceLogLevel level) { |
| 159 | fEventInfo.setLogLevel(level); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Sets the trace event log level to the level specified by the given name. |
| 164 | * @param levelName - event log level name |
| 165 | */ |
| 166 | public void setLogLevel(String levelName) { |
| 167 | fEventInfo.setLogLevel(levelName); |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * (non-Javadoc) |
| 172 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) |
| 173 | */ |
| 174 | @SuppressWarnings("rawtypes") |
| 175 | @Override |
| 176 | public Object getAdapter(Class adapter) { |
| 177 | if (adapter == IPropertySource.class) { |
| 178 | return new TraceEventPropertySource(this); |
| 179 | } |
| 180 | return null; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @return session name from parent |
| 185 | */ |
| 186 | public String getSessionName() { |
| 187 | return ((TraceChannelComponent)getParent()).getSessionName(); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * @return session from parent |
| 192 | */ |
| 193 | public TraceSessionComponent getSession() { |
| 194 | return ((TraceChannelComponent)getParent()).getSession(); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @return channel name from parent |
| 199 | */ |
| 200 | public String getChannelName() { |
| 201 | return getParent().getName(); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @return if domain is kernel or UST |
| 206 | */ |
| 207 | public boolean isKernel() { |
| 208 | return ((TraceChannelComponent)getParent()).isKernel(); |
| 209 | } |
| 210 | |
| 211 | // ------------------------------------------------------------------------ |
| 212 | // Operations |
| 213 | // ------------------------------------------------------------------------ |
| 214 | |
| 215 | /** |
| 216 | * Add contexts to given channels and or events |
| 217 | * @param contexts - a list of contexts to add |
| 218 | * @throws ExecutionException |
| 219 | */ |
| 220 | public void addContexts(List<String> contexts) throws ExecutionException { |
| 221 | addContexts(contexts, new NullProgressMonitor()); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Add contexts to given channels and or events |
| 226 | * @param contexts - a list of contexts to add |
| 227 | * @param monitor - a progress monitor |
| 228 | * @throws ExecutionException |
| 229 | */ |
| 230 | public void addContexts(List<String> contexts, IProgressMonitor monitor) throws ExecutionException { |
| 231 | getControlService().addContexts(getSessionName(),getChannelName(), getName(), isKernel(), contexts, monitor); |
| 232 | } |
| 233 | } |