private void appendChosenAnnotationsRoot( @NotNull final OrderEntry entry, @NotNull final VirtualFile vFile) { if (entry instanceof LibraryOrderEntry) { Library library = ((LibraryOrderEntry) entry).getLibrary(); LOG.assertTrue(library != null); final ModifiableRootModel rootModel = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel(); final Library.ModifiableModel model = library.getModifiableModel(); model.addRoot(vFile, AnnotationOrderRootType.getInstance()); model.commit(); rootModel.commit(); } else if (entry instanceof ModuleSourceOrderEntry) { final ModifiableRootModel model = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel(); final JavaModuleExternalPaths extension = model.getModuleExtension(JavaModuleExternalPaths.class); extension.setExternalAnnotationUrls( ArrayUtil.mergeArrays(extension.getExternalAnnotationsUrls(), vFile.getUrl())); model.commit(); } else if (entry instanceof JdkOrderEntry) { final SdkModificator sdkModificator = ((JdkOrderEntry) entry).getJdk().getSdkModificator(); sdkModificator.addRoot(vFile, AnnotationOrderRootType.getInstance()); sdkModificator.commitChanges(); } myExternalAnnotations.clear(); }
private List<String> collectModuleDepsNames(String moduleName, Class clazz) { List<String> actual = new ArrayList<String>(); for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) { if (clazz.isInstance(e)) { actual.add(e.getPresentableName()); } } return actual; }
public void selectOrderEntry(@NotNull OrderEntry entry) { for (int row = 0; row < myModel.getRowCount(); row++) { final OrderEntry orderEntry = getItemAt(row).getEntry(); if (orderEntry != null && entry.getPresentableName().equals(orderEntry.getPresentableName())) { myEntryTable.getSelectionModel().setSelectionInterval(row, row); TableUtil.scrollSelectionToVisible(myEntryTable); } } IdeFocusManager.getInstance(myState.getProject()).requestFocus(myEntryTable, true); }
private <T> T getModuleDep(String moduleName, String depName, Class<T> clazz) { T dep = null; for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) { if (clazz.isInstance(e) && e.getPresentableName().equals(depName)) { dep = (T) e; } } assertNotNull( "Dependency not found: " + depName + "\namong: " + collectModuleDepsNames(moduleName, clazz), dep); return dep; }
public static void customizeElementLabel(final PsiElement element, final JLabel label) { if (element != null) { PsiFile file = element.getContainingFile(); VirtualFile vfile = file == null ? null : file.getVirtualFile(); if (vfile == null) { label.setText(""); label.setIcon(null); return; } final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex(); final Module module = fileIndex.getModuleForFile(vfile); if (module != null) { label.setText(module.getName()); label.setIcon(AllIcons.Nodes.Module); } else { final List<OrderEntry> entries = fileIndex.getOrderEntriesForFile(vfile); OrderEntry entry = null; for (OrderEntry order : entries) { if (order instanceof LibraryOrderEntry || order instanceof SdkOrderEntry) { entry = order; break; } } if (entry != null) { label.setText(entry.getPresentableName()); label.setIcon(AllIcons.Nodes.PpLibFolder); } } } }
private void setupRootAndAnnotateExternally( @NotNull final OrderEntry entry, @NotNull final Project project, @NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQName, @NotNull final PsiFile fromFile, @NotNull final String packageName, @Nullable final PsiNameValuePair[] value) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setTitle( ProjectBundle.message( "external.annotations.root.chooser.title", entry.getPresentableName())); descriptor.setDescription( ProjectBundle.message("external.annotations.root.chooser.description")); final VirtualFile newRoot = FileChooser.chooseFile(descriptor, project, null); if (newRoot == null) { notifyAfterAnnotationChanging(listOwner, annotationFQName, false); return; } new WriteCommandAction(project) { @Override protected void run(final Result result) throws Throwable { appendChosenAnnotationsRoot(entry, newRoot); XmlFile xmlFileInRoot = findXmlFileInRoot(findExternalAnnotationsXmlFiles(listOwner), newRoot); if (xmlFileInRoot != null) { // file already exists under appeared content root if (!CodeInsightUtilBase.preparePsiElementForWrite(xmlFileInRoot)) { notifyAfterAnnotationChanging(listOwner, annotationFQName, false); return; } annotateExternally(listOwner, annotationFQName, xmlFileInRoot, fromFile, value); } else { final XmlFile annotationsXml = createAnnotationsXml(newRoot, packageName); if (annotationsXml != null) { final List<PsiFile> createdFiles = new ArrayList<PsiFile>(); createdFiles.add(annotationsXml); String fqn = getFQN(packageName, fromFile); if (fqn != null) { myExternalAnnotations.put(fqn, createdFiles); } } annotateExternally(listOwner, annotationFQName, annotationsXml, fromFile, value); } } }.execute(); }