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.phpeditor.PHPEditor;
21 import org.eclipse.core.resources.IFolder;
22 import org.eclipse.core.resources.IProject;
23 import org.eclipse.core.resources.IProjectNature;
24 import org.eclipse.core.resources.IResource;
25 import org.eclipse.core.runtime.CoreException;
26 import org.eclipse.jface.dialogs.MessageDialog;
27 import org.eclipse.swt.widgets.Shell;
30 * http://dev.eclipse.org/bugs/show_bug.cgi?id=19104
32 public class ActionUtil {
37 //bug 31998 we will have to disable renaming of linked packages (and cus)
38 public static boolean mustDisableJavaModelAction(Shell shell, Object element) {
39 if (!(element instanceof IPackageFragment) && !(element instanceof IPackageFragmentRoot))
42 IResource resource= ResourceUtil.getResource(element);
43 if ((resource == null) || (! (resource instanceof IFolder)) || (! resource.isLinked()))
46 MessageDialog.openInformation(shell, ActionMessages.getString("ActionUtil.not_possible"), ActionMessages.getString("ActionUtil.no_linked")); //$NON-NLS-1$ //$NON-NLS-2$
50 public static boolean isProcessable(Shell shell, PHPEditor editor) {
53 IJavaElement input= SelectionConverter.getInput(editor);
54 // if a Java editor doesn't have an input of type Java element
55 // then it is for sure not on the build path
57 MessageDialog.openInformation(shell,
58 ActionMessages.getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
59 ActionMessages.getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
62 return isProcessable(shell, input);
65 public static boolean isProcessable(Shell shell, Object element) {
66 if (!(element instanceof IJavaElement))
69 if (isOnBuildPath((IJavaElement)element))
71 MessageDialog.openInformation(shell,
72 ActionMessages.getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
73 ActionMessages.getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
77 public static boolean isOnBuildPath(IJavaElement element) {
78 //fix for bug http://dev.eclipse.org/bugs/show_bug.cgi?id=20051
79 if (element.getElementType() == IJavaElement.JAVA_PROJECT)
81 IJavaProject project= element.getJavaProject();
83 // if (!project.isOnClasspath(element))
85 IProject resourceProject= project.getProject();
86 if (resourceProject == null)
88 IProjectNature nature= resourceProject.getNature(PHPeclipsePlugin.PHP_NATURE_ID);
89 // We have a Java project
92 } catch (CoreException e) {