1 11 package org.eclipse.debug.internal.ui.views.console; 12 13 import java.io.IOException ; 14 15 import org.eclipse.core.commands.AbstractHandler; 16 import org.eclipse.core.commands.ExecutionEvent; 17 import org.eclipse.debug.core.DebugEvent; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.IDebugEventSetListener; 20 import org.eclipse.debug.core.ILaunch; 21 import org.eclipse.debug.core.ILaunchConfiguration; 22 import org.eclipse.debug.core.model.IDebugTarget; 23 import org.eclipse.debug.core.model.IProcess; 24 import org.eclipse.debug.core.model.IStreamsProxy; 25 import org.eclipse.debug.core.model.IStreamsProxy2; 26 import org.eclipse.debug.internal.ui.DebugUIPlugin; 27 import org.eclipse.debug.ui.DebugUITools; 28 import org.eclipse.debug.ui.IDebugUIConstants; 29 import org.eclipse.debug.ui.contexts.DebugContextEvent; 30 import org.eclipse.debug.ui.contexts.IDebugContextListener; 31 import org.eclipse.jface.action.IToolBarManager; 32 import org.eclipse.jface.viewers.ISelection; 33 import org.eclipse.jface.viewers.TreePath; 34 import org.eclipse.jface.viewers.TreeSelection; 35 import org.eclipse.ui.IActionBars; 36 import org.eclipse.ui.console.IConsole; 37 import org.eclipse.ui.console.IConsoleConstants; 38 import org.eclipse.ui.console.IConsolePageParticipant; 39 import org.eclipse.ui.console.IConsoleView; 40 import org.eclipse.ui.contexts.IContextActivation; 41 import org.eclipse.ui.contexts.IContextService; 42 import org.eclipse.ui.handlers.IHandlerActivation; 43 import org.eclipse.ui.handlers.IHandlerService; 44 import org.eclipse.ui.part.IPageBookViewPage; 45 import org.eclipse.ui.part.IPageSite; 46 import org.eclipse.ui.part.IShowInSource; 47 import org.eclipse.ui.part.IShowInTargetList; 48 import org.eclipse.ui.part.ShowInContext; 49 50 55 public class ProcessConsolePageParticipant implements IConsolePageParticipant, IShowInSource, IShowInTargetList, IDebugEventSetListener, IDebugContextListener { 56 57 private ConsoleTerminateAction fTerminate; 59 private ConsoleRemoveLaunchAction fRemoveTerminated; 60 private ConsoleRemoveAllTerminatedAction fRemoveAllTerminated; 61 private ShowWhenContentChangesAction fStdOut; 62 private ShowWhenContentChangesAction fStdErr; 63 64 private ProcessConsole fConsole; 65 66 private IPageBookViewPage fPage; 67 68 private IConsoleView fView; 69 70 private EOFHandler fEOFHandler; 71 private String fContextId = "org.eclipse.debug.ui.console"; private IContextActivation fActivatedContext; 73 private IHandlerActivation fActivatedHandler; 74 77 private class EOFHandler extends AbstractHandler { 78 public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { 79 IStreamsProxy proxy = getProcess().getStreamsProxy(); 80 if (proxy instanceof IStreamsProxy2) { 81 IStreamsProxy2 proxy2 = (IStreamsProxy2) proxy; 82 try { 83 proxy2.closeInputStream(); 84 } catch (IOException e1) { 85 } 86 } 87 return null; 88 } 89 90 } 91 92 95 public void init(IPageBookViewPage page, IConsole console) { 96 fPage = page; 97 fConsole = (ProcessConsole) console; 98 99 fRemoveTerminated = new ConsoleRemoveLaunchAction(fConsole.getProcess().getLaunch()); 100 fRemoveAllTerminated = new ConsoleRemoveAllTerminatedAction(); 101 fTerminate = new ConsoleTerminateAction(fConsole); 102 fStdOut = new ShowStandardOutAction(); 103 fStdErr = new ShowStandardErrorAction(); 104 105 fView = (IConsoleView) fPage.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW); 106 107 DebugPlugin.getDefault().addDebugEventListener(this); 108 DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).addDebugContextListener(this); 109 110 IActionBars actionBars = fPage.getSite().getActionBars(); 112 configureToolBar(actionBars.getToolBarManager()); 113 114 fEOFHandler = new EOFHandler(); 116 } 117 118 121 public void dispose() { 122 deactivated(); 123 DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).removeDebugContextListener(this); 124 DebugPlugin.getDefault().removeDebugEventListener(this); 125 if (fRemoveTerminated != null) { 126 fRemoveTerminated.dispose(); 127 fRemoveTerminated = null; 128 } 129 if (fRemoveAllTerminated != null) { 130 fRemoveAllTerminated.dispose(); 131 fRemoveAllTerminated = null; 132 } 133 if (fTerminate != null) { 134 fTerminate.dispose(); 135 fTerminate = null; 136 } 137 if (fStdOut != null) { 138 fStdOut.dispose(); 139 fStdOut = null; 140 } 141 if (fStdErr != null) { 142 fStdErr.dispose(); 143 fStdErr = null; 144 } 145 fConsole = null; 146 } 147 148 151 protected void configureToolBar(IToolBarManager mgr) { 152 mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fTerminate); 153 mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveTerminated); 154 mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveAllTerminated); 155 mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fStdOut); 156 mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fStdErr); 157 } 158 159 162 public Object getAdapter(Class required) { 163 if (IShowInSource.class.equals(required)) { 164 return this; 165 } 166 if (IShowInTargetList.class.equals(required)) { 167 return this; 168 } 169 if(ILaunchConfiguration.class.equals(required)) { 171 ILaunch launch = getProcess().getLaunch(); 172 if(launch != null) { 173 return launch.getLaunchConfiguration(); 174 } 175 return null; 176 } 177 return null; 178 } 179 180 183 public ShowInContext getShowInContext() { 184 IProcess process = getProcess(); 185 if (process == null) { 186 return null; 187 } 188 IDebugTarget target = (IDebugTarget)process.getAdapter(IDebugTarget.class); 189 ISelection selection = null; 190 if (target == null) { 191 selection = new TreeSelection(new TreePath(new Object []{ 192 DebugPlugin.getDefault().getLaunchManager(), 193 process.getLaunch(), 194 process})); 195 } else { 196 selection = new TreeSelection(new TreePath(new Object []{ 197 DebugPlugin.getDefault().getLaunchManager(), 198 target.getLaunch(), 199 target})); 200 } 201 return new ShowInContext(null, selection); 202 } 203 204 207 public String [] getShowInTargetIds() { 208 return new String [] {IDebugUIConstants.ID_DEBUG_VIEW}; 209 } 210 211 214 public void handleDebugEvents(DebugEvent[] events) { 215 for (int i = 0; i < events.length; i++) { 216 DebugEvent event = events[i]; 217 if (event.getSource().equals(getProcess())) { 218 Runnable r = new Runnable () { 219 public void run() { 220 if (fTerminate != null) { 221 fTerminate.update(); 222 } 223 } 224 }; 225 226 DebugUIPlugin.getStandardDisplay().asyncExec(r); 227 } 228 } 229 } 230 231 protected IProcess getProcess() { 232 return fConsole != null ? fConsole.getProcess() : null; 233 } 234 235 238 public void activated() { 239 IPageSite site = fPage.getSite(); 241 IHandlerService handlerService = (IHandlerService)site.getService(IHandlerService.class); 242 IContextService contextService = (IContextService)site.getService(IContextService.class); 243 fActivatedContext = contextService.activateContext(fContextId); 244 fActivatedHandler = handlerService.activateHandler("org.eclipse.debug.ui.commands.eof", fEOFHandler); } 246 247 250 public void deactivated() { 251 IPageSite site = fPage.getSite(); 253 IHandlerService handlerService = (IHandlerService)site.getService(IHandlerService.class); 254 IContextService contextService = (IContextService)site.getService(IContextService.class); 255 handlerService.deactivateHandler(fActivatedHandler); 256 contextService.deactivateContext(fActivatedContext); 257 } 258 259 262 public void debugContextChanged(DebugContextEvent event) { 263 if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { 264 if (fView != null && getProcess().equals(DebugUITools.getCurrentProcess())) { 265 fView.display(fConsole); 266 } 267 } 268 269 } 270 } 271 | Popular Tags |