diff --git a/src/main/java/com/couchbase/intellij/database/ActiveCluster.java b/src/main/java/com/couchbase/intellij/database/ActiveCluster.java index 47af8292..277cda5a 100644 --- a/src/main/java/com/couchbase/intellij/database/ActiveCluster.java +++ b/src/main/java/com/couchbase/intellij/database/ActiveCluster.java @@ -13,8 +13,8 @@ import com.couchbase.intellij.utils.Subscribable; import com.couchbase.intellij.workbench.Log; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.ui.Messages; import com.intellij.ui.ColorUtil; @@ -126,7 +126,7 @@ public void connect(SavedCluster savedCluster, Consumer connectListen disconnect(); } - new Task.ConditionalModal(null, "Connecting to Couchbase cluster '" + savedCluster.getId() + "'", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + ProgressManager.getInstance().run(new Task.Backgroundable(null, "Connecting to Couchbase cluster '" + savedCluster.getId() + "'", true) { @Override public void run(@NotNull ProgressIndicator indicator) { try { @@ -234,7 +234,7 @@ public void run(@NotNull ProgressIndicator indicator) { } } } - }.queue(); + }); } public void disconnect() { @@ -370,7 +370,8 @@ private void scheduleSchemaUpdate(Consumer onComplete) { } if (!schemaUpdating.get() && System.currentTimeMillis() - lastSchemaUpdate > 60000) { schemaUpdating.set(true); - new Task.ConditionalModal(null, "Reading Couchbase cluster schema", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(null, "Reading Couchbase cluster schema", true) { @Override public void run(@NotNull ProgressIndicator indicator) { try { @@ -387,7 +388,7 @@ public void run(@NotNull ProgressIndicator indicator) { disconnect(); } } - }.queue(); + }); } } diff --git a/src/main/java/com/couchbase/intellij/database/DataLoader.java b/src/main/java/com/couchbase/intellij/database/DataLoader.java index 432aabe2..fccb7b17 100644 --- a/src/main/java/com/couchbase/intellij/database/DataLoader.java +++ b/src/main/java/com/couchbase/intellij/database/DataLoader.java @@ -32,8 +32,8 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.UserBinaryFileType; -import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -402,7 +402,8 @@ public static void showSchema(DefaultMutableTreeNode parentNode, DefaultTreeMode String scopeName = colNode.getScope(); String bucketName = colNode.getBucket(); - new Task.ConditionalModal(null, String.format("Running INFER for collection %s.%s.%s", bucketName, scopeName, collectionName), true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + ProgressManager.getInstance().run(new Task.Backgroundable(null, String.format("Running INFER for collection %s.%s.%s", bucketName, scopeName, collectionName), false) { + @Override public void run(@NotNull ProgressIndicator indicator) { JsonObject inferenceQueryResults = InferHelper.inferSchema(collectionName, scopeName, bucketName); @@ -417,7 +418,7 @@ public void run(@NotNull ProgressIndicator indicator) { treeModel.nodeStructureChanged(parentNode); }); } - }.queue(); + }); } catch (Exception e) { Log.error(e); e.printStackTrace(); diff --git a/src/main/java/com/couchbase/intellij/database/entity/CouchbaseCollection.java b/src/main/java/com/couchbase/intellij/database/entity/CouchbaseCollection.java index f8b59ba1..04bbe8a3 100644 --- a/src/main/java/com/couchbase/intellij/database/entity/CouchbaseCollection.java +++ b/src/main/java/com/couchbase/intellij/database/entity/CouchbaseCollection.java @@ -6,8 +6,8 @@ import com.couchbase.client.java.manager.collection.CollectionSpec; import com.couchbase.intellij.database.InferHelper; import com.couchbase.intellij.workbench.Log; -import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import org.jetbrains.annotations.NotNull; @@ -51,7 +51,8 @@ public void updateSchema() { loadSchema(getSavedCluster().getInferCacheValue(path)); } else { updating.set(true); - new Task.ConditionalModal(null, "Running INFER for collection " + path, true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(null, "Running INFER for collection " + path, true) { @Override public void run(@NotNull ProgressIndicator indicator) { try { @@ -67,7 +68,7 @@ public void run(@NotNull ProgressIndicator indicator) { updating.set(false); } } - }.queue(); + }); } } diff --git a/src/main/java/com/couchbase/intellij/persistence/storage/ClustersStorage.java b/src/main/java/com/couchbase/intellij/persistence/storage/ClustersStorage.java index ab646ff4..289f62a2 100644 --- a/src/main/java/com/couchbase/intellij/persistence/storage/ClustersStorage.java +++ b/src/main/java/com/couchbase/intellij/persistence/storage/ClustersStorage.java @@ -7,8 +7,8 @@ import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; -import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.util.xmlb.XmlSerializerUtil; import org.jetbrains.annotations.NotNull; @@ -43,7 +43,8 @@ public ClustersStorage.State getState() { @Override public void loadState(@NotNull ClustersStorage.State state) { XmlSerializerUtil.copyBean(state, myState); - new Task.ConditionalModal(null, "Cleaning up stale cache entries...", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(null, "Cleaning up stale cache entries...", true) { @Override public void run(@NotNull ProgressIndicator indicator) { @@ -52,7 +53,7 @@ public void run(@NotNull ProgressIndicator indicator) { myState.clusters.getInferCacheUpdateTimes().entrySet().stream() .filter(entry -> { - if(myState.clusters.getMap() == null) { + if (myState.clusters.getMap() == null) { return false; } if (!myState.clusters.getMap().containsKey(entry.getKey())) { @@ -62,29 +63,29 @@ public void run(@NotNull ProgressIndicator indicator) { } return true; }) - .filter(e-> e.getValue() !=null) + .filter(e -> e.getValue() != null) .peek(utimes -> { utimes.setValue(utimes.getValue().entrySet().stream() - .filter(Objects::nonNull) - .filter(utime -> utime.getValue() != null) - .filter(utime -> { - SavedCluster savedCluster = myState.clusters.getMap().get(utimes.getKey()); - if (savedCluster != null) { - if (System.currentTimeMillis() - utime.getValue() < savedCluster.getInferCachePeriod()) { - return true; - } - } - savedCluster.getInferCacheValues().remove(utime.getKey()); - Log.debug("Removing stale cache for " + utime.getKey() + " on cluster " + utimes.getKey()); - return false; - }) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) + .filter(Objects::nonNull) + .filter(utime -> utime.getValue() != null) + .filter(utime -> { + SavedCluster savedCluster = myState.clusters.getMap().get(utimes.getKey()); + if (savedCluster != null) { + if (System.currentTimeMillis() - utime.getValue() < savedCluster.getInferCachePeriod()) { + return true; + } + } + savedCluster.getInferCacheValues().remove(utime.getKey()); + Log.debug("Removing stale cache for " + utime.getKey() + " on cluster " + utimes.getKey()); + return false; + }) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) ); }) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) ); } - }.queue(); + }); } public Clusters getValue() { diff --git a/src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java b/src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java index ac2606b8..37362f29 100644 --- a/src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java +++ b/src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java @@ -157,10 +157,9 @@ public void actionPerformed(@NotNull AnActionEvent e) { ActionToolbar rightActionToolbar = ActionManager.getInstance().createActionToolbar("MoreOptions", rightActionGroup, true); rightActionToolbar.setTargetComponent(toolBarPanel); toolBarPanel.add(rightActionToolbar.getComponent(), BorderLayout.EAST); - ActiveCluster.getInstance().registerNewConnectionListener(() -> { ApplicationManager.getApplication().invokeLater(() -> { - leftActionToolbar.updateActionsImmediately(); + leftActionToolbar.getComponent().revalidate(); toolBarPanel.revalidate(); }); }); diff --git a/src/main/java/com/couchbase/intellij/tree/cblite/CBLWindowContent.java b/src/main/java/com/couchbase/intellij/tree/cblite/CBLWindowContent.java index fbf723f6..070f8edd 100644 --- a/src/main/java/com/couchbase/intellij/tree/cblite/CBLWindowContent.java +++ b/src/main/java/com/couchbase/intellij/tree/cblite/CBLWindowContent.java @@ -16,8 +16,8 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -233,8 +233,8 @@ public void actionPerformed(@NotNull AnActionEvent e) { ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage("You need to connect to a database before running this task", "Couchbase Plugin")); return; } - new Task.ConditionalModal(project, String.format("Running Database Optimize for ", - ActiveCBLDatabase.getInstance().getDatabase().getName()), false, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + ProgressManager.getInstance().run(new Task.Backgroundable(project, String.format("Running Database Optimize for ", + ActiveCBLDatabase.getInstance().getDatabase().getName()), false) { @Override public void run(@NotNull ProgressIndicator indicator) { try { @@ -244,7 +244,7 @@ public void run(@NotNull ProgressIndicator indicator) { Log.error(ex); } } - }.queue(); + }); } }; @@ -259,8 +259,9 @@ public void actionPerformed(@NotNull AnActionEvent e) { ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage("You need to connect to a database before running this task", "Couchbase Plugin")); return; } - new Task.ConditionalModal(project, String.format("Running Database Full Optimize for ", - ActiveCBLDatabase.getInstance().getDatabase().getName()), false, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(project, String.format("Running Database Full Optimize for ", + ActiveCBLDatabase.getInstance().getDatabase().getName()), false) { @Override public void run(@NotNull ProgressIndicator indicator) { try { @@ -269,7 +270,7 @@ public void run(@NotNull ProgressIndicator indicator) { Log.error(ex); } } - }.queue(); + }); } }; @@ -284,8 +285,9 @@ public void actionPerformed(@NotNull AnActionEvent e) { ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage("You need to connect to a database before running this task", "Couchbase Plugin")); return; } - new Task.ConditionalModal(project, String.format("Running Database Compact for ", - ActiveCBLDatabase.getInstance().getDatabase().getName()), false, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(project, String.format("Running Database Compact for ", + ActiveCBLDatabase.getInstance().getDatabase().getName()), false) { @Override public void run(@NotNull ProgressIndicator indicator) { try { @@ -294,7 +296,7 @@ public void run(@NotNull ProgressIndicator indicator) { Log.error(ex); } } - }.queue(); + }); } }; @@ -308,8 +310,9 @@ public void actionPerformed(@NotNull AnActionEvent e) { ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage("You need to connect to a database before running this task", "Couchbase Plugin")); return; } - new Task.ConditionalModal(project, String.format("Running Database Integrity Check for ", - ActiveCBLDatabase.getInstance().getDatabase().getName()), false, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(project, String.format("Running Database Integrity Check for ", + ActiveCBLDatabase.getInstance().getDatabase().getName()), false) { @Override public void run(@NotNull ProgressIndicator indicator) { try { @@ -318,7 +321,7 @@ public void run(@NotNull ProgressIndicator indicator) { Log.error(ex); } } - }.queue(); + }); } }; diff --git a/src/main/java/com/couchbase/intellij/tree/cblite/sqlppl/SQLPPLiteFileEditor.java b/src/main/java/com/couchbase/intellij/tree/cblite/sqlppl/SQLPPLiteFileEditor.java index 141f2269..41767257 100644 --- a/src/main/java/com/couchbase/intellij/tree/cblite/sqlppl/SQLPPLiteFileEditor.java +++ b/src/main/java/com/couchbase/intellij/tree/cblite/sqlppl/SQLPPLiteFileEditor.java @@ -12,8 +12,8 @@ import com.intellij.openapi.fileEditor.*; import com.intellij.openapi.fileEditor.impl.LoadTextUtil; import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider; -import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.IconLoader; @@ -94,12 +94,13 @@ private void buildToolbar() { executeAction = new AnAction("Execute", "Execute the query statement in the editor", executeIcon) { @Override public void actionPerformed(@NotNull AnActionEvent e) { - new Task.ConditionalModal(null, "Running SQL++ Lite query", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(project, "Running SQL++ Lite query", true) { @Override public void run(@NotNull ProgressIndicator indicator) { SQLLiteQueryExecutor.runQuery(queryEditor.getDocument().getText(), 0, project); } - }.queue(); + }); } }; diff --git a/src/main/java/com/couchbase/intellij/tree/iq/ui/view/RSyntaxTextAreaView.java b/src/main/java/com/couchbase/intellij/tree/iq/ui/view/RSyntaxTextAreaView.java index f566ce42..8d58975a 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/ui/view/RSyntaxTextAreaView.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/ui/view/RSyntaxTextAreaView.java @@ -21,8 +21,8 @@ import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.ide.CopyPasteManager; -import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; @@ -326,7 +326,8 @@ public void actionPerformed(@NotNull AnActionEvent e) { .map(String::trim) .filter(s -> s != null && s.length() > 0) .collect(Collectors.toList()); - new Task.ConditionalModal(null, "Running SQL++ query", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(project, "Running SQL++ query", true) { @Override public void run(@NotNull ProgressIndicator indicator) { ApplicationManager.getApplication().invokeLater(() -> { @@ -337,7 +338,7 @@ public void run(@NotNull ProgressIndicator indicator) { } }); } - }.queue(); + }); } }, () -> { Notifications.Bus.notify( diff --git a/src/main/java/com/couchbase/intellij/workbench/CustomSqlFileEditor.java b/src/main/java/com/couchbase/intellij/workbench/CustomSqlFileEditor.java index f91b9969..20fb52a9 100644 --- a/src/main/java/com/couchbase/intellij/workbench/CustomSqlFileEditor.java +++ b/src/main/java/com/couchbase/intellij/workbench/CustomSqlFileEditor.java @@ -19,8 +19,8 @@ import com.intellij.openapi.fileEditor.*; import com.intellij.openapi.fileEditor.impl.LoadTextUtil; import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider; -import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -174,7 +174,8 @@ public void actionPerformed(@NotNull AnActionEvent e) { isExecutingQuery = true; List statements = getStatements(); - new Task.ConditionalModal(null, "Running SQL++ query", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) { + + ProgressManager.getInstance().run(new Task.Backgroundable(project, "Running SQL++ query", true) { @Override public void run(@NotNull ProgressIndicator indicator) { @@ -208,7 +209,7 @@ public void run(@NotNull ProgressIndicator indicator) { isExecutingQuery = false; }); } - }.queue(); + }); } } };