Java Code Examples for com.intellij.util.containers.JBIterable#of()

The following examples show how to use com.intellij.util.containers.JBIterable#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeSpeedSearch.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected Object[] getAllElements() {
  JBIterable<TreePath> paths;
  if (myCanExpand) {
    paths = TreeUtil.treePathTraverser(myComponent).traverse();
  }
  else {
    TreePath[] arr = new TreePath[myComponent.getRowCount()];
    for (int i = 0; i < arr.length; i++) {
      arr[i] = myComponent.getPathForRow(i);
    }
    paths = JBIterable.of(arr);
  }
  List<TreePath> result = paths.filter(o -> !(o.getLastPathComponent() instanceof LoadingNode)).toList();
  return result.toArray(new TreePath[0]);
}
 
Example 2
Source File: ScratchFileActions.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  JBIterable<VirtualFile> files = JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY));
  if (project == null || files.isEmpty()) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  Condition<VirtualFile> isScratch = fileFilter(project);
  if (!files.filter(not(isScratch)).isEmpty()) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }
  Set<Language> languages = files.filter(isScratch).map(fileLanguage(project)).filter(notNull()).addAllTo(new LinkedHashSet<>());
  String langName = languages.size() == 1 ? languages.iterator().next().getDisplayName() : languages.size() + " different";
  e.getPresentation().setText(String.format("Change %s (%s)...", getLanguageTerm(), langName));
  e.getPresentation().setEnabledAndVisible(true);
}
 
Example 3
Source File: NavBarPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
JBIterable<?> getSelection() {
  Object value = myModel.getSelectedValue();
  if (value != null) return JBIterable.of(value);
  int size = myModel.size();
  return JBIterable.of(size > 0 ? myModel.getElement(size - 1) : null);
}
 
Example 4
Source File: AbstractProjectViewPane.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public List<PsiElement> getElementsFromNode(@Nullable Object node) {
  Object value = getValueFromNode(node);
  JBIterable<?> it = value instanceof PsiElement || value instanceof VirtualFile
                     ? JBIterable.of(value)
                     : value instanceof Object[] ? JBIterable.of((Object[])value) : value instanceof Iterable ? JBIterable.from((Iterable<?>)value) : JBIterable.of(TreeUtil.getUserObject(node));
  return it.flatten(o -> o instanceof RootsProvider ? ((RootsProvider)o).getRoots() : Collections.singleton(o))
          .map(o -> o instanceof VirtualFile ? PsiUtilCore.findFileSystemItem(myProject, (VirtualFile)o) : o).filter(PsiElement.class).filter(PsiElement::isValid).toList();
}
 
Example 5
Source File: InlineProgressIndicator.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected JBIterable<ProgressButton> createEastButtons() {
  return JBIterable.of(createCancelButton());
}
 
Example 6
Source File: UIUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static JBIterable<Component> uiChildren(@Nullable Component component) {
  if (!(component instanceof Container)) return JBIterable.empty();
  Container container = (Container)component;
  return JBIterable.of(container.getComponents());
}