Search in sources :

Example 11 with LinkedHashMap

use of com.intellij.util.containers.hash.LinkedHashMap in project intellij-community by JetBrains.

the class EventLog method formatForLog.

public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
    DocumentImpl logDoc = new DocumentImpl("", true);
    AtomicBoolean showMore = new AtomicBoolean(false);
    Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
    List<RangeMarker> lineSeparators = new ArrayList<>();
    String title = notification.getTitle();
    String subtitle = notification.getSubtitle();
    if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
        title += " (" + subtitle + ")";
    }
    title = truncateLongString(showMore, title);
    String content = truncateLongString(showMore, notification.getContent());
    RangeMarker afterTitle = null;
    boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
    if (StringUtil.isNotEmpty(title)) {
        if (StringUtil.isNotEmpty(content)) {
            appendText(logDoc, ": ");
            afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
        }
    }
    int titleLength = logDoc.getTextLength();
    hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
    List<AnAction> actions = notification.getActions();
    if (!actions.isEmpty()) {
        String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {

            private int index;

            @Override
            public String fun(AnAction action) {
                return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
            }
        }, isLongLine(actions) ? "<br>" : "&nbsp;") + "</p>";
        Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
                Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
            }
        });
        if (title.length() > 0 || content.length() > 0) {
            lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
        }
        hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
    }
    String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
    indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
    ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
    for (RangeMarker marker : links.keySet()) {
        if (!marker.isValid()) {
            showMore.set(true);
            continue;
        }
        list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
    }
    if (showMore.get()) {
        String sb = "show balloon";
        if (!logDoc.getText().endsWith(" ")) {
            appendText(logDoc, " ");
        }
        appendText(logDoc, "(" + sb + ")");
        list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
    }
    return new LogEntry(logDoc.getText(), status, list, titleLength);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) RangeMarker(com.intellij.openapi.editor.RangeMarker) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) RelativePoint(com.intellij.ui.awt.RelativePoint) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 12 with LinkedHashMap

use of com.intellij.util.containers.hash.LinkedHashMap in project intellij-community by JetBrains.

