7a154e6c991f490b2a30bc8defabb5197a3ce15d
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / tracecontrol / model / config / TraceChannelCellModifier.java
1 /*******************************************************************************
2 * Copyright (c) 2011 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 *******************************************************************************/
13 package org.eclipse.linuxtools.lttng.ui.tracecontrol.model.config;
14
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;
20
21 /**
22 * <b><u>TraceChannelCellModifier</u></b>
23 * <p>
24 * ICellModifier implementation for TableViewers in order to modify cells of a table used for
25 * for displaying and configuring trace channel information.
26 * </p>
27 */
28 public class TraceChannelCellModifier implements ICellModifier {
29
30 // ------------------------------------------------------------------------
31 // Attributes
32 // -----------------------------------------------------------------------
33 KernelTraceChannelConfigurationPage fConfigPage;
34
35 // ------------------------------------------------------------------------
36 // Constructors
37 // -----------------------------------------------------------------------
38
39 /**
40 * Constructor
41 *
42 * @param configPage The trace configuration reference
43 */
44 public TraceChannelCellModifier(KernelTraceChannelConfigurationPage configPage) {
45 fConfigPage = configPage;
46 }
47
48 /*
49 * (non-Javadoc)
50 * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
51 */
52 @Override
53 public boolean canModify(Object element, String property) {
54 // Find the index of the column
55 int columnIndex = fConfigPage.getColumnProperties().indexOf(property);
56
57 switch (columnIndex) {
58 case 0: // Name
59 return false;
60 case 1: // Enabled
61 case 2: // Buffer Overwrite
62 case 3: // SubbufNum
63 case 4: // SubbufSize
64 if ((fConfigPage.getTraceState() == TraceState.CREATED) || (fConfigPage.getTraceState() == TraceState.CONFIGURED)) {
65 return true;
66 }
67 break;
68 case 5: // Channel Timer
69 if (fConfigPage.isLocalTrace() && ((fConfigPage.getTraceState() == TraceState.CREATED) || (fConfigPage.getTraceState() == TraceState.CONFIGURED))) {
70 return true;
71 }
72 break;
73 default:
74 }
75 return false;
76 }
77
78 /*
79 * (non-Javadoc)
80 * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
81 */
82 @Override
83 public Object getValue(Object element, String property) {
84
85 // Find the index of the column
86 int columnIndex = fConfigPage.getColumnProperties().indexOf(property);
87
88 Object result = null;
89 TraceChannel chan = (TraceChannel) element;
90
91 switch (columnIndex) {
92 case 0: // Name
93 result = chan.getName();
94 break;
95 case 1: // Enabled
96 result = Boolean.valueOf(chan.isEnabled());
97 break;
98 case 2: // Buffer Overwrite
99 result = Boolean.valueOf(chan.isChannelOverride());
100 break;
101 case 3: // SubbufNum
102 result = String.valueOf(chan.getSubbufNum());
103 break;
104 case 4: // SubbufSize
105 result = String.valueOf(chan.getSubbufSize());
106 break;
107 case 5: // Channel Timer
108 result = String.valueOf(chan.getTimer());
109 break;
110 default:
111 result = ""; //$NON-NLS-1$
112 }
113 return result;
114 }
115
116 /*
117 * (non-Javadoc)
118 * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
119 */
120 @Override
121 public void modify(Object element, String property, Object value) {
122 // Find the index of the column
123 int columnIndex = fConfigPage.getColumnProperties().indexOf(property);
124
125 TableItem item = (TableItem) element;
126 TraceChannel chan = (TraceChannel) item.getData();
127 String valueString;
128
129 switch (columnIndex) {
130 case 0:
131 chan.setName(((String) value).trim());
132 break;
133 case 1: // Name
134 chan.setIsEnabled(((Boolean) value).booleanValue());
135 break;
136 case 2:
137 chan.setIsChannelOverride(((Boolean) value).booleanValue());
138 break;
139 case 3: // SubbufNum
140 valueString = ((String) value).trim();
141 if (valueString.length() == 0) {
142 valueString = "0"; //$NON-NLS-1$
143 }
144 else if(TraceChannel.UNKNOWN_STRING.equals(valueString)) {
145 chan.setSubbufNum(TraceChannel.UNKNOWN_VALUE);
146 }
147 else {
148 chan.setSubbufNum(Integer.parseInt(valueString));
149 }
150 break;
151 case 4: // SubbufSize
152 valueString = ((String) value).trim();
153 if (valueString.length() == 0) {
154 valueString = "0"; //$NON-NLS-1$
155 }
156 else if(TraceChannel.UNKNOWN_STRING.equals(valueString)) {
157 chan.setSubbufSize(TraceChannel.UNKNOWN_VALUE);
158 }
159 else {
160 chan.setSubbufSize(Integer.parseInt(valueString));
161 }
162 break;
163 case 5: // Channel Timer
164 valueString = ((String) value).trim();
165 if (valueString.length() == 0) {
166 valueString = "0"; //$NON-NLS-1$
167 }
168 else if(TraceChannel.UNKNOWN_STRING.equals(valueString)) {
169 chan.setTimer(TraceChannel.UNKNOWN_VALUE);
170 }
171 else {
172 chan.setTimer(Integer.parseInt(valueString));
173 }
174 break;
175 default:
176 }
177 fConfigPage.refresh();
178 }
179 }
This page took 0.039704 seconds and 5 git commands to generate.