Search in sources :

Example 31 with HyperlinkEvent

use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.

the class GitBranchUiHandlerImpl method showUnmergedFilesNotification.

@Override
public void showUnmergedFilesNotification(@NotNull final String operationName, @NotNull final Collection<GitRepository> repositories) {
    String title = unmergedFilesErrorTitle(operationName);
    String description = unmergedFilesErrorNotificationDescription(operationName);
    VcsNotifier.getInstance(myProject).notifyError(title, description, new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getDescription().equals("resolve")) {
                GitConflictResolver.Params params = new GitConflictResolver.Params().setMergeDescription(String.format("The following files have unresolved conflicts. You need to resolve them before %s.", operationName)).setErrorNotificationTitle("Unresolved files remain.");
                new GitConflictResolver(myProject, myGit, GitUtil.getRootsFromRepositories(repositories), params).merge();
            }
        }
    });
}
Also used : GitConflictResolver(git4idea.merge.GitConflictResolver) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 32 with HyperlinkEvent

use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.

the class GitUntrackedFilesHelper method notifyUntrackedFilesOverwrittenBy.

/**
   * Displays notification about {@code untracked files would be overwritten by checkout} error.
   * Clicking on the link in the notification opens a simple dialog with the list of these files.
   * @param root
   * @param relativePaths
   * @param operation   the name of the Git operation that caused the error: {@code rebase, merge, checkout}.
   * @param description the content of the notification or null if the default content is to be used.
   */
public static void notifyUntrackedFilesOverwrittenBy(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull Collection<String> relativePaths, @NotNull final String operation, @Nullable String description) {
    final String notificationTitle = StringUtil.capitalize(operation) + " failed";
    final String notificationDesc = description == null ? createUntrackedFilesOverwrittenDescription(operation, true) : description;
    final Collection<String> absolutePaths = GitUtil.toAbsolute(root, relativePaths);
    final List<VirtualFile> untrackedFiles = ContainerUtil.mapNotNull(absolutePaths, new Function<String, VirtualFile>() {

        @Override
        public VirtualFile fun(String absolutePath) {
            return GitUtil.findRefreshFileOrLog(absolutePath);
        }
    });
    VcsNotifier.getInstance(project).notifyError(notificationTitle, notificationDesc, new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                final String dialogDesc = createUntrackedFilesOverwrittenDescription(operation, false);
                String title = "Untracked Files Preventing " + StringUtil.capitalize(operation);
                if (untrackedFiles.isEmpty()) {
                    GitUtil.showPathsInDialog(project, absolutePaths, title, dialogDesc);
                } else {
                    DialogWrapper dialog;
                    dialog = new UntrackedFilesDialog(project, untrackedFiles, dialogDesc);
                    dialog.setTitle(title);
                    dialog.show();
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Notification(com.intellij.notification.Notification) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) NotificationListener(com.intellij.notification.NotificationListener)

Example 33 with HyperlinkEvent

use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.

the class ImportMavenRepositoriesTask method performTask.

private void performTask() {
    if (myProject.isDisposed())
        return;
    if (ApplicationManager.getApplication().isUnitTestMode())
        return;
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final List<PsiFile> psiFileList = ContainerUtil.newArrayList();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    for (Module module : moduleManager.getModules()) {
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
            continue;
        final String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
        if (modulePath == null)
            continue;
        String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
        if (StringUtil.isEmpty(buildScript))
            continue;
        VirtualFile virtualFile = localFileSystem.refreshAndFindFileByPath(buildScript);
        if (virtualFile == null)
            continue;
        final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
        if (psiFile == null)
            continue;
        psiFileList.add(psiFile);
    }
    final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
    final Set<MavenRemoteRepository> mavenRemoteRepositories = new ReadAction<Set<MavenRemoteRepository>>() {

        @Override
        protected void run(@NotNull Result<Set<MavenRemoteRepository>> result) throws Throwable {
            Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
            for (PsiFile psiFile : psiFiles) {
                List<GrClosableBlock> repositoriesBlocks = ContainerUtil.newArrayList();
                repositoriesBlocks.addAll(findClosableBlocks(psiFile, "repositories"));
                for (GrClosableBlock closableBlock : findClosableBlocks(psiFile, "buildscript", "subprojects", "allprojects", "project", "configure")) {
                    repositoriesBlocks.addAll(findClosableBlocks(closableBlock, "repositories"));
                }
                for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
                    myRemoteRepositories.addAll(findMavenRemoteRepositories(repositoriesBlock));
                }
            }
            result.setResult(myRemoteRepositories);
        }
    }.execute().getResultObject();
    if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty())
        return;
    // register imported maven repository URLs but do not force to download the index
    // the index can be downloaded and/or updated later using Maven Configuration UI (Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Repositories)
    MavenRepositoriesHolder.getInstance(myProject).update(mavenRemoteRepositories);
    MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(indexes -> {
        if (myProject.isDisposed())
            return;
        final List<String> repositoriesWithEmptyIndex = ContainerUtil.mapNotNull(indexes, index -> index.getUpdateTimestamp() == -1 && MavenRepositoriesHolder.getInstance(myProject).contains(index.getRepositoryPathOrUrl()) ? index.getRepositoryPathOrUrl() : null);
        if (!repositoriesWithEmptyIndex.isEmpty()) {
            final NotificationData notificationData = new NotificationData(GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.title"), "\n<br>" + GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.text", StringUtil.join(repositoriesWithEmptyIndex, "<br>")), NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
            notificationData.setBalloonNotification(true);
            notificationData.setBalloonGroup(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP);
            notificationData.setListener("#open", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenRepositoriesConfigurable.class);
                }
            });
            notificationData.setListener("#disable", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    final int result = Messages.showYesNoDialog(myProject, "Notification will be disabled for all projects.\n\n" + "Settings | Appearance & Behavior | Notifications | " + UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP + "\ncan be used to configure the notification.", "Unindexed Maven Repositories Gradle Detection", "Disable Notification", CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
                    if (result == Messages.YES) {
                        NotificationsConfigurationImpl.getInstanceImpl().changeSettings(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP, NotificationDisplayType.NONE, false, false);
                        notification.hideBalloon();
                    }
                }
            });
            ExternalSystemNotificationManager.getInstance(myProject).showNotification(GradleConstants.SYSTEM_ID, notificationData);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) ModuleManager(com.intellij.openapi.module.ModuleManager) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) Result(com.intellij.openapi.application.Result) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ReadAction(com.intellij.openapi.application.ReadAction) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenRepositoriesConfigurable(org.jetbrains.idea.maven.indices.MavenRepositoriesConfigurable) Module(com.intellij.openapi.module.Module) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) NotificationListener(com.intellij.notification.NotificationListener)

