Commit | Line | Data |
---|---|---|
12c155f5 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 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 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; |
12c155f5 FC |
14 | |
15 | import org.eclipse.core.commands.AbstractHandler; | |
16 | import org.eclipse.core.commands.ExecutionEvent; | |
17 | import org.eclipse.core.commands.ExecutionException; | |
828e5592 PT |
18 | import org.eclipse.core.resources.IResource; |
19 | import org.eclipse.core.runtime.CoreException; | |
12c155f5 FC |
20 | import org.eclipse.jface.viewers.ISelection; |
21 | import org.eclipse.jface.viewers.TreeSelection; | |
9fa32496 | 22 | import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; |
12c155f5 FC |
23 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; |
24 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; | |
12c155f5 FC |
25 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; |
26 | import org.eclipse.ui.IWorkbenchPage; | |
27 | import org.eclipse.ui.IWorkbenchPart; | |
28 | import org.eclipse.ui.IWorkbenchWindow; | |
29 | import org.eclipse.ui.PlatformUI; | |
30 | ||
31 | /** | |
32 | * <b><u>RefreshHandler</u></b> | |
33 | * <p> | |
34 | * TODO: Handle multiple selections | |
35 | */ | |
36 | public class RefreshHandler extends AbstractHandler { | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Execution | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
42 | @Override | |
43 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
44 | ||
45 | // Check if we are closing down | |
46 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
47 | if (window == null) | |
48 | return null; | |
49 | ||
50 | // Get the selection | |
51 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
52 | IWorkbenchPart part = page.getActivePart(); | |
53 | ISelection selection = part.getSite().getSelectionProvider().getSelection(); | |
54 | if (selection instanceof TreeSelection) { | |
55 | TreeSelection treeSelection = (TreeSelection) selection; | |
56 | Object element = treeSelection.getFirstElement(); | |
828e5592 | 57 | IResource resource = null; |
12c155f5 FC |
58 | if (element instanceof TmfTraceFolder) { |
59 | TmfTraceFolder folder = (TmfTraceFolder) element; | |
828e5592 | 60 | resource = folder.getResource(); |
12c155f5 FC |
61 | } |
62 | else if (element instanceof TmfExperimentFolder) { | |
63 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
828e5592 | 64 | resource = folder.getResource(); |
12c155f5 FC |
65 | } |
66 | else if (element instanceof TmfExperimentElement) { | |
67 | TmfExperimentElement folder = (TmfExperimentElement) element; | |
828e5592 PT |
68 | resource = folder.getResource(); |
69 | } | |
70 | try { | |
71 | if (resource != null) { | |
72 | resource.refreshLocal(IResource.DEPTH_INFINITE, null); | |
73 | } | |
74 | } catch (CoreException e) { | |
9fa32496 | 75 | TmfUiPlugin.getDefault().logError("Error refreshing projects", e); //$NON-NLS-1$ |
12c155f5 FC |
76 | } |
77 | } | |
78 | ||
79 | ||
80 | return null; | |
81 | } | |
82 | ||
83 | } |