2010-11-09 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug315307
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / project / handlers / RefreshHandler.java
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
13 package org.eclipse.linuxtools.tmf.ui.views.project.handlers;
14
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;
29
30 /**
31 * <b><u>RefreshHandler</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35 public class RefreshHandler extends AbstractHandler {
36
37 private TmfProjectRoot fProjectRoot = null;
38
39 // ------------------------------------------------------------------------
40 // Validation
41 // ------------------------------------------------------------------------
42
43 @Override
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
71 @Override
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) {
78 throw new ExecutionException("CoreException", e); //$NON-NLS-1$
79 }
80
81 return null;
82 }
83
84 }
This page took 0.032377 seconds and 5 git commands to generate.