Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c16bd20e0a7a6ce7d6aee495ac2705729878d08e (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
/*******************************************************************************
 * Copyright (c) 2013 Red Hat.
 * 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
 *
 *******************************************************************************/

package org.eclipse.linuxtools.systemtap.ui.consolelog;

import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.contexts.DebugContextEvent;
import org.eclipse.debug.ui.contexts.IDebugContextListener;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.linuxtools.internal.systemtap.ui.consolelog.actions.CloseStapConsoleAction;
import org.eclipse.linuxtools.internal.systemtap.ui.consolelog.actions.SaveLogAction;
import org.eclipse.linuxtools.internal.systemtap.ui.consolelog.actions.StopScriptAction;
import org.eclipse.linuxtools.systemtap.structures.process.SystemTapRuntimeProcessFactory;
import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.ScriptConsole;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.IConsolePageParticipant;
import org.eclipse.ui.console.IConsoleView;
import org.eclipse.ui.part.IPageBookViewPage;

/**
 * This class is responsible for creating and initializing UI for a {@link ScriptConsole}
 * @since 2.0
 */
public class ScriptConsolePageParticipant implements IConsolePageParticipant, IDebugContextListener {

    private IPageBookViewPage fPage;
    private IConsoleView fView;
    private ScriptConsole fConsole;

    @Override
    public <T> T getAdapter(Class<T> adapter) {
        return null;
    }

    @Override
    public void init(IPageBookViewPage page, IConsole iConsole) {
        if (!(iConsole instanceof ScriptConsole)){
            return;
        }

        fPage = page;
        fConsole = (ScriptConsole) iConsole;
        fView = (IConsoleView) fPage.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW);

        StopScriptAction stopScriptAction = new StopScriptAction(fConsole);
        CloseStapConsoleAction closeConsoleAction = new CloseStapConsoleAction(fConsole);
        SaveLogAction saveLogAction = new SaveLogAction(fConsole);

        // contribute to toolbar
        IToolBarManager manager = fPage.getSite().getActionBars().getToolBarManager();
        manager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, stopScriptAction);
        manager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, closeConsoleAction);
        manager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, saveLogAction);

        //TODO if {@link ModifyParsingAction} is restored, it is to be used here,
        //in the same way stopScriptAction and saveLogAction are used.

        DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).addDebugContextListener(this);
    }

    @Override
    public void dispose() {
        DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).removeDebugContextListener(this);
        fConsole = null;
    }

    @Override
    public void activated() {
    }

    @Override
    public void deactivated() {
    }

    /**
     * @since 3.0
     */
    @Override
    public void debugContextChanged(DebugContextEvent event) {
        if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
            if (fView != null && fConsole != null) {
                IProcess process = DebugUITools.getCurrentProcess();
                if (process instanceof SystemTapRuntimeProcessFactory.SystemTapRuntimeProcess
                        && ((SystemTapRuntimeProcessFactory.SystemTapRuntimeProcess) process)
                                .matchesProcess(fConsole.getProcess())) {
                    fView.display(fConsole);
                }
            }
        }
    }

}

Back to the top