Skip to content

Commit

Permalink
implemented 'add helm repo' (redhat-developer#673)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Apr 18, 2024
1 parent 9b79403 commit 71e1fa0
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.openshift.actions.helm;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jboss.tools.intellij.openshift.actions.HelmAction;
import org.jboss.tools.intellij.openshift.actions.NodeUtils;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.tree.application.NamespaceNode;
import org.jboss.tools.intellij.openshift.ui.helm.AddHelmRepoDialog;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jetbrains.annotations.NotNull;

public class AddHelmRepoAction extends HelmAction {

@Override
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Helm helm) {
Project project = getEventProject(anActionEvent);
ApplicationsRootNode rootNode = NodeUtils.getRoot(selected);
if (rootNode == null) {
return;
}
AddHelmRepoDialog dialog = new AddHelmRepoDialog(rootNode, helm, project);
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
dialog.show();
}

@Override
public String getTelemetryActionName() {
return "helm-add repo";
}

@Override
public boolean isVisible(Object selected) {
return selected instanceof NamespaceNode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jboss.tools.intellij.openshift.actions.HelmAction;
import org.jboss.tools.intellij.openshift.actions.NodeUtils;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.tree.application.NamespaceNode;
import org.jboss.tools.intellij.openshift.tree.application.ParentableNode;
import org.jboss.tools.intellij.openshift.ui.helm.ChartsDialog;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
Expand All @@ -27,11 +27,10 @@ public class OpenHelmChartsAction extends HelmAction {
@Override
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Helm helm) {
Project project = getEventProject(anActionEvent);
ParentableNode<?> parentableNode = ((ParentableNode<?>) selected);
if (parentableNode == null) {
ApplicationsRootNode rootNode = NodeUtils.getRoot(selected);
if (rootNode == null) {
return;
}
ApplicationsRootNode rootNode = parentableNode.getRoot();
Odo odo = rootNode.getOdo().getNow(null);
if (odo == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.openshift.ui.helm;

import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.PopupBorder;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBPanel;
import com.intellij.ui.components.JBTextField;
import net.miginfocom.swing.MigLayout;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.ui.SwingUtils;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
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.util.concurrent.CompletableFuture;

import static org.jboss.tools.intellij.openshift.ui.SwingUtils.EXECUTOR_BACKGROUND;

public class AddHelmRepoDialog extends DialogWrapper {

private static final Logger LOGGER = LoggerFactory.getLogger(AddHelmRepoDialog.class);

private final ApplicationsRootNode rootNode;
private final Helm helm;

public AddHelmRepoDialog(ApplicationsRootNode rootNode, Helm helm, Project project) {
super(project, null, false, IdeModalityType.MODELESS, false);
this.rootNode = rootNode;
this.helm = helm;
init();
}

@Override
protected void init() {
super.init();
setUndecorated(true);
Window dialogWindow = getPeer().getWindow();
setOKButtonText("Add");
JRootPane rootPane = ((RootPaneContainer) dialogWindow).getRootPane();
registerShortcuts(rootPane);
setBorders(rootPane);
SwingUtils.setGlassPaneResizable(getPeer().getRootPane(), getDisposable());
SwingUtils.setMovable(getRootPane());
}

private static void setBorders(JRootPane rootPane) {
rootPane.setBorder(PopupBorder.Factory.create(true, true));
rootPane.setWindowDecorationStyle(JRootPane.NONE);
}

private void registerShortcuts(JRootPane rootPane) {
AnAction escape = ActionManager.getInstance().getAction("EditorEscape");
DumbAwareAction.create(e -> closeImmediately())
.registerCustomShortcutSet(
escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(),
rootPane,
myDisposable);
}

@Override
protected @Nullable JComponent createCenterPanel() {
JBPanel<?> panel = new JBPanel<>(new MigLayout(
"flowx, ins 0, gap 0, fillx, filly, hidemode 3",
"[left][fill]"));

JBLabel name = new JBLabel("Name:");
panel.add(name);

JBTextField nameText = new JBTextField();
panel.add(nameText);

IdeFocusManager.getInstance(null).requestFocus(nameText, true);

return panel;
}

private CompletableFuture<Void> addRepo(String name, String url, Helm helm) {
return CompletableFuture
.runAsync(() -> {
try {
helm.addRepo(name, url);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}, EXECUTOR_BACKGROUND);
}

private void closeImmediately() {
if (isVisible()) {
doCancelAction();
}
}

@Override
protected void doOKAction() {
super.doOKAction();
}

}

0 comments on commit 71e1fa0

Please sign in to comment.