diff --git a/snapshot/mongo4idea-0.12.1-SNAPSHOT.zip b/snapshot/mongo4idea-0.12.1-SNAPSHOT.zip index be06f73..ffebcfb 100644 Binary files a/snapshot/mongo4idea-0.12.1-SNAPSHOT.zip and b/snapshot/mongo4idea-0.12.1-SNAPSHOT.zip differ diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/ConfigurationDialog.java b/src/main/java/org/codinjutsu/tools/mongo/view/ConfigurationDialog.java index c8d5dda..18f07f9 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/ConfigurationDialog.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/ConfigurationDialog.java @@ -18,6 +18,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.ui.ValidationInfo; import org.codinjutsu.tools.mongo.ServerConfiguration; import org.codinjutsu.tools.mongo.logic.ConfigurationException; import org.codinjutsu.tools.mongo.logic.MongoManager; @@ -54,9 +55,9 @@ protected JComponent createCenterPanel() { protected void doOKAction() { try { serverConfigurationPanel.applyConfigurationData(configuration); + super.doOKAction(); } catch (ConfigurationException confEx) { serverConfigurationPanel.setErrorMessage(confEx.getMessage()); } - super.doOKAction(); } } diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/ServerConfigurationPanel.java b/src/main/java/org/codinjutsu/tools/mongo/view/ServerConfigurationPanel.java index 4a3750b..09f0b0b 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/ServerConfigurationPanel.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/ServerConfigurationPanel.java @@ -234,28 +234,8 @@ private ServerConfiguration createServerConfigurationForTesting() { return configuration; } - private void validateUrls() { - List serverUrls = getServerUrls(); - if (serverUrls == null) { - throw new ConfigurationException("URL(s) should be set"); - } - for (String serverUrl : serverUrls) { - String[] host_port = serverUrl.split(":"); - if (host_port.length < 2) { - throw new ConfigurationException(String.format("URL '%s' format is incorrect. It should be 'host:port'", serverUrl)); - } - - try { - Integer.valueOf(host_port[1]); - } catch (NumberFormatException e) { - throw new ConfigurationException(String.format("Port in the URL '%s' is incorrect. It should be a number", serverUrl)); - } - } - - } - - public void applyConfigurationData(ServerConfiguration configuration) { + validateLabel(); validateUrls(); configuration.setLabel(getLabel()); @@ -278,6 +258,34 @@ public void applyConfigurationData(ServerConfiguration configuration) { configuration.setSshTunnelingConfiguration(isSshTunneling() ? createSshTunnelingSettings() : SshTunnelingConfiguration.EMPTY); } + private void validateLabel() { + String label = getLabel(); + if (StringUtils.isBlank(label)) { + throw new ConfigurationException("Label should be set"); + } + } + + private void validateUrls() { + List serverUrls = getServerUrls(); + if (serverUrls == null) { + throw new ConfigurationException("URL(s) should be set"); + } + for (String serverUrl : serverUrls) { + String[] host_port = serverUrl.split(":"); + if (host_port.length < 2) { + throw new ConfigurationException(String.format("URL '%s' format is incorrect. It should be 'host:port'", serverUrl)); + } + + try { + Integer.valueOf(host_port[1]); + } catch (NumberFormatException e) { + throw new ConfigurationException(String.format("Port in the URL '%s' is incorrect. It should be a number", serverUrl)); + } + } + + } + + private SshTunnelingConfiguration createSshTunnelingSettings() { return new SshTunnelingConfiguration( getSshProxyHost(), getSshProxyUser(), diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/AddKeyAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/AddKeyAction.java index 03b38c8..7e94263 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/AddKeyAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/AddKeyAction.java @@ -19,12 +19,13 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.view.edition.AddKeyDialog; import org.codinjutsu.tools.mongo.view.edition.MongoEditionPanel; import java.awt.event.KeyEvent; -public class AddKeyAction extends AnAction { +public class AddKeyAction extends AnAction implements DumbAware { private final MongoEditionPanel mongoEditionPanel; diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/AddValueAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/AddValueAction.java index 6bce27e..8ea179f 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/AddValueAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/AddValueAction.java @@ -19,10 +19,11 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.view.edition.AddValueDialog; import org.codinjutsu.tools.mongo.view.edition.MongoEditionPanel; -public class AddValueAction extends AnAction { +public class AddValueAction extends AnAction implements DumbAware { private final MongoEditionPanel mongoEditionPanel; diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/DeleteKeyAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/DeleteKeyAction.java index cc5f73a..9ed4629 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/DeleteKeyAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/edition/DeleteKeyAction.java @@ -19,11 +19,12 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.view.edition.MongoEditionPanel; import java.awt.event.KeyEvent; -public class DeleteKeyAction extends AnAction { +public class DeleteKeyAction extends AnAction implements DumbAware { private final MongoEditionPanel mongoEditionPanel; diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/AddServerAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/AddServerAction.java index d983785..1376ca7 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/AddServerAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/AddServerAction.java @@ -19,12 +19,13 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.MongoConfiguration; import org.codinjutsu.tools.mongo.ServerConfiguration; import org.codinjutsu.tools.mongo.view.ConfigurationDialog; import org.codinjutsu.tools.mongo.view.MongoExplorerPanel; -public class AddServerAction extends AnAction { +public class AddServerAction extends AnAction implements DumbAware { private final MongoExplorerPanel mongoExplorerPanel; public AddServerAction(MongoExplorerPanel mongoExplorerPanel) { diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/DeleteAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/DeleteAction.java index 1eaa115..fd46955 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/DeleteAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/DeleteAction.java @@ -18,6 +18,7 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.util.SystemInfo; import org.codinjutsu.tools.mongo.model.MongoCollection; import org.codinjutsu.tools.mongo.model.MongoDatabase; @@ -27,7 +28,7 @@ import javax.swing.*; import java.awt.event.KeyEvent; -public class DeleteAction extends AnAction { +public class DeleteAction extends AnAction implements DumbAware { private final MongoExplorerPanel mongoExplorerPanel; public DeleteAction(MongoExplorerPanel mongoExplorerPanel) { diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/EditServerAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/EditServerAction.java index ecee05f..d6341ca 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/EditServerAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/explorer/EditServerAction.java @@ -19,6 +19,7 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.ServerConfiguration; import org.codinjutsu.tools.mongo.model.MongoServer; import org.codinjutsu.tools.mongo.view.ConfigurationDialog; @@ -27,7 +28,7 @@ import java.awt.*; import java.awt.event.KeyEvent; -public class EditServerAction extends AnAction { +public class EditServerAction extends AnAction implements DumbAware { private final MongoExplorerPanel mongoExplorerPanel; public EditServerAction(MongoExplorerPanel mongoExplorerPanel) { diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/EnableAggregateAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/EnableAggregateAction.java index 39876f6..07e6415 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/EnableAggregateAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/EnableAggregateAction.java @@ -18,13 +18,14 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.utils.GuiUtils; import org.codinjutsu.tools.mongo.view.QueryPanel; import org.jetbrains.annotations.NotNull; import javax.swing.*; -public class EnableAggregateAction extends ToggleAction { +public class EnableAggregateAction extends ToggleAction implements DumbAware { private static final String ENABLE_FIND_MODE = "Toggle to Find Mode"; private static final String ENABLE_AGGREGATION_MODE = "Toggle to Aggregation Mode"; diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ExecuteQuery.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ExecuteQuery.java index 5e9ecc3..475c99c 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ExecuteQuery.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ExecuteQuery.java @@ -19,12 +19,13 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.view.MongoPanel; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; -public class ExecuteQuery extends AnAction { +public class ExecuteQuery extends AnAction implements DumbAware { private final MongoPanel mongoPanel; public ExecuteQuery(MongoPanel mongoPanel) { diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/NavigateBackwardAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/NavigateBackwardAction.java index 7de0849..1c241c0 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/NavigateBackwardAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/NavigateBackwardAction.java @@ -19,9 +19,10 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.view.MongoPanel; -public class NavigateBackwardAction extends AnAction { +public class NavigateBackwardAction extends AnAction implements DumbAware { private final MongoPanel mongoPanel; public NavigateBackwardAction(MongoPanel mongoPanel) { diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/OperatorCompletionAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/OperatorCompletionAction.java index 52b535b..9a03dac 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/OperatorCompletionAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/OperatorCompletionAction.java @@ -24,6 +24,7 @@ import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.PopupChooserBuilder; import com.intellij.ui.components.JBList; @@ -36,7 +37,7 @@ import java.util.LinkedList; import java.util.List; -public class OperatorCompletionAction extends AnAction implements Disposable { +public class OperatorCompletionAction extends AnAction implements Disposable, DumbAware { private static final String MONGO_OPERATOR_COMPLETION = "MONGO_OPERATOR_COMPLETION"; diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ViewAsTableAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ViewAsTableAction.java index 34e9148..8bdf50f 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ViewAsTableAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ViewAsTableAction.java @@ -19,10 +19,11 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.view.MongoPanel; import org.codinjutsu.tools.mongo.view.MongoResultPanel; -public class ViewAsTableAction extends AnAction { +public class ViewAsTableAction extends AnAction implements DumbAware { private final MongoPanel mongoPanel; public ViewAsTableAction(MongoPanel mongoPanel) { diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ViewAsTreeAction.java b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ViewAsTreeAction.java index 9ec9f19..fc525b9 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ViewAsTreeAction.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/action/result/ViewAsTreeAction.java @@ -19,10 +19,11 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.codinjutsu.tools.mongo.view.MongoPanel; import org.codinjutsu.tools.mongo.view.MongoResultPanel; -public class ViewAsTreeAction extends AnAction { +public class ViewAsTreeAction extends AnAction implements DumbAware { private final MongoPanel mongoPanel; public ViewAsTreeAction(MongoPanel mongoPanel) { diff --git a/src/main/java/org/codinjutsu/tools/mongo/view/model/MongoTreeBuilder.java b/src/main/java/org/codinjutsu/tools/mongo/view/model/MongoTreeBuilder.java index d07e989..201656c 100644 --- a/src/main/java/org/codinjutsu/tools/mongo/view/model/MongoTreeBuilder.java +++ b/src/main/java/org/codinjutsu/tools/mongo/view/model/MongoTreeBuilder.java @@ -54,10 +54,6 @@ public class MongoTreeBuilder extends AbstractTreeBuilder { public MongoTreeBuilder(@NotNull Tree tree) { init(tree, new DefaultTreeModel(new DefaultMutableTreeNode()), new MyTreeStructure(), (descriptorLeft, descriptorRight) -> { - if (descriptorLeft.getElement() == null || descriptorRight.getElement() == null) { - return 0; - } - if (descriptorLeft instanceof ServerDescriptor && descriptorRight instanceof ServerDescriptor) { MongoServer mongoServerLeft = (MongoServer) descriptorLeft.getElement(); MongoServer mongoServerRight = (MongoServer) descriptorRight.getElement(); diff --git a/src/test/java/org/codinjutsu/tools/mongo/view/ServerConfigurationPanelTest.java b/src/test/java/org/codinjutsu/tools/mongo/view/ServerConfigurationPanelTest.java index 94ea077..0fd416c 100644 --- a/src/test/java/org/codinjutsu/tools/mongo/view/ServerConfigurationPanelTest.java +++ b/src/test/java/org/codinjutsu/tools/mongo/view/ServerConfigurationPanelTest.java @@ -234,10 +234,18 @@ public void loadFormWithSSHTunneling() { frameFixture.textBox("sshProxyPasswordField").requireText("mySecuredPassword"); } + @Test + public void validateFormWithMissingLabelShouldThrowAConfigurationException() { + thrown.expect(ConfigurationException.class); + thrown.expectMessage("Label should be set"); + + configurationPanel.applyConfigurationData(new ServerConfiguration()); + } @Test public void validateFormWithMissingMongoUrlShouldThrowAConfigurationException() { thrown.expect(ConfigurationException.class); thrown.expectMessage("URL(s) should be set"); + frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText(null); @@ -248,6 +256,7 @@ public void validateFormWithMissingMongoUrlShouldThrowAConfigurationException() public void validateFormWithEmptyMongoUrlShouldThrowAConfigurationException() { thrown.expect(ConfigurationException.class); thrown.expectMessage("URL(s) should be set"); + frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText(""); @@ -258,6 +267,7 @@ public void validateFormWithEmptyMongoUrlShouldThrowAConfigurationException() { public void validateFormWithBadMongoUrlShouldThrowAConfigurationException() { thrown.expect(ConfigurationException.class); thrown.expectMessage("URL 'host' format is incorrect. It should be 'host:port'"); + frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText("host"); @@ -268,6 +278,8 @@ public void validateFormWithBadMongoUrlShouldThrowAConfigurationException() { public void validateFormWithBadMongoPortShouldThrowAConfigurationException() { thrown.expect(ConfigurationException.class); thrown.expectMessage("Port in the URL 'host:port' is incorrect. It should be a number"); + frameFixture.textBox("labelField").setText("MyServer"); + frameFixture.textBox("serverUrlsField").setText("host:port"); @@ -276,7 +288,7 @@ public void validateFormWithBadMongoPortShouldThrowAConfigurationException() { @Test public void validateFormWithReplicatSet() { - + frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText(" localhost:25, localhost:26 "); ServerConfiguration configuration = new ServerConfiguration();