01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.javaeditor.selectionactions;
11:
12: import org.eclipse.core.runtime.Assert;
13:
14: import org.eclipse.jface.action.Action;
15:
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.texteditor.IUpdate;
18:
19: import org.eclipse.jdt.core.ISourceRange;
20:
21: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
22: import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
23:
24: public class StructureSelectHistoryAction extends Action implements
25: IUpdate {
26: private JavaEditor fEditor;
27: private SelectionHistory fHistory;
28:
29: public StructureSelectHistoryAction(JavaEditor editor,
30: SelectionHistory history) {
31: super (SelectionActionMessages.StructureSelectHistory_label);
32: setToolTipText(SelectionActionMessages.StructureSelectHistory_tooltip);
33: setDescription(SelectionActionMessages.StructureSelectHistory_description);
34: Assert.isNotNull(history);
35: Assert.isNotNull(editor);
36: fHistory = history;
37: fEditor = editor;
38: update();
39: PlatformUI
40: .getWorkbench()
41: .getHelpSystem()
42: .setHelp(
43: this ,
44: IJavaHelpContextIds.STRUCTURED_SELECTION_HISTORY_ACTION);
45: }
46:
47: public void update() {
48: setEnabled(!fHistory.isEmpty());
49: }
50:
51: public void run() {
52: ISourceRange old = fHistory.getLast();
53: if (old != null) {
54: try {
55: fHistory.ignoreSelectionChanges();
56: fEditor.selectAndReveal(old.getOffset(), old
57: .getLength());
58: } finally {
59: fHistory.listenToSelectionChanges();
60: }
61: }
62: }
63: }
|