/** Synchronize on the tern project load, tern script pats with JSDT "Include Path". */
 @Override
 public void handleEvent(IIDETernProject ternProject, LifecycleEventType eventType) {
   if (eventType != LifecycleEventType.onLoadAfter) {
     return;
   }
   // the given tern project is loading...
   IProject project = ternProject.getProject();
   if (JavaProject.hasJavaNature(project)) {
     // The project is a JSDT project.
     IJavaScriptProject jsProject = JavaScriptCore.create(project);
     // Synchronize tern script paths with JSDT "Include Path"
     synchTernScriptPaths(jsProject, ternProject);
   }
 }
  private CPListElement[] openProjectDialog(CPListElement elem) {

    try {
      ArrayList selectable = new ArrayList();
      selectable.addAll(Arrays.asList(fCurrJProject.getJavaScriptModel().getJavaScriptProjects()));
      selectable.remove(fCurrJProject);

      List elements = fProjectsList.getElements();
      for (int i = 0; i < elements.size(); i++) {
        CPListElement curr = (CPListElement) elements.get(0);
        IJavaScriptProject proj = (IJavaScriptProject) JavaScriptCore.create(curr.getResource());
        selectable.remove(proj);
      }
      Object[] selectArr = selectable.toArray();
      new JavaScriptElementComparator().sort(null, selectArr);

      ListSelectionDialog dialog =
          new ListSelectionDialog(
              getShell(),
              Arrays.asList(selectArr),
              new ArrayContentProvider(),
              new JavaUILabelProvider(),
              NewWizardMessages.ProjectsWorkbookPage_chooseProjects_message);
      dialog.setTitle(NewWizardMessages.ProjectsWorkbookPage_chooseProjects_title);
      dialog.setHelpAvailable(false);
      if (dialog.open() == Window.OK) {
        Object[] result = dialog.getResult();
        CPListElement[] cpElements = new CPListElement[result.length];
        for (int i = 0; i < result.length; i++) {
          IJavaScriptProject curr = (IJavaScriptProject) result[i];
          cpElements[i] =
              new CPListElement(
                  fCurrJProject, IIncludePathEntry.CPE_PROJECT, curr.getPath(), curr.getResource());
        }
        return cpElements;
      }
    } catch (JavaScriptModelException e) {
      return null;
    }
    return null;
  }
  /**
   * Returns the parent for the element.
   *
   * <p>Note: This method will return a working copy if the parent is a working copy. The super
   * class implementation returns the original element instead.
   */
  protected Object internalGetParent(Object element) {
    if (element instanceof IJavaScriptProject) {
      return ((IJavaScriptProject) element).getJavaScriptModel();
    }
    // try to map resources to the containing package fragment
    if (element instanceof IResource) {
      IResource parent = ((IResource) element).getParent();
      Object jParent = JavaScriptCore.create(parent);
      if (jParent != null) return jParent;
      return parent;
    }

    // for package fragments that are contained in a project package fragment
    // we have to skip the package fragment root as the parent.
    if (element instanceof IPackageFragment) {
      IPackageFragmentRoot parent = (IPackageFragmentRoot) ((IPackageFragment) element).getParent();
      return skipProjectPackageFragmentRoot(parent);
    }
    if (element instanceof IJavaScriptElement) return ((IJavaScriptElement) element).getParent();

    return null;
  }
 /* (non-Javadoc)
  * @see org.eclipse.wst.jsdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
  */
 public IJavaScriptElement getCreatedElement() {
   return JavaScriptCore.create(fFirstPage.getProjectHandle());
 }