Skip to content

Commit

Permalink
CompositeResult can be nested
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Feb 27, 2014
1 parent 4ed2740 commit 39bb404
Showing 1 changed file with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package org.jboss.tools.forge.ui.ext.wizards;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -85,38 +84,8 @@ public void run(IProgressMonitor monitor)
attributeMap.put(Shell.class, shell);

Result commandResult = controller.execute();

List<Result> results;
if (commandResult instanceof CompositeResult) {
results = ((CompositeResult) commandResult)
.getResults();
} else {
results = Arrays.asList(commandResult);
}
for (Result result : results) {
if (result != null) {
String message = result.getMessage();
if (message != null) {
NotificationType notificationType = result instanceof Failed ? NotificationType.ERROR
: NotificationType.INFO;
ForgeUIPlugin.displayMessage(getWindowTitle(),
message, notificationType);
}
if (result instanceof Failed) {
Throwable exception = ((Failed) result)
.getException();
if (exception != null) {
ForgeUIPlugin.log(exception);
ForgeUIPlugin.displayMessage(
getWindowTitle(), String
.valueOf(exception
.getMessage()),
NotificationType.ERROR);
}
}
}
EventBus.INSTANCE.fireWizardFinished(uiContext);
}
displayResult(commandResult);
EventBus.INSTANCE.fireWizardFinished(uiContext);
} catch (Exception e) {
ForgeUIPlugin.displayMessage(getWindowTitle(),
"Error while executing task, check Error log view",
Expand All @@ -133,6 +102,31 @@ public void run(IProgressMonitor monitor)
});
}

private void displayResult(Result result) {
if (result instanceof CompositeResult) {
for (Result thisResult : ((CompositeResult) result).getResults()) {
displayResult(thisResult);
}
} else if (result != null) {
String message = result.getMessage();
if (message != null) {
NotificationType notificationType = result instanceof Failed ? NotificationType.ERROR
: NotificationType.INFO;
ForgeUIPlugin.displayMessage(getWindowTitle(), message,
notificationType);
}
if (result instanceof Failed) {
Throwable exception = ((Failed) result).getException();
if (exception != null) {
ForgeUIPlugin.log(exception);
ForgeUIPlugin.displayMessage(getWindowTitle(),
String.valueOf(exception.getMessage()),
NotificationType.ERROR);
}
}
}
}

@Override
public boolean performCancel() {
EventBus.INSTANCE.fireWizardClosed(uiContext);
Expand Down

0 comments on commit 39bb404

Please sign in to comment.