1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: www.phpeclipse.de
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpeclipse.actions;
10 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
12 import org.eclipse.jface.action.IAction;
13 import org.eclipse.jface.text.ITextSelection;
14 import org.eclipse.jface.text.TextSelection;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.ui.IEditorActionDelegate;
18 import org.eclipse.ui.IEditorPart;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.actions.ActionDelegate;
22 public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IEditorActionDelegate {
23 private IWorkbenchWindow fWindow;
25 private PHPEditor fEditor;
27 public void init(IWorkbenchWindow window) {
28 this.fWindow = window;
31 public void selectionChanged(IAction action, ISelection selection) {
32 if (!selection.isEmpty()) {
33 if (selection instanceof TextSelection) {
34 action.setEnabled(true);
35 } else if (fWindow.getActivePage() != null && fWindow.getActivePage().getActivePart() != null) {
41 private boolean checkEnabled(IStructuredSelection selection) {
42 if (selection.isEmpty())
47 public void run(IAction action) {
48 if (fEditor == null) {
49 IEditorPart targetEditor = fWindow.getActivePage().getActiveEditor();
50 if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
51 fEditor = (PHPEditor) targetEditor;
54 if (fEditor != null) {
55 ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
56 OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(fEditor);
57 openAction.openSelectedElement(selection);
61 public void setActiveEditor(IAction action, IEditorPart targetEditor) {
62 if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
63 fEditor = (PHPEditor) targetEditor;