Search in sources :

Example 6 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class CodeSmellDetectorImpl method findCodeSmells.

@NotNull
private List<CodeSmellInfo> findCodeSmells(@NotNull final VirtualFile file, @NotNull final ProgressIndicator progress) {
    final List<CodeSmellInfo> result = Collections.synchronizedList(new ArrayList<CodeSmellInfo>());
    final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(myProject);
    final ProgressIndicator daemonIndicator = new DaemonProgressIndicator();
    ((ProgressIndicatorEx) progress).addStateDelegate(new AbstractProgressIndicatorExBase() {

        @Override
        public void cancel() {
            super.cancel();
            daemonIndicator.cancel();
        }
    });
    ProgressManager.getInstance().runProcess(new Runnable() {

        @Override
        public void run() {
            DumbService.getInstance(myProject).runReadActionInSmartMode(new Runnable() {

                @Override
                public void run() {
                    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
                    final Document document = FileDocumentManager.getInstance().getDocument(file);
                    if (psiFile == null || document == null) {
                        return;
                    }
                    List<HighlightInfo> infos = codeAnalyzer.runMainPasses(psiFile, document, daemonIndicator);
                    convertErrorsAndWarnings(infos, result, document);
                }
            });
        }
    }, daemonIndicator);
    return result;
}
Also used : CodeSmellInfo(com.intellij.codeInsight.CodeSmellInfo) Document(com.intellij.openapi.editor.Document) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class ExternalSystemUtil method refreshProject.

public static void refreshProject(@NotNull final String externalProjectPath, @NotNull final ImportSpec importSpec) {
    Project project = importSpec.getProject();
    ProjectSystemId externalSystemId = importSpec.getExternalSystemId();
    ExternalProjectRefreshCallback callback = importSpec.getCallback();
    boolean isPreviewMode = importSpec.isPreviewMode();
    ProgressExecutionMode progressExecutionMode = importSpec.getProgressExecutionMode();
    boolean reportRefreshError = importSpec.isReportRefreshError();
    String arguments = importSpec.getArguments();
    String vmOptions = importSpec.getVmOptions();
    File projectFile = new File(externalProjectPath);
    final String projectName;
    if (projectFile.isFile()) {
        projectName = projectFile.getParentFile().getName();
    } else {
        projectName = projectFile.getName();
    }
    final TaskUnderProgress refreshProjectStructureTask = new TaskUnderProgress() {

        private final ExternalSystemResolveProjectTask myTask = new ExternalSystemResolveProjectTask(externalSystemId, project, externalProjectPath, vmOptions, arguments, isPreviewMode);

        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "IOResourceOpenedButNotSafelyClosed" })
        @Override
        public void execute(@NotNull ProgressIndicator indicator) {
            if (project.isDisposed())
                return;
            if (indicator instanceof ProgressIndicatorEx) {
                ((ProgressIndicatorEx) indicator).addStateDelegate(new AbstractProgressIndicatorExBase() {

                    @Override
                    public void cancel() {
                        super.cancel();
                        ApplicationManager.getApplication().executeOnPooledThread((Runnable) () -> myTask.cancel(ExternalSystemTaskNotificationListener.EP_NAME.getExtensions()));
                    }
                });
            }
            ExternalSystemProcessingManager processingManager = ServiceManager.getService(ExternalSystemProcessingManager.class);
            if (processingManager.findTask(ExternalSystemTaskType.RESOLVE_PROJECT, externalSystemId, externalProjectPath) != null) {
                if (callback != null) {
                    callback.onFailure(ExternalSystemBundle.message("error.resolve.already.running", externalProjectPath), null);
                }
                return;
            }
            if (!(callback instanceof MyMultiExternalProjectRefreshCallback)) {
                ExternalSystemNotificationManager.getInstance(project).clearNotifications(null, NotificationSource.PROJECT_SYNC, externalSystemId);
            }
            final ExternalSystemTaskActivator externalSystemTaskActivator = ExternalProjectsManager.getInstance(project).getTaskActivator();
            if (!isPreviewMode && !externalSystemTaskActivator.runTasks(externalProjectPath, ExternalSystemTaskActivator.Phase.BEFORE_SYNC)) {
                return;
            }
            myTask.execute(indicator, ExternalSystemTaskNotificationListener.EP_NAME.getExtensions());
            if (project.isDisposed())
                return;
            final Throwable error = myTask.getError();
            if (error == null) {
                if (callback != null) {
                    DataNode<ProjectData> externalProject = myTask.getExternalProject();
                    if (externalProject != null && importSpec.shouldCreateDirectoriesForEmptyContentRoots()) {
                        externalProject.putUserData(ContentRootDataService.CREATE_EMPTY_DIRECTORIES, Boolean.TRUE);
                    }
                    callback.onSuccess(externalProject);
                }
                if (!isPreviewMode) {
                    externalSystemTaskActivator.runTasks(externalProjectPath, ExternalSystemTaskActivator.Phase.AFTER_SYNC);
                }
                return;
            }
            if (error instanceof ImportCanceledException) {
                // stop refresh task
                return;
            }
            String message = ExternalSystemApiUtil.buildErrorMessage(error);
            if (StringUtil.isEmpty(message)) {
                message = String.format("Can't resolve %s project at '%s'. Reason: %s", externalSystemId.getReadableName(), externalProjectPath, message);
            }
            if (callback != null) {
                callback.onFailure(message, extractDetails(error));
            }
            ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
            if (manager == null) {
                return;
            }
            AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(project);
            ExternalProjectSettings projectSettings = settings.getLinkedProjectSettings(externalProjectPath);
            if (projectSettings == null || !reportRefreshError) {
                return;
            }
            ExternalSystemNotificationManager.getInstance(project).processExternalProjectRefreshError(error, projectName, externalSystemId);
        }
    };
    final String title;
    switch(progressExecutionMode) {
        case NO_PROGRESS_SYNC:
        case NO_PROGRESS_ASYNC:
            throw new ExternalSystemException("Please, use progress for the project import!");
        case MODAL_SYNC:
            title = ExternalSystemBundle.message("progress.import.text", projectName, externalSystemId.getReadableName());
            new Task.Modal(project, title, true) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    refreshProjectStructureTask.execute(indicator);
                }
            }.queue();
            break;
        case IN_BACKGROUND_ASYNC:
            title = ExternalSystemBundle.message("progress.refresh.text", projectName, externalSystemId.getReadableName());
            new Task.Backgroundable(project, title) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    refreshProjectStructureTask.execute(indicator);
                }
            }.queue();
            break;
        case START_IN_FOREGROUND_ASYNC:
            title = ExternalSystemBundle.message("progress.refresh.text", projectName, externalSystemId.getReadableName());
            new Task.Backgroundable(project, title, true, PerformInBackgroundOption.DEAF) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    refreshProjectStructureTask.execute(indicator);
                }
            }.queue();
    }
}
Also used : ExternalSystemTaskActivator(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator) Task(com.intellij.openapi.progress.Task) ExternalSystemResolveProjectTask(com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask) ExternalSystemProcessingManager(com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager) ImportCanceledException(com.intellij.openapi.externalSystem.service.ImportCanceledException) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemResolveProjectTask(com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ProgressExecutionMode(com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) Project(com.intellij.openapi.project.Project) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) DisposeAwareRunnable(com.intellij.util.DisposeAwareRunnable) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class CustomizeFeaturedPluginsStepPanel method onPluginGroupsLoaded.

