com.intellij.util.containers.Convertor Java Examples

The following examples show how to use com.intellij.util.containers.Convertor. 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: DirectoryChooserModuleTreeView.java    From consulo with Apache License 2.0 6 votes vote down vote up
public DirectoryChooserModuleTreeView(@Nonnull Project project) {
  myRootNode = new DefaultMutableTreeNode();
  myTree = new Tree(myRootNode);
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  myProject = project;
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  myTree.setCellRenderer(new MyTreeCellRenderer());
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath o) {
      final Object userObject = ((DefaultMutableTreeNode)o.getLastPathComponent()).getUserObject();
      if (userObject instanceof Module) {
        return ((Module)userObject).getName();
      }
      else {
        if (userObject == null) return "";
        return userObject.toString();
      }
    }
  }, true);
}
 
Example #2
Source File: PantsTargetIndex.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
@NotNull
public Map<String, Void> map(@NotNull final FileContent inputData) {
  final PsiFile psiFile = inputData.getPsiFile();
  if (psiFile instanceof PyFile) {
    final Map<String, PyReferenceExpression> targetDefinitions = PantsPsiUtil.findTargetDefinitions((PyFile)psiFile);
    return ContainerUtil.newMapFromKeys(
      targetDefinitions.keySet().iterator(),
      new Convertor<String, Void>() {
        @Override
        public Void convert(String o) {
          return null;
        }
      }
    );
  }
  return Collections.emptyMap();
}
 
Example #3
Source File: JsonTreeTableView.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
public JsonTreeTableView(TreeNode rootNode, ColumnInfo[] columnInfos) {
    super(new ListTreeTableModelOnColumns(rootNode, columnInfos));
    this.columns = columnInfos;

    final TreeTableTree tree = getTree();

    tree.setShowsRootHandles(true);
    tree.setRootVisible(false);
    UIUtil.setLineStyleAngled(tree);
    setTreeCellRenderer(new KeyCellRenderer());

    TreeUtil.expand(tree, 2);

    new TreeTableSpeedSearch(this, new Convertor<TreePath, String>() {
        @Override
        public String convert(final TreePath path) {
            final NoSqlTreeNode node = (NoSqlTreeNode) path.getLastPathComponent();
            NodeDescriptor descriptor = node.getDescriptor();
            return descriptor.getFormattedKey();
        }
    });
}
 
Example #4
Source File: VfsUtilCore.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void processFilesRecursively(@Nonnull VirtualFile root, @Nonnull Processor<VirtualFile> processor, @Nonnull Convertor<VirtualFile, Boolean> directoryFilter) {
  if (!processor.process(root)) return;

  if (root.isDirectory() && directoryFilter.convert(root)) {
    final LinkedList<VirtualFile[]> queue = new LinkedList<VirtualFile[]>();

    queue.add(root.getChildren());

    do {
      final VirtualFile[] files = queue.removeFirst();

      for (VirtualFile file : files) {
        if (!processor.process(file)) return;
        if (file.isDirectory() && directoryFilter.convert(file)) {
          queue.add(file.getChildren());
        }
      }
    }
    while (!queue.isEmpty());
  }
}
 
Example #5
Source File: StepIntersection.java    From consulo with Apache License 2.0 6 votes vote down vote up
public StepIntersection(Convertor<Data, TextRange> dataConvertor,
                        Convertor<Area, TextRange> areasConvertor,
                        final List<Area> areas,
                        Getter<String> debugDocumentTextGetter) {
  myAreas = areas;
  myDebugDocumentTextGetter = debugDocumentTextGetter;
  myAreaIndex = 0;
  myDataConvertor = dataConvertor;
  myAreasConvertor = areasConvertor;
  myHackSearch = new HackSearch<Data, Area, TextRange>(myDataConvertor, myAreasConvertor, new Comparator<TextRange>() {
    @Override
    public int compare(TextRange o1, TextRange o2) {
      return o1.intersects(o2) ? 0 : o1.getStartOffset() < o2.getStartOffset() ? -1 : 1;
    }
  });
}
 
