mirror of https://gitee.com/makejava/EasyCode.git
优化大量代码,统一clone工具。
This commit is contained in:
parent
4ecec56a12
commit
31da856a4d
|
@ -1,10 +1,16 @@
|
|||
package com.sjhy.plugin;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 临时测试类
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
//Test
|
||||
System.out.println("varchar(20)".matches("varchar(\\(\\d+\\))?"));
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package com.sjhy.plugin.comm;
|
||||
|
||||
import com.sjhy.plugin.tool.CloneUtils;
|
||||
|
||||
public abstract class CommClone<T> implements Cloneable {
|
||||
//克隆工具
|
||||
protected CloneUtils cloneUtils = CloneUtils.getInstance();
|
||||
@SuppressWarnings({"unchecked", "CloneDoesntDeclareCloneNotSupportedException"})
|
||||
@Override
|
||||
public T clone() {
|
||||
try {
|
||||
return (T) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package com.sjhy.plugin.entity;
|
||||
|
||||
import com.sjhy.plugin.comm.CommClone;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -11,59 +9,32 @@ import java.util.List;
|
|||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
public abstract class AbstractGroup<T extends CommClone, E extends CommClone> extends CommClone<T> {
|
||||
public interface AbstractGroup<E> {
|
||||
/**
|
||||
* 组名
|
||||
* 获取分组名称
|
||||
*
|
||||
* @return 分组名称
|
||||
*/
|
||||
private String name;
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* 组元素
|
||||
* 设置分组名称
|
||||
*
|
||||
* @param name 分组名称
|
||||
*/
|
||||
private List<E> elementList;
|
||||
void setName(String name);
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* 获取元素集合
|
||||
*
|
||||
* @return 元素集合
|
||||
*/
|
||||
List<E> getElementList();
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<E> getElementList() {
|
||||
return elementList;
|
||||
}
|
||||
|
||||
public void setElementList(List<E> elementList) {
|
||||
this.elementList = elementList;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T clone() {
|
||||
AbstractGroup group = (AbstractGroup) super.clone();
|
||||
group.elementList = cloneUtils.cloneList(this.elementList);
|
||||
return (T) group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractGroup that = (AbstractGroup) o;
|
||||
|
||||
return name.equals(that.name) && elementList.equals(that.elementList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.hashCode();
|
||||
result = 31 * result + elementList.hashCode();
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 设置元素集合
|
||||
*
|
||||
* @param elementList 元素集合
|
||||
*/
|
||||
void setElementList(List<E> elementList);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.sjhy.plugin.entity;
|
||||
|
||||
import com.sjhy.plugin.comm.CommClone;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 列配置信息
|
||||
|
@ -11,7 +11,8 @@ import lombok.Data;
|
|||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
@Data
|
||||
public class ColumnConfig extends CommClone<ColumnConfig> {
|
||||
@NoArgsConstructor
|
||||
public class ColumnConfig {
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,24 @@
|
|||
package com.sjhy.plugin.entity;
|
||||
|
||||
public class ColumnConfigGroup extends AbstractGroup<ColumnConfigGroup, ColumnConfig> {
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 列配置分组
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/18 09:33
|
||||
*/
|
||||
@Data
|
||||
public class ColumnConfigGroup implements AbstractGroup<ColumnConfig> {
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 元素对象
|
||||
*/
|
||||
private List<ColumnConfig> elementList;
|
||||
}
|
||||
|
|
|
@ -1,51 +1,29 @@
|
|||
package com.sjhy.plugin.entity;
|
||||
|
||||
import com.sjhy.plugin.comm.CommClone;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
public class Template extends CommClone<Template> {
|
||||
//模板名称
|
||||
/**
|
||||
* 模板信息类
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class Template {
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
private String name;
|
||||
//模板代码
|
||||
/**
|
||||
* 模板代码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
public Template() {
|
||||
}
|
||||
|
||||
public Template(String name, String code) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Template template = (Template) o;
|
||||
|
||||
return name.equals(template.name) && code.equals(template.code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.hashCode();
|
||||
result = 31 * result + code.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,24 @@
|
|||
package com.sjhy.plugin.entity;
|
||||
|
||||
public class TemplateGroup extends AbstractGroup<TemplateGroup, Template> {
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模板分组类
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/18 09:33
|
||||
*/
|
||||
@Data
|
||||
public class TemplateGroup implements AbstractGroup<Template> {
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 元素对象
|
||||
*/
|
||||
private List<Template> elementList;
|
||||
}
|
||||
|
|
|
@ -1,51 +1,29 @@
|
|||
package com.sjhy.plugin.entity;
|
||||
|
||||
import com.sjhy.plugin.comm.CommClone;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
public class TypeMapper extends CommClone<TypeMapper> {
|
||||
//列类型
|
||||
/**
|
||||
* 类型隐射信息
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class TypeMapper {
|
||||
/**
|
||||
* 列类型
|
||||
*/
|
||||
private String columnType;
|
||||
//java类型
|
||||
/**
|
||||
* java类型
|
||||
*/
|
||||
private String javaType;
|
||||
|
||||
public TypeMapper() {
|
||||
}
|
||||
|
||||
public TypeMapper(String columnType, String javaType) {
|
||||
this.columnType = columnType;
|
||||
this.javaType = javaType;
|
||||
}
|
||||
|
||||
public String getColumnType() {
|
||||
return columnType;
|
||||
}
|
||||
|
||||
public void setColumnType(String columnType) {
|
||||
this.columnType = columnType;
|
||||
}
|
||||
|
||||
public String getJavaType() {
|
||||
return javaType;
|
||||
}
|
||||
|
||||
public void setJavaType(String javaType) {
|
||||
this.javaType = javaType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
TypeMapper that = (TypeMapper) o;
|
||||
|
||||
return columnType.equals(that.columnType) && javaType.equals(that.javaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = columnType.hashCode();
|
||||
result = 31 * result + javaType.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,24 @@
|
|||
package com.sjhy.plugin.entity;
|
||||
|
||||
public class TypeMapperGroup extends AbstractGroup<TypeMapperGroup, TypeMapper> {
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类型映射分组
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
@Data
|
||||
public class TypeMapperGroup implements AbstractGroup<TypeMapper> {
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 元素对象
|
||||
*/
|
||||
private List<TypeMapper> elementList;
|
||||
}
|
||||
|
|
|
@ -1,43 +1,98 @@
|
|||
package com.sjhy.plugin.tool;
|
||||
|
||||
import com.sjhy.plugin.comm.CommClone;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sjhy.plugin.entity.AbstractGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 克隆工具类,实现原理通过JSON序列化反序列化实现
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
public class CloneUtils {
|
||||
//单例模式
|
||||
private static class Instance {
|
||||
private static final CloneUtils ME = new CloneUtils();
|
||||
}
|
||||
private volatile static CloneUtils cloneUtils;
|
||||
|
||||
/**
|
||||
* 单例模式
|
||||
*/
|
||||
public static CloneUtils getInstance() {
|
||||
return Instance.ME;
|
||||
if (cloneUtils == null) {
|
||||
synchronized (CloneUtils.class) {
|
||||
if (cloneUtils == null) {
|
||||
cloneUtils = new CloneUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
return cloneUtils;
|
||||
}
|
||||
|
||||
private CloneUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON处理工具类
|
||||
*/
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 实体对象克隆方法
|
||||
*
|
||||
* @param entity 实体对象
|
||||
* @return 克隆后的实体对象
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> E clone(E entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
//noinspection unchecked
|
||||
return objectMapper.readValue(objectMapper.writeValueAsString(entity), (Class<E>) entity.getClass());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private CloneUtils(){}
|
||||
|
||||
/**
|
||||
* List集合克隆方法
|
||||
*
|
||||
* @param src 源数据
|
||||
* @param <E> 继承克隆父类
|
||||
* @param <E> 实体类型
|
||||
* @return 克隆结果
|
||||
*/
|
||||
public <E extends CommClone<E>> List<E> cloneList(List<E> src) {
|
||||
if (src==null) {
|
||||
public <E> List<E> cloneList(List<E> src) {
|
||||
if (src == null) {
|
||||
return null;
|
||||
}
|
||||
List<E> result = new ArrayList<>(src.size());
|
||||
src.forEach(e -> result.add(e.clone()));
|
||||
src.forEach(e -> result.add(this.clone(e)));
|
||||
return result;
|
||||
}
|
||||
|
||||
public <K,E extends CommClone<E>> Map<K, E> cloneMap(Map<K, E> src) {
|
||||
if (src==null) {
|
||||
/**
|
||||
* Map集合克隆方法
|
||||
*
|
||||
* @param src 源数据
|
||||
* @param <K> 键类型
|
||||
* @param <E> 值类型
|
||||
* @return 克隆结果
|
||||
*/
|
||||
public <K, E> Map<K, E> cloneMap(Map<K, E> src) {
|
||||
if (src == null) {
|
||||
return null;
|
||||
}
|
||||
Map<K, E> result = new HashMap<>();
|
||||
src.forEach((k, e) -> result.put(k, e.clone()));
|
||||
Map<K, E> result;
|
||||
if (src instanceof LinkedHashMap) {
|
||||
result = new LinkedHashMap<>(src.size());
|
||||
} else {
|
||||
result = new HashMap<>(src.size());
|
||||
}
|
||||
src.forEach((k, e) -> result.put(k, this.clone(e)));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,79 +1,141 @@
|
|||
package com.sjhy.plugin.ui;
|
||||
|
||||
import com.intellij.openapi.ui.VerticalFlowLayout;
|
||||
import com.sjhy.plugin.comm.CommClone;
|
||||
import com.sjhy.plugin.entity.AbstractGroup;
|
||||
import com.sjhy.plugin.tool.CloneUtils;
|
||||
import com.sjhy.plugin.tool.ConfigInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class AbstractGroupPanel<T extends AbstractGroup<T, E>, E extends CommClone> {
|
||||
private JPanel mainPanel;
|
||||
private JComboBox groupComboBox;
|
||||
private JButton copyGroupButton;
|
||||
private JButton deleteGroupButton;
|
||||
private JButton addItemButton;
|
||||
private JButton deleteItemButton;
|
||||
private JButton copyItemButton;
|
||||
private JPanel itemGroupPanel;
|
||||
private JPanel itemPanel;
|
||||
/**
|
||||
* 抽象分组面板
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
public abstract class AbstractGroupPanel<T extends AbstractGroup<E>, E> {
|
||||
/**
|
||||
* 主面板
|
||||
*/
|
||||
protected JPanel mainPanel;
|
||||
/**
|
||||
* 分组下拉选择框
|
||||
*/
|
||||
protected JComboBox groupComboBox;
|
||||
/**
|
||||
* 复制按钮
|
||||
*/
|
||||
protected JButton copyGroupButton;
|
||||
/**
|
||||
* 删除按钮
|
||||
*/
|
||||
protected JButton deleteGroupButton;
|
||||
/**
|
||||
* 新增元素
|
||||
*/
|
||||
protected JButton addItemButton;
|
||||
/**
|
||||
* 删除元素
|
||||
*/
|
||||
protected JButton deleteItemButton;
|
||||
/**
|
||||
* 复制元素
|
||||
*/
|
||||
protected JButton copyItemButton;
|
||||
/**
|
||||
* 元素分组面板
|
||||
*/
|
||||
protected JPanel itemGroupPanel;
|
||||
/**
|
||||
* 元素面板
|
||||
*/
|
||||
protected JPanel itemPanel;
|
||||
|
||||
private Boolean initFlag = Boolean.FALSE;
|
||||
private int selectItemIndex;
|
||||
/**
|
||||
* 初始化标记
|
||||
*/
|
||||
protected Boolean initFlag = Boolean.FALSE;
|
||||
/**
|
||||
* 当前选中的元素下标索引值
|
||||
*/
|
||||
protected int selectItemIndex;
|
||||
|
||||
String currGroupName;
|
||||
/**
|
||||
* 当前分组名称
|
||||
*/
|
||||
protected String currGroupName;
|
||||
|
||||
Map<String, T> group;
|
||||
/**
|
||||
* 分组映射对象
|
||||
*/
|
||||
protected Map<String, T> group;
|
||||
|
||||
AbstractGroupPanel(Map<String, T> group, String selectGroupName) {
|
||||
itemGroupPanel.setLayout(new VerticalFlowLayout());
|
||||
itemPanel.setLayout(new GridLayout());
|
||||
initEvent();
|
||||
init(group, selectGroupName);
|
||||
}
|
||||
/**
|
||||
* 克隆工具类
|
||||
*/
|
||||
protected CloneUtils cloneUtils = CloneUtils.getInstance();
|
||||
|
||||
void init(Map<String, T> group, String selectGroupName) {
|
||||
/**
|
||||
* 构造方法
|
||||
* @param group 分组映射对象
|
||||
* @param selectGroupName 当前选中的分组名称
|
||||
*/
|
||||
public AbstractGroupPanel(Map<String, T> group, String selectGroupName) {
|
||||
this.group = group;
|
||||
this.currGroupName = selectGroupName;
|
||||
initFlag = Boolean.FALSE;
|
||||
//所有组名
|
||||
Set<String> groupNameSet = group.keySet();
|
||||
//选中组名称
|
||||
AbstractGroup<T, E> selectGroup = group.get(selectGroupName);
|
||||
// 设置布局
|
||||
itemGroupPanel.setLayout(new VerticalFlowLayout());
|
||||
itemPanel.setLayout(new GridLayout());
|
||||
// 初始化事件
|
||||
initEvent();
|
||||
// 初始化
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
initFlag = false;
|
||||
|
||||
//初始化所有组
|
||||
initGroup(groupNameSet, selectGroupName);
|
||||
initGroup();
|
||||
|
||||
//初始化所有元素
|
||||
initItem(selectGroup.getElementList());
|
||||
initItem();
|
||||
|
||||
|
||||
initFlag = Boolean.TRUE;
|
||||
initFlag = true;
|
||||
}
|
||||
|
||||
//初始化分组
|
||||
@SuppressWarnings("unchecked")
|
||||
private void initGroup(Set<String> groupNameSet, String selectGroupName) {
|
||||
/**
|
||||
* 初始化分组
|
||||
*/
|
||||
private void initGroup() {
|
||||
groupComboBox.removeAllItems();
|
||||
groupNameSet.forEach(groupComboBox::addItem);
|
||||
groupComboBox.setSelectedItem(selectGroupName);
|
||||
for (String groupName : group.keySet()) {
|
||||
//noinspection unchecked
|
||||
groupComboBox.addItem(groupName);
|
||||
}
|
||||
// 设置选中默认分组
|
||||
groupComboBox.setSelectedItem(currGroupName);
|
||||
}
|
||||
|
||||
//初始化所有元素
|
||||
private void initItem(List<E> itemList) {
|
||||
/**
|
||||
* 初始化所有元素
|
||||
*/
|
||||
private void initItem() {
|
||||
initFlag = false;
|
||||
//获取选中组的所有元素
|
||||
List<E> elementList = group.get(currGroupName).getElementList();
|
||||
itemGroupPanel.removeAll();
|
||||
if (itemList.isEmpty()) {
|
||||
if (elementList.isEmpty()) {
|
||||
itemGroupPanel.updateUI();
|
||||
initFlag = true;
|
||||
return;
|
||||
}
|
||||
itemList.forEach(item -> {
|
||||
elementList.forEach(item -> {
|
||||
JButton button = new JButton();
|
||||
button.setText(getItemName(item));
|
||||
//元素选中事件
|
||||
|
@ -83,8 +145,8 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T, E>, E extend
|
|||
return;
|
||||
}
|
||||
String itemName = button.getText();
|
||||
for (int i = 0; i < itemList.size(); i++) {
|
||||
E element = itemList.get(i);
|
||||
for (int i = 0; i < elementList.size(); i++) {
|
||||
E element = elementList.get(i);
|
||||
if (itemName.equals(getItemName(element))) {
|
||||
selectItemIndex = i;
|
||||
initItemPanel(itemPanel, element);
|
||||
|
@ -96,36 +158,40 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T, E>, E extend
|
|||
});
|
||||
itemGroupPanel.updateUI();
|
||||
//初始化第一个元素面板
|
||||
initItemPanel(itemPanel, itemList.get(selectItemIndex));
|
||||
initItemPanel(itemPanel, elementList.get(selectItemIndex));
|
||||
initFlag = true;
|
||||
}
|
||||
|
||||
//初始化所有事件
|
||||
/**
|
||||
* 初始化所有事件
|
||||
*/
|
||||
private void initEvent() {
|
||||
//切换分组事件
|
||||
groupComboBox.addActionListener(e -> {
|
||||
// 未初始化完成禁止切换分组
|
||||
if (!initFlag) {
|
||||
return;
|
||||
}
|
||||
String groupName = (String) groupComboBox.getSelectedItem();
|
||||
if (groupName == null) {
|
||||
if (StringUtils.isEmpty(groupName)) {
|
||||
return;
|
||||
}
|
||||
if (currGroupName.equals(groupName)) {
|
||||
return;
|
||||
}
|
||||
init(group, groupName);
|
||||
this.currGroupName = groupName;
|
||||
init();
|
||||
});
|
||||
|
||||
//复制分组事件
|
||||
copyGroupButton.addActionListener(e -> {
|
||||
// 未初始化禁止复制分组
|
||||
if (!initFlag) {
|
||||
return;
|
||||
}
|
||||
// 输入分组名称
|
||||
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName + " Copy");
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (value.trim().length() == 0) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
|
||||
return;
|
||||
}
|
||||
|
@ -133,37 +199,39 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T, E>, E extend
|
|||
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
|
||||
return;
|
||||
}
|
||||
//noinspection unchecked
|
||||
T groupItem = group.get(currGroupName).clone();
|
||||
// 克隆对象
|
||||
T groupItem = cloneUtils.clone(group.get(currGroupName));
|
||||
groupItem.setName(value);
|
||||
group.put(value, groupItem);
|
||||
init(group, value);
|
||||
currGroupName = value;
|
||||
init();
|
||||
});
|
||||
|
||||
//删除分组事件
|
||||
deleteGroupButton.addActionListener(e -> {
|
||||
if (!initFlag) {
|
||||
return;
|
||||
}
|
||||
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group " + currGroupName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (result == 0) {
|
||||
// 点击YES选项时
|
||||
if (JOptionPane.YES_OPTION == result) {
|
||||
if (ConfigInfo.DEFAULT_NAME.equals(currGroupName)) {
|
||||
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
|
||||
return;
|
||||
}
|
||||
group.remove(currGroupName);
|
||||
init(group, ConfigInfo.DEFAULT_NAME);
|
||||
currGroupName = ConfigInfo.DEFAULT_NAME;
|
||||
init();
|
||||
}
|
||||
});
|
||||
|
||||
//添加元素事件
|
||||
addItemButton.addActionListener(e -> {
|
||||
if (!initFlag) {
|
||||
return;
|
||||
}
|
||||
String value = JOptionPane.showInputDialog(null, "Input Item Name:", "Demo");
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (value.trim().length() == 0) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
|
||||
return;
|
||||
}
|
||||
|
@ -175,9 +243,11 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T, E>, E extend
|
|||
}
|
||||
}
|
||||
itemList.add(createItem(value));
|
||||
// 选中最后一个元素,即当前添加的元素
|
||||
selectItemIndex = itemList.size() - 1;
|
||||
initItem(itemList);
|
||||
initItem();
|
||||
});
|
||||
|
||||
//删除元素
|
||||
deleteItemButton.addActionListener(e -> {
|
||||
if (!initFlag) {
|
||||
|
@ -189,14 +259,16 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T, E>, E extend
|
|||
}
|
||||
String itemName = getItemName(itemList.get(selectItemIndex));
|
||||
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Item " + itemName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (result == 0) {
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
itemList.remove(selectItemIndex);
|
||||
if (selectItemIndex >= itemList.size()) {
|
||||
selectItemIndex = itemList.size() - 1;
|
||||
// 移步到当前删除元素的前一个元素
|
||||
if (selectItemIndex>0) {
|
||||
selectItemIndex--;
|
||||
}
|
||||
initItem(itemList);
|
||||
initItem();
|
||||
}
|
||||
});
|
||||
|
||||
//复制元素
|
||||
copyItemButton.addActionListener(e -> {
|
||||
if (!initFlag) {
|
||||
|
@ -216,60 +288,41 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T, E>, E extend
|
|||
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
|
||||
return;
|
||||
}
|
||||
//noinspection unchecked
|
||||
item = (E) item.clone();
|
||||
item = cloneUtils.clone(item);
|
||||
// 设置元素名称
|
||||
setItemName(item, value);
|
||||
itemList.add(item);
|
||||
// 移步至当前复制的元素
|
||||
selectItemIndex = itemList.size() - 1;
|
||||
initItem(itemList);
|
||||
initItem();
|
||||
});
|
||||
}
|
||||
|
||||
//初始化元素面板
|
||||
/**
|
||||
* 初始化元素面板
|
||||
* @param itemPanel 父面板
|
||||
* @param item 元素对象
|
||||
*/
|
||||
protected abstract void initItemPanel(JPanel itemPanel, E item);
|
||||
|
||||
//获取元素名称
|
||||
/**
|
||||
* 获取元素名称
|
||||
* @param item 元素对象
|
||||
* @return 元素名称
|
||||
*/
|
||||
protected abstract String getItemName(E item);
|
||||
|
||||
/**
|
||||
* 设置元素名称
|
||||
* @param item 元素对象
|
||||
* @param itemName 元素名称
|
||||
*/
|
||||
protected abstract void setItemName(E item, String itemName);
|
||||
|
||||
//创建元素
|
||||
/**
|
||||
* 创建元素
|
||||
* @param name 元素名称
|
||||
* @return 元素对象
|
||||
*/
|
||||
protected abstract E createItem(String name);
|
||||
|
||||
//所有元素Get方法
|
||||
JPanel getMainPanel() {
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
JComboBox getGroupComboBox() {
|
||||
return groupComboBox;
|
||||
}
|
||||
|
||||
JButton getCopyGroupButton() {
|
||||
return copyGroupButton;
|
||||
}
|
||||
|
||||
JButton getDeleteGroupButton() {
|
||||
return deleteGroupButton;
|
||||
}
|
||||
|
||||
JButton getAddItemButton() {
|
||||
return addItemButton;
|
||||
}
|
||||
|
||||
JButton getDeleteItemButton() {
|
||||
return deleteItemButton;
|
||||
}
|
||||
|
||||
JButton getCopyItemButton() {
|
||||
return copyItemButton;
|
||||
}
|
||||
|
||||
JPanel getItemGroupPanel() {
|
||||
return itemGroupPanel;
|
||||
}
|
||||
|
||||
JPanel getItemPanel() {
|
||||
return itemPanel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@ package com.sjhy.plugin.ui;
|
|||
|
||||
import com.intellij.ui.BooleanTableCellEditor;
|
||||
import com.intellij.util.ui.ComboBoxCellEditor;
|
||||
import com.sjhy.plugin.comm.CommClone;
|
||||
import com.sjhy.plugin.entity.AbstractGroup;
|
||||
import com.sjhy.plugin.entity.ColumnConfig;
|
||||
import com.sjhy.plugin.tool.CloneUtils;
|
||||
import com.sjhy.plugin.tool.ConfigInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
@ -19,31 +20,84 @@ import java.util.*;
|
|||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E extends CommClone> {
|
||||
public abstract class AbstractTableGroupPanel<T extends AbstractGroup<E>, E> {
|
||||
/**
|
||||
* 主面板
|
||||
*/
|
||||
private JPanel mainPanel;
|
||||
/**
|
||||
* 分组下拉选择框
|
||||
*/
|
||||
private JComboBox groupComboBox;
|
||||
/**
|
||||
* 表格
|
||||
*/
|
||||
private JTable table;
|
||||
/**
|
||||
* 分组按钮
|
||||
*/
|
||||
private JButton copyGroupButton;
|
||||
/**
|
||||
* 删除按钮
|
||||
*/
|
||||
private JButton deleteGroupButton;
|
||||
/**
|
||||
* 新增元素按钮
|
||||
*/
|
||||
private JButton addItemButton;
|
||||
/**
|
||||
* 新增元素按钮
|
||||
*/
|
||||
private JButton deleteItemButton;
|
||||
|
||||
/**
|
||||
* 列配置信息
|
||||
*/
|
||||
private ColumnConfig[] columnConfigInfo;
|
||||
|
||||
/**
|
||||
* 表模型
|
||||
*/
|
||||
private DefaultTableModel tableModel;
|
||||
|
||||
/**
|
||||
* 分组对象
|
||||
*/
|
||||
protected Map<String, T> group;
|
||||
/**
|
||||
* 当前分组名称
|
||||
*/
|
||||
protected String currGroupName;
|
||||
|
||||
/**
|
||||
* 初始化标记
|
||||
*/
|
||||
private boolean initFlag;
|
||||
/**
|
||||
* 克隆工具类
|
||||
*/
|
||||
protected CloneUtils cloneUtils = CloneUtils.getInstance();
|
||||
|
||||
|
||||
AbstractTableGroupPanel(Map<String, T> group, String currGroupName) {
|
||||
init(group, currGroupName);
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param group 分组对象
|
||||
* @param currGroupName 分组名称
|
||||
*/
|
||||
public AbstractTableGroupPanel(Map<String, T> group, String currGroupName) {
|
||||
this.group = group;
|
||||
this.currGroupName = currGroupName;
|
||||
init();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
protected AbstractGroup<T, E> getCurrGroup() {
|
||||
/**
|
||||
* 获取当前分组对象
|
||||
*
|
||||
* @return 当前分组对象
|
||||
*/
|
||||
protected T getCurrGroup() {
|
||||
return this.group.get(this.currGroupName);
|
||||
}
|
||||
|
||||
|
@ -73,12 +127,13 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
}
|
||||
}
|
||||
|
||||
protected void init(Map<String, T> group, String currGroupName) {
|
||||
this.group = group;
|
||||
this.currGroupName = currGroupName;
|
||||
/**
|
||||
* 初始化方法
|
||||
*/
|
||||
protected void init() {
|
||||
initFlag = false;
|
||||
//初始化分组
|
||||
initGroup(group.keySet(), currGroupName);
|
||||
initGroup();
|
||||
//初始化列
|
||||
columnConfigInfo = initColumn();
|
||||
tableModel = new DefaultTableModel();
|
||||
|
@ -95,20 +150,25 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
initFlag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化事件
|
||||
*/
|
||||
private void initEvent() {
|
||||
//切换分组事件
|
||||
groupComboBox.addActionListener(e -> {
|
||||
// 未初始化完成禁止切换分组
|
||||
if (!initFlag) {
|
||||
return;
|
||||
}
|
||||
String groupName = (String) groupComboBox.getSelectedItem();
|
||||
if (groupName == null) {
|
||||
if (StringUtils.isEmpty(groupName)) {
|
||||
return;
|
||||
}
|
||||
if (currGroupName.equals(groupName)) {
|
||||
return;
|
||||
}
|
||||
init(group, groupName);
|
||||
this.currGroupName = groupName;
|
||||
init();
|
||||
});
|
||||
//复制分组事件
|
||||
copyGroupButton.addActionListener(e -> {
|
||||
|
@ -116,10 +176,7 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
return;
|
||||
}
|
||||
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName + " Copy");
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (value.trim().length() == 0) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
|
||||
return;
|
||||
}
|
||||
|
@ -127,11 +184,12 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
|
||||
return;
|
||||
}
|
||||
//noinspection unchecked
|
||||
T groupItem = group.get(currGroupName).clone();
|
||||
// 克隆对象
|
||||
T groupItem = cloneUtils.clone(group.get(currGroupName));
|
||||
groupItem.setName(value);
|
||||
group.put(value, groupItem);
|
||||
init(group, value);
|
||||
currGroupName = value;
|
||||
init();
|
||||
});
|
||||
//删除分组事件
|
||||
deleteGroupButton.addActionListener(e -> {
|
||||
|
@ -139,13 +197,14 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
return;
|
||||
}
|
||||
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group " + currGroupName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (result == 0) {
|
||||
if (JOptionPane.YES_OPTION == result) {
|
||||
if (ConfigInfo.DEFAULT_NAME.equals(currGroupName)) {
|
||||
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
|
||||
return;
|
||||
}
|
||||
group.remove(currGroupName);
|
||||
init(group, ConfigInfo.DEFAULT_NAME);
|
||||
currGroupName = ConfigInfo.DEFAULT_NAME;
|
||||
init();
|
||||
}
|
||||
});
|
||||
//添加元素事件
|
||||
|
@ -154,10 +213,7 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
return;
|
||||
}
|
||||
String value = JOptionPane.showInputDialog(null, "Input Item Name:", "Demo");
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (value.trim().length() == 0) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
|
||||
return;
|
||||
}
|
||||
|
@ -169,7 +225,7 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
}
|
||||
}
|
||||
itemList.add(createItem(value));
|
||||
init(group, currGroupName);
|
||||
init();
|
||||
});
|
||||
//删除元素
|
||||
deleteItemButton.addActionListener(e -> {
|
||||
|
@ -191,15 +247,22 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
});
|
||||
}
|
||||
|
||||
//初始化分组
|
||||
@SuppressWarnings("unchecked")
|
||||
private void initGroup(Set<String> groupNameSet, String selectGroupName) {
|
||||
/**
|
||||
* 初始化分组
|
||||
*/
|
||||
private void initGroup() {
|
||||
groupComboBox.removeAllItems();
|
||||
groupNameSet.forEach(groupComboBox::addItem);
|
||||
groupComboBox.setSelectedItem(selectGroupName);
|
||||
Set<String> groupNameSet = group.keySet();
|
||||
for (String groupName : groupNameSet) {
|
||||
//noinspection unchecked
|
||||
groupComboBox.addItem(groupName);
|
||||
}
|
||||
groupComboBox.setSelectedItem(currGroupName);
|
||||
}
|
||||
|
||||
//用于数据回绑定
|
||||
/**
|
||||
* 刷新,用于数据回绑定
|
||||
*/
|
||||
protected void refresh() {
|
||||
if (tableModel == null) {
|
||||
return;
|
||||
|
@ -227,16 +290,50 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E e
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 元素转行数据
|
||||
*
|
||||
* @param item 元素对象
|
||||
* @return 行数据
|
||||
*/
|
||||
protected abstract Object[] toRow(E item);
|
||||
|
||||
/**
|
||||
* 行数据转元素
|
||||
*
|
||||
* @param rowData 行数据
|
||||
* @return 元素对象
|
||||
*/
|
||||
protected abstract E toItem(Object[] rowData);
|
||||
|
||||
/**
|
||||
* 获取元素名称
|
||||
*
|
||||
* @param item 元素
|
||||
* @return 元素名称
|
||||
*/
|
||||
protected abstract String getItemName(E item);
|
||||
|
||||
protected abstract E createItem(String value);
|
||||
/**
|
||||
* 创建元素
|
||||
*
|
||||
* @param name 元素名称
|
||||
* @return 元素对象
|
||||
*/
|
||||
protected abstract E createItem(String name);
|
||||
|
||||
/**
|
||||
* 初始化列配置
|
||||
*
|
||||
* @return 列配置数组
|
||||
*/
|
||||
protected abstract ColumnConfig[] initColumn();
|
||||
|
||||
/**
|
||||
* 获取主面板对象
|
||||
*
|
||||
* @return 主面板对象
|
||||
*/
|
||||
public JPanel getMainPanel() {
|
||||
return mainPanel;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,13 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* 表设置面板
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
public class TableSettingPanel extends AbstractTableGroupPanel<ColumnConfigGroup, ColumnConfig> implements Configurable {
|
||||
private ConfigInfo configInfo = ConfigInfo.getInstance();
|
||||
private CloneUtils cloneUtils = CloneUtils.getInstance();
|
||||
|
@ -74,6 +81,8 @@ public class TableSettingPanel extends AbstractTableGroupPanel<ColumnConfigGroup
|
|||
|
||||
@Override
|
||||
public void reset() {
|
||||
init(cloneUtils.cloneMap(configInfo.getColumnConfigGroupMap()), configInfo.getCurrColumnConfigGroupName());
|
||||
this.group = cloneUtils.cloneMap(configInfo.getColumnConfigGroupMap());
|
||||
this.currGroupName = configInfo.getCurrColumnConfigGroupName();
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,6 @@ public class TemplateSettingPanel extends AbstractGroupPanel<TemplateGroup, Temp
|
|||
* 配置信息
|
||||
*/
|
||||
private ConfigInfo configInfo = ConfigInfo.getInstance();
|
||||
/**
|
||||
* 对象克隆工具
|
||||
*/
|
||||
private CloneUtils cloneUtils = CloneUtils.getInstance();
|
||||
/**
|
||||
* 编辑框面板
|
||||
*/
|
||||
|
@ -34,18 +30,20 @@ public class TemplateSettingPanel extends AbstractGroupPanel<TemplateGroup, Temp
|
|||
/**
|
||||
* 默认构造方法
|
||||
*/
|
||||
TemplateSettingPanel() {
|
||||
public TemplateSettingPanel() {
|
||||
super(CloneUtils.getInstance().cloneMap(ConfigInfo.getInstance().getTemplateGroupMap()), ConfigInfo.getInstance().getCurrTemplateGroupName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换模板编辑时
|
||||
*
|
||||
* @param itemPanel 面板对象
|
||||
* @param item 模板对象
|
||||
* @param item 模板对象
|
||||
*/
|
||||
@Override
|
||||
protected void initItemPanel(JPanel itemPanel, Template item) {
|
||||
if (editTemplatePanel!=null) {
|
||||
// 如果编辑面板已经实例化,需要选释放后再初始化
|
||||
if (editTemplatePanel != null) {
|
||||
editTemplatePanel.disposeEditor();
|
||||
}
|
||||
itemPanel.removeAll();
|
||||
|
@ -69,18 +67,33 @@ public class TemplateSettingPanel extends AbstractGroupPanel<TemplateGroup, Temp
|
|||
return new Template(name, "Demo!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置显示的名称
|
||||
*
|
||||
* @return 名称
|
||||
*/
|
||||
@Nls
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Template Setting";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主面板对象
|
||||
*
|
||||
* @return 主面板对象
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return getMainPanel();
|
||||
return super.mainPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置是否修改过
|
||||
*
|
||||
* @return 是否修改过
|
||||
*/
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
editTemplatePanel.refresh();
|
||||
|
@ -101,7 +114,10 @@ public class TemplateSettingPanel extends AbstractGroupPanel<TemplateGroup, Temp
|
|||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
init(cloneUtils.cloneMap(configInfo.getTemplateGroupMap()), configInfo.getCurrTemplateGroupName());
|
||||
// 防止对象篡改,需要进行克隆
|
||||
super.group = cloneUtils.cloneMap(configInfo.getTemplateGroupMap());
|
||||
super.currGroupName = configInfo.getCurrTemplateGroupName();
|
||||
super.init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,51 +4,89 @@ import com.intellij.openapi.options.Configurable;
|
|||
import com.sjhy.plugin.entity.TypeMapper;
|
||||
import com.sjhy.plugin.entity.TypeMapperGroup;
|
||||
import com.sjhy.plugin.entity.TypeMapperModel;
|
||||
import com.sjhy.plugin.tool.CloneUtils;
|
||||
import com.sjhy.plugin.tool.ConfigInfo;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 类型映射设置
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
public class TypeMapperSetting implements Configurable {
|
||||
//主面板
|
||||
/**
|
||||
* 主面板
|
||||
*/
|
||||
private JPanel mainPanel;
|
||||
//类型映射分组切换下拉框
|
||||
/**
|
||||
* 类型映射分组切换下拉框
|
||||
*/
|
||||
private JComboBox typeMapperComboBox;
|
||||
//分组复制按钮
|
||||
/**
|
||||
* 分组复制按钮
|
||||
*/
|
||||
private JButton typeMapperCopyButton;
|
||||
//类型映射表
|
||||
/**
|
||||
* 类型映射表
|
||||
*/
|
||||
private JTable typeMapperTable;
|
||||
//添加映射按钮
|
||||
/**
|
||||
* 添加映射按钮
|
||||
*/
|
||||
private JButton addButton;
|
||||
//移除映射按钮
|
||||
/**
|
||||
* 移除映射按钮
|
||||
*/
|
||||
private JButton removeButton;
|
||||
//删除分组按钮
|
||||
/**
|
||||
* 删除分组按钮
|
||||
*/
|
||||
private JButton deleteButton;
|
||||
|
||||
//是否初始化完成
|
||||
/**
|
||||
* 是否初始化完成
|
||||
*/
|
||||
private boolean init;
|
||||
//类型映射表模型
|
||||
/**
|
||||
* 类型映射表模型
|
||||
*/
|
||||
private TypeMapperModel typeMapperModel;
|
||||
|
||||
//当前选中分组
|
||||
/**
|
||||
* 当前选中分组
|
||||
*/
|
||||
private String currGroupName;
|
||||
//类型映射分组集合
|
||||
/**
|
||||
* 类型映射分组集合
|
||||
*/
|
||||
private Map<String, TypeMapperGroup> typeMapperGroupMap;
|
||||
//全局配置服务
|
||||
/**
|
||||
* 全局配置服务
|
||||
*/
|
||||
private ConfigInfo configInfo;
|
||||
/**
|
||||
* 克隆工具类
|
||||
*/
|
||||
private CloneUtils cloneUtils = CloneUtils.getInstance();
|
||||
|
||||
|
||||
TypeMapperSetting(ConfigInfo configInfo) {
|
||||
public TypeMapperSetting(ConfigInfo configInfo) {
|
||||
this.configInfo = configInfo;
|
||||
this.typeMapperGroupMap = cloneUtils.cloneMap(configInfo.getTypeMapperGroupMap());
|
||||
this.currGroupName = configInfo.getCurrTypeMapperGroupName();
|
||||
//添加类型
|
||||
addButton.addActionListener(e -> typeMapperModel.addRow(new TypeMapper("demoColumn", "java.lang.Object")));
|
||||
|
||||
//移除类型
|
||||
removeButton.addActionListener(e -> {
|
||||
int[] selectRows = typeMapperTable.getSelectedRows();
|
||||
// 从后面往前面移除,防止下标错位问题。
|
||||
for (int i = selectRows.length - 1; i >= 0; i--) {
|
||||
typeMapperModel.removeRow(selectRows[i]);
|
||||
}
|
||||
|
@ -84,7 +122,8 @@ public class TypeMapperSetting implements Configurable {
|
|||
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
|
||||
return;
|
||||
}
|
||||
TypeMapperGroup typeMapperGroup = typeMapperGroupMap.get(currGroupName).clone();
|
||||
// 克隆对象
|
||||
TypeMapperGroup typeMapperGroup = cloneUtils.clone(typeMapperGroupMap.get(currGroupName));
|
||||
typeMapperGroup.setName(value);
|
||||
typeMapperGroupMap.put(value, typeMapperGroup);
|
||||
currGroupName = value;
|
||||
|
@ -105,6 +144,7 @@ public class TypeMapperSetting implements Configurable {
|
|||
}
|
||||
});
|
||||
|
||||
// 初始化操作
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -113,13 +153,6 @@ public class TypeMapperSetting implements Configurable {
|
|||
* 初始化方法
|
||||
*/
|
||||
private void init() {
|
||||
//复制数据
|
||||
this.typeMapperGroupMap = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, TypeMapperGroup> entry : configInfo.getTypeMapperGroupMap().entrySet()) {
|
||||
this.typeMapperGroupMap.put(entry.getKey(), entry.getValue().clone());
|
||||
}
|
||||
this.currGroupName = configInfo.getCurrTypeMapperGroupName();
|
||||
|
||||
//初始化表格
|
||||
this.typeMapperModel = new TypeMapperModel();
|
||||
this.typeMapperTable.setModel(typeMapperModel);
|
||||
|
@ -129,11 +162,11 @@ public class TypeMapperSetting implements Configurable {
|
|||
/**
|
||||
* 刷新方法
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void refresh() {
|
||||
init = false;
|
||||
//初始化下拉框
|
||||
this.typeMapperComboBox.removeAllItems();
|
||||
//noinspection unchecked
|
||||
typeMapperGroupMap.keySet().forEach(this.typeMapperComboBox::addItem);
|
||||
this.typeMapperComboBox.setSelectedItem(this.currGroupName);
|
||||
this.typeMapperModel.init(this.typeMapperGroupMap.get(currGroupName).getElementList());
|
||||
|
|
|
@ -23,9 +23,8 @@
|
|||
<!-- uncomment to enable plugin in all products
|
||||
<depends>com.intellij.modules.lang</depends>
|
||||
-->
|
||||
<depends>com.intellij.modules.lang</depends>
|
||||
<!--必须运行在企业版-->
|
||||
<depends optional="true">com.intellij.modules.ultimate</depends>
|
||||
<depends>com.intellij.modules.ultimate</depends>
|
||||
<!--必须存在database插件-->
|
||||
<!--suppress PluginXmlValidity -->
|
||||
<depends optional="true">com.intellij.database</depends>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.sjhy.plugin;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/07/18 17:35
|
||||
*/
|
||||
public class MinTest {
|
||||
@Test
|
||||
public void run() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue