1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.handlers
;
15 import java
.util
.HashMap
;
16 import java
.util
.LinkedList
;
18 import java
.util
.Map
.Entry
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.core
.runtime
.CoreException
;
22 import org
.eclipse
.jface
.action
.IContributionItem
;
23 import org
.eclipse
.jface
.action
.MenuManager
;
24 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
25 import org
.eclipse
.jface
.viewers
.ISelection
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.ParserProviderManager
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.ProjectView
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfExperimentNode
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfTraceNode
;
32 import org
.eclipse
.ui
.IWorkbenchPage
;
33 import org
.eclipse
.ui
.IWorkbenchWindow
;
34 import org
.eclipse
.ui
.PlatformUI
;
35 import org
.eclipse
.ui
.actions
.CompoundContributionItem
;
36 import org
.eclipse
.ui
.menus
.CommandContributionItem
;
37 import org
.eclipse
.ui
.menus
.CommandContributionItemParameter
;
40 public class SelectParserContributionItem
extends CompoundContributionItem
{
42 private static final ImageDescriptor SELECTED_ICON
= ImageDescriptor
.createFromImage(TmfUiPlugin
.getDefault().getImageFromPath("icons/elcl16/bullet.gif")); //$NON-NLS-1$
45 protected IContributionItem
[] getContributionItems() {
46 Map
<String
, String
> params
;
47 LinkedList
<IContributionItem
> list
= new LinkedList
<IContributionItem
>();
49 ParserProviderManager
.getParserMap();
52 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
53 IWorkbenchPage page
= window
.getActivePage();
54 ISelection selection
= page
.getSelection(ProjectView
.ID
);
55 if (selection
instanceof StructuredSelection
) {
56 Object element
= ((StructuredSelection
) selection
).getFirstElement();
57 if (! (element
instanceof TmfTraceNode
)) {
58 return new IContributionItem
[0];
60 TmfTraceNode trace
= (TmfTraceNode
) element
;
61 IResource resource
= trace
.getResource();
62 if (trace
.getParent() instanceof TmfExperimentNode
) {
63 resource
= trace
.getProject().getTracesFolder().getTraceForLocation(resource
.getLocation()).getResource();
66 parser
= resource
.getPersistentProperty(ParserProviderManager
.PARSER_PROPERTY
);
67 } catch (CoreException e
) {
72 for(Entry
<String
, Map
<String
, String
>> providerEntry
: ParserProviderManager
.getParserMap().entrySet()) {
73 MenuManager subMenu
= new MenuManager(providerEntry
.getKey());
74 for(Entry
<String
, String
> entry
: providerEntry
.getValue().entrySet()) {
75 params
= new HashMap
<String
, String
>();
76 params
.put("org.eclipse.linuxtools.tmf.ui.commandparameter.project.trace.selectparser.parser", entry
.getValue()); //$NON-NLS-1$
78 ImageDescriptor icon
= null;
79 if (entry
.getValue().equals(parser
)) {
83 CommandContributionItemParameter param
= new CommandContributionItemParameter(PlatformUI
.getWorkbench().getActiveWorkbenchWindow(),
84 "my.parameterid", //$NON-NLS-1$
85 "org.eclipse.linuxtools.tmf.ui.command.project.trace.selectparser", //$NON-NLS-1$
88 null, // disabled icon
90 entry
.getKey().replaceAll("&", "&&"), // label //$NON-NLS-1$//$NON-NLS-2$
93 CommandContributionItem
.STYLE_PUSH
,
94 null, // help context id
98 subMenu
.add(new CommandContributionItem(param
));
103 return (IContributionItem
[]) list
.toArray(new IContributionItem
[list
.size()]);