Exemplo n.º 1
0
  public static IPath getPortalDir(IProject project) {
    try {
      IFacetedProject facetedProject = ProjectFacetsManager.create(project);

      org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime =
          facetedProject.getPrimaryRuntime();

      if (runtime != null) {
        return ServerUtil.getPortalDir(runtime);
      }
    } catch (CoreException e) {
      LiferayServerCorePlugin.logError(e);
    }

    return null;
  }
  @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;
  }