1 11 package org.eclipse.team.internal.ccvs.core.client; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.team.internal.ccvs.core.client.listeners.IConsoleListener; 20 21 25 public class ConsoleListeners implements IConsoleListener { 26 27 private static ConsoleListeners instance = new ConsoleListeners(); 28 private Set listeners = new HashSet (); 29 30 34 public static ConsoleListeners getInstance() { 35 return instance; 36 } 37 38 public void addListener(IConsoleListener listener) { 39 synchronized(listeners) { 40 listeners.add(listener); 41 } 42 } 43 44 public void removeListener(IConsoleListener listener) { 45 synchronized(listeners) { 46 listeners.remove(listener); 47 } 48 } 49 50 private IConsoleListener[] getListeners() { 51 synchronized(listeners) { 52 return (IConsoleListener[]) listeners.toArray(new IConsoleListener[listeners.size()]); 53 } 54 } 55 56 59 public void commandInvoked(final Session session, final String line) { 60 if (listeners.isEmpty()) return; 61 IConsoleListener[] listeners = getListeners(); 62 for (int i = 0; i < listeners.length; i++) { 63 final IConsoleListener listener = listeners[i]; 64 Platform.run(new ISafeRunnable() { 65 public void handleException(Throwable exception) { 66 } 68 public void run() throws Exception { 69 listener.commandInvoked(session, line); 70 } 71 }); 72 } 73 } 74 75 78 public void messageLineReceived(final Session session, final String line, final IStatus status) { 79 if (listeners.isEmpty()) return; 80 IConsoleListener[] listeners = getListeners(); 81 for (int i = 0; i < listeners.length; i++) { 82 final IConsoleListener listener = listeners[i]; 83 Platform.run(new ISafeRunnable() { 84 public void handleException(Throwable exception) { 85 } 87 public void run() throws Exception { 88 listener.messageLineReceived(session, line, status); 89 } 90 }); 91 } 92 } 93 94 97 public void errorLineReceived(final Session session, final String line, final IStatus status) { 98 if (listeners.isEmpty()) return; 99 IConsoleListener[] listeners = getListeners(); 100 for (int i = 0; i < listeners.length; i++) { 101 final IConsoleListener listener = listeners[i]; 102 Platform.run(new ISafeRunnable() { 103 public void handleException(Throwable exception) { 104 } 106 public void run() throws Exception { 107 listener.errorLineReceived(session, line, status); 108 } 109 }); 110 } 111 } 112 113 116 public void commandCompleted(final Session session, final IStatus status, final Exception exception) { 117 if (listeners.isEmpty()) return; 118 IConsoleListener[] listeners = getListeners(); 119 for (int i = 0; i < listeners.length; i++) { 120 final IConsoleListener listener = listeners[i]; 121 Platform.run(new ISafeRunnable() { 122 public void handleException(Throwable exception) { 123 } 125 public void run() throws Exception { 126 listener.commandCompleted(session, status, exception); 127 } 128 }); 129 } 130 } 131 } 132 | Popular Tags |