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 {
34 private 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)
40 && !(element instanceof IPackageFragmentRoot))
43 IResource resource = ResourceUtil.getResource(element);
44 if ((resource == null) || (!(resource instanceof IFolder))
45 || (!resource.isLinked()))
51 ActionMessages.getString("ActionUtil.not_possible"), ActionMessages.getString("ActionUtil.no_linked")); //$NON-NLS-1$ //$NON-NLS-2$
55 public static boolean isProcessable(Shell shell, PHPEditor editor) {
58 IJavaElement input = SelectionConverter.getInput(editor);
59 // if a Java editor doesn't have an input of type Java element
60 // then it is for sure not on the build path
62 MessageDialog.openInformation(shell, ActionMessages
63 .getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
65 .getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
68 return isProcessable(shell, input);
71 public static boolean isProcessable(Shell shell, Object element) {
72 if (!(element instanceof IJavaElement))
75 if (isOnBuildPath((IJavaElement) element))
77 MessageDialog.openInformation(shell, ActionMessages
78 .getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
79 ActionMessages.getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
83 public static boolean isOnBuildPath(IJavaElement element) {
84 // fix for bug http://dev.eclipse.org/bugs/show_bug.cgi?id=20051
85 if (element.getElementType() == IJavaElement.JAVA_PROJECT)
87 IJavaProject project = element.getJavaProject();
89 // if (!project.isOnClasspath(element))
91 IProject resourceProject = project.getProject();
92 if (resourceProject == null)
94 IProjectNature nature = resourceProject
95 .getNature(PHPeclipsePlugin.PHP_NATURE_ID);
96 // We have a Java project
99 } catch (CoreException e) {