Example #6
Source File: HackSearch.java    From consulo with Apache License 2.0 6 votes vote down vote up
public HackSearch(Convertor<T, Z> TZConvertor, Convertor<S, Z> SZConvertor, Comparator<Z> zComparator) {
  myTZConvertor = TZConvertor;
  mySZConvertor = SZConvertor;
  myZComparator = zComparator;
  myComparator = new Comparator<S>() {
  @Override
  public int compare(S o1, S o2) {
    Z z1 = mySZConvertor.convert(o1);
    Z z2 = mySZConvertor.convert(o2);
    if (o1 == myFake) {
      z1 = myFakeConverted;
    } else if (o2 == myFake) {
      z2 = myFakeConverted;
    }
    return myZComparator.compare(z1, z2);
  }
};
}
 
Example #7
Source File: OptionsAndConfirmations.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void init(final Convertor<String, VcsShowConfirmationOption.Value> initOptions) {
  createSettingFor(VcsConfiguration.StandardOption.ADD);
  createSettingFor(VcsConfiguration.StandardOption.REMOVE);
  createSettingFor(VcsConfiguration.StandardOption.CHECKOUT);
  createSettingFor(VcsConfiguration.StandardOption.UPDATE);
  createSettingFor(VcsConfiguration.StandardOption.STATUS);
  createSettingFor(VcsConfiguration.StandardOption.EDIT);

  myConfirmations.put(VcsConfiguration.StandardConfirmation.ADD.getId(), new VcsShowConfirmationOptionImpl(
    VcsConfiguration.StandardConfirmation.ADD.getId(),
    VcsBundle.message("label.text.when.files.created.with.idea", ApplicationNamesInfo.getInstance().getProductName()),
    VcsBundle.message("radio.after.creation.do.not.add"), VcsBundle.message("radio.after.creation.show.options"),
    VcsBundle.message("radio.after.creation.add.silently")));

  myConfirmations.put(VcsConfiguration.StandardConfirmation.REMOVE.getId(), new VcsShowConfirmationOptionImpl(
    VcsConfiguration.StandardConfirmation.REMOVE.getId(),
    VcsBundle.message("label.text.when.files.are.deleted.with.idea", ApplicationNamesInfo.getInstance().getProductName()),
    VcsBundle.message("radio.after.deletion.do.not.remove"), VcsBundle.message("radio.after.deletion.show.options"),
    VcsBundle.message("radio.after.deletion.remove.silently")));

  restoreReadConfirm(VcsConfiguration.StandardConfirmation.ADD, initOptions);
  restoreReadConfirm(VcsConfiguration.StandardConfirmation.REMOVE, initOptions);
}
 
Example #8
Source File: IssueLinkHtmlRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"HardCodedStringLiteral"})
public static String formatTextWithLinks(final Project project, final String c, final Convertor<String, String> convertor) {
  if (c == null) return "";
  String comment = XmlTagUtilBase.escapeString(c, false);

  StringBuilder commentBuilder = new StringBuilder();
  IssueNavigationConfiguration config = IssueNavigationConfiguration.getInstance(project);
  final List<IssueNavigationConfiguration.LinkMatch> list = config.findIssueLinks(comment);
  int pos = 0;
  for(IssueNavigationConfiguration.LinkMatch match: list) {
    TextRange range = match.getRange();
    commentBuilder.append(convertor.convert(comment.substring(pos, range.getStartOffset()))).append("<a href=\"").append(match.getTargetUrl()).append("\">");
    commentBuilder.append(range.substring(comment)).append("</a>");
    pos = range.getEndOffset();
  }
  commentBuilder.append(convertor.convert(comment.substring(pos)));
  comment = commentBuilder.toString();

  return comment.replace("\n", "<br>");
}
 
Example #9
Source File: ModulesDependenciesPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void initTree(Tree tree, boolean isRightTree) {
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  tree.setCellRenderer(new MyTreeCellRenderer());
  tree.setRootVisible(false);
  tree.setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(tree);

  TreeUtil.installActions(tree);
  new TreeSpeedSearch(tree, new Convertor<TreePath, String>() {
    @Override
    public String convert(TreePath o) {
      return o.getLastPathComponent().toString();
    }
  }, true);
  PopupHandler.installUnknownPopupHandler(tree, createTreePopupActions(isRightTree, tree), ActionManager.getInstance());
}
 