Example 34 with HyperlinkEvent

use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.

the class ConfigurationErrorEvent method process.

@Override
public void process(@NotNull final TestEventXmlView xml) throws TestEventXmlView.XmlParserException {
    final String errorTitle = xml.getEventTitle();
    final String configurationErrorMsg = xml.getEventMessage();
    final boolean openSettings = xml.isEventOpenSettings();
    final Project project = getProject();
    assert project != null;
    final String message = openSettings ? String.format("<br>\n%s<br><br>\n\n<a href=\"Gradle settings\">Open gradle settings</a>", configurationErrorMsg) : String.format("<br>\n%s", configurationErrorMsg);
    GradleNotification.getInstance(project).showBalloon(errorTitle, message, NotificationType.WARNING, new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            notification.expire();
            if ("Gradle settings".equals(event.getDescription())) {
                ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(GradleConstants.SYSTEM_ID);
                assert manager instanceof GradleManager;
                GradleManager gradleManager = (GradleManager) manager;
                Configurable configurable = gradleManager.getConfigurable(project);
                ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
            } else {
                BrowserUtil.browse(event.getDescription());
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ExternalSystemManager(com.intellij.openapi.externalSystem.ExternalSystemManager) GradleManager(org.jetbrains.plugins.gradle.GradleManager) Configurable(com.intellij.openapi.options.Configurable) GradleNotification(org.jetbrains.plugins.gradle.service.project.GradleNotification) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 35 with HyperlinkEvent

use of javax.swing.event.HyperlinkEvent in project ChatGameFontificator by GlitchCog.

the class ControlWindow method constructAboutPopup.

/**
     * Construct the popup dialog containing the About message
     */
private void constructAboutPopup() {
    aboutPane = new JEditorPane("text/html", ABOUT_CONTENTS);
    aboutPane.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (EventType.ACTIVATED.equals(e.getEventType())) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(URI.create("https://" + e.getDescription()));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    });
    aboutPane.setEditable(false);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) JEditorPane(javax.swing.JEditorPane) IOException(java.io.IOException)

Aggregations

HyperlinkEvent (javax.swing.event.HyperlinkEvent)90 NotNull (org.jetbrains.annotations.NotNull)36 Notification (com.intellij.notification.Notification)33 NotificationListener (com.intellij.notification.NotificationListener)31 HyperlinkListener (javax.swing.event.HyperlinkListener)30 Project (com.intellij.openapi.project.Project)14 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)14 File (java.io.File)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)9 IOException (java.io.IOException)7 URL (java.net.URL)5 AnAction (com.intellij.openapi.actionSystem.AnAction)4 DataContext (com.intellij.openapi.actionSystem.DataContext)4 IdeFrame (com.intellij.openapi.wm.IdeFrame)3 MultiMap (com.intellij.util.containers.MultiMap)3 NonNls (org.jetbrains.annotations.NonNls)3 Nullable (org.jetbrains.annotations.Nullable)3 UISettings (com.intellij.ide.ui.UISettings)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2