Search in sources :

Example 11 with HyperlinkEvent

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

the class FrameworkDetectionManager method doRunDetection.

private void doRunDetection() {
    Set<Integer> detectorsToProcess;
    synchronized (myLock) {
        detectorsToProcess = new HashSet<>(myDetectorsToProcess);
        detectorsToProcess.addAll(myDetectorsToProcess);
        myDetectorsToProcess.clear();
    }
    if (detectorsToProcess.isEmpty())
        return;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Starting framework detectors: " + detectorsToProcess);
    }
    final FileBasedIndex index = FileBasedIndex.getInstance();
    List<DetectedFrameworkDescription> newDescriptions = new ArrayList<>();
    List<DetectedFrameworkDescription> oldDescriptions = new ArrayList<>();
    final DetectionExcludesConfiguration excludesConfiguration = DetectionExcludesConfiguration.getInstance(myProject);
    for (Integer id : detectorsToProcess) {
        final List<? extends DetectedFrameworkDescription> frameworks = runDetector(id, index, excludesConfiguration, true);
        oldDescriptions.addAll(frameworks);
        final Collection<? extends DetectedFrameworkDescription> updated = myDetectedFrameworksData.updateFrameworksList(id, frameworks);
        newDescriptions.addAll(updated);
        oldDescriptions.removeAll(updated);
        if (LOG.isDebugEnabled()) {
            LOG.debug(frameworks.size() + " frameworks detected, " + updated.size() + " changed");
        }
    }
    Set<String> frameworkNames = new HashSet<>();
    for (final DetectedFrameworkDescription description : FrameworkDetectionUtil.removeDisabled(newDescriptions, oldDescriptions)) {
        frameworkNames.add(description.getDetector().getFrameworkType().getPresentableName());
    }
    if (!frameworkNames.isEmpty()) {
        String names = StringUtil.join(frameworkNames, ", ");
        final String text = ProjectBundle.message("framework.detected.info.text", names, frameworkNames.size());
        FRAMEWORK_DETECTION_NOTIFICATION.createNotification("Frameworks detected", text, NotificationType.INFORMATION, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    showSetupFrameworksDialog(notification);
                }
            }
        }).notify(myProject);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) DetectedFrameworkDescription(com.intellij.framework.detection.DetectedFrameworkDescription) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) DetectionExcludesConfiguration(com.intellij.framework.detection.DetectionExcludesConfiguration) NotificationListener(com.intellij.notification.NotificationListener)

Example 12 with HyperlinkEvent

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

the class ExtractCodeStyleAction method reportResult.

