1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.actions
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Iterator
;
17 import java
.util
.List
;
19 import org
.eclipse
.jface
.action
.IAction
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.model
.TraceResource
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.Messages
;
25 import org
.eclipse
.rse
.core
.events
.ISystemRemoteChangeEvents
;
26 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
27 import org
.eclipse
.rse
.core
.model
.SystemStartHere
;
28 import org
.eclipse
.rse
.ui
.SystemBasePlugin
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
30 import org
.eclipse
.ui
.IObjectActionDelegate
;
31 import org
.eclipse
.ui
.IViewActionDelegate
;
32 import org
.eclipse
.ui
.IViewPart
;
33 import org
.eclipse
.ui
.IWorkbenchPart
;
34 import org
.eclipse
.ui
.IWorkbenchWindow
;
35 import org
.eclipse
.ui
.IWorkbenchWindowActionDelegate
;
38 * <b><u>DeleteTrace</u></b>
40 * Action implementation to delete a new trace.
43 public class DeleteTrace
implements IObjectActionDelegate
, IWorkbenchWindowActionDelegate
, IViewActionDelegate
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 private List
<TraceResource
> fSelectedTraces
;
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 public DeleteTrace() {
56 fSelectedTraces
= new ArrayList
<TraceResource
>();
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
65 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
68 public void setActivePart(IAction arg0
, IWorkbenchPart arg1
) {
72 * Gets the first selected target.
74 * @return first selected target.
76 protected TraceResource
getSelectedTarget() {
77 if (fSelectedTraces
.size() > 0) {
78 return (TraceResource
) fSelectedTraces
.get(0);
85 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
88 public void run(IAction arg0
) {
90 boolean confirm
= MessageDialog
.openConfirm(getShell(),
91 Messages
.DeleteTrace_ConfirmTitle
,
92 Messages
.DeleteTrace_ConfirmMessage
);
97 int size
= fSelectedTraces
.size();
98 for (int i
= 0; i
< size
; i
++) {
100 final TraceResource trace
= (TraceResource
) fSelectedTraces
.get(i
);
102 trace
.getParent().removeTrace(trace
);
104 ISystemRegistry registry
= SystemStartHere
.getSystemRegistry();
105 registry
.fireRemoteResourceChangeEvent(ISystemRemoteChangeEvents
.SYSTEM_REMOTE_RESOURCE_DELETED
, trace
, trace
.getParent(), trace
.getSubSystem(), null);
111 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
113 @SuppressWarnings("unchecked")
115 public void selectionChanged(IAction action
, ISelection selection
) {
117 if (selection
instanceof IStructuredSelection
) {
118 fSelectedTraces
.clear();
120 // store the selected targets to be used when running
121 Iterator
<IStructuredSelection
> theSet
= ((IStructuredSelection
) selection
).iterator();
122 while (theSet
.hasNext()) {
123 Object obj
= theSet
.next();
124 if (obj
instanceof TraceResource
) {
125 fSelectedTraces
.add((TraceResource
)obj
);
133 * Returns the active workbench shell of this plug-in.
135 * @return active workbench shell.
137 protected Shell
getShell() {
138 return SystemBasePlugin
.getActiveWorkbenchShell();
143 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
146 public void init(IWorkbenchWindow window
) {
151 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
154 public void dispose() {
159 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
162 public void init(IViewPart view
) {