Commit | Line | Data |
---|---|---|
c068a752 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
c068a752 GB |
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 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.analysis; |
c068a752 | 14 | |
2bdf0193 AM |
15 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
16 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | |
715154b1 | 17 | |
c068a752 GB |
18 | /** |
19 | * Abstract class for parameter providers, implements methods and | |
20 | * functionalities to warn the analysis module of parameter changed | |
21 | * | |
22 | * @author Geneviève Bastien | |
23 | * @since 3.0 | |
24 | */ | |
25 | public abstract class TmfAbstractAnalysisParamProvider implements IAnalysisParameterProvider { | |
26 | ||
27 | /** | |
28 | * The module registered with this provider | |
29 | */ | |
30 | private IAnalysisModule fModule; | |
31 | ||
32 | @Override | |
33 | public void registerModule(IAnalysisModule module) { | |
34 | if (module == null) { | |
35 | throw new IllegalArgumentException(); | |
36 | } | |
715154b1 GB |
37 | ITmfTrace selectedTrace = TmfTraceManager.getInstance().getActiveTrace(); |
38 | /* If no trace is active, just register the module */ | |
39 | if (selectedTrace == null) { | |
40 | fModule = module; | |
41 | return; | |
42 | } | |
43 | IAnalysisModule selectedModule = selectedTrace.getAnalysisModule(module.getId()); | |
44 | /* register only if the module is for the currently selected trace */ | |
45 | if (selectedModule == module) { | |
46 | fModule = module; | |
47 | } | |
c068a752 GB |
48 | } |
49 | ||
50 | /** | |
51 | * Gets the analysis module | |
52 | * | |
53 | * @return the {@link IAnalysisModule} associated with this provider | |
54 | */ | |
55 | protected IAnalysisModule getModule() { | |
56 | return fModule; | |
57 | } | |
58 | ||
59 | /** | |
60 | * Notify the registered module that the said parameter has a new value. The | |
61 | * analysis module will decide what to do with this information | |
62 | * | |
63 | * @param name | |
64 | * Name of the modified parameter | |
65 | */ | |
66 | protected void notifyParameterChanged(String name) { | |
ba27dd38 GB |
67 | IAnalysisModule module = fModule; |
68 | if (module != null && name != null) { | |
69 | module.notifyParameterChanged(name); | |
c068a752 GB |
70 | } |
71 | } | |
72 | } |