Adding new code for feature save on unfocus. This is from ticket #542. It also adds...
[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
23                 IEditorActionDelegate {
24         private IWorkbenchWindow fWindow;
25
26         private PHPEditor fEditor;
27
28         public void init(IWorkbenchWindow window) {
29                 this.fWindow = window;
30         }
31
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) {
38                                 //
39                         }
40                 }
41         }
42
43         private boolean checkEnabled(IStructuredSelection selection) {
44                 if (selection.isEmpty())
45                         return false;
46                 return true;
47         }
48
49         public void run(IAction action) {
50                 if (fEditor == null) {
51                         IEditorPart targetEditor = fWindow.getActivePage()
52                                         .getActiveEditor();
53                         if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
54                                 fEditor = (PHPEditor) targetEditor;
55                         }
56                 }
57                 if (fEditor != null) {
58                         ITextSelection selection = (ITextSelection) fEditor
59                                         .getSelectionProvider().getSelection();
60                         OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(
61                                         fEditor);
62                         openAction.openSelectedElement(selection);
63                 }
64         }
65
66         public void setActiveEditor(IAction action, IEditorPart targetEditor) {
67                 if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
68                         fEditor = (PHPEditor) targetEditor;
69                 }
70         }
71
72 }