Skip to main content
summaryrefslogtreecommitdiffstats
blob: c5abe9a2533c7f5b65b0bcf0334dc3d1cc852a39 (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
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.views.console;

import java.text.MessageFormat;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.internal.ui.DebugPluginImages;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.console.AbstractConsole;
import org.eclipse.debug.internal.ui.console.IConsoleView;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.part.IPageBookViewPage;

/**
 * A console for a system process
 * <p>
 * Clients may instantiate this class. This class is not intended for
 * sub-classing.
 * </p>
 * @since 3.0
 */
public class ProcessConsole extends AbstractConsole implements IDebugEventSetListener {
	
	private IProcess fProcess = null;

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.console.IConsole#createPage(org.eclipse.debug.internal.ui.console.IConsoleView)
	 */
	public IPageBookViewPage createPage(IConsoleView view) {
		return new ProcessConsolePage(view, this);
	}

	/**
	 * Computes and returns the image descriptor for this console.
	 * 
	 * @return an image descriptor for this console or <code>null</code>
	 */
	protected ImageDescriptor computeImageDescriptor() {
		ILaunchConfiguration configuration = getProcess().getLaunch().getLaunchConfiguration();
		if (configuration != null) {
			ILaunchConfigurationType type;
			try {
				type = configuration.getType();
				return DebugPluginImages.getImageDescriptor(type.getIdentifier());
			} catch (CoreException e) {
				DebugUIPlugin.log(e);
			}
		}
		return null;
	}

	/**
	 * Computes and returns the current name of this console.
	 * 
	 * @return a name for this console
	 */
	protected String computeName() {	
		ILaunchConfiguration configuration = getProcess().getLaunch().getLaunchConfiguration(); 
		if (configuration != null) {
			if (getProcess().isTerminated()) {
				return MessageFormat.format(ConsoleMessages.getString("ProcessConsole.0"), new String[]{configuration.getName()}); //$NON-NLS-1$
			} else {
				return configuration.getName();
			}
		}
		if (getProcess().isTerminated()) {
			return MessageFormat.format(ConsoleMessages.getString("ProcessConsole.0"), new String[]{getProcess().getLabel()}); //$NON-NLS-1$
		} else {
			return getProcess().getLabel();
		}
	}

	/**
	 * Proxy to a console document
	 */
	public ProcessConsole(IProcess process) {
		super("", null); //$NON-NLS-1$
		fProcess = process;
		setName(computeName());
		setImageDescriptor(computeImageDescriptor());
	}
			
	/**
	 * Returns the process associated with this console.
	 * 
	 * @return the process associated with this console
	 */
	public IProcess getProcess() {
		return fProcess;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.console.AbstractConsole#dispose()
	 */
	protected void dispose() {
		super.dispose();
		DebugPlugin.getDefault().removeDebugEventListener(this);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.console.AbstractConsole#init()
	 */
	protected void init() {
		super.init();
		DebugPlugin.getDefault().addDebugEventListener(this);
	}
	
	/**
	 * Notify listeners when name changes.
	 * 
	 * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
	 */
	public void handleDebugEvents(DebugEvent[] events) {
		for (int i = 0; i < events.length; i++) {
			DebugEvent event = events[i];
			if (event.getSource().equals(getProcess())) {
				Runnable r = new Runnable() {
					public void run() {
						setName(computeName());
					}
				};	
				DebugUIPlugin.getStandardDisplay().asyncExec(r);
			}
		}
	}
}

Back to the top