private void onPluginGroupsLoaded() {
    List<IdeaPluginDescriptor> pluginsFromRepository = myPluginGroups.getPluginsFromRepository();
    if (pluginsFromRepository.isEmpty()) {
        myInProgressLabel.setText("Cannot get featured plugins description online.");
        return;
    }
    removeAll();
    JPanel gridPanel = new JPanel(new GridLayout(0, 3));
    JBScrollPane scrollPane = CustomizePluginsStepPanel.createScrollPane(gridPanel);
    Map<String, String> config = myPluginGroups.getFeaturedPlugins();
    for (Map.Entry<String, String> entry : config.entrySet()) {
        JPanel groupPanel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = GridBagConstraints.BOTH;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.weightx = 1;
        String title = entry.getKey();
        String s = entry.getValue();
        int i = s.indexOf(':');
        String topic = s.substring(0, i);
        int j = s.indexOf(':', i + 1);
        String description = s.substring(i + 1, j);
        final String pluginId = s.substring(j + 1);
        IdeaPluginDescriptor foundDescriptor = null;
        for (IdeaPluginDescriptor descriptor : pluginsFromRepository) {
            if (descriptor.getPluginId().getIdString().equals(pluginId) && !PluginManagerCore.isBrokenPlugin(descriptor)) {
                foundDescriptor = descriptor;
                break;
            }
        }
        if (foundDescriptor == null)
            continue;
        final IdeaPluginDescriptor descriptor = foundDescriptor;
        final boolean isVIM = PluginGroups.IDEA_VIM_PLUGIN_ID.equals(descriptor.getPluginId().getIdString());
        boolean isCloud = "#Cloud".equals(topic);
        if (isCloud) {
            title = descriptor.getName();
            description = StringUtil.defaultIfEmpty(descriptor.getDescription(), "No description available");
            topic = StringUtil.defaultIfEmpty(descriptor.getCategory(), "Unknown");
        }
        JLabel titleLabel = new JLabel("<html><body><h2 style=\"text-align:left;\">" + title + "</h2></body></html>");
        JLabel topicLabel = new JLabel("<html><body><h4 style=\"text-align:left;color:#808080;font-weight:bold;\">" + topic + "</h4></body></html>");
        JLabel descriptionLabel = createHTMLLabel(description);
        JLabel warningLabel = null;
        if (isVIM || isCloud) {
            if (isCloud) {
                warningLabel = createHTMLLabel("From your JetBrains account");
                warningLabel.setIcon(AllIcons.General.BalloonInformation);
            } else {
                warningLabel = createHTMLLabel("Recommended only if you are<br> familiar with Vim.");
                warningLabel.setIcon(AllIcons.General.BalloonWarning);
            }
            if (!SystemInfo.isWindows)
                UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, warningLabel);
        }
        final CardLayout wrapperLayout = new CardLayout();
        final JPanel buttonWrapper = new JPanel(wrapperLayout);
        final JButton installButton = new JButton(isVIM ? "Install and Enable" : "Install");
        final JProgressBar progressBar = new JProgressBar(0, 100);
        progressBar.setStringPainted(true);
        JPanel progressPanel = new JPanel(new VerticalFlowLayout(true, false));
        progressPanel.add(progressBar);
        final LinkLabel cancelLink = new LinkLabel("Cancel", AllIcons.Actions.Cancel);
        JPanel linkWrapper = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
        linkWrapper.add(cancelLink);
        progressPanel.add(linkWrapper);
        final JPanel buttonPanel = new JPanel(new VerticalFlowLayout(0, 0));
        buttonPanel.add(installButton);
        buttonWrapper.add(buttonPanel, "button");
        buttonWrapper.add(progressPanel, "progress");
        wrapperLayout.show(buttonWrapper, "button");
        final ProgressIndicatorEx indicator = new AbstractProgressIndicatorExBase(true) {

            @Override
            public void start() {
                myCanceled.set(false);
                super.start();
                SwingUtilities.invokeLater(() -> wrapperLayout.show(buttonWrapper, "progress"));
            }

            @Override
            public void processFinish() {
                super.processFinish();
                SwingUtilities.invokeLater(() -> {
                    wrapperLayout.show(buttonWrapper, "button");
                    installButton.setEnabled(false);
                    installButton.setText("Installed");
                });
            }

            @Override
            public void setFraction(final double fraction) {
                super.setFraction(fraction);
                SwingUtilities.invokeLater(() -> {
                    int value = (int) (100 * fraction + .5);
                    progressBar.setValue(value);
                    progressBar.setString(value + "%");
                });
            }

            @Override
            public void cancel() {
                stop();
                myCanceled.set(true);
                super.cancel();
                SwingUtilities.invokeLater(() -> {
                    wrapperLayout.show(buttonWrapper, "button");
                    progressBar.setValue(0);
                    progressBar.setString("0%");
                });
            }
        };
        installButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                wrapperLayout.show(buttonWrapper, "progress");
                ourService.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            indicator.start();
                            IdeInitialConfigButtonUsages.addDownloadedPlugin(descriptor.getPluginId().getIdString());
                            PluginDownloader downloader = PluginDownloader.createDownloader(descriptor);
                            downloader.prepareToInstall(indicator);
                            downloader.install();
                            indicator.processFinish();
                        } catch (Exception ignored) {
                            if (!myCanceled.get()) {
                                onFail();
                            }
                        }
                    }

                    void onFail() {
                        //noinspection SSBasedInspection
                        SwingUtilities.invokeLater(() -> {
                            indicator.stop();
                            wrapperLayout.show(buttonWrapper, "progress");
                            progressBar.setString("Cannot download plugin");
                        });
                    }
                });
            }
        });
        cancelLink.setListener(new LinkListener() {

            @Override
            public void linkSelected(LinkLabel aSource, Object aLinkData) {
                indicator.cancel();
            }
        }, null);
        gbc.insets.left = installButton.getInsets().left / 2;
        gbc.insets.right = installButton.getInsets().right / 2;
        gbc.insets.bottom = -5;
        groupPanel.add(titleLabel, gbc);
        gbc.insets.bottom = SMALL_GAP;
        groupPanel.add(topicLabel, gbc);
        groupPanel.add(descriptionLabel, gbc);
        gbc.weighty = 1;
        groupPanel.add(Box.createVerticalGlue(), gbc);
        gbc.weighty = 0;
        if (warningLabel != null) {
            Insets insetsBefore = gbc.insets;
            gbc.insets = new Insets(0, -10, SMALL_GAP, -10);
            gbc.insets.left += insetsBefore.left;
            gbc.insets.right += insetsBefore.right;
            JPanel warningPanel = new JPanel(new BorderLayout());
            warningPanel.setBorder(new EmptyBorder(5, 10, 5, 10));
            warningPanel.add(warningLabel);
            groupPanel.add(warningPanel, gbc);
            gbc.insets = insetsBefore;
        }
        gbc.insets.bottom = gbc.insets.left = gbc.insets.right = 0;
        groupPanel.add(buttonWrapper, gbc);
        gridPanel.add(groupPanel);
    }
    while (gridPanel.getComponentCount() < 4) {
        gridPanel.add(Box.createVerticalBox());
    }
    int cursor = 0;
    Component[] components = gridPanel.getComponents();
    int rowCount = components.length / COLS;
    for (Component component : components) {
        ((JComponent) component).setBorder(new CompoundBorder(new CustomLineBorder(ColorUtil.withAlpha(JBColor.foreground(), .2), 0, 0, cursor / 3 < rowCount && (!(component instanceof Box)) ? 1 : 0, cursor % COLS != COLS - 1 && (!(component instanceof Box)) ? 1 : 0) {

            @Override
            protected Color getColor() {
                return ColorUtil.withAlpha(JBColor.foreground(), .2);
            }
        }, BorderFactory.createEmptyBorder(0, SMALL_GAP, 0, SMALL_GAP)));
        cursor++;
    }
    add(scrollPane);
    revalidate();
    repaint();
}
Also used : VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) ActionEvent(java.awt.event.ActionEvent) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginDownloader(com.intellij.openapi.updateSettings.impl.PluginDownloader) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) LinkListener(com.intellij.ui.components.labels.LinkListener) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) ActionListener(java.awt.event.ActionListener) LinkLabel(com.intellij.ui.components.labels.LinkLabel) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) Map(java.util.Map) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 9 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class InfoAndProgressPanel method removeFromMaps.

