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
.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();
51 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
52 IWorkbenchPart part
= page
.getActivePart();
53 ISelection selection
= part
.getSite().getSelectionProvider().getSelection();
54 if (selection
instanceof TreeSelection
) {
55 TreeSelection treeSelection
= (TreeSelection
) selection
;
56 Object element
= treeSelection
.getFirstElement();
57 IResource resource
= null;
58 if (element
instanceof TmfTraceFolder
) {
59 TmfTraceFolder folder
= (TmfTraceFolder
) element
;
60 resource
= folder
.getResource();
62 else if (element
instanceof TmfExperimentFolder
) {
63 TmfExperimentFolder folder
= (TmfExperimentFolder
) element
;
64 resource
= folder
.getResource();
66 else if (element
instanceof TmfExperimentElement
) {
67 TmfExperimentElement folder
= (TmfExperimentElement
) element
;
68 resource
= folder
.getResource();
71 if (resource
!= null) {
72 resource
.refreshLocal(IResource
.DEPTH_INFINITE
, null);
74 } catch (CoreException e
) {
75 Activator
.getDefault().logError("Error refreshing projects", e
); //$NON-NLS-1$