tmf: Move default tracing project name to common constants
[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.tmf.core.TmfCommonConstants;
22 import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider;
23 import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
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 }
99
100 @Override
101 public void postWindowCreate() {
102 super.postWindowOpen();
103 TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new PerspectiveListener());
104 createDefaultProject();
105 hideActionSets();
106 openTraceIfNecessary();
107 }
108
109
110
111 private static void openTraceIfNecessary() {
112 String traceToOpen = TracingRcpPlugin.getDefault().getCli().getArgument(CliParser.OPEN_FILE_LOCATION);
113 if (traceToOpen != null) {
114 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
115 final IWorkspaceRoot root = workspace.getRoot();
116 IProject project = root.getProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME);
117 final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
118 ncp.getChildren( project ); // force the model to be populated
119 TmfOpenTraceHelper oth = new TmfOpenTraceHelper();
120 try {
121 oth.openTraceFromPath(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME,traceToOpen, TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
122 } catch (CoreException e) {
123 TracingRcpPlugin.getDefault().logError(e.getMessage());
124 }
125
126 }
127 }
128
129 // ------------------------------------------------------------------------
130 // Helper methods
131 // ------------------------------------------------------------------------
132
133 /**
134 * Hides the unwanted action sets
135 */
136 private static void hideActionSets() {
137
138 IWorkbenchPage page = TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
139
140 for (int i = 0; i < UNWANTED_ACTION_SET.length; i++) {
141 page.hideActionSet(UNWANTED_ACTION_SET[i]);
142 }
143 }
144
145 private static void createDefaultProject() {
146 TmfProjectRegistry.createProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, new NullProgressMonitor());
147 }
148
149 /**
150 * A perspective listener implementation
151 *
152 * @author Bernd Hufmann
153 */
154 public class PerspectiveListener implements IPerspectiveListener {
155
156 /**
157 * Default Constructor
158 */
159 public PerspectiveListener() {
160 }
161
162 @Override
163 public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
164 createDefaultProject();
165 hideActionSets();
166 }
167
168 @Override
169 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
170 }
171 }
172
173 }
This page took 0.035302 seconds and 6 git commands to generate.