package com.vci.client.workflow.template;
|
|
import java.awt.BorderLayout;
|
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 javax.swing.tree.TreePath;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.IconSelectDialog;
|
import com.vci.client.common.VCIBasePanel;
|
import com.vci.client.framework.rightConfig.object.FunctionObject;
|
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.ui.tree.VCIBaseTreeNode;
|
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.client.workflow.template.object.ProcessDefinitionObject;
|
import com.vci.corba.common.VCIError;
|
|
|
|
/**
|
* @author liudi
|
*
|
* 2012-5-21
|
*/
|
public class ProcessCategoryPanel extends VCIBasePanel {
|
|
private static final long serialVersionUID = 8564910826301969195L;
|
|
private KJButton okBtn = new KJButton(this.getI18nString("btnOk"), "ok.gif");
|
private KJButton cancelBtn = new KJButton(this.getI18nString("btnCancel"), "cancel.gif");
|
private KJButton selectIconBtn = new KJButton(this.getI18nString("btnChooseIcon"), "process_edit.gif");
|
private KTextField nameField = new KTextField();
|
private JTextArea descArea = new JTextArea();
|
|
private String optType = null;
|
private ProcessCustomOperate operate = null;
|
private ProcessCategoryObject processCategoryObject = null;
|
|
private ProcessCustomClientDelegate preferLibraryDelegate ;
|
|
KJButton addBtn = new KJButton("新建", "add.png");
|
KJButton editBtn = new KJButton("修改", "edit.png");
|
KJButton delBtn = new KJButton("删除", "delete.png");
|
|
ProcessCustomPanel panel;
|
public ProcessCategoryPanel(ProcessCustomPanel panel,FunctionObject object) throws VCIException{
|
super(object);
|
preferLibraryDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
|
// this.processCategoryObject = processCategoryObject;
|
this.panel = panel;
|
init();
|
}
|
public ProcessCategoryPanel(String optType, ProcessCategoryObject processCategoryObject,FunctionObject object) throws VCIException {
|
super(object);
|
preferLibraryDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
|
this.optType = optType;
|
this.processCategoryObject = processCategoryObject;
|
|
init();
|
// checkPermission();
|
}
|
|
private void init() throws VCIException {
|
initPanelContent();
|
// if (optType.equals("create")) {
|
// this.setTitle(this.getI18nString("createTitle"));
|
// } else if (optType.equals("modify")) {
|
// this.setTitle(this.getI18nString("modifyTitle"));
|
this.setUIContent();
|
// }
|
addListener();
|
}
|
|
/**
|
* <p>Description: 初始所有UI元素</p>
|
*/
|
private void initPanelContent() {
|
JPanel panel = new JPanel();
|
BorderLayout thisLayout = new BorderLayout();
|
setLayout(thisLayout);
|
panel.setLayout(null);
|
|
JLabel lblNewLabel = new JLabel(this.getI18nString("lblName"));
|
lblNewLabel.setBounds(222, 60, 60, 25);
|
panel.add(lblNewLabel);
|
|
nameField.setBounds(260, 60, 300, 25);
|
panel.add(nameField);
|
|
JLabel descLabel = new JLabel(getI18nString("lblDesc"));
|
descLabel.setBounds(222, 120, 60, 25);
|
panel.add(descLabel);
|
|
JScrollPane scrollPane = new JScrollPane();
|
scrollPane.getViewport().add(descArea);
|
scrollPane.setBounds(260, 120, 300, 120);
|
panel.add(scrollPane);
|
add(panel,BorderLayout.CENTER);
|
|
JPanel btnPanel = new JPanel();
|
btnPanel.add(addBtn);
|
btnPanel.add(editBtn);
|
btnPanel.add(delBtn);
|
add(btnPanel,BorderLayout.SOUTH);
|
// panel.setPreferredSize(new java.awt.Dimension(205, 142));
|
}
|
|
/**
|
* <p>Description: 初始化所有按钮关联的操作监听</p>
|
*/
|
private void addListener() {
|
selectIconBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
selectIcon();
|
}
|
});
|
|
addBtn.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
ok("create");
|
}
|
|
});
|
editBtn.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
ok("edit") ;
|
}
|
});
|
delBtn.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
// ok();
|
deleteProcessCategory();
|
}
|
});
|
// okBtn.addActionListener(new ActionListener() {
|
// public void actionPerformed(ActionEvent e) {
|
// ok();
|
// }
|
// });
|
//
|
// cancelBtn.addActionListener(new ActionListener() {
|
// public void actionPerformed(ActionEvent e) {
|
// }
|
// });
|
}
|
public void deleteProcessCategory() {
|
// ProcessCustomPanel mainPanel = panel;
|
Object selectedObject = panel.getCurrentSelectedObject();
|
if (selectedObject instanceof ProcessCategoryObject) {
|
if (VCIOptionPane.showQuestion(LogonApplication.frame, ClientHelper
|
.getI18nStringForWorkflow(this.getClass().getName() + "."
|
+ "deleteProcessCategoryConfirmMessage",
|
panel.getLocale())) != 0) {
|
return;
|
}
|
ProcessCategoryObject object = (ProcessCategoryObject) selectedObject;
|
deleteProcessCategoryClassify(object.getId());
|
} else {
|
VCIOptionPane.showError(LogonApplication.frame, ClientHelper
|
.getI18nStringForWorkflow(this.getClass().getName() + "."
|
+ "pleaseChooseTreeNode", panel.getLocale()));
|
}
|
}
|
|
private void deleteProcessCategoryClassify(String id) {
|
try {
|
ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
|
ProcessDefinitionObject[] processDefinitions = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getProcessDefinitions(id);
|
if(processDefinitions.length>0){
|
VCIOptionPane.showMessage(LogonApplication.frame, "分类下有模板,请先删除模版!");
|
return;
|
}else{
|
boolean rs = delegate.deleteProcessCategory(id);
|
if (rs) {
|
VCIBaseTreeNode node = panel.getCurrentSelectedTreeNode();
|
panel.removeNode(node);
|
panel.getLeftTree().setSelectionPath(new TreePath(panel.getRootPane()));
|
panel.setEmptyPanel();
|
}
|
}
|
} catch (VCIException exp) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", exp);
|
}
|
}
|
private void selectIcon() {
|
String title = getI18nString("lblIcon");
|
IconSelectDialog iconDialog = new IconSelectDialog(title, true, optType, selectIconBtn);
|
iconDialog.setVisible(true);
|
}
|
|
private void ok(String opertype) {
|
if(opertype.equalsIgnoreCase("create")){
|
ProcessCategoryObject object = getCreateProcessCategory();
|
if (!checkProcessCategoryData(object)) {
|
return;
|
}
|
String parentId = "root";
|
// Object currentSelectedObject = getOperate().getToolBar().getMainPanel().getCurrentSelectedObject();
|
Object currentSelectedObject = panel.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);
|
panel.addNewObjectToTree(object);
|
} 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 = panel.getCurrentSelectedObject();
|
if (currentSelectedObject instanceof ProcessCategoryObject) {
|
parentId = ((ProcessCategoryObject)currentSelectedObject).getParentId();
|
};
|
object.setParentId(parentId);
|
try {
|
if(!checkNameExisted(object)) return;
|
preferLibraryDelegate.updateProcessCategory(object);
|
panel.refreshModifyObjectToTree(object);
|
} 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());
|
// }
|
Object object = panel.getCurrentSelectedObject();
|
if(object instanceof ProcessCategoryObject){
|
ProcessCategoryObject pcObject = (ProcessCategoryObject) object;
|
if(pcObject!=null){
|
obj.setId(pcObject.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;
|
}
|
|
public ProcessCategoryObject getCreateProcessCategory() {
|
return getProcessCategoryFromUIControl();
|
}
|
|
public ProcessCategoryObject getModifyProcessCategory() {
|
ProcessCategoryObject obj = getProcessCategoryFromUIControl();
|
Object object = panel.getCurrentSelectedObject();
|
if(object instanceof ProcessCategoryObject){
|
ProcessCategoryObject pcObject = (ProcessCategoryObject) object;
|
if(pcObject!=null){
|
obj.setId(pcObject.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() {
|
Object object = panel.getCurrentSelectedObject();
|
if(object instanceof ProcessCategoryObject){
|
ProcessCategoryObject pcObject = (ProcessCategoryObject) object;
|
|
this.nameField.setText(pcObject.getName());
|
this.descArea.setText(pcObject.getDesc());
|
String icon = pcObject.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());
|
}
|
|
public ProcessCustomOperate getOperate() {
|
return this.operate;
|
}
|
|
private void initGUI() {
|
try {
|
{
|
this.setPreferredSize(new java.awt.Dimension(265, 159));
|
}
|
} catch(Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|