rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / rcp / org.eclipse.tracecompass.rcp.ui / src / org / eclipse / tracecompass / internal / tracing / rcp / ui / ApplicationWorkbenchWindowAdvisor.java
1 /**********************************************************************
2 * Copyright (c) 2013, 2015 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 * Marc-Andre Laperle - Bug 459835
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.tracing.rcp.ui;
14
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;
30
31 /**
32 * The WorkbenchAdvisor implementation of the LTTng RCP.
33 *
34 * @author Bernd Hufmann
35 */
36 public 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
68 // ------------------------------------------------------------------------
69 // Constructors
70 // ------------------------------------------------------------------------
71
72 /**
73 * Standard constructor
74 *
75 * @param configurer
76 * - the workbench window configurer
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);
96 }
97
98 @Override
99 public void postWindowCreate() {
100 super.postWindowOpen();
101 TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new PerspectiveListener());
102 IProject defaultProject = createDefaultProject();
103 hideActionSets();
104 openTraceIfNecessary(defaultProject);
105 }
106
107
108
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$
115 }
116
117 if (traceToOpen != null) {
118 try {
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());
123 }
124
125 }
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
144 private static IProject createDefaultProject() {
145 return TmfProjectRegistry.createProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, new NullProgressMonitor());
146 }
147
148 /**
149 * A perspective listener implementation
150 *
151 * @author Bernd Hufmann
152 */
153 public class PerspectiveListener implements IPerspectiveListener {
154
155 /**
156 * Default Constructor
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.037372 seconds and 5 git commands to generate.