Added TMF statistics feature (Bug 360572)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / project / handlers / RefreshHandler.java
CommitLineData
abfad0aa
FC
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 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
13package org.eclipse.linuxtools.tmf.ui.views.project.handlers;
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.resources.IResource;
19import org.eclipse.core.resources.IWorkspaceRoot;
20import org.eclipse.core.resources.ResourcesPlugin;
21import org.eclipse.core.runtime.CoreException;
22import org.eclipse.jface.viewers.ISelection;
23import org.eclipse.jface.viewers.StructuredSelection;
24import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView;
25import org.eclipse.linuxtools.tmf.ui.views.project.model.ITmfProjectTreeNode;
26import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfProjectRoot;
27import org.eclipse.ui.IWorkbenchWindow;
28import org.eclipse.ui.PlatformUI;
29
30/**
31 * <b><u>RefreshHandler</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35public class RefreshHandler extends AbstractHandler {
36
37 private TmfProjectRoot fProjectRoot = null;
38
39 // ------------------------------------------------------------------------
40 // Validation
41 // ------------------------------------------------------------------------
42
9ccc6d01 43 @Override
abfad0aa
FC
44 public boolean isEnabled() {
45
46 // Check if we are closing down
47 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
48 if (window == null)
49 return false;
50
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();
59 }
60 fProjectRoot = (node instanceof TmfProjectRoot) ? (TmfProjectRoot) node : null;
61 }
62 }
63
64 return (fProjectRoot != null);
65 }
66
67 // ------------------------------------------------------------------------
68 // Execution
69 // ------------------------------------------------------------------------
70
d4011df2 71 @Override
abfad0aa
FC
72 public Object execute(ExecutionEvent event) throws ExecutionException {
73 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
74 try {
75 root.refreshLocal(IResource.DEPTH_INFINITE, null);
76 fProjectRoot.refreshChildren();
77 } catch (CoreException e) {
3b38ea61 78 throw new ExecutionException("CoreException", e); //$NON-NLS-1$
abfad0aa
FC
79 }
80
81 return null;
82 }
83
84}
This page took 0.028414 seconds and 5 git commands to generate.