Example #10
Source File: MemberChooser.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void installSpeedSearch() {
  final TreeSpeedSearch treeSpeedSearch = new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    @Nullable
    public String convert(TreePath path) {
      final ElementNode lastPathComponent = (ElementNode)path.getLastPathComponent();
      if (lastPathComponent == null) return null;
      String text = lastPathComponent.getDelegate().getText();
      if (text != null) {
        text = convertElementText(text);
      }
      return text;
    }
  });
  treeSpeedSearch.setComparator(getSpeedSearchComparator());
}
 
Example #11
Source File: ScopeChooserConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void initTree() {
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      final TreePath path = e.getOldLeadSelectionPath();
      if (path != null) {
        final MyNode node = (MyNode)path.getLastPathComponent();
        final NamedConfigurable namedConfigurable = node.getConfigurable();
        if (namedConfigurable instanceof ScopeConfigurable) {
          ((ScopeConfigurable)namedConfigurable).cancelCurrentProgress();
        }
      }
    }
  });
  super.initTree();
  myTree.setShowsRootHandles(false);
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath treePath) {
      return ((MyNode)treePath.getLastPathComponent()).getDisplayName();
    }
  }, true);

  myTree.getEmptyText().setText(IdeBundle.message("scopes.no.scoped"));
}
 
Example #12
Source File: BaseStructureConfigurableNoDaemon.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTree() {
  if (myWasTreeInitialized) return;
  myWasTreeInitialized = true;

  super.initTree();
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath treePath) {
      return ((MyNode)treePath.getLastPathComponent()).getDisplayName();
    }
  }, true);
  ToolTipManager.sharedInstance().registerComponent(myTree);
  myTree.setCellRenderer(new ProjectStructureElementRenderer(null));
}
 
Example #13
Source File: BaseStructureConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTree() {
  if (myWasTreeInitialized) return;
  myWasTreeInitialized = true;

  super.initTree();
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath treePath) {
      return ((MyNode)treePath.getLastPathComponent()).getDisplayName();
    }
  }, true);
  ToolTipManager.sharedInstance().registerComponent(myTree);
  myTree.setCellRenderer(new ProjectStructureElementRenderer(myContext));
}
 
Example #14
Source File: InspectionTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
public InspectionTree(@Nonnull Project project, @Nonnull GlobalInspectionContextImpl context) {
  super(new InspectionRootNode(project));
  myContext = context;

  setCellRenderer(new CellRenderer());
  setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(this);
  addTreeWillExpandListener(new ExpandListener());

  myExpandedUserObjects = new HashSet<Object>();
  myExpandedUserObjects.add(project);

  TreeUtil.installActions(this);
  new TreeSpeedSearch(this, new Convertor<TreePath, String>() {
    @Override
    public String convert(TreePath o) {
      return InspectionsConfigTreeComparator.getDisplayTextToSort(o.getLastPathComponent().toString());
    }
  });

  addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      TreePath newSelection = e.getNewLeadSelectionPath();
      if (newSelection != null) {
        mySelectionPath = new SelectionPath(newSelection);
      }
    }
  });
}
 
Example #15
Source File: LayoutTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureUiHelper(TreeUIHelper helper) {
  final Convertor<TreePath, String> convertor = new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath path) {
      final SimpleNode node = getNodeFor(path);
      if (node instanceof PackagingElementNode) {
        return ((PackagingElementNode<?>)node).getElementPresentation().getSearchName();
      }
      return "";
    }
  };
  new TreeSpeedSearch(this, convertor, true);
}
 
Example #16
Source File: FavoritesManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public synchronized boolean removeRoot(@Nonnull String name, @Nonnull List<AbstractTreeNode> elements) {
  final Convertor<AbstractTreeNode, AbstractUrl> convertor = new Convertor<AbstractTreeNode, AbstractUrl>() {
    @Override
    public AbstractUrl convert(AbstractTreeNode obj) {
      return createUrlByElement(obj.getValue(), myProject);
    }
  };
  boolean result = true;
  for (AbstractTreeNode element : elements) {
    final List<AbstractTreeNode> path = TaskDefaultFavoriteListProvider.getPathToUsualNode(element);
    result &= findListToRemoveFrom(name, path.subList(1, path.size()), convertor);
  }
  return result;
}
 
