1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
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
;
31 * <b><u>RefreshHandler</u></b>
33 * TODO: Handle multiple selections
35 public class RefreshHandler
extends AbstractHandler
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
42 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
44 // Check if we are closing down
45 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
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();
61 else if (element
instanceof TmfExperimentFolder
) {
62 TmfExperimentFolder folder
= (TmfExperimentFolder
) element
;
63 resource
= folder
.getResource();
65 else if (element
instanceof TmfExperimentElement
) {
66 TmfExperimentElement folder
= (TmfExperimentElement
) element
;
67 resource
= folder
.getResource();
70 if (resource
!= null) {
71 resource
.refreshLocal(IResource
.DEPTH_INFINITE
, null);
73 } catch (CoreException e
) {