Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 7cfb668

Browse files
committed
namespace/project in 'Change Project' action and dialog (#701)
Signed-off-by: Andre Dietisheim <[email protected]> Signed-off-by: Stephane Bouchet <[email protected]>
1 parent 5f64e97 commit 7cfb668

File tree

7 files changed

+70
-31
lines changed

7 files changed

+70
-31
lines changed

src/main/java/org/jboss/tools/intellij/openshift/actions/project/ChangeActiveProjectAction.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ public static void execute(ParentableNode<?> node) {
5656
action.doActionPerformed(rootNode, location, odo, project);
5757
}
5858

59+
@Override
60+
public void update(AnActionEvent e) {
61+
super.update(e);
62+
if (e.getPresentation().isVisible()) {
63+
Odo odo = getOdo(e);
64+
if (odo == null) {
65+
return;
66+
}
67+
// overrides label given in plugin.xml
68+
e.getPresentation().setText("Change " + odo.getNamespaceKind());
69+
}
70+
}
71+
5972
@Override
6073
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Odo odo) {
6174
Project project = getEventProject(anActionEvent);
@@ -71,7 +84,9 @@ private void doActionPerformed(final ApplicationsRootNode rootNode, final Point
7184
try {
7285
return new ClusterProjects(odo.isOpenShift(), odo.getCurrentNamespace(), odo.getNamespaces());
7386
} catch (IOException e) {
74-
NotificationUtils.notifyError("Change Active Project", "Could not get projects: " + e.getMessage());
87+
NotificationUtils.notifyError(
88+
"Change Active " + odo.getNamespaceKind(),
89+
"Could not get " + odo.getNamespaceKind().toLowerCase() + ": " + e.getMessage());
7590
sendTelemetryError(e.getMessage());
7691
throw new RuntimeException(e);
7792
}
@@ -80,7 +95,7 @@ private void doActionPerformed(final ApplicationsRootNode rootNode, final Point
8095
if (error != null) {
8196
return null;
8297
}
83-
ChangeActiveProjectDialog dialog = openActiveProjectDialog(clusterProjects.isOpenShift, clusterProjects.current, clusterProjects.all, location, project);
98+
ChangeActiveProjectDialog dialog = openActiveProjectDialog(clusterProjects.current, clusterProjects.all, location, odo, project);
8499
if (dialog.isOK()) {
85100
return new ChangeActiveProjectOperation(dialog.getActiveProject(), odo);
86101
} else if (dialog.isCreateNewProject()) {
@@ -103,9 +118,8 @@ private void doActionPerformed(final ApplicationsRootNode rootNode, final Point
103118
project);
104119
}
105120

106-
private ChangeActiveProjectDialog openActiveProjectDialog(boolean isOpenShift, String currentProject, List<String> allProjects, Point location, Project project) {
107-
String kind = isOpenShift ? "Project" : "Namespace";
108-
ChangeActiveProjectDialog dialog = new ChangeActiveProjectDialog(project, kind, currentProject, allProjects, location);
121+
private ChangeActiveProjectDialog openActiveProjectDialog(String currentProject, List<String> allProjects, Point location, Odo odo, Project project) {
122+
ChangeActiveProjectDialog dialog = new ChangeActiveProjectDialog(project, odo.getNamespaceKind(), currentProject, allProjects, location);
109123
dialog.show();
110124
return dialog;
111125
}
@@ -146,12 +160,17 @@ private ChangeActiveProjectOperation(String activeProject, Odo odo) {
146160

147161
@Override
148162
public void run() {
163+
String kind = odo.getNamespaceKind();
149164
try {
150165
odo.setProject(activeProject);
151-
NotificationUtils.notifyInformation("Change active project", "Active project set to '" + activeProject + "'");
166+
NotificationUtils.notifyInformation(
167+
"Change active " + kind,
168+
"Active " + kind.toLowerCase() + " set to '" + activeProject + "'");
152169
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
153170
} catch (IOException e) {
154-
NotificationUtils.notifyError("Change active project", "Could not set active project: " + e.getMessage());
171+
NotificationUtils.notifyError(
172+
"Change active " + kind.toLowerCase(),
173+
"Could not set active " + kind.toLowerCase() + ": " + e.getMessage());
155174
throw new RuntimeException(e);
156175
}
157176
}

src/main/java/org/jboss/tools/intellij/openshift/actions/project/CreateProjectAction.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public class CreateProjectAction extends LoggedInClusterAction {
4242

4343
private static final Logger LOGGER = LoggerFactory.getLogger(CreateProjectAction.class);
4444

45+
public static void execute(ApplicationsRootNode rootNode) {
46+
Odo odo = rootNode.getOdo().getNow(null);
47+
if (odo == null) {
48+
return;
49+
}
50+
CreateProjectAction action = ActionUtils.createAction(CreateProjectAction.class.getName());
51+
action.doActionPerformed(null, odo, rootNode.getProject());
52+
}
53+
4554
@Override
4655
public void update(AnActionEvent e) {
4756
super.update(e);
@@ -51,7 +60,7 @@ public void update(AnActionEvent e) {
5160
return;
5261
}
5362
// overrides label given in plugin.xml
54-
e.getPresentation().setText("New " + getKind(odo));
63+
e.getPresentation().setText("New " + odo.getNamespaceKind());
5564
}
5665
}
5766

@@ -60,23 +69,14 @@ public String getTelemetryActionName() {
6069
return "create project";
6170
}
6271

63-
public static void execute(ApplicationsRootNode rootNode) {
64-
Odo odo = rootNode.getOdo().getNow(null);
65-
if (odo == null) {
66-
return;
67-
}
68-
CreateProjectAction action = ActionUtils.createAction(CreateProjectAction.class.getName());
69-
action.doActionPerformed(null, odo, rootNode.getProject());
70-
}
71-
7272
@Override
7373
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Odo odo) {
7474
Point location = ActionUtils.getLocation(anActionEvent);
7575
doActionPerformed(location, odo, getEventProject(anActionEvent));
7676
}
7777

7878
private void doActionPerformed(final Point location, @NotNull final Odo odo, Project project) {
79-
String kind = getKind(odo);
79+
String kind = odo.getNamespaceKind();
8080
runWithProgress((ProgressIndicator progress) ->
8181
CompletableFuture
8282
.supplyAsync(() -> {
@@ -113,7 +113,7 @@ private void doActionPerformed(final Point location, @NotNull final Odo odo, Pro
113113
}
114114

115115
private void createProject(String newProject, @NotNull Odo odo) {
116-
String kind = getKind(odo);
116+
String kind = odo.getNamespaceKind();
117117
Notification notification = NotificationUtils.notifyInformation("Create " + kind, "Creating " + kind.toLowerCase() + " newProject");
118118
try {
119119
odo.createProject(newProject);
@@ -150,12 +150,4 @@ private boolean isLoggedIn(Object node) {
150150
private boolean isRoot(Object node) {
151151
return node instanceof ApplicationsRootNode;
152152
}
153-
154-
private String getKind(Odo odo) {
155-
if (odo.isOpenShift()) {
156-
return "Project";
157-
} else {
158-
return "Namespace";
159-
}
160-
}
161153
}

src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationRootNodeOdo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public boolean namespaceExists(String name) {
7373
return delegate.namespaceExists(name);
7474
}
7575

76+
@Override
77+
public String getNamespaceKind() {
78+
return delegate.getNamespaceKind();
79+
}
80+
7681
@Override
7782
public void start(String project, String context, String component, ComponentFeature feature,
7883
Consumer<Boolean> callback, Consumer<Boolean> processTerminatedCallback) throws IOException {

src/main/java/org/jboss/tools/intellij/openshift/tree/application/ChangeActiveProjectLinkNode.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,26 @@
1212

1313
import com.redhat.devtools.intellij.common.tree.LinkElement;
1414
import org.jboss.tools.intellij.openshift.actions.project.ChangeActiveProjectAction;
15+
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
1516

1617
public class ChangeActiveProjectLinkNode extends MessageNode<NamespaceNode> implements LinkElement {
18+
1719
protected ChangeActiveProjectLinkNode(ApplicationsRootNode root, NamespaceNode parent) {
18-
super(root, parent, "Missing project, <a>choose or create a different one</a>");
20+
super(root, parent, getLabel(root));
1921
}
2022

2123
@Override
2224
public void execute() {
2325
ChangeActiveProjectAction.execute(getParent());
2426
}
27+
28+
private static String getLabel(ApplicationsRootNode root) {
29+
Odo odo = root.getOdo().getNow(null);
30+
String label = "Missing %s, <a>choose or create a different one</a>";
31+
if (odo == null) {
32+
return String.format(label, "project/namespace");
33+
} else {
34+
return String.format(label, odo.getNamespaceKind().toLowerCase());
35+
}
36+
}
2537
}

src/main/java/org/jboss/tools/intellij/openshift/ui/project/ChangeActiveProjectDialog.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected void init() {
9292
.installOn(activeProjectTextField)
9393
.andRegisterOnDocumentListener(activeProjectTextField);
9494
activeProjectValidator.revalidate();
95-
JLabel createProjectLabel = new JBLabel("<html>You can <a href=\"\">create a new project</a> instead.</html>");
95+
JLabel createProjectLabel = new JBLabel("<html>You can <a href=\"\">create a new " + kind.toLowerCase() + "</a> instead.</html>");
9696
createProjectLabel.setBorder(JBUI.Borders.emptyTop(20));
9797
createProjectLabel.addMouseListener(onClicked());
9898
panel.add(createProjectLabel, "spanx");
@@ -146,9 +146,9 @@ public ValidationInfo get() {
146146
private ValidationInfo getValidationInfo(String project) {
147147
ValidationInfo validation = new ValidationInfo("").withOKEnabled();
148148
if (StringUtil.isEmptyOrSpaces(project)) {
149-
validation = new ValidationInfo("Provide active Project").forComponent(activeProjectTextField).asWarning();
149+
validation = new ValidationInfo("Provide active " + kind).forComponent(activeProjectTextField).asWarning();
150150
} else if (project.equals(currentProject)) {
151-
validation = new ValidationInfo("Choose different Project").forComponent(activeProjectTextField).asWarning();
151+
validation = new ValidationInfo("Choose different " + kind).forComponent(activeProjectTextField).asWarning();
152152
}
153153
return validation;
154154
}

src/main/java/org/jboss/tools/intellij/openshift/utils/odo/Odo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public interface Odo {
3131

3232
boolean namespaceExists(String name);
3333

34+
String getNamespaceKind();
35+
3436
void start(String project, String context, String component, ComponentFeature feature, Consumer<Boolean> callback, Consumer<Boolean> processTerminatedCallback) throws IOException;
3537

3638
void stop(String project, String context, String component, ComponentFeature feature) throws IOException;

src/main/java/org/jboss/tools/intellij/openshift/utils/odo/OdoCli.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ public boolean namespaceExists(String name) {
327327
}
328328
}
329329

330+
@Override
331+
public String getNamespaceKind() {
332+
if (isOpenShift()) {
333+
return "Project";
334+
} else {
335+
return "Namespace";
336+
}
337+
}
338+
330339
private static String execute(@NotNull File workingDirectory, String command, Map<String, String> envs, String... args) throws IOException {
331340
ExecHelper.ExecResult output = ExecHelper.executeWithResult(command, true, workingDirectory, envs, args);
332341
try (BufferedReader reader = new BufferedReader(new StringReader(output.getStdOut()))) {

0 commit comments

Comments
 (0)