Search in sources :

Example 6 with HyperlinkListener

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

the class ContentRootPanel method createFolderComponent.

private <P extends JpsElement> JComponent createFolderComponent(final ContentFolder folder, Color foreground, ModuleSourceRootEditHandler<P> editor) {
    final VirtualFile folderFile = folder.getFile();
    final VirtualFile contentEntryFile = getContentEntry().getFile();
    final String properties = folder instanceof SourceFolder ? StringUtil.notNullize(editor.getPropertiesString((P) ((SourceFolder) folder).getJpsElement().getProperties())) : "";
    if (folderFile != null && contentEntryFile != null) {
        String path = folderFile.equals(contentEntryFile) ? "." : VfsUtilCore.getRelativePath(folderFile, contentEntryFile, File.separatorChar);
        HoverHyperlinkLabel hyperlinkLabel = new HoverHyperlinkLabel(path + properties, foreground);
        hyperlinkLabel.setMinimumSize(new Dimension(0, 0));
        hyperlinkLabel.addHyperlinkListener(new HyperlinkListener() {

            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                myCallback.navigateFolder(getContentEntry(), folder);
            }
        });
        registerTextComponent(hyperlinkLabel, foreground);
        return new UnderlinedPathLabel(hyperlinkLabel);
    } else {
        String path = toRelativeDisplayPath(folder.getUrl(), getContentEntry().getUrl());
        final JLabel pathLabel = new JLabel(path + properties);
        pathLabel.setOpaque(false);
        pathLabel.setForeground(JBColor.RED);
        return new UnderlinedPathLabel(pathLabel);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) HoverHyperlinkLabel(com.intellij.ui.HoverHyperlinkLabel) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 7 with HyperlinkListener

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

the class ExecutionUtil method handleExecutionError.

public static void handleExecutionError(@NotNull final Project project, @NotNull final String toolWindowId, @NotNull String taskName, @NotNull ExecutionException e) {
    if (e instanceof RunCanceledByUserException) {
        return;
    }
    LOG.debug(e);
    String description = e.getMessage();
    if (StringUtil.isEmptyOrSpaces(description)) {
        LOG.warn("Execution error without description", e);
        description = "Unknown error";
    }
    HyperlinkListener listener = null;
    if ((description.contains("87") || description.contains("111") || description.contains("206")) && e instanceof ProcessNotCreatedException && !PropertiesComponent.getInstance(project).isTrueValue("dynamic.classpath")) {
        final String commandLineString = ((ProcessNotCreatedException) e).getCommandLine().getCommandLineString();
        if (commandLineString.length() > 1024 * 32) {
            description = "Command line is too long. In order to reduce its length classpath file can be used.<br>" + "Would you like to enable classpath file mode for all run configurations of your project?<br>" + "<a href=\"\">Enable</a>";
            listener = new HyperlinkListener() {

                @Override
                public void hyperlinkUpdate(HyperlinkEvent event) {
                    PropertiesComponent.getInstance(project).setValue("dynamic.classpath", "true");
                }
            };
        }
    }
    final String title = ExecutionBundle.message("error.running.configuration.message", taskName);
    final String fullMessage = title + ":<br>" + description;
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        LOG.error(fullMessage, e);
    }
    if (listener == null) {
        listener = ExceptionUtil.findCause(e, HyperlinkListener.class);
    }
    final HyperlinkListener finalListener = listener;
    final String finalDescription = description;
    UIUtil.invokeLaterIfNeeded(() -> {
        if (project.isDisposed()) {
            return;
        }
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        if (toolWindowManager.canShowNotification(toolWindowId)) {
            //noinspection SSBasedInspection
            toolWindowManager.notifyByBalloon(toolWindowId, MessageType.ERROR, fullMessage, null, finalListener);
        } else {
            Messages.showErrorDialog(project, UIUtil.toHtml(fullMessage), "");
        }
        NotificationListener notificationListener = finalListener == null ? null : (notification, event) -> {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                finalListener.hyperlinkUpdate(event);
            }
        };
        ourNotificationGroup.createNotification(title, finalDescription, NotificationType.ERROR, notificationListener).notify(project);
    });
}
Also used : ProcessNotCreatedException(com.intellij.execution.process.ProcessNotCreatedException) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) NotificationListener(com.intellij.notification.NotificationListener)

Example 8 with HyperlinkListener

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

the class LongLineInspection method createOptionsPanel.

@Nullable
@Override
public JComponent createOptionsPanel() {
    final HyperlinkLabel codeStyleHyperlink = new HyperlinkLabel("Edit Code Style settings");
    codeStyleHyperlink.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {

                @Override
                public void consume(DataContext context) {
                    if (context != null) {
                        final Settings settings = Settings.KEY.getData(context);
                        if (settings != null) {
                            settings.select(settings.find(CodeStyleSchemesConfigurable.class));
                        } else {
                            ShowSettingsUtil.getInstance().showSettingsDialog(CommonDataKeys.PROJECT.getData(context), CodeStyleSchemesConfigurable.class);
                        }
                    }
                }
            });
        }
    });
    final JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(codeStyleHyperlink, BorderLayout.NORTH);
    return panel;
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) CodeStyleSchemesConfigurable(com.intellij.application.options.CodeStyleSchemesConfigurable) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Consumer(com.intellij.util.Consumer) HyperlinkListener(javax.swing.event.HyperlinkListener) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) Settings(com.intellij.openapi.options.ex.Settings) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with HyperlinkListener

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

the class HyperlinkLabel method setHyperlinkTarget.

public void setHyperlinkTarget(@Nullable final String url) {
    if (myHyperlinkListener != null) {
        removeHyperlinkListener(myHyperlinkListener);
    }
    if (url != null) {
        myHyperlinkListener = new HyperlinkListener() {

            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                BrowserUtil.browse(url);
            }
        };
        addHyperlinkListener(myHyperlinkListener);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 10 with HyperlinkListener

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

the class DiffUtil method showSuccessPopup.

public static void showSuccessPopup(@NotNull String message, @NotNull RelativePoint point, @NotNull Disposable disposable, @Nullable Runnable hyperlinkHandler) {
    HyperlinkListener listener = null;
    if (hyperlinkHandler != null) {
        listener = new HyperlinkAdapter() {

            @Override
            protected void hyperlinkActivated(HyperlinkEvent e) {
                hyperlinkHandler.run();
            }
        };
    }
    Color bgColor = MessageType.INFO.getPopupBackground();
    Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, null, bgColor, listener).setAnimationCycle(200).createBalloon();
    balloon.show(point, Balloon.Position.below);
    Disposer.register(disposable, balloon);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) Balloon(com.intellij.openapi.ui.popup.Balloon)

Aggregations

HyperlinkListener (javax.swing.event.HyperlinkListener)33 HyperlinkEvent (javax.swing.event.HyperlinkEvent)31 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)6 Project (com.intellij.openapi.project.Project)5 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)4 File (java.io.File)4 IOException (java.io.IOException)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Ref (com.intellij.openapi.util.Ref)3 Logger (com.intellij.openapi.diagnostic.Logger)2 MessageType (com.intellij.openapi.ui.MessageType)2 Balloon (com.intellij.openapi.ui.popup.Balloon)2 Computable (com.intellij.openapi.util.Computable)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 IdeFrame (com.intellij.openapi.wm.IdeFrame)2 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)2 JBScrollPane (com.intellij.ui.components.JBScrollPane)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2