Example #17
Source File: MacroManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public String expandSilentMarcos(String str, boolean firstQueueExpand, DataContext dataContext) throws Macro.ExecutionCancelledException {
  final Convertor<Macro, Macro> convertor = new Convertor<Macro, Macro>() {
    @Override
    public Macro convert(Macro macro) {
      if (macro instanceof PromptingMacro) {
        return new Macro.Silent(macro, "");
      }
      return macro;
    }
  };
  return expandMacroSet(
    str, firstQueueExpand, dataContext, ConvertingIterator.create(getMacros().iterator(), convertor)
  );
}
 
Example #18
Source File: CoverageSuiteChooserDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CoverageSuiteChooserDialog(Project project) {
  super(project, true);
  myProject = project;
  myCoverageManager = CoverageDataManager.getInstance(project);

  myRootNode = new CheckedTreeNode("");
  initTree();
  mySuitesTree = new CheckboxTree(new SuitesRenderer(), myRootNode) {
    protected void installSpeedSearch() {
      new TreeSpeedSearch(this, new Convertor<TreePath, String>() {
        public String convert(TreePath path) {
          final DefaultMutableTreeNode component = (DefaultMutableTreeNode)path.getLastPathComponent();
          final Object userObject = component.getUserObject();
          if (userObject instanceof CoverageSuite) {
            return ((CoverageSuite)userObject).getPresentableName();
          }
          return userObject.toString();
        }
      });
    }
  };
  mySuitesTree.getEmptyText().appendText("No coverage suites configured.");
  mySuitesTree.setRootVisible(false);
  mySuitesTree.setShowsRootHandles(false);
  TreeUtil.installActions(mySuitesTree);
  TreeUtil.expandAll(mySuitesTree);
  TreeUtil.selectFirstNode(mySuitesTree);
  mySuitesTree.setMinimumSize(new Dimension(25, -1));
  setOKButtonText("Show selected");
  init();
  setTitle("Choose Coverage Suite to Display");
}
 
Example #19
Source File: TestTreeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void installHandlers() {
  EditSourceOnDoubleClickHandler.install(this);
  new TreeSpeedSearch(this, new Convertor<TreePath, String>() {
    public String convert(final TreePath path) {
      final AbstractTestProxy testProxy = getSelectedTest(path);
      if (testProxy == null) return null;
      return testProxy.getName();
    }
  });
  TreeUtil.installActions(this);
  PopupHandler.installPopupHandler(this, IdeActions.GROUP_TESTTREE_POPUP, ActionPlaces.TESTTREE_VIEW_POPUP);
}
 
Example #20
Source File: FavoritesManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private <T> boolean findListToRemoveFrom(@Nonnull String name, @Nonnull final List<T> elements, final Convertor<T, AbstractUrl> convertor) {
  Collection<TreeItem<Pair<AbstractUrl, String>>> list = getFavoritesListRootUrls(name);
  if (elements.size() > 1) {
    final List<T> sublist = elements.subList(0, elements.size() - 1);
    for (T obj : sublist) {
      AbstractUrl objUrl = convertor.convert(obj);
      final TreeItem<Pair<AbstractUrl, String>> item = findNextItem(objUrl, list);
      if (item == null || item.getChildren() == null) return false;
      list = item.getChildren();
    }
  }

  TreeItem<Pair<AbstractUrl, String>> found = null;
  AbstractUrl url = convertor.convert(elements.get(elements.size() - 1));
  if (url == null) return false;
  for (TreeItem<Pair<AbstractUrl, String>> pair : list) {
    if (url.equals(pair.getData().getFirst())) {
      found = pair;
      break;
    }
  }

  if (found != null) {
    list.remove(found);
    rootsChanged();
    return true;
  }
  return false;
}
 
Example #21
Source File: TriggerAdditionOrDeletion.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void prepare() {
  if (myExisting.isEmpty() && myDeleted.isEmpty()) return;

  final SortByVcsRoots<FilePath> sortByVcsRoots = new SortByVcsRoots<>(myProject, new Convertor.IntoSelf<>());

  if (! myExisting.isEmpty()) {
    processAddition(sortByVcsRoots);
  }
  if (! myDeleted.isEmpty()) {
    processDeletion(sortByVcsRoots);
  }
}
 
