mirror of https://gitee.com/makejava/EasyCode.git
优化代码生成弹窗
This commit is contained in:
parent
a604b259fb
commit
676e9b54cd
|
@ -36,6 +36,9 @@ public class EasyCodeEntityAction extends AnAction {
|
|||
|
||||
// 过滤选择Java文件
|
||||
VirtualFile[] psiFiles = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
|
||||
if (psiFiles == null) {
|
||||
return;
|
||||
}
|
||||
PsiManager psiManager = PsiManager.getInstance(project);
|
||||
List<PsiJavaFile> psiJavaFiles = Arrays.stream(psiFiles)
|
||||
.map(psiManager::findFile)
|
||||
|
@ -55,7 +58,7 @@ public class EasyCodeEntityAction extends AnAction {
|
|||
// 缓存选中值
|
||||
cacheDataUtils.setSelectPsiClass(psiClassList.get(0));
|
||||
cacheDataUtils.setPsiClassList(psiClassList);
|
||||
new SelectSavePath(project, true).open();
|
||||
new SelectSavePath(project, true).show();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,13 +67,9 @@ public class EasyCodeEntityAction extends AnAction {
|
|||
private List<PsiClass> resolvePsiClassByFile(List<PsiJavaFile> psiJavaFiles) {
|
||||
List<PsiClass> psiClassList = Lists.newArrayListWithCapacity(psiJavaFiles.size());
|
||||
for (PsiJavaFile psiJavaFile : psiJavaFiles) {
|
||||
PsiClass psiClass = Arrays.stream(psiJavaFile.getClasses())
|
||||
Arrays.stream(psiJavaFile.getClasses())
|
||||
.filter(o -> o.getModifierList() != null && o.getModifierList().hasModifierProperty(PsiModifier.PUBLIC))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (psiClass != null) {
|
||||
psiClassList.add(psiClass);
|
||||
}
|
||||
.findFirst().ifPresent(psiClassList::add);
|
||||
}
|
||||
return psiClassList;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,6 @@ public class MainAction extends AnAction {
|
|||
return;
|
||||
}
|
||||
//开始处理
|
||||
new SelectSavePath(event.getProject()).open();
|
||||
new SelectSavePath(event.getProject()).show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public class TableInfoServiceImpl implements TableInfoService {
|
|||
}
|
||||
// 添加附加列
|
||||
for (ColumnInfo configColumn : tableInfoConfig.getFullColumn()) {
|
||||
if (configColumn.getCustom()) {
|
||||
if (Boolean.TRUE.equals(configColumn.getCustom())) {
|
||||
fullColumn.add(configColumn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,10 +88,10 @@ public class ConfigTableDialog extends DialogWrapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void processDoNotAskOnOk(int exitCode) {
|
||||
super.processDoNotAskOnOk(exitCode);
|
||||
protected void doOKAction() {
|
||||
// 保存信息
|
||||
TableInfoSettingsService.getInstance().saveTableInfo(tableInfo);
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.sjhy.plugin.ui.SelectSavePath">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="436" height="336"/>
|
||||
|
@ -8,47 +8,6 @@
|
|||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="94766" 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="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="98af6">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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="e7465" class="javax.swing.JButton" binding="buttonOK">
|
||||
<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>
|
||||
<text resource-bundle="string" key="label.ok"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="string" key="label.cancel"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="e3588" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
|
|
|
@ -5,11 +5,12 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
|||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
import com.sjhy.plugin.dict.GlobalDict;
|
||||
import com.sjhy.plugin.constants.StrState;
|
||||
import com.sjhy.plugin.dict.GlobalDict;
|
||||
import com.sjhy.plugin.dto.SettingsStorageDTO;
|
||||
import com.sjhy.plugin.entity.TableInfo;
|
||||
import com.sjhy.plugin.entity.Template;
|
||||
|
@ -18,10 +19,13 @@ import com.sjhy.plugin.service.CodeGenerateService;
|
|||
import com.sjhy.plugin.service.SettingsStorageService;
|
||||
import com.sjhy.plugin.service.TableInfoService;
|
||||
import com.sjhy.plugin.tool.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -36,19 +40,11 @@ import java.util.List;
|
|||
* @version 1.0.0
|
||||
* @since 2018/07/17 13:10
|
||||
*/
|
||||
public class SelectSavePath extends JDialog {
|
||||
public class SelectSavePath extends DialogWrapper {
|
||||
/**
|
||||
* 主面板
|
||||
*/
|
||||
private JPanel contentPane;
|
||||
/**
|
||||
* 确认按钮
|
||||
*/
|
||||
private JButton buttonOK;
|
||||
/**
|
||||
* 取消按钮
|
||||
*/
|
||||
private JButton buttonCancel;
|
||||
/**
|
||||
* 模型下拉框
|
||||
*/
|
||||
|
@ -134,10 +130,18 @@ public class SelectSavePath extends JDialog {
|
|||
this(project, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable JComponent createCenterPanel() {
|
||||
return this.contentPane;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public SelectSavePath(Project project, boolean entityMode) {
|
||||
super(project);
|
||||
this.entityMode = entityMode;
|
||||
this.project = project;
|
||||
this.tableInfoService = TableInfoService.getInstance(project);
|
||||
|
@ -153,27 +157,15 @@ public class SelectSavePath extends JDialog {
|
|||
this.moduleList.add(module);
|
||||
}
|
||||
}
|
||||
initPanel();
|
||||
init();
|
||||
setTitle(GlobalDict.TITLE_INFO);
|
||||
setContentPane(contentPane);
|
||||
setModal(true);
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
}
|
||||
|
||||
buttonOK.addActionListener(e -> onOK());
|
||||
|
||||
buttonCancel.addActionListener(e -> onCancel());
|
||||
|
||||
// call onCancel() when cross is clicked
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() on ESCAPE
|
||||
contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
onOK();
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -249,16 +241,8 @@ public class SelectSavePath extends JDialog {
|
|||
|
||||
// 生成代码
|
||||
codeGenerateService.generateByUnifiedConfig(getSelectTemplate(), unifiedConfig.isSelected(), !titleConfig.isSelected(), this.entityMode);
|
||||
// 关闭窗口
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消按钮回调事件
|
||||
*/
|
||||
private void onCancel() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化模板组
|
||||
|
@ -289,7 +273,7 @@ public class SelectSavePath extends JDialog {
|
|||
/**
|
||||
* 初始化方法
|
||||
*/
|
||||
private void init() {
|
||||
private void initPanel() {
|
||||
// 初始化模板组
|
||||
initTemplateGroup();
|
||||
|
||||
|
@ -400,7 +384,6 @@ public class SelectSavePath extends JDialog {
|
|||
this.templateGroup = settings.getTemplateGroupMap().get(selectedItem);
|
||||
// 选中的模板组发生变化,尝试重新初始化
|
||||
initTemplateGroup();
|
||||
this.open();
|
||||
});
|
||||
String savePath = tableInfo.getSavePath();
|
||||
if (!StringUtils.isEmpty(savePath)) {
|
||||
|
@ -463,13 +446,4 @@ public class SelectSavePath extends JDialog {
|
|||
}
|
||||
pathField.setText(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开窗口
|
||||
*/
|
||||
public void open() {
|
||||
this.pack();
|
||||
setLocationRelativeTo(null);
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue