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