Skip to content

Commit

Permalink
fixing deprected methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Rosa authored and Denis Rosa committed Mar 20, 2024
1 parent 4dc11d6 commit fccf5e9
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 54 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/couchbase/intellij/database/ActiveCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,7 +126,7 @@ public void connect(SavedCluster savedCluster, Consumer<Exception> 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 {
Expand Down Expand Up @@ -234,7 +234,7 @@ public void run(@NotNull ProgressIndicator indicator) {
}
}
}
}.queue();
});
}

public void disconnect() {
Expand Down Expand Up @@ -370,7 +370,8 @@ private void scheduleSchemaUpdate(Consumer<Exception> 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 {
Expand All @@ -387,7 +388,7 @@ public void run(@NotNull ProgressIndicator indicator) {
disconnect();
}
}
}.queue();
});
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/couchbase/intellij/database/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -417,7 +418,7 @@ public void run(@NotNull ProgressIndicator indicator) {
treeModel.nodeStructureChanged(parentNode);
});
}
}.queue();
});
} catch (Exception e) {
Log.error(e);
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -67,7 +68,7 @@ public void run(@NotNull ProgressIndicator indicator) {
updating.set(false);
}
}
}.queue();
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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())) {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -244,7 +244,7 @@ public void run(@NotNull ProgressIndicator indicator) {
Log.error(ex);
}
}
}.queue();
});
}
};

Expand All @@ -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 {
Expand All @@ -269,7 +270,7 @@ public void run(@NotNull ProgressIndicator indicator) {
Log.error(ex);
}
}
}.queue();
});
}
};

Expand All @@ -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 {
Expand All @@ -294,7 +296,7 @@ public void run(@NotNull ProgressIndicator indicator) {
Log.error(ex);
}
}
}.queue();
});
}
};

Expand All @@ -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 {
Expand All @@ -318,7 +321,7 @@ public void run(@NotNull ProgressIndicator indicator) {
Log.error(ex);
}
}
}.queue();
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() -> {
Expand All @@ -337,7 +338,7 @@ public void run(@NotNull ProgressIndicator indicator) {
}
});
}
}.queue();
});
}
}, () -> {
Notifications.Bus.notify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -174,7 +174,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
isExecutingQuery = true;

List<String> 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) {

Expand Down Expand Up @@ -208,7 +209,7 @@ public void run(@NotNull ProgressIndicator indicator) {
isExecutingQuery = false;
});
}
}.queue();
});
}
}
};
Expand Down

0 comments on commit fccf5e9

Please sign in to comment.