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