Search in sources :

Example 41 with Consumer

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);
        }
    }
}
Also used : IntegrationKey(com.intellij.openapi.externalSystem.util.IntegrationKey) Consumer(com.intellij.util.Consumer)

Example 42 with Consumer

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;
}
Also used : java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) ContainerUtil(com.intellij.util.containers.ContainerUtil) ProjectManager(com.intellij.openapi.project.ProjectManager) CustomFileTemplate(com.intellij.ide.fileTemplates.impl.CustomFileTemplate) ParseException(org.apache.velocity.runtime.parser.ParseException) PsiElement(com.intellij.psi.PsiElement) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) StringUtils(org.apache.velocity.util.StringUtils) FileTypes(com.intellij.openapi.fileTypes.FileTypes) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Token(org.apache.velocity.runtime.parser.Token) org.apache.velocity.runtime.parser.node(org.apache.velocity.runtime.parser.node) Logger(com.intellij.openapi.diagnostic.Logger) VelocityException(org.apache.velocity.exception.VelocityException) Extensions(com.intellij.openapi.extensions.Extensions) ClassLoaderUtil(com.intellij.openapi.util.ClassLoaderUtil) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) StringUtil(com.intellij.openapi.util.text.StringUtil) StringWriter(java.io.StringWriter) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) IOException(java.io.IOException) FileType(com.intellij.openapi.fileTypes.FileType) CodeStyleSettingsManager(com.intellij.psi.codeStyle.CodeStyleSettingsManager) FileTypeManagerEx(com.intellij.openapi.fileTypes.ex.FileTypeManagerEx) VelocityContext(org.apache.velocity.VelocityContext) IdeBundle(com.intellij.ide.IdeBundle) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) StringReader(java.io.StringReader) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiDirectory(com.intellij.psi.PsiDirectory) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) Project(com.intellij.openapi.project.Project) StringWriter(java.io.StringWriter) VelocityException(org.apache.velocity.exception.VelocityException)

Example 43 with Consumer

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Consumer(com.intellij.util.Consumer) List(java.util.List) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 44 with Consumer

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);
        }
    });
}
Also used : com.intellij.remoteServer.runtime.deployment(com.intellij.remoteServer.runtime.deployment) java.util(java.util) ExecutionException(com.intellij.execution.ExecutionException) DeploymentLogManagerImpl(com.intellij.remoteServer.impl.runtime.log.DeploymentLogManagerImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) DeploymentConfiguration(com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration) Deployment(com.intellij.remoteServer.runtime.Deployment) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) LocalDeploymentImpl(com.intellij.remoteServer.impl.runtime.deployment.LocalDeploymentImpl) DebugConnectionData(com.intellij.remoteServer.runtime.deployment.debug.DebugConnectionData) DebugConnector(com.intellij.remoteServer.runtime.deployment.debug.DebugConnector) ConnectionStatus(com.intellij.remoteServer.runtime.ConnectionStatus) RemoteServer(com.intellij.remoteServer.configuration.RemoteServer) LoggingHandlerImpl(com.intellij.remoteServer.impl.runtime.log.LoggingHandlerImpl) DebugConnectionDataNotAvailableException(com.intellij.remoteServer.runtime.deployment.debug.DebugConnectionDataNotAvailableException) DeploymentTaskImpl(com.intellij.remoteServer.impl.runtime.deployment.DeploymentTaskImpl) Nullable(org.jetbrains.annotations.Nullable) ServerConnection(com.intellij.remoteServer.runtime.ServerConnection) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DeploymentImpl(com.intellij.remoteServer.impl.runtime.deployment.DeploymentImpl) ServerConnector(com.intellij.remoteServer.runtime.ServerConnector) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) LoggingHandlerImpl(com.intellij.remoteServer.impl.runtime.log.LoggingHandlerImpl) LocalDeploymentImpl(com.intellij.remoteServer.impl.runtime.deployment.LocalDeploymentImpl) DeploymentImpl(com.intellij.remoteServer.impl.runtime.deployment.DeploymentImpl) DeploymentLogManagerImpl(com.intellij.remoteServer.impl.runtime.log.DeploymentLogManagerImpl)

Example 45 with Consumer

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);
        }
    };
}
Also used : ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) DateFormatUtil(com.intellij.util.text.DateFormatUtil) LinkListener(com.intellij.ui.components.labels.LinkListener) Change(com.intellij.openapi.vcs.changes.Change) UIUtil.getWarningIcon(com.intellij.util.ui.UIUtil.getWarningIcon) ModalityState(com.intellij.openapi.application.ModalityState) PairConsumer(com.intellij.util.PairConsumer) com.intellij.ide.todo(com.intellij.ide.todo) ActionManager(com.intellij.openapi.actionSystem.ActionManager) VcsConfiguration(com.intellij.openapi.vcs.VcsConfiguration) Task(com.intellij.openapi.progress.Task) ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) Project(com.intellij.openapi.project.Project) LinkLabel(com.intellij.ui.components.labels.LinkLabel) Messages(com.intellij.openapi.ui.Messages) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) CheckinProjectPanel(com.intellij.openapi.vcs.CheckinProjectPanel) ToolWindow(com.intellij.openapi.wm.ToolWindow) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) Content(com.intellij.ui.content.Content) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) VcsBundle(com.intellij.openapi.vcs.VcsBundle) java.awt(java.awt) IdeBundle(com.intellij.ide.IdeBundle) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ServiceManager(com.intellij.openapi.components.ServiceManager) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ContentManager(com.intellij.ui.content.ContentManager) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) CommonBundle.getCancelButtonText(com.intellij.CommonBundle.getCancelButtonText) LinkListener(com.intellij.ui.components.labels.LinkListener) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) LinkLabel(com.intellij.ui.components.labels.LinkLabel) ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent)

Aggregations

Consumer (com.intellij.util.Consumer)59 NotNull (org.jetbrains.annotations.NotNull)41 Project (com.intellij.openapi.project.Project)37 Nullable (org.jetbrains.annotations.Nullable)33 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 List (java.util.List)22 ApplicationManager (com.intellij.openapi.application.ApplicationManager)17 StringUtil (com.intellij.openapi.util.text.StringUtil)17 javax.swing (javax.swing)16 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 Logger (com.intellij.openapi.diagnostic.Logger)14 Module (com.intellij.openapi.module.Module)12 java.awt (java.awt)12 Pair (com.intellij.openapi.util.Pair)11 java.util (java.util)11 File (java.io.File)10 Collection (java.util.Collection)10 PsiElement (com.intellij.psi.PsiElement)9 PsiFile (com.intellij.psi.PsiFile)9 DataContext (com.intellij.openapi.actionSystem.DataContext)8