Java 类com.intellij.uiDesigner.binding.FormClassIndex 实例源码

项目:intellij-ce-playground    文件:GenerateMainAction.java   
private static boolean isActionEnabled(final AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return false;
  Editor editor = e.getData(CommonDataKeys.EDITOR);
  if (editor == null) return false;
  int offset = editor.getCaretModel().getOffset();
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (file == null) return false;
  PsiElement element = file.findElementAt(offset);
  if (element == null) return false;
  PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
  if (psiClass == null) return false;
  if (PsiMethodUtil.findMainMethod(psiClass) != null) return false;
  if (FormClassIndex.findFormsBoundToClass(project, psiClass).isEmpty()) return false;
  return true;
}
项目:tools-idea    文件:GenerateMainAction.java   
private static boolean isActionEnabled(final AnActionEvent e) {
  Project project = e.getData(PlatformDataKeys.PROJECT);
  if (project == null) return false;
  Editor editor = e.getData(PlatformDataKeys.EDITOR);
  if (editor == null) return false;
  int offset = editor.getCaretModel().getOffset();
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (file == null) return false;
  PsiElement element = file.findElementAt(offset);
  if (element == null) return false;
  PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
  if (psiClass == null) return false;
  if (PsiMethodUtil.findMainMethod(psiClass) != null) return false;
  if (FormClassIndex.findFormsBoundToClass(psiClass).isEmpty()) return false;
  return true;
}
项目:consulo-ui-designer    文件:GenerateMainAction.java   
private static boolean isActionEnabled(final AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return false;
  Editor editor = e.getData(PlatformDataKeys.EDITOR);
  if (editor == null) return false;
  int offset = editor.getCaretModel().getOffset();
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (file == null) return false;
  PsiElement element = file.findElementAt(offset);
  if (element == null) return false;
  PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
  if (psiClass == null) return false;
  if (PsiMethodUtil.findMainMethod(psiClass) != null) return false;
  if (FormClassIndex.findFormsBoundToClass(psiClass).isEmpty()) return false;
  return true;
}
项目:intellij-ce-playground    文件:ComponentItem.java   
@Nullable public PsiFile getBoundForm() {
  if (myClassName.length() == 0 || myClassName.startsWith("javax.swing")) {
    return null;
  }
  List<PsiFile> boundForms = FormClassIndex.findFormsBoundToClass(myProject, myClassName.replace('$', '.'));
  if (boundForms.size() > 0) {
    return boundForms.get(0);
  }
  return null;
}
项目:tools-idea    文件:ComponentItem.java   
@Nullable public PsiFile getBoundForm() {
  if (myClassName.length() == 0 || myClassName.startsWith("javax.swing")) {
    return null;
  }
  List<PsiFile> boundForms = FormClassIndex.findFormsBoundToClass(myProject, myClassName.replace('$', '.'));
  if (boundForms.size() > 0) {
    return boundForms.get(0);
  }
  return null;
}
项目:consulo-ui-designer    文件:ComponentItem.java   
@Nullable public PsiFile getBoundForm() {
  if (myClassName.length() == 0 || myClassName.startsWith("javax.swing")) {
    return null;
  }
  List<PsiFile> boundForms = FormClassIndex.findFormsBoundToClass(myProject, myClassName.replace('$', '.'));
  if (boundForms.size() > 0) {
    return boundForms.get(0);
  }
  return null;
}
项目:intellij-ce-playground    文件:Form.java   
public Form(PsiClass classToBind) {
  myClassToBind = classToBind;
  myFormFiles = FormClassIndex.findFormsBoundToClass(classToBind.getProject(), classToBind);
}
项目:intellij-ce-playground    文件:FormMergerTreeStructureProvider.java   
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
  if (parent.getValue() instanceof Form) return children;

  // Optimization. Check if there are any forms at all.
  boolean formsFound = false;
  for (AbstractTreeNode node : children) {
    if (node.getValue() instanceof PsiFile) {
      PsiFile file = (PsiFile)node.getValue();
      if (file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM) {
        formsFound = true;
        break;
      }
    }
  }

  if (!formsFound) return children;

  Collection<AbstractTreeNode> result = new LinkedHashSet<AbstractTreeNode>(children);
  ProjectViewNode[] copy = children.toArray(new ProjectViewNode[children.size()]);
  for (ProjectViewNode element : copy) {
    PsiClass psiClass = null;
    if (element.getValue() instanceof PsiClass) {
      psiClass = (PsiClass)element.getValue();
    }
    else if (element.getValue() instanceof PsiClassOwner) {
      final PsiClass[] psiClasses = ((PsiClassOwner) element.getValue()).getClasses();
      if (psiClasses.length == 1) {
        psiClass = psiClasses[0];
      }
    }
    if (psiClass == null) continue;
    String qName = psiClass.getQualifiedName();
    if (qName == null) continue;
    List<PsiFile> forms;
    try {
      forms = FormClassIndex.findFormsBoundToClass(myProject, qName);
    }
    catch (ProcessCanceledException e) {
      continue;
    }
    Collection<BasePsiNode<? extends PsiElement>> formNodes = findFormsIn(children, forms);
    if (!formNodes.isEmpty()) {
      Collection<PsiFile> formFiles = convertToFiles(formNodes);
      Collection<BasePsiNode<? extends PsiElement>> subNodes = new ArrayList<BasePsiNode<? extends PsiElement>>();
      //noinspection unchecked
      subNodes.add((BasePsiNode<? extends PsiElement>) element);
      subNodes.addAll(formNodes);
      result.add(new FormNode(myProject, new Form(psiClass, formFiles), settings, subNodes));
      result.remove(element);
      result.removeAll(formNodes);
    }
  }
  return result;
}
项目:tools-idea    文件:Form.java   
public Form(PsiClass classToBind) {
  myClassToBind = classToBind;
  myFormFiles = FormClassIndex.findFormsBoundToClass(classToBind);
}
项目:tools-idea    文件:FormMergerTreeStructureProvider.java   
public Collection<AbstractTreeNode> modify(AbstractTreeNode parent, Collection<AbstractTreeNode> children, ViewSettings settings) {
  if (parent.getValue() instanceof Form) return children;

  // Optimization. Check if there are any forms at all.
  boolean formsFound = false;
  for (AbstractTreeNode node : children) {
    if (node.getValue() instanceof PsiFile) {
      PsiFile file = (PsiFile)node.getValue();
      if (file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM) {
        formsFound = true;
        break;
      }
    }
  }

  if (!formsFound) return children;

  Collection<AbstractTreeNode> result = new LinkedHashSet<AbstractTreeNode>(children);
  ProjectViewNode[] copy = children.toArray(new ProjectViewNode[children.size()]);
  for (ProjectViewNode element : copy) {
    PsiClass psiClass = null;
    if (element.getValue() instanceof PsiClass) {
      psiClass = (PsiClass)element.getValue();
    }
    else if (element.getValue() instanceof PsiClassOwner) {
      final PsiClass[] psiClasses = ((PsiClassOwner) element.getValue()).getClasses();
      if (psiClasses.length == 1) {
        psiClass = psiClasses[0];
      }
    }
    if (psiClass == null) continue;
    String qName = psiClass.getQualifiedName();
    if (qName == null) continue;
    List<PsiFile> forms;
    try {
      forms = FormClassIndex.findFormsBoundToClass(myProject, qName);
    }
    catch (ProcessCanceledException e) {
      continue;
    }
    Collection<BasePsiNode<? extends PsiElement>> formNodes = findFormsIn(children, forms);
    if (!formNodes.isEmpty()) {
      Collection<PsiFile> formFiles = convertToFiles(formNodes);
      Collection<BasePsiNode<? extends PsiElement>> subNodes = new ArrayList<BasePsiNode<? extends PsiElement>>();
      //noinspection unchecked
      subNodes.add((BasePsiNode<? extends PsiElement>) element);
      subNodes.addAll(formNodes);
      result.add(new FormNode(myProject, new Form(psiClass, formFiles), settings, subNodes));
      result.remove(element);
      result.removeAll(formNodes);
    }
  }
  return result;
}
项目:consulo-ui-designer    文件:Form.java   
public Form(PsiClass classToBind) {
  myClassToBind = classToBind;
  myFormFiles = FormClassIndex.findFormsBoundToClass(classToBind);
}
项目:consulo-ui-designer    文件:FormMergerTreeStructureProvider.java   
@Override
public Collection<AbstractTreeNode> modify(AbstractTreeNode parent, Collection<AbstractTreeNode> children, ViewSettings settings)
{
    if(parent.getValue() instanceof Form)
    {
        return children;
    }

    // Optimization. Check if there are any forms at all.
    boolean formsFound = false;
    for(AbstractTreeNode node : children)
    {
        if(node.getValue() instanceof PsiFile)
        {
            PsiFile file = (PsiFile) node.getValue();
            if(file.getFileType() == GuiFormFileType.INSTANCE)
            {
                formsFound = true;
                break;
            }
        }
    }

    if(!formsFound)
    {
        return children;
    }

    Collection<AbstractTreeNode> result = new LinkedHashSet<>(children);
    ProjectViewNode[] copy = children.toArray(new ProjectViewNode[children.size()]);
    for(ProjectViewNode element : copy)
    {
        PsiClass psiClass = null;
        if(element.getValue() instanceof PsiClass)
        {
            psiClass = (PsiClass) element.getValue();
        }
        else if(element.getValue() instanceof PsiClassOwner)
        {
            final PsiClass[] psiClasses = ((PsiClassOwner) element.getValue()).getClasses();
            if(psiClasses.length == 1)
            {
                psiClass = psiClasses[0];
            }
        }
        if(psiClass == null)
        {
            continue;
        }
        String qName = psiClass.getQualifiedName();
        if(qName == null)
        {
            continue;
        }
        List<PsiFile> forms;
        try
        {
            forms = FormClassIndex.findFormsBoundToClass(myProject, qName);
        }
        catch(ProcessCanceledException e)
        {
            continue;
        }
        Collection<BasePsiNode<? extends PsiElement>> formNodes = findFormsIn(children, forms);
        if(!formNodes.isEmpty())
        {
            Collection<PsiFile> formFiles = convertToFiles(formNodes);
            Collection<BasePsiNode<? extends PsiElement>> subNodes = new ArrayList<>();
            //noinspection unchecked
            subNodes.add((BasePsiNode<? extends PsiElement>) element);
            subNodes.addAll(formNodes);
            result.add(new FormNode(myProject, new Form(psiClass, formFiles), settings, subNodes));
            result.remove(element);
            result.removeAll(formNodes);
        }
    }
    return result;
}