tmf: Drop generics from ITmfTrace and TmfExperiment
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / DeleteExperimentHandler.java
CommitLineData
12c155f5
FC
1/*******************************************************************************
2 * Copyright (c) 2009, 2010, 2011 Ericsson
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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
d34665f9 13package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
12c155f5
FC
14
15import java.util.Iterator;
16
17import org.eclipse.core.commands.AbstractHandler;
18import org.eclipse.core.commands.ExecutionEvent;
19import org.eclipse.core.commands.ExecutionException;
20import org.eclipse.core.resources.IResource;
21import org.eclipse.core.runtime.CoreException;
22import org.eclipse.jface.viewers.ISelection;
23import org.eclipse.jface.viewers.TreeSelection;
8fd82db5 24import org.eclipse.linuxtools.internal.tmf.ui.Activator;
12c155f5
FC
25import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
26import org.eclipse.swt.SWT;
27import org.eclipse.swt.widgets.MessageBox;
28import org.eclipse.swt.widgets.Shell;
29import org.eclipse.ui.IWorkbenchPage;
30import org.eclipse.ui.IWorkbenchPart;
31import org.eclipse.ui.IWorkbenchWindow;
32import org.eclipse.ui.PlatformUI;
33
34/**
35 * <b><u>DeleteExperimentHandler</u></b>
36 * <p>
37 */
38public class DeleteExperimentHandler extends AbstractHandler {
39
40 // ------------------------------------------------------------------------
41 // Execution
42 // ------------------------------------------------------------------------
43
44 @Override
45 public Object execute(ExecutionEvent event) throws ExecutionException {
46
47 // Check if we are closing down
48 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
49 if (window == null)
50 return null;
51
52 // Confirm the operation
53 Shell shell = window.getShell();
54 MessageBox confirmOperation = new MessageBox(shell, SWT.ICON_QUESTION | SWT.CANCEL | SWT.OK);
55 confirmOperation.setText(Messages.DeleteDialog_Title);
56 confirmOperation.setMessage(Messages.DeleteExperimentHandler_Message);
57 if (confirmOperation.open() != SWT.OK)
58 return null;
59
60 // Get the selection
61 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
62 IWorkbenchPart part = page.getActivePart();
63 ISelection selection = part.getSite().getSelectionProvider().getSelection();
64
65 if (selection instanceof TreeSelection) {
66 TreeSelection sel = (TreeSelection) selection;
67 @SuppressWarnings("unchecked")
68 Iterator<Object> iterator = sel.iterator();
69 while (iterator.hasNext()) {
70 Object element = iterator.next();
71 if (element instanceof TmfExperimentElement) {
72 TmfExperimentElement experiment = (TmfExperimentElement) element;
73 IResource resource = experiment.getResource();
74 try {
75 resource.delete(true, null);
76 experiment.getProject().refresh();
77 } catch (CoreException e) {
8fd82db5 78 Activator.getDefault().logError("Error deleting experiment: " + experiment.getName(), e); //$NON-NLS-1$
12c155f5
FC
79 }
80 }
81 }
82 }
83
84 return null;
85 }
86}
This page took 0.04316 seconds and 5 git commands to generate.