KickJava   Java API By Example, From Geeks To Geeks.

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


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.ui.javaeditor.selectionactions;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jface.action.Action;
16
17 import org.eclipse.ui.PlatformUI;
18 import org.eclipse.ui.texteditor.IUpdate;
19
20 import org.eclipse.jdt.core.ISourceRange;
21
22 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
23 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
24
25 public class StructureSelectHistoryAction extends Action implements IUpdate {
26     private JavaEditor fEditor;
27     private SelectionHistory fHistory;
28
29     public StructureSelectHistoryAction(JavaEditor editor, SelectionHistory history) {
30         super(SelectionActionMessages.StructureSelectHistory_label);
31         setToolTipText(SelectionActionMessages.StructureSelectHistory_tooltip);
32         setDescription(SelectionActionMessages.StructureSelectHistory_description);
33         Assert.isNotNull(history);
34         Assert.isNotNull(editor);
35         fHistory= history;
36         fEditor= editor;
37         update();
38         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.STRUCTURED_SELECTION_HISTORY_ACTION);
39     }
40
41     public void update() {
42         setEnabled(!fHistory.isEmpty());
43     }
44
45     public void run() {
46         ISourceRange old= fHistory.getLast();
47         if (old != null) {
48             try {
49                 fHistory.ignoreSelectionChanges();
50                 fEditor.selectAndReveal(old.getOffset(), old.getLength());
51             } finally {
52                 fHistory.listenToSelectionChanges();
53             }
54         }
55     }
56 }
57
Popular Tags