the class ExportEclipseProjectsAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    // to flush iml files
    if (project == null) {
        return;
    }
    project.save();
    List<Module> modules = new SmartList<>();
    List<Module> incompatibleModules = new SmartList<>();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        if (!EclipseModuleManagerImpl.isEclipseStorage(module)) {
            try {
                ClasspathStorageProvider provider = ClasspathStorage.getProvider(JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID);
                if (provider != null) {
                    provider.assertCompatible(ModuleRootManager.getInstance(module));
                }
                modules.add(module);
            } catch (ConfigurationException ignored) {
                incompatibleModules.add(module);
            }
        }
    }
    //todo suggest smth with hierarchy modules
    if (incompatibleModules.isEmpty()) {
        if (modules.isEmpty()) {
            Messages.showInfoMessage(project, EclipseBundle.message("eclipse.export.nothing.to.do"), EclipseBundle.message("eclipse.export.dialog.title"));
            return;
        }
    } else if (Messages.showOkCancelDialog(project, "<html><body>Eclipse incompatible modules found:<ul><br><li>" + StringUtil.join(incompatibleModules, module -> module.getName(), "<br><li>") + "</ul><br>Would you like to proceed and possibly lose your configurations?</body></html>", EclipseBundle.message("eclipse.export.dialog.title"), Messages.getWarningIcon()) != Messages.OK) {
        return;
    }
    modules.addAll(incompatibleModules);
    ExportEclipseProjectsDialog dialog = new ExportEclipseProjectsDialog(project, modules);
    if (!dialog.showAndGet()) {
        return;
    }
    if (dialog.isLink()) {
        for (Module module : dialog.getSelectedModules()) {
            ClasspathStorage.setStorageType(ModuleRootManager.getInstance(module), JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID);
        }
    } else {
        LinkedHashMap<Module, String> module2StorageRoot = new LinkedHashMap<>();
        for (Module module : dialog.getSelectedModules()) {
            VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
            String storageRoot = contentRoots.length == 1 ? contentRoots[0].getPath() : ClasspathStorage.getStorageRootFromOptions(module);
            module2StorageRoot.put(module, storageRoot);
            try {
                DotProjectFileHelper.saveDotProjectFile(module, storageRoot);
            } catch (Exception e1) {
                LOG.error(e1);
            }
        }
        for (Module module : module2StorageRoot.keySet()) {
            ModuleRootModel model = ModuleRootManager.getInstance(module);
            String storageRoot = module2StorageRoot.get(module);
            try {
                Element classpathElement = new EclipseClasspathWriter().writeClasspath(null, model);
                File classpathFile = new File(storageRoot, EclipseXml.CLASSPATH_FILE);
                if (!FileUtil.createIfDoesntExist(classpathFile)) {
                    continue;
                }
                EclipseJDOMUtil.output(classpathElement, classpathFile, project);
                final Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
                if (IdeaSpecificSettings.writeIdeaSpecificClasspath(ideaSpecific, model)) {
                    File emlFile = new File(storageRoot, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX);
                    if (!FileUtil.createIfDoesntExist(emlFile)) {
                        continue;
                    }
                    EclipseJDOMUtil.output(ideaSpecific, emlFile, project);
                }
            } catch (Exception e1) {
                LOG.error(e1);
            }
        }
    }
    try {
        EclipseUserLibrariesHelper.appendProjectLibraries(project, dialog.getUserLibrariesFile());
    } catch (IOException e1) {
        LOG.error(e1);
    }
    project.save();
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaXml(org.jetbrains.idea.eclipse.IdeaXml) ClasspathStorage(com.intellij.openapi.roots.impl.storage.ClasspathStorage) DotProjectFileHelper(org.jetbrains.idea.eclipse.conversion.DotProjectFileHelper) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) SmartList(com.intellij.util.SmartList) EclipseUserLibrariesHelper(org.jetbrains.idea.eclipse.conversion.EclipseUserLibrariesHelper) EclipseXml(org.jetbrains.idea.eclipse.EclipseXml) Project(com.intellij.openapi.project.Project) EclipseClasspathWriter(org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter) Messages(com.intellij.openapi.ui.Messages) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) DumbAware(com.intellij.openapi.project.DumbAware) JpsEclipseClasspathSerializer(org.jetbrains.jps.eclipse.model.JpsEclipseClasspathSerializer) StringUtil(com.intellij.openapi.util.text.StringUtil) EclipseModuleManagerImpl(org.jetbrains.idea.eclipse.config.EclipseModuleManagerImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) IOException(java.io.IOException) EclipseJDOMUtil(org.jdom.output.EclipseJDOMUtil) IdeaSpecificSettings(org.jetbrains.idea.eclipse.conversion.IdeaSpecificSettings) File(java.io.File) List(java.util.List) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) ClasspathStorageProvider(com.intellij.openapi.roots.impl.storage.ClasspathStorageProvider) Function(com.intellij.util.Function) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) EclipseBundle(org.jetbrains.idea.eclipse.EclipseBundle) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) EclipseClasspathWriter(org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter) IOException(java.io.IOException) IOException(java.io.IOException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) Project(com.intellij.openapi.project.Project) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ClasspathStorageProvider(com.intellij.openapi.roots.impl.storage.ClasspathStorageProvider) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) SmartList(com.intellij.util.SmartList) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

LinkedHashMap (com.intellij.util.containers.hash.LinkedHashMap)12 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)2 AnAction (com.intellij.openapi.actionSystem.AnAction)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 PrefixMatcher (com.intellij.codeInsight.completion.PrefixMatcher)1 AnnotationHolderImpl (com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 CopyPastePreProcessor (com.intellij.codeInsight.editorActions.CopyPastePreProcessor)1 Variable (com.intellij.codeInsight.template.impl.Variable)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 ProcessInfo (com.intellij.execution.process.ProcessInfo)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 GroupDescriptor (com.intellij.internal.statistic.beans.GroupDescriptor)1 Annotation (com.intellij.lang.annotation.Annotation)1 AnnotationSession (com.intellij.lang.annotation.AnnotationSession)1 ExternalAnnotator (com.intellij.lang.annotation.ExternalAnnotator)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1