Example #22
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected ChangesBrowserNode getParentNodeFor(@Nonnull StaticFilePath nodePath, @Nonnull ChangesBrowserNode subtreeRoot, @Nonnull Convertor<StaticFilePath, ChangesBrowserNode> nodeBuilder) {
  if (myShowFlatten) {
    return subtreeRoot;
  }

  ChangesGroupingPolicy policy = myGroupingPoliciesCache.get(subtreeRoot);
  if (policy != null) {
    ChangesBrowserNode nodeFromPolicy = policy.getParentNodeFor(nodePath, subtreeRoot);
    if (nodeFromPolicy != null) {
      return nodeFromPolicy;
    }
  }

  StaticFilePath parentPath = nodePath.getParent();
  while (parentPath != null) {
    ChangesBrowserNode oldParentNode = getFolderCache(subtreeRoot).get(parentPath.getKey());
    if (oldParentNode != null) return oldParentNode;

    ChangesBrowserNode parentNode = nodeBuilder.convert(parentPath);
    if (parentNode != null) {
      ChangesBrowserNode grandPa = getParentNodeFor(parentPath, subtreeRoot, nodeBuilder);
      myModel.insertNodeInto(parentNode, grandPa, grandPa.getChildCount());
      getFolderCache(subtreeRoot).put(parentPath.getKey(), parentNode);
      return parentNode;
    }

    parentPath = parentPath.getParent();
  }

  return subtreeRoot;
}
 
Example #23
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void insertChangeNode(@Nonnull Object change,
                                @Nonnull ChangesBrowserNode subtreeRoot,
                                @Nonnull ChangesBrowserNode node,
                                @Nonnull Convertor<StaticFilePath, ChangesBrowserNode> nodeBuilder) {
  final StaticFilePath pathKey = getKey(change);
  ChangesBrowserNode parentNode = getParentNodeFor(pathKey, subtreeRoot, nodeBuilder);
  myModel.insertNodeInto(node, parentNode, myModel.getChildCount(parentNode));

  if (pathKey.isDirectory()) {
    getFolderCache(subtreeRoot).put(pathKey.getKey(), node);
  }
}
 
Example #24
Source File: ColumnFilteringStrategy.java    From consulo with Apache License 2.0 5 votes vote down vote up
public <T> void addNext(final Collection<T> values, final Convertor<T, String> convertor) {
  final TreeSet<String> set = new TreeSet<String>(Arrays.asList(myValues));
  for (T value : values) {
    final String converted = convertor.convert(value);
    if (converted != null) {
      // also works as filter
      set.add(converted);
    }
  }
  myValues = ArrayUtil.toStringArray(set);
  fireContentsChanged(this, 0, myValues.length);
}
 
Example #25
Source File: MatchPatchPaths.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void putSelected(@Nonnull MultiMap<VirtualFile, AbstractFilePatchInProgress> result,
                                @Nonnull final List<AbstractFilePatchInProgress> variants,
                                @Nonnull AbstractFilePatchInProgress patchInProgress) {
  patchInProgress.setAutoBases(ObjectsConvertor.convert(variants, new Convertor<AbstractFilePatchInProgress, VirtualFile>() {
    @Override
    public VirtualFile convert(AbstractFilePatchInProgress o) {
      return o.getBase();
    }
  }, ObjectsConvertor.NOT_NULL));
  result.putValue(patchInProgress.getBase(), patchInProgress);
}
 
