Skip to content

Commit

Permalink
Project clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-wyluda committed Apr 29, 2014
1 parent 9afaa75 commit a54715a
Show file tree
Hide file tree
Showing 23 changed files with 1,232 additions and 1,141 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>10</version>
<version>14</version>
</parent>

<groupId>org.jboss.forge</groupId>
Expand All @@ -22,8 +22,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<idea.version>12.1.3</idea.version>
<forge.version>2.0.0.Alpha6</forge.version>
<idea.version>13.1.2</idea.version>
<forge.version>2.5.1-SNAPSHOT</forge.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -144,9 +144,9 @@

<plugins>
<plugin>
<groupId>org.jboss.forge</groupId>
<artifactId>forge-maven-plugin</artifactId>
<version>1.0.0.Alpha3</version>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-maven-plugin</artifactId>
<version>${forge.version}</version>
<executions>
<execution>
<id>deploy-addons</id>
Expand Down
80 changes: 39 additions & 41 deletions src/main/java/org/jboss/forge/plugin/idea/ForgeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,61 @@
import org.jboss.forge.furnace.ContainerStatus;
import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.addons.AddonRegistry;
import org.jboss.forge.furnace.services.ExportedInstance;
import org.jboss.forge.furnace.services.Imported;

/**
* This is a singleton for the {@link Forge} class.
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*/

public enum ForgeService
{
INSTANCE;
INSTANCE;

private transient Furnace forge;
private transient Furnace forge;

private ForgeService()
{
}
private ForgeService()
{
}

public void setForge(Furnace forge)
{
this.forge = forge;
}
public void setForge(Furnace forge)
{
this.forge = forge;
}

public void start(ClassLoader loader)
{
forge.startAsync(loader);
}
public void start(ClassLoader loader)
{
forge.startAsync(loader);
}

public AddonRegistry getAddonRegistry()
{
return forge.getAddonRegistry();
}
public AddonRegistry getAddonRegistry()
{
return forge.getAddonRegistry();
}

public void stop()
{
forge.stop();
}
public void stop()
{
forge.stop();
}

public ContainerStatus getContainerStatus()
{
return (forge == null) ? ContainerStatus.STOPPED : forge.getStatus();
}
public ContainerStatus getContainerStatus()
{
return (forge == null) ? ContainerStatus.STOPPED : forge.getStatus();
}

public ConverterFactory getConverterFactory()
{
return lookup(ConverterFactory.class);
}
public ConverterFactory getConverterFactory()
{
return lookup(ConverterFactory.class);
}

public <S> S lookup(Class<S> service)
{
ExportedInstance<S> exportedInstance = null;
if (forge != null)
{
exportedInstance = forge.getAddonRegistry().getExportedInstance(
service);
}
return (exportedInstance == null) ? null : exportedInstance.get();
}
public <S> S lookup(Class<S> service)
{
Imported<S> exportedInstance = null;
if (forge != null)
{
exportedInstance = forge.getAddonRegistry().getServices(service);
}
return (exportedInstance == null) ? null : exportedInstance.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@
*/
package org.jboss.forge.plugin.idea.actions;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.swing.DefaultListModel;
import javax.swing.JList;

import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.addon.ui.wizard.UIWizardStep;
import org.jboss.forge.furnace.addons.AddonRegistry;
import org.jboss.forge.furnace.services.ExportedInstance;
import org.jboss.forge.plugin.idea.ForgeService;
import org.jboss.forge.plugin.idea.wizards.ForgeWizardDialog;
import org.jboss.forge.plugin.idea.wizards.ForgeWizardModel;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
Expand All @@ -34,94 +19,117 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.components.JBList;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.addon.ui.wizard.UIWizardStep;
import org.jboss.forge.furnace.addons.AddonRegistry;
import org.jboss.forge.furnace.services.Imported;
import org.jboss.forge.plugin.idea.ForgeService;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
* Creates a popup list and displays all the currently registered
* {@link UICommand} instances
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*/
public class ShowForgeMenuAction extends AnAction {
volatile boolean active;

@Override
public void actionPerformed(final AnActionEvent e) {
if (active)
return;
active = true;
final VirtualFile[] selectedFiles = e
.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);

final JBList list = new JBList();
DefaultListModel model = new DefaultListModel();

final Project project = e.getData(DataKeys.PROJECT);

final List<UICommand> allCandidates = getAllCandidates();
model.setSize(allCandidates.size());

list.setCellRenderer(new ListCellRendererWrapper<UICommand>() {
@Override
public void customize(JList list, UICommand data, int index,
boolean selected, boolean hasFocus) {
if (data != null) {
setIcon(AllIcons.Nodes.Plugin);
setText(data.getMetadata().getName());

// if (hasFocus)
// {
// HintManager.getInstance().showInformationHint(editor,
// data.getMetadata().getDescription());
// }
}
}
});

for (int i = 0; i < allCandidates.size(); i++) {
model.set(i, allCandidates.get(i));
}

list.setModel(model);

final PopupChooserBuilder listPopupBuilder = JBPopupFactory
.getInstance().createListPopupBuilder(list);
listPopupBuilder.setTitle("Run a Forge command");
listPopupBuilder.addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
ShowForgeMenuAction.this.active = false;
}
});
listPopupBuilder.setItemChoosenCallback(new Runnable() {
@Override
public void run() {
int selectedIndex = list.getSelectedIndex();
UICommand selectedCommand = allCandidates.get(selectedIndex);
openWizard(selectedCommand, selectedFiles);
}
}).createPopup().showCenteredInCurrentWindow(project);
}

