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;
 
  21 import net.sourceforge.phpeclipse.ui.WebUI;
 
  23 import org.eclipse.core.resources.IFolder;
 
  24 import org.eclipse.core.resources.IProject;
 
  25 import org.eclipse.core.resources.IProjectNature;
 
  26 import org.eclipse.core.resources.IResource;
 
  27 import org.eclipse.core.runtime.CoreException;
 
  28 import org.eclipse.jface.dialogs.MessageDialog;
 
  29 import org.eclipse.swt.widgets.Shell;
 
  32  * http://dev.eclipse.org/bugs/show_bug.cgi?id=19104
 
  34 public class ActionUtil {
 
  36         private ActionUtil() {
 
  39         // bug 31998 we will have to disable renaming of linked packages (and cus)
 
  40         public static boolean mustDisableJavaModelAction(Shell shell, Object element) {
 
  41                 if (!(element instanceof IPackageFragment)
 
  42                                 && !(element instanceof IPackageFragmentRoot))
 
  45                 IResource resource = ResourceUtil.getResource(element);
 
  46                 if ((resource == null) || (!(resource instanceof IFolder))
 
  47                                 || (!resource.isLinked()))
 
  53                                                 ActionMessages.getString("ActionUtil.not_possible"), ActionMessages.getString("ActionUtil.no_linked")); //$NON-NLS-1$ //$NON-NLS-2$
 
  57         public static boolean isProcessable(Shell shell, PHPEditor editor) {
 
  60                 IJavaElement input = SelectionConverter.getInput(editor);
 
  61                 // if a Java editor doesn't have an input of type Java element
 
  62                 // then it is for sure not on the build path
 
  64                         MessageDialog.openInformation(shell, ActionMessages
 
  65                                         .getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
 
  67                                                         .getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
 
  70                 return isProcessable(shell, input);
 
  73         public static boolean isProcessable(Shell shell, Object element) {
 
  74                 if (!(element instanceof IJavaElement))
 
  77                 if (isOnBuildPath((IJavaElement) element))
 
  79                 MessageDialog.openInformation(shell, ActionMessages
 
  80                                 .getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
 
  81                                 ActionMessages.getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
 
  85         public static boolean isOnBuildPath(IJavaElement element) {
 
  86                 // fix for bug http://dev.eclipse.org/bugs/show_bug.cgi?id=20051
 
  87                 if (element.getElementType() == IJavaElement.JAVA_PROJECT)
 
  89                 IJavaProject project = element.getJavaProject();
 
  91                         // if (!project.isOnClasspath(element))
 
  93                         IProject resourceProject = project.getProject();
 
  94                         if (resourceProject == null)
 
  96                         IProjectNature nature = resourceProject
 
  97                                         .getNature(/*WebUI*/PHPeclipsePlugin.PHP_NATURE_ID);
 
  98                         // We have a Java project
 
 101                 } catch (CoreException e) {