Skip to content

Commit

Permalink
#4 JDK 6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
makasprzak committed Mar 26, 2015
1 parent 00b0294 commit 0929c80
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>makasprzak.step-builder-generator</id>
<name>Step Builder Pattern generator</name>
<version>1.0</version>
<version>1.1</version>
<vendor email="[email protected]" url="https://github.com/makasprzak">Maciej Kasprzak</vendor>

<description><![CDATA[
Expand Down
19 changes: 16 additions & 3 deletions src/makasprzak/idea/plugins/dialog/GeneratorDialog.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package makasprzak.idea.plugins.dialog;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.psi.PsiClass;
Expand All @@ -11,18 +12,19 @@
import makasprzak.idea.plugins.model.PsiPropertyContainer;

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

import static com.google.common.collect.Lists.transform;

public class GeneratorDialog extends DialogWrapper{
private JList<PsiPropertyContainer> properties;
private JList properties;
private final LabeledComponent<JPanel> component;

protected GeneratorDialog(PsiClass psiClass, List<PsiPropertyContainer> allProperties) {
super(psiClass.getProject());
setTitle("Configure Step Builder");
this.properties = new JBList(new CollectionListModel<>(allProperties));
this.properties = new JBList(new CollectionListModel<PsiPropertyContainer>(allProperties));
this.properties.setCellRenderer(new PropertyCellRenderer());
this.properties.setSelectedIndices(range(allProperties.size()));
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(properties);
Expand All @@ -48,7 +50,18 @@ protected JComponent createCenterPanel() {
}

public List<Property> getProperties() {
return transform(properties.getSelectedValuesList(), toProperty());
return transform(getPsiPropertyContainers(), toProperty());
}

private List<PsiPropertyContainer> getPsiPropertyContainers() {
Object[] selectedObjects = properties.getSelectedValues();
List<Object> selectedObjectList = Arrays.asList(selectedObjects);
return Lists.transform(selectedObjectList, new Function<Object, PsiPropertyContainer>() {
@Override
public PsiPropertyContainer apply(Object o) {
return (PsiPropertyContainer) o;
}
});
}

private Function<PsiPropertyContainer, Property> toProperty() {
Expand Down
13 changes: 9 additions & 4 deletions src/makasprzak/idea/plugins/dialog/PropertyCellRenderer.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package makasprzak.idea.plugins.dialog;

import com.intellij.ide.util.DefaultPsiElementCellRenderer;
import com.intellij.psi.PsiElement;
import makasprzak.idea.plugins.model.PsiPropertyContainer;

import javax.swing.*;
import java.awt.*;

public class PropertyCellRenderer implements ListCellRenderer<PsiPropertyContainer> {
public class PropertyCellRenderer implements ListCellRenderer {
private final DefaultPsiElementCellRenderer renderer = new DefaultPsiElementCellRenderer();

@Override
public Component getListCellRendererComponent(JList<? extends PsiPropertyContainer> list,
PsiPropertyContainer value,
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
return renderer.getListCellRendererComponent(list,value.getPsiElement(),index,isSelected,cellHasFocus);
return renderer.getListCellRendererComponent(list, getValue(value),index,isSelected,cellHasFocus);
}

private PsiElement getValue(Object value) {
return ((PsiPropertyContainer)value).getPsiElement();
}
}
4 changes: 2 additions & 2 deletions step-builder-generator.iml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/META-INF/plugin.xml" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="IDEA IU-139.1117.1 (1)" jdkType="IDEA JDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library>
Expand Down

0 comments on commit 0929c80

Please sign in to comment.