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
 
  23                 IEditorActionDelegate {
 
  24         private IWorkbenchWindow fWindow;
 
  26         private PHPEditor fEditor;
 
  28         public void init(IWorkbenchWindow window) {
 
  29                 this.fWindow = window;
 
  32         public void selectionChanged(IAction action, ISelection selection) {
 
  33                 if (!selection.isEmpty()) {
 
  34                         if (selection instanceof TextSelection) {
 
  35                                 action.setEnabled(true);
 
  36                         } else if (fWindow.getActivePage() != null
 
  37                                         && fWindow.getActivePage().getActivePart() != null) {
 
  43 //      private boolean checkEnabled(IStructuredSelection selection) {
 
  44 //              if (selection.isEmpty())
 
  49         public void run(IAction action) {
 
  50                 if (fEditor == null) {
 
  51                         IEditorPart targetEditor = fWindow.getActivePage()
 
  53                         if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
 
  54                                 fEditor = (PHPEditor) targetEditor;
 
  57                 if (fEditor != null) {
 
  58                         ITextSelection selection = (ITextSelection) fEditor
 
  59                                         .getSelectionProvider().getSelection();
 
  60                         OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(
 
  62                         openAction.openSelectedElement(selection);
 
  66         public void setActiveEditor(IAction action, IEditorPart targetEditor) {
 
  67                 if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
 
  68                         fEditor = (PHPEditor) targetEditor;