package com.vci.client.workflow.template;
|
|
import java.awt.BorderLayout;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseEvent;
|
import java.util.ArrayList;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Set;
|
|
import javax.swing.JComponent;
|
import javax.swing.JMenuItem;
|
import javax.swing.JPanel;
|
import javax.swing.JPopupMenu;
|
import javax.swing.JScrollPane;
|
import javax.swing.JSplitPane;
|
import javax.swing.event.TreeExpansionEvent;
|
import javax.swing.event.TreeExpansionListener;
|
import javax.swing.event.TreeSelectionEvent;
|
import javax.swing.event.TreeSelectionListener;
|
import javax.swing.tree.TreeNode;
|
import javax.swing.tree.TreePath;
|
|
import com.vci.client.LogonApplication;
|
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.swing.VCIOptionPane;
|
import com.vci.client.ui.tree.VCIBaseTree;
|
import com.vci.client.ui.tree.VCIBaseTreeModel;
|
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.client.workflow.template.object.RMTypeObject;
|
|
public class ProcessCustomPanel extends VCIBasePanel {
|
|
private static final long serialVersionUID = 3053694281232264263L;
|
|
private VCIBaseTree leftTree = null;
|
private VCIBaseTreeModel treeModel = null;
|
private VCIBaseTreeNode rootNode = null;
|
|
private ProcessCustomToolBar toolBar = null;
|
JComponent rightPanel = null;
|
JPanel rightEmptyPanel = new JPanel();
|
|
private JSplitPane splitPane;
|
|
private JPopupMenu popupMenu = new JPopupMenu();// 弹出式菜单
|
private JMenuItem menuitem_cute = new JMenuItem("剪切");
|
private JMenuItem menuitem_past = new JMenuItem("粘贴");
|
private Set<TreePath> movePath;
|
|
// 保存剪切和粘贴的临时数据
|
private List<VCIBaseTreeNode> tempTreeNode = new ArrayList<VCIBaseTreeNode>();
|
|
FunctionObject object = new FunctionObject();
|
|
public void setLeftTree(VCIBaseTree leftTree) {
|
this.leftTree = leftTree;
|
}
|
|
public ProcessCustomPanel(FunctionObject object) {
|
super(object);
|
this.object = object;
|
// LogonApplication.frame.getUserEntityObject().setModules(this.getClass().getName());
|
init();
|
}
|
|
private void init() {
|
JScrollPane leftScrPane = new JScrollPane();
|
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrPane, rightEmptyPanel);
|
splitPane.setDividerSize(10);
|
splitPane.setContinuousLayout(true);
|
splitPane.setOneTouchExpandable(true);
|
splitPane.setDividerLocation(200);
|
this.setLayout(new BorderLayout());
|
this.add(splitPane, BorderLayout.CENTER);
|
initLeftPanel(leftScrPane);
|
}
|
|
private void initLeftPanel(JScrollPane leftJsp) {
|
String rootObj = "root";
|
rootNode = new VCIBaseTreeNode(this.getI18nString("treeRootNodeName"), rootObj);
|
treeModel = new VCIBaseTreeModel(rootNode);
|
leftTree = new VCIBaseTree(treeModel, new ProcessCategoryTreeCellRender());
|
// leftTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
|
popupMenu.add(menuitem_cute);
|
popupMenu.add(menuitem_past);
|
|
leftTree.addTreeSelectionListener(new TreeSelectionListener() {
|
public void valueChanged(TreeSelectionEvent e) {
|
treeValueChanged(e);
|
}
|
});
|
leftTree.addTreeExpansionListener(new TreeExpansionListener() {
|
public void treeExpanded(TreeExpansionEvent event) {
|
TreePath treePath = event.getPath();
|
VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent();
|
if (!selectNode.isExpand() && !selectNode.getObj().equals("root")) {
|
selectNode.removeAllChildren();
|
getExpandTreeData(selectNode);
|
}
|
}
|
|
public void treeCollapsed(TreeExpansionEvent event) {
|
}
|
});
|
leftTree.addMouseListener(new MouseAdapter() {
|
@Override
|
public void mouseClicked(MouseEvent e) {
|
super.mouseClicked(e);
|
// TreePath treePath = leftTree.getPathForLocation(e.getX(), e.getY());
|
TreePath[] treePath = leftTree.getSelectionPaths();
|
VCIBaseTreeNode node = (VCIBaseTreeNode) leftTree.getSelectionPath().getLastPathComponent();
|
|
if (!(node.getObj() instanceof String)) {
|
movePath = new HashSet<TreePath>();
|
for (TreePath tp : treePath) {
|
movePath.add(tp);
|
}
|
}
|
};
|
|
@Override
|
public void mouseReleased(MouseEvent e) {
|
super.mouseReleased(e);
|
TreePath treePath = leftTree.getPathForLocation(e.getX(), e.getY());
|
if (treePath == null) {
|
return;
|
}
|
VCIBaseTreeNode node = (VCIBaseTreeNode) treePath.getLastPathComponent();
|
Object obj = node.getObj();
|
if (e.isPopupTrigger()) {
|
if (obj instanceof ProcessCategoryObject) {
|
menuitem_cute.setEnabled(false);
|
menuitem_past.setEnabled(true);
|
} else if (obj instanceof ProcessDefinitionObject) {
|
menuitem_cute.setEnabled(true);
|
menuitem_past.setEnabled(false);
|
}
|
popupMenu.show(leftTree, e.getX(), e.getY());
|
}
|
}
|
});
|
// 剪切事件
|
menuitem_cute.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
for (TreePath tp : movePath) {
|
VCIBaseTreeNode node = (VCIBaseTreeNode) tp.getLastPathComponent();
|
if (node != null) {
|
tempTreeNode.add(node);
|
}
|
}
|
}
|
});
|
// 粘贴事件
|
menuitem_past.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
if (tempTreeNode == null) {
|
return;
|
}
|
// 分类id
|
String categoryId = "";
|
// 模板id
|
String deploymentId = "";
|
VCIBaseTreeNode expendNode = null;
|
for (TreePath tp : movePath) {
|
VCIBaseTreeNode parentNode = (VCIBaseTreeNode) tp.getLastPathComponent();
|
Object obj = parentNode.getObj();
|
if (obj instanceof ProcessCategoryObject) {
|
categoryId = ((ProcessCategoryObject) obj).getId();
|
for (VCIBaseTreeNode nd : tempTreeNode) {
|
if (nd.getObj() instanceof ProcessDefinitionObject) {
|
ProcessDefinitionObject definitionObj = (ProcessDefinitionObject) nd.getObj();
|
deploymentId = definitionObj.getJbpmDeploymentId();
|
// if(nd.isExpand()){
|
treeModel.insertNodeInto(nd, parentNode, parentNode.getChildCount());
|
// }
|
parentNode.setExpand(true);
|
ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(
|
LogonApplication.getUserEntityObject());
|
try {
|
delegate.moveDefinition(deploymentId, categoryId);
|
} catch (VCIException e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
}
|
}
|
tempTreeNode = new ArrayList<VCIBaseTreeNode>();
|
movePath = new HashSet<TreePath>();
|
leftTree.updateUI();
|
|
}
|
});
|
|
leftJsp.getViewport().add(leftTree);
|
initLeftTree(rootNode);
|
}
|
|
protected void treeValueChanged(TreeSelectionEvent e) {
|
TreePath treePath = e.getPath();
|
if (treePath == null) {
|
splitPane.setRightComponent(rightEmptyPanel);
|
return;
|
}
|
|
VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent();
|
Object object = selectNode.getObj();
|
ProcessDefinitionObject processDefinitionObject = null;
|
|
if (object instanceof ProcessDefinitionObject) {
|
processDefinitionObject = (ProcessDefinitionObject) object;
|
if (rightPanel == null) {
|
rightPanel = new ProcessDefinitionPanel();
|
}
|
((ProcessDefinitionPanel) rightPanel).setObject(processDefinitionObject);
|
splitPane.setRightComponent(rightPanel);
|
} else {
|
splitPane.setRightComponent(rightEmptyPanel);
|
}
|
int location = splitPane.getDividerLocation();
|
splitPane.setDividerLocation(location);
|
}
|
|
public ProcessCustomToolBar getSpecialToolBar() {
|
if (toolBar == null) {
|
toolBar = new ProcessCustomToolBar(LogonApplication.frame, this);
|
}
|
return toolBar;
|
}
|
|
/**
|
* 返回当前选中的树节点
|
*
|
* @return
|
*/
|
public VCIBaseTreeNode getCurrentSelectedTreeNode() {
|
return (VCIBaseTreeNode) this.leftTree.getLastSelectedPathComponent();
|
}
|
|
public Object getCurrentSelectedObject() {
|
return this.getCurrentSelectedTreeNode().getObj();
|
}
|
|
/**
|
* toolbar上的刷新按钮会调用该方法
|
*/
|
public void updateTree() {
|
((VCIBaseTreeNode) this.leftTree.getLastSelectedPathComponent()).removeAllChildren();
|
getExpandTreeData(((VCIBaseTreeNode) this.leftTree.getLastSelectedPathComponent()));
|
this.leftTree.updateUI();
|
}
|
|
private void getExpandTreeData(VCIBaseTreeNode treeNode) {
|
try {
|
String processCategoryId = "";
|
Object nodeObject = treeNode.getObj();
|
|
if (nodeObject instanceof String && nodeObject.toString().equals("root")) {
|
initLeftTree(rootNode);
|
} else {
|
if (nodeObject instanceof ProcessCategoryObject) {
|
processCategoryId = ((ProcessCategoryObject) nodeObject).getId();
|
} else if (nodeObject instanceof RMTypeObject) {
|
TreeNode[] treeNodes = treeNode.getPath();
|
processCategoryId = ((ProcessCategoryObject) (((VCIBaseTreeNode) treeNodes[1]).getObj())).getId();
|
}
|
// refresh tree from db
|
ProcessCategoryObject[] processCategories = new ProcessCustomClientDelegate(
|
LogonApplication.getUserEntityObject()).getProcessCategories(processCategoryId);
|
for (ProcessCategoryObject obj : processCategories) {
|
VCIBaseTreeNode node = new VCIBaseTreeNode(obj.getName(), obj);
|
treeModel.insertNodeInto(node, treeNode, treeNode.getChildCount());
|
treeNode.setExpand(true);
|
}
|
|
ProcessDefinitionObject[] processDefinitions = new ProcessCustomClientDelegate(
|
LogonApplication.getUserEntityObject()).getProcessDefinitions(processCategoryId);
|
if (processDefinitions != null && processDefinitions.length > 0) {
|
for (ProcessDefinitionObject processDefinitionObject : processDefinitions) {
|
String nodeName = processDefinitionObject.toString();
|
VCIBaseTreeNode node = new VCIBaseTreeNode(nodeName, processDefinitionObject);
|
node.setLeaf(true);
|
treeModel.insertNodeInto(node, treeNode, treeNode.getChildCount());
|
}
|
treeNode.setExpand(true);
|
}
|
}
|
} catch (VCIException ex) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", ex);
|
}
|
}
|
|
public void initLeftTree() {
|
initLeftTree(this.rootNode);
|
}
|
|
public void initLeftTree(VCIBaseTreeNode treeNode) {
|
try {
|
ProcessCustomClientDelegate delSrv = new ProcessCustomClientDelegate(
|
LogonApplication.getUserEntityObject());
|
ProcessCategoryObject[] processCategories = delSrv.getProcessCategories("root");
|
treeNode.removeAllChildren();
|
for (ProcessCategoryObject obj : processCategories) {
|
VCIBaseTreeNode node = new VCIBaseTreeNode(obj.getName(), obj);
|
treeNode.add(node);
|
}
|
|
this.leftTree.setSelectionPath(new TreePath(treeNode));
|
this.leftTree.updateUI();
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", e);
|
return;
|
}
|
}
|
|
public void setEmptyPanel() {
|
splitPane.setRightComponent(rightEmptyPanel);
|
int location = splitPane.getDividerLocation();
|
splitPane.setDividerLocation(location);
|
}
|
|
public void addNewObjectToTree(ProcessCategoryObject object) {
|
VCIBaseTreeNode newNode = new VCIBaseTreeNode(object.getName(), object);
|
this.treeModel.insertNodeInto(newNode, getCurrentSelectedTreeNode(),
|
getCurrentSelectedTreeNode().getChildCount());
|
this.leftTree.setSelectionPath(new TreePath(newNode.getPath()));
|
this.leftTree.updateUI();
|
}
|
|
public void refreshModifyObjectToTree(ProcessCategoryObject object) {
|
VCIBaseTreeNode modifyNode = getCurrentSelectedTreeNode();
|
modifyNode.setUserObject(object.getName());
|
modifyNode.setObj(object);
|
this.leftTree.setSelectionPath(new TreePath(modifyNode.getPath()));
|
this.leftTree.updateUI();
|
}
|
|
public void removeNode(VCIBaseTreeNode treeNode) {
|
treeNode.removeFromParent();
|
this.leftTree.updateUI();
|
}
|
|
public VCIBaseTree getLeftTree() {
|
return leftTree;
|
}
|
|
private String getI18nString(String spCode) {
|
return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, this.getLocale());
|
}
|
}
|