1    	package acl2s.plugin.console;
2    	
3    	import java.io.IOException;
4    	
5    	import org.eclipse.ui.console.ConsolePlugin;
6    	import org.eclipse.ui.console.IConsole;
7    	import org.eclipse.ui.console.IConsoleManager;
8    	import org.eclipse.ui.console.IOConsole;
9    	import org.peterd.util.ExceptionHandler;
10   	
11   	public class MyConsole extends IOConsole implements ExceptionHandler<IOException> {
12   		protected IOException exception = null;
13   		
14   		protected MyConsolePageParticipant pp = null;
15   		
16   		protected MyConsole() {
17   			super("", MyConsole.class.getName(), null);
18   		}
19   		
20   		protected void setPageParticipant(MyConsolePageParticipant pp) {
21   			this.pp = pp;
22   		}
23   		
24   		public synchronized final void handleException(IOException e) {
25   			if (exception != null) {
26   				doHandleException(e);
27   			}
28   		}
29   	
30   		protected synchronized void doHandleException(IOException e) {
31   			exception = e;
32   		}
33   	
34   		public void add() {
35   			add(this);
36   		}
37   		
38   		public void remove() {
39   			remove(this);
40   		}
41   		
42   		public void show() {
43   			show(this);
44   		}
45   		
46   		
47   		// STATIC STUFF
48   		
49   		public static <T extends IIdentifiableConsole>  T find(Class<T> typ, Object id) {
50   			IConsoleManager conman = getConsoleManager();
51   			synchronized (conman) {
52   				for (IConsole c : conman.getConsoles()) {
53   					if (typ.isInstance(c)) {
54   						IIdentifiableConsole ic = (IIdentifiableConsole) c;
Event use_ref_eq: You should use "==" here instead of "equals(...)". [10/12 equality checks]
Also see events: [ref_eq_use][ref_eq_use][ref_eq_use][ref_eq_use][ref_eq_use]
55   						if (ic.getIdentity().equals(id)) {
56   							return typ.cast(ic);
57   						}
58   					}
59   				}
60   				return null;
61   			}
62   		}
63   	
64   		public static <T extends IFinishableConsole> T removeIfFinished(T c) {
65   			if (c == null) {
66   				return null;
67   			} else if (c.finished()) {
68   				remove(c);
69   				return null;
70   			} else {
71   				return c;
72   			}
73   		}
74   		
75   		public static IConsoleManager getConsoleManager() {
76   			return ConsolePlugin.getDefault().getConsoleManager();
77   		}
78   	
79   		public static void add(IConsole c) {
80   			IConsoleManager conman = getConsoleManager();
81   			synchronized (conman) {
82   				conman.addConsoles(new IConsole[] { c });
83   			}
84   		}
85   		
86   		public static void remove(IConsole c) {
87   			IConsoleManager conman = getConsoleManager();
88   			synchronized (conman) {
89   				conman.removeConsoles(new IConsole[] { c });
90   			}
91   		}
92   		
93   		public static void show(IConsole c) {
94   			IConsoleManager conman = getConsoleManager();
95   			synchronized (conman) {
96   				conman.showConsoleView(c);
97   			}
98   		}
99   	}