Skip to content

Commit

Permalink
Merge pull request #183 from couchbaselabs/show_link_to_cbmigrate
Browse files Browse the repository at this point in the history
adding link to dialog
  • Loading branch information
deniswsrosa authored Mar 19, 2024
2 parents c166d7c + b76ed2b commit d4c8cd0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ private JPanel createMongoDBPanel() {
JLabel infoLabel = new JLabel();

infoLabel.setIcon(IconLoader.getIcon("/assets/icons/information_big.svg", DocumentFilterDialog.class));

infoLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
String content = """
<html>
<h2>MongoDB Connection URI</h2>
<div>
The MongoDB Connection URI is a string that specifies how to connect to a MongoDB database. It contains all the information needed to establish a connection, including:
<p>The MongoDB Connection URI is a string that specifies how to connect to a MongoDB database.<br> It contains all the information needed to establish a connection, including:</p>
<ul>
<li>Hostnames or IP addresses of MongoDB servers</li>
<li>Port number for the MongoDB server</li>
Expand All @@ -117,6 +118,10 @@ <li>Authentication credentials (username and password)</li>
<li><strong>?authSource=admin&ssl=true</strong> - Additional connection options (optional)</li>
</ul>
</div>
<br>
Check the CLI tool for additional options <a href='https://github.com/couchbaselabs/cbmigrate'>here</a>
<br>
</html>""";

TemplateUtil.showGotItTooltip(e.getComponent(), content);
Expand Down Expand Up @@ -262,6 +267,9 @@ public void mouseEntered(MouseEvent e) {
<h3>Migrate Collections Indexes and Definitions</h3>
Check this option if you want to migrate the indexes and definitions of the selected collections.
</div>
<br>
Check the CLI tool for additional options <a href='https://github.com/couchbaselabs/cbmigrate'>here</a>
<br>
</html>""";

TemplateUtil.showGotItTooltip(e.getComponent(), content);
Expand Down Expand Up @@ -376,6 +384,9 @@ public void mouseEntered(MouseEvent e) {
<h3>Scope</h3>
Select the scope within the chosen bucket where the data will be migrated.
</div>
<br>
Check the CLI tool for additional options <a href='https://github.com/couchbaselabs/cbmigrate'>here</a>
<br>
</html>""";

TemplateUtil.showGotItTooltip(e.getComponent(), content);
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/utils/TemplateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.intellij.util.ui.UIUtil;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
Expand All @@ -26,15 +27,35 @@ public class TemplateUtil {
public static void showGotItTooltip(Component component, String tooltipText) {
Point screenPoint = component.getLocationOnScreen();
Point tooltipPoint = new Point(screenPoint.x + component.getWidth(), screenPoint.y);
JLabel label = new JLabel(tooltipText);
JTextPane label = new JTextPane();
label.setContentType("text/html"); // Set content type to HTML
label.setText(tooltipText);
label.setEditable(false);
label.setOpaque(false);
label.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
Desktop.getDesktop().browse(e.getURL().toURI()); // Open the link in the default browser
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
label.setBorder(JBUI.Borders.empty(2));
JBScrollPane scroll = new JBScrollPane(label);
scroll.setOpaque(false);
scroll.setBorder(null);
scroll.getViewport().setOpaque(false);
// Wrap the JTextPane in a JBScrollPane
Dimension preferredSize = new Dimension(600, 200);
JBScrollPane scrollPane = new JBScrollPane(label);
scrollPane.setOpaque(false);
scrollPane.getViewport().setOpaque(false);
scrollPane.setBorder(null);
scrollPane.setPreferredSize(preferredSize);

SwingUtilities.invokeLater(() -> {
scrollPane.getViewport().setViewPosition(new Point(0, 0));
});

Balloon balloon = JBPopupFactory.getInstance()
.createBalloonBuilder(scroll)
.createBalloonBuilder(scrollPane)
.setFillColor(UIUtil.getToolTipBackground())
.setBorderColor(JBColor.GRAY)
.setAnimationCycle(200)
Expand Down

0 comments on commit d4c8cd0

Please sign in to comment.