Skip to content

Commit 540b157

Browse files
authored
Merge pull request #102 from eharris369/101-runRefreshActionsInJob
Issue #101: Run refresh actions in a job
2 parents d1bbc08 + 044d4c8 commit 540b157

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/connection/MicroclimateConnection.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,8 @@ public void refreshApps(String projectID) {
281281

282282
final URI projectsURL = baseUrl.resolve(MCConstants.APIPATH_PROJECT_LIST);
283283

284-
String projectsResponse = null;
285-
try {
286-
projectsResponse = HttpUtil.get(projectsURL).response;
287-
} catch (IOException e) {
288-
MCLogger.logError("Error contacting Projects endpoint", e); //$NON-NLS-1$
289-
return;
290-
}
291-
292284
try {
285+
String projectsResponse = HttpUtil.get(projectsURL).response;
293286
MicroclimateApplicationFactory.getAppsFromProjectsJson(this, projectsResponse, projectID);
294287
MCLogger.log("App list update success"); //$NON-NLS-1$
295288
}

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/RefreshAction.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 IBM Corporation and others.
2+
* Copyright (c) 2018, 2019 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -11,15 +11,21 @@
1111

1212
package com.ibm.microclimate.ui.internal.actions;
1313

14+
import org.eclipse.core.runtime.IProgressMonitor;
15+
import org.eclipse.core.runtime.IStatus;
16+
import org.eclipse.core.runtime.Status;
17+
import org.eclipse.core.runtime.jobs.Job;
1418
import org.eclipse.jface.action.IAction;
1519
import org.eclipse.jface.viewers.ISelection;
1620
import org.eclipse.jface.viewers.IStructuredSelection;
21+
import org.eclipse.osgi.util.NLS;
1722
import org.eclipse.ui.IObjectActionDelegate;
1823
import org.eclipse.ui.IWorkbenchPart;
1924

2025
import com.ibm.microclimate.core.internal.MCLogger;
2126
import com.ibm.microclimate.core.internal.MicroclimateApplication;
2227
import com.ibm.microclimate.core.internal.connection.MicroclimateConnection;
28+
import com.ibm.microclimate.ui.internal.messages.Messages;
2329
import com.ibm.microclimate.ui.internal.views.ViewHelper;
2430

2531
/**
@@ -52,13 +58,27 @@ public void selectionChanged(IAction action, ISelection selection) {
5258
@Override
5359
public void run(IAction action) {
5460
if (microclimateObject instanceof MicroclimateConnection) {
55-
MicroclimateConnection connection = (MicroclimateConnection) microclimateObject;
56-
connection.refreshApps(null);
57-
ViewHelper.refreshMicroclimateExplorerView(connection);
61+
final MicroclimateConnection connection = (MicroclimateConnection) microclimateObject;
62+
Job job = new Job(NLS.bind(Messages.RefreshConnectionJobLabel, connection.baseUrl.toString())) {
63+
@Override
64+
protected IStatus run(IProgressMonitor monitor) {
65+
connection.refreshApps(null);
66+
ViewHelper.refreshMicroclimateExplorerView(connection);
67+
return Status.OK_STATUS;
68+
}
69+
};
70+
job.schedule();
5871
} else if (microclimateObject instanceof MicroclimateApplication) {
59-
MicroclimateApplication app = (MicroclimateApplication) microclimateObject;
60-
app.mcConnection.refreshApps(app.projectID);
61-
ViewHelper.refreshMicroclimateExplorerView(app);
72+
final MicroclimateApplication app = (MicroclimateApplication) microclimateObject;
73+
Job job = new Job(NLS.bind(Messages.RefreshProjectJobLabel, app.name)) {
74+
@Override
75+
protected IStatus run(IProgressMonitor monitor) {
76+
app.mcConnection.refreshApps(app.projectID);
77+
ViewHelper.refreshMicroclimateExplorerView(app);
78+
return Status.OK_STATUS;
79+
}
80+
};
81+
job.schedule();
6282
} else {
6383
// Should not happen
6484
MCLogger.logError("RefreshAction ran but no Microclimate object was selected");

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/messages/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public class Messages extends NLS {
8686
public static String DeleteProjectErrorMsg;
8787
public static String refreshResourceJobLabel;
8888
public static String RefreshResourceError;
89+
public static String RefreshConnectionJobLabel;
90+
public static String RefreshProjectJobLabel;
8991

9092
public static String ImportProjectError;
9193
public static String StartBuildError;

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/messages/messages.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ DeleteProjectErrorTitle=Project Delete Error
7979
DeleteProjectErrorMsg=An error occurred trying to delete Microclimate project {0}: {1}
8080
refreshResourceJobLabel=Refreshing resource: {0}
8181
RefreshResourceError=An error occurred while trying to refresh the {0} resource.
82-
82+
RefreshConnectionJobLabel=Refreshing connection: {0}
83+
RefreshProjectJobLabel=Refreshing project: {0}
84+
8385
ImportProjectError=An error occurred while importing the {0} project.
8486
StartBuildError=An error occurred while starting a build for the {0} project.
8587
OpenMicroclimateUIError=An error occurred while opening the Microclimate UI.

0 commit comments

Comments
 (0)