1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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
.internal
.tmf
.ui
.Activator
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
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
;
32 * <b><u>RefreshHandler</u></b>
34 * TODO: Handle multiple selections
36 public class RefreshHandler
extends AbstractHandler
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
43 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
45 // Check if we are closing down
46 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
52 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
53 IWorkbenchPart part
= page
.getActivePart();
57 ISelection selection
= part
.getSite().getSelectionProvider().getSelection();
58 if (selection
instanceof TreeSelection
) {
59 TreeSelection treeSelection
= (TreeSelection
) selection
;
60 Object element
= treeSelection
.getFirstElement();
61 IResource resource
= null;
62 if (element
instanceof TmfTraceFolder
) {
63 TmfTraceFolder folder
= (TmfTraceFolder
) element
;
64 resource
= folder
.getResource();
66 else if (element
instanceof TmfExperimentFolder
) {
67 TmfExperimentFolder folder
= (TmfExperimentFolder
) element
;
68 resource
= folder
.getResource();
70 else if (element
instanceof TmfExperimentElement
) {
71 TmfExperimentElement folder
= (TmfExperimentElement
) element
;
72 resource
= folder
.getResource();
75 if (resource
!= null) {
76 resource
.refreshLocal(IResource
.DEPTH_INFINITE
, null);
78 } catch (CoreException e
) {
79 Activator
.getDefault().logError("Error refreshing projects", e
); //$NON-NLS-1$