2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / 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.lttng.ui.views.project.handlers;
14
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.IHandler;
18 import org.eclipse.core.commands.IHandlerListener;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView;
22 import org.eclipse.linuxtools.lttng.ui.views.project.model.ILTTngProjectTreeNode;
23 import org.eclipse.linuxtools.lttng.ui.views.project.model.LTTngProjectRoot;
24 import org.eclipse.ui.IWorkbenchWindow;
25 import org.eclipse.ui.PlatformUI;
26
27 /**
28 * <b><u>RefreshHandler</u></b>
29 * <p>
30 * TODO: Implement me. Please.
31 */
32 public class RefreshHandler implements IHandler {
33
34 private LTTngProjectRoot fProjectRoot = null;
35
36 // ------------------------------------------------------------------------
37 // Validation
38 // ------------------------------------------------------------------------
39
40 @Override
41 public boolean isEnabled() {
42
43 // Check if we are closing down
44 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
45 if (window == null)
46 return false;
47
48 // Check if we can find the project model root node
49 ISelection selection = window.getActivePage().getSelection(ProjectView.ID);
50 if (selection instanceof StructuredSelection) {
51 Object element = ((StructuredSelection) selection).getFirstElement();
52 if (element instanceof ILTTngProjectTreeNode) {
53 ILTTngProjectTreeNode node = (ILTTngProjectTreeNode) element;
54 while (node != null && !(node instanceof LTTngProjectRoot)) {
55 node = node.getParent();
56 }
57 fProjectRoot = (node instanceof LTTngProjectRoot) ? (LTTngProjectRoot) node : null;
58 }
59 }
60
61 return (fProjectRoot != null);
62 }
63
64 // Handled if we are in the ProjectView
65 @Override
66 public boolean isHandled() {
67 return true;
68 }
69
70 // ------------------------------------------------------------------------
71 // Execution
72 // ------------------------------------------------------------------------
73
74 @Override
75 public Object execute(ExecutionEvent event) throws ExecutionException {
76
77 if (fProjectRoot != null) {
78 fProjectRoot.refreshChildren();
79 fProjectRoot.refresh();
80 }
81
82 return null;
83 }
84
85 @Override
86 public void dispose() {
87 // TODO Auto-generated method stub
88 }
89
90 // ------------------------------------------------------------------------
91 // IHandlerListener
92 // ------------------------------------------------------------------------
93
94 @Override
95 public void addHandlerListener(IHandlerListener handlerListener) {
96 // TODO Auto-generated method stub
97 }
98
99 @Override
100 public void removeHandlerListener(IHandlerListener handlerListener) {
101 // TODO Auto-generated method stub
102 }
103
104 }
This page took 0.032766 seconds and 5 git commands to generate.