KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > LookupSourceAction


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 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.debug.internal.ui.sourcelookup;
12
13 import org.eclipse.debug.core.ILaunch;
14 import org.eclipse.debug.core.model.IStackFrame;
15 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
16 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
17 import org.eclipse.debug.internal.ui.views.launch.LaunchView;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.ui.IWorkbenchPage;
21 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.ui.actions.SelectionListenerAction;
23
24 /**
25  * Does source lookup for the selected stack frame again.
26  *
27  * @since 3.0
28  */

29 public class LookupSourceAction extends SelectionListenerAction {
30     
31     private ISourceLookupDirector director = null;
32     private LaunchView fView = null;
33     private IStackFrame frame = null;
34     
35     public LookupSourceAction(LaunchView view) {
36         super(SourceLookupUIMessages.LookupSourceAction_0);
37         setEnabled(false);
38         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.LOOKUP_SOURCE_ACTION);
39         fView = view;
40     }
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
44      */

45     protected boolean updateSelection(IStructuredSelection selection) {
46         director = null;
47         frame = null;
48         if (selection.size() == 1) {
49             Object JavaDoc object = selection.getFirstElement();
50             if (object instanceof IStackFrame) {
51                 frame = (IStackFrame)object;
52                 ILaunch launch = frame.getLaunch();
53                 if (launch != null && launch.getLaunchConfiguration() != null &&
54                         launch.getSourceLocator() instanceof ISourceLookupDirector) {
55                     director = (ISourceLookupDirector) launch.getSourceLocator();
56                 }
57             }
58         }
59         return director != null;
60     }
61     /* (non-Javadoc)
62      * @see org.eclipse.jface.action.IAction#run()
63      */

64     public void run() {
65         ISelection selection = fView.getViewer().getSelection();
66         if (selection instanceof IStructuredSelection) {
67             IStructuredSelection ss = (IStructuredSelection) selection;
68             if (ss.size() == 1) {
69                 IWorkbenchPage page = fView.getSite().getPage();
70                 SourceLookupManager.getDefault().displaySource(ss.getFirstElement(), page, true);
71             }
72         }
73     }
74 }
75
Popular Tags