KickJava   Java API By Example, From Geeks To Geeks.

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


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.IDebugElement;
15 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
16 import org.eclipse.debug.internal.ui.DebugUIPlugin;
17 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
18 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19 import org.eclipse.debug.internal.ui.views.launch.LaunchView;
20 import org.eclipse.debug.ui.DebugUITools;
21 import org.eclipse.debug.ui.sourcelookup.SourceLookupDialog;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.jface.viewers.IStructuredSelection;
24 import org.eclipse.jface.window.Window;
25 import org.eclipse.swt.widgets.Shell;
26 import org.eclipse.ui.IWorkbenchPage;
27 import org.eclipse.ui.PlatformUI;
28 import org.eclipse.ui.actions.SelectionListenerAction;
29
30 /**
31  * The action for editing the source lookup path. Brings up the
32  * EditSourceLookupPathDialog.
33  *
34  * @since 3.0
35  */

36 public class EditSourceLookupPathAction extends SelectionListenerAction {
37     
38     private ISourceLookupDirector director = null;
39     private LaunchView fView = null;
40     
41     public EditSourceLookupPathAction(LaunchView view) {
42         super(SourceLookupUIMessages.EditSourceLookupPathAction_0);
43         setEnabled(false);
44         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.EDIT_SOURCELOOKUP_ACTION);
45         setImageDescriptor(DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_SRC_LOOKUP_MENU));
46         fView = view;
47     }
48     
49     /* (non-Javadoc)
50      * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
51      */

52     protected boolean updateSelection(IStructuredSelection selection) {
53         director = null;
54         if (selection.size() == 1) {
55             Object JavaDoc object = selection.getFirstElement();
56             ILaunch launch = null;
57             if (object instanceof IDebugElement) {
58                 launch = ((IDebugElement)object).getLaunch();
59             } else if (object instanceof ILaunch) {
60                 launch = (ILaunch)object;
61             }
62             if (launch != null && launch.getLaunchConfiguration() != null &&
63                     launch.getSourceLocator() instanceof ISourceLookupDirector) {
64                 director = (ISourceLookupDirector) launch.getSourceLocator();
65             }
66         }
67         return director != null;
68     }
69     /* (non-Javadoc)
70      * @see org.eclipse.jface.action.IAction#run()
71      */

72     public void run() {
73         Shell shell = DebugUIPlugin.getShell();
74         SourceLookupDialog dialog = new SourceLookupDialog(shell, director);
75         if (dialog.open() == Window.OK) {
76             ISelection selection = fView.getViewer().getSelection();
77             if (selection instanceof IStructuredSelection) {
78                 IStructuredSelection ss = (IStructuredSelection) selection;
79                 if (ss.size() == 1) {
80                     IWorkbenchPage page = fView.getSite().getPage();
81                     SourceLookupManager.getDefault().displaySource(ss.getFirstElement(), page, true);
82                 }
83             }
84         }
85     }
86 }
87
Popular Tags