~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChangeChannelStateHandler.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**********************************************************************
2
2
 * Copyright (c) 2012 Ericsson
3
 
 * 
 
3
 *
4
4
 * All rights reserved. This program and the accompanying materials are
5
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
6
 * accompanies this distribution, and is available at
7
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 
 * 
9
 
 * Contributors: 
 
8
 *
 
9
 * Contributors:
10
10
 *   Bernd Hufmann - Initial API and implementation
11
11
 **********************************************************************/
12
12
package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
38
38
 * <p>
39
39
 * Abstract command handler implementation to enable or disabling a trace channel.
40
40
 * </p>
41
 
 * 
 
41
 *
42
42
 * @author Bernd Hufmann
43
43
 */
44
44
abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
57
57
    /**
58
58
     * @return the new state to set
59
59
     */
60
 
    abstract protected TraceEnablement getNewState(); 
 
60
    abstract protected TraceEnablement getNewState();
61
61
 
62
62
    // ------------------------------------------------------------------------
63
63
    // Operations
65
65
    /**
66
66
     * Changes the state of the given channels.
67
67
     * @param domain - the domain of the channels.
68
 
     * @param channelNames - a list of channel names 
 
68
     * @param channelNames - a list of channel names
69
69
     * @param monitor - a progress monitor
70
70
     * @throws ExecutionException
71
71
     */
72
 
    abstract protected void changeState(TraceDomainComponent domain, List<String> channelNames, IProgressMonitor monitor) throws ExecutionException; 
 
72
    abstract protected void changeState(TraceDomainComponent domain, List<String> channelNames, IProgressMonitor monitor) throws ExecutionException;
73
73
 
74
74
    /*
75
75
     * (non-Javadoc)
104
104
                            List<String> channelNames = new ArrayList<String>();
105
105
                            for (Iterator<TraceChannelComponent> iterator = kernelChannels.iterator(); iterator.hasNext();) {
106
106
                                // Enable all selected channels which are disabled
107
 
                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
 
107
                                TraceChannelComponent channel = iterator.next();
108
108
                                channelNames.add(channel.getName());
109
109
                            }
110
110
 
112
112
 
113
113
                            for (Iterator<TraceChannelComponent> iterator = kernelChannels.iterator(); iterator.hasNext();) {
114
114
                                // Enable all selected channels which are disabled
115
 
                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
 
115
                                TraceChannelComponent channel = iterator.next();
116
116
                                channel.setState(getNewState());
117
117
                            }
118
118
                        }
127
127
                            List<String> channelNames = new ArrayList<String>();
128
128
                            for (Iterator<TraceChannelComponent> iterator = ustChannels.iterator(); iterator.hasNext();) {
129
129
                                // Enable all selected channels which are disabled
130
 
                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
 
130
                                TraceChannelComponent channel = iterator.next();
131
131
                                channelNames.add(channel.getName());
132
132
                            }
133
133
 
135
135
 
136
136
                            for (Iterator<TraceChannelComponent> iterator = ustChannels.iterator(); iterator.hasNext();) {
137
137
                                // Enable all selected channels which are disabled
138
 
                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
 
138
                                TraceChannelComponent channel = iterator.next();
139
139
                                channel.setState(getNewState());
140
140
                            }
141
141
                        }
143
143
                        error = e;
144
144
                    }
145
145
 
146
 
                    // In all cases notify listeners  
147
 
                    session.fireComponentChanged(session);
 
146
                    // In all cases notify listeners
 
147
                    if (session != null) {
 
148
                        session.fireComponentChanged(session);
 
149
                    }
148
150
 
149
151
                    if (error != null) {
150
 
                        return new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeChannelStateFailure, error);
 
152
                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeChannelStateFailure, error);
151
153
                    }
152
154
 
153
155
                    return Status.OK_STATUS;
179
181
        TraceDomainComponent ustDomain = null;
180
182
        List<TraceChannelComponent> kernelChannels = new ArrayList<TraceChannelComponent>();
181
183
        List<TraceChannelComponent> ustChannels = new ArrayList<TraceChannelComponent>();
182
 
        
 
184
 
183
185
        // Check if one or more session are selected
184
186
        ISelection selection = page.getSelection(ControlView.ID);
185
187
        if (selection instanceof StructuredSelection) {
186
188
            StructuredSelection structered = ((StructuredSelection) selection);
187
189
            String sessionName = null;
188
190
            for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
189
 
                Object element = (Object) iterator.next();
190
 
                 
 
191
                Object element = iterator.next();
 
192
 
191
193
                if (element instanceof TraceChannelComponent) {
192
 
                    
 
194
 
193
195
                    // Add only TraceChannelComponents that are disabled
194
196
                    TraceChannelComponent channel = (TraceChannelComponent) element;
195
197
                    if (sessionName == null) {
219
221
                }
220
222
            }
221
223
        }
222
 
        
 
224
 
223
225
        boolean isEnabled = (!kernelChannels.isEmpty() || !ustChannels.isEmpty());
224
226
        fLock.lock();
225
227
        try {
229
231
        } finally {
230
232
            fLock.unlock();
231
233
        }
232
 
        
 
234
 
233
235
        return isEnabled;
234
236
    }
235
 
    
 
237
 
236
238
    /**
237
 
     *  Class containing parameter for the command execution. 
 
239
     *  Class containing parameter for the command execution.
238
240
     */
239
241
    static protected class Parameter {
240
242
        /**
246
248
         */
247
249
        final protected TraceDomainComponent fUstDomain;
248
250
        /**
249
 
         * The list of kernel channel components the command is to be executed on. 
 
251
         * The list of kernel channel components the command is to be executed on.
250
252
         */
251
253
        final protected List<TraceChannelComponent> fKernelChannels;
252
254
        /**
253
 
         * The list of UST channel components the command is to be executed on. 
 
255
         * The list of UST channel components the command is to be executed on.
254
256
         */
255
257
        final protected List<TraceChannelComponent> fUstChannels;
256
 
        
 
258
 
257
259
        /**
258
260
         * Constructor
259
261
         * @param kernelDomain - a kernel domain component
269
271
            fUstChannels = new ArrayList<TraceChannelComponent>();
270
272
            fUstChannels.addAll(ustChannels);
271
273
        }
272
 
        
 
274
 
273
275
        /**
274
276
         * Copy constructor
275
277
         * @param other a parameter to copy
277
279
        public Parameter(Parameter other) {
278
280
            this(other.fKernelDomain, other.fUstDomain, other.fKernelChannels, other.fUstChannels);
279
281
        }
280
 
        
 
282
 
281
283
        /**
282
284
         * @return the kernel domain component.
283
285
         */
284
286
        public TraceDomainComponent getKernelDomain() {
285
287
            return fKernelDomain;
286
288
        }
287
 
        
 
289
 
288
290
        /**
289
291
         * @return the UST domain component.
290
292
         */
291
293
        public TraceDomainComponent getUstDomain() {
292
294
            return fUstDomain;
293
 
        }   
294
 
        
 
295
        }
 
296
 
295
297
        /**
296
298
         * @return the list of kernel channel components.
297
299
         */
298
300
        public List<TraceChannelComponent> getKernelChannels() {
299
301
            return fKernelChannels;
300
302
        }
301
 
        
 
303
 
302
304
        /**
303
305
         * @return the list of UST channel components.
304
306
         */