Merge branch 'dev'

This commit is contained in:
makejava 2018-08-02 18:13:25 +08:00
commit 5d674ecb83
17 changed files with 305 additions and 192 deletions

View File

@ -17,7 +17,7 @@ apply plugin: 'idea'
apply plugin: 'org.jetbrains.intellij'
group 'com.sjhy'
version '1.1.1-SNAPSHOT'
version '1.1.2-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -29,6 +29,7 @@ repositories {
dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.6'
// compile group: 'org.apache.velocity', name: 'velocity', version: '1.7'
testCompile group: 'junit', name: 'junit', version: '4.12'
compileOnly "org.projectlombok:lombok:1.18.0"
// compileClasspath fileTree(dir: 'lib', includes: ['*.jar'])

View File

@ -0,0 +1,15 @@
package com.sjhy.plugin.constants;
/**
* 消息常量值
*
* @author makejava
* @version 1.0.0
* @since 2018/08/02 11:55
*/
public class MsgValue {
/**
* 提示信息
*/
public static final String TITLE_INFO = "EasyCode Title Info";
}

View File

@ -1,7 +1,7 @@
package com.sjhy.plugin.tool;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sjhy.plugin.entity.AbstractGroup;
import com.intellij.util.ExceptionUtil;
import java.io.IOException;
import java.util.*;
@ -52,7 +52,7 @@ public class CloneUtils {
//noinspection unchecked
return objectMapper.readValue(objectMapper.writeValueAsString(entity), (Class<E>) entity.getClass());
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
return null;
}

View File

