use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElement in project intellij-community by JetBrains.
the class NamedLibraryUrl method createUrlByElement.
@Override
public AbstractUrl createUrlByElement(Object element) {
if (element instanceof NamedLibraryElement) {
NamedLibraryElement libraryElement = (NamedLibraryElement) element;
Module context = libraryElement.getModule();
return new NamedLibraryUrl(libraryElement.getOrderEntry().getPresentableName(), context != null ? context.getName() : null);
}
return null;
}
use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElement in project intellij-community by JetBrains.
the class FavoritesManager method contains.
// currently only one level here..
public boolean contains(@NotNull String name, @NotNull final VirtualFile vFile) {
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
final Set<Boolean> find = new HashSet<>();
final ContentIterator contentIterator = new ContentIterator() {
@Override
public boolean processFile(VirtualFile fileOrDir) {
if (fileOrDir != null && fileOrDir.getPath().equals(vFile.getPath())) {
find.add(Boolean.TRUE);
}
return true;
}
};
Collection<TreeItem<Pair<AbstractUrl, String>>> urls = getFavoritesListRootUrls(name);
for (TreeItem<Pair<AbstractUrl, String>> pair : urls) {
AbstractUrl abstractUrl = pair.getData().getFirst();
if (abstractUrl == null) {
continue;
}
final Object[] path = abstractUrl.createPath(myProject);
if (path == null || path.length < 1 || path[0] == null) {
continue;
}
Object element = path[path.length - 1];
if (element instanceof SmartPsiElementPointer) {
final VirtualFile virtualFile = PsiUtilBase.getVirtualFile(((SmartPsiElementPointer) element).getElement());
if (virtualFile == null)
continue;
if (vFile.getPath().equals(virtualFile.getPath())) {
return true;
}
if (!virtualFile.isDirectory()) {
continue;
}
projectFileIndex.iterateContentUnderDirectory(virtualFile, contentIterator);
}
if (element instanceof PsiElement) {
final VirtualFile virtualFile = PsiUtilBase.getVirtualFile((PsiElement) element);
if (virtualFile == null)
continue;
if (vFile.getPath().equals(virtualFile.getPath())) {
return true;
}
if (!virtualFile.isDirectory()) {
continue;
}
projectFileIndex.iterateContentUnderDirectory(virtualFile, contentIterator);
}
if (element instanceof Module) {
ModuleRootManager.getInstance((Module) element).getFileIndex().iterateContent(contentIterator);
}
if (element instanceof LibraryGroupElement) {
final boolean inLibrary = ModuleRootManager.getInstance(((LibraryGroupElement) element).getModule()).getFileIndex().isInContent(vFile) && projectFileIndex.isInLibraryClasses(vFile);
if (inLibrary) {
return true;
}
}
if (element instanceof NamedLibraryElement) {
NamedLibraryElement namedLibraryElement = (NamedLibraryElement) element;
final VirtualFile[] files = namedLibraryElement.getOrderEntry().getRootFiles(OrderRootType.CLASSES);
if (files != null && ArrayUtil.find(files, vFile) > -1) {
return true;
}
}
if (element instanceof ModuleGroup) {
ModuleGroup group = (ModuleGroup) element;
final Collection<Module> modules = group.modulesInGroup(myProject, true);
for (Module module : modules) {
ModuleRootManager.getInstance(module).getFileIndex().iterateContent(contentIterator);
}
}
for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
if (provider.elementContainsFile(element, vFile)) {
return true;
}
}
if (!find.isEmpty()) {
return true;
}
}
return false;
}
use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElement in project intellij-community by JetBrains.
the class FavoritesTreeNodeDescriptor method getLocation.
public static String getLocation(final AbstractTreeNode element, @NotNull final Project project) {
Object nodeElement = element.getValue();
if (nodeElement instanceof SmartPsiElementPointer) {
nodeElement = ((SmartPsiElementPointer) nodeElement).getElement();
}
if (nodeElement instanceof PsiElement) {
if (nodeElement instanceof PsiDirectory) {
return VfsUtilCore.getRelativeLocation(((PsiDirectory) nodeElement).getVirtualFile(), project.getBaseDir());
}
if (nodeElement instanceof PsiFile) {
final PsiFile containingFile = (PsiFile) nodeElement;
return VfsUtilCore.getRelativeLocation(containingFile.getVirtualFile(), project.getBaseDir());
}
}
if (nodeElement instanceof LibraryGroupElement) {
return ((LibraryGroupElement) nodeElement).getModule().getName();
}
if (nodeElement instanceof NamedLibraryElement) {
final NamedLibraryElement namedLibraryElement = ((NamedLibraryElement) nodeElement);
final Module module = namedLibraryElement.getModule();
return (module != null ? module.getName() : "") + ":" + namedLibraryElement.getOrderEntry().getPresentableName();
}
if (nodeElement instanceof File) {
return VfsUtilCore.getRelativeLocation(VfsUtil.findFileByIoFile((File) nodeElement, false), project.getBaseDir());
}
final FavoriteNodeProvider[] nodeProviders = Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project);
for (FavoriteNodeProvider provider : nodeProviders) {
String location = provider.getElementLocation(nodeElement);
if (location != null)
return location;
}
return null;
}
use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElement in project intellij-community by JetBrains.
the class CommanderPanel method getDataImpl.
public final Object getDataImpl(final String dataId) {
if (myBuilder == null)
return null;
final Object selectedValue = getSelectedValue();
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
final PsiElement selectedElement = getSelectedElement();
return selectedElement != null && selectedElement.isValid() ? selectedElement : null;
}
if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
return filterInvalidElements(getSelectedElements());
}
if (LangDataKeys.PASTE_TARGET_PSI_ELEMENT.is(dataId)) {
final AbstractTreeNode parentNode = myBuilder.getParentNode();
final Object element = parentNode != null ? parentNode.getValue() : null;
return element instanceof PsiElement && ((PsiElement) element).isValid() ? element : null;
}
if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
return getNavigatables();
}
if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCopyProvider() : null;
}
if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCutProvider() : null;
}
if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
return myCopyPasteDelegator != null ? myCopyPasteDelegator.getPasteProvider() : null;
}
if (LangDataKeys.IDE_VIEW.is(dataId)) {
return myIdeView;
}
if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
return myDeleteElementProvider;
}
if (LangDataKeys.MODULE.is(dataId)) {
return selectedValue instanceof Module ? selectedValue : null;
}
if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
return selectedValue instanceof ModuleGroup ? new ModuleGroup[] { (ModuleGroup) selectedValue } : null;
}
if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
return selectedValue instanceof LibraryGroupElement ? new LibraryGroupElement[] { (LibraryGroupElement) selectedValue } : null;
}
if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
return selectedValue instanceof NamedLibraryElement ? new NamedLibraryElement[] { (NamedLibraryElement) selectedValue } : null;
}
if (myProjectTreeStructure != null) {
return myProjectTreeStructure.getDataFromProviders(getSelectedNodes(), dataId);
}
return null;
}
use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElement in project intellij-community by JetBrains.
the class PyTreeStructureProvider method getPythonSdk.
@Nullable
private static Sdk getPythonSdk(@NotNull AbstractTreeNode node) {
if (node instanceof NamedLibraryElementNode) {
final NamedLibraryElement value = ((NamedLibraryElementNode) node).getValue();
if (value != null) {
final LibraryOrSdkOrderEntry entry = value.getOrderEntry();
if (entry instanceof JdkOrderEntry) {
final Sdk sdk = ((JdkOrderEntry) entry).getJdk();
final SdkTypeId type = sdk.getSdkType();
if (type instanceof PythonSdkType) {
return sdk;
}
}
}
}
return null;
}
Aggregations