Internalize some more TMF APIs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / RefreshHandler.java
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
13 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
14
15 import org.eclipse.core.commands.AbstractHandler;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.resources.IResource;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.TreeSelection;
22 import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
23 import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder;
24 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
25 import org.eclipse.ui.IWorkbenchPage;
26 import org.eclipse.ui.IWorkbenchPart;
27 import org.eclipse.ui.IWorkbenchWindow;
28 import org.eclipse.ui.PlatformUI;
29
30 /**
31 * <b><u>RefreshHandler</u></b>
32 * <p>
33 * TODO: Handle multiple selections
34 */
35 public class RefreshHandler extends AbstractHandler {
36
37 // ------------------------------------------------------------------------
38 // Execution
39 // ------------------------------------------------------------------------
40
41 @Override
42 public Object execute(ExecutionEvent event) throws ExecutionException {
43
44 // Check if we are closing down
45 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
46 if (window == null)
47 return null;
48
49 // Get the selection
50 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
51 IWorkbenchPart part = page.getActivePart();
52 ISelection selection = part.getSite().getSelectionProvider().getSelection();
53 if (selection instanceof TreeSelection) {
54 TreeSelection treeSelection = (TreeSelection) selection;
55 Object element = treeSelection.getFirstElement();
56 IResource resource = null;
57 if (element instanceof TmfTraceFolder) {
58 TmfTraceFolder folder = (TmfTraceFolder) element;
59 resource = folder.getResource();
60 }
61 else if (element instanceof TmfExperimentFolder) {
62 TmfExperimentFolder folder = (TmfExperimentFolder) element;
63 resource = folder.getResource();
64 }
65 else if (element instanceof TmfExperimentElement) {
66 TmfExperimentElement folder = (TmfExperimentElement) element;
67 resource = folder.getResource();
68 }
69 try {
70 if (resource != null) {
71 resource.refreshLocal(IResource.DEPTH_INFINITE, null);
72 }
73 } catch (CoreException e) {
74 e.printStackTrace();
75 }
76 }
77
78
79 return null;
80 }
81
82 }
This page took 0.031611 seconds and 5 git commands to generate.