|
Lines 1-5
Link Here
|
| 1 |
/********************************************************************** |
1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2007, 2008 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 11-36
Link Here
|
| 11 |
***********************************************************************/ |
11 |
***********************************************************************/ |
| 12 |
package org.eclipse.tptp.platform.instrumentation.ui.internal.control.provider.application; |
12 |
package org.eclipse.tptp.platform.instrumentation.ui.internal.control.provider.application; |
| 13 |
|
13 |
|
| 14 |
import java.util.Iterator; |
14 |
import org.eclipse.core.commands.IHandler; |
| 15 |
|
|
|
| 16 |
import org.eclipse.core.runtime.CoreException; |
| 17 |
import org.eclipse.hyades.trace.ui.ProfileEvent; |
| 18 |
import org.eclipse.hyades.trace.ui.UIPlugin; |
| 19 |
import org.eclipse.hyades.trace.ui.internal.actions.DeleteAction; |
15 |
import org.eclipse.hyades.trace.ui.internal.actions.DeleteAction; |
| 20 |
import org.eclipse.hyades.trace.ui.internal.actions.SaveAction; |
16 |
import org.eclipse.hyades.trace.ui.internal.actions.SaveAction; |
| 21 |
import org.eclipse.hyades.trace.ui.internal.core.TraceUIImages; |
|
|
| 22 |
import org.eclipse.hyades.ui.extension.INavigatorContribution; |
17 |
import org.eclipse.hyades.ui.extension.INavigatorContribution; |
| 23 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
|
| 24 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 25 |
import org.eclipse.tptp.platform.common.ui.trace.internal.CommonUITraceConstants; |
| 26 |
import org.eclipse.tptp.trace.ui.internal.control.provider.TraceControlItemManager; |
18 |
import org.eclipse.tptp.trace.ui.internal.control.provider.TraceControlItemManager; |
| 27 |
import org.eclipse.tptp.trace.ui.internal.control.provider.application.ControlMessages; |
|
|
| 28 |
import org.eclipse.tptp.trace.ui.internal.launcher.core.LauncherUtility; |
| 29 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.AbstractControlProvider; |
19 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.AbstractControlProvider; |
| 30 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.ControlItem; |
20 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.ControlItemHandler; |
| 31 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IAgentStateModifier; |
21 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IAgentStateModifier; |
| 32 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IControlItem; |
22 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IControlItem; |
| 33 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IProcessStateModifier; |
23 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IProcessStateModifier; |
|
|
24 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.PauseControlItem; |
| 25 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.RefreshOption; |
| 26 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.RefreshView; |
| 27 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.ResumeControlItem; |
| 28 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.TerminateAction; |
| 34 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.ProcessControlProvider.ProcessStateModifier; |
29 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.ProcessControlProvider.ProcessStateModifier; |
| 35 |
|
30 |
|
| 36 |
/** |
31 |
/** |
|
Lines 40-53
Link Here
|
| 40 |
*/ |
35 |
*/ |
| 41 |
public class AgentControlProvider extends AbstractControlProvider { |
36 |
public class AgentControlProvider extends AbstractControlProvider { |
| 42 |
|
37 |
|
| 43 |
/* The id of the contributed items */ |
|
|
| 44 |
private static final String REFRESH_ITEM = "org.eclipse.tptp.platform.instrumentation.ui.internal.control.provider.refreshViews"; |
| 45 |
private static final String REFRESH_OPTION = "org.eclipse.tptp.platform.instrumentation.ui.internal.control.provider.refreshOption"; |
| 46 |
private static final String TERMINATE_ITEM = "org.eclipse.tptp.platform.instrumentation.ui.internal.control.provider.terminateAction"; |
| 47 |
public static final String START_MONITORING = "org.eclipse.tptp.platform.instrumentation.ui.internal.control.provider.startMonitoring"; |
| 48 |
public static final String PAUSE_MONITORING = "org.eclipse.tptp.platform.instrumentation.ui.internal.control.provider.stopMonitoring"; |
| 49 |
|
| 50 |
|
| 51 |
/* The delete item */ |
38 |
/* The delete item */ |
| 52 |
private IControlItem delete; |
39 |
private IControlItem delete; |
| 53 |
|
40 |
|
|
Lines 74-80
Link Here
|
| 74 |
|
61 |
|
| 75 |
/* The agent state modifier */ |
62 |
/* The agent state modifier */ |
| 76 |
private IAgentStateModifier agentStateModifier; |
63 |
private IAgentStateModifier agentStateModifier; |
| 77 |
|
64 |
|
|
|
65 |
/* The handler for the actions */ |
| 66 |
private IHandler handler; |
| 78 |
/** |
67 |
/** |
| 79 |
* Default constructor. |
68 |
* Default constructor. |
| 80 |
*/ |
69 |
*/ |
|
Lines 136-162
Link Here
|
| 136 |
protected IControlItem createRefreshViewsControlItem() { |
125 |
protected IControlItem createRefreshViewsControlItem() { |
| 137 |
if (refresh != null) |
126 |
if (refresh != null) |
| 138 |
return refresh; |
127 |
return refresh; |
| 139 |
|
128 |
|
| 140 |
class RefreshView extends ControlItem |
|
|
| 141 |
{ |
| 142 |
public RefreshView() |
| 143 |
{ |
| 144 |
super (REFRESH_ITEM, CommonUITraceConstants.PROFILE_REFRESH_GROUP, ControlMessages.CONTROL_ITEM_REFRESH_VIEWS, TraceUIImages.INSTANCE.getImageDescriptor("c", TraceUIImages.IMG_REFRESH_VIEWS)); |
| 145 |
} |
| 146 |
|
| 147 |
public void run() |
| 148 |
{ |
| 149 |
if (input == null) |
| 150 |
return; |
| 151 |
|
| 152 |
for (Iterator sources = input.iterator(); sources.hasNext();) |
| 153 |
{ |
| 154 |
ProfileEvent event = UIPlugin.getDefault().getRefreshViewEvent(sources.next()); |
| 155 |
UIPlugin.getDefault().notifyProfileEventListener(event); |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
refresh = new RefreshView(); |
129 |
refresh = new RefreshView(); |
|
|
130 |
handler = new ControlItemHandler(refresh); |
| 131 |
refresh.setHandler(handler); |
| 160 |
return refresh; |
132 |
return refresh; |
| 161 |
} |
133 |
} |
| 162 |
|
134 |
|
|
Lines 168-196
Link Here
|
| 168 |
protected IControlItem createRefreshOptionControlItem() { |
140 |
protected IControlItem createRefreshOptionControlItem() { |
| 169 |
if (refreshOption != null) |
141 |
if (refreshOption != null) |
| 170 |
return refreshOption; |
142 |
return refreshOption; |
| 171 |
|
143 |
|
| 172 |
class RefreshOption extends ControlItem |
|
|
| 173 |
{ |
| 174 |
public RefreshOption() |
| 175 |
{ |
| 176 |
super (REFRESH_OPTION, CommonUITraceConstants.PROFILE_REFRESH_GROUP, ControlMessages.CONTROL_ITEM_REFRESH_OPTION, TraceUIImages.INSTANCE.getImageDescriptor("c", TraceUIImages.IMG_REFRESH_OPTIONS)); |
| 177 |
} |
| 178 |
|
| 179 |
/* This method is invoked when ever user clicks the 'Change Refresh Options' button. |
| 180 |
* It simply invokes the 'handleProfileEvent' method of PDProjectExplorer */ |
| 181 |
public void run() |
| 182 |
{ |
| 183 |
if (input == null) |
| 184 |
return; |
| 185 |
|
| 186 |
for (Iterator sources = input.iterator(); sources.hasNext();) |
| 187 |
{ |
| 188 |
ProfileEvent event = UIPlugin.getDefault().getRefreshOptionEvent(sources.next()); |
| 189 |
UIPlugin.getDefault().notifyProfileEventListener(event); |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
refreshOption = new RefreshOption(); |
144 |
refreshOption = new RefreshOption(); |
|
|
145 |
handler = new ControlItemHandler(refreshOption); |
| 146 |
refreshOption.setHandler(handler); |
| 194 |
return refreshOption; |
147 |
return refreshOption; |
| 195 |
} |
148 |
} |
| 196 |
|
149 |
|
|
Lines 199-273
Link Here
|
| 199 |
if (resumeItem != null) |
152 |
if (resumeItem != null) |
| 200 |
return resumeItem; |
153 |
return resumeItem; |
| 201 |
|
154 |
|
| 202 |
class ResumeControlItem extends AgentControlItem |
155 |
resumeItem = new ResumeControlItem(getAgentStateModifier()); |
| 203 |
{ |
156 |
handler = new ControlItemHandler(resumeItem); |
| 204 |
public ResumeControlItem() |
157 |
resumeItem.setHandler(handler); |
| 205 |
{ |
|
|
| 206 |
super(getAgentStateModifier(), START_MONITORING, CommonUITraceConstants.PROFILE_MONITOR_GROUP, ControlMessages.CONTROL_ITEM_RESUME, TraceUIImages.INSTANCE.getImageDescriptor("c", TraceUIImages.IMG_RESUME)); |
| 207 |
setDisabledImageDescriptor(TraceUIImages.INSTANCE.getImageDescriptor("d", TraceUIImages.IMG_RESUME)); |
| 208 |
} |
| 209 |
|
| 210 |
public void run() |
| 211 |
{ |
| 212 |
IAgentStateModifier agentStateModifier = getAgentStateModifier(); |
| 213 |
|
| 214 |
try |
| 215 |
{ |
| 216 |
/* Resume the agent */ |
| 217 |
agentStateModifier.startMonitoring(); |
| 218 |
} catch (CoreException e) |
| 219 |
{ |
| 220 |
/* Display status */ |
| 221 |
LauncherUtility.openMessageWithDetail(e.getStatus().getSeverity(), "", e.getMessage(), e); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
public boolean isEnabled() |
| 226 |
{ |
| 227 |
return getAgentStateModifier().canResume(); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
resumeItem = new ResumeControlItem(); |
| 233 |
return resumeItem; |
158 |
return resumeItem; |
| 234 |
} |
159 |
} |
| 235 |
|
160 |
|
| 236 |
protected IControlItem createPauseMonitoringControlItem() { |
161 |
protected IControlItem createPauseMonitoringControlItem() { |
| 237 |
if (pauseItem != null) |
162 |
if (pauseItem != null) |
| 238 |
return pauseItem; |
163 |
return pauseItem; |
| 239 |
|
|
|
| 240 |
class PauseControlItem extends AgentControlItem |
| 241 |
{ |
| 242 |
public PauseControlItem() |
| 243 |
{ |
| 244 |
super(getAgentStateModifier(), PAUSE_MONITORING, CommonUITraceConstants.PROFILE_MONITOR_GROUP, ControlMessages.CONTROL_ITEM_PAUSE, TraceUIImages.INSTANCE.getImageDescriptor("c", TraceUIImages.IMG_PAUSE)); |
| 245 |
setDisabledImageDescriptor(TraceUIImages.INSTANCE.getImageDescriptor("d", TraceUIImages.IMG_PAUSE)); |
| 246 |
} |
| 247 |
|
| 248 |
public void run() |
| 249 |
{ |
| 250 |
IAgentStateModifier agentStateModifier = getAgentStateModifier(); |
| 251 |
|
| 252 |
try |
| 253 |
{ |
| 254 |
/* Pause the agent */ |
| 255 |
agentStateModifier.pauseMonitoring(); |
| 256 |
} catch (CoreException e) |
| 257 |
{ |
| 258 |
/* Display status */ |
| 259 |
LauncherUtility.openMessageWithDetail(e.getStatus().getSeverity(), "", e.getMessage(), e); |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
public boolean isEnabled() |
| 264 |
{ |
| 265 |
return getAgentStateModifier().canPause(); |
| 266 |
} |
| 267 |
} |
| 268 |
|
164 |
|
| 269 |
|
165 |
pauseItem = new PauseControlItem(getAgentStateModifier()); |
| 270 |
pauseItem = new PauseControlItem(); |
166 |
handler = new ControlItemHandler(pauseItem); |
|
|
167 |
pauseItem.setHandler(handler); |
| 271 |
return pauseItem; |
168 |
return pauseItem; |
| 272 |
} |
169 |
} |
| 273 |
|
170 |
|
|
Lines 281-368
Link Here
|
| 281 |
protected IControlItem createTerminateControlItem() { |
178 |
protected IControlItem createTerminateControlItem() { |
| 282 |
if (terminateItem != null) |
179 |
if (terminateItem != null) |
| 283 |
return terminateItem; |
180 |
return terminateItem; |
| 284 |
|
181 |
|
| 285 |
class TerminateAction extends ControlItem |
182 |
terminateItem = new TerminateAction(getProcessStateModifier()); |
| 286 |
{ |
183 |
handler = new ControlItemHandler(terminateItem); |
| 287 |
public TerminateAction() |
184 |
terminateItem.setHandler(handler); |
| 288 |
{ |
|
|
| 289 |
super (TERMINATE_ITEM, CommonUITraceConstants.PROFILE_TERMINATE_GROUP, ControlMessages.CONTROL_ITEM_TERMINATE, TraceUIImages.INSTANCE.getImageDescriptor("c", TraceUIImages.IMG_TERMINATE)); |
| 290 |
setDisabledImageDescriptor(TraceUIImages.INSTANCE.getImageDescriptor("d", TraceUIImages.IMG_TERMINATE)); |
| 291 |
} |
| 292 |
|
| 293 |
public void run() |
| 294 |
{ |
| 295 |
IProcessStateModifier processStateModifier = getProcessStateModifier(); |
| 296 |
|
| 297 |
try |
| 298 |
{ |
| 299 |
/* Terminate the process */ |
| 300 |
processStateModifier.terminate(); |
| 301 |
} catch (CoreException e) |
| 302 |
{ |
| 303 |
/* Display status */ |
| 304 |
LauncherUtility.openMessageWithDetail(e.getStatus().getSeverity(), "", e.getMessage(), e); |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
public boolean isEnabled() |
| 309 |
{ |
| 310 |
return getProcessStateModifier().canTerminate(); |
| 311 |
} |
| 312 |
|
| 313 |
public void setInput(StructuredSelection input) |
| 314 |
{ |
| 315 |
getProcessStateModifier().setInput(input); |
| 316 |
} |
| 317 |
|
| 318 |
public IProcessStateModifier getStateModifier() |
| 319 |
{ |
| 320 |
return getProcessStateModifier(); |
| 321 |
} |
| 322 |
|
| 323 |
public boolean equals (Object o) |
| 324 |
{ |
| 325 |
if (!(o instanceof TerminateAction)) |
| 326 |
return false; |
| 327 |
|
| 328 |
return getProcessStateModifier() == ((TerminateAction)o).getStateModifier() && super.equals(o); |
| 329 |
} |
| 330 |
|
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
terminateItem = new TerminateAction(); |
| 335 |
return terminateItem; |
185 |
return terminateItem; |
| 336 |
} |
186 |
} |
| 337 |
|
187 |
|
| 338 |
private static class AgentControlItem extends ControlItem { |
|
|
| 339 |
private IAgentStateModifier stateModifier; |
| 340 |
|
| 341 |
public AgentControlItem (IAgentStateModifier stateModifier, String itemId, String groupName, String text, ImageDescriptor imageDescriptor) |
| 342 |
{ |
| 343 |
super(itemId, groupName, text, imageDescriptor); |
| 344 |
this.stateModifier = stateModifier; |
| 345 |
} |
| 346 |
|
| 347 |
public void setInput(StructuredSelection input) |
| 348 |
{ |
| 349 |
stateModifier.setInput(input); |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
public IAgentStateModifier getStateModifier() |
| 354 |
{ |
| 355 |
return stateModifier; |
| 356 |
} |
| 357 |
|
| 358 |
public boolean equals (Object o) |
| 359 |
{ |
| 360 |
if (!(o instanceof AgentControlItem)) |
| 361 |
return false; |
| 362 |
|
| 363 |
return stateModifier == ((AgentControlItem)o).getStateModifier() && super.equals(o); |
| 364 |
} |
| 365 |
|
| 366 |
} |
| 367 |
|
188 |
|
| 368 |
} |
189 |
} |