Skip to content

Commit

Permalink
Basic command result notification support
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-wyluda committed Jun 11, 2014
1 parent 985797d commit 141334f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import org.jboss.forge.addon.ui.controller.WizardCommandController;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.output.UIMessage;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.plugin.idea.ui.component.ComponentBuilder;
import org.jboss.forge.plugin.idea.ui.component.ComponentBuilderRegistry;
import org.jboss.forge.plugin.idea.ui.component.ForgeComponent;
import org.jboss.forge.plugin.idea.util.ForgeNotifications;

import javax.swing.*;
import java.util.ArrayList;
Expand Down Expand Up @@ -137,7 +139,8 @@ public boolean onFinish()
{
try
{
controller.execute();
Result result = controller.execute();
ForgeNotifications.showExecutionResult(result);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.plugin.idea.util;

import com.intellij.notification.NotificationGroup;
import com.intellij.openapi.ui.MessageType;
import org.jboss.forge.addon.ui.result.CompositeResult;
import org.jboss.forge.addon.ui.result.Failed;
import org.jboss.forge.addon.ui.result.Result;

/**
* Forge notification
*
* @author Adam Wyłuda
*/
public class ForgeNotifications
{
private static final NotificationGroup NOTIFICATION_GROUP =
NotificationGroup.balloonGroup("Forge Notifications");

private static final String SUCCESS_MESSAGE = "Command executed successfully";
private static final String FAILURE_MESSAGE = "Command execution failed";

public static void showExecutionResult(Result result)
{
result = getFirstResult(result);
NOTIFICATION_GROUP.createNotification(messageFrom(result), messageTypeOf(result)).notify(null);
}

private static String messageFrom(Result result)
{
if (result.getMessage() != null && !result.getMessage().isEmpty())
{
return result.getMessage();
}

if (result instanceof Failed)
{
return SUCCESS_MESSAGE;
}

return FAILURE_MESSAGE;
}

private static MessageType messageTypeOf(Result result)
{
if (result instanceof Failed)
{
return MessageType.ERROR;
}

return MessageType.INFO;
}

private static Result getFirstResult(Result result)
{
while (result instanceof CompositeResult)
{
result = ((CompositeResult) result).getResults().get(0);
}

return result;
}
}

0 comments on commit 141334f

Please sign in to comment.