forked from redhat-developer/intellij-openshift-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented 'add helm repo' (redhat-developer#673)
Signed-off-by: Andre Dietisheim <[email protected]>
- Loading branch information
Showing
7 changed files
with
263 additions
and
64 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/main/java/org/jboss/tools/intellij/openshift/UndecoratedDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
import com.intellij.openapi.actionSystem.ActionManager; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
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.impl.IdeGlassPaneEx; | ||
import com.intellij.ui.PopupBorder; | ||
import com.intellij.ui.WindowMoveListener; | ||
import com.intellij.ui.WindowResizeListener; | ||
import com.intellij.util.Consumer; | ||
import com.intellij.util.ui.JBUI; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.util.stream.Stream; | ||
|
||
abstract public class UndecoratedDialog extends DialogWrapper { | ||
|
||
public UndecoratedDialog(@Nullable Project project, | ||
@Nullable Component parentComponent, | ||
boolean canBeParent, | ||
@NotNull IdeModalityType ideModalityType, | ||
boolean createSouth) { | ||
super(project, parentComponent, canBeParent, ideModalityType, createSouth); | ||
init(); | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
super.init(); | ||
setUndecorated(true); | ||
Window dialogWindow = getPeer().getWindow(); | ||
setBorders(); | ||
} | ||
|
||
protected void closeImmediately() { | ||
if (isVisible()) { | ||
doCancelAction(); | ||
} | ||
} | ||
|
||
protected void registerEscapeShortcut(Consumer<AnActionEvent> onEscape) { | ||
AnAction escape = ActionManager.getInstance().getAction("EditorEscape"); | ||
DumbAwareAction.create(onEscape::accept) | ||
.registerCustomShortcutSet( | ||
escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), | ||
getRootPane(), | ||
getDisposable()); | ||
} | ||
|
||
protected void setGlassPaneResizable() { | ||
WindowResizeListener resizeListener = new WindowResizeListener(getRootPane(), JBUI.insets(10), null); | ||
IdeGlassPaneEx glassPane = (IdeGlassPaneEx) getRootPane().getGlassPane(); | ||
glassPane.addMousePreprocessor(resizeListener, getDisposable()); | ||
glassPane.addMouseMotionPreprocessor(resizeListener, getDisposable()); | ||
} | ||
|
||
private void setBorders() { | ||
getRootPane().setBorder(PopupBorder.Factory.create(true, true)); | ||
getRootPane().setWindowDecorationStyle(JRootPane.NONE); | ||
} | ||
|
||
protected void setMovableUsing(JComponent... movableComponents) { | ||
WindowMoveListener windowMoveListener = new WindowMoveListener(getRootPane()); | ||
Stream.of(movableComponents).forEach( | ||
component -> component.addMouseListener(windowMoveListener)); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/org/jboss/tools/intellij/openshift/actions/helm/AddHelmRepoAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.HelmRepositoriesNode; | ||
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 HelmRepositoriesNode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/main/java/org/jboss/tools/intellij/openshift/ui/helm/AddHelmRepoDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/******************************************************************************* | ||
* 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.icons.AllIcons; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.wm.IdeFocusManager; | ||
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.UndecoratedDialog; | ||
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode; | ||
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.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
import java.io.IOException; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static org.jboss.tools.intellij.openshift.ui.SwingUtils.EXECUTOR_BACKGROUND; | ||
import static org.jboss.tools.intellij.openshift.ui.SwingUtils.setBold; | ||
|
||
public class AddHelmRepoDialog extends UndecoratedDialog { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(AddHelmRepoDialog.class); | ||
|
||
private final ApplicationsRootNode rootNode; | ||
private final Helm helm; | ||
private JBLabel title; | ||
|
||
public AddHelmRepoDialog(ApplicationsRootNode rootNode, Helm helm, Project project) { | ||
super(project, null, false, IdeModalityType.MODELESS, true); | ||
this.rootNode = rootNode; | ||
this.helm = helm; | ||
init(); | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
super.init(); | ||
setOKButtonText("Add"); | ||
setGlassPaneResizable(); | ||
setMovableUsing(title); | ||
registerEscapeShortcut(e -> closeImmediately()); | ||
} | ||
|
||
@Override | ||
protected @Nullable JComponent createCenterPanel() { | ||
JBPanel<?> panel = new JBPanel<>(new MigLayout( | ||
"flowx, ins 0, gap 0, fillx, filly, hidemode 3", | ||
"[left][300:pref][right]")); | ||
|
||
this.title = new JBLabel("Add repository"); | ||
setBold(title); | ||
panel.add(title, "spanx 2, gap 0 0 0 16"); | ||
|
||
JBLabel closeIcon = new JBLabel(); | ||
closeIcon.setIcon(AllIcons.Windows.CloseSmall); | ||
closeIcon.addMouseListener(onClose()); | ||
panel.add(closeIcon, "aligny top, wrap"); | ||
|
||
JBLabel name = new JBLabel("Name:"); | ||
panel.add(name); | ||
JBTextField nameText = new JBTextField(); | ||
panel.add(nameText, "growx, spanx 2, wrap"); | ||
|
||
JBLabel url = new JBLabel("URL:"); | ||
panel.add(url); | ||
JBTextField urlText = new JBTextField(); | ||
panel.add(urlText, "growx, spanx 2, wrap"); | ||
|
||
JBLabel flags = new JBLabel("Flags:"); | ||
panel.add(flags); | ||
JBTextField flagsText = new JBTextField(); | ||
panel.add(flagsText, "growx, spanx 2, wrap"); | ||
|
||
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 MouseAdapter onClose() { | ||
return new MouseAdapter() { | ||
@Override | ||
public void mouseReleased(MouseEvent e) { | ||
close(0); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected void doOKAction() { | ||
super.doOKAction(); | ||
} | ||
|
||
} |
Oops, something went wrong.