* Added browser like links (Ctrl+Mouseclick on identifier; same as F3 shortcut)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPOpenDeclarationAction.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.phpdt.internal.ui.actions.ActionUtil;
11 import net.sourceforge.phpdt.internal.ui.actions.SelectionConverter;
12 import net.sourceforge.phpdt.ui.actions.SelectionDispatchAction;
13 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
14
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.text.IDocument;
17 import org.eclipse.jface.text.ITextSelection;
18 import org.eclipse.jface.text.TextSelection;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.ui.IWorkbenchSite;
22 import org.eclipse.ui.IWorkbenchWindow;
23
24 public class PHPOpenDeclarationAction extends SelectionDispatchAction {
25   private IWorkbenchWindow fWindow;
26
27   private PHPEditor fEditor;
28
29   public void dispose() {
30   }
31
32   public PHPOpenDeclarationAction(IWorkbenchSite site) {
33     super(site);
34     //  setText(ActionMessages.getString("OpenAction.label")); //$NON-NLS-1$
35     //  setToolTipText(ActionMessages.getString("OpenAction.tooltip")); //$NON-NLS-1$
36     //  setDescription(ActionMessages.getString("OpenAction.description")); //$NON-NLS-1$
37     //  WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_ACTION);
38   }
39   
40   /**
41    * Note: This constructor is for internal use only. Clients should not call this constructor.
42    */
43   public PHPOpenDeclarationAction(PHPEditor editor) {
44     this(editor.getEditorSite());
45     fEditor = editor;
46     //          setText(ActionMessages.getString("OpenAction.declaration.label")); //$NON-NLS-1$
47     setEnabled(SelectionConverter.canOperateOn(fEditor));
48   }
49   
50   public void init(IWorkbenchWindow window) {
51     this.fWindow = window;
52   }
53
54   public void selectionChanged(IAction action, ISelection selection) {
55     if (!selection.isEmpty()) {
56       if (selection instanceof TextSelection) {
57         action.setEnabled(true);
58       } else if (fWindow.getActivePage() != null && fWindow.getActivePage().getActivePart() != null) {
59         //
60       }
61     }
62   }
63
64   private boolean checkEnabled(IStructuredSelection selection) {
65     if (selection.isEmpty())
66       return false;
67     return true;
68   }
69
70   /*
71    * (non-Javadoc) Method declared on SelectionDispatchAction.
72    */
73   public void run(ITextSelection selection) {
74     if (!ActionUtil.isProcessable(getShell(), fEditor))
75       return;
76     OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(fEditor);
77     openAction.openSelectedElement(selection);
78   }
79
80   /*
81    * (non-Javadoc) Method declared on SelectionDispatchAction.
82    */
83   public void run(IStructuredSelection selection) {
84     if (!checkEnabled(selection))
85       return;
86     run(selection.toArray());
87   }
88
89   /**
90    * Note: this method is for internal use only. Clients should not call this method.
91    */
92   public void run(Object[] elements) {
93     if (elements != null && elements.length > 0) {
94       ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
95       IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
96       int pos = selection.getOffset();
97
98       OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(fEditor);
99       openAction.openSelectedPosition(doc, pos);
100     }
101   }
102
103 }