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; }
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; }
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; }
@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; }
public Form(PsiClass classToBind) { myClassToBind = classToBind; myFormFiles = FormClassIndex.findFormsBoundToClass(classToBind.getProject(), classToBind); }
@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; }
public Form(PsiClass classToBind) { myClassToBind = classToBind; myFormFiles = FormClassIndex.findFormsBoundToClass(classToBind); }
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; }
@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; }