private void openWizard(UICommand command, VirtualFile[] files) {
ForgeWizardModel model = new ForgeWizardModel(command.getMetadata()
.getName(), command, files);
ForgeWizardDialog dialog = new ForgeWizardDialog(model);
dialog.show();
}

private List<UICommand> getAllCandidates() {
List<UICommand> result = new ArrayList<UICommand>();
AddonRegistry addonRegistry = ForgeService.INSTANCE.getAddonRegistry();
Set<ExportedInstance<UICommand>> exportedInstances = addonRegistry
.getExportedInstances(UICommand.class);
for (ExportedInstance<UICommand> instance : exportedInstances) {
UICommand uiCommand = instance.get();
if (!(uiCommand instanceof UIWizardStep)) {
result.add(uiCommand);
}
}
return result;
}
public class ShowForgeMenuAction extends AnAction
{
volatile boolean active;

@Override
public void actionPerformed(final AnActionEvent e)
{
if (active)
return;
active = true;
final VirtualFile[] selectedFiles = e
.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);

final JBList list = new JBList();
DefaultListModel model = new DefaultListModel();

final Project project = e.getData(DataKeys.PROJECT);

final List<UICommand> allCandidates = getAllCandidates();
model.setSize(allCandidates.size());

list.setCellRenderer(new ListCellRendererWrapper<UICommand>()
{
@Override
public void customize(JList list, UICommand data, int index,
boolean selected, boolean hasFocus)
{
if (data != null)
{
setIcon(AllIcons.Nodes.Plugin);

// TODO Pass UIContext to getMetadata()
// setText(data.getMetadata().getName());

// if (hasFocus)
// {
// HintManager.getInstance().showInformationHint(editor,
// data.getMetadata().getDescription());
// }
}
}
});

for (int i = 0; i < allCandidates.size(); i++)
{
model.set(i, allCandidates.get(i));
}

list.setModel(model);

final PopupChooserBuilder listPopupBuilder = JBPopupFactory
.getInstance().createListPopupBuilder(list);
listPopupBuilder.setTitle("Run a Forge command");
listPopupBuilder.addListener(new JBPopupAdapter()
{
@Override
public void onClosed(LightweightWindowEvent event)
{
ShowForgeMenuAction.this.active = false;
}
});
listPopupBuilder.setItemChoosenCallback(new Runnable()
{
@Override
public void run()
{
int selectedIndex = list.getSelectedIndex();
UICommand selectedCommand = allCandidates.get(selectedIndex);
openWizard(selectedCommand, selectedFiles);
}
}).createPopup().showCenteredInCurrentWindow(project);
}

private void openWizard(UICommand command, VirtualFile[] files)
{
// TODO Pass UIContext to getMetadata()
// ForgeWizardModel model = new ForgeWizardModel(command.getMetadata().getName(), command, files);
// ForgeWizardDialog dialog = new ForgeWizardDialog(model);
// dialog.show();
}

private List<UICommand> getAllCandidates()
{
List<UICommand> result = new ArrayList<UICommand>();
AddonRegistry addonRegistry = ForgeService.INSTANCE.getAddonRegistry();
Imported<UICommand> exportedInstances = addonRegistry
.getServices(UICommand.class);
for (UICommand uiCommand : exportedInstances)
{
if (!(uiCommand instanceof UIWizardStep))
{
result.add(uiCommand);
}
}
return result;
}

}
Loading

0 comments on commit a54715a

Please sign in to comment.