Skip to content

Commit

Permalink
Implement command loading
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-wyluda committed May 30, 2014
1 parent 63d4b09 commit 440f615
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
23 changes: 21 additions & 2 deletions src/main/java/org/jboss/forge/plugin/idea/ui/CommandListPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.components.JBList;
import org.jboss.forge.addon.ui.command.CommandFactory;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.addon.ui.wizard.UIWizardStep;
import org.jboss.forge.plugin.idea.service.ServiceHelper;

import javax.swing.*;
import java.util.ArrayList;
Expand Down Expand Up @@ -104,8 +107,24 @@ public void run()

private List<UICommand> getAllCandidates()
{
// TODO Implement getAllCandidates()
return new ArrayList<>();
List<UICommand> commands = new ArrayList<UICommand>();
CommandFactory commandFactory = ServiceHelper.getForgeService().getCommandFactory();

for (UICommand command : commandFactory.getCommands())
{
if (isCandidate(command))
{
commands.add(command);
}
}

return commands;
}

private boolean isCandidate(UICommand command)
{
// TODO Call command.isEnabled() with UIContext
return !(command instanceof UIWizardStep);
}

private void openWizard(UICommand command, VirtualFile[] files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
*/
package org.jboss.forge.plugin.idea.service;

import org.jboss.forge.addon.ui.command.CommandFactory;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.furnace.util.Lists;
import org.junit.*;

import java.util.List;

import static org.junit.Assert.*;

/**
Expand All @@ -17,16 +22,47 @@ public class ForgeServiceTest //extends LightCodeInsightFixtureTestCase
{
// TODO Run test in real IntelliJ environment

@Test
public void testFurnaceLoading() throws Exception
private ForgeService service;

@Before
public void prepare()
{
// This should be obtained and initialized using IntelliJ API:
// ForgeService service = ServiceHelper.getForgeService();
ForgeService service = new ForgeService();
// service = ServiceHelper.getForgeService();
service = new ForgeService();
service.createFurnace();
service.initializeAddonRepositories(false);
}

@Test
public void testFurnaceLoading()
{
startFurnace();

service.startAsync().get();
assertTrue(service.isLoaded());
}

@Test
public void testCommandLoading()
{
startFurnace();

CommandFactory factory = service.getCommandFactory();
assertNotNull(factory);

List<UICommand> commands = Lists.toList(factory.getCommands());
assertTrue(commands.size() > 0);
}

private void startFurnace()
{
try
{
service.startAsync().get();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}

0 comments on commit 440f615

Please sign in to comment.