Package: ProcessConsolePageParticipant

ProcessConsolePageParticipant

nameinstructionbranchcomplexitylinemethod
ProcessConsolePageParticipant()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
activated()
M: 34 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
configureToolBar(IToolBarManager)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
deactivated()
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
debugContextChanged(DebugContextEvent)
M: 22 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getAdapter(Class)
M: 29 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getProcess()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getShowInContext()
M: 69 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
getShowInTargetIds()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
handleDebugEvents(DebugEvent[])
M: 27 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
init(IPageBookViewPage, IConsole)
M: 54 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.debug.ui;
23:
24: import java.io.IOException;
25:
26: import org.eclipse.core.commands.AbstractHandler;
27: import org.eclipse.core.commands.ExecutionEvent;
28: import org.eclipse.debug.core.DebugEvent;
29: import org.eclipse.debug.core.DebugPlugin;
30: import org.eclipse.debug.core.IDebugEventSetListener;
31: import org.eclipse.debug.core.ILaunch;
32: import org.eclipse.debug.core.ILaunchConfiguration;
33: import org.eclipse.debug.core.model.IDebugTarget;
34: import org.eclipse.debug.core.model.IProcess;
35: import org.eclipse.debug.core.model.IStreamsProxy;
36: import org.eclipse.debug.core.model.IStreamsProxy2;
37: import org.eclipse.debug.internal.ui.DebugUIPlugin;
38: import org.eclipse.debug.ui.DebugUITools;
39: import org.eclipse.debug.ui.IDebugUIConstants;
40: import org.eclipse.debug.ui.contexts.DebugContextEvent;
41: import org.eclipse.debug.ui.contexts.IDebugContextListener;
42: import org.eclipse.jface.action.IToolBarManager;
43: import org.eclipse.jface.viewers.ISelection;
44: import org.eclipse.jface.viewers.TreePath;
45: import org.eclipse.jface.viewers.TreeSelection;
46: import org.eclipse.ui.IActionBars;
47: import org.eclipse.ui.console.IConsole;
48: import org.eclipse.ui.console.IConsoleConstants;
49: import org.eclipse.ui.console.IConsolePageParticipant;
50: import org.eclipse.ui.console.IConsoleView;
51: import org.eclipse.ui.contexts.IContextActivation;
52: import org.eclipse.ui.contexts.IContextService;
53: import org.eclipse.ui.handlers.IHandlerActivation;
54: import org.eclipse.ui.handlers.IHandlerService;
55: import org.eclipse.ui.part.IPageBookViewPage;
56: import org.eclipse.ui.part.IPageSite;
57: import org.eclipse.ui.part.IShowInSource;
58: import org.eclipse.ui.part.IShowInTargetList;
59: import org.eclipse.ui.part.ShowInContext;
60:
61: /**
62: * Creates and manages process console specific actions. This class is a copy of the internal one in eclipse debug
63: *
64: * @since 3.1
65: */
66: public class ProcessConsolePageParticipant implements IConsolePageParticipant,
67:                 IShowInSource, IShowInTargetList, IDebugEventSetListener,
68:                 IDebugContextListener
69: {
70:
71:         // actions
72:         private ConsoleTerminateAction fTerminate;
73:         // private ConsoleRemoveLaunchAction fRemoveTerminated;
74:         // private ConsoleRemoveAllTerminatedAction fRemoveAllTerminated;
75:         // private ShowWhenContentChangesAction fStdOut;
76:         // private ShowWhenContentChangesAction fStdErr;
77:
78:         private VdmDebugConsole fConsole;
79:
80:         private IPageBookViewPage fPage;
81:
82:         private IConsoleView fView;
83:
84:         private EOFHandler fEOFHandler;
85:         private String fContextId = "org.eclipse.debug.ui.console"; //$NON-NLS-1$;
86:         private IContextActivation fActivatedContext;
87:         private IHandlerActivation fActivatedHandler;
88:
89:         /**
90:          * Handler to send EOF
91:          */
92:         private class EOFHandler extends AbstractHandler
93:         {
94:                 public Object execute(ExecutionEvent event)
95:                                 throws org.eclipse.core.commands.ExecutionException
96:                 {
97:                         IStreamsProxy proxy = getProcess().getStreamsProxy();
98:                         if (proxy instanceof IStreamsProxy2)
99:                         {
100:                                 IStreamsProxy2 proxy2 = (IStreamsProxy2) proxy;
101:                                 try
102:                                 {
103:                                         proxy2.closeInputStream();
104:                                 } catch (IOException e1)
105:                                 {
106:                                 }
107:                         }
108:                         return null;
109:                 }
110:
111:         }
112:
113:         /*
114:          * (non-Javadoc)
115:          * @see org.eclipse.ui.console.IConsolePageParticipant#init(IPageBookViewPage, IConsole)
116:          */
117:         public void init(IPageBookViewPage page, IConsole console)
118:         {
119:                 fPage = page;
120:                 fConsole = (VdmDebugConsole) console;
121:
122:                 // fRemoveTerminated = new ConsoleRemoveLaunchAction(fConsole.getProcess().getLaunch());
123:                 // fRemoveAllTerminated = new ConsoleRemoveAllTerminatedAction();
124:                 fTerminate = new ConsoleTerminateAction(page.getSite().getWorkbenchWindow(), fConsole);
125:                 // fStdOut = new ShowStandardOutAction();
126:                 // fStdErr = new ShowStandardErrorAction();
127:
128:                 fView = (IConsoleView) fPage.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW);
129:
130:                 DebugPlugin.getDefault().addDebugEventListener(this);
131:                 DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).addDebugContextListener(this);
132:
133:                 // contribute to toolbar
134:                 IActionBars actionBars = fPage.getSite().getActionBars();
135:                 configureToolBar(actionBars.getToolBarManager());
136:
137:                 // create handler and submissions for EOF
138:                 fEOFHandler = new EOFHandler();
139:         }
140:
141:         /*
142:          * (non-Javadoc)
143:          * @see org.eclipse.ui.console.IConsolePageParticipant#dispose()
144:          */
145:         public void dispose()
146:         {
147:                 DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).removeDebugContextListener(this);
148:                 DebugPlugin.getDefault().removeDebugEventListener(this);
149:                 // if (fRemoveTerminated != null) {
150:                 // fRemoveTerminated.dispose();
151:                 // fRemoveTerminated = null;
152:                 // }
153:                 // if (fRemoveAllTerminated != null) {
154:                 // fRemoveAllTerminated.dispose();
155:                 // fRemoveAllTerminated = null;
156:                 // }
157:•                if (fTerminate != null)
158:                 {
159:                         fTerminate.dispose();
160:                         fTerminate = null;
161:                 }
162:                 // if (fStdOut != null) {
163:                 // fStdOut.dispose();
164:                 // fStdOut = null;
165:                 // }
166:                 // if (fStdErr != null) {
167:                 // fStdErr.dispose();
168:                 // fStdErr = null;
169:                 // }
170:                 fConsole = null;
171:         }
172:
173:         /**
174:          * Contribute actions to the toolbar
175:          */
176:         protected void configureToolBar(IToolBarManager mgr)
177:         {
178:                 mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fTerminate);
179:                 // mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveTerminated);
180:                 // mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveAllTerminated);
181:                 // mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fStdOut);
182:                 // mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fStdErr);
183:         }
184:
185:         /*
186:          * (non-Javadoc)
187:          * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
188:          */
189:         public Object getAdapter(Class required)
190:         {
191:•                if (IShowInSource.class.equals(required))
192:                 {
193:                         return this;
194:                 }
195:•                if (IShowInTargetList.class.equals(required))
196:                 {
197:                         return this;
198:                 }
199:                 // CONTEXTLAUNCHING
200:•                if (ILaunchConfiguration.class.equals(required))
201:                 {
202:                         ILaunch launch = getProcess().getLaunch();
203:•                        if (launch != null)
204:                         {
205:                                 return launch.getLaunchConfiguration();
206:                         }
207:                         return null;
208:                 }
209:                 return null;
210:         }
211:
212:         /*
213:          * (non-Javadoc)
214:          * @see org.eclipse.ui.part.IShowInSource#getShowInContext()
215:          */
216:         public ShowInContext getShowInContext()
217:         {
218:                 IProcess process = getProcess();
219:•                if (process == null)
220:                 {
221:                         return null;
222:                 }
223:                 IDebugTarget target = (IDebugTarget) process.getAdapter(IDebugTarget.class);
224:                 ISelection selection = null;
225:•                if (target == null)
226:                 {
227:                         selection = new TreeSelection(new TreePath(new Object[] {
228:                                         DebugPlugin.getDefault().getLaunchManager(),
229:                                         process.getLaunch(), process }));
230:                 } else
231:                 {
232:                         selection = new TreeSelection(new TreePath(new Object[] {
233:                                         DebugPlugin.getDefault().getLaunchManager(),
234:                                         target.getLaunch(), target }));
235:                 }
236:                 return new ShowInContext(null, selection);
237:         }
238:
239:         /*
240:          * (non-Javadoc)
241:          * @see org.eclipse.ui.part.IShowInTargetList#getShowInTargetIds()
242:          */
243:         public String[] getShowInTargetIds()
244:         {
245:                 return new String[] { IDebugUIConstants.ID_DEBUG_VIEW };
246:         }
247:
248:         /*
249:          * (non-Javadoc)
250:          * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
251:          */
252:         public void handleDebugEvents(DebugEvent[] events)
253:         {
254:•                for (int i = 0; i < events.length; i++)
255:                 {
256:                         DebugEvent event = events[i];
257:•                        if (event.getSource().equals(getProcess()))
258:                         {
259:                                 Runnable r = new Runnable()
260:                                 {
261:                                         public void run()
262:                                         {
263:                                                 if (fTerminate != null)
264:                                                 {
265:                                                         fTerminate.update();
266:                                                 }
267:                                                 if (fView != null)
268:                                                         fView.display(fConsole);
269:                                         }
270:                                 };
271:
272:                                 DebugUIPlugin.getStandardDisplay().asyncExec(r);
273:                         }
274:                 }
275:         }
276:
277:         protected IProcess getProcess()
278:         {
279:•                return fConsole != null ? fConsole.getProcess() : null;
280:         }
281:
282:         /*
283:          * (non-Javadoc)
284:          * @see org.eclipse.ui.console.IConsolePageParticipant#activated()
285:          */
286:         public void activated()
287:         {
288:                 // add EOF submissions
289:                 IPageSite site = fPage.getSite();
290:•                if (fActivatedContext == null && fActivatedHandler == null)
291:                 {
292:                         IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
293:                         IContextService contextService = (IContextService) site.getService(IContextService.class);
294:                         fActivatedContext = contextService.activateContext(fContextId);
295:                         fActivatedHandler = handlerService.activateHandler("org.eclipse.debug.ui.commands.eof", fEOFHandler); //$NON-NLS-1$
296:                 }
297:         }
298:
299:         /*
300:          * (non-Javadoc)
301:          * @see org.eclipse.ui.console.IConsolePageParticipant#deactivated()
302:          */
303:         public void deactivated()
304:         {
305:                 // remove EOF submissions
306:                 IPageSite site = fPage.getSite();
307:                 IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
308:                 IContextService contextService = (IContextService) site.getService(IContextService.class);
309:                 handlerService.deactivateHandler(fActivatedHandler);
310:                 contextService.deactivateContext(fActivatedContext);
311:                 fActivatedContext = null;
312:                 fActivatedHandler = null;
313:         }
314:
315:         /*
316:          * (non-Javadoc)
317:          * @see
318:          * org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextListener#contextEvent(org.eclipse.debug.internal
319:          * .ui.contexts.provisional.DebugContextEvent)
320:          */
321:         public void debugContextChanged(DebugContextEvent event)
322:         {
323:•                if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0)
324:                 {
325:•                        if (fView != null && getProcess()!=null
326:•                                        && getProcess().equals(DebugUITools.getCurrentProcess()))
327:                         {
328:                                 fView.display(fConsole);
329:                         }
330:                 }
331:
332:         }
333: }