statesystem: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.rcp.ui / src / org / eclipse / tracecompass / internal / tracing / rcp / ui / ApplicationWorkbenchWindowAdvisor.java
CommitLineData
9c0ffa34 1/**********************************************************************
19d855ca 2 * Copyright (c) 2013, 2015 Ericsson
9c0ffa34
BH
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
19d855ca 11 * Marc-Andre Laperle - Bug 459835
9c0ffa34 12 **********************************************************************/
9d26aebf 13package org.eclipse.tracecompass.internal.tracing.rcp.ui;
9c0ffa34 14
977ca87f 15import org.eclipse.core.resources.IProject;
76fccfb0 16import org.eclipse.core.runtime.CoreException;
9c0ffa34 17import org.eclipse.core.runtime.NullProgressMonitor;
9d26aebf 18import org.eclipse.tracecompass.internal.tracing.rcp.ui.cli.CliParser;
2bdf0193
AM
19import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
20import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper;
21import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
22import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder;
9c0ffa34
BH
23import org.eclipse.ui.IPerspectiveDescriptor;
24import org.eclipse.ui.IPerspectiveListener;
25import org.eclipse.ui.IWorkbenchPage;
26import org.eclipse.ui.application.ActionBarAdvisor;
27import org.eclipse.ui.application.IActionBarConfigurer;
28import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
29import org.eclipse.ui.application.WorkbenchWindowAdvisor;
30
31/**
32 * The WorkbenchAdvisor implementation of the LTTng RCP.
33 *
34 * @author Bernd Hufmann
35 */
36public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
37
38 // ------------------------------------------------------------------------
39 // Constants
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"
66 };
67
9c0ffa34
BH
68 // ------------------------------------------------------------------------
69 // Constructors
70 // ------------------------------------------------------------------------
71
72 /**
73 * Standard constructor
76fccfb0 74 *
9c0ffa34 75 * @param configurer
76fccfb0 76 * - the workbench window configurer
9c0ffa34
BH
77 */
78 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
79 super(configurer);
80 }
81
82 // ------------------------------------------------------------------------
83 // Operations
84 // ------------------------------------------------------------------------
85 @Override
86 public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
87 return new ApplicationActionBarAdvisor(configurer);
88 }
89
90 @Override
91 public void preWindowOpen() {
92 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
93 configurer.setShowCoolBar(false);
94 configurer.setShowStatusLine(true);
95 configurer.setShowProgressIndicator(true);
9c0ffa34
BH
96 }
97
98 @Override
99 public void postWindowCreate() {
100 super.postWindowOpen();
101 TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new PerspectiveListener());
977ca87f 102 IProject defaultProject = createDefaultProject();
9c0ffa34 103 hideActionSets();
977ca87f 104 openTraceIfNecessary(defaultProject);
76fccfb0
MK
105 }
106
107
108
977ca87f 109 private static void openTraceIfNecessary(IProject project) {
76fccfb0 110 String traceToOpen = TracingRcpPlugin.getDefault().getCli().getArgument(CliParser.OPEN_FILE_LOCATION);
19d855ca
MAL
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
8d96cb20 113 if ((traceToOpen != null) && traceToOpen.startsWith("~/") && (userHome != null)) { //$NON-NLS-1$
19d855ca
MAL
114 traceToOpen = traceToOpen.replaceFirst("^~", userHome); //$NON-NLS-1$
115 }
116
76fccfb0 117 if (traceToOpen != null) {
76fccfb0 118 try {
8405b756 119 TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
977ca87f 120 TmfOpenTraceHelper.openTraceFromPath(destinationFolder, traceToOpen, TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
76fccfb0
MK
121 } catch (CoreException e) {
122 TracingRcpPlugin.getDefault().logError(e.getMessage());
123 }
124
125 }
9c0ffa34
BH
126 }
127
128 // ------------------------------------------------------------------------
129 // Helper methods
130 // ------------------------------------------------------------------------
131
132 /**
133 * Hides the unwanted action sets
134 */
135 private static void hideActionSets() {
136
137 IWorkbenchPage page = TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
138
139 for (int i = 0; i < UNWANTED_ACTION_SET.length; i++) {
140 page.hideActionSet(UNWANTED_ACTION_SET[i]);
141 }
142 }
143
977ca87f
PT
144 private static IProject createDefaultProject() {
145 return TmfProjectRegistry.createProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, new NullProgressMonitor());
9c0ffa34
BH
146 }
147
148 /**
76fccfb0
MK
149 * A perspective listener implementation
150 *
151 * @author Bernd Hufmann
9c0ffa34
BH
152 */
153 public class PerspectiveListener implements IPerspectiveListener {
154
155 /**
76fccfb0 156 * Default Constructor
9c0ffa34
BH
157 */
158 public PerspectiveListener() {
159 }
160
161 @Override
162 public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
163 createDefaultProject();
164 hideActionSets();
165 }
166
167 @Override
168 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
169 }
170 }
171
172}
This page took 0.066081 seconds and 5 git commands to generate.