public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final StrutsFacet strutsFacet = StrutsFacet.getInstance(file); assert strutsFacet != null; final Set<StrutsFileSet> strutsFileSets = strutsFacet.getConfiguration().getFileSets(); final BaseListPopupStep<StrutsFileSet> step = new BaseListPopupStep<StrutsFileSet>( StrutsBundle.message("annotators.fileset.fix.choose.fileset"), new ArrayList<StrutsFileSet>(strutsFileSets)) { public Icon getIconFor(final StrutsFileSet aValue) { return StrutsIcons.STRUTS_CONFIG_FILE; } public PopupStep onChosen( final StrutsFileSet selectedValue, final boolean finalChoice) { selectedValue.addFile(file.getVirtualFile()); ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { ProjectRootManagerEx.getInstanceEx(project) .makeRootsChange(EmptyRunnable.getInstance(), false, true); } }); // re-highlight (remove annotation) DaemonCodeAnalyzer.getInstance(project).restart(); return super.onChosen(selectedValue, finalChoice); } }; JBPopupFactory.getInstance() .createListPopup(step) .showInBestPositionFor(DataManager.getInstance().getDataContext(editor.getComponent())); }
public void annotate( @NotNull final PsiElement psiElement, @NotNull final AnnotationHolder holder) { if (!(psiElement instanceof XmlFile)) { return; } if (psiElement instanceof JspFile) { return; } final Module module = ModuleUtil.findModuleForPsiElement(psiElement); if (module == null) { return; } // do not run when facet not enabled if (StrutsFacet.getInstance(module) == null) { return; } final XmlFile xmlFile = (XmlFile) psiElement; final Project project = psiElement.getProject(); final StrutsManager strutsManager = StrutsManager.getInstance(project); if (!strutsManager.isStruts2ConfigFile(xmlFile)) { return; } final VirtualFile currentVirtualFile = xmlFile.getVirtualFile(); assert currentVirtualFile != null; final Set<StrutsFileSet> allConfigFileSets = strutsManager.getAllConfigFileSets(module); for (final StrutsFileSet configFileSet : allConfigFileSets) { if (configFileSet.hasFile(currentVirtualFile)) { return; } } final boolean fileSetAvailable = allConfigFileSets.size() != 0; final Annotation annotation = holder.createWarningAnnotation( xmlFile, fileSetAvailable ? StrutsBundle.message("annotators.fileset.file.not.registered") : StrutsBundle.message("annotators.fileset.no.file.sets")); annotation.setFileLevelAnnotation(true); if (fileSetAvailable) { final AddToFileSetFix addToFileSetFix = new AddToFileSetFix(xmlFile.getName()); annotation.registerFix(addToFileSetFix); } else { annotation.registerFix( new IntentionAction() { @NotNull public String getText() { return StrutsBundle.message("annotators.fileset.edit.facet.settings"); } @NotNull public String getFamilyName() { return StrutsBundle.message("intentions.family.name"); } public boolean isAvailable( @NotNull final Project project, final Editor editor, final PsiFile psiFile) { return true; } public void invoke( @NotNull final Project project, final Editor editor, final PsiFile psiFile) throws IncorrectOperationException { final StrutsFacet strutsFacet = StrutsFacet.getInstance(module); assert strutsFacet != null; ModulesConfigurator.showFacetSettingsDialog(strutsFacet, null); } public boolean startInWriteAction() { return false; } }); } }