Search in sources :

Example 1 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class ShowJavadoc method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    final DocumentationComponent component = new DocumentationComponent(documentationManager);
    final Property property = myTable.getSelectionProperty();
    if (property == null) {
        return;
    }
    PsiElement javadocElement = property.getJavadocElement();
    ActionCallback callback;
    if (javadocElement == null) {
        callback = new ActionCallback();
        component.setText(property.getJavadocText(), null, true);
    } else {
        callback = documentationManager.queueFetchDocInfo(javadocElement, component);
    }
    callback.doWhenProcessed(() -> {
        JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component).setProject(project).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(DesignerBundle.message("designer.properties.javadoc.title", property.getName())).setCancelCallback(() -> {
            Disposer.dispose(component);
            return Boolean.TRUE;
        }).createPopup();
        component.setHint(hint);
        Disposer.register(hint, component);
        hint.show(new RelativePoint(myTable.getParent(), new Point(0, 0)));
    });
    if (javadocElement == null) {
        callback.setDone();
    }
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) ActionCallback(com.intellij.openapi.util.ActionCallback) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Property(com.intellij.designer.model.Property) PsiElement(com.intellij.psi.PsiElement)

Example 2 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class EduStepicUpdater method updateCourseList.

private static ActionCallback updateCourseList() {
    ActionCallback callback = new ActionCallback();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final List<CourseInfo> courses = EduStepicConnector.getCourses(null);
        final List<CourseInfo> cachedCourses = StudyProjectGenerator.getCoursesFromCache();
        StudyProjectGenerator.flushCache(courses);
        StepicUpdateSettings.getInstance().setLastTimeChecked(System.currentTimeMillis());
        courses.removeAll(cachedCourses);
        if (!courses.isEmpty() && !cachedCourses.isEmpty()) {
            final String message;
            final String title;
            if (courses.size() == 1) {
                message = courses.get(0).getName();
                title = "New course available";
            } else {
                title = "New courses available";
                message = StringUtil.join(courses, CourseInfo::getName, ", ");
            }
            final Notification notification = new Notification("New.course", title, message, NotificationType.INFORMATION);
            notification.notify(null);
        }
    });
    return callback;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) Notification(com.intellij.notification.Notification)

Example 3 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class MavenAttachSourcesProvider method getActions.

@Override
@NotNull
public Collection<AttachSourcesAction> getActions(final List<LibraryOrderEntry> orderEntries, final PsiFile psiFile) {
    Collection<MavenProject> projects = getMavenProjects(psiFile);
    if (projects.isEmpty())
        return Collections.emptyList();
    if (findArtifacts(projects, orderEntries).isEmpty())
        return Collections.emptyList();
    return Collections.singleton(new AttachSourcesAction() {

        @Override
        public String getName() {
            return ProjectBundle.message("maven.action.download.sources");
        }

        @Override
        public String getBusyText() {
            return ProjectBundle.message("maven.action.download.sources.busy.text");
        }

        @Override
        public ActionCallback perform(List<LibraryOrderEntry> orderEntries) {
            // may have been changed by this time...
            Collection<MavenProject> mavenProjects = getMavenProjects(psiFile);
            if (mavenProjects.isEmpty()) {
                return ActionCallback.REJECTED;
            }
            MavenProjectsManager manager = MavenProjectsManager.getInstance(psiFile.getProject());
            Collection<MavenArtifact> artifacts = findArtifacts(mavenProjects, orderEntries);
            if (artifacts.isEmpty())
                return ActionCallback.REJECTED;
            final AsyncResult<MavenArtifactDownloader.DownloadResult> result = new AsyncResult<>();
            manager.scheduleArtifactsDownloading(mavenProjects, artifacts, true, false, result);
            final ActionCallback resultWrapper = new ActionCallback();
            result.doWhenDone(new Consumer<MavenArtifactDownloader.DownloadResult>() {

                @Override
                public void consume(MavenArtifactDownloader.DownloadResult downloadResult) {
                    if (!downloadResult.unresolvedSources.isEmpty()) {
                        final StringBuilder message = new StringBuilder();
                        message.append("<html>Sources not found for:");
                        int count = 0;
                        for (MavenId each : downloadResult.unresolvedSources) {
                            if (count++ > 5) {
                                message.append("<br>and more...");
                                break;
                            }
                            message.append("<br>").append(each.getDisplayString());
                        }
                        message.append("</html>");
                        Notifications.Bus.notify(new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Cannot download sources", message.toString(), NotificationType.WARNING), psiFile.getProject());
                    }
                    if (downloadResult.resolvedSources.isEmpty()) {
                        resultWrapper.setRejected();
                    } else {
                        resultWrapper.setDone();
                    }
                }
            });
            return resultWrapper;
        }
    });
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) ActionCallback(com.intellij.openapi.util.ActionCallback) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Notification(com.intellij.notification.Notification) MavenArtifactDownloader(org.jetbrains.idea.maven.project.MavenArtifactDownloader) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Consumer(com.intellij.util.Consumer) Collection(java.util.Collection) AsyncResult(com.intellij.openapi.util.AsyncResult) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class UpdaterTreeState method processHangByParent.

private ActionCallback processHangByParent(Object each) {
    ActionCallback result = new ActionCallback();
    processNextHang(each, result);
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 5 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class JumpToColorsAndFontsAction method openSettingsAndSelectKey.

private static boolean openSettingsAndSelectKey(@NotNull Project project, @NotNull ColorSettingsPage page, @NotNull AttributesDescriptor descriptor) {
    SettingsDialog dialog = (SettingsDialog) ShowSettingsUtilImpl.getDialog(project, ShowSettingsUtilImpl.getConfigurableGroups(project, true), null);
    Settings settings = Settings.KEY.getData(dialog);
    ColorAndFontOptions configurable0 = settings == null ? null : settings.find(ColorAndFontOptions.class);
    SearchableConfigurable configurable = configurable0 == null ? null : configurable0.findSubConfigurable(page.getDisplayName());
    if (configurable == null)
        return false;
    Runnable runnable = configurable.enableSearch(descriptor.getDisplayName());
    ActionCallback callback = settings.select(configurable);
    if (runnable != null)
        callback.doWhenDone(runnable);
    dialog.show();
    return true;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) SettingsDialog(com.intellij.openapi.options.newEditor.SettingsDialog) Settings(com.intellij.openapi.options.ex.Settings)

Aggregations

ActionCallback (com.intellij.openapi.util.ActionCallback)70 NotNull (org.jetbrains.annotations.NotNull)16 IOException (java.io.IOException)5 Notification (com.intellij.notification.Notification)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrayList (java.util.ArrayList)4 ProjectView (com.intellij.ide.projectView.ProjectView)3 Configurable (com.intellij.openapi.options.Configurable)3 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)3 AsyncResult (com.intellij.openapi.util.AsyncResult)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 DocumentInfo (com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 Project (com.intellij.openapi.project.Project)2 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)2 MasterDetailsComponent (com.intellij.openapi.ui.MasterDetailsComponent)2 NamedConfigurable (com.intellij.openapi.ui.NamedConfigurable)2 TypingTarget (com.intellij.openapi.ui.TypingTarget)2 FocusCommand (com.intellij.openapi.wm.FocusCommand)2