Example #26
Source File: MatchPatchPaths.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void findCandidates(@Nonnull List<? extends FilePatch> list,
                            @Nonnull final PatchBaseDirectoryDetector directoryDetector,
                            @Nonnull List<PatchAndVariants> candidates, @Nonnull List<FilePatch> newOrWithoutMatches) {
  for (final FilePatch patch : list) {
    final String fileName = patch.getBeforeFileName();
    if (patch.isNewFile() || (patch.getBeforeName() == null)) {
      newOrWithoutMatches.add(patch);
      continue;
    }
    final Collection<VirtualFile> files = new ArrayList<>(findFilesFromIndex(directoryDetector, fileName));
    // for directories outside the project scope but under version control
    if (patch.getBeforeName() != null && patch.getBeforeName().startsWith("..")) {
      final VirtualFile relativeFile = VfsUtil.findRelativeFile(myBaseDir, patch.getBeforeName().replace('\\', '/').split("/"));
      if (relativeFile != null) {
        files.add(relativeFile);
      }
    }
    if (files.isEmpty()) {
      newOrWithoutMatches.add(patch);
    }
    else {
      //files order is not defined, so get the best variant depends on it, too
      final List<AbstractFilePatchInProgress> variants =
              ObjectsConvertor.convert(files, new Convertor<VirtualFile, AbstractFilePatchInProgress>() {
                @Override
                public AbstractFilePatchInProgress convert(VirtualFile o) {
                  return processMatch(patch, o);
                }
              }, ObjectsConvertor.NOT_NULL);
      if (variants.isEmpty()) {
        newOrWithoutMatches.add(patch); // just to be sure
      }
      else {
        candidates.add(new PatchAndVariants(variants));
      }
    }
  }
}
 
Example #27
Source File: OptionsAndConfirmations.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void restoreReadConfirm(final VcsConfiguration.StandardConfirmation confirm,
                                final Convertor<String, VcsShowConfirmationOption.Value> initOptions) {
  final VcsShowConfirmationOption.Value initValue = initOptions.convert(confirm.getId());
  if (initValue != null) {
    getConfirmation(confirm).setValue(initValue);
  }
}
 
Example #28
Source File: SettingsEditorWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public SettingsEditorWrapper(SettingsEditor<Dst> wrapped, Convertor<Src, Dst> convertor) {
  mySrcToDstConvertor = convertor;
  myWrapped = wrapped;
  myListener = new SettingsEditorListener<Dst>() {
    public void stateChanged(SettingsEditor<Dst> settingsEditor) {
      fireEditorStateChanged();
    }
  };
  myWrapped.addSettingsEditorListener(myListener);
}
 
Example #29
Source File: ObjectsConvertor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T,U, S extends U> List<S> convert(@Nonnull final Collection<T> in, final Convertor<T,S> convertor,
                                                 @Nullable final NotNullFunction<U, Boolean> outFilter) {
  final List<S> out = new ArrayList<S>();
  for (T t : in) {
    final S converted = convertor.convert(t);
    if ((outFilter != null) && (! Boolean.TRUE.equals(outFilter.fun(converted)))) continue;
    out.add(converted);
  }
  return out;
}
 
Example #30
Source File: IdeaTextPatchBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static List<BeforeAfter<AirContentRevision>> revisionsConvertor(final Project project, final List<Change> changes) throws VcsException {
  final List<BeforeAfter<AirContentRevision>> result = new ArrayList<BeforeAfter<AirContentRevision>>(changes.size());

  final Convertor<Change, FilePath> beforePrefferingConvertor = new Convertor<Change, FilePath>() {
    @Override
    public FilePath convert(Change o) {
      final FilePath before = ChangesUtil.getBeforePath(o);
      return before == null ? ChangesUtil.getAfterPath(o) : before;
    }
  };
  final MultiMap<VcsRoot,Change> byRoots = new SortByVcsRoots<Change>(project, beforePrefferingConvertor).sort(changes);

  for (VcsRoot root : byRoots.keySet()) {
    final Collection<Change> rootChanges = byRoots.get(root);
    if (root.getVcs() == null || root.getVcs().getOutgoingChangesProvider() == null) {
      addConvertChanges(rootChanges, result);
      continue;
    }
    final VcsOutgoingChangesProvider<?> provider = root.getVcs().getOutgoingChangesProvider();
    final Collection<Change> basedOnLocal = provider.filterLocalChangesBasedOnLocalCommits(rootChanges, root.getPath());
    rootChanges.removeAll(basedOnLocal);
    addConvertChanges(rootChanges, result);

    for (Change change : basedOnLocal) {
      // dates are here instead of numbers
      result.add(new BeforeAfter<AirContentRevision>(convertRevision(change.getBeforeRevision(), provider),
                                                     convertRevision(change.getAfterRevision(), provider)));
    }
  }
  return result;
}