Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing deprecated methods #184

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 */))
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
94 changes: 27 additions & 67 deletions src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IQWindowContent> getInstance() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -163,8 +162,7 @@ public final void expand() {
content.cancel(onHide);
popup = null;
return true;
}
catch (Exception ignore) {
} catch (Exception ignore) {
return false;
}
}).createPopup();
Expand Down Expand Up @@ -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();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Icon>) null);
}

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

Expand Down
Loading