1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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 * Bernd Hufmann - Initial API and implementation
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.model
.config
;
15 import org
.eclipse
.jface
.viewers
.ICellModifier
;
16 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.TraceResource
.TraceState
;
17 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.config
.TraceChannel
;
18 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.wizards
.KernelTraceChannelConfigurationPage
;
19 import org
.eclipse
.swt
.widgets
.TableItem
;
22 * <b><u>TraceChannelCellModifier</u></b>
24 * ICellModifier implementation for TableViewers in order to modify cells of a table used for
25 * for displaying and configuring trace channel information.
28 public class TraceChannelCellModifier
implements ICellModifier
{
30 // ------------------------------------------------------------------------
32 // -----------------------------------------------------------------------
33 KernelTraceChannelConfigurationPage fConfigPage
;
35 // ------------------------------------------------------------------------
37 // -----------------------------------------------------------------------
42 * @param configPage The trace configuration reference
44 public TraceChannelCellModifier(KernelTraceChannelConfigurationPage configPage
) {
45 fConfigPage
= configPage
;
50 * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
53 public boolean canModify(Object element
, String property
) {
54 // Find the index of the column
55 int columnIndex
= fConfigPage
.getColumnProperties().indexOf(property
);
57 switch (columnIndex
) {
61 case 2: // Buffer Overwrite
64 if ((fConfigPage
.getTraceState() == TraceState
.CREATED
) || (fConfigPage
.getTraceState() == TraceState
.CONFIGURED
)) {
68 case 5: // Channel Timer
69 if (fConfigPage
.isLocalTrace() && ((fConfigPage
.getTraceState() == TraceState
.CREATED
) || (fConfigPage
.getTraceState() == TraceState
.CONFIGURED
))) {
80 * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
83 public Object
getValue(Object element
, String property
) {
85 // Find the index of the column
86 int columnIndex
= fConfigPage
.getColumnProperties().indexOf(property
);
89 TraceChannel chan
= (TraceChannel
) element
;
91 switch (columnIndex
) {
93 result
= chan
.getName();
96 result
= Boolean
.valueOf(chan
.isEnabled());
98 case 2: // Buffer Overwrite
99 result
= Boolean
.valueOf(chan
.isChannelOverride());
102 result
= String
.valueOf(chan
.getSubbufNum());
104 case 4: // SubbufSize
105 result
= String
.valueOf(chan
.getSubbufSize());
107 case 5: // Channel Timer
108 result
= String
.valueOf(chan
.getTimer());
111 result
= ""; //$NON-NLS-1$
118 * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
121 public void modify(Object element
, String property
, Object value
) {
122 // Find the index of the column
123 int columnIndex
= fConfigPage
.getColumnProperties().indexOf(property
);
125 TableItem item
= (TableItem
) element
;
126 TraceChannel chan
= (TraceChannel
) item
.getData();
129 switch (columnIndex
) {
131 chan
.setName(((String
) value
).trim());
134 chan
.setIsEnabled(((Boolean
) value
).booleanValue());
137 chan
.setIsChannelOverride(((Boolean
) value
).booleanValue());
140 valueString
= ((String
) value
).trim();
141 if (valueString
.length() == 0) {
142 valueString
= "0"; //$NON-NLS-1$
144 else if(TraceChannel
.UNKNOWN_STRING
.equals(valueString
)) {
145 chan
.setSubbufNum(TraceChannel
.UNKNOWN_VALUE
);
148 chan
.setSubbufNum(Integer
.parseInt(valueString
));
151 case 4: // SubbufSize
152 valueString
= ((String
) value
).trim();
153 if (valueString
.length() == 0) {
154 valueString
= "0"; //$NON-NLS-1$
156 else if(TraceChannel
.UNKNOWN_STRING
.equals(valueString
)) {
157 chan
.setSubbufSize(TraceChannel
.UNKNOWN_VALUE
);
160 chan
.setSubbufSize(Integer
.parseInt(valueString
));
163 case 5: // Channel Timer
164 valueString
= ((String
) value
).trim();
165 if (valueString
.length() == 0) {
166 valueString
= "0"; //$NON-NLS-1$
168 else if(TraceChannel
.UNKNOWN_STRING
.equals(valueString
)) {
169 chan
.setTimer(TraceChannel
.UNKNOWN_VALUE
);
172 chan
.setTimer(Integer
.parseInt(valueString
));
177 fConfigPage
.refresh();