Merge master in TmfTraceModel
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / RefreshHandler.java
CommitLineData
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 13package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
12c155f5
FC
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
828e5592
PT
18import org.eclipse.core.resources.IResource;
19import org.eclipse.core.runtime.CoreException;
12c155f5
FC
20import org.eclipse.jface.viewers.ISelection;
21import org.eclipse.jface.viewers.TreeSelection;
22import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
23import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder;
12c155f5
FC
24import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
25import org.eclipse.ui.IWorkbenchPage;
26import org.eclipse.ui.IWorkbenchPart;
27import org.eclipse.ui.IWorkbenchWindow;
28import org.eclipse.ui.PlatformUI;
29
30/**
31 * <b><u>RefreshHandler</u></b>
32 * <p>
33 * TODO: Handle multiple selections
34 */
35public 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();
828e5592 56 IResource resource = null;
12c155f5
FC
57 if (element instanceof TmfTraceFolder) {
58 TmfTraceFolder folder = (TmfTraceFolder) element;
828e5592 59 resource = folder.getResource();
12c155f5
FC
60 }
61 else if (element instanceof TmfExperimentFolder) {
62 TmfExperimentFolder folder = (TmfExperimentFolder) element;
828e5592 63 resource = folder.getResource();
12c155f5
FC
64 }
65 else if (element instanceof TmfExperimentElement) {
66 TmfExperimentElement folder = (TmfExperimentElement) element;
828e5592
PT
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();
12c155f5
FC
75 }
76 }
77
78
79 return null;
80 }
81
82}
This page took 0.03056 seconds and 5 git commands to generate.