Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f9ee5e7816cadcf6f3198c9ba6ba2d04bd440145 (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
/*******************************************************************************
 * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.ui.views.monitor.events;

import java.util.EventObject;

import org.eclipse.core.runtime.Assert;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.te.tcf.log.core.events.MonitorEvent;
import org.eclipse.tcf.te.tcf.ui.views.monitor.console.Console;
import org.eclipse.tcf.te.tcf.ui.views.monitor.console.Factory;
import org.eclipse.tcf.te.ui.events.AbstractEventListener;

/**
 * Communication monitor console event listener
 */
public class EventListener extends AbstractEventListener {

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.interfaces.events.IEventListener#eventFired(java.util.EventObject)
	 */
	@Override
	public void eventFired(EventObject event) {
		if (event instanceof MonitorEvent) {
			MonitorEvent monitorEvent = (MonitorEvent)event;

			// Get the event simulator and message
			MonitorEvent.Type type = monitorEvent.getType();
			MonitorEvent.Message message = monitorEvent.getMessage();

			switch (type) {
				case CLOSE:
					// Channel close messages are logged only if there is an error
					if (message != null && message.text != null && !message.text.contains("(error=null)")) { //$NON-NLS-1$
						// Get the console
						Console console = Factory.getConsole((IPeer)monitorEvent.getSource(), true);
						Assert.isNotNull(console);
						// Message type 'X' is an unknown type and will lead to print the
						// message text using the error color.
						console.appendMessage('X', message.text);
					}
					break;
				case ACTIVITY:
					if (message != null) {
						// Get the console
						Console console = Factory.getConsole((IPeer)monitorEvent.getSource(), true);
						Assert.isNotNull(console);
						console.appendMessage(message.type, message.text);
					}
					break;
				case OPEN:
				default:
					break;
			}
		}
	}

}

Back to the top