From 409349a6ed937500af5828787fabaf02218deb1a Mon Sep 17 00:00:00 2001 From: Denis Rosa Date: Wed, 20 Mar 2024 07:34:02 +0100 Subject: [PATCH] fixing deprecated methods --- build.gradle.kts | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../intellij/tree/iq/CapellaApiMethods.java | 3 +- .../intellij/tree/iq/IQWindowContent.java | 94 ++++++------------- .../tree/iq/ui/ExpandableSupportExt.java | 8 +- .../action/editor/AbstractEditorAction.java | 2 +- .../tree/overview/SidePanelCountLabel.java | 4 +- .../QueryResultToolWindowFactory.java | 4 +- 8 files changed, 39 insertions(+), 82 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3dae26f1..a30eae7f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("java") - id("org.jetbrains.intellij") version "1.15.0" + id("org.jetbrains.intellij") version "1.17.2" } group = "com.couchbase" @@ -61,7 +61,7 @@ dependencies { // Configure Gradle IntelliJ Plugin // Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html intellij { - version.set("2023.1.5") + version.set("2023.3.5") type.set("IC") // Target IDE Platform plugins.set(listOf(/* Plugin Dependencies */)) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f398c33c..3499ded5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/couchbase/intellij/tree/iq/CapellaApiMethods.java b/src/main/java/com/couchbase/intellij/tree/iq/CapellaApiMethods.java index b97ed3c0..3a436e1f 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/CapellaApiMethods.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/CapellaApiMethods.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Base64; public class CapellaApiMethods { @@ -67,7 +68,7 @@ public static CapellaOrganizationList loadOrganizations(CapellaAuth auth) throws } - String result = IOUtils.toString(connection.getInputStream()); + String result = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8); ObjectMapper objectMapper = new ObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); CapellaOrganizationList resultList = objectMapper.readValue(result, CapellaOrganizationList.class); diff --git a/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java b/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java index 186272ea..8807d90f 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java @@ -12,17 +12,19 @@ import com.intellij.notification.Notification; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; +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 org.apache.commons.io.IOUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.swing.*; import java.awt.*; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; @@ -42,15 +44,21 @@ public IQWindowContent(@NotNull Project project) { setLayout(new GridBagLayout()); this.project = project; instance.set(this); - // SQLPP highlighter in response code blocks marked as ```sqlpp -// AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance(); -// atmf.putMapping("text/sqlpp", SqlppTokenMaker.class.getCanonicalName()); +// // SQLPP highlighter in response code blocks marked as ```sqlpp +//// AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance(); +//// atmf.putMapping("text/sqlpp", SqlppTokenMaker.class.getCanonicalName()); +// +// if (!credentials.getCredentials().isEmpty() && credentials.checkAuthStatus()) { +// onLogin(credentials); +// } else { + + ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading iQ Credentials", false) { + @Override + public void run(@NotNull ProgressIndicator indicator) { + onLogout(null); + } + }); - if (!credentials.getCredentials().isEmpty() && credentials.checkAuthStatus()) { - onLogin(credentials); - } else { - onLogout(null); - } } public static Optional getInstance() { @@ -78,14 +86,7 @@ public void onLogin(IQCredentials credentials) { try { this.organizationList = CapellaApiMethods.loadOrganizations(credentials.getAuth()); if (organizationList.getData().isEmpty()) { - Notifications.Bus.notify( - new Notification( - ChatGptBundle.message("group.id"), - "No Capella organizations found", - "At least one organization is required to use Couchbase IQ. No organizations found.", - NotificationType.ERROR - ) - ); + Notifications.Bus.notify(new Notification(ChatGptBundle.message("group.id"), "No Capella organizations found", "At least one organization is required to use Couchbase IQ. No organizations found.", NotificationType.ERROR)); onLogout(null); return; } @@ -94,43 +95,21 @@ public void onLogin(IQCredentials credentials) { this.organizationList = this.organizationList.getOnlyIqEnabledOrgs(); } - CapellaOrganization activeOrg = organizationList.getData().stream() - .map(org -> org.getData()) - .filter(data -> credentials.checkIqIsEnabled(data.getId())) - .filter(data -> credentials.checkTermsAccepted(data.getId())) - .findFirst().orElse(null); + CapellaOrganization activeOrg = organizationList.getData().stream().map(org -> org.getData()).filter(data -> credentials.checkIqIsEnabled(data.getId())).filter(data -> credentials.checkTermsAccepted(data.getId())).findFirst().orElse(null); String orgId = IQStorage.getInstance().getState().getActiveOrganization(); if (orgId != null) { - activeOrg = organizationList.getData().stream() - .filter(org -> orgId.equalsIgnoreCase(org.getData().getId())) - .map(CapellaOrganizationList.Entry::getData) - .findFirst() - .orElse(activeOrg); + activeOrg = organizationList.getData().stream().filter(org -> orgId.equalsIgnoreCase(org.getData().getId())).map(CapellaOrganizationList.Entry::getData).findFirst().orElse(activeOrg); } if (activeOrg == null) { - Notifications.Bus.notify( - new Notification( - ChatGptBundle.message("group.id"), - "No Capella organizations with iQ enabled found", - "At least one organization with enabled iQ feature and accepted terms and conditions is required to use Couchbase IQ. No organizations found.", - NotificationType.ERROR - ) - ); + Notifications.Bus.notify(new Notification(ChatGptBundle.message("group.id"), "No Capella organizations with iQ enabled found", "At least one organization with enabled iQ feature and accepted terms and conditions is required to use Couchbase IQ. No organizations found.", NotificationType.ERROR)); onLogout(null); } else { this.onOrgSelected(activeOrg); } } catch (Exception e) { Log.error("Failed to initialize IQ", e); - Notifications.Bus.notify( - new Notification( - ChatGptBundle.message("group.id"), - "Something went wrong while trying to login into Capella", - "Failed to login, please try again later", - NotificationType.ERROR - ) - ); + Notifications.Bus.notify(new Notification(ChatGptBundle.message("group.id"), "Something went wrong while trying to login into Capella", "Failed to login, please try again later", NotificationType.ERROR)); onLogout(e); } } @@ -146,27 +125,13 @@ public boolean onLogout(@Nullable Throwable reason) { @Override public void onOrgSelected(CapellaOrganization organization) { if (!credentials.checkIqIsEnabled(organization.getId())) { - Notifications.Bus.notify( - new Notification( - ChatGptBundle.message("group.id"), - "Unable to use this organization", - "Capella iQ is not enabled for this organization.", - NotificationType.ERROR - ) - ); + Notifications.Bus.notify(new Notification(ChatGptBundle.message("group.id"), "Unable to use this organization", "Capella iQ is not enabled for this organization.", NotificationType.ERROR)); onLogout(null); return; } if (!credentials.checkTermsAccepted(organization.getId())) { - Notifications.Bus.notify( - new Notification( - ChatGptBundle.message("group.id"), - "Unable to use this organization", - "Capella iQ terms of use have not been accepted for this organization. Please accept terms of use in Capella", - NotificationType.ERROR - ) - ); + Notifications.Bus.notify(new Notification(ChatGptBundle.message("group.id"), "Unable to use this organization", "Capella iQ terms of use have not been accepted for this organization. Please accept terms of use in Capella", NotificationType.ERROR)); onLogout(null); return; } @@ -194,13 +159,8 @@ public static String systemPrompt() { try { if (cachedPrompt == null) { InputStream is = IQWindowContent.class.getResourceAsStream("/iq/intent_prompt.txt"); - cachedPrompt = IOUtils.toString(is); - String collections = ActiveCluster.getInstance().getChildren().stream() - .flatMap(b -> b.getChildren().stream()) - .flatMap(s -> s.getChildren().stream()) - .map(c -> c.getName()) - .distinct() - .collect(Collectors.joining(", ")); + cachedPrompt = IOUtils.toString(is, StandardCharsets.UTF_8); + String collections = ActiveCluster.getInstance().getChildren().stream().flatMap(b -> b.getChildren().stream()).flatMap(s -> s.getChildren().stream()).map(c -> c.getName()).distinct().collect(Collectors.joining(", ")); cachedPrompt = cachedPrompt.replaceAll("\\$\\{collections\\}", collections); if (ActiveCluster.getInstance() != null) { QueryContext context = ActiveCluster.getInstance().getQueryContext().getValue(); diff --git a/src/main/java/com/couchbase/intellij/tree/iq/ui/ExpandableSupportExt.java b/src/main/java/com/couchbase/intellij/tree/iq/ui/ExpandableSupportExt.java index 3b06de87..165cc3e1 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/ui/ExpandableSupportExt.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/ui/ExpandableSupportExt.java @@ -132,8 +132,7 @@ public final void expand() { int top = location.y - screen.y + source.getHeight(); if (top < bottom) { size.height = bottom; - } - else { + } else { if (size.height > top) size.height = top; location.y -= size.height - source.getHeight(); } @@ -163,8 +162,7 @@ public final void expand() { content.cancel(onHide); popup = null; return true; - } - catch (Exception ignore) { + } catch (Exception ignore) { return false; } }).createPopup(); @@ -207,7 +205,7 @@ public void mouseExited(MouseEvent event) { @Override public void mouseClicked(MouseEvent event) { - Runnable action = extension.getActionOnClick(event); + Runnable action = extension.getActionOnClick(); if (action != null) action.run(); } }); diff --git a/src/main/java/com/couchbase/intellij/tree/iq/ui/action/editor/AbstractEditorAction.java b/src/main/java/com/couchbase/intellij/tree/iq/ui/action/editor/AbstractEditorAction.java index 728a070a..e17cfac6 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/ui/action/editor/AbstractEditorAction.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/ui/action/editor/AbstractEditorAction.java @@ -28,7 +28,7 @@ protected AbstractEditorAction( protected AbstractEditorAction( @NotNull Supplier<@NlsActions.ActionText String> dynamicText, @NotNull Supplier<@NlsActions.ActionText String> dynamicDescription) { - super(dynamicText, dynamicDescription, null); + super(dynamicText, dynamicDescription, (Supplier) null); } @Override diff --git a/src/main/java/com/couchbase/intellij/tree/overview/SidePanelCountLabel.java b/src/main/java/com/couchbase/intellij/tree/overview/SidePanelCountLabel.java index 587ed216..adc7d15d 100644 --- a/src/main/java/com/couchbase/intellij/tree/overview/SidePanelCountLabel.java +++ b/src/main/java/com/couchbase/intellij/tree/overview/SidePanelCountLabel.java @@ -5,7 +5,6 @@ import com.intellij.ui.Gray; import com.intellij.ui.JBColor; import com.intellij.util.ui.GraphicsUtil; -import com.intellij.util.ui.StartupUiUtil; import com.intellij.util.ui.UIUtil; import javax.swing.*; @@ -48,8 +47,9 @@ protected void paintComponent(Graphics g) { g.setColor(isSelected() ? UIUtil.getListSelectionBackground(true) : UIUtil.SIDE_PANEL_BACKGROUND); g.fillRect(0, 0, getWidth(), getHeight()); if (StringUtil.isEmpty(getText())) return; + final JBColor deepBlue = new JBColor(new Color(0x97A4B2), new Color(92, 98, 113)); - g.setColor(isSelected() ? Gray._255.withAlpha(StartupUiUtil.isUnderDarcula() ? 100 : 220) : deepBlue); + g.setColor(isSelected() ? Gray._255.withAlpha(!JBColor.isBright() ? 100 : 220) : deepBlue); final GraphicsConfig config = GraphicsUtil.setupAAPainting(g); g.fillRoundRect(0, 3, getWidth() - 6 - 1, getHeight() - 6, getHeight() - 6, getHeight() - 6); config.restore(); diff --git a/src/main/java/com/couchbase/intellij/workbench/QueryResultToolWindowFactory.java b/src/main/java/com/couchbase/intellij/workbench/QueryResultToolWindowFactory.java index f35f86f1..35a8edb0 100644 --- a/src/main/java/com/couchbase/intellij/workbench/QueryResultToolWindowFactory.java +++ b/src/main/java/com/couchbase/intellij/workbench/QueryResultToolWindowFactory.java @@ -42,7 +42,6 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; -import javax.swing.border.Border; import java.awt.*; import java.awt.event.ActionListener; import java.util.ArrayList; @@ -170,7 +169,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { queryLimitSelector.addActionListener(e -> { Integer limit = null; - if (queryLimitSelector.getSelectedIndex() < QUERY_LIMITS.length -1) { + if (queryLimitSelector.getSelectedIndex() < QUERY_LIMITS.length - 1) { limit = Integer.valueOf(QUERY_LIMITS[queryLimitSelector.getSelectedIndex()]); } ActiveCluster.getInstance().setQueryLimit(limit); @@ -294,7 +293,6 @@ public void actionPerformed(@NotNull AnActionEvent e) { actionGroup.add(clearAction); ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("ConsoleToolbar", actionGroup, true); - actionToolbar.setLayoutPolicy(ActionToolbar.WRAP_LAYOUT_POLICY); JPanel actionPanel = new JPanel(new FlowLayout()); actionPanel.add(actionToolbar.getComponent());