private ProgressIndicatorEx removeFromMaps(@NotNull InlineProgressIndicator progress) {
    final ProgressIndicatorEx original = myInline2Original.get(progress);
    myInline2Original.remove(progress);
    synchronized (myDirtyIndicators) {
        myDirtyIndicators.remove(progress);
    }
    myOriginal2Inlines.remove(original, progress);
    if (myOriginal2Inlines.get(original) == null) {
        final int originalIndex = myOriginals.indexOf(original);
        myOriginals.remove(originalIndex);
        myInfos.remove(originalIndex);
    }
    return original;
}
Also used : ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 10 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class DumbServiceImpl method pollTaskQueue.

@Nullable
private Pair<DumbModeTask, ProgressIndicatorEx> pollTaskQueue() {
    while (true) {
        if (myUpdatesQueue.isEmpty()) {
            queueUpdateFinished();
            return null;
        }
        DumbModeTask queuedTask = myUpdatesQueue.pullFirst();
        myQueuedEquivalences.remove(queuedTask.getEquivalenceObject());
        ProgressIndicatorEx indicator = myProgresses.get(queuedTask);
        if (indicator.isCanceled()) {
            Disposer.dispose(queuedTask);
            continue;
        }
        return Pair.create(queuedTask, indicator);
    }
}
Also used : ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProgressIndicatorEx (com.intellij.openapi.wm.ex.ProgressIndicatorEx)10 AbstractProgressIndicatorExBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 NotNull (org.jetbrains.annotations.NotNull)2 CodeSmellInfo (com.intellij.codeInsight.CodeSmellInfo)1 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 DelegatingProgressIndicator (com.intellij.ide.util.DelegatingProgressIndicator)1 Document (com.intellij.openapi.editor.Document)1 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)1 ImportCanceledException (com.intellij.openapi.externalSystem.service.ImportCanceledException)1 ProgressExecutionMode (com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode)1 ExternalSystemProcessingManager (com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager)1 ExternalSystemResolveProjectTask (com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask)1 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)1 ExternalSystemTaskActivator (com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator)1 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)1 Task (com.intellij.openapi.progress.Task)1 ProgressIndicatorBase (com.intellij.openapi.progress.util.ProgressIndicatorBase)1