map =
+ RelationshipStorage.getInstance().getValue().getRelationships().get(ActiveCluster.getInstance().getId());
if (map != null && map.containsKey(userObject.getPath())) {
AnAction clearRelationShip = new AnAction("Clear Relationship") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- RelationshipStorage.getInstance().getValue().getRelationships()
- .get(ActiveCluster.getInstance().getId())
- .remove(userObject.getPath());
+ RelationshipStorage.getInstance().getValue().getRelationships().get(ActiveCluster.getInstance().getId()).remove(userObject.getPath());
userObject.setReference(null);
tree.revalidate();
@@ -125,7 +126,9 @@ public void actionPerformed(@NotNull AnActionEvent e) {
showPopup(e, tree, actionGroup);
}
- private static void handleConnectionRightClick(Project project, JPanel toolBarPanel, MouseEvent e, DefaultMutableTreeNode clickedNode, ConnectionNodeDescriptor userObject, Tree tree) {
+ private static void handleConnectionRightClick(Project project, JPanel toolBarPanel, MouseEvent e,
+ DefaultMutableTreeNode clickedNode,
+ ConnectionNodeDescriptor userObject, Tree tree) {
DefaultActionGroup actionGroup = new DefaultActionGroup();
if (userObject.isActive()) {
@@ -227,8 +230,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}
// Migration Dialog
- if (!ActiveCluster.getInstance().isReadOnlyMode() && CBTools.getTool(CBTools.Type.CBMIGRATE).isAvailable()
- ) {
+ if (!ActiveCluster.getInstance().isReadOnlyMode() && CBTools.getTool(CBTools.Type.CBMIGRATE).isAvailable()) {
AnAction cbMigration = new AnAction("MongoDB to Couchbase Migration") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
@@ -236,7 +238,16 @@ public void actionPerformed(@NotNull AnActionEvent e) {
dialog.show();
}
};
+
+ AnAction dynamo = new AnAction("DynamoDB to Couchbase Migration") {
+ @Override
+ public void actionPerformed(@NotNull AnActionEvent e) {
+ DynamoMigrationDialog dialog = new DynamoMigrationDialog(project);
+ dialog.show();
+ }
+ };
tools.add(cbMigration);
+ tools.add(dynamo);
tools.addSeparator();
}
@@ -267,7 +278,8 @@ public void closed(@Nullable Color color) {
}
};
- ColorPicker.showDialog(tree, "Choose a Color for This Connection", initialColor, true, List.of(colorPickerListener), true);
+ ColorPicker.showDialog(tree, "Choose a Color for This Connection", initialColor, true,
+ List.of(colorPickerListener), true);
}
};
colors.add(colorAction);
@@ -277,7 +289,7 @@ public void closed(@Nullable Color color) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
ActiveCluster.getInstance().setReadOnlyMode(true);
- ApplicationManager.getApplication().invokeLater(() -> Messages.showWarningDialog("The Read Only Mode is a simple guardrail in the plugin to avoid unwanted changes in sensible environments. Please note that this is a best effort approach. For true read-only approach, connect to the cluster using read-only credentials.", "Couchbase Plugin Warning"));
+ ApplicationManager.getApplication().invokeLater(() -> Messages.showWarningDialog("The " + "Read Only Mode is a simple guardrail in the plugin to avoid " + "unwanted changes in sensible environments. Please note that this is a best " + "effort approach. For true read-only approach, connect to the cluster using " + "read-only credentials.", "Couchbase Plugin Warning"));
}
};
@@ -351,7 +363,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction editConnection = new AnAction("Edit Connection") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- NewConnectionDialog dialog = new NewConnectionDialog(project, tree, userObject.getSavedCluster(), clickedNode);
+ NewConnectionDialog dialog = new NewConnectionDialog(project, tree, userObject.getSavedCluster(),
+ clickedNode);
dialog.show();
}
};
@@ -369,7 +382,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
showPopup(e, tree, actionGroup);
}
- private static void handleBucketRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode, Tree tree) {
+ private static void handleBucketRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode,
+ Tree tree) {
DefaultActionGroup actionGroup = new DefaultActionGroup();
AnAction menuItem = new AnAction("Refresh Scopes") {
@Override
@@ -414,7 +428,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
String bucketName = ((BucketNodeDescriptor) clickedNode.getUserObject()).getText();
// Show confirmation dialog before deleting bucket
- int result = Messages.showYesNoDialog("Are you sure you want to delete the bucket " + bucketName + "?", "Delete Bucket", Messages.getQuestionIcon());
+ int result =
+ Messages.showYesNoDialog("Are you sure you want to delete the bucket " + bucketName + "?", "Delete Bucket", Messages.getQuestionIcon());
if (result != Messages.YES) {
return;
}
@@ -428,7 +443,9 @@ public void actionPerformed(@NotNull AnActionEvent e) {
tree.collapsePath(treePath.getParentPath());
tree.expandPath(treePath.getParentPath());
} catch (Exception ex) {
- ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage("An error occurred while creating the bucket. Check the Log tab for more.", "Couchbase Plugin Error"));
+ ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage("An error " +
+ "occurred while creating the bucket. Check the Log tab for more.", "Couchbase Plugin "
+ + "Error"));
Log.error("Bucket deletion failed ", ex);
}
}
@@ -439,7 +456,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
showPopup(e, tree, actionGroup);
}
- private static void handleScopeRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode, Tree tree) {
+ private static void handleScopeRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode,
+ Tree tree) {
DefaultActionGroup actionGroup = new DefaultActionGroup();
ScopeNodeDescriptor scope = (ScopeNodeDescriptor) clickedNode.getUserObject();
String bucketName = scope.getBucket();
@@ -461,7 +479,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- NewCollectionDialog dialog = new NewCollectionDialog(project, bucketName, scopeName, clickedNode, tree);
+ NewCollectionDialog dialog = new NewCollectionDialog(project, bucketName, scopeName, clickedNode,
+ tree);
dialog.show();
}
};
@@ -477,7 +496,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
try {
// Show confirmation dialog before deleting scope
- int result = Messages.showYesNoDialog("Are you sure you want to delete the scope " + scopeName + "?", "Delete Scope", Messages.getQuestionIcon());
+ int result =
+ Messages.showYesNoDialog("Are you sure you want to delete the scope " + scopeName + "?", "Delete Scope", Messages.getQuestionIcon());
if (result != Messages.YES) {
return;
}
@@ -510,7 +530,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
if (file != null) {
CBImport.simpleScopeImport(scope.getBucket(), scope.getText(), file.getPath(), project);
} else {
- Messages.showErrorDialog("Simple Import requires a .json file. Please try again.", "Simple Import Error");
+ Messages.showErrorDialog("Simple Import requires a .json file. Please try again.",
+ "Simple " + "Import Error");
}
}
};
@@ -520,8 +541,10 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction simpleExport = new AnAction("Simple Export") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- FileSaverDescriptor fsd = new FileSaverDescriptor("Simple Scope Export", "Choose where you want to save the file:");
- VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(fsd, project).save(("cb_export-" + scope.getText() + "-" + TimeUtils.getCurrentDateTime() + ".json"));
+ FileSaverDescriptor fsd = new FileSaverDescriptor("Simple Scope Export",
+ "Choose where you want to " + "save the file:");
+ VirtualFileWrapper wrapper =
+ FileChooserFactory.getInstance().createSaveFileDialog(fsd, project).save(("cb_export-" + scope.getText() + "-" + TimeUtils.getCurrentDateTime() + ".json"));
if (wrapper != null) {
File file = wrapper.getFile();
CBExport.simpleScopeExport(scope.getBucket(), scope.getText(), file.getAbsolutePath());
@@ -540,8 +563,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
MermaidERDiagramDialog dialog = new MermaidERDiagramDialog(bucketName, scopeName);
dialog.show();
} catch (Exception ex) {
- Log.error("Failed to load the ER Diagram. Double check if the JRE that you are running your IDE has support for JCEF." +
- " https://plugins.jetbrains.com/docs/intellij/jcef.html#enabling-jcef", ex);
+ Log.error("Failed to load the ER Diagram. Double check if the JRE that you are running your " + "IDE has support for JCEF." + " https://plugins.jetbrains.com/docs/intellij/jcef" + ".html#enabling-jcef", ex);
}
}
@@ -553,7 +575,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
showPopup(e, tree, actionGroup);
}
- private static void handleDocumentRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode, FileNodeDescriptor col, Tree tree) {
+ private static void handleDocumentRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode,
+ FileNodeDescriptor col, Tree tree) {
DefaultActionGroup actionGroup = new DefaultActionGroup();
String bucket = col.getBucket();
@@ -576,7 +599,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}
}
if (metadata != null) {
- VirtualFile virtualFile = new LightVirtualFile("(read-only) " + docId + "_meta.json", FileTypeManager.getInstance().getFileTypeByExtension("json"), metadata);
+ VirtualFile virtualFile = new LightVirtualFile("(read-only) " + docId + "_meta.json",
+ FileTypeManager.getInstance().getFileTypeByExtension("json"), metadata);
DocumentFormatter.formatFile(project, virtualFile);
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
fileEditorManager.openFile(virtualFile, true);
@@ -591,7 +615,9 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction deleteDoc = new AnAction("Delete Document") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- int result = Messages.showYesNoDialog("Are you sure you want to delete the document " + col.getId() + "?", "Delete Document", Messages.getQuestionIcon());
+ int result = Messages.showYesNoDialog("Are you sure you want to delete the document " +
+ "" + col.getId() + "?", "Delete Document",
+ Messages.getQuestionIcon());
if (result != Messages.YES) {
return;
}
@@ -617,7 +643,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
} catch (Exception ex) {
ex.printStackTrace();
Log.error("An error occurred while trying to delete the document " + col.getId(), ex);
- Messages.showErrorDialog("Could not delete the document. Please check the logs for more.", "Couchbase Plugin Error");
+ Messages.showErrorDialog("Could not delete the document. Please check the logs for more.",
+ "Couchbase Plugin Error");
}
}
@@ -628,13 +655,15 @@ public void actionPerformed(@NotNull AnActionEvent e) {
showPopup(e, tree, actionGroup);
}
- private static void handleIndexRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode, IndexNodeDescriptor idx, Tree tree) {
+ private static void handleIndexRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode,
+ IndexNodeDescriptor idx, Tree tree) {
DefaultActionGroup actionGroup = new DefaultActionGroup();
AnAction viewIdxStatsAction = new AnAction("View Stats") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- IndexOverviewDialog dialog = new IndexOverviewDialog(project, idx.getBucket(), idx.getScope(), idx.getCollection(), idx.getText().substring(0, idx.getText().lastIndexOf('.')));
+ IndexOverviewDialog dialog = new IndexOverviewDialog(project, idx.getBucket(), idx.getScope(),
+ idx.getCollection(), idx.getText().substring(0, idx.getText().lastIndexOf('.')));
dialog.show();
}
};
@@ -645,17 +674,20 @@ public void actionPerformed(@NotNull AnActionEvent e) {
private static void showPopup(MouseEvent e, Tree tree, DefaultActionGroup actionGroup) {
DataContext dataContext = DataManager.getInstance().getDataContext(tree);
- JBPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, actionGroup, dataContext, JBPopupFactory.ActionSelectionAid.MNEMONICS, false);
+ JBPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, actionGroup, dataContext,
+ JBPopupFactory.ActionSelectionAid.MNEMONICS, false);
popup.show(new RelativePoint(e));
}
- private static void handleCollectionRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode, CollectionNodeDescriptor col, Tree tree) {
+ private static void handleCollectionRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode,
+ CollectionNodeDescriptor col, Tree tree) {
DefaultActionGroup actionGroup = new DefaultActionGroup();
AnAction openDocument = new AnAction("Open Document") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- OpenDocumentDialog dialog = new OpenDocumentDialog(false, project, tree, col.getBucket(), col.getScope(), col.getText());
+ OpenDocumentDialog dialog = new OpenDocumentDialog(false, project, tree, col.getBucket(),
+ col.getScope(), col.getText());
dialog.show();
}
};
@@ -665,7 +697,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction createDocument = new AnAction("Create Document") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- OpenDocumentDialog dialog = new OpenDocumentDialog(true, project, tree, col.getBucket(), col.getScope(), col.getText());
+ OpenDocumentDialog dialog = new OpenDocumentDialog(true, project, tree, col.getBucket(),
+ col.getScope(), col.getText());
dialog.show();
}
};
@@ -683,11 +716,12 @@ public void actionPerformed(@NotNull AnActionEvent e) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- CollectionNodeDescriptor desc = new CollectionNodeDescriptor(
- col.getText(), null, col.getBucket(), col.getScope(), null);
+ CollectionNodeDescriptor desc = new CollectionNodeDescriptor(col.getText(), null, col.getBucket(),
+ col.getScope(), null);
String field = DataLoader.getIndexedField(desc);
- DocumentFilterDialog dialog = new DocumentFilterDialog(tree, clickedNode, col.getBucket(), col.getScope(), col.getText(), field != null);
+ DocumentFilterDialog dialog = new DocumentFilterDialog(tree, clickedNode, col.getBucket(),
+ col.getScope(), col.getText(), field != null);
dialog.show();
}
};
@@ -714,7 +748,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction refreshDocuments = new AnAction("Refresh Documents") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- InferHelper.invalidateInferCacheIfOlder(col.getBucket(), col.getScope(), col.getText(), TimeUnit.MINUTES.toMillis(1));
+ InferHelper.invalidateInferCacheIfOlder(col.getBucket(), col.getScope(), col.getText(),
+ TimeUnit.MINUTES.toMillis(1));
DataLoader.listDocuments(clickedNode, tree, 0);
}
};
@@ -730,7 +765,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
public void actionPerformed(@NotNull AnActionEvent e) {
try {
- int result = Messages.showYesNoDialog("Are you sure you want to delete the collection " + col.getText() + "?", "Delete Collection", Messages.getQuestionIcon());
+ int result =
+ Messages.showYesNoDialog("Are you sure you want to delete the collection " + col.getText() + "?", "Delete Collection", Messages.getQuestionIcon());
if (result != Messages.YES) {
return;
}
@@ -759,12 +795,15 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction simpleImport = new AnAction("Simple Import") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor("json");
+ FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(
+ "json");
VirtualFile file = FileChooser.chooseFile(descriptor, project, null);
if (file != null) {
- CBImport.simpleCollectionImport(col.getBucket(), col.getScope(), col.getText(), file.getPath(), null);
+ CBImport.simpleCollectionImport(col.getBucket(), col.getScope(), col.getText(),
+ file.getPath(), null);
} else {
- Messages.showErrorDialog("Simple Import requires a .json file. Please try again.", "Simple Import Error");
+ Messages.showErrorDialog("Simple Import requires a .json file. Please try again.",
+ "Simple Import Error");
}
}
};
@@ -774,11 +813,14 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction simpleExport = new AnAction("Simple Export") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- FileSaverDescriptor fsd = new FileSaverDescriptor("Simple Collection Export", "Choose where you want to save the file:");
- VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(fsd, project).save(("cb_export-" + col.getScope() + "_" + col.getText() + "-" + TimeUtils.getCurrentDateTime() + ".json"));
+ FileSaverDescriptor fsd = new FileSaverDescriptor("Simple Collection Export",
+ "Choose where you " + "want to save the file:");
+ VirtualFileWrapper wrapper =
+ FileChooserFactory.getInstance().createSaveFileDialog(fsd, project).save(("cb_export-" + col.getScope() + "_" + col.getText() + "-" + TimeUtils.getCurrentDateTime() + ".json"));
if (wrapper != null) {
File file = wrapper.getFile();
- CBExport.simpleCollectionExport(col.getBucket(), col.getScope(), col.getText(), file.getAbsolutePath(), null);
+ CBExport.simpleCollectionExport(col.getBucket(), col.getScope(), col.getText(),
+ file.getAbsolutePath(), null);
}
}
};
@@ -789,7 +831,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}
- private static void handleSearchIndexRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode, SearchIndexNodeDescriptor idx, Tree tree) {
+ private static void handleSearchIndexRightClick(Project project, MouseEvent e, DefaultMutableTreeNode clickedNode
+ , SearchIndexNodeDescriptor idx, Tree tree) {
DefaultActionGroup actionGroup = new DefaultActionGroup();
@@ -809,7 +852,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
"fields": ["*"]
}
""";
- VirtualFile virtualFile = new LightVirtualFile(fileName, FileTypeManager.getInstance().getFileTypeByExtension("cbs.json"), fileContent);
+ VirtualFile virtualFile = new LightVirtualFile(fileName,
+ FileTypeManager.getInstance().getFileTypeByExtension("cbs.json"), fileContent);
virtualFile.putUserData(VirtualFileKeys.BUCKET, idx.getBucket());
virtualFile.putUserData(VirtualFileKeys.SEARCH_INDEX, idx.getIndexName());
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
@@ -828,7 +872,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction deleteDoc = new AnAction("Delete Index") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- int result = Messages.showYesNoDialog("Are you sure you want to delete the index " + idx.getIndexName() + "?", "Delete Document", Messages.getQuestionIcon());
+ int result =
+ Messages.showYesNoDialog("Are you sure you want to delete the index " + idx.getIndexName() + "?", "Delete Document", Messages.getQuestionIcon());
if (result != Messages.YES) {
return;
}
@@ -855,7 +900,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
} catch (Exception ex) {
ex.printStackTrace();
Log.error("An error occurred while trying to delete the index " + idx.getIndexName(), ex);
- Messages.showErrorDialog("Could not delete the index. Please check the logs for more.", "Couchbase Plugin Error");
+ Messages.showErrorDialog("Could not delete the index. Please check the logs for more.",
+ "Couchbase Plugin Error");
}
}
diff --git a/src/main/java/com/couchbase/intellij/tree/docfilter/DocumentFilterDialog.java b/src/main/java/com/couchbase/intellij/tree/docfilter/DocumentFilterDialog.java
index 85a1972e..ead69c87 100644
--- a/src/main/java/com/couchbase/intellij/tree/docfilter/DocumentFilterDialog.java
+++ b/src/main/java/com/couchbase/intellij/tree/docfilter/DocumentFilterDialog.java
@@ -3,7 +3,6 @@
import com.couchbase.client.core.error.CouchbaseException;
import com.couchbase.intellij.database.ActiveCluster;
import com.couchbase.intellij.persistence.QueryFilter;
-import com.couchbase.intellij.persistence.storage.QueryFiltersStorage;
import com.couchbase.intellij.tree.node.CollectionNodeDescriptor;
import com.couchbase.intellij.tree.overview.apis.CouchbaseRestAPI;
import com.couchbase.intellij.workbench.SQLPPQueryUtils;
@@ -15,7 +14,6 @@
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.components.JBScrollPane;
-import com.intellij.ui.components.JBTabbedPane;
import com.intellij.ui.components.JBTextField;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.ui.JBUI;
@@ -25,7 +23,6 @@
import utils.TemplateUtil;
import javax.swing.*;
-import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
@@ -40,19 +37,16 @@ public class DocumentFilterDialog extends DialogWrapper {
private final String scope;
private final Tree tree;
private final DefaultMutableTreeNode clickedNode;
+ private final boolean hasIndex;
private EditorEx editor;
private JLabel resultsLabel;
private JLabel errorLabel;
-
private JBTextField startingDocumentIdField;
private JBTextField endingDocumentIdField;
private JSpinner offsetField;
-
private JRadioButton queryRadioButton;
private JRadioButton keyValueRadioButton;
-
private QueryFilter queryFilter;
- private final boolean hasIndex;
public DocumentFilterDialog(Tree tree, DefaultMutableTreeNode clickedNode, String bucket, String scope, String collectionName, boolean hasIndex) {
super(false);
@@ -118,10 +112,7 @@ protected JComponent createCenterPanel() {
infoLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
- String content = "Complete the query with filters you would like to apply:
" +
- "
Ex: country =
'United States'" +
- "
- If you don't provide an ORDER BY, the documents will be sorted by the document's id.
" +
- "- Your filter should not include a LIMIT or OFFSET
";
+ String content = "Complete the query with filters you would like to apply:
" + "
Ex: country =
'United States'" + "
- If you don't provide an ORDER BY, the documents will be sorted by the document's id.
" + "- Your filter should not include a LIMIT or OFFSET
";
TemplateUtil.showGotItTooltip(e.getComponent(), content);
}
});
@@ -130,9 +121,8 @@ public void mouseEntered(MouseEvent e) {
queryPanel.add(infoPanel, BorderLayout.NORTH);
JPanel labelPanel = new JPanel(new BorderLayout());
- JLabel label = new JLabel("SELECT" +
- " meta().id FROM `" + collectionName + "` WHERE
");
+ JLabel label = new JLabel(
+ "SELECT" + " meta().id FROM `" + collectionName + "` WHERE
");
label.setBorder(JBUI.Borders.emptyLeft(45));
label.setVerticalAlignment(JLabel.TOP);
labelPanel.add(label, BorderLayout.CENTER);
@@ -149,12 +139,15 @@ public void mouseEntered(MouseEvent e) {
startingDocumentIdField = new JBTextField(20);
endingDocumentIdField = new JBTextField(20);
- offsetField = new JSpinner(new SpinnerNumberModel(queryFilter == null ? 0 : queryFilter.getOffset(), 0, 2147483648L, 1));
+ offsetField = new JSpinner(
+ new SpinnerNumberModel(queryFilter == null ? 0 : queryFilter.getOffset(), 0, 2147483648L, 1));
if (queryFilter != null) {
- startingDocumentIdField.setText(queryFilter.getDocumentStartKey() != null ? queryFilter.getDocumentStartKey() : "");
- endingDocumentIdField.setText(queryFilter.getDocumentEndKey() != null ? queryFilter.getDocumentEndKey() : "");
+ startingDocumentIdField.setText(
+ queryFilter.getDocumentStartKey() != null ? queryFilter.getDocumentStartKey() : "");
+ endingDocumentIdField.setText(
+ queryFilter.getDocumentEndKey() != null ? queryFilter.getDocumentEndKey() : "");
offsetField.setValue(Double.valueOf(queryFilter.getOffset()));
}
@@ -270,9 +263,14 @@ protected JComponent createSouthPanel() {
return;
}
- results = CouchbaseRestAPI.listKVDocuments(bucket, scope, collectionName, ((Double) offsetField.getValue()).intValue(), 10,
- "".equals(startingDocumentIdField.getText().trim()) ? null : startingDocumentIdField.getText().trim(),
- "".equals(endingDocumentIdField.getText().trim()) ? null : endingDocumentIdField.getText().trim()).size();
+ results = CouchbaseRestAPI.listKVDocuments(bucket, scope, collectionName,
+ ((Double) offsetField.getValue()).intValue(), 10,
+ "".equals(startingDocumentIdField.getText()
+ .trim()) ? null : startingDocumentIdField
+ .getText().trim(), "".equals(
+ endingDocumentIdField.getText().trim()) ? null : endingDocumentIdField.getText()
+ .trim())
+ .size();
} else {
if (!validateFilterKeywords(filter)) {
resultsLabel.setText("");
@@ -314,9 +312,13 @@ protected JComponent createSouthPanel() {
return;
}
- CouchbaseRestAPI.listKVDocuments(bucket, scope, collectionName, ((Double) offsetField.getValue()).intValue(), 10,
- "".equals(startingDocumentIdField.getText().trim()) ? null : startingDocumentIdField.getText().trim(),
- "".equals(endingDocumentIdField.getText().trim()) ? null : endingDocumentIdField.getText().trim()).size();
+ CouchbaseRestAPI.listKVDocuments(bucket, scope, collectionName,
+ ((Double) offsetField.getValue()).intValue(), 10, "".equals(
+ startingDocumentIdField.getText().trim()) ? null : startingDocumentIdField.getText()
+ .trim(),
+ "".equals(endingDocumentIdField.getText()
+ .trim()) ? null : endingDocumentIdField
+ .getText().trim()).size();
} else {
String filter = editor.getDocument().getText();
if (!validateFilterKeywords(filter)) {
@@ -347,8 +349,12 @@ protected JComponent createSouthPanel() {
if (keyValueRadioButton.isSelected()) {
queryFilter.setQuery(null);
- queryFilter.setDocumentStartKey(startingDocumentIdField.getText().trim().isEmpty() ? null : startingDocumentIdField.getText().trim());
- queryFilter.setDocumentEndKey(endingDocumentIdField.getText().trim().isEmpty() ? null : endingDocumentIdField.getText().trim());
+ queryFilter.setDocumentStartKey(
+ startingDocumentIdField.getText().trim().isEmpty() ? null : startingDocumentIdField.getText()
+ .trim());
+ queryFilter.setDocumentEndKey(
+ endingDocumentIdField.getText().trim().isEmpty() ? null : endingDocumentIdField.getText()
+ .trim());
queryFilter.setOffset(((Double) offsetField.getValue()).intValue());
} else {
queryFilter.setQuery(editor.getDocument().getText());
@@ -414,25 +420,24 @@ private boolean validateFilterKeywords(String filter) {
}
private boolean validateKVFilters() {
- if (endingDocumentIdField.getText().trim().isEmpty()
- && startingDocumentIdField.getText().trim().isEmpty()
- && ((Double) offsetField.getValue()).intValue() == 0) {
+ if (endingDocumentIdField.getText().trim().isEmpty() && startingDocumentIdField.getText().trim()
+ .isEmpty() && ((Double) offsetField.getValue()).intValue() == 0) {
errorLabel.setText("You must specify at least one filtering value");
return false;
}
+
+ if (((Double) offsetField.getValue()).intValue() > 1000) {
+ errorLabel.setText("The offset should be less than 1000");
+ return false;
+ }
return true;
}
private int validateQueryFilters(String bucket, String scope, String collectionName, String filter) {
- String query = "SELECT * FROM `" + collectionName + "` WHERE "
- + filter
- + (SQLPPQueryUtils.hasOrderBy(filter) ? "" : " ORDER BY meta().id")
- + " LIMIT 10 OFFSET 0";
- return ActiveCluster.getInstance().get()
- .bucket(bucket)
- .scope(scope)
- .query(query).rowsAsObject().size();
+ String query = "SELECT * FROM `" + collectionName + "` WHERE " + filter + (SQLPPQueryUtils.hasOrderBy(
+ filter) ? "" : " ORDER BY meta().id") + " LIMIT 10 OFFSET 0";
+ return ActiveCluster.getInstance().get().bucket(bucket).scope(scope).query(query).rowsAsObject().size();
}
}
diff --git a/src/main/java/com/couchbase/intellij/workbench/FavoriteQueryDialog.java b/src/main/java/com/couchbase/intellij/workbench/FavoriteQueryDialog.java
index 71eabcda..03836f21 100644
--- a/src/main/java/com/couchbase/intellij/workbench/FavoriteQueryDialog.java
+++ b/src/main/java/com/couchbase/intellij/workbench/FavoriteQueryDialog.java
@@ -40,6 +40,7 @@ public class FavoriteQueryDialog extends DialogWrapper {
private final EditorEx editor;
private final EditorEx editorBuiltIn;
private final Document document;
+ private JTabbedPane tabbedPane;
private JEditorPane queryDesc;
@@ -58,11 +59,13 @@ protected FavoriteQueryDialog(Project project, Document document) {
editorSettings.setIndentGuidesShown(false);
final Document builtinDoc = EditorFactory.getInstance().createDocument("");
- editorBuiltIn = (EditorEx) EditorFactory.getInstance().createEditor(builtinDoc, null, SQLPPFileType.INSTANCE, false);
+ editorBuiltIn = (EditorEx) EditorFactory.getInstance().createEditor(builtinDoc, null, SQLPPFileType.INSTANCE,
+ false);
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
- public Component getListCellRendererComponent(JList> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ public Component getListCellRendererComponent(JList> list, Object value, int index, boolean isSelected,
+ boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 5)); // Set left padding
return this;
@@ -83,7 +86,8 @@ public void actionPerformed(ActionEvent e) {
listModel.remove(index);
}
List favList = FavoriteQueryStorage.getInstance().getValue().getList();
- favList = favList.stream().filter(f -> !f.getName().equals(value)).collect(Collectors.toList());
+ favList =
+ favList.stream().filter(f -> !f.getName().equals(value)).collect(Collectors.toList());
FavoriteQueryStorage.getInstance().getValue().setList(favList);
ApplicationManager.getApplication().runWriteAction(() -> editor.getDocument().setText(""));
}
@@ -113,7 +117,9 @@ public void actionPerformed(ActionEvent e) {
FavoriteQueryStorage.getInstance().getValue().getList().forEach(e -> addItem(e.getName()));
try {
- InputStream inputStream = FavoriteQueryDialog.class.getClassLoader().getResourceAsStream("builtinQueries/defaultFavoriteQueries.json");
+ InputStream inputStream =
+ FavoriteQueryDialog.class.getClassLoader().getResourceAsStream("builtinQueries" +
+ "/defaultFavoriteQueries.json");
ObjectMapper objectMapper = new ObjectMapper();
queries = objectMapper.readValue(inputStream, new TypeReference>() {
});
@@ -135,7 +141,8 @@ public void actionPerformed(ActionEvent e) {
builtinList.setCellRenderer(new DefaultListCellRenderer() {
@Override
- public Component getListCellRendererComponent(JList> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ public Component getListCellRendererComponent(JList> list, Object value, int index,
+ boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 5));
return this;
@@ -159,7 +166,7 @@ public void addItem(String item) {
@Override
protected JComponent createCenterPanel() {
- JTabbedPane tabbedPane = new JTabbedPane();
+ tabbedPane = new JTabbedPane();
JPanel yourQueriesPanel = new JPanel(new BorderLayout());
yourQueriesPanel.add(scrollPane, BorderLayout.WEST);
@@ -170,7 +177,8 @@ protected JComponent createCenterPanel() {
HyperlinkLabel hyperlinkLabel = new HyperlinkLabel("Help us to expand this list");
hyperlinkLabel.addHyperlinkListener(e -> {
try {
- Desktop.getDesktop().browse(new URI("https://github.com/couchbaselabs/couchbase_jetbrains_plugin/issues"));
+ Desktop.getDesktop().browse(new URI("https://github.com/couchbaselabs/couchbase_jetbrains_plugin" +
+ "/issues"));
} catch (Exception ex) {
Log.error(ex);
}
@@ -213,9 +221,17 @@ protected JComponent createCenterPanel() {
@Override
protected void doAction(ActionEvent e) {
ApplicationManager.getApplication().runWriteAction(() -> {
- if (!editor.getDocument().getText().isEmpty()) {
- document.setText(editor.getDocument().getText());
- close(0);
+
+ if (tabbedPane.getSelectedIndex() == 1) {
+ if (!editorBuiltIn.getDocument().getText().isEmpty()) {
+ document.setText(editorBuiltIn.getDocument().getText());
+ close(0);
+ }
+ } else {
+ if (!editor.getDocument().getText().isEmpty()) {
+ document.setText(editor.getDocument().getText());
+ close(0);
+ }
}
});
}