KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > selectionactions > StructureSelectEnclosingAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.ui.javaeditor.selectionactions;
12
13 import org.eclipse.ui.PlatformUI;
14
15 import org.eclipse.jdt.core.ISourceRange;
16 import org.eclipse.jdt.core.ISourceReference;
17 import org.eclipse.jdt.core.JavaModelException;
18 import org.eclipse.jdt.core.dom.ASTNode;
19
20 import org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer;
21
22 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
23 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
24
25 public class StructureSelectEnclosingAction extends StructureSelectionAction {
26
27     public StructureSelectEnclosingAction(JavaEditor editor, SelectionHistory history) {
28         super(SelectionActionMessages.StructureSelectEnclosing_label, editor, history);
29         setToolTipText(SelectionActionMessages.StructureSelectEnclosing_tooltip);
30         setDescription(SelectionActionMessages.StructureSelectEnclosing_description);
31         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.STRUCTURED_SELECT_ENCLOSING_ACTION);
32     }
33
34     /*
35      * This constructor is for testing purpose only.
36      */

37     public StructureSelectEnclosingAction() {
38     }
39
40     /*
41      * @see StructureSelectionAction#internalGetNewSelectionRange(ISourceRange, ICompilationUnit, SelectionAnalyzer)
42      */

43     ISourceRange internalGetNewSelectionRange(ISourceRange oldSourceRange, ISourceReference sr, SelectionAnalyzer selAnalyzer) throws JavaModelException{
44         ASTNode first= selAnalyzer.getFirstSelectedNode();
45         if (first == null || first.getParent() == null)
46             return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer);
47
48         return getSelectedNodeSourceRange(sr, first.getParent());
49     }
50 }
51
Popular Tags