@ -1,18 +1,20 @@
package com.sjhy.plugin.tool;
import com.intellij.openapi.components.*;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.intellij.util.xmlb.annotations.Transient;
import com.sjhy.plugin.entity.*;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 全局配置信息
@ -111,9 +113,8 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
if (this.templateGroupMap == null) {
this.templateGroupMap = new LinkedHashMap<>();
}
for (String groupName : new String[]{DEFAULT_NAME, "MybatisPlus"}) {
this.templateGroupMap.put(groupName, loadTemplateGroup(groupName));
}
this.templateGroupMap.put(DEFAULT_NAME, loadTemplateGroup(DEFAULT_NAME, "entity", "dao", "service", "serviceImpl", "controller"));
this.templateGroupMap.put("MybatisPlus", loadTemplateGroup(DEFAULT_NAME, "entity", "dao", "service", "serviceImpl", "controller"));
//配置默认类型映射
if (this.typeMapperGroupMap == null) {
@ -151,9 +152,7 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
if (this.globalConfigGroupMap == null) {
this.globalConfigGroupMap = new LinkedHashMap<>();
}
for (String groupName : new String[]{DEFAULT_NAME}) {
this.globalConfigGroupMap.put(groupName, loadGlobalConfigGroup(groupName));
}
this.globalConfigGroupMap.put(DEFAULT_NAME, loadGlobalConfigGroup(DEFAULT_NAME, "init", "define", "autoImport"));
}
/**
@ -169,35 +168,17 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
/**
* 加载模板组
*
* @param groupName 组名
* @param groupName 组名
* @param templateNames 模板名称
* @return 模板组
*/
private static TemplateGroup loadTemplateGroup(String groupName) {
private static TemplateGroup loadTemplateGroup(String groupName, String... templateNames) {
TemplateGroup templateGroup = new TemplateGroup();
templateGroup.setName(groupName);
templateGroup.setElementList(new ArrayList<>());
// 获取jar中的文件名
String path = ConfigInfo.class.getResource("/template").getPath();
String jarFileName = path.substring(6, path.indexOf("!"));
try (JarFile jarFile = new JarFile(jarFileName)) {
// 遍历JAR文件
Enumeration<JarEntry> entries = jarFile.entries();
String prefix = "template/" + groupName;
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
// 目录跳过
if (jarEntry.isDirectory()) {
continue;
}
String name = jarEntry.getName();
if (name.startsWith(prefix)) {
String templatePath = "/" + name;
name = name.substring(name.lastIndexOf("/") + 1, name.length() - 3);
templateGroup.getElementList().add(new Template(name, loadTemplate(templatePath)));
}
}
} catch (IOException e) {
e.printStackTrace();
for (String templateName : templateNames) {
String path = "/template/" + groupName + "/" + templateName + ".vm";
templateGroup.getElementList().add(new Template(templateName, loadTemplate(path)));
}
return templateGroup;
}
@ -205,35 +186,17 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
/**
* 加载全局配置组
*
* @param groupName 组名
* @param groupName 组名
* @param templateNames 模板名称
* @return 模板组
*/
private static GlobalConfigGroup loadGlobalConfigGroup(String groupName) {
private static GlobalConfigGroup loadGlobalConfigGroup(String groupName, String... templateNames) {
GlobalConfigGroup globalConfigGroup = new GlobalConfigGroup();
globalConfigGroup.setName(groupName);
globalConfigGroup.setElementList(new ArrayList<>());
// 获取jar中的文件名
String path = ConfigInfo.class.getResource("/globalConfig").getPath();
String jarFileName = path.substring(6, path.indexOf("!"));
try (JarFile jarFile = new JarFile(jarFileName)) {
// 遍历JAR文件
Enumeration<JarEntry> entries = jarFile.entries();
String prefix = "globalConfig/" + groupName;
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
// 目录跳过
if (jarEntry.isDirectory()) {
continue;
}
String name = jarEntry.getName();
if (name.startsWith(prefix)) {
String templatePath = "/" + name;
name = name.substring(name.lastIndexOf("/") + 1, name.length() - 3);
globalConfigGroup.getElementList().add(new GlobalConfig(name, loadTemplate(templatePath)));
}
}
} catch (IOException e) {
e.printStackTrace();
for (String templateName : templateNames) {
String path = "/globalConfig/" + groupName + "/" + templateName + ".vm";
globalConfigGroup.getElementList().add(new GlobalConfig(templateName, loadTemplate(path)));
}
return globalConfigGroup;
}
@ -253,7 +216,7 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
XmlSerializerUtil.copyBean(configInfo, this);
// 已经合并不再重复合并
if (configInfo.getVersion()!=null && configInfo.getVersion().equals(version)) {
if (configInfo.getVersion() != null && configInfo.getVersion().equals(version)) {
return;
}

View File

@ -1,6 +1,7 @@
package com.sjhy.plugin.tool;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ExceptionUtil;
import java.io.File;
import java.io.IOException;
@ -43,7 +44,7 @@ public class FileUtils {
try {
builder.append(FileUtil.loadFileText(file, "UTF-8"));
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
return builder.toString();
}
@ -58,13 +59,13 @@ public class FileUtils {
byte[] temp = FileUtil.loadBytes(in);
return new String(temp, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
}
}
@ -90,7 +91,7 @@ public class FileUtils {
try {
FileUtil.writeToFile(file, content, append);
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
}
}

View File

@ -5,9 +5,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.intellij.database.model.DasColumn;
import com.intellij.database.psi.DbTable;
import com.intellij.database.util.DasUtil;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.containers.JBIterable;
import com.sjhy.plugin.comm.AbstractService;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.entity.ColumnInfo;
import com.sjhy.plugin.entity.TableInfo;
import com.sjhy.plugin.entity.TypeMapper;
@ -182,7 +185,7 @@ public class TableInfoUtils extends AbstractService {
}
}
//弹出消息框
JOptionPane.showMessageDialog(null, "发现未知类型:" + typeName, "温馨提示", JOptionPane.PLAIN_MESSAGE);
Messages.showWarningDialog("发现未知类型:" + typeName, MsgValue.TITLE_INFO);
return "java.lang.Object";
}
@ -219,10 +222,10 @@ public class TableInfoUtils extends AbstractService {
try {
content = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(tableInfo);
} catch (JsonProcessingException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
if (content == null) {
JOptionPane.showMessageDialog(null, "保存失败JSON序列化错误。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
Messages.showWarningDialog("保存失败JSON序列化错误。", MsgValue.TITLE_INFO);
return;
}
// 获取或创建保存目录
@ -230,7 +233,7 @@ public class TableInfoUtils extends AbstractService {
File dir = new File(path);
if (!dir.exists()) {
if (!dir.mkdir()) {
JOptionPane.showMessageDialog(null, "保存失败,无法创建目录。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
Messages.showWarningDialog("保存失败,无法创建目录。", MsgValue.TITLE_INFO);
return;
}
}
@ -241,12 +244,12 @@ public class TableInfoUtils extends AbstractService {
if (!file.exists()) {
try {
if (!file.createNewFile()) {
JOptionPane.showMessageDialog(null, "保存失败,无法创建文件。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
Messages.showWarningDialog("保存失败,无法创建文件。", MsgValue.TITLE_INFO);
return;
}
} catch (IOException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "保存失败,创建文件异常。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
ExceptionUtil.rethrow(e);
Messages.showWarningDialog("保存失败,创建文件异常。", MsgValue.TITLE_INFO);
return;
}
}
@ -290,8 +293,8 @@ public class TableInfoUtils extends AbstractService {
try {
return objectMapper.readValue(str, TableInfo.class);
} catch (IOException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "读取配置失败JSON反序列化异常。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
ExceptionUtil.rethrow(e);
Messages.showWarningDialog("读取配置失败JSON反序列化异常。", MsgValue.TITLE_INFO);
}
return null;
}

View File

@ -1,7 +1,11 @@
package com.sjhy.plugin.tool;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.ExceptionUtil;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.entity.Callback;
import com.sjhy.plugin.entity.GlobalConfig;
import com.sjhy.plugin.entity.TableInfo;
@ -9,15 +13,13 @@ import com.sjhy.plugin.entity.Template;
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Velocity工具类主要用于代码生成
@ -48,6 +50,9 @@ public class VelocityUtils {
*/
private VelocityUtils() {
velocityEngine = new VelocityEngine();
// 修复部分用户的velocity日志记录无权访问velocity.log文件问题
velocityEngine.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute" );
velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", "velocity");
}
/**
@ -124,7 +129,17 @@ public class VelocityUtils {
map.put("packageName", cacheDataUtils.getPackageName());
if (selectModule != null) {
//module绝对路径
map.put("modulePath", new File(selectModule.getModuleFilePath()).getParent());
String modulePath = new File(selectModule.getModuleFilePath()).getParent();
if (modulePath != null) {
// 兼容Linux
modulePath = modulePath.replace("\\", "/");
// 针对Mac版路径做优化
if (modulePath.contains("/.idea")) {
modulePath = modulePath.substring(0, modulePath.indexOf("/.idea"));
}
}
map.put("modulePath", modulePath);
map.put("moduleName", selectModule.getName());
}
// 项目路径
@ -142,8 +157,7 @@ public class VelocityUtils {
private boolean createPath(String savePath) {
File path = new File(savePath);
if (!new File(savePath).exists()) {
int result = JOptionPane.showConfirmDialog(null, "Save Path Is Not Exists, Confirm Create?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result == 0) {
if (MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Save Path Is Not Exists, Confirm Create?").isYes()) {
if (!path.mkdirs()) {
return false;
}
@ -152,7 +166,7 @@ public class VelocityUtils {
}
}
if (path.isFile()) {
JOptionPane.showMessageDialog(null, "Error,Save Path Is File!");
Messages.showMessageDialog("Error,Save Path Is File!", MsgValue.TITLE_INFO, Messages.getErrorIcon());
return false;
}
return true;
@ -167,19 +181,19 @@ public class VelocityUtils {
private boolean coverFile(File file) {
if (file.exists()) {
if (file.isDirectory()) {
JOptionPane.showMessageDialog(null, "Error,Save File Is Path!");
Messages.showMessageDialog("Error,Save File Is Path!", MsgValue.TITLE_INFO, Messages.getErrorIcon());
return false;
}
// 是否覆盖
int result = JOptionPane.showConfirmDialog(null, "File " + file.getName() + " Exists, Confirm Continue?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
return result == 0;
return MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "File " + file.getName() + " Exists, Confirm Continue?").isYes();
} else {
try {
if (!file.createNewFile()) {
return false;
}
} catch (IOException e) {
e.printStackTrace();
// 直接抛出异常
ExceptionUtil.rethrow(e);
return false;
}
}
@ -255,7 +269,7 @@ public class VelocityUtils {
fileUtils.write(file, content);
});
});
JOptionPane.showMessageDialog(null, "Code Generate Success!");
Messages.showMessageDialog("Code Generate Successful!", MsgValue.TITLE_INFO, Messages.getInformationIcon());
//刷新整个项目
VirtualFileManager.getInstance().syncRefresh();
}
@ -286,12 +300,18 @@ public class VelocityUtils {
cacheDataUtils.setSavePath(savePath);
}
String projectPath = cacheDataUtils.getProject().getBasePath();
if (savePath.indexOf(projectPath) == 0) {
savePath = savePath.substring(projectPath.length());
if (savePath.startsWith("/")) {
savePath = "." + savePath;
} else {
savePath = "./" + savePath;
if (projectPath!=null) {
// 兼容Linux路径
if (projectPath.contains("\\")) {
projectPath = projectPath.replace("\\", "/");
}
if (savePath.indexOf(projectPath) == 0) {
savePath = savePath.substring(projectPath.length());
if (savePath.startsWith("/")) {
savePath = "." + savePath;
} else {
savePath = "./" + savePath;
}
}
}

View File

@ -1,6 +1,10 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.entity.AbstractGroup;
import com.sjhy.plugin.tool.CloneUtils;
import com.sjhy.plugin.tool.ConfigInfo;
@ -195,21 +199,24 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<E>, E> {
return;
}
// 输入分组名称
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName + " Copy");
String value = Messages.showInputDialog("Group Name:", "Input Group Name", Messages.getQuestionIcon(), currGroupName + "Copy", new InputValidator() {
@Override
public boolean checkInput(String inputString) {
// 要求非空并且不存在
return !StringUtils.isEmpty(inputString) && !group.containsKey(inputString);
}
@Override
public boolean canClose(String inputString) {
return this.checkInput(inputString);
}
});
// 取消复制不需要提示信息
if (value == null) {
return;
}
if (StringUtils.isEmpty(value)) {
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
return;
}
if (group.containsKey(value)) {
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
return;
}
// 克隆对象
T groupItem = cloneUtils.clone(group.get(currGroupName));
groupItem.setName(value);
@ -223,11 +230,10 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<E>, E> {
if (!initFlag) {
return;
}
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group " + currGroupName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
// 点击YES选项时
if (JOptionPane.YES_OPTION == result) {
if (MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Confirm Delete Group " + currGroupName + "?").isYes()) {
if (ConfigInfo.DEFAULT_NAME.equals(currGroupName)) {
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
Messages.showWarningDialog("Can't Delete Default Group!", MsgValue.TITLE_INFO);
return;
}
group.remove(currGroupName);
@ -241,22 +247,32 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<E>, E> {
if (!initFlag) {
return;
}
String value = JOptionPane.showInputDialog(null, "Input Item Name:", "Demo");
List<E> itemList = group.get(currGroupName).getElementList();
String value = Messages.showInputDialog("Item Name:", "Input Item Name", Messages.getQuestionIcon(), "Demo", new InputValidator() {
@Override
public boolean checkInput(String inputString) {
//输入空字符串
if (StringUtils.isEmpty(inputString)) {
return false;
}
//已经存在
for (E item : itemList) {
if (getItemName(item).equals(inputString)) {
return false;
}
}
return true;
}
@Override
public boolean canClose(String inputString) {
return this.checkInput(inputString);
}
});
// 取消添加不需要提示信息
if (value == null) {
return;
}
if (StringUtils.isEmpty(value)) {
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
return;
}
List<E> itemList = group.get(currGroupName).getElementList();
for (E item : itemList) {
if (getItemName(item).equals(value)) {
JOptionPane.showMessageDialog(null, "Item Name Already exist!");
return;
}
}
itemList.add(createItem(value));
// 选中最后一个元素即当前添加的元素
selectItemIndex = itemList.size() - 1;
@ -273,8 +289,7 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<E>, E> {
return;
}
String itemName = getItemName(itemList.get(selectItemIndex));
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Item " + itemName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.YES_OPTION) {
if (MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Confirm Delete Item " + itemName + "?").isYes()) {
itemList.remove(selectItemIndex);
// 移步到当前删除元素的前一个元素
if (selectItemIndex > 0) {
@ -295,15 +310,31 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<E>, E> {
}
E item = itemList.get(selectItemIndex);
String itemName = getItemName(item);
String value = JOptionPane.showInputDialog(null, "Input Item Name:", itemName + " Copy");
String value = Messages.showInputDialog("Item Name:", "Input Item Name", Messages.getQuestionIcon(), itemName + "Copy", new InputValidator() {
@Override
public boolean checkInput(String inputString) {
//输入空字符串
if (StringUtils.isEmpty(inputString)) {
return false;
}
//已经存在
for (E item : itemList) {
if (getItemName(item).equals(inputString)) {
return false;
}
}
return true;
}
@Override
public boolean canClose(String inputString) {
return this.checkInput(inputString);
}
});
// 取消复制不需要提示信息
if (value == null) {
return;
}
if (value.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
return;
}
item = cloneUtils.clone(item);
// 设置元素名称
setItemName(item, value);

View File

@ -1,7 +1,11 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.Messages;
import com.intellij.ui.BooleanTableCellEditor;
import com.intellij.util.ui.ComboBoxCellEditor;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.entity.AbstractGroup;
import com.sjhy.plugin.entity.ColumnConfig;
import com.sjhy.plugin.tool.CloneUtils;
@ -176,21 +180,24 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<E>, E> {
if (!initFlag) {
return;
}
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName + " Copy");
//输入分组名称
String value = Messages.showInputDialog("Group Name:", "Input Group Name:", Messages.getQuestionIcon(), currGroupName + " Copy", new InputValidator() {
@Override
public boolean checkInput(String inputString) {
//非空并且不存在分组名称
return !StringUtils.isEmpty(inputString) && !group.containsKey(inputString);
}
@Override
public boolean canClose(String inputString) {
return this.checkInput(inputString);
}
});
// 取消复制不需要提示信息
if (value == null) {
return;
}
if (StringUtils.isEmpty(value)) {
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
return;
}
if (group.containsKey(value)) {
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
return;
}
// 克隆对象
T groupItem = cloneUtils.clone(group.get(currGroupName));
groupItem.setName(value);
@ -203,10 +210,9 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<E>, E> {
if (!initFlag) {
return;
}
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group " + currGroupName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (JOptionPane.YES_OPTION == result) {
if (MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Confirm Delete Group " + currGroupName + "?").isYes()) {
if (ConfigInfo.DEFAULT_NAME.equals(currGroupName)) {
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
Messages.showWarningDialog("Can't Delete Default Group!", MsgValue.TITLE_INFO);
return;
}
group.remove(currGroupName);
@ -219,22 +225,32 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<E>, E> {
if (!initFlag) {
return;
}
String value = JOptionPane.showInputDialog(null, "Input Item Name:", "Demo");
List<E> itemList = group.get(currGroupName).getElementList();
// 输入名称
String value = Messages.showInputDialog("Item Name:", "Input Item Name", Messages.getQuestionIcon(), "Demo", new InputValidator() {
@Override
public boolean checkInput(String inputString) {
if (StringUtils.isEmpty(inputString)) {
return false;
}
for (E item : itemList) {
if (getItemName(item).equals(inputString)) {
return false;
}
}
return true;
}
@Override
public boolean canClose(String inputString) {
return this.checkInput(inputString);
}
});
// 取消添加不需要提示信息
if (value == null) {
return;
}
if (StringUtils.isEmpty(value)) {
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
return;
}
List<E> itemList = group.get(currGroupName).getElementList();
for (E item : itemList) {
if (getItemName(item).equals(value)) {
JOptionPane.showMessageDialog(null, "Item Name Already exist!");
return;
}
}
itemList.add(createItem(value));
init();
});
@ -247,8 +263,7 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<E>, E> {
if (itemList.isEmpty()) {
return;
}
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Selected Item?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result == 0) {
if (MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Confirm Delete Selected Item?").isYes()) {
int[] rows = table.getSelectedRows();
for (int i = rows.length - 1; i >= 0; i--) {
tableModel.removeRow(rows[i]);

View File

@ -1,7 +1,10 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.Messages;
import com.intellij.ui.BooleanTableCellEditor;
import com.intellij.util.ui.ComboBoxCellEditor;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.entity.*;
import com.sjhy.plugin.tool.CacheDataUtils;
import com.sjhy.plugin.tool.ConfigInfo;
@ -173,7 +176,8 @@ public class ConfigTableDialog extends JDialog {
if (column == 0) {
for (ColumnInfo info : tableInfo.getFullColumn()) {
if (info.getName().equals(val) && !info.getName().equals(columnInfo.getName())) {
JOptionPane.showMessageDialog(null, "Column Name Already exist!");
Messages.showWarningDialog("Column Name Already exist!", MsgValue.TITLE_INFO);
// 输入的名称已经存在时直接还原
tableModel.setValueAt(columnInfo.getName(), row, column);
return;
}
@ -209,18 +213,31 @@ public class ConfigTableDialog extends JDialog {
if (!initFlag) {
return;
}
String value = JOptionPane.showInputDialog(null, "Input Column Name:", "Demo");
if (StringUtils.isEmpty(value)) {
JOptionPane.showMessageDialog(null, "Column Name Can't Is Empty!");
//输入列名
String value = Messages.showInputDialog("Column Name:", "Input Column Name:", Messages.getQuestionIcon(), "Demo", new InputValidator() {
@Override
public boolean checkInput(String inputString) {
if (StringUtils.isEmpty(inputString)) {
return false;
}
for (ColumnInfo columnInfo : tableInfo.getFullColumn()) {
if (columnInfo.getName().equals(inputString)) {
return false;
}
}
return true;
}
@Override
public boolean canClose(String inputString) {
return this.checkInput(inputString);
}
});
//取消输入
if (value == null) {
return;
}
for (ColumnInfo columnInfo : tableInfo.getFullColumn()) {
if (columnInfo.getName().equals(value)) {
JOptionPane.showMessageDialog(null, "Column Name Already exist!");
return;
}
}
ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setName(value);
columnInfo.setType("java.lang.String");
@ -231,6 +248,7 @@ public class ConfigTableDialog extends JDialog {
/**
* 刷新列编辑器
*
* @param columnConfigList 列配置集合
*/
private void refreshColumnEditor(List<ColumnConfig> columnConfigList) {
@ -270,6 +288,7 @@ public class ConfigTableDialog extends JDialog {
/**
* 获取初始列
*
* @param columnConfigList 列配置集合
* @return 初始列信息
*/

View File

@ -1,5 +1,6 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
@ -54,7 +55,7 @@ public class EditTemplatePanel {
EditTemplatePanel(String value, Callback callback) {
this.value = value;
this.callback = callback;
init();
this.init();
}
/**
@ -64,8 +65,14 @@ public class EditTemplatePanel {
//初始化系统编辑器
EditorFactory factory = EditorFactory.getInstance();
Document velocityTemplate = factory.createDocument(value);
// 非调度线程不创建编辑器
if(!ApplicationManager.getApplication().isDispatchThread()){
Application application = ApplicationManager.getApplication();
//如果非调度线程则稍后创建编辑框
if (!application.isDispatchThread()) {
application.invokeLater(() -> {
editor = factory.createEditor(velocityTemplate, CacheDataUtils.getInstance().getProject(), FILE_TYPE, false);
editPanel.add(editor.getComponent(), GRID_CONSTRAINTS);
});
return;
}
editor = factory.createEditor(velocityTemplate, CacheDataUtils.getInstance().getProject(), FILE_TYPE, false);
@ -76,6 +83,9 @@ public class EditTemplatePanel {
* 刷新编辑可内容
*/
public void refresh() {
if (editor == null) {
return;
}
this.callback.refreshValue(editor.getDocument().getText());
}

View File

@ -3,8 +3,6 @@ package com.sjhy.plugin.ui;
import com.intellij.openapi.options.Configurable;
import com.sjhy.plugin.entity.GlobalConfig;
import com.sjhy.plugin.entity.GlobalConfigGroup;
import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.tool.CloneUtils;
import com.sjhy.plugin.tool.ConfigInfo;
import org.jetbrains.annotations.Nls;
@ -130,6 +128,9 @@ public class GlobalConfigSettingPanel extends AbstractGroupPanel<GlobalConfigGro
*/
@Override
public void disposeUIResources() {
editTemplatePanel.disposeEditor();
// 修复兼容性问题
if (editTemplatePanel != null) {
editTemplatePanel.disposeEditor();
}
}
}

View File

@ -3,7 +3,9 @@ package com.sjhy.plugin.ui;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.sjhy.plugin.comm.AbstractService;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.tool.CollectionUtil;
import com.sjhy.plugin.tool.ConfigInfo;
import org.jetbrains.annotations.Nls;
@ -59,8 +61,7 @@ public class MainSetting extends AbstractService implements Configurable, Config
ConfigInfo configInfo = ConfigInfo.getInstance();
//重置配置信息
resetBtn.addActionListener(e -> {
int result = JOptionPane.showConfirmDialog(null, "确认重置默认配置?\n重置默认配置只会还原插件自带分组配置信息不会删除用户新增分组信息。", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (JOptionPane.YES_OPTION == result) {
if (MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "确认重置默认配置?\n重置默认配置只会还原插件自带分组配置信息不会删除用户新增分组信息。").isYes()) {
if (CollectionUtil.isEmpty(resetList)) {
return;
}

View File

@ -4,9 +4,11 @@ import com.intellij.ide.util.PackageChooserDialog;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.psi.PsiPackage;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.entity.TableInfo;
import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.entity.TemplateGroup;
@ -156,12 +158,12 @@ public class SelectSavePath extends JDialog {
List<Template> selectTemplateList = getSelectTemplate();
// 如果选择的模板是空的
if (selectTemplateList.isEmpty()) {
JOptionPane.showMessageDialog(null, "Can't Select Template!");
Messages.showWarningDialog("Can't Select Template!", MsgValue.TITLE_INFO);
return;
}
String savePath = pathField.getText();
if (StringUtils.isEmpty(savePath)) {
JOptionPane.showMessageDialog(null, "Can't Select Save Path!");
Messages.showWarningDialog("Can't Select Save Path!", MsgValue.TITLE_INFO);
return;
}
// 设置好配置信息
@ -229,7 +231,7 @@ public class SelectSavePath extends JDialog {
//将当前选中的model设置为基础路径
VirtualFile path = cacheDataUtils.getProject().getBaseDir();
Module module = getSelectModule();
if (module!=null) {
if (module != null) {
path = VirtualFileManager.getInstance().findFileByUrl("file://" + new File(module.getModuleFilePath()).getParent());
}
VirtualFile virtualFile = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), cacheDataUtils.getProject(), path);
@ -275,14 +277,19 @@ public class SelectSavePath extends JDialog {
/**
* 获取基本路径
*
* @return 基本路径
*/
private String getBasePath() {
Module module = getSelectModule();
String baseDir = cacheDataUtils.getProject().getBasePath();
if (module!=null) {
if (module != null) {
baseDir = new File(module.getModuleFilePath()).getParent();
}
// 针对Mac版路径做优化
if (baseDir != null && baseDir.contains("/.idea")) {
baseDir = baseDir.substring(0, baseDir.indexOf("/.idea"));
}
// 针对Maven项目
File file = new File(baseDir + "/src/main/java");
if (file.exists()) {
@ -304,10 +311,10 @@ public class SelectSavePath extends JDialog {
// 获取基本路径
String path = getBasePath();
// 兼容Linux路径
path = path.replaceAll("\\\\", "/");
path = path.replace("\\", "/");
// 如果存在包路径添加包路径
if (!StringUtils.isEmpty(packageName)) {
path += "/" + packageName.replaceAll("\\.", "/");
path += "/" + packageName.replace(".", "/");
}
pathField.setText(path);
}

View File

@ -97,7 +97,7 @@ public class TemplateSettingPanel extends AbstractGroupPanel<TemplateGroup, Temp
@Override
public boolean isModified() {
// 修复BUG当初始未完成时插件进行修改判断
if (editTemplatePanel!=null) {
if (editTemplatePanel != null) {
editTemplatePanel.refresh();
}
return !configInfo.getTemplateGroupMap().equals(group) || !configInfo.getCurrTemplateGroupName().equals(currGroupName);
@ -128,6 +128,9 @@ public class TemplateSettingPanel extends AbstractGroupPanel<TemplateGroup, Temp
*/
@Override
public void disposeUIResources() {
editTemplatePanel.disposeEditor();
// 修复兼容性问题
if (editTemplatePanel != null) {
editTemplatePanel.disposeEditor();
}
}
}

View File

@ -1,11 +1,16 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.Messages;
import com.sjhy.plugin.constants.MsgValue;
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.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
@ -86,6 +91,12 @@ public class TypeMapperSetting implements Configurable {
//移除类型
removeButton.addActionListener(e -> {
int[] selectRows = typeMapperTable.getSelectedRows();
if (selectRows == null || selectRows.length == 0) {
return;
}
if (!MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Confirm Delete Selected Item?").isYes()) {
return;
}
// 从后面往前面移除防止下标错位问题
for (int i = selectRows.length - 1; i >= 0; i--) {
typeMapperModel.removeRow(selectRows[i]);
@ -110,18 +121,20 @@ public class TypeMapperSetting implements Configurable {
//复制分组按钮
typeMapperCopyButton.addActionListener(e -> {
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName + " Copy");
String value = Messages.showInputDialog("Group Name:", "Input Group Name:", Messages.getQuestionIcon(), currGroupName + " Copy", new InputValidator() {
@Override
public boolean checkInput(String inputString) {
return !StringUtils.isEmpty(inputString) && !typeMapperGroupMap.containsKey(inputString);
}
@Override
public boolean canClose(String inputString) {
return this.checkInput(inputString);
}
});
if (value == null) {
return;
}
if (value.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
return;
}
if (typeMapperGroupMap.containsKey(value)) {
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
return;
}
// 克隆对象
TypeMapperGroup typeMapperGroup = cloneUtils.clone(typeMapperGroupMap.get(currGroupName));
typeMapperGroup.setName(value);
@ -132,10 +145,9 @@ public class TypeMapperSetting implements Configurable {
//删除分组
deleteButton.addActionListener(e -> {
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group " + typeMapperComboBox.getSelectedItem() + "?", "温馨提示", JOptionPane.OK_CANCEL_OPTION);
if (result == 0) {
if (MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Confirm Delete Group " + typeMapperComboBox.getSelectedItem() + "?").isYes()) {
if (ConfigInfo.DEFAULT_NAME.equals(currGroupName)) {
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
Messages.showWarningDialog("Can't Delete Default Group!", MsgValue.TITLE_INFO);
return;
}
typeMapperGroupMap.remove(currGroupName);
@ -197,6 +209,8 @@ public class TypeMapperSetting implements Configurable {
@Override
public void reset() {
this.typeMapperGroupMap = cloneUtils.cloneMap(configInfo.getTypeMapperGroupMap());
this.currGroupName = configInfo.getCurrTypeMapperGroupName();
init();
}
}

View File

@ -1,7 +1,7 @@
<idea-plugin>
<id>com.sjhy.plugin.easycode</id>
<name>Easy Code</name>
<version>1.1.1</version>
<version>1.1.2</version>
<vendor email="1353036300@qq.com" url="http://www.shujuhaiyang.com">数据海洋</vendor>
@ -21,6 +21,15 @@
<change-notes><![CDATA[
<p>1.1.2-SNAPSHOT</p>
<ul>
<li>1.This update focuses on optimizing MacOS devices.</li>
<li>1.Repair a part of the user to generate code when the card is dead.</li>
</ul>
<ul>
<li>1.本次更新注意针对Mac设备做了大量优化</li>
<li>2.修复部分用户生成代码时卡死的BUG</li>
</ul>
<p>1.1.1-SNAPSHOT</p>
<ul>
<li>1.Repairing global config can not save after modification.</li>