1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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
.tmf
.ui
.views
.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
.resources
.IWorkspaceRoot
;
20 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
21 import org
.eclipse
.core
.runtime
.CoreException
;
22 import org
.eclipse
.jface
.viewers
.ISelection
;
23 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.ProjectView
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.ITmfProjectTreeNode
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfProjectRoot
;
27 import org
.eclipse
.ui
.IWorkbenchWindow
;
28 import org
.eclipse
.ui
.PlatformUI
;
31 * <b><u>RefreshHandler</u></b>
33 * TODO: Implement me. Please.
35 public class RefreshHandler
extends AbstractHandler
{
37 private TmfProjectRoot fProjectRoot
= null;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 public boolean isEnabled() {
46 // Check if we are closing down
47 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
51 // Check if we can find the project model root node
52 ISelection selection
= window
.getActivePage().getSelection(ProjectView
.ID
);
53 if (selection
instanceof StructuredSelection
) {
54 Object element
= ((StructuredSelection
) selection
).getFirstElement();
55 if (element
instanceof ITmfProjectTreeNode
) {
56 ITmfProjectTreeNode node
= (ITmfProjectTreeNode
) element
;
57 while (node
!= null && !(node
instanceof TmfProjectRoot
)) {
58 node
= node
.getParent();
60 fProjectRoot
= (node
instanceof TmfProjectRoot
) ?
(TmfProjectRoot
) node
: null;
64 return (fProjectRoot
!= null);
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 IWorkspaceRoot root
= ResourcesPlugin
.getWorkspace().getRoot();
75 root
.refreshLocal(IResource
.DEPTH_INFINITE
, null);
76 fProjectRoot
.refreshChildren();
77 } catch (CoreException e
) {
78 throw new ExecutionException("CoreException", e
); //$NON-NLS-1$