DBE-515 Connecting dialog: provide a way to see the full database error message

This commit is contained in:
Gregory.Shrago
2015-11-06 03:33:34 +03:00
parent 07bc39444c
commit 6ae2aac04a
5 changed files with 56 additions and 53 deletions
@@ -36,8 +36,9 @@ import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* @author cdr
@@ -106,7 +107,7 @@ public class ColorAndFontDescriptionPanel extends JPanel {
c.addActionListener(actionListener);
}
myEffectsCombo.addActionListener(actionListener);
Messages.configureMessagePaneUi(myInheritanceLabel, "<html>", false);
Messages.configureMessagePaneUi(myInheritanceLabel, "<html>", null);
myInheritanceLabel.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
@@ -77,7 +77,7 @@ public class ConvertProjectDialog extends DialogWrapper {
ApplicationNamesInfo.getInstance().getFullProductName()));
}
message.append(IdeBundle.message("conversion.dialog.text.2", myBackupDir.getAbsolutePath()));
Messages.configureMessagePaneUi(myTextPane, XmlStringUtil.wrapInHtml(message), false);
Messages.configureMessagePaneUi(myTextPane, XmlStringUtil.wrapInHtml(message), null);
myTextPane.addHyperlinkListener(new HyperlinkListener() {
@Override
@@ -29,11 +29,7 @@ import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.BrowserHyperlinkListener;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.InsertPathAction;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.MessageException;
import com.intellij.ui.*;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.mac.MacMessages;
import com.intellij.ui.mac.foundation.MacUtil;
@@ -1519,25 +1515,8 @@ public class Messages {
panel.add(container, BorderLayout.WEST);
}
if (myMessage != null) {
final JTextPane messageComponent = createMessageComponent(myMessage);
final Dimension screenSize = messageComponent.getToolkit().getScreenSize();
final Dimension textSize = messageComponent.getPreferredSize();
if (myMessage.length() > 100) {
final JScrollPane pane = ScrollPaneFactory.createScrollPane(messageComponent);
pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
final int scrollSize = (int)new JScrollBar(Adjustable.VERTICAL).getPreferredSize().getWidth();
final Dimension preferredSize =
new Dimension(Math.min(textSize.width, screenSize.width / 2) + scrollSize,
Math.min(textSize.height, screenSize.height / 3) + scrollSize);
pane.setPreferredSize(preferredSize);
panel.add(pane, BorderLayout.CENTER);
}
else {
panel.add(messageComponent, BorderLayout.CENTER);
}
JTextPane messageComponent = createMessageComponent(myMessage);
panel.add(wrapToScrollPaneIfNeeded(messageComponent, 50, 10), BorderLayout.CENTER);
}
return panel;
}
@@ -1586,22 +1565,25 @@ public class Messages {
@NotNull
public static JTextPane configureMessagePaneUi(JTextPane messageComponent, String message) {
return configureMessagePaneUi(messageComponent, message, true);
JTextPane pane = configureMessagePaneUi(messageComponent, message, null);
if (UIUtil.HTML_MIME.equals(pane.getContentType())) {
pane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
}
return pane;
}
@NotNull
public static JTextPane configureMessagePaneUi(JTextPane messageComponent,
String message,
final boolean addBrowserHyperlinkListener) {
messageComponent.setFont(UIUtil.getLabelFont());
public static JTextPane configureMessagePaneUi(@NotNull JTextPane messageComponent,
@Nullable String message,
@Nullable UIUtil.FontSize fontSize) {
UIUtil.FontSize fixedFontSize = fontSize == null ? UIUtil.FontSize.NORMAL : fontSize;
messageComponent.setFont(UIUtil.getLabelFont(fixedFontSize));
if (BasicHTML.isHTMLString(message)) {
final HTMLEditorKit editorKit = new HTMLEditorKit();
editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(UIUtil.getLabelFont(), UIUtil.getLabelForeground()));
HTMLEditorKit editorKit = new HTMLEditorKit();
Font font = UIUtil.getLabelFont(fixedFontSize);
editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(font, UIUtil.getLabelForeground()));
messageComponent.setEditorKit(editorKit);
messageComponent.setContentType(UIUtil.HTML_MIME);
if (addBrowserHyperlinkListener) {
messageComponent.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
}
}
messageComponent.setText(message);
messageComponent.setEditable(false);
@@ -1621,6 +1603,25 @@ public class Messages {
return messageComponent;
}
@NotNull
public static JComponent wrapToScrollPaneIfNeeded(@NotNull JComponent comp, int columns, int lines) {
float fontSize = comp.getFont().getSize2D();
Dimension maxDim = new Dimension((int)(fontSize * columns), (int)(fontSize * lines));
Dimension prefDim = comp.getPreferredSize();
if (prefDim.width <= maxDim.width && prefDim.height <= maxDim.height) return comp;
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(comp);
scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
int barWidth = UIUtil.getScrollBarWidth();
Dimension preferredSize = new Dimension(
Math.min(prefDim.width, maxDim.width) + barWidth,
Math.min(prefDim.height, maxDim.height) + barWidth);
scrollPane.setPreferredSize(preferredSize);
return scrollPane;
}
protected static class TwoStepConfirmationDialog extends MessageDialog {
private JCheckBox myCheckBox;
private final String myCheckboxText;
@@ -18,14 +18,6 @@
<properties/>
<border type="none"/>
<children>
<component id="96e22" class="javax.swing.JLabel" binding="myMessageLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Message"/>
</properties>
</component>
<grid id="8cb22" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
@@ -101,6 +93,14 @@
</grid>
</children>
</grid>
<grid id="8fce7" binding="myMessagePanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<component id="99da1" class="javax.swing.JLabel" binding="myIconLabel">
@@ -22,17 +22,18 @@ import com.intellij.util.ui.DialogUtil;
import com.intellij.util.ui.UIUtil;
import javax.swing.*;
import java.awt.*;
/**
* @author gregsh
*/
public class PasswordPromptComponent {
private JPanel myRootPanel;
private JPanel myMessagePanel;
private JPanel myUserPanel;
private JPanel myPasswordPanel;
private JPasswordField myPasswordField;
private JCheckBox myRememberCheckBox;
private JLabel myMessageLabel;
private JLabel myPasswordLabel;
private JLabel myUserLabel;
private JTextField myUserTextField;
@@ -41,17 +42,17 @@ public class PasswordPromptComponent {
public PasswordPromptComponent(PasswordSafeSettings.ProviderType type,
String message,
boolean showUserName,
String passwordPrompt,
String rememberPrompt) {
String passwordFieldLabel,
String rememberCheckBoxLabel) {
myIconLabel.setText("");
myIconLabel.setIcon(Messages.getWarningIcon());
myMessageLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
myMessageLabel.setText(message);
JTextPane messageField = Messages.configureMessagePaneUi(new JTextPane(), message, UIUtil.FontSize.SMALL);
myMessagePanel.add(Messages.wrapToScrollPaneIfNeeded(messageField, 0, 4), BorderLayout.CENTER);
setTargetProviderType(type);
setUserInputVisible(showUserName);
if (passwordPrompt != null) myPasswordLabel.setText(passwordPrompt);
if (rememberPrompt != null) {
myRememberCheckBox.setText(rememberPrompt);
if (passwordFieldLabel != null) myPasswordLabel.setText(passwordFieldLabel);
if (rememberCheckBoxLabel != null) {
myRememberCheckBox.setText(rememberCheckBoxLabel);
DialogUtil.registerMnemonic(myRememberCheckBox);
}
}