Commit | Line | Data |
---|---|---|
12c155f5 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
d5210347 | 3 | * |
12c155f5 FC |
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 | |
d5210347 | 8 | * |
12c155f5 FC |
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; | |
8fd82db5 | 22 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
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(); | |
d5210347 PT |
47 | if (window == null) { |
48 | return null; | |
49 | } | |
12c155f5 FC |
50 | |
51 | // Get the selection | |
52 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
53 | IWorkbenchPart part = page.getActivePart(); | |
d5210347 PT |
54 | if (part == null) { |
55 | return false; | |
56 | } | |
12c155f5 FC |
57 | ISelection selection = part.getSite().getSelectionProvider().getSelection(); |
58 | if (selection instanceof TreeSelection) { | |
59 | TreeSelection treeSelection = (TreeSelection) selection; | |
60 | Object element = treeSelection.getFirstElement(); | |
828e5592 | 61 | IResource resource = null; |
12c155f5 FC |
62 | if (element instanceof TmfTraceFolder) { |
63 | TmfTraceFolder folder = (TmfTraceFolder) element; | |
828e5592 | 64 | resource = folder.getResource(); |
12c155f5 FC |
65 | } |
66 | else if (element instanceof TmfExperimentFolder) { | |
67 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
828e5592 | 68 | resource = folder.getResource(); |
12c155f5 FC |
69 | } |
70 | else if (element instanceof TmfExperimentElement) { | |
71 | TmfExperimentElement folder = (TmfExperimentElement) element; | |
828e5592 PT |
72 | resource = folder.getResource(); |
73 | } | |
74 | try { | |
75 | if (resource != null) { | |
76 | resource.refreshLocal(IResource.DEPTH_INFINITE, null); | |
77 | } | |
78 | } catch (CoreException e) { | |
8fd82db5 | 79 | Activator.getDefault().logError("Error refreshing projects", e); //$NON-NLS-1$ |
12c155f5 FC |
80 | } |
81 | } | |
82 | ||
83 | ||
84 | return null; | |
85 | } | |
86 | ||
87 | } |