Skip to content

Commit

Permalink
Merge pull request #203 from couchbaselabs/named_params
Browse files Browse the repository at this point in the history
Adding the Named params support
  • Loading branch information
deniswsrosa authored May 23, 2024
2 parents 4bf94cf + a53ff29 commit ce366f7
Show file tree
Hide file tree
Showing 11 changed files with 611 additions and 168 deletions.
6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/main/java/com/couchbase/intellij/persistence/NamedParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.couchbase.intellij.persistence;

import lombok.Data;

import java.util.Map;

@Data
public class NamedParams {
private Map<String, String> params;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.couchbase.intellij.persistence.storage;

import com.couchbase.intellij.persistence.FavoriteQueries;
import com.couchbase.intellij.persistence.NamedParams;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;

@State(
name = "NamedParamsStorage",
storages = {
@Storage(
value = "named_params.xml"
)
}
)
public class NamedParamsStorage implements PersistentStateComponent<NamedParamsStorage.State> {

private final NamedParamsStorage.State myState = new NamedParamsStorage.State();

public static NamedParamsStorage getInstance() {
return ApplicationManager.getApplication().getService(NamedParamsStorage.class);
}

@Nullable
@Override
public NamedParamsStorage.State getState() {
return myState;
}

@Override
public void loadState(@NotNull NamedParamsStorage.State state) {
XmlSerializerUtil.copyBean(state, myState);
}

public NamedParams getValue() {
if (myState.namedParams == null) {
myState.namedParams = new NamedParams();
}

if(myState.namedParams.getParams() == null) {
myState.namedParams.setParams(new HashMap<>());
}
return myState.namedParams;
}

public void setValue(NamedParams newValue) {
myState.namedParams = newValue;
}

public static class State {
public NamedParams namedParams = null;

public NamedParams getNamedParams() {
return namedParams;
}

public void setNamedParams(NamedParams namedParams) {
this.namedParams = namedParams;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,15 @@ public void actionPerformed(@NotNull AnActionEvent e) {
ActionToolbar favToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.TOOLBAR, favoriteActionGroup, true);
favToolbar.setTargetComponent(panel);

favoriteActionGroup.add(new AnAction("Named Parameters", "Named parameters",
IconLoader.getIcon("/assets/icons/named_param.svg", CustomSqlFileEditor.class)) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
NamedParameterDialog dialog = new NamedParameterDialog(project);
dialog.show();
}
});

favoriteActionGroup.add(new AnAction("Favorite Query", "Favorite query", IconLoader.getIcon("/assets/icons/star-empty.svg", CustomSqlFileEditor.class)) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Expand All @@ -348,7 +357,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
});

favoriteActionGroup.addSeparator();
favoriteActionGroup.add(new AnAction("Query Options", "Query Options", IconLoader.getIcon("/assets/icons/gear.svg", CustomSqlFileEditor.class)) {
favoriteActionGroup.add(new AnAction("Query Options", "Query options", IconLoader.getIcon("/assets/icons/gear.svg", CustomSqlFileEditor.class)) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
if (ActiveCluster.getInstance().getCluster() != null) {
Expand Down
Loading

0 comments on commit ce366f7

Please sign in to comment.