package com.vci.client.workflow.editor.ui;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.swing.BoxLayout;
|
import javax.swing.JButton;
|
import javax.swing.JComboBox;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTable;
|
|
import com.vci.client.workflow.commom.ClientHelper;
|
import com.vci.client.workflow.delegate.EventConfClientDelegate;
|
import com.vci.client.workflow.editor.DblclickCellEditor;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.workflow.data.PropertyInfo;
|
|
public class CustomClassEditPanel extends JPanel {
|
private static final long serialVersionUID = 1300418480939892949L;
|
|
private JTable customTable;
|
private JButton addBtn;
|
private JButton deleteBtn;
|
|
private JButton okBtn;
|
private JButton cancelBtn;
|
|
private EventPanel eventPanel;
|
|
public CustomClassEditPanel(EventPanel eventPanel) {
|
// super(LogonApplication.frame,true);
|
this.eventPanel = eventPanel;
|
// this.setTitle("自定义事件页面");
|
initUI();
|
addListener();
|
// this.setSize(600, 400);
|
// dispalyCenter();
|
}
|
|
private void dispalyCenter() {
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension frameSize = this.getSize();
|
if (frameSize.height > screenSize.height) {
|
frameSize.height = screenSize.height;
|
}
|
if (frameSize.width > screenSize.width) {
|
frameSize.width = screenSize.width;
|
}
|
this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
|
}
|
|
private void addListener() {
|
addBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
CustomClassTableModel model = (CustomClassTableModel) customTable.getModel();
|
model.addRow();
|
}
|
});
|
|
deleteBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
int[] selectedRows = customTable.getSelectedRows();
|
CustomClassTableModel model = (CustomClassTableModel) customTable.getModel();
|
model.deleteRow(selectedRows);
|
}
|
});
|
// okBtn.addActionListener(new ActionListener() {
|
//
|
// @Override
|
// public void actionPerformed(ActionEvent arg0) {
|
// cursorLeave(customTable);
|
// eventPanel.setCustomInfos(getCustomUserInfos());
|
//// dispose();
|
// }
|
// });
|
// cancelBtn.addActionListener(new ActionListener() {
|
//
|
// @Override
|
// public void actionPerformed(ActionEvent e) {
|
//// eventPanel.setCustomInfos(new CustomInfo[0]);
|
//// dispose();
|
// }
|
// });
|
}
|
|
/**
|
* 直接取得table中cell的值
|
*
|
* @param table
|
*/
|
public void cursorLeave(JTable table) {
|
try {
|
if (table == null) {
|
return;
|
}
|
if (table.isEditing()) {
|
table.getCellEditor(table.getEditingRow(), table.getEditingColumn()).stopCellEditing();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
private void initUI() {
|
setLayout(new BorderLayout());
|
add(new JScrollPane(getCustomProperty()), BorderLayout.CENTER);
|
|
JPanel BtnPanel = new JPanel();
|
add(BtnPanel, BorderLayout.EAST);
|
BtnPanel.setLayout(new BoxLayout(BtnPanel, BoxLayout.Y_AXIS));
|
|
addBtn = new JButton("添加");
|
BtnPanel.add(addBtn);
|
|
deleteBtn = new JButton("删除");
|
BtnPanel.add(deleteBtn);
|
|
okBtn = new JButton("确定");
|
cancelBtn = new JButton("取消");
|
// JPanel botmPanel = new JPanel();
|
// botmPanel.add(okBtn);
|
// botmPanel.add(cancelBtn);
|
// add(botmPanel, BorderLayout.SOUTH);
|
}
|
|
private JTable getCustomProperty() {
|
if (customTable == null) {
|
customTable = new JTable(new CustomClassTableModel());
|
customTable.setRowHeight(20);
|
|
Dimension size = customTable.getTableHeader().getPreferredSize();
|
size.height = 22;
|
customTable.getTableHeader().setPreferredSize(size);
|
// customTable.setPreferredScrollableViewportSize(new Dimension(300, 60));
|
JComboBox c = new JComboBox(getEventTypes(eventPanel.getEventType()));
|
// customTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(c));
|
customTable.getColumnModel().getColumn(0).setCellEditor(new DblclickCellEditor(c, customTable));
|
}
|
return customTable;
|
}
|
|
private PropertyObject[] getEventTypes(String eventType) {
|
/*
|
* String[] types =
|
* EventProperties.getStringProperty("workflow.event.type."+eventType).split(","
|
* );
|
*/
|
// add by caill start 2016.4.8 通过corba连接服务端
|
String[] types = null;
|
try {
|
types = new EventConfClientDelegate().getStringProperty("workflow.event.type." + eventType).split(",");
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
// add by caill end
|
List<PropertyObject> taskTypes = new ArrayList<PropertyObject>();
|
taskTypes.add(new PropertyObject("", ""));
|
for (int i = 0; i < types.length; i++) {
|
/*
|
* taskTypes.add(new PropertyObject(types[i],
|
* EventProperties.getStringProperty("workflow.event.type." + types[i])));
|
*/
|
// add by caill start 2016.4.8 通过corba连接服务端
|
try {
|
taskTypes.add(new PropertyObject(types[i],
|
new EventConfClientDelegate().getStringProperty("workflow.event.type." + types[i])));
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
// add by caill end
|
}
|
return taskTypes.toArray(new PropertyObject[0]);
|
}
|
|
// private PropertyObject[] getEventTypes() {
|
// String[] types = getI18nForEvent("workflow.event.type").split(",");
|
// List<PropertyObject> taskTypes = new ArrayList<PropertyObject>();
|
// taskTypes.add(new PropertyObject("", ""));
|
// for (int i = 0; i < types.length; i++) {
|
// taskTypes.add(new PropertyObject(types[i],
|
// getI18nForEvent("workflow.event.type." + types[i])));
|
// }
|
// return taskTypes.toArray(new PropertyObject[0]);
|
// }
|
public PropertyInfo[] getCustomUserInfos() {
|
List<PropertyInfo> result = new ArrayList<PropertyInfo>();
|
CustomClassTableModel model = (CustomClassTableModel) customTable.getModel();
|
List<PropertyInfo> data = model.getData();
|
if (data != null && data.size() > 0) {
|
for (PropertyInfo customInfo : data) {
|
if (customInfo != null) {
|
if (customInfo.property.trim().length() > 0
|
// && customInfo.value.trim().length() > 0
|
) {
|
result.add(customInfo);
|
}
|
}
|
}
|
}
|
return result.toArray(new PropertyInfo[0]);
|
}
|
|
public void setData(List<PropertyInfo> data) {
|
CustomClassTableModel model = (CustomClassTableModel) customTable.getModel();
|
model.setData(data);
|
}
|
|
private String getI18nString(String spCode) {
|
return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, this.getLocale());
|
}
|
|
}
|