* Added browser like links (Ctrl+Mouseclick on identifier; same as F3 shortcut)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPOpenDeclarationEditorAction.java
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
5  * 
6  * Contributors: www.phpeclipse.de
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpeclipse.actions;
9
10 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
11
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;
21
22 public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IEditorActionDelegate {
23   private IWorkbenchWindow fWindow;
24
25   private PHPEditor fEditor;
26
27   public void init(IWorkbenchWindow window) {
28     this.fWindow = window;
29   }
30
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) {
36         //
37       }
38     }
39   }
40
41   private boolean checkEnabled(IStructuredSelection selection) {
42     if (selection.isEmpty())
43       return false;
44     return true;
45   }
46  
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;
52       }
53     }
54     if (fEditor != null) {
55       ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
56       OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(fEditor);
57       openAction.openSelectedElement(selection);
58     }
59   }
60
61   public void setActiveEditor(IAction action, IEditorPart targetEditor) {
62     if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
63       fEditor = (PHPEditor) targetEditor;
64     }
65   }
66
67 }