Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5e8f830446f47adee8e339db2b0f42176417e390 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**********************************************************************
 * Copyright (c) 2013, 2014 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Bernd Hufmann - Initial API and implementation
 **********************************************************************/
package org.eclipse.linuxtools.internal.tracing.rcp.ui;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.CliParser;
import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

/**
 * The WorkbenchAdvisor implementation of the LTTng RCP.
 *
 * @author Bernd Hufmann
 */
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

    // ------------------------------------------------------------------------
    // Constants
    // ------------------------------------------------------------------------
    @SuppressWarnings("nls")
    private static final String[] UNWANTED_ACTION_SET = {
        "org.eclipse.search.searchActionSet",
        "org.eclipse.rse.core.search.searchActionSet",
        "org.eclipse.debug.ui.launchActionSet",
        "org.eclipse.debug.ui.debugActionSet",
        "org.eclipse.debug.ui.breakpointActionSet",
        "org.eclipse.team.ui",
        "org.eclipse.ui.externaltools.ExternalToolsSet",
//        "org.eclipse.update.ui.softwareUpdates",
//        "org.eclipse.ui.edit.text.actionSet.navigation",
//        "org.eclipse.ui.actionSet.keyBindings",
//        "org.eclipse.ui.edit.text.actionSet.navigation",
        "org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
//        "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
//        "org.eclipse.ui.NavigateActionSet",
//        "org.eclipse.jdt.ui.JavaActionSet",
//        "org.eclipse.jdt.ui.A_OpenActionSet",
//        "org.eclipse.jdt.ui.text.java.actionSet.presentation",
//        "org.eclipse.jdt.ui.JavaElementCreationActionSet",
//        "org.eclipse.jdt.ui.CodingActionSet",
//        "org.eclipse.jdt.ui.SearchActionSet",
//        "org.eclipse.jdt.debug.ui.JDTDebugActionSet",
        "org.eclipse.ui.edit.text.actionSet.openExternalFile",
//        "org.eclipse.debug.ui.profileActionSet"
    };

    // ------------------------------------------------------------------------
    // Constructors
    // ------------------------------------------------------------------------

    /**
     * Standard constructor
     *
     * @param configurer
     *            - the workbench window configurer
     */
    public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
    }

    // ------------------------------------------------------------------------
    // Operations
    // ------------------------------------------------------------------------
    @Override
    public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
        return new ApplicationActionBarAdvisor(configurer);
    }

    @Override
    public void preWindowOpen() {
        IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
        configurer.setShowCoolBar(false);
        configurer.setShowStatusLine(true);
        configurer.setShowProgressIndicator(true);
    }

    @Override
    public void postWindowCreate() {
        super.postWindowOpen();
        TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new PerspectiveListener());
        IProject defaultProject = createDefaultProject();
        hideActionSets();
        openTraceIfNecessary(defaultProject);
    }



    private static void openTraceIfNecessary(IProject project) {
        String traceToOpen = TracingRcpPlugin.getDefault().getCli().getArgument(CliParser.OPEN_FILE_LOCATION);
        if (traceToOpen != null) {
            try {
                TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
                TmfOpenTraceHelper.openTraceFromPath(destinationFolder, traceToOpen, TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
            } catch (CoreException e) {
                TracingRcpPlugin.getDefault().logError(e.getMessage());
            }

        }
    }

    // ------------------------------------------------------------------------
    // Helper methods
    // ------------------------------------------------------------------------

    /**
     * Hides the unwanted action sets
     */
    private static void hideActionSets() {

        IWorkbenchPage page = TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();

        for (int i = 0; i < UNWANTED_ACTION_SET.length; i++) {
            page.hideActionSet(UNWANTED_ACTION_SET[i]);
        }
    }

    private static IProject createDefaultProject() {
        return TmfProjectRegistry.createProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, new NullProgressMonitor());
    }

    /**
     * A perspective listener implementation
     *
     * @author Bernd Hufmann
     */
    public class PerspectiveListener implements IPerspectiveListener {

        /**
         * Default Constructor
         */
        public PerspectiveListener() {
        }

        @Override
        public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
            createDefaultProject();
            hideActionSets();
        }

        @Override
        public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
        }
    }

}

Back to the top