Skip to content

Commit

Permalink
SLE-927: Dialogs don't focus on "Open in IDE"
Browse files Browse the repository at this point in the history
The failure notifications were designed for the "Open in IDE" feature once and had to be adopted to not feature this information in the title anymore.

In order to work for different features they were adopted to be more generic.
  • Loading branch information
thahnen committed Aug 26, 2024
1 parent aee7e97 commit 4ac1aab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ protected IStatus run(IProgressMonitor monitor) {
var status = statusRef.get();
if (Status.CANCEL_STATUS == status) {
if (cancelledByJob.get()) {
MessageDialogUtils.openInIdeError("The previous dialog was closed either manually by you or the connection was not ready in "
+ "time. The reason for the latter could be a slow network connection.");
MessageDialogUtils.dialogCancelled("The previous dialog was closed either manually by you or the connection "
+ "was not ready in time. The reason for the latter could be a slow network connection.");
}
return status;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ protected IStatus run(IProgressMonitor monitor) {
actualRun();
} catch (CoreException e) {
var message = "An error occured while trying to run the requested action.";
MessageDialogUtils.openInIdeError(message + " Please see the console for the full error log!");
MessageDialogUtils.openInEclipseFailed(message + " Please see the console for the full error log!");
SonarLintLogger.get().error(message, e);
}

Expand All @@ -150,7 +150,7 @@ private Optional<ISonarLintFile> tryGetLocalFile() {
// Check if file exists in project based on the server to IDE path matching
var fileOpt = project.find(getIdeFilePath());
if (fileOpt.isEmpty()) {
MessageDialogUtils.openInIdeError("The required file cannot be found in the project '"
MessageDialogUtils.fileNotFound("The required file cannot be found in the project '"
+ project.getName() + "'. Maybe it was already changed locally!");
return Optional.empty();
}
Expand Down Expand Up @@ -186,10 +186,10 @@ private boolean tryMatchBranches() {

if (localBranch.isEmpty()) {
// This error message may be misleading to COBOL / ABAP developers but that is okay for now :>
MessageDialogUtils.openInIdeInformation("The local branch of the project '" + project.getName()
MessageDialogUtils.branchNotAvailable("The local branch of the project '" + project.getName()
+ "' could not be determined. SonarLint now can only try to find the matching local issue!");
} else if (!branch.equals(localBranch.get())) {
MessageDialogUtils.openInIdeError("The local branch '" + localBranch.get() + "' of the project '"
MessageDialogUtils.branchMismatch("The local branch '" + localBranch.get() + "' of the project '"
+ project.getName() + "' does not match the remote branch '" + branch + "'. "
+ "Please checkout the correct branch and invoke the requested action once again!");
BrowserUtils.openExternalBrowser(SonarLintDocumentation.BRANCH_AWARENESS, Display.getDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void done(IJobChangeEvent event) {
new OpenIssueInEclipseJob(new OpenIssueContext(name, issueDetails, project, binding, file, true))
.schedule(1000);
} else {
MessageDialogUtils.openInIdeError("Fetching the issue to be displayed failed because the dependent "
MessageDialogUtils.openInEclipseFailed("Fetching the issue to be displayed failed because the dependent "
+ "job did not finish successfully.");
}
}
Expand All @@ -162,7 +162,7 @@ private IStatus handlePossibleHiddenIssue() {
// When we already asked the user to change his workspace preferences, he agreed but did not change anything we
// don't want to end up in a loop asking the user if could please change his preferences ^^
if (askedForPreferenceChangeAlready) {
MessageDialogUtils.openInIdeError("The issue was not found locally. Maybe the issue was already "
MessageDialogUtils.openInEclipseFailed("The issue was not found locally. Maybe the issue was already "
+ "resolved or the resources has moved / was deleted.");
return Status.CANCEL_STATUS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,41 @@

/** When we want to display simple dialogs we can use the JFace MessageDialog */
public class MessageDialogUtils {
private static final String OPEN_IN_IDE_TITLE = "Open in IDE";

private MessageDialogUtils() {
// utility class
}

/** For the "Open in IDE" feature we want to display an information */
public static void openInIdeInformation(String message) {
Display.getDefault().syncExec(() -> MessageDialog.openInformation(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), OPEN_IN_IDE_TITLE, message));
private static void showError(String title, String message) {
Display.getDefault().syncExec(() -> MessageDialog.openError(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, message));
}

/** For the "Open in IDE" feature we want to display an error message */
public static void openInIdeError(String message) {
Display.getDefault().syncExec(() -> MessageDialog.openError(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), OPEN_IN_IDE_TITLE, message));
public static void fileNotFound(String message) {
showError("File not found", message);
}

public static void dialogCancelled(String message) {
showError("Dialog cancelled", message);
}

public static void branchMismatch(String message) {
showError("Branch not matching", message);
}

public static void openInEclipseFailed(String message) {
showError("Open in Eclipse failed", message);
}

public static void branchNotAvailable(String message) {
Display.getDefault().syncExec(() -> MessageDialog.openInformation(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Branch not matchable", message));
}

/** For the "Open in IDE" feature we want to display a yes/no question for the user to answer */
public static void openInIdeQuestion(String message, Runnable yesHandler) {
Display.getDefault().asyncExec(() -> {
var result = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
OPEN_IN_IDE_TITLE, message);
"Open in IDE", message);
if (result) {
yesHandler.run();
}
Expand Down

0 comments on commit 4ac1aab

Please sign in to comment.