use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.
the class GotoActionItemProvider method processActions.
private boolean processActions(String pattern, boolean everywhere, Processor<MatchedValue> consumer, DataContext dataContext) {
JBIterable<AnAction> actions;
if (everywhere) {
Set<String> ids = ((ActionManagerImpl) myActionManager).getActionIds();
actions = JBIterable.from(ids).transform(myActionManager::getAction).filter(Condition.NOT_NULL);
} else {
actions = JBIterable.from(myModel.myActionGroups.keySet());
}
MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
JBIterable<ActionWrapper> actionWrappers = actions.transform(action -> {
MatchMode mode = myModel.actionMatches(pattern, matcher, action);
if (mode == MatchMode.NONE)
return null;
return new ActionWrapper(action, myModel.myActionGroups.get(action), mode, dataContext);
}).filter(Condition.NOT_NULL);
return processItems(pattern, actionWrappers, consumer);
}
use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.
the class PluginsTableRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (myPluginDescriptor != null) {
Couple<Color> colors = UIUtil.getCellColors(table, isSelected, row, column);
Color fg = colors.getFirst();
final Color background = colors.getSecond();
Color grayedFg = isSelected ? fg : new JBColor(Gray._130, Gray._120);
myPanel.setBackground(background);
myName.setForeground(fg);
myCategory.setForeground(grayedFg);
myStatus.setForeground(grayedFg);
myLastUpdated.setForeground(grayedFg);
myDownloads.setForeground(grayedFg);
myName.clear();
myName.setOpaque(false);
myCategory.clear();
myCategory.setOpaque(false);
String pluginName = myPluginDescriptor.getName() + " ";
Object query = table.getClientProperty(SpeedSearchSupply.SEARCH_QUERY_KEY);
SimpleTextAttributes attr = new SimpleTextAttributes(UIUtil.getListBackground(isSelected), UIUtil.getListForeground(isSelected), JBColor.RED, SimpleTextAttributes.STYLE_PLAIN);
Matcher matcher = NameUtil.buildMatcher("*" + query, NameUtil.MatchingCaseSensitivity.NONE);
if (query instanceof String) {
SpeedSearchUtil.appendColoredFragmentForMatcher(pluginName, myName, attr, matcher, UIUtil.getTableBackground(isSelected), true);
} else {
myName.append(pluginName);
}
String category = myPluginDescriptor.getCategory() == null ? null : StringUtil.toUpperCase(myPluginDescriptor.getCategory());
if (category != null) {
if (query instanceof String) {
SpeedSearchUtil.appendColoredFragmentForMatcher(category, myCategory, attr, matcher, UIUtil.getTableBackground(isSelected), true);
} else {
myCategory.append(category);
}
} else if (!myPluginsView) {
myCategory.append(AvailablePluginsManagerMain.N_A);
}
myStatus.setIcon(AllIcons.Nodes.Plugin);
if (myPluginDescriptor.isBundled()) {
myCategory.append(" [Bundled]");
myStatus.setIcon(AllIcons.Nodes.PluginJB);
}
String vendor = myPluginDescriptor.getVendor();
if (vendor != null && StringUtil.containsIgnoreCase(vendor, "jetbrains")) {
myStatus.setIcon(AllIcons.Nodes.PluginJB);
}
String downloads = myPluginDescriptor.getDownloads();
if (downloads != null && myPluginDescriptor instanceof PluginNode) {
if (downloads.length() > 3) {
downloads = new DecimalFormat("#,###").format(Integer.parseInt(downloads));
}
myDownloads.setText(downloads);
myRating.setRate(((PluginNode) myPluginDescriptor).getRating());
myLastUpdated.setText(DateFormatUtil.formatBetweenDates(((PluginNode) myPluginDescriptor).getDate(), System.currentTimeMillis()));
}
// plugin state-dependent rendering
PluginId pluginId = myPluginDescriptor.getPluginId();
IdeaPluginDescriptor installed = PluginManager.getPlugin(pluginId);
if (installed != null && ((IdeaPluginDescriptorImpl) installed).isDeleted()) {
// existing plugin uninstalled (both views)
myStatus.setIcon(AllIcons.Nodes.PluginRestart);
if (!isSelected)
myName.setForeground(FileStatus.DELETED.getColor());
myPanel.setToolTipText(IdeBundle.message("plugin.manager.uninstalled.tooltip"));
} else if (ourState.wasInstalled(pluginId)) {
// new plugin installed (both views)
myStatus.setIcon(AllIcons.Nodes.PluginRestart);
if (!isSelected)
myName.setForeground(FileStatus.ADDED.getColor());
myPanel.setToolTipText(IdeBundle.message("plugin.manager.installed.tooltip"));
} else if (ourState.wasUpdated(pluginId)) {
// existing plugin updated (both views)
myStatus.setIcon(AllIcons.Nodes.PluginRestart);
if (!isSelected)
myName.setForeground(FileStatus.ADDED.getColor());
myPanel.setToolTipText(IdeBundle.message("plugin.manager.updated.tooltip"));
} else if (ourState.hasNewerVersion(pluginId)) {
// existing plugin has a newer version (both views)
myStatus.setIcon(AllIcons.Nodes.Pluginobsolete);
if (!isSelected)
myName.setForeground(FileStatus.MODIFIED.getColor());
if (!myPluginsView && installed != null) {
myPanel.setToolTipText(IdeBundle.message("plugin.manager.new.version.tooltip", installed.getVersion()));
} else {
myPanel.setToolTipText(IdeBundle.message("plugin.manager.update.available.tooltip"));
}
} else if (isIncompatible(myPluginDescriptor, table.getModel())) {
// a plugin is incompatible with current installation (both views)
if (!isSelected)
myName.setForeground(JBColor.RED);
myPanel.setToolTipText(whyIncompatible(myPluginDescriptor, table.getModel()));
} else if (!myPluginDescriptor.isEnabled() && myPluginsView) {
// a plugin is disabled (plugins view only)
myStatus.setIcon(IconLoader.getDisabledIcon(myStatus.getIcon()));
}
}
return myPanel;
}
use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.
the class ChooseByNameBase method rebuildList.
protected void rebuildList(final int pos, final int delay, @NotNull final ModalityState modalityState, @Nullable final Runnable postRunnable) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (!myInitialized) {
return;
}
myAlarm.cancelAllRequests();
if (delay > 0) {
myAlarm.addRequest(() -> rebuildList(pos, 0, modalityState, postRunnable), delay, ModalityState.stateForComponent(myTextField));
return;
}
myListUpdater.cancelAll();
final CalcElementsThread calcElementsThread = myCalcElementsThread;
if (calcElementsThread != null) {
calcElementsThread.cancel();
}
final String text = getTrimmedText();
if (!canShowListForEmptyPattern() && text.isEmpty()) {
myListModel.removeAll();
hideList();
myTextFieldPanel.hideHint();
myCard.show(myCardContainer, CHECK_BOX_CARD);
return;
}
ListCellRenderer cellRenderer = myList.getCellRenderer();
if (cellRenderer instanceof ExpandedItemListCellRendererWrapper) {
cellRenderer = ((ExpandedItemListCellRendererWrapper) cellRenderer).getWrappee();
}
final String pattern = patternToLowerCase(transformPattern(text));
final Matcher matcher = buildPatternMatcher(isSearchInAnyPlace() ? "*" + pattern : pattern);
if (cellRenderer instanceof MatcherHolder) {
((MatcherHolder) cellRenderer).setPatternMatcher(matcher);
}
MatcherHolder.associateMatcher(myList, matcher);
scheduleCalcElements(text, myCheckBox.isSelected(), modalityState, elements -> {
ApplicationManager.getApplication().assertIsDispatchThread();
backgroundCalculationFinished(elements, pos);
if (postRunnable != null) {
postRunnable.run();
}
});
}
Aggregations