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")); //$NON-NLS-1$
36 // setDescription(ActionMessages.getString("OpenAction.description")); //$NON-NLS-1$
37 // WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_ACTION);
41 * Note: This constructor is for internal use only. Clients should not call this constructor.
43 public PHPOpenDeclarationAction(PHPEditor editor) {
44 this(editor.getEditorSite());
46 // setText(ActionMessages.getString("OpenAction.declaration.label")); //$NON-NLS-1$
47 setEnabled(SelectionConverter.canOperateOn(fEditor));
50 public void init(IWorkbenchWindow window) {
51 this.fWindow = window;
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) {
64 private boolean checkEnabled(IStructuredSelection selection) {
65 if (selection.isEmpty())
71 * (non-Javadoc) Method declared on SelectionDispatchAction.
73 public void run(ITextSelection selection) {
74 if (!ActionUtil.isProcessable(getShell(), fEditor))
76 OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(fEditor);
77 openAction.openSelectedElement(selection);
81 * (non-Javadoc) Method declared on SelectionDispatchAction.
83 public void run(IStructuredSelection selection) {
84 if (!checkEnabled(selection))
86 run(selection.toArray());
90 * Note: this method is for internal use only. Clients should not call this method.
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();
98 OpenDeclarationEditorAction openAction = new OpenDeclarationEditorAction(fEditor);
99 openAction.openSelectedPosition(doc, pos);