KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > console > JavaStackTracePageParticipant


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.console;
12
13 import org.eclipse.core.commands.AbstractHandler;
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.core.commands.IHandler;
17 import org.eclipse.jface.action.IToolBarManager;
18 import org.eclipse.ui.IWorkbench;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.console.IConsole;
21 import org.eclipse.ui.console.IConsoleConstants;
22 import org.eclipse.ui.console.IConsolePageParticipant;
23 import org.eclipse.ui.console.actions.CloseConsoleAction;
24 import org.eclipse.ui.contexts.IContextActivation;
25 import org.eclipse.ui.contexts.IContextService;
26 import org.eclipse.ui.handlers.IHandlerActivation;
27 import org.eclipse.ui.handlers.IHandlerService;
28 import org.eclipse.ui.part.IPageBookViewPage;
29
30 /**
31  * JavaStackTracePageParticipant
32  */

33 public class JavaStackTracePageParticipant implements IConsolePageParticipant {
34     
35     private CloseConsoleAction fCloseAction;
36     private FormatStackTraceActionDelegate fFormatAction;
37     private IHandlerActivation fHandlerActivation;
38     private IContextActivation fContextActivation;
39
40     /* (non-Javadoc)
41      * @see org.eclipse.ui.console.IConsolePageParticipant#init(org.eclipse.ui.part.IPageBookViewPage, org.eclipse.ui.console.IConsole)
42      */

43     public void init(IPageBookViewPage page, IConsole console) {
44         fCloseAction = new CloseConsoleAction(console);
45         
46         IToolBarManager manager = page.getSite().getActionBars().getToolBarManager();
47         manager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fCloseAction);
48         
49         fFormatAction = new FormatStackTraceActionDelegate((JavaStackTraceConsole) console);
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.ui.console.IConsolePageParticipant#dispose()
54      */

55     public void dispose() {
56         deactivated();
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
61      */

62     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
63         return null;
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.ui.console.IConsolePageParticipant#activated()
68      */

69     public void activated() {
70         // add EOF submissions
71
IWorkbench workbench = PlatformUI.getWorkbench();
72         IHandlerService handlerService = (IHandlerService) workbench.getAdapter(IHandlerService.class);
73         
74         IHandler formatHandler = new AbstractHandler() {
75             public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
76                 fFormatAction.run(null);
77                 return null;
78             }
79         };
80         
81         fHandlerActivation = handlerService.activateHandler("org.eclipse.jdt.ui.edit.text.java.format", formatHandler); //$NON-NLS-1$
82

83         IContextService contextService = (IContextService) workbench.getAdapter(IContextService.class);
84         fContextActivation = contextService.activateContext("org.eclipse.jdt.ui.javaEditorScope"); //$NON-NLS-1$
85
}
86
87     /* (non-Javadoc)
88      * @see org.eclipse.ui.console.IConsolePageParticipant#deactivated()
89      */

90     public void deactivated() {
91         // remove EOF submissions
92
IWorkbench workbench = PlatformUI.getWorkbench();
93         IHandlerService handlerService = (IHandlerService) workbench.getAdapter(IHandlerService.class);
94         handlerService.deactivateHandler(fHandlerActivation);
95         IContextService contextService = (IContextService) workbench.getAdapter(IContextService.class);
96         contextService.deactivateContext(fContextActivation);
97     }
98
99 }
100
Popular Tags