package com.vci.client.workflow.template;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
|
import javax.swing.JLabel;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.IconSelectDialog;
|
import com.vci.client.framework.rightConfig.object.FunctionObject;
|
import com.vci.client.logon.base.BaseJDialog;
|
import com.vci.client.ui.exception.VCIException;
|
import com.vci.client.ui.image.BundleImage;
|
import com.vci.client.ui.locale.LocaleDisplay;
|
import com.vci.client.ui.swing.KJButton;
|
import com.vci.client.ui.swing.KTextField;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.workflow.commom.ClientHelper;
|
import com.vci.client.workflow.delegate.ProcessCustomClientDelegate;
|
import com.vci.client.workflow.template.object.ProcessCategoryObject;
|
import com.vci.corba.common.VCIError;
|
|
public class ProcessCategoryTypeDialog extends BaseJDialog {
|
|
private static final long serialVersionUID = 8564910826301969195L;
|
|
private KJButton okBtn = new KJButton("确定", "ok.gif");
|
private KJButton cancelBtn = new KJButton("取消", "cancel.gif");
|
private KJButton selectIconBtn = new KJButton("选择", "newresourcetypes.gif");
|
private KTextField nameField = new KTextField();
|
private JTextArea descArea;
|
|
private String optType = null;
|
private ProcessCategoryObject processCategoryObject = null;
|
|
private ProcessCustomClientDelegate preferLibraryDelegate;
|
FunctionObject funcObj = new FunctionObject();
|
public ProcessCategoryTypeDialog(String title,
|
String optType, ProcessCategoryObject processCategoryObject) throws VCIException {
|
super(LogonApplication.frame, title, true);
|
preferLibraryDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
|
this.optType = optType;
|
this.processCategoryObject = processCategoryObject;
|
|
init();
|
// checkPermission();
|
}
|
|
public ProcessCategoryTypeDialog(String title,String optType,ProcessCategoryObject processCategoryObject,FunctionObject funcObj) throws VCIException {
|
super(LogonApplication.frame, title, true);
|
preferLibraryDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
|
this.optType = optType;
|
this.funcObj = funcObj;
|
this.processCategoryObject = processCategoryObject;
|
|
init();
|
// checkPermission();
|
}
|
|
private void init() throws VCIException {
|
initPanelContent();
|
if (optType.equals("create")) {
|
this.setTitle("创建模板分类");
|
} else if (optType.equals("modify")) {
|
this.setTitle("编辑模板分类");
|
this.setUIContent();
|
}
|
addListener();
|
setSize(340, 280);
|
centerToScreen();
|
}
|
|
/**
|
* <p>Description: 初始所有UI元素</p>
|
*/
|
private void initPanelContent() {
|
JPanel panel = new JPanel();
|
getContentPane().add(panel, BorderLayout.CENTER);
|
GridBagLayout gbl_panel = new GridBagLayout();
|
panel.setLayout(gbl_panel);
|
|
JLabel lblNewLabel = new JLabel("名称");
|
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
|
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
|
gbc_lblNewLabel.gridx = 0;
|
gbc_lblNewLabel.gridy = 0;
|
panel.add(lblNewLabel, gbc_lblNewLabel);
|
|
GridBagConstraints gbc_textField = new GridBagConstraints();
|
gbc_textField.insets = new Insets(0, 0, 5, 0);
|
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
|
gbc_textField.gridx = 1;
|
gbc_textField.gridy = 0;
|
panel.add(nameField, gbc_textField);
|
|
// JLabel lblNewLabel_2 = new JLabel("选择图标");
|
// GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
// gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
// gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
// gbc_lblNewLabel_2.gridx = 0;
|
// gbc_lblNewLabel_2.gridy = 1;
|
// panel.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
|
// GridBagConstraints gbc_textField_2 = new GridBagConstraints();
|
// gbc_textField_2.insets = new Insets(0, 0, 5, 0);
|
// gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
|
// gbc_textField_2.gridx = 1;
|
// gbc_textField_2.gridy = 1;
|
// panel.add(selectIconBtn, gbc_textField_2);
|
|
JLabel descLabel = new JLabel("描述");
|
GridBagConstraints descLabelGbc = new GridBagConstraints();
|
descLabelGbc.anchor = GridBagConstraints.NORTHEAST;
|
descLabelGbc.insets = new Insets(0, 0, 0, 5);
|
descLabelGbc.gridx = 0;
|
descLabelGbc.gridy = 1;
|
panel.add(descLabel, descLabelGbc);
|
|
descArea = new JTextArea(5, 20);
|
JScrollPane scrollPane = new JScrollPane(descArea);
|
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
gbc_scrollPane.gridx = 1;
|
gbc_scrollPane.gridy = 1;
|
panel.add(scrollPane, gbc_scrollPane);
|
|
JPanel btnPanel = new JPanel();
|
btnPanel.add(okBtn);
|
btnPanel.add(cancelBtn);
|
getContentPane().add(btnPanel, BorderLayout.SOUTH);
|
}
|
|
private void centerToScreen() {
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension componentSize = getSize();
|
if (componentSize.height > screenSize.height) {
|
componentSize.height = screenSize.height;
|
}
|
|
if (componentSize.width > screenSize.width) {
|
componentSize.width = screenSize.width;
|
}
|
|
this.setLocation((screenSize.width - componentSize.width) / 2,
|
(screenSize.height - componentSize.height) / 2);
|
}
|
|
/**
|
* <p>Description: 初始化所有按钮关联的操作监听</p>
|
*/
|
private void addListener() {
|
selectIconBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
selectIcon();
|
}
|
});
|
|
okBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
ok();
|
}
|
});
|
|
cancelBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
close();
|
}
|
});
|
}
|
|
private void selectIcon() {
|
String title = getI18nString("lblIcon");
|
IconSelectDialog iconDialog = new IconSelectDialog(title, true, optType, selectIconBtn);
|
iconDialog.setVisible(true);
|
}
|
|
private void ok() {
|
if(optType.equalsIgnoreCase("create")){
|
ProcessCategoryObject object = getCreateProcessCategory();
|
if (!checkProcessCategoryData(object)) {
|
return;
|
}
|
String parentId = "root";
|
// Object currentSelectedObject = getOperate().getToolBar().getMainPanel().getCurrentSelectedObject();
|
// if (currentSelectedObject instanceof ProcessCategoryObject) {
|
// parentId = ((ProcessCategoryObject)currentSelectedObject).getId();
|
// };
|
object.setParentId(parentId);
|
|
try {
|
if(!checkNameExisted(object)) return;
|
String id = preferLibraryDelegate.saveProcessCategory(object);
|
object.setId(id);
|
// operate.getToolBar().getMainPanel().addNewObjectToTree(object);
|
close();
|
} catch (VCIError ex) {
|
VCIOptionPane.showError(this,
|
LocaleDisplay.getI18nString(String.valueOf(ex.code), "RMIPWorkflow", getLocale()));
|
}
|
}else{
|
ProcessCategoryObject object = getModifyPreferLibrary();
|
if (!checkProcessCategoryData(object)) {
|
return;
|
}
|
String parentId = "root";
|
// Object currentSelectedObject = getOperate().getToolBar().getMainPanel().getCurrentSelectedObject();
|
// if (currentSelectedObject instanceof ProcessCategoryObject) {
|
// parentId = ((ProcessCategoryObject)currentSelectedObject).getParentId();
|
// };
|
object.setParentId(parentId);
|
try {
|
if(!checkNameExisted(object)) return;
|
preferLibraryDelegate.updateProcessCategory(object);
|
// operate.getToolBar().getMainPanel().refreshModifyObjectToTree(object);
|
close();
|
} catch (VCIError ex) {
|
VCIOptionPane.showError(LogonApplication.frame,
|
LocaleDisplay.getI18nString(String.valueOf(ex.code), "RMIPWorkflow", getLocale()));
|
}
|
}
|
}
|
|
private ProcessCategoryObject getModifyPreferLibrary() {
|
ProcessCategoryObject obj = getProcessCategoryFromUIControl();
|
if (this.processCategoryObject != null) {
|
obj.setId(this.processCategoryObject.getId());
|
}
|
return obj;
|
}
|
|
private boolean checkNameExisted(ProcessCategoryObject object) throws VCIError{
|
boolean res = true;
|
//判断是否存在相同名称的模板分类
|
if(preferLibraryDelegate.existProcessCategory(object.getId(), object.getName())){
|
VCIOptionPane.showError(LogonApplication.frame, getI18nString("nameDuplicated"));
|
nameField.requestFocus();
|
nameField.selectAll();
|
return false;
|
}
|
return res;
|
}
|
|
private void close() {
|
this.dispose();
|
this.setVisible(false);
|
}
|
|
public ProcessCategoryObject getCreateProcessCategory() {
|
return getProcessCategoryFromUIControl();
|
}
|
|
public ProcessCategoryObject getModifyProcessCategory() {
|
ProcessCategoryObject obj = getProcessCategoryFromUIControl();
|
if (this.processCategoryObject != null) {
|
obj.setId(this.processCategoryObject.getId());
|
}
|
return obj;
|
}
|
|
/**
|
* <p>Description: 获取页面填写内容,并将其构建成集成任务对象</p>
|
*/
|
private ProcessCategoryObject getProcessCategoryFromUIControl() {
|
ProcessCategoryObject obj = new ProcessCategoryObject();
|
obj.setName(this.nameField.getText());
|
obj.setIcon(getIconFromIconButton());
|
obj.setDesc(this.descArea.getText());
|
obj.setCreateUser(LogonApplication.getUserEntityObject().getUserName());
|
obj.setModifyUser(LogonApplication.getUserEntityObject().getUserName());
|
return obj;
|
}
|
|
/**
|
* <p>Description: 根据被修改对象的内容初始化编辑对话框</p>
|
*/
|
private void setUIContent() {
|
this.nameField.setText(this.processCategoryObject.getName());
|
this.descArea.setText(this.processCategoryObject.getDesc());
|
String icon = this.processCategoryObject.getIcon();
|
if(!icon.equals("")){
|
selectIconBtn.setIcon(new BundleImage().createImageIcon(icon));
|
}
|
}
|
|
/**
|
* 检查优选库数据
|
* @param object
|
* @return
|
*/
|
public boolean checkProcessCategoryData(ProcessCategoryObject object){
|
boolean res = false;
|
if(object.getName().equals("")){
|
VCIOptionPane.showMessage(this, getI18nString("nameIsNotNull"));
|
}else{
|
res = true;
|
}
|
return res;
|
}
|
|
/**
|
* <p>Description: 获取去图标按钮选择的图片</p>
|
*/
|
private String getIconFromIconButton(){
|
String icon = this.selectIconBtn.getIcon().toString();
|
return icon.substring(icon.lastIndexOf("/") + 1);
|
}
|
|
private String getI18nString(String code){
|
return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + code, this.getLocale());
|
}
|
}
|