|
1 /* |
|
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * TraceViewer event listener |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.engine; |
|
20 |
|
21 import org.eclipse.ui.PlatformUI; |
|
22 |
|
23 import com.nokia.trace.eventrouter.PropertySource; |
|
24 import com.nokia.trace.eventrouter.TraceEvent; |
|
25 import com.nokia.trace.eventrouter.TraceEventListener; |
|
26 import com.nokia.trace.eventrouter.TraceEventRouter; |
|
27 import com.nokia.traceviewer.TraceViewerPlugin; |
|
28 |
|
29 /** |
|
30 * TraceViewer event listener |
|
31 * |
|
32 */ |
|
33 final class TraceViewerEventListener implements TraceEventListener { |
|
34 |
|
35 /** |
|
36 * Component ID string |
|
37 */ |
|
38 private static final String CID_STR = "cid"; //$NON-NLS-1$ |
|
39 |
|
40 /** |
|
41 * Group ID string |
|
42 */ |
|
43 private static final String GID_STR = "gid"; //$NON-NLS-1$ |
|
44 |
|
45 /** |
|
46 * Trace ID string |
|
47 */ |
|
48 private static final String TID_STR = "tid"; //$NON-NLS-1$ |
|
49 |
|
50 /** |
|
51 * Search trace action string |
|
52 */ |
|
53 private static final String SEARCHTRACEACTION = "searchtrace"; //$NON-NLS-1$ |
|
54 |
|
55 /* |
|
56 * (non-Javadoc) |
|
57 * |
|
58 * @see |
|
59 * com.nokia.trace.eventrouter.TraceEventListener#processEvent(com.nokia |
|
60 * .trace.eventrouter.TraceEvent) |
|
61 */ |
|
62 public void processEvent(TraceEvent event) { |
|
63 if (event.getSource() instanceof PropertySource) { |
|
64 final PropertySource source = (PropertySource) event.getSource(); |
|
65 |
|
66 // This Event is meant for this plugin if the target is the |
|
67 // ID of this Plugin |
|
68 if (source.getTargetId().equals(TraceViewerPlugin.PLUGIN_ID)) { |
|
69 PlatformUI.getWorkbench().getDisplay().asyncExec( |
|
70 new Runnable() { |
|
71 |
|
72 /* |
|
73 * (non-Javadoc) |
|
74 * |
|
75 * @see java.lang.Runnable#run() |
|
76 */ |
|
77 public void run() { |
|
78 handleEvent(source); |
|
79 } |
|
80 }); |
|
81 } |
|
82 } |
|
83 } |
|
84 |
|
85 /** |
|
86 * Handles the event |
|
87 * |
|
88 * @param source |
|
89 * propertysource of the event to handle |
|
90 */ |
|
91 private void handleEvent(PropertySource source) { |
|
92 String action = source.getActionName(); |
|
93 if (action.equals(SEARCHTRACEACTION)) { |
|
94 handleSearchTraceAction(source); |
|
95 } else { |
|
96 // Unknown event action, do nothing |
|
97 } |
|
98 } |
|
99 |
|
100 /** |
|
101 * Handles search trace action |
|
102 * |
|
103 * @param source |
|
104 * propertysource of the event to handle |
|
105 */ |
|
106 private void handleSearchTraceAction(PropertySource source) { |
|
107 |
|
108 // View must exist to use the search functionality |
|
109 if (TraceViewerGlobals.getTraceViewer().getView() != null) { |
|
110 String cidStr = source.getProperties().get(CID_STR); |
|
111 String gidStr = source.getProperties().get(GID_STR); |
|
112 String tidStr = source.getProperties().get(TID_STR); |
|
113 |
|
114 try { |
|
115 |
|
116 int cid = Integer.parseInt(cidStr); |
|
117 |
|
118 // Get the group ID in a separate method |
|
119 int gid = getGroupID(cid, gidStr); |
|
120 |
|
121 int tid = Integer.parseInt(tidStr); |
|
122 |
|
123 // Create the search if ID's are valid |
|
124 if (gid != -1 && tid != -1) { |
|
125 TraceViewerGlobals.getTraceViewer() |
|
126 .getDataProcessorAccess().getSearchProcessor() |
|
127 .searchTraceWithID(cid, gid, tid); |
|
128 } |
|
129 |
|
130 } catch (NumberFormatException e) { |
|
131 // If numbers parsing failed, show a error message |
|
132 String errMsg1 = Messages |
|
133 .getString("TraceViewerEventListener.InvalidSearchTraceMsg1"); //$NON-NLS-1$ |
|
134 String errMsg2 = Messages |
|
135 .getString("TraceViewerEventListener.InvalidSearchTraceMsg2"); //$NON-NLS-1$ |
|
136 TraceViewerGlobals.getTraceViewer().getDialogs() |
|
137 .showErrorMessage( |
|
138 errMsg1 + source.getSourceId() + errMsg2); |
|
139 } |
|
140 } |
|
141 |
|
142 } |
|
143 |
|
144 /** |
|
145 * Gets group ID from the group string |
|
146 * |
|
147 * @param componentId |
|
148 * component ID |
|
149 * @param gidStr |
|
150 * group ID string |
|
151 * @return group ID or -1 if parsing failed |
|
152 */ |
|
153 private int getGroupID(int componentId, String gidStr) { |
|
154 int groupId = -1; |
|
155 // First try to parse integer |
|
156 try { |
|
157 groupId = Integer.parseInt(gidStr); |
|
158 |
|
159 // If parsing failed, string contains the group name. Go ask the ID |
|
160 // from the DecodeProvider |
|
161 } catch (NumberFormatException e) { |
|
162 if (TraceViewerGlobals.getDecodeProvider() != null) { |
|
163 groupId = TraceViewerGlobals.getDecodeProvider().getGroupId( |
|
164 componentId, gidStr); |
|
165 } |
|
166 } |
|
167 return groupId; |
|
168 } |
|
169 |
|
170 /** |
|
171 * Registers itself to the event router |
|
172 */ |
|
173 public void register() { |
|
174 TraceEventRouter.getInstance().addEventListener(this); |
|
175 } |
|
176 |
|
177 /** |
|
178 * Unregisters itself from the event router |
|
179 */ |
|
180 public void unregister() { |
|
181 TraceEventRouter.getInstance().removeEventListener(this); |
|
182 } |
|
183 } |