public void reportResult(final ValuesExtractionResult forSelection, final Project project, final CodeStyleSettings cloneSettings, final PsiFile file, final Map<Value, Object> backup) {
    final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("Formatting Options were extracted<br/><a href=\"apply\">Apply</a> <a href=\"details\">Details...</a>", MessageType.INFO, new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                boolean apply = "apply".equals(e.getDescription());
                ExtractedSettingsDialog myDialog = null;
                if (!apply) {
                    final List<Value> values = forSelection.getValues();
                    final LanguageCodeStyleSettingsProvider[] providers = Extensions.getExtensions(LanguageCodeStyleSettingsProvider.EP_NAME);
                    Language language = file.getLanguage();
                    CodeStyleSettingsNameProvider nameProvider = new CodeStyleSettingsNameProvider();
                    for (final LanguageCodeStyleSettingsProvider provider : providers) {
                        Language target = provider.getLanguage();
                        if (target.equals(language)) {
                            //this is our language
                            nameProvider.addSettings(provider);
                            myDialog = new ExtractedSettingsDialog(project, nameProvider, values);
                            apply = myDialog.showAndGet();
                            break;
                        }
                    }
                }
                if (apply && myDialog != null) {
                    //create new settings named after the file
                    final ExtractedSettingsDialog finalMyDialog = myDialog;
                    forSelection.applyConditioned(value -> finalMyDialog.valueIsSelectedInTree(value), backup);
                    CodeStyleScheme derivedScheme = CodeStyleSchemes.getInstance().createNewScheme("Derived from " + file.getName(), null);
                    derivedScheme.getCodeStyleSettings().copyFrom(cloneSettings);
                    CodeStyleSchemes.getInstance().addScheme(derivedScheme);
                    CodeStyleSchemesImpl.getSchemeManager().setCurrent(derivedScheme);
                    CodeStyleSettingsManager.getInstance(project).PREFERRED_PROJECT_CODE_STYLE = derivedScheme.getName();
                }
            }
        }
    }).setDisposable(ApplicationManager.getApplication()).setShowCallout(false).setFadeoutTime(0).setShowCallout(false).setAnimationCycle(0).setHideOnClickOutside(false).setHideOnKeyOutside(false).setCloseButtonEnabled(true).setHideOnLinkClick(true).createBalloon();
    ApplicationManager.getApplication().invokeLater(() -> {
        Window window = WindowManager.getInstance().getFrame(project);
        if (window == null) {
            window = JOptionPane.getRootFrame();
        }
        if (window instanceof IdeFrame) {
            BalloonLayout layout = ((IdeFrame) window).getBalloonLayout();
            if (layout != null) {
                layout.add(balloon);
            }
        }
    });
}
Also used : Language(com.intellij.lang.Language) IdeFrame(com.intellij.openapi.wm.IdeFrame) MessageType(com.intellij.openapi.ui.MessageType) HyperlinkEvent(javax.swing.event.HyperlinkEvent) com.intellij.psi.codeStyle(com.intellij.psi.codeStyle) VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeStyleDeriveProcessor(com.intellij.psi.codeStyle.extractor.processor.CodeStyleDeriveProcessor) LangCodeStyleExtractor(com.intellij.psi.codeStyle.extractor.differ.LangCodeStyleExtractor) Value(com.intellij.psi.codeStyle.extractor.values.Value) PsiManager(com.intellij.psi.PsiManager) Balloon(com.intellij.openapi.ui.popup.Balloon) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Task(com.intellij.openapi.progress.Task) BalloonLayout(com.intellij.ui.BalloonLayout) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) DumbAware(com.intellij.openapi.project.DumbAware) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) ExtractedSettingsDialog(com.intellij.psi.codeStyle.extractor.ui.ExtractedSettingsDialog) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) HyperlinkListener(javax.swing.event.HyperlinkListener) WindowManager(com.intellij.openapi.wm.WindowManager) Editor(com.intellij.openapi.editor.Editor) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) GenProcessor(com.intellij.psi.codeStyle.extractor.processor.GenProcessor) CodeStyleSchemesImpl(com.intellij.psi.impl.source.codeStyle.CodeStyleSchemesImpl) LanguageFormatting(com.intellij.lang.LanguageFormatting) ApplicationManager(com.intellij.openapi.application.ApplicationManager) CodeStyleSettingsNameProvider(com.intellij.psi.codeStyle.extractor.ui.CodeStyleSettingsNameProvider) ValuesExtractionResult(com.intellij.psi.codeStyle.extractor.values.ValuesExtractionResult) NotNull(org.jetbrains.annotations.NotNull) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ExtractedSettingsDialog(com.intellij.psi.codeStyle.extractor.ui.ExtractedSettingsDialog) Balloon(com.intellij.openapi.ui.popup.Balloon) CodeStyleSettingsNameProvider(com.intellij.psi.codeStyle.extractor.ui.CodeStyleSettingsNameProvider) IdeFrame(com.intellij.openapi.wm.IdeFrame) BalloonLayout(com.intellij.ui.BalloonLayout) Language(com.intellij.lang.Language) HyperlinkListener(javax.swing.event.HyperlinkListener) List(java.util.List)

Example 13 with HyperlinkEvent

use of javax.swing.event.HyperlinkEvent 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 14 with HyperlinkEvent

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

the class ChangeListStorageImpl method notifyUser.

public static void notifyUser(String message) {
    final String logFile = PathManager.getLogPath();
    /*String createIssuePart = "<br>" +
                             "<br>" +
                             "Please attach log files from <a href=\"file\">" + logFile + "</a><br>" +
                             "to the <a href=\"url\">YouTrack issue</a>";*/
    Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Local History is broken", message, /*+ createIssuePart*/
    NotificationType.ERROR, new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if ("url".equals(event.getDescription())) {
                    BrowserUtil.browse("http://youtrack.jetbrains.net/issue/IDEA-71270");
                } else {
                    File file = new File(logFile);
                    ShowFilePathAction.openFile(file);
                }
            }
        }
    }), null);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 15 with HyperlinkEvent

use of javax.swing.event.HyperlinkEvent 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)

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