部分完成!

This commit is contained in:
makejava 2018-01-10 23:51:16 +08:00
parent a12d295d79
commit b804e890bf
12 changed files with 261 additions and 25 deletions

View File

@ -1,4 +1,6 @@
button.type.mapper.copy.group=Copy Group
label.author.name=&\u4F5C\u8005\u540D\u79F0\uFF1A
label.default.encode=&\u9ED8\u8BA4\u7F16\u7801\uFF1A
label.operate=\u64CD\u4F5C
label.template.group=&\u6A21\u677F\u7EC4\uFF1A
label.type.mapper=&\u7C7B\u578B\u6620\u5C04\u7EC4\uFF1A

View File

@ -0,0 +1 @@
这里什么都没有

View File

@ -19,7 +19,7 @@ public abstract class AbstractTableModel<T> extends DefaultTableModel {
}
this.data = data;
removeAllRow();
data.forEach(this::addRow);
data.forEach(item-> super.addRow(toObj(item)));
}

View File

@ -6,6 +6,14 @@ public class Template implements Cloneable {
//模板代码
private String code;
public Template() {
}
public Template(String name, String code) {
this.name = name;
this.code = code;
}
public String getName() {
return name;
}

View File

@ -2,6 +2,7 @@ package com.sjhy.plugin.service;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.entity.TypeMapperGroup;
import java.util.Map;
@ -9,6 +10,7 @@ import java.util.Map;
public interface ConfigService extends PersistentStateComponent<ConfigService> {
//默认名称
String DEFAULT_NAME = "Default";
static ConfigService getInstance() {
return ServiceManager.getService(ConfigService.class);
}
@ -23,8 +25,6 @@ public interface ConfigService extends PersistentStateComponent<ConfigService> {
void setCurrTemplateGroupName(String currTemplateGroupName);
// Map<String, Map<String, String>> getTemplateGroup();
String getEncode();
void setEncode(String encode);
@ -34,4 +34,8 @@ public interface ConfigService extends PersistentStateComponent<ConfigService> {
void setAuthor(String author);
void setTypeMapperGroupMap(Map<String, TypeMapperGroup> typeMapperGroupMap);
Map<String, TemplateGroup> getTemplateGroupMap();
void setTemplateGroupMap(Map<String, TemplateGroup> templateGroupMap);
}

View File

@ -4,6 +4,8 @@ import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.entity.TypeMapper;
import com.sjhy.plugin.entity.TypeMapperGroup;
import com.sjhy.plugin.service.ConfigService;
@ -23,13 +25,14 @@ public class ConfigServiceImpl implements ConfigService {
private Map<String, TypeMapperGroup> typeMapperGroupMap;
//当前模板组名
private String currTemplateGroupName;
// //模板组
// private Map<String, Map<String, String>> templateGroup;
//模板组
private Map<String, TemplateGroup> templateGroupMap;
//默认编码
private String encode;
//作者
private String author;
//是否初始化
private Boolean init = false;
public ConfigServiceImpl() {
@ -51,6 +54,9 @@ public class ConfigServiceImpl implements ConfigService {
if (configService.getTypeMapperGroupMap().isEmpty()) {
return;
}
if (configService.getTemplateGroupMap().isEmpty()) {
return;
}
//加载配置信息
XmlSerializerUtil.copyBean(configService, this);
}
@ -71,13 +77,17 @@ public class ConfigServiceImpl implements ConfigService {
if (this.currTypeMapperGroupName==null) {
this.currTypeMapperGroupName = DEFAULT_NAME;
}
// //配置默认模板
// if (this.templateGroup==null) {
// this.templateGroup = new LinkedHashMap<>();
// }
// Map<String, String> template = new LinkedHashMap<>();
// template.put("entity", loadTemplate("entity"));
// this.templateGroup.put(DEFAULT_NAME, template);
//配置默认模板
if (this.templateGroupMap==null) {
this.templateGroupMap = new LinkedHashMap<>();
}
TemplateGroup templateGroup = new TemplateGroup();
List<Template> templateList = new ArrayList<>();
templateList.add(new Template("entity", loadTemplate("entity")));
templateList.add(new Template("dao", loadTemplate("dao")));
templateGroup.setName(DEFAULT_NAME);
templateGroup.setTemplateList(templateList);
this.templateGroupMap.put(DEFAULT_NAME, templateGroup);
//配置默认类型映射
if (this.typeMapperGroupMap==null) {
@ -133,11 +143,6 @@ public class ConfigServiceImpl implements ConfigService {
this.currTemplateGroupName = currTemplateGroupName;
}
// @Override
// public Map<String, Map<String, String>> getTemplateGroup() {
// return templateGroup;
// }
@Override
public String getEncode() {
return encode;
@ -163,10 +168,15 @@ public class ConfigServiceImpl implements ConfigService {
this.typeMapperGroupMap = typeMapperGroupMap;
}
// public void setTemplateGroup(Map<String, Map<String, String>> templateGroup) {
// this.templateGroup = templateGroup;
// }
@Override
public Map<String, TemplateGroup> getTemplateGroupMap() {
return templateGroupMap;
}
@Override
public void setTemplateGroupMap(Map<String, TemplateGroup> templateGroupMap) {
this.templateGroupMap = templateGroupMap;
}
public Boolean getInit() {
return init;

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.sjhy.plugin.ui.EditTemplatePanel">
<grid id="27dc6" binding="mainPanel" 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>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d3e6e" class="javax.swing.JTextArea" binding="textArea">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>

View File

@ -0,0 +1,39 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.uiDesigner.core.GridConstraints;
import javax.swing.*;
import java.awt.*;
public class EditTemplatePanel {
private JTextArea textArea;
private JPanel mainPanel;
private Editor editor;
public EditTemplatePanel() {
addVmEditor("test");
}
private void addVmEditor(String template) {
EditorFactory factory = EditorFactory.getInstance();
Document velocityTemplate = factory.createDocument(template);
editor = factory.createEditor(velocityTemplate, null, FileTypeManager.getInstance()
.getFileTypeByExtension("vm"), false);
GridConstraints constraints = new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST,
GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(300, 300), null, 0, true);
mainPanel.add(editor.getComponent(), constraints);
}
public JTextArea getTextArea() {
return textArea;
}
public JPanel getMainPanel() {
return mainPanel;
}
}

View File

@ -46,8 +46,9 @@ public class MainSetting extends ServiceComm implements Configurable, Configurab
@NotNull
@Override
public Configurable[] getConfigurables() {
Configurable[] result = new Configurable[1];
Configurable[] result = new Configurable[2];
result[0] = new TypeMapperSetting(configService);
result[1] = new TemplateSetting(configService);
return result;
}

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.sjhy.plugin.ui.TemplateSetting">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="33" width="586" height="454"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<tabbedpane id="272b3" binding="templateTabbedPane">
<constraints>
<grid row="1" column="0" row-span="2" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</tabbedpane>
<component id="ffaa3" class="javax.swing.JLabel">
<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>
<labelFor value="e5431"/>
<text resource-bundle="string" key="label.template.group"/>
</properties>
</component>
<component id="e5431" class="javax.swing.JComboBox" binding="groupButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<grid id="e30b5" layout-manager="GridLayoutManager" row-count="3" 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="2" column="5" 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="eedcb" class="javax.swing.JButton" binding="removeButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="actions/delete.png"/>
</properties>
</component>
<vspacer id="1da1">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="ee190" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="general/add.png"/>
</properties>
</component>
</children>
</grid>
<component id="9d5e2" class="javax.swing.JButton" binding="deleteButton">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="actions/delete.png"/>
</properties>
</component>
<component id="96a1b" class="javax.swing.JButton" binding="copyGroupButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="actions/copy.png"/>
</properties>
</component>
<hspacer id="2b805">
<constraints>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="76ed0" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.operate"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@ -0,0 +1,51 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.options.Configurable;
import com.sjhy.plugin.service.ConfigService;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
public class TemplateSetting implements Configurable {
private JPanel mainPanel;
private JButton copyGroupButton;
private JButton deleteButton;
private JTabbedPane templateTabbedPane;
private JComboBox groupButton;
private JButton addButton;
private JButton removeButton;
private ConfigService configService;
TemplateSetting(ConfigService configService) {
this.configService = configService;
init();
}
private void init() {
this.templateTabbedPane.addTab("entity", new EditTemplatePanel().getMainPanel());
}
@Nls
@Override
public String getDisplayName() {
return "Template Setting";
}
@Nullable
@Override
public JComponent createComponent() {
return this.mainPanel;
}
@Override
public boolean isModified() {
return false;
}
@Override
public void apply() {
}
}

View File

@ -3,7 +3,7 @@
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="633" height="400"/>
<xy x="20" y="20" width="666" height="495"/>
</constraints>
<properties/>
<border type="none"/>
@ -37,7 +37,7 @@
</hspacer>
<component id="448" class="javax.swing.JComboBox" binding="typeMapperComboBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false">
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
@ -47,7 +47,7 @@
</component>
<component id="7b067" class="javax.swing.JButton" binding="typeMapperCopyButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="actions/copy.png"/>
@ -68,7 +68,6 @@
</constraints>
<properties>
<icon value="general/add.png"/>
<text value=""/>
</properties>
</component>
<component id="222d7" class="javax.swing.JButton" binding="removeButton" default-binding="true">