Commit | Line | Data |
---|---|---|
12c155f5 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 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.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.jface.viewers.ISelection; | |
19 | import org.eclipse.jface.viewers.TreeSelection; | |
20 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; | |
21 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; | |
22 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; | |
23 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; | |
24 | import org.eclipse.ui.IWorkbenchPage; | |
25 | import org.eclipse.ui.IWorkbenchPart; | |
26 | import org.eclipse.ui.IWorkbenchWindow; | |
27 | import org.eclipse.ui.PlatformUI; | |
28 | ||
29 | /** | |
30 | * <b><u>RefreshHandler</u></b> | |
31 | * <p> | |
32 | * TODO: Handle multiple selections | |
33 | */ | |
34 | public class RefreshHandler extends AbstractHandler { | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Execution | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
40 | @Override | |
41 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
42 | ||
43 | // Check if we are closing down | |
44 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
45 | if (window == null) | |
46 | return null; | |
47 | ||
48 | // Get the selection | |
49 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
50 | IWorkbenchPart part = page.getActivePart(); | |
51 | ISelection selection = part.getSite().getSelectionProvider().getSelection(); | |
52 | if (selection instanceof TreeSelection) { | |
53 | TreeSelection treeSelection = (TreeSelection) selection; | |
54 | Object element = treeSelection.getFirstElement(); | |
55 | if (element instanceof TmfTraceFolder) { | |
56 | TmfTraceFolder folder = (TmfTraceFolder) element; | |
57 | TmfProjectElement project = (TmfProjectElement) folder.getProject(); | |
58 | project.refresh(); | |
59 | } | |
60 | else if (element instanceof TmfExperimentFolder) { | |
61 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
62 | TmfProjectElement project = (TmfProjectElement) folder.getProject(); | |
63 | project.refresh(); | |
64 | } | |
65 | else if (element instanceof TmfExperimentElement) { | |
66 | TmfExperimentElement folder = (TmfExperimentElement) element; | |
67 | TmfProjectElement project = folder.getProject(); | |
68 | project.refresh(); | |
69 | } | |
70 | } | |
71 | ||
72 | ||
73 | return null; | |
74 | } | |
75 | ||
76 | } |