Commit | Line | Data |
---|---|---|
abfad0aa FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
3 | * \r | |
4 | * All rights reserved. This program and the accompanying materials are\r | |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
8 | * \r | |
9 | * Contributors:\r | |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.tmf.ui.views.project.handlers;\r | |
14 | \r | |
15 | import java.util.HashMap;\r | |
16 | import java.util.LinkedList;\r | |
17 | import java.util.Map;\r | |
18 | import java.util.Map.Entry;\r | |
19 | \r | |
15b6d03e FC |
20 | import org.eclipse.core.resources.IResource;\r |
21 | import org.eclipse.core.runtime.CoreException;\r | |
abfad0aa FC |
22 | import org.eclipse.jface.action.IContributionItem;\r |
23 | import org.eclipse.jface.action.MenuManager;\r | |
15b6d03e FC |
24 | import org.eclipse.jface.resource.ImageDescriptor;\r |
25 | import org.eclipse.jface.viewers.ISelection;\r | |
26 | import org.eclipse.jface.viewers.StructuredSelection;\r | |
27 | import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;\r | |
abfad0aa | 28 | import org.eclipse.linuxtools.tmf.ui.parsers.ParserProviderManager;\r |
15b6d03e FC |
29 | import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView;\r |
30 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfExperimentNode;\r | |
31 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfTraceNode;\r | |
32 | import org.eclipse.ui.IWorkbenchPage;\r | |
33 | import org.eclipse.ui.IWorkbenchWindow;\r | |
abfad0aa FC |
34 | import org.eclipse.ui.PlatformUI;\r |
35 | import org.eclipse.ui.actions.CompoundContributionItem;\r | |
36 | import org.eclipse.ui.menus.CommandContributionItem;\r | |
37 | import org.eclipse.ui.menus.CommandContributionItemParameter;\r | |
38 | \r | |
39 | \r | |
40 | public class SelectParserContributionItem extends CompoundContributionItem {\r | |
41 | \r | |
15b6d03e FC |
42 | private static final ImageDescriptor SELECTED_ICON = ImageDescriptor.createFromImage(TmfUiPlugin.getDefault().getImageFromPath("icons/elcl16/bullet.gif")); //$NON-NLS-1$\r |
43 | \r | |
abfad0aa FC |
44 | @Override\r |
45 | protected IContributionItem[] getContributionItems() {\r | |
46 | Map<String, String> params;\r | |
47 | LinkedList<IContributionItem> list = new LinkedList<IContributionItem>();\r | |
48 | \r | |
49 | ParserProviderManager.getParserMap();\r | |
15b6d03e FC |
50 | \r |
51 | String parser = null;\r | |
52 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();\r | |
53 | IWorkbenchPage page = window.getActivePage();\r | |
54 | ISelection selection = page.getSelection(ProjectView.ID);\r | |
55 | if (selection instanceof StructuredSelection) {\r | |
56 | Object element = ((StructuredSelection) selection).getFirstElement();\r | |
57 | if (! (element instanceof TmfTraceNode)) {\r | |
58 | return new IContributionItem[0];\r | |
59 | }\r | |
60 | TmfTraceNode trace = (TmfTraceNode) element;\r | |
61 | IResource resource = trace.getResource();\r | |
62 | if (trace.getParent() instanceof TmfExperimentNode) {\r | |
63 | resource = trace.getProject().getTracesFolder().getTraceForLocation(resource.getLocation()).getResource();\r | |
64 | }\r | |
65 | try {\r | |
66 | parser = resource.getPersistentProperty(ParserProviderManager.PARSER_PROPERTY);\r | |
67 | } catch (CoreException e) {\r | |
68 | e.printStackTrace();\r | |
69 | }\r | |
70 | }\r | |
71 | \r | |
abfad0aa FC |
72 | for(Entry<String, Map<String, String>> providerEntry : ParserProviderManager.getParserMap().entrySet()) {\r |
73 | MenuManager subMenu = new MenuManager(providerEntry.getKey());\r | |
74 | for(Entry<String, String> entry : providerEntry.getValue().entrySet()) {\r | |
75 | params = new HashMap<String, String>();\r | |
3b38ea61 | 76 | params.put("org.eclipse.linuxtools.tmf.ui.commandparameter.project.trace.selectparser.parser", entry.getValue()); //$NON-NLS-1$\r |
abfad0aa | 77 | \r |
15b6d03e FC |
78 | ImageDescriptor icon = null;\r |
79 | if (entry.getValue().equals(parser)) {\r | |
80 | icon = SELECTED_ICON;\r | |
81 | }\r | |
82 | \r | |
3b38ea61 FC |
83 | CommandContributionItemParameter param = new CommandContributionItemParameter(PlatformUI.getWorkbench().getActiveWorkbenchWindow(),\r |
84 | "my.parameterid", //$NON-NLS-1$\r | |
85 | "org.eclipse.linuxtools.tmf.ui.command.project.trace.selectparser", //$NON-NLS-1$\r | |
abfad0aa | 86 | params,\r |
15b6d03e | 87 | icon, // icon\r |
abfad0aa FC |
88 | null, // disabled icon\r |
89 | null, // hover icon\r | |
3b38ea61 | 90 | entry.getKey().replaceAll("&", "&&"), // label //$NON-NLS-1$//$NON-NLS-2$\r |
abfad0aa FC |
91 | null, // mnemonic\r |
92 | null, // tooltip\r | |
93 | CommandContributionItem.STYLE_PUSH,\r | |
94 | null, // help context id\r | |
95 | true // visibleEnable\r | |
96 | );\r | |
97 | \r | |
98 | subMenu.add(new CommandContributionItem(param));\r | |
99 | }\r | |
100 | list.add(subMenu);\r | |
101 | }\r | |
102 | \r | |
103 | return (IContributionItem[]) list.toArray(new IContributionItem[list.size()]);\r | |
104 | }\r | |
105 | \r | |
106 | }\r |