mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Color scheme import: show a message on failure
This commit is contained in:
+5
-14
@@ -122,34 +122,25 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper {
|
||||
final CodeStyleScheme scheme = importExternalCodeStyle(importer);
|
||||
if (scheme != null) {
|
||||
final String additionalImportInfo = StringUtil.notNullize(importer.getAdditionalImportInfo(scheme));
|
||||
showStatus(myImportButton,
|
||||
SchemeImportUtil
|
||||
.showStatus(myImportButton,
|
||||
ApplicationBundle.message("message.code.style.scheme.import.success", selectedImporterName, scheme.getName(), additionalImportInfo),
|
||||
MessageType.INFO);
|
||||
}
|
||||
}
|
||||
catch (SchemeImportException e) {
|
||||
if (e.isWarning()) {
|
||||
showStatus(myImportButton, e.getMessage(), MessageType.WARNING);
|
||||
SchemeImportUtil.showStatus(myImportButton, e.getMessage(), MessageType.WARNING);
|
||||
return;
|
||||
}
|
||||
final String message = ApplicationBundle.message("message.code.style.scheme.import.failure", selectedImporterName, e.getMessage());
|
||||
showStatus(myImportButton, message, MessageType.ERROR);
|
||||
SchemeImportUtil.showStatus(myImportButton, message, MessageType.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void showStatus(final JComponent component, final String message, MessageType messageType) {
|
||||
BalloonBuilder balloonBuilder = JBPopupFactory.getInstance()
|
||||
.createHtmlTextBalloonBuilder(message, messageType.getDefaultIcon(),
|
||||
messageType.getPopupBackground(), null);
|
||||
balloonBuilder.setFadeoutTime(5000);
|
||||
final Balloon balloon = balloonBuilder.createBalloon();
|
||||
balloon.showInCenterOf(component);
|
||||
Disposer.register(ProjectManager.getInstance().getDefaultProject(), balloon);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CodeStyleScheme importExternalCodeStyle(final SchemeImporter<CodeStyleScheme> importer) throws SchemeImportException {
|
||||
final VirtualFile selectedFile = SchemeImportUtil
|
||||
@@ -415,6 +406,6 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper {
|
||||
|
||||
private void exportSelectedScheme() {
|
||||
new CodeStyleSchemeExporterUI(myExportButton, getSelectedScheme(),
|
||||
(message, messageType) -> showStatus(myExportButton, message, messageType)).export();
|
||||
(message, messageType) -> SchemeImportUtil.showStatus(myExportButton, message, messageType)).export();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.intellij.openapi.options.SchemeImportUtil;
|
||||
import com.intellij.openapi.options.SchemeImporter;
|
||||
import com.intellij.openapi.options.SchemeImporterEP;
|
||||
import com.intellij.openapi.project.DefaultProjectFactory;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.EventDispatcher;
|
||||
@@ -242,7 +243,7 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent {
|
||||
|
||||
}
|
||||
catch (SchemeImportException e) {
|
||||
e.printStackTrace();
|
||||
SchemeImportUtil.showStatus(myImportButton, "Import failed: " + e.getMessage(), MessageType.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,17 @@ package com.intellij.openapi.options;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDialog;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.ui.popup.BalloonBuilder;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -59,4 +66,14 @@ public class SchemeImportUtil {
|
||||
virtualFiles[0].refresh(false, false);
|
||||
return virtualFiles[0];
|
||||
}
|
||||
|
||||
public static void showStatus(final JComponent component, final String message, MessageType messageType) {
|
||||
BalloonBuilder balloonBuilder = JBPopupFactory.getInstance()
|
||||
.createHtmlTextBalloonBuilder(message, messageType.getDefaultIcon(),
|
||||
messageType.getPopupBackground(), null);
|
||||
balloonBuilder.setFadeoutTime(5000);
|
||||
final Balloon balloon = balloonBuilder.createBalloon();
|
||||
balloon.showInCenterOf(component);
|
||||
Disposer.register(ProjectManager.getInstance().getDefaultProject(), balloon);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user