Skip to content

Commit

Permalink
update template
Browse files Browse the repository at this point in the history
  • Loading branch information
hykes committed Jan 17, 2018
1 parent f8000de commit 3928764
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 55 deletions.
6 changes: 3 additions & 3 deletions resources/templates/ControllerTemplate.vm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.util.List;
#ImportPackage("${model}WriteService")

/**
*
* $!{comment}
* @author $!{email}
* @date ${NOW}
* Created by CodeGen .
Expand All @@ -29,7 +29,7 @@ public class ${model}s {
private ${model}ReadService #LowerCase(${model})ReadService;

/**
* 查询
* 查询$!{comment}
* @param id
* @return
*/
Expand All @@ -39,7 +39,7 @@ public class ${model}s {
}

/**
* 创建
* 创建$!{comment}
* @param #LowerCase(${model})
* @return
*/
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/DaoTemplate.vm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.springframework.stereotype.Repository;
#ImportPackage(${model})

/**
*
* $!{comment} DAO层
* @author $!{email}
* @date ${NOW}
* Created by CodeGen .
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/ModelTemplate.vm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.Serializable;
import java.util.Date;

/**
*
* $!{comment}
* @author $!{email}
* @date ${NOW}
* Created by CodeGen .
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/ReadServiceImplTemplate.vm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.List;
#ImportPackage("${model}Dao")

/**
*
* $!{comment}读服务实现类
* @author $!{email}
* @date ${NOW}
* Created by CodeGen .
Expand Down
4 changes: 2 additions & 2 deletions resources/templates/ReadServiceTemplate.vm
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import java.util.List;
#ImportPackage(${model})

/**
*
* $!{comment}读服务接口
* @author $!{email}
* @date ${NOW}
* Created by CodeGen .
*/
public interface ${model}ReadService {

/**
* 查询
* 查询$!{comment}
* @param id
* @return #LowerCase(${model})

Expand Down
2 changes: 1 addition & 1 deletion resources/templates/WriteServiceImplTemplate.vm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service;
#ImportPackage("${model}Dao")

/**
*
* $!{comment}写服务实现类
* @author $!{email}
* @date ${NOW}
* Created by CodeGen .
Expand Down
4 changes: 2 additions & 2 deletions resources/templates/WriteServiceTemplate.vm
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#ImportPackage(${model})

/**
*
* $!{comment}写服务接口
* @author $!{email}
* @date ${NOW}
* Created by CodeGen .
*/
public interface ${model}WriteService {

/**
* 创建
* 创建$!{comment}
* @param #LowerCase(${model})

* @return Boolean
Expand Down
9 changes: 2 additions & 7 deletions src/com/github/hykes/codegen/configurable/ui/TemplatesUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.AnActionButton;
import com.intellij.ui.GuiUtils;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.components.JBPanel;
import com.intellij.ui.treeStructure.Tree;
Expand All @@ -40,11 +39,8 @@
import java.awt.*;
import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.*;
import java.util.List;
import java.util.Map;

/**
* 模版配置面板
Expand Down Expand Up @@ -247,7 +243,7 @@ public void actionPerformed(AnActionEvent e) {
for (CodeGroup group : root.getGroups()) {
for (CodeTemplate template : group.getTemplates()) {
ExportTemplate exportTemplate = new ExportTemplate();
exportTemplate.setName(group.getName()+template.getDisplay()+".vm");
exportTemplate.setName(root.getName() + "_" + group.getName() + "_" + template.getDisplay() +".vm");
ByteArrayOutputStream o = new ByteArrayOutputStream();
o.write("#*\n".getBytes());
o.write(("display: "+ template.getDisplay() +";\n").getBytes());
Expand All @@ -267,7 +263,6 @@ public void actionPerformed(AnActionEvent e) {
}
ZipUtil.export(files, virtualFile.getCanonicalPath() + "/CodeGen-Templates.zip");
Messages.showInfoMessage("Export CodeGen templates success", "INFO");
// NotifyUtil.notice("Export CodeGen templates success", virtualFile.getCanonicalPath() + "/CodeGen-Templates.zip", MessageType.INFO);
} catch (Exception var){
LOGGER.error(var.getMessage());
}
Expand Down
7 changes: 6 additions & 1 deletion src/com/github/hykes/codegen/constants/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ public static List<CodeRoot> getDefaultTemplates(){
templates2.add(new CodeTemplate(UUID.randomUUID().toString(), "ReadService", "java", "${model}ReadServiceImpl", FileUtil.loadTextAndClose(Defaults.class.getResourceAsStream("/templates/ReadServiceImplTemplate.vm")), "service", false));
templates2.add(new CodeTemplate(UUID.randomUUID().toString(), "WriteService", "java", "${model}WriteServiceImpl", FileUtil.loadTextAndClose(Defaults.class.getResourceAsStream("/templates/WriteServiceImplTemplate.vm")), "service", false));
templates2.add(new CodeTemplate(UUID.randomUUID().toString(), "Mapper", "xml", "${model}Mapper", FileUtil.loadTextAndClose(Defaults.class.getResourceAsStream("/templates/MapperTemplate.vm")), "mapper", true));
CodeGroup implGroup = new CodeGroup(UUID.randomUUID().toString(), "impl-dao", 2, templates2);
CodeGroup implGroup = new CodeGroup(UUID.randomUUID().toString(), "service-impl-dao", 2, templates2);
groups.add(implGroup);

List<CodeTemplate> templates3 = new ArrayList<>();
templates3.add(new CodeTemplate(UUID.randomUUID().toString(), "Controller", "java", "${model}s", FileUtil.loadTextAndClose(Defaults.class.getResourceAsStream("/templates/ControllerTemplate.vm")), "front", false));
CodeGroup apiGroup = new CodeGroup(UUID.randomUUID().toString(), "api", 2, templates3);
groups.add(apiGroup);
} catch (Exception e){
LOGGER.error(StringUtils.getStackTraceAsString(e));
}
Expand Down
17 changes: 7 additions & 10 deletions src/com/github/hykes/codegen/gui/ColumnEditorFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ private void init(IdeaContext ideaContext, List<Table> tables){
for (TablePanel panel: panels) {
String modelName = panel.getModelTextField().getText().trim();
String tableName = panel.getTableTextField().getText().trim();
String comment = panel.getCommentTextField().getText().trim();
// 组装数据
CodeContext context = new CodeContext(modelName, tableName, panel.getFields());
CodeContext context = new CodeContext(modelName, tableName, comment, panel.getFields());
contexts.add(context);
}
generator(ideaContext, selectGroups, contexts);
Expand All @@ -122,8 +123,7 @@ private List<String> getAllJCheckBoxValue(Container ct, List<String> selectGroup
Component c=ct.getComponent(i);
if(c instanceof JCheckBox && ((JCheckBox)c).isSelected()){
selectGroups.add(c.getName());
}
else if(c instanceof Container){
} else if (c instanceof Container){
this.getAllJCheckBoxValue((Container)c, selectGroups);
}
}
Expand Down Expand Up @@ -161,16 +161,13 @@ public void generator(IdeaContext ideaContext, List<String> groups, List<CodeCon
*/
public class ComparatorUtil implements Comparator<CodeGroup> {

/**
* 倒序排列即从大到小,若需要从小到大修改返回值1 和 -1
*/
@Override
public int compare(CodeGroup o1, CodeGroup o2) {
double tempResult1 = o1.getLevel();
double tempResult2 = o2.getLevel();
if (tempResult1 > tempResult2) {
double level1 = o1.getLevel();
double level2 = o2.getLevel();
if (level1 > level2) {
return 1;
} else if (tempResult1 < tempResult2) {
} else if (level1 < level2) {
return -1;
} else {
return 0;
Expand Down
10 changes: 4 additions & 6 deletions src/com/github/hykes/codegen/gui/SelectGroupPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ private void renderGroupsPanel(CodeRoot root) {
SelectPathDialog dialog = new SelectPathDialog(project);
dialog.setSize(350, 160);
dialog.setAlwaysOnTop(true);
dialog.setLocationRelativeTo(this.rootPanel);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
dialog.setLocation((screenSize.width-dialog.getWidth())/2, (screenSize.height-dialog.getHeight())/2);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
Expand Down Expand Up @@ -113,11 +115,7 @@ private void createUIComponents() {
public class CellRenderer extends JLabel implements ListCellRenderer {

@Override
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
CodeRoot root = (CodeRoot) value;
setHorizontalAlignment(JLabel.CENTER);
try {
Expand Down
53 changes: 34 additions & 19 deletions src/com/github/hykes/codegen/gui/TablePanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,64 @@
<properties/>
<border type="none"/>
<children>
<grid id="c2410" binding="modelPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="c2410" binding="modelPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="8eeb1" binding="tablePanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="68b9c" class="javax.swing.JLabel" binding="modelLab">
<component id="79ff9" class="javax.swing.JLabel" binding="tableLab">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Model"/>
<text value="Table "/>
</properties>
</component>
<component id="9ee53" class="javax.swing.JTextField" binding="modelTextField">
<component id="950ca" class="javax.swing.JTextField" binding="tableTextField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="8eeb1" binding="tablePanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="79ff9" class="javax.swing.JLabel" binding="tableLab">
<component id="89e46" class="javax.swing.JLabel" binding="commentLab">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Model Comment"/>
</properties>
</component>
<component id="40e53" class="javax.swing.JTextField" binding="commentTextField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="68b9c" class="javax.swing.JLabel" binding="modelLab">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Table "/>
<text value="Model"/>
</properties>
</component>
<component id="950ca" class="javax.swing.JTextField" binding="tableTextField">
<component id="9ee53" class="javax.swing.JTextField" binding="modelTextField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
Expand Down
6 changes: 6 additions & 0 deletions src/com/github/hykes/codegen/gui/TablePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class TablePanel {
private JLabel modelLab;
private JLabel tableLab;
private JPanel columnsPanel;
private JTextField commentTextField;
private JLabel commentLab;

private JBTable fieldTable = new JBTable();

Expand All @@ -47,6 +49,10 @@ public JTextField getTableTextField() {
return tableTextField;
}

public JTextField getCommentTextField() {
return commentTextField;
}

public TablePanel(Table table) {
$$$setupUI$$$();
rootPanel.setBorder(IdeBorderFactory.createTitledBorder(table.getTableName(), false));
Expand Down
13 changes: 12 additions & 1 deletion src/com/github/hykes/codegen/model/CodeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ public class CodeContext implements Serializable {

private static final long serialVersionUID = 6235968905610310027L;

public CodeContext(String model, String table, List<Field> fields) {
public CodeContext(String model, String table, String comment, List<Field> fields) {
this.model = model;
this.table = table;
this.comment = comment;
this.fields = fields;
}

private String model;

private String table;

private String comment;

private List<Field> fields;

public String getModel() {
Expand All @@ -47,5 +50,13 @@ public List<Field> getFields() {
public void setFields(List<Field> fields) {
this.fields = fields;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}
}

0 comments on commit 3928764

Please sign in to comment.