You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
306 lines
13 KiB
306 lines
13 KiB
2 years ago
|
package com.fr.plugin.db.procedure.designframe;
|
||
|
|
||
|
import com.fr.base.BaseUtils;
|
||
|
import com.fr.design.dialog.BasicDialog;
|
||
|
import com.fr.design.dialog.BasicPane;
|
||
|
import com.fr.design.dialog.DialogActionAdapter;
|
||
|
import com.fr.design.dialog.FineJOptionPane;
|
||
|
import com.fr.design.gui.frpane.LoadingBasicPane;
|
||
|
import com.fr.design.gui.ibutton.UIButton;
|
||
|
import com.fr.design.i18n.Toolkit;
|
||
|
import com.fr.design.layout.FRGUIPaneFactory;
|
||
|
import com.fr.design.mainframe.DesignerContext;
|
||
|
import com.fr.design.webattr.ServerPrinterPane;
|
||
|
import com.fr.locale.InterProviderFactory;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.plugin.db.procedure.designframe.widgets.AddWidget;
|
||
|
import com.fr.plugin.db.procedure.entity.TemplateProcedureDBAUtil;
|
||
|
import com.fr.plugin.db.procedure.entity.TemplateProcedureEntity;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
|
||
|
import javax.swing.*;
|
||
|
import javax.swing.event.ListSelectionEvent;
|
||
|
import javax.swing.event.ListSelectionListener;
|
||
|
import javax.swing.table.DefaultTableCellRenderer;
|
||
|
import javax.swing.table.DefaultTableModel;
|
||
|
import java.awt.*;
|
||
|
import java.awt.event.ActionEvent;
|
||
|
import java.awt.event.ActionListener;
|
||
|
import java.awt.event.MouseAdapter;
|
||
|
import java.awt.event.MouseEvent;
|
||
|
import java.util.List;
|
||
|
import java.util.UUID;
|
||
|
import java.util.Vector;
|
||
|
|
||
|
//ReportWebAttrPane
|
||
|
public class TemplateProcedurcePanel extends LoadingBasicPane {
|
||
|
public TemplateProcedurcePanel() {
|
||
|
|
||
|
}
|
||
|
|
||
|
private JTable dataList;
|
||
|
//private DefaultTableModel dtm;
|
||
|
private UIButton addButton;
|
||
|
private UIButton editButton;
|
||
|
private UIButton removeButton;
|
||
|
private int dataIndex = 0;
|
||
|
private String currentDataSelectedId = "";
|
||
|
private String[] columnNames ={"序号","存储过程id","存储过程名称","模板路径","连接名字"};
|
||
|
private List<TemplateProcedureEntity> eneitys;
|
||
|
|
||
|
ActionListener addActionListener = new ActionListener() {
|
||
|
public void actionPerformed(ActionEvent evt) {
|
||
|
final AddWidget var4 = new AddWidget() {
|
||
|
public void complete() {
|
||
|
this.populate(null);
|
||
|
}
|
||
|
};
|
||
|
FineLoggerFactory.getLogger().info("增加存储过程 .....");
|
||
|
BasicDialog var5 = var4.showWindow(DesignerContext.getDesignerFrame());
|
||
|
var5.addDialogActionListener(new DialogActionAdapter() {
|
||
|
public void doOk() {
|
||
|
String procedureId = var4.getProcedurceId();
|
||
|
String procedureName = var4.getProceduceName();
|
||
|
String connectName = var4.getConnectName();
|
||
|
String connctId = var4.getConnectId();
|
||
|
String templatePath = var4.getTemplatePath();
|
||
|
FineLoggerFactory.getLogger().info("点击确定按钮.....");
|
||
|
|
||
|
TemplateProcedureEntity oldEntity = TemplateProcedureDBAUtil.getInstance().getEntityByprocedureId(procedureId);
|
||
|
if(oldEntity == null){
|
||
|
FineLoggerFactory.getLogger().info("可以新增存储过程");
|
||
|
TemplateProcedureEntity entity = new TemplateProcedureEntity();
|
||
|
entity.setId(UUID.randomUUID().toString());
|
||
|
entity.setConnectionId(connctId);
|
||
|
entity.setConnectionName(connectName);
|
||
|
entity.setProcedureId(procedureId);
|
||
|
entity.setProcedureName(procedureName);
|
||
|
entity.setReportPath(templatePath);
|
||
|
|
||
|
try {
|
||
|
FineLoggerFactory.getLogger().info("开始新增存储过程");
|
||
|
TemplateProcedureDBAUtil.getInstance().addEntity(entity);
|
||
|
|
||
|
DefaultTableModel model = entityTableModel();
|
||
|
dataList.setModel(model); //给table设置更新后的tablemodel
|
||
|
dataList.repaint();
|
||
|
setDataListColumns();
|
||
|
JOptionPane.showMessageDialog(null,"添加成功");
|
||
|
} catch (Exception e) {
|
||
|
JOptionPane.showMessageDialog(null,"添加失败:"+e.getMessage());
|
||
|
throw new RuntimeException(e);
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
JOptionPane.showMessageDialog(null,"存储过程id"+procedureId+"已经存在");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public void doCancel(){
|
||
|
FineLoggerFactory.getLogger().info("点击取消按钮.....");
|
||
|
}
|
||
|
});
|
||
|
|
||
|
var5.setVisible(true);
|
||
|
}
|
||
|
};
|
||
|
ActionListener editActionListener = new ActionListener() {
|
||
|
public void actionPerformed(ActionEvent evt) {
|
||
|
if(StringUtils.isNotBlank(currentDataSelectedId)){
|
||
|
for(TemplateProcedureEntity entity : eneitys){
|
||
|
if(entity.getId().equals(currentDataSelectedId)){
|
||
|
final AddWidget var4 = new AddWidget() {
|
||
|
public void complete() {
|
||
|
FineLoggerFactory.getLogger().info("编辑赋值");
|
||
|
this.populate(entity);
|
||
|
}
|
||
|
};
|
||
|
BasicDialog var5 = var4.showWindow(DesignerContext.getDesignerFrame());
|
||
|
var5.addDialogActionListener(new DialogActionAdapter() {
|
||
|
public void doOk() {
|
||
|
String id = entity.getId();
|
||
|
String procedureId = var4.getProcedurceId();
|
||
|
String procedureName = var4.getProceduceName();
|
||
|
String connectName = var4.getConnectName();
|
||
|
String connctId = var4.getConnectId();
|
||
|
String templatePath = var4.getTemplatePath();
|
||
|
FineLoggerFactory.getLogger().info("点击确定按钮.....");
|
||
|
|
||
|
TemplateProcedureEntity entity = new TemplateProcedureEntity();
|
||
|
entity.setId(id);
|
||
|
entity.setConnectionId(connctId);
|
||
|
entity.setConnectionName(connectName);
|
||
|
entity.setProcedureId(procedureId);
|
||
|
entity.setProcedureName(procedureName);
|
||
|
entity.setReportPath(templatePath);
|
||
|
|
||
|
try {
|
||
|
TemplateProcedureDBAUtil.getInstance().updateEntity(entity);
|
||
|
DefaultTableModel model = entityTableModel();
|
||
|
dataList.setModel(model); //给table设置更新后的tablemodel
|
||
|
dataList.repaint();
|
||
|
setDataListColumns();
|
||
|
JOptionPane.showMessageDialog(null,"编辑成功");
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public void doCancel(){
|
||
|
FineLoggerFactory.getLogger().info("点击取消按钮.....");
|
||
|
}
|
||
|
});
|
||
|
|
||
|
var5.setVisible(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
ActionListener removeActionListener = new ActionListener() {
|
||
|
public void actionPerformed(ActionEvent evt) {
|
||
|
if(StringUtils.isNotBlank(currentDataSelectedId)){
|
||
|
int input = JOptionPane.showConfirmDialog(null, "您确定要删除当前选中数据吗?");
|
||
|
if(input == 0){
|
||
|
FineLoggerFactory.getLogger().info("确认要删除.....");
|
||
|
try {
|
||
|
TemplateProcedureDBAUtil.getInstance().removeById(currentDataSelectedId);
|
||
|
DefaultTableModel model = entityTableModel();
|
||
|
dataList.setModel(model); //给table设置更新后的tablemodel
|
||
|
dataList.repaint();
|
||
|
setDataListColumns();
|
||
|
} catch (Exception e) {
|
||
|
throw new RuntimeException(e);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
};
|
||
|
|
||
|
ListSelectionListener dataListSelectionListener = new ListSelectionListener() {
|
||
|
public void valueChanged(ListSelectionEvent evt) {
|
||
|
if(!evt.getValueIsAdjusting()){
|
||
|
int rowIndex = dataList.getSelectedRow();
|
||
|
if(rowIndex >= 0 && rowIndex < eneitys.size()){
|
||
|
TemplateProcedureEntity entity = eneitys.get(rowIndex);
|
||
|
currentDataSelectedId = entity.getId();
|
||
|
FineLoggerFactory.getLogger().info("currentDataSelectedId:"+currentDataSelectedId+",procedureId"+entity.getProcedureId());
|
||
|
}
|
||
|
else{
|
||
|
currentDataSelectedId = "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
};
|
||
|
MouseAdapter mouseClickedListener = new MouseAdapter() {
|
||
|
public void mouseClicked(MouseEvent e) {
|
||
|
int clickedNumber = e.getClickCount();
|
||
|
if (clickedNumber >= 2) {
|
||
|
// ServerPrinterPane.this.editPrinterList();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
};
|
||
|
|
||
|
protected synchronized void initComponents(JPanel container) {
|
||
|
FineLoggerFactory.getLogger().info("加载存储过程列表 initComponents");
|
||
|
container.setLayout(FRGUIPaneFactory.createBorderLayout());
|
||
|
container.setBorder(BorderFactory.createEmptyBorder(6, 2, 4, 2));
|
||
|
JToolBar toolbar = new JToolBar();
|
||
|
container.add(toolbar, "North");
|
||
|
Dimension preferDimension = new Dimension(24, 24);
|
||
|
this.addButton = new UIButton(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png"));
|
||
|
this.addButton.addActionListener(this.addActionListener);
|
||
|
this.addButton.setToolTipText(Toolkit.i18nText("Fine-Design_Basic_Add"));
|
||
|
this.addButton.setPreferredSize(preferDimension);
|
||
|
|
||
|
this.editButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/control/edit.png"));
|
||
|
this.editButton.addActionListener(this.editActionListener);
|
||
|
this.editButton.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Edit"));
|
||
|
this.editButton.setPreferredSize(preferDimension);
|
||
|
|
||
|
this.removeButton = new UIButton(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png"));
|
||
|
this.removeButton.addActionListener(this.removeActionListener);
|
||
|
this.removeButton.setToolTipText(Toolkit.i18nText("Fine-Design_Basic_Remove"));
|
||
|
this.removeButton.setPreferredSize(preferDimension);
|
||
|
|
||
|
toolbar.add(this.addButton);
|
||
|
toolbar.add(this.editButton);
|
||
|
toolbar.add(this.removeButton);
|
||
|
|
||
|
|
||
|
this.dataList = new JTable(entityTableModel());
|
||
|
this.dataList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||
|
this.dataList.getSelectionModel().addListSelectionListener(this.dataListSelectionListener);
|
||
|
this.dataList.getSelectionModel().setSelectionInterval(0, 0);
|
||
|
this.dataList.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||
|
setDataListColumns();
|
||
|
container.add(new JScrollPane(this.dataList), "Center");
|
||
|
}
|
||
|
|
||
|
private void setDataListColumns(){
|
||
|
DefaultTableCellRenderer ter = new DefaultTableCellRenderer() {
|
||
|
@Override
|
||
|
public Component getTableCellRendererComponent(JTable table,
|
||
|
Object value, boolean isSelected, boolean hasFocus,
|
||
|
int row, int column) {
|
||
|
|
||
|
JLabel label = (JLabel)super.getTableCellRendererComponent(table, value,
|
||
|
isSelected, hasFocus, row, column);
|
||
|
label.setToolTipText(value.toString());
|
||
|
return label;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
for (int i = 0; i < 5; i++) {
|
||
|
this.dataList.getColumn(columnNames[i]).setCellRenderer(ter);
|
||
|
}
|
||
|
|
||
|
this.dataList.getColumnModel().getColumn(0).setPreferredWidth(60);
|
||
|
this.dataList.getColumnModel().getColumn(1).setPreferredWidth(200);
|
||
|
this.dataList.getColumnModel().getColumn(2).setPreferredWidth(120);
|
||
|
this.dataList.getColumnModel().getColumn(3).setPreferredWidth(160);
|
||
|
this.dataList.getColumnModel().getColumn(4).setPreferredWidth(100);
|
||
|
}
|
||
|
|
||
|
private DefaultTableModel entityTableModel(){
|
||
|
DefaultTableModel dtm = new DefaultTableModel();
|
||
|
dtm.setColumnIdentifiers(columnNames);
|
||
|
this.eneitys = TemplateProcedureDBAUtil.getInstance().getAll();
|
||
|
dataIndex = 0;
|
||
|
if(eneitys.size() > 0){
|
||
|
this.currentDataSelectedId = eneitys.get(0).getId();
|
||
|
}
|
||
|
for(TemplateProcedureEntity entity:eneitys){
|
||
|
Vector v = new Vector();
|
||
|
dataIndex++;
|
||
|
v.add(dataIndex);
|
||
|
v.add(entity.getProcedureId());
|
||
|
v.add(entity.getProcedureName());
|
||
|
v.add(entity.getReportPath());
|
||
|
v.add(entity.getConnectionName());
|
||
|
dtm.addRow(v);
|
||
|
}
|
||
|
|
||
|
return dtm;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public void populate(Object reportWebAttr) {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
protected String title4PopupWindow() {
|
||
|
return InterProviderFactory.getProvider().getLocText("Fine-db-procedurce-dialog-title");
|
||
|
}
|
||
|
}
|