public void checkValidProjectTypes() {
    IProject[] projects = CoreUtil.getAllProjects();
    boolean hasValidProjectTypes = false;

    boolean hasJsfFacet = false;

    for (IProject project : projects) {
      if (ProjectUtil.isLiferayProject(project)) {
        Set<IProjectFacetVersion> facets =
            ProjectUtil.getFacetedProject(project).getProjectFacets();

        if (validProjectTypes != null && facets != null) {
          String[] validTypes = validProjectTypes.split(",");

          for (String validProjectType : validTypes) {
            for (IProjectFacetVersion facet : facets) {
              String id = facet.getProjectFacet().getId();

              if (isJsfPortlet && id.equals("jst.jsf")) {
                hasJsfFacet = true;
              }

              if (id.startsWith("liferay.") && id.equals("liferay." + validProjectType)) {
                hasValidProjectTypes = true;
              }
            }
          }
        }
      }
    }

    if (isJsfPortlet) {
      hasValidProjectTypes = hasJsfFacet && hasValidProjectTypes;
    }

    if (!hasValidProjectTypes) {
      final Shell activeShell = Display.getDefault().getActiveShell();
      Boolean openNewLiferayProjectWizard =
          MessageDialog.openQuestion(
              activeShell,
              "New Element",
              "There are no suitable Liferay projects available for this new element.\nDo you want"
                  + " to open the \'New Liferay Project\' wizard now?");

      if (openNewLiferayProjectWizard) {
        Action[] actions = NewPluginProjectDropDownAction.getNewProjectActions();

        if (actions.length > 0) {
          actions[0].run();
          this.checkValidProjectTypes();
        }
      }
    }
  }
    protected void handleSelectServiceButton(Text text) {
      PortalServiceSearchScope scope = new PortalServiceSearchScope();
      scope.setResourcePattern(new String[] {".*Service.class$"}); // $NON-NLS-1$

      IProject project = ProjectUtil.getProject(model);

      ILiferayProject liferayProject = LiferayCore.create(project);

      IPath serviceJarPath = liferayProject.getLibraryPath("portal-service");

      scope.setEnclosingJarPaths(new IPath[] {serviceJarPath});

      FilteredTypesSelectionDialog dialog =
          new FilteredTypesSelectionDialogEx(
              getShell(), false, null, scope, IJavaSearchConstants.INTERFACE);
      dialog.setTitle(J2EEUIMessages.SUPERCLASS_SELECTION_DIALOG_TITLE);
      dialog.setMessage(J2EEUIMessages.SUPERCLASS_SELECTION_DIALOG_DESC);

      if (dialog.open() == Window.OK) {
        IType type = (IType) dialog.getFirstResult();

        String classFullPath = J2EEUIMessages.EMPTY_STRING;

        if (type != null) {
          classFullPath = type.getFullyQualifiedName();
        }

        text.setText(classFullPath);
      }
    }
  public IStatus doSetCustomJSPDir(IDOMDocument document, IDataModel model) {
    // <hook> element
    Element rootElement = document.getDocumentElement();

    final ILiferayProject lrproject = LiferayCore.create(project);
    final IPath defaultWebappRootFolderFullPath = lrproject.getDefaultDocrootFolder().getFullPath();

    String customJSPsFolder = model.getStringProperty(CUSTOM_JSPS_FOLDER);

    String relativeJspFolderPath =
        ProjectUtil.getRelativePathFromDocroot(
            this.project,
            defaultWebappRootFolderFullPath.append(customJSPsFolder).toPortableString());

    Element customJspElement = null;

    // check for existing element
    NodeList nodeList = rootElement.getElementsByTagName("custom-jsp-dir"); // $NON-NLS-1$

    if (nodeList != null && nodeList.getLength() > 0) {
      customJspElement = (Element) nodeList.item(0);

      NodeUtil.removeChildren(customJspElement);

      Node textNode = document.createTextNode(relativeJspFolderPath);

      customJspElement.appendChild(textNode);
    } else {
      // need to insert customJspElement before any <service>
      NodeList serviceTags = rootElement.getElementsByTagName("service"); // $NON-NLS-1$

      if (serviceTags != null && serviceTags.getLength() > 0) {
        customJspElement =
            NodeUtil.insertChildElement(
                rootElement,
                serviceTags.item(0),
                "custom-jsp-dir",
                relativeJspFolderPath); //$NON-NLS-1$
      } else {
        customJspElement =
            NodeUtil.appendChildElement(
                rootElement, "custom-jsp-dir", relativeJspFolderPath); // $NON-NLS-1$

        // append a newline text node
        rootElement.appendChild(
            document.createTextNode(System.getProperty("line.separator"))); // $NON-NLS-1$
      }
    }

    // format the new node added to the model;
    FormatProcessorXML processor = new FormatProcessorXML();

    processor.formatNode(customJspElement);

    return Status.OK_STATUS;
  }
  protected IFacetedProject getFacetedProject() {
    IFacetedProject retval = null;

    IProject project = getProject();

    if (project != null) {
      retval = ProjectUtil.getFacetedProject(project);
    }

    return retval;
  }
  private void clearWebXmlDescriptors(IProject project, IPath path, IProgressMonitor monitor) {
    // copy over web.xml so the liferay deployer doesn't copy web.xml filters incorrectly
    IModuleResource webXmlRes = getWebXmlFile(project, path);

    if (webXmlRes != null) {
      helper.publishToPath(new IModuleResource[] {webXmlRes}, path.append(WEB_XML_PATH), monitor);
    } else {
      File webXmlFile = path.append(WEB_XML_PATH).toFile();
      File liferayWebXmlFile = path.append(LIFERAY_WEB_XML_PATH).toFile();

      if (webXmlFile.exists()) {
        if (!webXmlFile.delete()) {
          ProjectUtil.createDefaultWebXml(webXmlFile);
        }
      }

      if (liferayWebXmlFile.exists()) {
        if (!liferayWebXmlFile.delete()) {
          ProjectUtil.createDefaultWebXml(liferayWebXmlFile);
        }
      }
    }
  }
  protected void createInfoGroup(Composite parent) {
    new Label(parent, SWT.LEFT).setText(Msgs.liferayPluginTypeLabel);

    final Text pluginTypeLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
    pluginTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    final IProjectFacet liferayFacet = ProjectUtil.getLiferayFacet(getFacetedProject());

    if (liferayFacet != null) {
      pluginTypeLabel.setText(liferayFacet.getLabel());
    }

    new Label(parent, SWT.LEFT).setText(Msgs.liferayRuntimeLabel);

    this.runtimeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    this.runtimeCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    String currentRuntimeName = null;

    try {
      ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(getProject());

      currentRuntimeName = liferayRuntime.getRuntime().getName();
    } catch (Exception e) {
      ProjectUIPlugin.logError("Could not determine liferay runtime", e); // $NON-NLS-1$
    }

    final List<String> runtimeNames = new ArrayList<String>();
    int selectionIndex = -1;

    for (IRuntime runtime : ServerCore.getRuntimes()) {
      if (ServerUtil.isLiferayRuntime(runtime)) {
        runtimeNames.add(runtime.getName());

        if (runtime.getName().equals(currentRuntimeName)) {
          selectionIndex = runtimeNames.size() - 1;
        }
      }
    }

    if (runtimeNames.size() == 0) {
      runtimeNames.add("No Liferay runtimes available."); // $NON-NLS-1$
    }

    this.runtimeCombo.setItems(runtimeNames.toArray(new String[0]));

    if (selectionIndex > -1) {
      this.runtimeCombo.select(selectionIndex);
    }
  }
  @Override
  public IPath getModuleDeployDirectory(IModule module) {
    final IPath defaultPath = super.getModuleDeployDirectory(module);

    IPath updatedPath = null;

    if (defaultPath != null && defaultPath.lastSegment() != null) {
      final IProject project = module.getProject();
      final String requiredSuffix = ProjectUtil.getRequiredSuffix(project);

      if (requiredSuffix != null && !defaultPath.lastSegment().endsWith(requiredSuffix)) {
        String lastSegment = defaultPath.lastSegment();
        updatedPath = defaultPath.removeLastSegments(1).append(lastSegment + requiredSuffix);
      }
    }

    return updatedPath == null ? defaultPath : updatedPath;
  }
 public Object[] getChildren(Object element) {
   if (element instanceof IJavaModel) {
     IJavaModel model = (IJavaModel) element;
     Set<IJavaProject> set = new HashSet<IJavaProject>();
     try {
       IJavaProject[] projects = model.getJavaProjects();
       for (int i = 0; i < projects.length; i++) {
         if (ProjectUtil.isLiferayFacetedProject(projects[i].getProject())) {
           set.add(projects[i]);
         }
       }
     } catch (JavaModelException jme) {
       // ignore
     }
     return set.toArray();
   }
   return super.getChildren(element);
 }
  @Override
  public boolean performOk() {
    final String selectedRuntimeName = this.runtimeCombo.getText();

    if (!CoreUtil.isNullOrEmpty(selectedRuntimeName)) {
      final org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime =
          RuntimeManager.getRuntime(selectedRuntimeName);

      if (runtime != null) {
        final IFacetedProject fProject = ProjectUtil.getFacetedProject(getProject());

        final org.eclipse.wst.common.project.facet.core.runtime.IRuntime primaryRuntime =
            fProject.getPrimaryRuntime();

        if (!runtime.equals(primaryRuntime)) {
          Job job = new WorkspaceJob("Setting targeted runtime for project.") // $NON-NLS-1$
              {
                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                  IStatus retval = Status.OK_STATUS;

                  try {
                    fProject.setTargetedRuntimes(Collections.singleton(runtime), monitor);
                    fProject.setPrimaryRuntime(runtime, monitor);
                  } catch (Exception e) {
                    retval =
                        ProjectUIPlugin.createErrorStatus(
                            "Could not set targeted runtime", e); // $NON-NLS-1$
                  }

                  return retval;
                }
              };

          job.schedule();
        }
      } else {
        return false;
      }
    }

    return true;
  }
  private boolean runMavenGoal(final IProject project, final IProgressMonitor monitor)
      throws CoreException {
    boolean retval = false;

    final IMavenProjectFacade facade = MavenUtil.getProjectFacade(project, monitor);
    final String pluginType = MavenUtil.getLiferayMavenPluginType(facade.getMavenProject(monitor));
    final MavenProject parentProject = facade.getMavenProject(monitor).getParent();
    final String goal = getMavenDeployGoals();

    if (isServiceBuilderProject(project, pluginType, parentProject)) {
      retval =
          execMavenLaunch(
              ProjectUtil.getProject(parentProject.getName()),
              " package -am -pl " + project.getName(),
              MavenUtil.getProjectFacade(project, monitor),
              monitor);
    } else {
      retval = execMavenLaunch(project, goal, facade, monitor);
    }

    return retval;
  }
  public static final Status[] performUpgrade(
      final List<String> projectItems,
      final List<String> projectActions,
      final String runtimeName,
      final IProgressMonitor monitor) {
    final List<Status> retval = new ArrayList<Status>();

    int worked = 0;
    int workUnit = projectItems.size();
    int actionUnit = projectActions.size();
    int totalWork = 100;
    int perUnit = totalWork / (workUnit * actionUnit);
    monitor.beginTask("Upgrading Project ", totalWork);

    final UpgradeProjectHandlerReader upgradeLiferayProjectActionReader =
        new UpgradeProjectHandlerReader();
    final HashMap<String, AbstractUpgradeProjectHandler> actionMap =
        getActionMap(upgradeLiferayProjectActionReader.getUpgradeActions());

    for (String projectItem : projectItems) {
      if (projectItem != null) {
        final IProject project = ProjectUtil.getProject(projectItem);
        monitor.subTask("Upgrading project " + project.getName());

        for (String action : projectActions) {
          final AbstractUpgradeProjectHandler upgradeLiferayProjectAction = actionMap.get(action);
          final Status status =
              upgradeLiferayProjectAction.execute(project, runtimeName, monitor, perUnit);
          retval.add(status);
          worked = worked + totalWork / (workUnit * actionUnit);
          monitor.worked(worked);
        }
      }
    }

    return retval.toArray(new Status[0]);
  }
  protected IProject getTargetProject() {
    String projectName = model.getStringProperty(PROJECT_NAME);

    return ProjectUtil.getProject(projectName);
  }
  public IStatus moveContextToAutoDeployDir(
      IModule module,
      IPath deployDir,
      IPath baseDir,
      IPath autoDeployDir,
      boolean noPath,
      boolean serverStopped) {
    IPath confDir = baseDir.append("conf"); // $NON-NLS-1$
    IPath serverXml = confDir.append("server.xml"); // $NON-NLS-1$

    try {
      Factory factory = new Factory();
      factory.setPackageName(
          "org.eclipse.jst.server.tomcat.core.internal.xml.server40"); //$NON-NLS-1$
      Server publishedServer =
          (Server) factory.loadDocument(new FileInputStream(serverXml.toFile()));
      ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);

      IPath contextPath = null;

      if (autoDeployDir.isAbsolute()) {
        contextPath = autoDeployDir;
      } else {
        contextPath = baseDir.append(autoDeployDir);
      }

      File contextDir = contextPath.toFile();

      if (!contextDir.exists()) {
        contextDir.mkdirs();
      }

      Context context = publishedInstance.createContext(-1);
      context.setReloadable("true"); // $NON-NLS-1$

      final String moduleName = module.getName();
      final String requiredSuffix = ProjectUtil.getRequiredSuffix(module.getProject());

      String contextName = moduleName;

      if (!moduleName.endsWith(requiredSuffix)) {
        contextName = moduleName + requiredSuffix;
      }

      context.setSource("org.eclipse.jst.jee.server:" + contextName); // $NON-NLS-1$

      if (Boolean.valueOf(context.getAttributeValue("antiResourceLocking"))
          .booleanValue()) //$NON-NLS-1$
      {
        context.setAttributeValue("antiResourceLocking", "false"); // $NON-NLS-1$ //$NON-NLS-2$
      }

      File contextFile = new File(contextDir, contextName + ".xml"); // $NON-NLS-1$

      if (!LiferayTomcatUtil.isExtProjectContext(context)) {
        // If requested, remove path attribute
        if (noPath) {
          context.removeAttribute("path"); // $NON-NLS-1$
        }

        // need to fix the doc base to contain entire path to help autoDeployer for Liferay
        context.setDocBase(deployDir.toOSString());
        // context.setAttributeValue("antiJARLocking", "true");

        // check to see if we need to move from conf folder
        // IPath existingContextPath =
        // confDir.append("Catalina/localhost").append(contextFile.getName());
        // if (existingContextPath.toFile().exists()) {
        // existingContextPath.toFile().delete();
        // }

        DocumentBuilder builder = XMLUtil.getDocumentBuilder();
        Document contextDoc = builder.newDocument();
        contextDoc.appendChild(contextDoc.importNode(context.getElementNode(), true));
        XMLUtil.save(contextFile.getAbsolutePath(), contextDoc);
      }
    } catch (Exception e) {
      // Trace.trace(Trace.SEVERE,
      // "Could not modify context configurations to serve directly for Tomcat configuration " +
      // confDir.toOSString() + ": " + e.getMessage());
      return new Status(
          IStatus.ERROR,
          TomcatPlugin.PLUGIN_ID,
          0,
          NLS.bind(Messages.errorPublishConfiguration, new String[] {e.getLocalizedMessage()}),
          e);
    } finally {
      // monitor.done();
    }

    return Status.OK_STATUS;
  }
  private boolean isHookProjectDelta(IModuleResourceDelta del) {
    IProject project =
        ((IResource) del.getModuleResource().getAdapter(IResource.class)).getProject();

    return ProjectUtil.isHookProject(project);
  }