use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class ExternalSystemFacadeManager method onProjectRename.
private static <V> void onProjectRename(@NotNull Map<IntegrationKey, V> data, @NotNull String oldName, @NotNull String newName) {
Set<IntegrationKey> keys = ContainerUtilRt.newHashSet(data.keySet());
for (IntegrationKey key : keys) {
if (!key.getIdeProjectName().equals(oldName)) {
continue;
}
IntegrationKey newKey = new IntegrationKey(newName, key.getIdeProjectLocationHash(), key.getExternalSystemId(), key.getExternalProjectConfigPath());
V value = data.get(key);
data.put(newKey, value);
data.remove(key);
if (value instanceof Consumer) {
//noinspection unchecked
((Consumer) value).consume(newKey);
}
}
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class FileTemplateUtil method mergeTemplate.
private static String mergeTemplate(String templateContent, final VelocityContext context, boolean useSystemLineSeparators, @Nullable Consumer<VelocityException> exceptionHandler) throws IOException {
final StringWriter stringWriter = new StringWriter();
try {
Project project = null;
final Object projectName = context.get(FileTemplateManager.PROJECT_NAME_VARIABLE);
if (projectName instanceof String) {
Project[] projects = ProjectManager.getInstance().getOpenProjects();
project = ContainerUtil.find(projects, project1 -> projectName.equals(project1.getName()));
}
VelocityWrapper.evaluate(project, context, stringWriter, templateContent);
} catch (final VelocityException e) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
LOG.error(e);
}
LOG.info("Error evaluating template:\n" + templateContent, e);
if (exceptionHandler == null) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(IdeBundle.message("error.parsing.file.template", e.getMessage()), IdeBundle.message("title.velocity.error")));
} else {
exceptionHandler.consume(e);
}
}
final String result = stringWriter.toString();
if (useSystemLineSeparators) {
final String newSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
if (!"\n".equals(newSeparator)) {
return StringUtil.convertLineSeparators(result, newSeparator);
}
}
return result;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class CompareWithSelectedRevisionAction method actionPerformed.
@Override
protected void actionPerformed(@NotNull VcsContext vcsContext) {
final VirtualFile file = vcsContext.getSelectedFiles()[0];
final Project project = vcsContext.getProject();
final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
final VcsHistoryProvider vcsHistoryProvider = vcs.getVcsHistoryProvider();
new VcsHistoryProviderBackgroundableProxy(vcs, vcsHistoryProvider, vcs.getDiffProvider()).createSessionFor(vcs.getKeyInstanceMethod(), VcsUtil.getFilePath(file), new Consumer<VcsHistorySession>() {
@Override
public void consume(VcsHistorySession session) {
if (session == null)
return;
final List<VcsFileRevision> revisions = session.getRevisionList();
final HistoryAsTreeProvider treeHistoryProvider = session.getHistoryAsTreeProvider();
if (treeHistoryProvider != null) {
showTreePopup(treeHistoryProvider.createTreeOn(revisions), file, project, vcs.getDiffProvider());
} else {
showListPopup(revisions, project, new Consumer<VcsFileRevision>() {
@Override
public void consume(final VcsFileRevision revision) {
DiffActionExecutor.showDiff(vcs.getDiffProvider(), revision.getRevisionNumber(), file, project, VcsBackgroundableActions.COMPARE_WITH);
}
}, true);
}
}
}, VcsBackgroundableActions.COMPARE_WITH, false, null);
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class ServerConnectionImpl method undeploy.
@Override
public void undeploy(@NotNull Deployment deployment, @NotNull final DeploymentRuntime runtime) {
final String deploymentName = deployment.getName();
final DeploymentImpl deploymentImpl;
final Map<String, ? extends DeploymentImpl> deploymentsMap;
synchronized (myLocalDeployments) {
synchronized (myRemoteDeployments) {
DeploymentImpl localDeployment = myLocalDeployments.get(deploymentName);
if (localDeployment != null) {
deploymentImpl = localDeployment;
deploymentsMap = myLocalDeployments;
} else {
DeploymentImpl remoteDeployment = myRemoteDeployments.get(deploymentName);
if (remoteDeployment != null) {
deploymentImpl = remoteDeployment;
deploymentsMap = myRemoteDeployments;
} else {
deploymentImpl = null;
deploymentsMap = null;
}
}
if (deploymentImpl != null) {
deploymentImpl.changeState(DeploymentStatus.DEPLOYED, DeploymentStatus.UNDEPLOYING, null, null);
}
}
}
myEventDispatcher.queueDeploymentsChanged(this);
DeploymentLogManagerImpl logManager = myLogManagers.get(deploymentName);
final LoggingHandlerImpl loggingHandler = logManager == null ? null : logManager.getMainLoggingHandler();
final Consumer<String> logConsumer = message -> {
if (loggingHandler == null) {
LOG.info(message);
} else {
loggingHandler.printlnSystemMessage(message);
}
};
logConsumer.consume("Undeploying '" + deploymentName + "'...");
runtime.undeploy(new DeploymentRuntime.UndeploymentTaskCallback() {
@Override
public void succeeded() {
logConsumer.consume("'" + deploymentName + "' has been undeployed successfully.");
if (deploymentImpl != null) {
synchronized (deploymentsMap) {
if (deploymentImpl.changeState(DeploymentStatus.UNDEPLOYING, DeploymentStatus.NOT_DEPLOYED, null, null)) {
deploymentsMap.remove(deploymentName);
}
}
}
DeploymentLogManagerImpl logManager = myLogManagers.remove(deploymentName);
if (logManager != null) {
logManager.disposeLogs();
}
myEventDispatcher.queueDeploymentsChanged(ServerConnectionImpl.this);
computeDeployments(myRuntimeInstance, EmptyRunnable.INSTANCE);
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
logConsumer.consume("Failed to undeploy '" + deploymentName + "': " + errorMessage);
if (deploymentImpl != null) {
synchronized (deploymentsMap) {
deploymentImpl.changeState(DeploymentStatus.UNDEPLOYING, DeploymentStatus.DEPLOYED, errorMessage, runtime);
}
}
myEventDispatcher.queueDeploymentsChanged(ServerConnectionImpl.this);
}
});
}
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);
}
};
}
Aggregations