use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class TodoCheckinHandler method getBeforeCheckinConfigurationPanel.
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
JCheckBox checkBox = new JCheckBox(VcsBundle.message("before.checkin.new.todo.check", ""));
return new RefreshableOnComponent() {
@Override
public JComponent getComponent() {
JPanel panel = new JPanel(new BorderLayout(4, 0));
panel.add(checkBox, BorderLayout.WEST);
setFilterText(myConfiguration.myTodoPanelSettings.todoFilterName);
if (myConfiguration.myTodoPanelSettings.todoFilterName != null) {
myTodoFilter = TodoConfiguration.getInstance().getTodoFilter(myConfiguration.myTodoPanelSettings.todoFilterName);
}
Consumer<TodoFilter> consumer = todoFilter -> {
myTodoFilter = todoFilter;
String name = todoFilter == null ? null : todoFilter.getName();
myConfiguration.myTodoPanelSettings.todoFilterName = name;
setFilterText(name);
};
LinkLabel linkLabel = new LinkLabel("Configure", null);
linkLabel.setListener(new LinkListener() {
@Override
public void linkSelected(LinkLabel aSource, Object aLinkData) {
DefaultActionGroup group = SetTodoFilterAction.createPopupActionGroup(myProject, myConfiguration.myTodoPanelSettings, consumer);
ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.TODO_VIEW_TOOLBAR, group);
popupMenu.getComponent().show(linkLabel, 0, linkLabel.getHeight());
}
}, null);
panel.add(linkLabel, BorderLayout.CENTER);
CheckinHandlerUtil.disableWhenDumb(myProject, checkBox, "TODO check is impossible until indices are up-to-date");
return panel;
}
private void setFilterText(String filterName) {
if (filterName == null) {
checkBox.setText(VcsBundle.message("before.checkin.new.todo.check", IdeBundle.message("action.todo.show.all")));
} else {
checkBox.setText(VcsBundle.message("before.checkin.new.todo.check", "Filter: " + filterName));
}
}
@Override
public void refresh() {
}
@Override
public void saveState() {
myConfiguration.CHECK_NEW_TODO = checkBox.isSelected();
}
@Override
public void restoreState() {
checkBox.setSelected(myConfiguration.CHECK_NEW_TODO);
}
};
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class NavBarPanel method getHintContainerShowPoint.
AsyncResult<RelativePoint> getHintContainerShowPoint() {
final AsyncResult<RelativePoint> result = new AsyncResult<>();
if (myLocationCache == null) {
if (myHintContainer != null) {
final Point p = AbstractPopup.getCenterOf(myHintContainer, this);
p.y -= myHintContainer.getVisibleRect().height / 4;
myLocationCache = RelativePoint.fromScreen(p);
} else {
if (myContextComponent != null) {
myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent));
} else {
DataManager.getInstance().getDataContextFromFocus().doWhenDone((Consumer<DataContext>) dataContext -> {
myContextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent));
});
}
}
}
final Component c = myLocationCache.getComponent();
if (!(c instanceof JComponent && c.isShowing())) {
//Yes. It happens sometimes.
// 1. Empty frame. call nav bar, select some package and open it in Project View
// 2. Call nav bar, then Esc
// 3. Hide all tool windows (Ctrl+Shift+F12), so we've got empty frame again
// 4. Call nav bar. NPE. ta da
final JComponent ideFrame = WindowManager.getInstance().getIdeFrame(getProject()).getComponent();
final JRootPane rootPane = UIUtil.getRootPane(ideFrame);
myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(rootPane);
}
result.setDone(myLocationCache);
return result;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class SvnCommittedChangesProvider method loadCommittedChanges.
@Override
public void loadCommittedChanges(@NotNull ChangeBrowserSettings settings, @NotNull RepositoryLocation location, int maxCount, @NotNull AsynchConsumer<CommittedChangeList> consumer) throws VcsException {
try {
SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location;
String repositoryRoot = getRepositoryRoot(svnLocation);
ChangeBrowserSettings.Filter filter = settings.createFilter();
Consumer<LogEntry> resultConsumer = logEntry -> {
SvnChangeList list = new SvnChangeList(myVcs, svnLocation, logEntry, repositoryRoot);
if (filter.accepts(list)) {
consumer.consume(list);
}
};
SvnTarget target = SvnTarget.fromURL(svnLocation.toSvnUrl(), createBeforeRevision(settings));
getCommittedChangesImpl(settings, target, maxCount, resultConsumer, false, true);
} finally {
consumer.finished();
}
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class SvnCommittedChangesProvider method getCommittedChanges.
@Override
@NotNull
public List<SvnChangeList> getCommittedChanges(@NotNull ChangeBrowserSettings settings, @NotNull RepositoryLocation location, int maxCount) throws VcsException {
SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location;
List<SvnChangeList> result = newArrayList();
String repositoryRoot = getRepositoryRoot(svnLocation);
Consumer<LogEntry> resultConsumer = logEntry -> result.add(new SvnChangeList(myVcs, svnLocation, logEntry, repositoryRoot));
SvnTarget target = SvnTarget.fromURL(svnLocation.toSvnUrl(), createBeforeRevision(settings));
getCommittedChangesImpl(settings, target, maxCount, resultConsumer, false, true);
settings.filterChanges(result);
return result;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class PropertiesCopyHandler method copyPropertyToAnotherBundle.
private static void copyPropertyToAnotherBundle(@NotNull Collection<IProperty> properties, @NotNull final String newName, @NotNull ResourceBundle targetResourceBundle) {
final Map<IProperty, PropertiesFile> propertiesFileMapping = new HashMap<>();
for (IProperty property : properties) {
final PropertiesFile containingFile = property.getPropertiesFile();
final PropertiesFile matched = findWithMatchedSuffix(containingFile, targetResourceBundle);
if (matched != null) {
propertiesFileMapping.put(property, matched);
}
}
final Project project = targetResourceBundle.getProject();
if (properties.size() != propertiesFileMapping.size() && Messages.NO == Messages.showYesNoDialog(project, "Source and target resource bundles properties files are not matched correctly. Copy properties anyway?", "Resource Bundles Are not Matched", null)) {
return;
}
if (!propertiesFileMapping.isEmpty()) {
WriteCommandAction.runWriteCommandAction(project, () -> {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(ContainerUtil.map(propertiesFileMapping.values(), (Function<PropertiesFile, PsiElement>) PropertiesFile::getContainingFile)))
return;
for (Map.Entry<IProperty, PropertiesFile> entry : propertiesFileMapping.entrySet()) {
final String value = entry.getKey().getValue();
final PropertiesFile target = entry.getValue();
target.addProperty(newName, value);
}
});
final IProperty representativeFromSourceBundle = ContainerUtil.getFirstItem(properties);
LOG.assertTrue(representativeFromSourceBundle != null);
final ResourceBundle sourceResourceBundle = representativeFromSourceBundle.getPropertiesFile().getResourceBundle();
if (sourceResourceBundle.equals(targetResourceBundle)) {
DataManager.getInstance().getDataContextFromFocus().doWhenDone((Consumer<DataContext>) context -> {
final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (fileEditor instanceof ResourceBundleEditor) {
final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor) fileEditor;
resourceBundleEditor.updateTreeRoot();
resourceBundleEditor.selectProperty(newName);
}
});
} else {
for (FileEditor editor : FileEditorManager.getInstance(project).openFile(new ResourceBundleAsVirtualFile(targetResourceBundle), true)) {
((ResourceBundleEditor) editor).updateTreeRoot();
((ResourceBundleEditor) editor).selectProperty(newName);
}
}
}
}
Aggregations