IDEA-171124 - Docker: allow long text for test connection error

- fixed for right pane of the Docker view
- removed duplication of error text for soften-only RuntimeExceptions
This commit is contained in:
Michael Golubev
2017-07-13 20:04:45 +02:00
parent d695843ceb
commit e5f918f48d
@@ -24,10 +24,12 @@ import com.intellij.remoteServer.runtime.ServerConnection;
import com.intellij.remoteServer.runtime.ServerConnectionListener;
import com.intellij.remoteServer.runtime.ServerConnectionManager;
import com.intellij.ui.*;
import com.intellij.ui.components.JBPanelWithEmptyText;
import com.intellij.ui.components.JBPanel;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.Alarm;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ui.JBSwingUtilities;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -64,7 +66,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv
private final Tree myTree;
private final CardLayout myPropertiesPanelLayout;
private final JPanel myPropertiesPanel;
private final JBPanelWithEmptyText myMessagePanel;
private final JBPanelWithHtmlEmptyText myMessagePanel;
private final Map<String, JComponent> myLogComponents = new HashMap<>();
private final DefaultTreeModel myTreeModel;
@@ -95,7 +97,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv
splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree, SideBorder.LEFT));
myPropertiesPanelLayout = new CardLayout();
myPropertiesPanel = new JPanel(myPropertiesPanelLayout);
myMessagePanel = new JBPanelWithEmptyText().withEmptyText(EMPTY_SELECTION_MESSAGE);
myMessagePanel = new JBPanelWithHtmlEmptyText().withEmptyText(EMPTY_SELECTION_MESSAGE);
myPropertiesPanel.add(MESSAGE_CARD, myMessagePanel);
splitter.setSecondComponent(myPropertiesPanel);
getMainPanel().add(splitter, BorderLayout.CENTER);
@@ -209,8 +211,14 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv
}
}
private void showMessageLabel(String text) {
myMessagePanel.getEmptyText().setText(text);
private void showMessageLabel(@NotNull String text) {
if (text.contains("<br/>") && !text.startsWith("<html>")) {
String html = "<html><center>" + text + "</center></html>";
myMessagePanel.setEmptyText(html);
}
else {
myMessagePanel.setEmptyText(text);
}
myPropertiesPanelLayout.show(myPropertiesPanel, MESSAGE_CARD);
}
@@ -364,4 +372,51 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv
return isServerNodeMatch(serverNode, connection)
&& node.getDeployment().getName().equals(deploymentName);
}
private static class JBPanelWithHtmlEmptyText extends JBPanel<JBPanelWithHtmlEmptyText> {
private final JLabel myLabel = new JLabel();
public JBPanelWithHtmlEmptyText withEmptyText(@NotNull String text) {
setEmptyText(text);
return this;
}
public void setEmptyText(@NotNull String text) {
myLabel.setText(text);
repaint();
}
@Override
protected Graphics getComponentGraphics(Graphics graphics) {
return JBSwingUtilities.runGlobalCGTransform(this, super.getComponentGraphics(graphics));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (!UIUtil.uiChildren(this).filter(Component::isVisible).isEmpty()) {
return;
}
myLabel.setFont(getFont());
myLabel.setBackground(getBackground());
myLabel.setForeground(UIUtil.getInactiveTextColor());
Rectangle bounds = getBounds();
Dimension size = myLabel.getPreferredSize();
myLabel.setBounds(0, 0, size.width, size.height);
int x = (bounds.width - size.width) / 2;
int y = (bounds.height - size.height) / 3; // above center
Graphics g2 = g.create(bounds.x + x, bounds.y + y, bounds.width, bounds.height);
try {
myLabel.paint(g2);
}
finally {
g2.dispose();
}
}
}
}