1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.core.IJavaProject;
15 //import net.sourceforge.phpdt.core.IPackageFragment;
16 //import net.sourceforge.phpdt.core.IPackageFragmentRoot;
17 //import net.sourceforge.phpdt.internal.corext.refactoring.util.ResourceUtil;
18 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
22 //import org.eclipse.core.resources.IFolder;
23 import org.eclipse.core.resources.IProject;
24 import org.eclipse.core.resources.IProjectNature;
25 //import org.eclipse.core.resources.IResource;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.jface.dialogs.MessageDialog;
28 import org.eclipse.swt.widgets.Shell;
31 * http://dev.eclipse.org/bugs/show_bug.cgi?id=19104
33 public class ActionUtil {
35 private ActionUtil() {
38 // bug 31998 we will have to disable renaming of linked packages (and cus)
39 // public static boolean mustDisableJavaModelAction(Shell shell, Object element) {
40 // if (!(element instanceof IPackageFragment)
41 // && !(element instanceof IPackageFragmentRoot))
44 // IResource resource = ResourceUtil.getResource(element);
45 // if ((resource == null) || (!(resource instanceof IFolder))
46 // || (!resource.isLinked()))
52 // ActionMessages.getString("ActionUtil.not_possible"), ActionMessages.getString("ActionUtil.no_linked")); //$NON-NLS-1$ //$NON-NLS-2$
56 public static boolean isProcessable(Shell shell, PHPEditor editor) {
59 IJavaElement input = SelectionConverter.getInput(editor);
60 // if a Java editor doesn't have an input of type Java element
61 // then it is for sure not on the build path
63 MessageDialog.openInformation(shell, ActionMessages
64 .getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
66 .getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
69 return isProcessable(shell, input);
72 public static boolean isProcessable(Shell shell, Object element) {
73 if (!(element instanceof IJavaElement))
76 if (isOnBuildPath((IJavaElement) element))
78 MessageDialog.openInformation(shell, ActionMessages
79 .getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
80 ActionMessages.getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
84 public static boolean isOnBuildPath(IJavaElement element) {
85 // fix for bug http://dev.eclipse.org/bugs/show_bug.cgi?id=20051
86 if (element.getElementType() == IJavaElement.JAVA_PROJECT)
88 IJavaProject project = element.getJavaProject();
90 // if (!project.isOnClasspath(element))
92 IProject resourceProject = project.getProject();
93 if (resourceProject == null)
95 IProjectNature nature = resourceProject
96 .getNature(PHPeclipsePlugin.PHP_NATURE_ID);
97 // We have a Java project
100 } catch (CoreException e) {