1) Changed indentation of (single or double) quoted strings to align on the first...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / actions / ActionUtil.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
12
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
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;
29
30 /*
31  * http://dev.eclipse.org/bugs/show_bug.cgi?id=19104
32  */
33 public class ActionUtil {
34
35         private ActionUtil() {
36         }
37
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))
42 //                      return false;
43 //
44 //              IResource resource = ResourceUtil.getResource(element);
45 //              if ((resource == null) || (!(resource instanceof IFolder))
46 //                              || (!resource.isLinked()))
47 //                      return false;
48 //
49 //              MessageDialog
50 //                              .openInformation(
51 //                                              shell,
52 //                                              ActionMessages.getString("ActionUtil.not_possible"), ActionMessages.getString("ActionUtil.no_linked")); //$NON-NLS-1$ //$NON-NLS-2$
53 //              return true;
54 //      }
55
56         public static boolean isProcessable(Shell shell, PHPEditor editor) {
57                 if (editor == null)
58                         return true;
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
62                 if (input == null) {
63                         MessageDialog.openInformation(shell, ActionMessages
64                                         .getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
65                                         ActionMessages
66                                                         .getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
67                         return false;
68                 }
69                 return isProcessable(shell, input);
70         }
71
72         public static boolean isProcessable(Shell shell, Object element) {
73                 if (!(element instanceof IJavaElement))
74                         return true;
75
76                 if (isOnBuildPath((IJavaElement) element))
77                         return true;
78                 MessageDialog.openInformation(shell, ActionMessages
79                                 .getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$
80                                 ActionMessages.getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$
81                 return false;
82         }
83
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)
87                         return true;
88                 IJavaProject project = element.getJavaProject();
89                 try {
90                         // if (!project.isOnClasspath(element))
91                         // return false;
92                         IProject resourceProject = project.getProject();
93                         if (resourceProject == null)
94                                 return false;
95                         IProjectNature nature = resourceProject
96                                         .getNature(PHPeclipsePlugin.PHP_NATURE_ID);
97                         // We have a Java project
98                         if (nature != null)
99                                 return true;
100                 } catch (CoreException e) {
101                 }
102                 return false;
103         }
104 }