tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tracing.rcp.ui / src / org / eclipse / linuxtools / internal / tracing / rcp / ui / ApplicationWorkbenchWindowAdvisor.java
1 /**********************************************************************
2 * Copyright (c) 2013, 2014 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 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.internal.tracing.rcp.ui;
13
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.NullProgressMonitor;
17 import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.CliParser;
18 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
19 import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
20 import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
21 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
22 import org.eclipse.ui.IPerspectiveDescriptor;
23 import org.eclipse.ui.IPerspectiveListener;
24 import org.eclipse.ui.IWorkbenchPage;
25 import org.eclipse.ui.application.ActionBarAdvisor;
26 import org.eclipse.ui.application.IActionBarConfigurer;
27 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
28 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
29
30 /**
31 * The WorkbenchAdvisor implementation of the LTTng RCP.
32 *
33 * @author Bernd Hufmann
34 */
35 public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
36
37 // ------------------------------------------------------------------------
38 // Constants
39 // ------------------------------------------------------------------------
40 @SuppressWarnings("nls")
41 private static final String[] UNWANTED_ACTION_SET = {
42 "org.eclipse.search.searchActionSet",
43 "org.eclipse.rse.core.search.searchActionSet",
44 "org.eclipse.debug.ui.launchActionSet",
45 "org.eclipse.debug.ui.debugActionSet",
46 "org.eclipse.debug.ui.breakpointActionSet",
47 "org.eclipse.team.ui",
48 "org.eclipse.ui.externaltools.ExternalToolsSet",
49 // "org.eclipse.update.ui.softwareUpdates",
50 // "org.eclipse.ui.edit.text.actionSet.navigation",
51 // "org.eclipse.ui.actionSet.keyBindings",
52 // "org.eclipse.ui.edit.text.actionSet.navigation",
53 "org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
54 // "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
55 // "org.eclipse.ui.NavigateActionSet",
56 // "org.eclipse.jdt.ui.JavaActionSet",
57 // "org.eclipse.jdt.ui.A_OpenActionSet",
58 // "org.eclipse.jdt.ui.text.java.actionSet.presentation",
59 // "org.eclipse.jdt.ui.JavaElementCreationActionSet",
60 // "org.eclipse.jdt.ui.CodingActionSet",
61 // "org.eclipse.jdt.ui.SearchActionSet",
62 // "org.eclipse.jdt.debug.ui.JDTDebugActionSet",
63 "org.eclipse.ui.edit.text.actionSet.openExternalFile",
64 // "org.eclipse.debug.ui.profileActionSet"
65 };
66
67 // ------------------------------------------------------------------------
68 // Constructors
69 // ------------------------------------------------------------------------
70
71 /**
72 * Standard constructor
73 *
74 * @param configurer
75 * - the workbench window configurer
76 */
77 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
78 super(configurer);
79 }
80
81 // ------------------------------------------------------------------------
82 // Operations
83 // ------------------------------------------------------------------------
84 @Override
85 public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
86 return new ApplicationActionBarAdvisor(configurer);
87 }
88
89 @Override
90 public void preWindowOpen() {
91 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
92 configurer.setShowCoolBar(false);
93 configurer.setShowStatusLine(true);
94 configurer.setShowProgressIndicator(true);
95 }
96
97 @Override
98 public void postWindowCreate() {
99 super.postWindowOpen();
100 TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new PerspectiveListener());
101 IProject defaultProject = createDefaultProject();
102 hideActionSets();
103 openTraceIfNecessary(defaultProject);
104 }
105
106
107
108 private static void openTraceIfNecessary(IProject project) {
109 String traceToOpen = TracingRcpPlugin.getDefault().getCli().getArgument(CliParser.OPEN_FILE_LOCATION);
110 if (traceToOpen != null) {
111 try {
112 TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
113 TmfOpenTraceHelper.openTraceFromPath(destinationFolder, traceToOpen, TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
114 } catch (CoreException e) {
115 TracingRcpPlugin.getDefault().logError(e.getMessage());
116 }
117
118 }
119 }
120
121 // ------------------------------------------------------------------------
122 // Helper methods
123 // ------------------------------------------------------------------------
124
125 /**
126 * Hides the unwanted action sets
127 */
128 private static void hideActionSets() {
129
130 IWorkbenchPage page = TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
131
132 for (int i = 0; i < UNWANTED_ACTION_SET.length; i++) {
133 page.hideActionSet(UNWANTED_ACTION_SET[i]);
134 }
135 }
136
137 private static IProject createDefaultProject() {
138 return TmfProjectRegistry.createProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, new NullProgressMonitor());
139 }
140
141 /**
142 * A perspective listener implementation
143 *
144 * @author Bernd Hufmann
145 */
146 public class PerspectiveListener implements IPerspectiveListener {
147
148 /**
149 * Default Constructor
150 */
151 public PerspectiveListener() {
152 }
153
154 @Override
155 public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
156 createDefaultProject();
157 hideActionSets();
158 }
159
160 @Override
161 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
162 }
163 }
164
165 }
This page took 0.040417 seconds and 5 git commands to generate.