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.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;
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;
24 public class PHPOpenDeclarationAction extends SelectionDispatchAction {
25 private IWorkbenchWindow fWindow;
27 private PHPEditor fEditor;
29 public void dispose() {
32 public PHPOpenDeclarationAction(IWorkbenchSite site) {
34 // setText(ActionMessages.getString("OpenAction.label")); //$NON-NLS-1$
35 // setToolTipText(ActionMessages.getString("OpenAction.tooltip"));
37 // setDescription(ActionMessages.getString("OpenAction.description"));
39 // WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_ACTION);
43 * Note: This constructor is for internal use only. Clients should not call
46 public PHPOpenDeclarationAction(PHPEditor editor) {
47 this(editor.getEditorSite());
49 // setText(ActionMessages.getString("OpenAction.declaration.label"));
51 setEnabled(SelectionConverter.canOperateOn(fEditor));
54 public void init(IWorkbenchWindow window) {
55 this.fWindow = window;
58 public void selectionChanged(IAction action, ISelection selection) {
59 if (!selection.isEmpty()) {
60 if (selection instanceof TextSelection) {
61 action.setEnabled(true);
62 } else if (fWindow.getActivePage() != null
63 && fWindow.getActivePage().getActivePart() != null) {
69 private boolean checkEnabled(IStructuredSelection selection) {
70 if (selection.isEmpty())
76 * (non-Javadoc) Method declared on SelectionDispatchAction.
78 public void run(ITextSelection selection) {
79 if (!ActionUtil.isProcessable(getShell(), fEditor))
81 OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(
83 openAction.openSelectedElement(selection);
87 * (non-Javadoc) Method declared on SelectionDispatchAction.
89 public void run(IStructuredSelection selection) {
90 if (!checkEnabled(selection))
92 run(selection.toArray());
96 * Note: this method is for internal use only. Clients should not call this
99 public void run(Object[] elements) {
100 if (elements != null && elements.length > 0) {
101 ITextSelection selection = (ITextSelection) fEditor
102 .getSelectionProvider().getSelection();
103 IDocument doc = fEditor.getDocumentProvider().getDocument(
104 fEditor.getEditorInput());
105 int pos = selection.getOffset();
107 OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(
109 openAction.openSelectedPosition(doc, pos);