ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / TmfActionProvider.java
CommitLineData
828e5592 1/*******************************************************************************
b36d7773 2* Copyright (c) 2012, 2014 Ericsson
a0a88f65 3 *
828e5592
PT
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
a0a88f65 8 *
828e5592
PT
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
d34665f9 13package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
828e5592 14
b36d7773
PT
15import org.eclipse.core.resources.IFile;
16import org.eclipse.jface.action.IMenuManager;
17import org.eclipse.jface.action.MenuManager;
18import org.eclipse.jface.viewers.ISelection;
19import org.eclipse.jface.viewers.IStructuredSelection;
20import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
828e5592 21import org.eclipse.ui.IActionBars;
b36d7773 22import org.eclipse.ui.IWorkbenchPage;
b36d7773 23import org.eclipse.ui.actions.OpenWithMenu;
828e5592
PT
24import org.eclipse.ui.navigator.CommonActionProvider;
25import org.eclipse.ui.navigator.ICommonActionConstants;
26import org.eclipse.ui.navigator.ICommonActionExtensionSite;
b36d7773 27import org.eclipse.ui.navigator.ICommonMenuConstants;
828e5592
PT
28import org.eclipse.ui.navigator.ICommonViewerSite;
29import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
30
a0a88f65
AM
31/**
32 * Base action provider.
33 *
34 * @author Patrick Tassé
35 */
828e5592
PT
36public class TmfActionProvider extends CommonActionProvider {
37
38 private OpenAction openAction;
828e5592 39
b36d7773
PT
40 private IWorkbenchPage page;
41
828e5592
PT
42 /**
43 * Default constructor
44 */
45 public TmfActionProvider() {
46 }
47
828e5592
PT
48 @Override
49 public void init(ICommonActionExtensionSite aSite) {
50 ICommonViewerSite viewSite = aSite.getViewSite();
51 if (viewSite instanceof ICommonViewerWorkbenchSite) {
52 ICommonViewerWorkbenchSite workbenchSite = (ICommonViewerWorkbenchSite) viewSite;
b36d7773
PT
53 page = workbenchSite.getPage();
54 openAction = new OpenAction(page, workbenchSite.getSelectionProvider());
b36d7773
PT
55 }
56 }
57
58 @Override
59 public void fillContextMenu(IMenuManager menu) {
60 ISelection selection = getContext().getSelection();
61 if (selection instanceof IStructuredSelection) {
62 IStructuredSelection structuredSelection = (IStructuredSelection) selection;
63 if (structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof TmfTraceElement) {
64 TmfTraceElement traceElement = (TmfTraceElement) structuredSelection.getFirstElement();
65 if (traceElement.getResource() instanceof IFile) {
66 MenuManager openWithMenu = new MenuManager(Messages.TmfActionProvider_OpenWith);
67 openWithMenu.add(new OpenWithMenu(page, traceElement.getResource()));
68 menu.insertAfter(ICommonMenuConstants.GROUP_OPEN_WITH, openWithMenu);
69 }
70 }
828e5592
PT
71 }
72 }
73
828e5592
PT
74 @Override
75 public void fillActionBars(IActionBars actionBars) {
76 if (openAction.isEnabled()) {
77 actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, openAction);
78 }
828e5592
PT
79 }
80
81}
This page took 0.05617 seconds and 5 git commands to generate.