|
2 | 2 |
|
3 | 3 | import com.intellij.icons.AllIcons; |
4 | 4 | import com.intellij.openapi.fileChooser.*; |
| 5 | +import com.intellij.openapi.options.ConfigurationException; |
5 | 6 | import com.intellij.openapi.project.Project; |
6 | 7 | import com.intellij.openapi.ui.*; |
7 | 8 | import com.intellij.ui.*; |
|
11 | 12 | import org.digma.intellij.plugin.analytics.BackendInfoHolder; |
12 | 13 | import org.digma.intellij.plugin.auth.account.*; |
13 | 14 | import org.digma.intellij.plugin.common.*; |
| 15 | +import org.digma.intellij.plugin.errorreporting.ErrorReporter; |
14 | 16 | import org.jetbrains.annotations.*; |
15 | 17 |
|
16 | 18 | import javax.swing.*; |
@@ -386,33 +388,45 @@ private static JBLabel createBackendVersionLabel() { |
386 | 388 | private JPanel createImportExportPanel() { |
387 | 389 | //noinspection ExtractMethodRecommender |
388 | 390 | var exportSettingsButton = new JButton("Export Settings"); |
389 | | - exportSettingsButton.addActionListener(e -> { |
| 391 | + exportSettingsButton.addActionListener(actionEvent -> { |
| 392 | + try { |
390 | 393 |
|
391 | | - Messages.showInfoMessage("I Will export the saved settings, Not necessarily what is now showing. to export the shown values please first save and reopen settings to export.", "Export"); |
| 394 | + SettingsUtils.validateSettings(this); |
392 | 395 |
|
393 | | - var dialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export To File", "Export settings to file", "conf"), (Project) null); |
394 | | - var file = dialog.save("digma-setting.conf"); |
395 | | - if (file != null) { |
396 | | - var exportResult = SettingsUtils.exportSettingsToFile(file.getFile()); |
397 | | - if (!exportResult) { |
398 | | - Messages.showErrorDialog("Could not export settings,Please check the logs.", "Export Error"); |
| 396 | + var dialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export To File", "Export settings to file", "conf"), (Project) null); |
| 397 | + var file = dialog.save("digma-setting.conf"); |
| 398 | + if (file != null) { |
| 399 | + var exportResult = SettingsUtils.exportSettingsToFile(file.getFile(), toProperties()); |
| 400 | + if (!exportResult) { |
| 401 | + Messages.showErrorDialog("Could not export settings,Please check the logs.", "Export Error"); |
| 402 | + } |
399 | 403 | } |
| 404 | + } catch (ConfigurationException configurationException) { |
| 405 | + Messages.showErrorDialog(configurationException.getMessage(), "Invalid Settings"); |
| 406 | + } catch (Throwable e) { |
| 407 | + Messages.showErrorDialog(e.getMessage(), "Error"); |
| 408 | + ErrorReporter.getInstance().reportError("SettingsComponent.exportSettingsButton.ActionListener", e); |
400 | 409 | } |
401 | 410 | }); |
402 | 411 |
|
403 | 412 | var importSettingsButton = new JButton("Import Settings"); |
404 | | - importSettingsButton.addActionListener(e -> { |
405 | | - var dialog = FileChooserFactory.getInstance().createPathChooser(new FileChooserDescriptor(true, false, false, false, false, false), null, myMainPanel); |
406 | | - dialog.choose(null, virtualFiles -> { |
407 | | - if (virtualFiles.size() == 1) { |
408 | | - var properties = SettingsUtils.importSettingsFromFile(virtualFiles.get(0)); |
409 | | - if (properties == null) { |
410 | | - Messages.showErrorDialog("Could not import settings,Please check the logs.", "Import Error"); |
411 | | - } else { |
412 | | - resetFromSettings(SettingsState.fromProperties(properties)); |
| 413 | + importSettingsButton.addActionListener(actionEvent -> { |
| 414 | + try { |
| 415 | + var dialog = FileChooserFactory.getInstance().createPathChooser(new FileChooserDescriptor(true, false, false, false, false, false), null, myMainPanel); |
| 416 | + dialog.choose(null, virtualFiles -> { |
| 417 | + if (virtualFiles.size() == 1) { |
| 418 | + var properties = SettingsUtils.importSettingsFromFile(virtualFiles.get(0)); |
| 419 | + if (properties == null) { |
| 420 | + Messages.showErrorDialog("Could not import settings,Please check the logs.", "Import Error"); |
| 421 | + } else { |
| 422 | + fromProperties(properties); |
| 423 | + } |
413 | 424 | } |
414 | | - } |
415 | | - }); |
| 425 | + }); |
| 426 | + } catch (Throwable e) { |
| 427 | + Messages.showErrorDialog(e.getMessage(), "Error"); |
| 428 | + ErrorReporter.getInstance().reportError("SettingsComponent.importSettingsButton.ActionListener", e); |
| 429 | + } |
416 | 430 | }); |
417 | 431 |
|
418 | 432 | var importExportPanel = new JPanel(); |
@@ -443,4 +457,41 @@ private JButton createResetPluginButton() { |
443 | 457 | return resetPluginButton; |
444 | 458 | } |
445 | 459 |
|
| 460 | + |
| 461 | + private Map<String, String> toProperties() { |
| 462 | + Map<String, String> properties = new HashMap<>(); |
| 463 | + properties.put("apiUrl", getApiUrl()); |
| 464 | + if (getApiToken() != null) { |
| 465 | + properties.put("apiToken", getApiToken()); |
| 466 | + } |
| 467 | + if (getJaegerUrl() != null) { |
| 468 | + properties.put("jaegerUrl", getJaegerUrl()); |
| 469 | + } |
| 470 | + if (getJaegerQueryUrl() != null) { |
| 471 | + properties.put("jaegerQueryUrl", getJaegerQueryUrl()); |
| 472 | + } |
| 473 | + properties.put("jaegerLinkMode", getJaegerLinkMode().name()); |
| 474 | + properties.put("springBootObservabilityMode", getSpringBootObservabilityMode().name()); |
| 475 | + properties.put("runtimeObservabilityBackendUrl", getRuntimeObservabilityBackendUrl()); |
| 476 | + if (getExtendedObservability() != null) { |
| 477 | + properties.put("extendedObservability", getExtendedObservability()); |
| 478 | + } |
| 479 | + if (getExtendedObservabilityExclude() != null) { |
| 480 | + properties.put("extendedObservabilityExcludes", getExtendedObservabilityExclude()); |
| 481 | + } |
| 482 | + return properties; |
| 483 | + } |
| 484 | + |
| 485 | + private void fromProperties(Map<String, String> properties) { |
| 486 | + setApiUrl(properties.get("apiUrl")); |
| 487 | + setApiToken(properties.get("apiToken")); |
| 488 | + setJaegerUrl(properties.get("jaegerUrl")); |
| 489 | + setJaegerQueryUrl(properties.get("jaegerQueryUrl")); |
| 490 | + setJaegerLinkMode(JaegerLinkMode.valueOf(properties.get("jaegerLinkMode"))); |
| 491 | + setSpringBootObservabilityMode(SpringBootObservabilityMode.valueOf(properties.get("springBootObservabilityMode"))); |
| 492 | + setRuntimeObservabilityBackendUrl(properties.get("runtimeObservabilityBackendUrl")); |
| 493 | + setExtendedObservability(properties.get("extendedObservability")); |
| 494 | + setExtendedObservabilityExclude(properties.get("extendedObservabilityExcludes")); |
| 495 | + } |
| 496 | + |
446 | 497 | } |
0 commit comments