1 /**********************************************************************
2 * Copyright (c) 2013, 2015 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 * Bernd Hufmann - Initial API and implementation
11 * Marc-Andre Laperle - Bug 459835
12 **********************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tracing
.rcp
.ui
;
15 import org
.eclipse
.core
.resources
.IProject
;
16 import org
.eclipse
.core
.runtime
.CoreException
;
17 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
18 import org
.eclipse
.tracecompass
.internal
.tracing
.rcp
.ui
.cli
.CliParser
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.TmfCommonConstants
;
20 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfOpenTraceHelper
;
21 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectRegistry
;
22 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceFolder
;
23 import org
.eclipse
.ui
.IPerspectiveDescriptor
;
24 import org
.eclipse
.ui
.IPerspectiveListener
;
25 import org
.eclipse
.ui
.IWorkbenchPage
;
26 import org
.eclipse
.ui
.application
.ActionBarAdvisor
;
27 import org
.eclipse
.ui
.application
.IActionBarConfigurer
;
28 import org
.eclipse
.ui
.application
.IWorkbenchWindowConfigurer
;
29 import org
.eclipse
.ui
.application
.WorkbenchWindowAdvisor
;
32 * The WorkbenchAdvisor implementation of the LTTng RCP.
34 * @author Bernd Hufmann
36 public class ApplicationWorkbenchWindowAdvisor
extends WorkbenchWindowAdvisor
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
41 @SuppressWarnings("nls")
42 private static final String
[] UNWANTED_ACTION_SET
= {
43 "org.eclipse.search.searchActionSet",
44 "org.eclipse.rse.core.search.searchActionSet",
45 "org.eclipse.debug.ui.launchActionSet",
46 "org.eclipse.debug.ui.debugActionSet",
47 "org.eclipse.debug.ui.breakpointActionSet",
48 "org.eclipse.team.ui",
49 "org.eclipse.ui.externaltools.ExternalToolsSet",
50 // "org.eclipse.update.ui.softwareUpdates",
51 // "org.eclipse.ui.edit.text.actionSet.navigation",
52 // "org.eclipse.ui.actionSet.keyBindings",
53 // "org.eclipse.ui.edit.text.actionSet.navigation",
54 "org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
55 // "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
56 // "org.eclipse.ui.NavigateActionSet",
57 // "org.eclipse.jdt.ui.JavaActionSet",
58 // "org.eclipse.jdt.ui.A_OpenActionSet",
59 // "org.eclipse.jdt.ui.text.java.actionSet.presentation",
60 // "org.eclipse.jdt.ui.JavaElementCreationActionSet",
61 // "org.eclipse.jdt.ui.CodingActionSet",
62 // "org.eclipse.jdt.ui.SearchActionSet",
63 // "org.eclipse.jdt.debug.ui.JDTDebugActionSet",
64 "org.eclipse.ui.edit.text.actionSet.openExternalFile",
65 // "org.eclipse.debug.ui.profileActionSet"
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * Standard constructor
76 * - the workbench window configurer
78 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer
) {
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
86 public ActionBarAdvisor
createActionBarAdvisor(IActionBarConfigurer configurer
) {
87 return new ApplicationActionBarAdvisor(configurer
);
91 public void preWindowOpen() {
92 IWorkbenchWindowConfigurer configurer
= getWindowConfigurer();
93 configurer
.setShowCoolBar(false);
94 configurer
.setShowStatusLine(true);
95 configurer
.setShowProgressIndicator(true);
99 public void postWindowCreate() {
100 super.postWindowOpen();
101 TracingRcpPlugin
.getDefault().getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new PerspectiveListener());
102 IProject defaultProject
= createDefaultProject();
104 openTraceIfNecessary(defaultProject
);
109 private static void openTraceIfNecessary(IProject project
) {
110 String traceToOpen
= TracingRcpPlugin
.getDefault().getCli().getArgument(CliParser
.OPEN_FILE_LOCATION
);
111 String userHome
= System
.getProperty("user.home"); //$NON-NLS-1$
112 // In case the application was not started on the shell, expand ~ to home directory
113 if ((traceToOpen
!= null) && traceToOpen
.startsWith("~/") && (userHome
!= null)) { //$NON-NLS-1$
114 traceToOpen
= traceToOpen
.replaceFirst("^~", userHome
); //$NON-NLS-1$
117 if (traceToOpen
!= null) {
119 TmfTraceFolder destinationFolder
= TmfProjectRegistry
.getProject(project
, true).getTracesFolder();
120 TmfOpenTraceHelper
.openTraceFromPath(destinationFolder
, traceToOpen
, TracingRcpPlugin
.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
121 } catch (CoreException e
) {
122 TracingRcpPlugin
.getDefault().logError(e
.getMessage());
128 // ------------------------------------------------------------------------
130 // ------------------------------------------------------------------------
133 * Hides the unwanted action sets
135 private static void hideActionSets() {
137 IWorkbenchPage page
= TracingRcpPlugin
.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
139 for (int i
= 0; i
< UNWANTED_ACTION_SET
.length
; i
++) {
140 page
.hideActionSet(UNWANTED_ACTION_SET
[i
]);
144 private static IProject
createDefaultProject() {
145 return TmfProjectRegistry
.createProject(TmfCommonConstants
.DEFAULT_TRACE_PROJECT_NAME
, null, new NullProgressMonitor());
149 * A perspective listener implementation
151 * @author Bernd Hufmann
153 public class PerspectiveListener
implements IPerspectiveListener
{
156 * Default Constructor
158 public PerspectiveListener() {
162 public void perspectiveActivated(IWorkbenchPage page
, IPerspectiveDescriptor perspective
) {
163 createDefaultProject();
168 public void perspectiveChanged(IWorkbenchPage page
, IPerspectiveDescriptor perspective
, String changeId
) {