/*
|
* 此类主要是实现生命周期模板的创建功能,以及对已经创建好的生命周期模板的各种操作,主要用的了jgraph的相关知识。
|
* */
|
package com.vci.client.omd.lifecycle.ui;
|
|
import java.awt.BorderLayout;
|
import java.awt.Color;
|
import java.awt.Cursor;
|
import java.awt.Dimension;
|
import java.awt.FlowLayout;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.HeadlessException;
|
import java.awt.Insets;
|
import java.awt.Point;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemListener;
|
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyEvent;
|
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseListener;
|
import java.awt.event.MouseMotionListener;
|
import java.awt.geom.Point2D;
|
import java.awt.geom.Rectangle2D;
|
import java.net.MalformedURLException;
|
import java.net.URL;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Map;
|
import javax.swing.BorderFactory;
|
import javax.swing.Icon;
|
import javax.swing.ImageIcon;
|
import javax.swing.JButton;
|
import javax.swing.JComboBox;
|
import javax.swing.JLabel;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JSplitPane;
|
import javax.swing.JTable;
|
import javax.swing.JTextArea;
|
import javax.swing.JTextField;
|
import javax.swing.JTree;
|
import javax.swing.ScrollPaneConstants;
|
import javax.swing.table.TableColumnModel;
|
import javax.swing.text.BadLocationException;
|
import javax.swing.text.PlainDocument;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.TreeNode;
|
import javax.swing.tree.TreePath;
|
|
import org.dom4j.DocumentException;
|
import org.jgraph.JGraph;
|
import org.jgraph.event.GraphModelEvent;
|
import org.jgraph.event.GraphModelListener;
|
import org.jgraph.graph.DefaultEdge;
|
import org.jgraph.graph.DefaultGraphCell;
|
import org.jgraph.graph.DefaultGraphModel;
|
import org.jgraph.graph.DefaultPort;
|
import org.jgraph.graph.GraphConstants;
|
import org.jgraph.graph.GraphLayoutCache;
|
|
import com.vci.mw.InvocationUtility;
|
import com.vci.client.omd.lifecycle.LifeCycleStart;
|
import com.vci.client.omd.lifecycle.itf.InterLCy;
|
import com.vci.client.omd.lifecycle.pubimpl.InterLCyManager;
|
import com.vci.client.omd.lifecycle.pubimpl.LifeCycleTransitionEvents;
|
import com.vci.client.ui.image.BundleImage;
|
import com.vci.client.ui.util.PostorderEnumeration;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.omd.lcm.Bound;
|
import com.vci.corba.omd.lcm.LifeCycle;
|
import com.vci.corba.omd.lcm.TransitionVO;
|
import com.vci.corba.omd.lcm.TransitionVOEvent;
|
|
public class LifeCyclePanel extends JPanel {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
private static LifeCyclePanel lifecycleUI = null;
|
|
// private ImageIcon imageIcon = null;
|
|
// private String imageName = "";
|
|
// static boolean isNoPressSaveTransitionEvents = false;
|
|
//private boolean door = false;
|
/**
|
* 跃迁事件全局变量
|
*/
|
|
// private List<Map<String, List<TransitionVOEvent>>> transitionevents_maps =
|
// get_transitionevents_maps_instance();
|
private Map<String, List<TransitionVOEvent>> mapTransitionEvents;
|
|
// 用户设置跃迁事件的跃迁对象集合
|
private List<TransitionVO> transitionVOs = getTransitionVOListInstance();
|
|
// 跃迁事件集合
|
private List<TransitionVOEvent> transationEvents = null;
|
|
//private List<TransitionVO> transitionVOs;
|
|
private JTable tableEvent = null;
|
|
private LifeCycleTableModel eventTableModel = null;
|
|
//private JScrollPane s_pan = null;
|
|
private JButton deleteTansitionEventButton = null, addTansitionEventButton = null, saveTansitionEventButton = null;// ,
|
// selectedLcStartState = null;
|
|
//private JPanel northJPanel = null;
|
|
//private JPanel westJPanel;// = new JPanel();
|
// add by caill start 2016.3.31
|
// 创建westCenterJPanel用来盛放splitPane,创建splitPane用来分割生命周期和状态区域
|
//private JPanel westCenterJPanel;// = new JPanel();
|
private JSplitPane splitPane;// = new JSplitPane(JSplitPane.VERTICAL_SPLIT);;
|
// add by caill end
|
|
//private JPanel westTopJPanel;// = new JPanel();
|
private JTextField textField;// = new JTextField();
|
private JButton btnSelect;// = new JButton("定位");
|
|
//private JPanel eastJpanel;// = new JPanel();
|
|
private String[] eventKeys;// = LifeCycleTransitionEvents.get_lce_events_keys();
|
|
private JPanel mainPanel;// = new JPanel();
|
|
// private JPanel panelBase;
|
private int editingFlag = 0;
|
//private JPanel jp1;
|
//private JPanel eastJPanel1;// = new JPanel();
|
// private static JPanel eastJPanel2 = new JPanel();
|
private JButton addButton;
|
private JButton modifyButton;
|
private JButton deleteButton;
|
private JButton checkButton;
|
private JButton saveButton;
|
private JButton cancelButton;
|
|
private JTextField textFieldName;// = new JTextField(45);
|
private JTextField textFieldTag;// = new JTextField(45);
|
private JComboBox lc_startState;// = new JComboBox();
|
private JTextField textFieldFromStatus;// = new JTextField(45);
|
private JTextField textFieldToStatus;// = new JTextField(45);
|
private JTextField textFieldEdgeName;// = new JTextField(45);
|
private JTextField textFieldEdgeType;// = new JTextField(45);
|
private JTextArea textFieldDescription;// = new JTextArea(5, 45);
|
|
// private DefaultGraphCell[] cellsBounds = null;
|
// private DefaultGraphCell[] cellsRoutes = null;
|
// private DefaultGraphCell[] cellsLifecyles = null;
|
|
// ArrayList<DefaultGraphCell> cells = new ArrayList<DefaultGraphCell>();
|
// ArrayList<DefaultEdge> cells1 = new ArrayList<DefaultEdge>();
|
// Map<String, String> map = new HashMap<String, String>();
|
// 定义滚动条用于存放tree
|
//private JScrollPane scrollPane;// = new JScrollPane();
|
|
//private JScrollPane jScrollPane;// = new JScrollPane(lcGraph);
|
//private WestJpanel wj;// = new WestJpanel();
|
//private JScrollPane weScrollPane;// = new JScrollPane(wj);
|
|
//private JScrollPane westsPane;// = new JScrollPane();
|
//private JScrollPane eastsScrollPane;// = new JScrollPane();
|
// 定义一棵树
|
private JTree treeLifeCycle;
|
// private String nodeName = null;
|
//Point point = new Point(0, 0);
|
//Point newPoint = new Point(0, 0);
|
|
private JButton btnExp;
|
|
private JButton btnImp;
|
|
private LifeCycleGraph lcGraph;// = (LifeCycleGraph) new LifeCycleGraph();
|
|
Dimension dimScreen = Toolkit.getDefaultToolkit().getScreenSize();
|
|
public static LifeCyclePanel getInstance() {
|
if (lifecycleUI == null) {
|
lifecycleUI = new LifeCyclePanel();
|
return lifecycleUI;
|
}
|
// flushed();// add by caill 2016.3.31初始化时刷新左侧导航栏的数据
|
// eastJPanel1.removeAll();
|
// eastJPanel1.updateUI();
|
// eastJPanel1.add(lifecycleUI.createBaseInfoPanel(), BorderLayout.CENTER);
|
// selectedLcStartState.setEnabled(false);
|
return lifecycleUI;
|
}
|
|
// 构造器,用于初始化首先要执行的操作
|
protected LifeCyclePanel() {
|
initComponent();
|
//createLifeCycleTree();
|
saveListeneradd();
|
addListeneradd();
|
addListenerdelete();
|
addListenermodify();
|
addListenercancel();
|
// add by guo 起始状态发生改变的时候,后面的按钮中的图片也跟着改变
|
addListenerStartStateChanged();
|
// 跃迁监听事件
|
addTransationListener();
|
deleteTransationListener();
|
saveTransationListener();
|
// 查看使用范围事件
|
addListenner();
|
btnExp.addActionListener(new ExpActionListener());
|
btnImp.addActionListener(new ImpActionListener());
|
}
|
|
public LifeCycleGraph getGraph() {
|
return lcGraph;
|
}
|
|
private void addListenerStartStateChanged() {
|
// TODO Auto-generated method stub
|
lc_startState.addItemListener(new ItemListener() {
|
@Override
|
public void itemStateChanged(ItemEvent e) {
|
// TODO Auto-generated method stub
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
List<Bound> bounds = ImageSelectDialog.getInstance().getbounds();
|
String selectedName = (String) lc_startState.getSelectedItem();
|
for (Bound bound : bounds) {
|
if (bound.name.equals(selectedName)) {
|
// String imageiconName = bound.cellicon;
|
// ImageIcon icon = new BundleImage().createImageIcon(imageiconName);
|
// selectedLcStartState.setIcon(icon);
|
return;
|
}
|
}
|
}
|
}
|
});
|
}
|
|
private void initVars() {
|
// imageIcon = null;
|
// isNoPressSaveTransitionEvents = false;
|
//door = false;
|
// transitionevents_maps = get_transitionevents_maps_instance();
|
|
mapTransitionEvents = new HashMap<String, List<TransitionVOEvent>>();
|
|
transitionVOs = getTransitionVOListInstance();
|
transationEvents = null;
|
//transitionVOs = null;
|
tableEvent = null;
|
eventTableModel = null;
|
deleteTansitionEventButton = null;
|
addTansitionEventButton = null;
|
saveTansitionEventButton = null;
|
// selectedLcStartState = null;
|
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
textField = new JTextField();
|
btnSelect = new JButton("定位");
|
|
eventKeys = LifeCycleTransitionEvents.get_lce_events_keys();
|
// lifecycleUI = null;
|
//jp1 = null;
|
|
textFieldName = new JTextField(45);
|
textFieldTag = new JTextField(45);
|
lc_startState = new JComboBox();
|
lc_startState.setEditable(false);
|
textFieldFromStatus = new JTextField(45);
|
textFieldToStatus = new JTextField(45);
|
textFieldEdgeName = new JTextField(45);
|
textFieldEdgeType = new JTextField(45);
|
textFieldDescription = new JTextArea(5, 45);
|
// cellsBounds = null;
|
// cellsRoutes = null;
|
// cellsLifecyles = null;
|
//WestJpanel wj = new WestJpanel();
|
|
|
treeLifeCycle = null;
|
// nodeName = null;
|
lcGraph = (LifeCycleGraph) new LifeCycleGraph();
|
dimScreen = Toolkit.getDefaultToolkit().getScreenSize();
|
}
|
|
// public static void cleanInstance() {
|
// initVars();
|
// lifecycleUI = null;
|
// }
|
|
// public List<Map<String, List<TransitionVOEvent>>> get_transitionevents_maps_instance() {
|
// if (transitionevents_maps == null) {
|
// transitionevents_maps = new ArrayList<Map<String, List<TransitionVOEvent>>>();
|
// }
|
// return transitionevents_maps;
|
// }
|
|
public List<TransitionVO> getTransitionVOListInstance() {
|
if (transitionVOs == null) {
|
transitionVOs = new ArrayList<TransitionVO>();
|
}
|
return transitionVOs;
|
}
|
|
// 页面布局,首次进入的时候所看到的页面
|
public void initComponent() {
|
initVars();
|
|
mainPanel = new JPanel();
|
|
//door = false;
|
setLayout(new BorderLayout());
|
JPanel northJPanel = new JPanel();
|
FlowLayout fl = (FlowLayout) northJPanel.getLayout();
|
fl.setAlignment(FlowLayout.CENTER);
|
this.add(northJPanel, BorderLayout.PAGE_START);
|
addButton = new JButton("创建");
|
modifyButton = new JButton("修改");
|
deleteButton = new JButton("删除");
|
checkButton = new JButton("查看使用范围");
|
saveButton = new JButton("保存");
|
cancelButton = new JButton("取消");
|
btnExp = new JButton("导出");
|
btnImp = new JButton("导入");
|
|
deleteTansitionEventButton = new JButton("删除");
|
addTansitionEventButton = new JButton("添加");
|
saveTansitionEventButton = new JButton("保存");
|
|
JScrollPane jScrollPane = new JScrollPane(lcGraph);
|
northJPanel.add(addButton);
|
northJPanel.add(modifyButton);
|
northJPanel.add(deleteButton);
|
northJPanel.add(checkButton);
|
northJPanel.add(saveButton);
|
northJPanel.add(cancelButton);
|
northJPanel.add(btnExp);
|
northJPanel.add(btnImp);
|
saveButton.setEnabled(false);
|
cancelButton.setEnabled(false);
|
deleteTansitionEventButton.setEnabled(false);
|
addTansitionEventButton.setEnabled(false);
|
// System.out.println("265");
|
saveTansitionEventButton.setEnabled(false);
|
mainPanel.setBorder(BorderFactory.createTitledBorder("生命周期模板"));
|
mainPanel.setLayout(new GridBagLayout());
|
GridBagConstraints gbc = new GridBagConstraints();
|
gbc.anchor = GridBagConstraints.NORTH;
|
gbc.gridx = 0;
|
gbc.gridy = 0;
|
gbc.weightx = 3.0;
|
gbc.weighty = 3.0;
|
gbc.gridheight = 1;
|
gbc.fill = GridBagConstraints.BOTH;
|
// westJPanel1.setBackground(Color.WHITE);
|
// scrollPane.setViewportView(treeLifeCycle);
|
// westJPanel1.add(scrollPane,BorderLayout.WEST);
|
gbc.gridy = 1;
|
// gbc.fill = GridBagConstraints.BOTH;
|
gbc.weighty = 1.0;
|
gbc.weightx = 0.5;
|
|
// add by caill start
|
// 搜索框的设置
|
GridBagConstraints gb = new GridBagConstraints();
|
gb.gridx = 0;
|
gb.gridy = 0;
|
gb.weightx = 0.7;
|
gb.weighty = 0;
|
gb.fill = GridBagConstraints.HORIZONTAL;
|
|
JPanel westTopJPanel = new JPanel();
|
westTopJPanel.setLayout(new GridBagLayout());
|
westTopJPanel.add(textField, gb);
|
westTopJPanel.add(btnSelect);
|
|
// add by caill start 2016.3.31重新布置左侧导航栏的结构
|
JPanel westJPanel = new JPanel();
|
westJPanel.add(westTopJPanel, BorderLayout.NORTH);
|
|
JPanel westCenterJPanel = new JPanel();
|
westCenterJPanel.setLayout(new GridBagLayout());
|
GridBagConstraints gbct = new GridBagConstraints();
|
gbct.gridx = 0;
|
gbct.gridy = 0;
|
gbct.weightx = 1.0;
|
gbct.weighty = 1.0;
|
gbct.fill = GridBagConstraints.BOTH;
|
westJPanel.add(westCenterJPanel, BorderLayout.CENTER);
|
splitPane.setOneTouchExpandable(true);
|
|
JScrollPane scrollPane = new JScrollPane();
|
createLifeCycleTree();
|
scrollPane.setViewportView(treeLifeCycle);
|
splitPane.setTopComponent(scrollPane);
|
|
JScrollPane weScrollPane = new JScrollPane(new WestJpanel());
|
splitPane.setBottomComponent(weScrollPane);
|
|
splitPane.setDividerLocation(dimScreen.height / 4);
|
westCenterJPanel.add(splitPane, gbct);
|
// add by caill end
|
|
// 为定位按钮增加点击事件
|
btnSelect.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// e.getSource();
|
String test = textField.getText().trim();
|
DefaultTreeModel model = (DefaultTreeModel) treeLifeCycle.getModel();
|
model.reload();
|
TreeNode root = (TreeNode) model.getRoot();
|
PostorderEnumeration enumeration = new PostorderEnumeration(root);
|
while (enumeration.hasMoreElements()) {
|
DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration.nextElement();
|
if (element.getUserObject() instanceof LifeCycleWrapper) {
|
LifeCycleWrapper wrapper = (LifeCycleWrapper) element.getUserObject();
|
|
if (wrapper != null && wrapper.getLC() != null && wrapper.getLC().name.equals(test)) {
|
TreeNode[] path = element.getPath();
|
TreePath treePath = new TreePath(path);
|
treeLifeCycle.setSelectionPath(treePath);
|
return;
|
}
|
;
|
}
|
}
|
if (test.equals("")) {
|
JOptionPane.showMessageDialog(com.vci.client.LogonApplication.frame, "请输入生命周期", "提示",
|
JOptionPane.INFORMATION_MESSAGE);
|
} else {
|
JOptionPane.showMessageDialog(com.vci.client.LogonApplication.frame,
|
"{ " + test + " }生命周期不存在", "提示", JOptionPane.INFORMATION_MESSAGE);
|
}
|
|
}
|
|
});
|
// 为定位框添加事件
|
textField.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
|
JTextField text = (JTextField) e.getSource();
|
String test = text.getText().trim();
|
DefaultTreeModel model = (DefaultTreeModel) treeLifeCycle.getModel();
|
model.reload();
|
TreeNode root = (TreeNode) model.getRoot();
|
PostorderEnumeration enumeration = new PostorderEnumeration(root);
|
|
while (enumeration.hasMoreElements()) {
|
DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration.nextElement();
|
if (element.getUserObject() instanceof LifeCycleWrapper) {
|
LifeCycleWrapper wrapper = (LifeCycleWrapper) element.getUserObject();
|
|
if (wrapper != null && wrapper.getLC() != null && wrapper.getLC().name.equals(test)) {
|
TreeNode[] path = element.getPath();
|
TreePath treePath = new TreePath(path);
|
treeLifeCycle.setSelectionPath(treePath);
|
return;
|
}
|
;
|
}
|
}
|
if (test.equals("")) {
|
JOptionPane.showMessageDialog(com.vci.client.LogonApplication.frame, "请输入生命周期", "提示",
|
JOptionPane.INFORMATION_MESSAGE);
|
} else {
|
JOptionPane.showMessageDialog(com.vci.client.LogonApplication.frame,
|
"{ " + test + " }生命周期不存在", "提示", JOptionPane.INFORMATION_MESSAGE);
|
}
|
|
}
|
|
});
|
|
// add by caill end
|
|
// add by caill start 2016.3.31重新设置左侧导航栏各panel的高度
|
scrollPane.setPreferredSize(new Dimension(dimScreen.width / 6, dimScreen.height / 4));
|
westTopJPanel.setPreferredSize(new Dimension(dimScreen.width / 6 - 5, dimScreen.height / 40));
|
westCenterJPanel.setPreferredSize(new Dimension(dimScreen.width / 6 - 5,
|
(dimScreen.height - dimScreen.height / 40 - dimScreen.height / 5)));
|
|
westJPanel.setPreferredSize(new Dimension(dimScreen.width / 6, dimScreen.height));
|
|
JScrollPane westsPane = new JScrollPane();
|
westsPane.setPreferredSize(new Dimension(dimScreen.width / 6, dimScreen.height));
|
// add by caill end
|
westsPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);// 将左侧导航栏最底部水平的滚动条去掉
|
westsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);// 将左侧导航栏最外面的垂直的滚动条去掉
|
|
westsPane.setViewportView(westJPanel);
|
|
westsPane.repaint();
|
|
this.add(westsPane, BorderLayout.LINE_START);
|
gbc.gridx = 1;
|
gbc.gridy = 0;
|
gbc.weightx = 8.0;
|
gbc.gridheight = 2;
|
|
jScrollPane.setPreferredSize(new Dimension(dimScreen.width * (5 / 6), dimScreen.height));
|
mainPanel.add(jScrollPane, gbc);
|
mainPanel.setPreferredSize(new Dimension(dimScreen.width * (5 / 6), dimScreen.height));
|
gbc.gridx = 2;
|
gbc.gridy = 0;
|
gbc.weightx = 2.0;
|
gbc.gridheight = 1;
|
gbc.fill = GridBagConstraints.BOTH;
|
|
//JPanel eastJPanel1 = new JPanel();
|
// eastJPanel1.setBackground(Color.white);
|
// eastJPanel1.setPreferredSize(new Dimension(dimScreen.width / 3,
|
// dimScreen.height / 4));
|
|
//eastJPanel1.setPreferredSize(new Dimension(dimScreen.width / 4, 220));
|
// eastJPanel1.setBorder(BorderFactory.createEtchedBorder(1));
|
// textFieldName.setText("");
|
// textFieldTag.setText("");
|
// textFieldDescription.setText("");
|
// eastJPanel1.removeAll();
|
// eastJPanel1.updateUI();
|
// createBaseInfoPanel().setPreferredSize(new Dimension(dimScreen.width/6,
|
// dimScreen.height/4));
|
|
JPanel panel = createBaseInfoPanel();
|
panel.setPreferredSize(new Dimension(dimScreen.width / 4 - 10, 220));
|
//eastJPanel1.add(panel, BorderLayout.CENTER);
|
// mainPanel.add(eastJPanel1, gbc);
|
gbc.gridy = 1;
|
gbc.fill = GridBagConstraints.BOTH;
|
// eastJPanel2.setBackground(Color.white);
|
// eastJPanel2.setBorder(BorderFactory.createEtchedBorder(1));
|
// eastJPanel2.add(lcGraph.eastJPanelUI());
|
// eastJPanel2.setPreferredSize(new Dimension(dimScreen.width/3,
|
// dimScreen.height*(3/4)));
|
// eastJpanel.add(eastJPanel1, BorderLayout.NORTH);
|
JPanel eastJpanel = new JPanel();
|
eastJpanel.add(panel, BorderLayout.NORTH);
|
eastJpanel.add(initEastJPanelUI(), BorderLayout.SOUTH);
|
|
eastJpanel.setPreferredSize(new Dimension(dimScreen.width / 4 - 5, 0));// .height));
|
|
JScrollPane eastsScrollPane = new JScrollPane();
|
eastsScrollPane.setPreferredSize(new Dimension(dimScreen.width / 4, 0));// dimScreen.height));
|
|
eastsScrollPane.setViewportView(eastJpanel);
|
|
eastsScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
eastsScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
|
this.add(mainPanel, BorderLayout.CENTER);
|
this.add(eastsScrollPane, BorderLayout.LINE_END);
|
clearLifeCycleInfo();
|
// textFieldName.setText("");
|
// textFieldTag.setText("");
|
// textFieldFromStatus.setText("");
|
// textFieldToStatus.setText("");
|
// textFieldEdgeName.setText("");
|
// textFieldEdgeType.setText("");
|
// textFieldDescription.setText("");
|
|
setModifyState(false);
|
// textFieldName.setEditable(false);
|
// textFieldTag.setEditable(false);
|
// textFieldDescription.setEditable(false);
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
// lc_startState.setEditable(false);
|
// selectedLcStartState.setEnabled(false);
|
|
}
|
|
// 右下角的显示页面,为跃迁的显示做准备
|
private JPanel initEastJPanelUI() {
|
JPanel newJpaJPanel = new JPanel();
|
JPanel jp1 = new JPanel();
|
jp1.setLayout(new GridBagLayout());
|
jp1.setBorder(BorderFactory.createTitledBorder(""));
|
|
GridBagConstraints g = new GridBagConstraints();
|
g.anchor = GridBagConstraints.WEST;
|
g.insets = new Insets(10, 5, 0, 5);
|
g.gridx = 0;
|
g.gridy = 0;
|
JLabel jl4 = new JLabel("起始状态");
|
jl4.setBounds(10, 5, 0, 5);
|
jp1.add(jl4, g);
|
// jp1.add(getStartStateJcombox(),g);
|
|
GridBagConstraints g1 = new GridBagConstraints();
|
g1.insets = new Insets(10, 5, 0, 5);
|
g1.gridx = 1;
|
g1.gridy = 0;
|
g1.gridwidth = GridBagConstraints.REMAINDER;
|
jp1.add(textFieldFromStatus, g1);
|
|
g.insets = new Insets(10, 5, 0, 5);
|
g.gridx = 0;
|
g.gridy = 1;
|
JLabel jl5 = new JLabel("目标状态");
|
jp1.add(jl5, g);
|
g.gridx = 1;
|
g.gridy = 1;
|
jp1.add(textFieldToStatus, g);
|
|
g.gridx = 0;
|
g.gridy = 2;
|
JLabel jl6 = new JLabel("名称");
|
jp1.add(jl6, g);
|
g.gridx = 1;
|
g.gridy = 2;
|
jp1.add(textFieldEdgeName, g);
|
|
g.gridx = 0;
|
g.gridy = 3;
|
JLabel jl7 = new JLabel("类型");
|
jp1.add(jl7, g);
|
g.gridx = 1;
|
g.gridy = 3;
|
jp1.add(textFieldEdgeType, g);
|
|
JPanel jPanel = new JPanel();
|
JPanel jpBtn = new JPanel();
|
jPanel.setLayout(new BorderLayout());
|
|
jpBtn.add(addTansitionEventButton);
|
jpBtn.add(deleteTansitionEventButton);
|
jpBtn.add(saveTansitionEventButton);
|
|
jPanel.add(jpBtn, BorderLayout.NORTH);
|
|
eventTableModel = new LifeCycleTableModel(10);
|
tableEvent = new JTable(eventTableModel);
|
tableEvent.setRowHeight(25);
|
JComboBox com = new JComboBox(eventKeys);
|
TableColumnModel tcm = tableEvent.getColumnModel();
|
tcm.getColumn(0).setCellEditor(new DblclickCellEditor(com, tableEvent));
|
JScrollPane s_pan = new JScrollPane(tableEvent);
|
jPanel.add(s_pan, BorderLayout.CENTER);
|
newJpaJPanel.setLayout(new BorderLayout());
|
newJpaJPanel.add(jp1, BorderLayout.NORTH);
|
newJpaJPanel.add(jPanel, BorderLayout.CENTER);
|
|
return newJpaJPanel;
|
}
|
|
|
private void setModifyState(boolean modify) {
|
// 什么周期模板功能按钮
|
addButton.setEnabled(!modify);
|
modifyButton.setEnabled(!modify);
|
deleteButton.setEnabled(!modify);
|
saveButton.setEnabled(modify);
|
cancelButton.setEnabled(modify);
|
|
textFieldName.setEditable(modify);
|
textFieldTag.setEditable(modify);
|
textFieldDescription.setEditable(modify);
|
lc_startState.setEnabled(modify);
|
|
textFieldFromStatus.setEditable(false);
|
textFieldToStatus.setEditable(false);
|
textFieldEdgeName.setEditable(false);
|
textFieldEdgeType.setEditable(false);
|
|
// 设置图形区可编辑状态
|
lcGraph.setMoveable(modify);
|
lcGraph.setEdgeLabelsMovable(modify);
|
lcGraph.setEditable(modify);
|
lcGraph.setCloneable(modify);
|
lcGraph.setInvokesStopCellEditing(modify);
|
lcGraph.setJumpToDefaultPort(modify);
|
|
if (!modify)
|
setEventModify(false);
|
}
|
|
private void setEventModify(boolean modify) {
|
// 状态迁移事件编辑功能按钮
|
deleteTansitionEventButton.setEnabled(modify);
|
addTansitionEventButton.setEnabled(modify);
|
saveTansitionEventButton.setEnabled(modify);
|
|
tableEvent.setEnabled(modify);
|
}
|
|
private void clearLifeCycleInfo() {
|
textFieldName.setText("");
|
textFieldTag.setText("");
|
textFieldDescription.setText("");
|
|
lcGraph.getModel().remove(lcGraph.getRoots());
|
lcGraph.updateUI();
|
lcGraph.refresh();
|
lcGraph.setOo(null);
|
lcGraph.setCloneable(true);
|
lcGraph.setInvokesStopCellEditing(true);
|
lcGraph.setJumpToDefaultPort(true);
|
|
clearEventInfo();
|
|
clear();
|
}
|
|
private void clearEventInfo() {
|
textFieldFromStatus.setText("");
|
textFieldToStatus.setText("");
|
textFieldEdgeName.setText("");
|
textFieldEdgeType.setText("");
|
|
if (eventTableModel.getRowCount() > 0) {
|
eventTableModel.removeRows(0, eventTableModel.getRowCount());
|
tableEvent.updateUI();
|
}
|
}
|
|
/*
|
* 初始化生命周期模板信息到界面
|
*/
|
private void initLifeCycleInfo(LifeCycle lc) {
|
try {
|
textFieldName.setText(lc.name);
|
textFieldTag.setText(lc.tag);
|
textFieldDescription.setText(lc.description);
|
|
lcGraph.refreshGraph(lc);
|
|
initTransitionEventMap(lc);
|
} catch (DocumentException e) {
|
e.printStackTrace();
|
}
|
}
|
|
// 返回按钮的监听器,执行返回操作后界面将重置
|
public void addListenercancel() {
|
cancelButton.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
int n = JOptionPane.showConfirmDialog(saveButton, "您确认要执行返回操作?");
|
if (n == JOptionPane.YES_OPTION) {
|
|
clearLifeCycleInfo();
|
|
LifeCycle selLC = lifeCycleTreeSelection();
|
|
// textFieldName.setText("");
|
// textFieldTag.setText("");
|
// textFieldFromStatus.setText("");
|
// textFieldToStatus.setText("");
|
// textFieldEdgeName.setText("");
|
// textFieldEdgeType.setText("");
|
// textFieldDescription.setText("");
|
// lc_startState.setText("");
|
// if (eventTableModel.getRowCount() > 0) {
|
// eventTableModel.removeRows(0, eventTableModel.getRowCount());
|
// tableEvent.updateUI();
|
// }
|
// eastJPanel2.removeAll();
|
// eastJPanel2.updateUI();
|
// lcGraph.getModel().remove(lcGraph.getRoots());
|
// lcGraph.updateUI();
|
// lcGraph.refresh();
|
// lcGraph.setOo(null);
|
// lcGraph.setCloneable(true);
|
// lcGraph.setInvokesStopCellEditing(true);
|
// lcGraph.setJumpToDefaultPort(true);
|
|
setModifyState(false);
|
|
initLifeCycleInfo(selLC);
|
// //door = false;
|
// addButton.setEnabled(true);
|
// modifyButton.setEnabled(true);
|
// deleteButton.setEnabled(true);
|
// checkButton.setEnabled(true);
|
// saveButton.setEnabled(false);
|
// cancelButton.setEnabled(false);
|
// // selectedLcStartState.setEnabled(false);
|
// textFieldName.setEditable(false);
|
// textFieldTag.setEditable(false);
|
// textFieldDescription.setEditable(false);
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
// lc_startState.setEnabled(false);
|
|
editingFlag = 0;
|
|
} else if (n == JOptionPane.NO_OPTION) {
|
return;
|
}
|
}
|
|
});
|
}
|
|
// 修改按钮的监听器,主要任务是提示操作人员是否执行修改操作并且将修改后的数据存入XML文件和重置界面
|
public void addListenermodify() {
|
modifyButton.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
//door = false;
|
editingFlag = 2;
|
LifeCycle selectedLC = lifeCycleTreeSelection();
|
if (selectedLC != null) {
|
// String nodeName = selectedLC.name;
|
|
ArrayList<InterLCy> interLcyList = InterLCyManager.getInstance().getInterLCyList();
|
if (interLcyList == null || interLcyList.size() == 0) {
|
textFieldName.setEditable(true);
|
}
|
// textFieldName.setEditable(false); // add by caill 2016.1.12无论生命周期有没有被引用,其名称都不可以被更改。
|
// if (eventTableModel.getRowCount() > 0) {
|
// eventTableModel.removeRows(0, eventTableModel.getRowCount());
|
// tableEvent.updateUI();
|
// }
|
//
|
setModifyState(true);
|
|
// textFieldTag.setEditable(true);
|
// textFieldDescription.setEditable(true);
|
// lc_startState.setEnabled(true);
|
// selectedLcStartState.setEnabled(true);
|
// textFieldName.setEnabled(true);
|
// textFieldTag.setEnabled(true);
|
// textFieldDescription.setEnabled(true);
|
// startStateComboBox.setEnabled(true);
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
|
// lcGraph.setMoveable(true);
|
// lcGraph.setEdgeLabelsMovable(true);
|
// lcGraph.setEditable(true);
|
// lcGraph.setCloneable(true);
|
// lcGraph.setInvokesStopCellEditing(true);
|
// lcGraph.setJumpToDefaultPort(true);
|
|
// if (eventTableModel.getRowCount() > 0) {
|
// eventTableModel.removeRows(0, eventTableModel.getRowCount());
|
// tableEvent.updateUI();
|
// }
|
|
// addButton.setEnabled(false);
|
// modifyButton.setEnabled(false);
|
// deleteButton.setEnabled(false);
|
// checkButton.setEnabled(false);
|
// saveButton.setEnabled(true);
|
// cancelButton.setEnabled(true);
|
// deleteTansitionEventButton.setEnabled(true);
|
// addTansitionEventButton.setEnabled(true);
|
// saveTansitionEventButton.setEnabled(true);
|
initlc_startState();
|
lc_startState.setSelectedItem(selectedLC.startState);
|
} else {
|
JOptionPane.showMessageDialog(null, "请先选中要修改的项");
|
}
|
|
}
|
|
});
|
}
|
|
// 为delete按钮添加监听器
|
public void addListenerdelete() {
|
deleteButton.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
LifeCycle selectedLC = lifeCycleTreeSelection();
|
Object[] options = { "Yes", "No" };
|
int n = JOptionPane.showOptionDialog(getInstance(), "确认是否删除生命周期规则\"" + selectedLC.name + "\"",
|
"生命周期规则删除", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
|
|
if (n != JOptionPane.YES_OPTION) {
|
return;
|
}
|
try {
|
if (selectedLC != null) {
|
//door = false;
|
String nodeName = selectedLC.name;
|
try {
|
ArrayList<InterLCy> interLcyList = InterLCyManager.getInstance().getInterLCyList();
|
for (InterLCy lcy : interLcyList) {
|
ArrayList<String> usedNameList = lcy.getUsedNameList(nodeName);
|
if (usedNameList != null && usedNameList.size() > 0) {
|
JOptionPane.showMessageDialog(null, "该生命周期已被使用不允许删除");
|
return;
|
}
|
}
|
|
LifeCycleStart.getService().deleteLifeCycle(selectedLC);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
// lcGraph.getModel().remove(lcGraph.getRoots());
|
// lcGraph.updateUI();
|
// lcGraph.refresh();
|
// lcGraph.setOo(null);
|
//
|
// lcGraph.setMoveable(true);
|
// lcGraph.setEdgeLabelsMovable(true);
|
// lcGraph.setEditable(true);
|
// lcGraph.setCloneable(true);
|
// lcGraph.setInvokesStopCellEditing(true);
|
// lcGraph.setJumpToDefaultPort(true);
|
//
|
// if (eventTableModel.getRowCount() > 0) {
|
// eventTableModel.removeRows(0, eventTableModel.getRowCount());
|
// tableEvent.updateUI();
|
// }
|
|
clearLifeCycleInfo();
|
|
setModifyState(false);
|
|
// textFieldName.setText("");
|
// textFieldTag.setText("");
|
// textFieldFromStatus.setText("");
|
// textFieldToStatus.setText("");
|
// textFieldEdgeName.setText("");
|
// textFieldEdgeType.setText("");
|
// textFieldDescription.setText("");
|
|
//
|
// textFieldName.setEditable(false);
|
// textFieldTag.setEditable(false);
|
// textFieldDescription.setEditable(false);
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
// lc_startState.setEditable(false);
|
// // selectedLcStartState.setEnabled(false);
|
// deleteTansitionEventButton.setEnabled(false);
|
// addTansitionEventButton.setEnabled(false);
|
// // System.out.println("627");
|
// saveTansitionEventButton.setEnabled(false);
|
//
|
// addButton.setEnabled(true);
|
// modifyButton.setEnabled(true);
|
// deleteButton.setEnabled(true);
|
// checkButton.setEnabled(true);
|
// saveButton.setEnabled(false);
|
// cancelButton.setEnabled(false);
|
|
// 删除树节点
|
TreePath treePath = treeLifeCycle.getSelectionPath();
|
treeLifeCycle.removeSelectionPath(treePath);
|
|
// createLifeCycleTree();
|
// scrollPane.setViewportView(treeLifeCycle);
|
// scrollPane.updateUI();
|
|
} else {
|
JOptionPane.showMessageDialog(null, "请先选中要删除的项");
|
}
|
} catch (HeadlessException e) {
|
e.printStackTrace();
|
}
|
}
|
|
});
|
}
|
|
public void clear() {
|
|
if (transationEvents != null) {
|
// for (int i = 0; i < transationEvents.size(); i++) {
|
// TransitionVOEvent tVoEvent = transationEvents.get(i);
|
// tVoEvent = null;
|
// }
|
transationEvents.clear();
|
transationEvents = null;
|
}
|
|
if (transitionVOs != null) {
|
// for (int i = 0; i < transitionVOs.size(); i++) {
|
// TransitionVO tVo_Events = transitionVOs.get(i);
|
// tVo_Events = null;
|
// }
|
transitionVOs.clear();
|
transitionVOs = null;
|
}
|
|
// if (transitionVOs != null) {
|
//// for (int i = 0; i < transitionVOs.size(); i++) {
|
//// TransitionVO tVo = transitionVOs.get(i);
|
//// tVo = null;
|
//// }
|
// transitionVOs.clear();
|
// transitionVOs = null;
|
// }
|
|
mapTransitionEvents.clear();
|
// if (transitionevents_maps != null) {
|
// for (int i = 0; i < transitionevents_maps.size(); i++) {
|
// Map<String, List<TransitionVOEvent>> map = transitionevents_maps.get(i);
|
// map = null;
|
// }
|
// transitionevents_maps = null;
|
// }
|
|
}
|
|
public boolean used(String name) {
|
try {
|
LifeCycle lc = LifeCycleStart.getService().getLifeCycle(name);
|
if (lc != null && !lc.name.equals("")) {
|
return true;
|
}
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
|
return false;
|
}
|
|
public boolean isMatchesEnglish(String name) {
|
if (!name.matches("[a-z A-Z]*")) {
|
// JOptionPane.showMessageDialog(this, "生命周期名称只能为英文字母", "注意",
|
// JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
return true;
|
}
|
|
public boolean check() {
|
String name = textFieldName.getText();
|
if (name.equals("")) {
|
JOptionPane.showMessageDialog(this, "请输入生命周期名称", "注意", JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
|
if (!isMatchesEnglish(name)) {
|
JOptionPane.showMessageDialog(this, "生命周期名称只能为英文字母", "注意", JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
|
if (used(name)) {
|
JOptionPane.showMessageDialog(this, "该生命周期名称已经存在", "请更换", JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
|
if (lc_startState.getSelectedItem() == null || lc_startState.getSelectedItem().toString() == "") {
|
JOptionPane.showMessageDialog(null, "请选择开始状态");
|
return false;
|
}
|
return true;
|
|
}
|
|
// 为save按钮添加监听器
|
public void saveListeneradd() {
|
saveButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
Object[] o = lcGraph.getOo();
|
List<Bound> bounds = null;
|
List<TransitionVO> routes = null;
|
if (editingFlag != 2) {
|
try {
|
if (!check()) {
|
return;
|
}
|
LifeCycle lifeCycle = new LifeCycle();
|
lifeCycle.name = textFieldName.getText();
|
lifeCycle.tag = textFieldTag.getText();
|
lifeCycle.description = textFieldDescription.getText();
|
lifeCycle.startState = lc_startState.getSelectedItem().toString();
|
bounds = new ArrayList<Bound>();
|
routes = new ArrayList<TransitionVO>();
|
// int j = 0;
|
// int k = 0;
|
for (int i = 0; i < o.length; ++i) {
|
if (o[i] instanceof DefaultEdge) {
|
DefaultEdge edge = (DefaultEdge) o[i];
|
DefaultPort s = (DefaultPort) edge.getSource();
|
DefaultGraphCell ps = (DefaultGraphCell) s.getParent();
|
DefaultPort t = (DefaultPort) edge.getTarget();
|
DefaultGraphCell pt = (DefaultGraphCell) t.getParent();
|
|
String startName = ps.toString();
|
String endName = pt.toString();
|
String routeName = edge.getUserObject().toString();
|
|
TransitionVO route = new TransitionVO();
|
route.source = startName;
|
route.connect = routeName;
|
route.destination = endName;
|
|
List<TransitionVOEvent> transitionVOEvents = null;
|
// if (transitionevents_maps != null && transitionevents_maps.size() > 0) {
|
// for (int m = 0; m < transitionevents_maps.size(); m++) {
|
// Map<String, List<TransitionVOEvent>> map = transitionevents_maps.get(m);
|
// String key = getKey(map);
|
// if (key == null) {
|
// continue;
|
// }
|
// if (key.equals(routeName)) {
|
// transitionVOEvents = map.get(key);
|
// break;
|
// }
|
// }
|
// }
|
|
if (mapTransitionEvents.containsKey(routeName)) {
|
transitionVOEvents = mapTransitionEvents.get(routeName);
|
}
|
|
if (transitionVOEvents != null && transitionVOEvents.size() > 0) {
|
TransitionVOEvent[] tVoEvents = (TransitionVOEvent[]) transitionVOEvents
|
.toArray(new TransitionVOEvent[0]);
|
route.transitionVOEvents = tVoEvents;
|
} else {
|
route.transitionVOEvents = new TransitionVOEvent[0];
|
}
|
|
routes.add(route);
|
|
} else if (o[i] instanceof DefaultGraphCell && !(o[i] instanceof DefaultPort)) {
|
DefaultGraphCell ci = (DefaultGraphCell) o[i];
|
double dx = GraphConstants.getBounds(ci.getAttributes()).getX();
|
|
double dy = GraphConstants.getBounds(ci.getAttributes()).getY();
|
|
double dw = GraphConstants.getBounds(ci.getAttributes()).getWidth();
|
|
double dh = GraphConstants.getBounds(ci.getAttributes()).getHeight();
|
|
String icon = "";
|
|
Icon icn = GraphConstants.getIcon(ci.getAttributes());
|
if (icn != null) {
|
icn.toString().replace("\\", "/");
|
icon = icon.substring(icon.lastIndexOf("/") + 1);
|
}
|
|
Bound b = new Bound();
|
b.name = ci.toString();
|
b.cellx = dx + "";
|
b.celly = dy + "";
|
b.cellw = dw + "";
|
b.cellh = dh + "";
|
b.cellicon = icon;
|
bounds.add(b);
|
} else {
|
System.out.println("此数据类型暂不支持");
|
}
|
}
|
|
lifeCycle.bounds = ((Bound[]) bounds.toArray(new Bound[0]));
|
lifeCycle.routes = ((TransitionVO[]) routes.toArray(new TransitionVO[0]));
|
String userName = InvocationUtility.getInvocation().userName;
|
lifeCycle.creator = userName;
|
lifeCycle.modifier = userName;
|
LifeCycleStart.getService().addLifeCycle(lifeCycle);
|
// 保存成功后清内存
|
// clear();
|
// lcGraph.getModel().remove(lcGraph.getRoots());
|
// lcGraph.updateUI();
|
// lcGraph.refresh();
|
// lcGraph.setOo(null);
|
//
|
// lcGraph.setCloneable(true);
|
// lcGraph.setInvokesStopCellEditing(true);
|
// lcGraph.setJumpToDefaultPort(true);
|
|
//door = false;
|
// clearLifeCycleInfo();
|
// textFieldName.setText("");
|
// textFieldTag.setText("");
|
// textFieldFromStatus.setText("");
|
// textFieldToStatus.setText("");
|
// textFieldEdgeName.setText("");
|
// textFieldEdgeType.setText("");
|
// textFieldDescription.setText("");
|
// lc_startState.setText("");
|
|
setModifyState(false);
|
|
// textFieldName.setEditable(false);
|
// textFieldTag.setEditable(false);
|
// textFieldDescription.setEditable(false);
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
// // selectedLcStartState.setEnabled(false);
|
// addButton.setEnabled(true);
|
// modifyButton.setEnabled(true);
|
// deleteButton.setEnabled(true);
|
// checkButton.setEnabled(true);
|
// saveButton.setEnabled(false);
|
// cancelButton.setEnabled(false);
|
// // selectedLcStartState.setEnabled(false);
|
// deleteTansitionEventButton.setEnabled(false);
|
// addTansitionEventButton.setEnabled(false);
|
// // System.out.println("934");
|
// saveTansitionEventButton.setEnabled(false);
|
|
/**
|
* createTree(); westJPanel.add(scrollPane,BorderLayout.CENTER);
|
* westJPanel.updateUI();
|
*/
|
|
DefaultMutableTreeNode nodeRoot = (DefaultMutableTreeNode)treeLifeCycle.getModel().getRoot();
|
if (nodeRoot != null) {
|
nodeRoot.add(new DefaultMutableTreeNode(new LifeCycleWrapper(lifeCycle)));
|
}
|
|
treeLifeCycle.updateUI();
|
// createLifeCycleTree();
|
// scrollPane.updateUI();
|
// // add by caill start 2016.3.31 将刷新后的生命周期panel放入splitPane的上部(创建)
|
// splitPane.setTopComponent(scrollPane);
|
// splitPane.updateUI();
|
// // add by caill end
|
|
editingFlag = 0;
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
} else {
|
try {
|
LifeCycle selectedLC = lifeCycleTreeSelection();
|
if (selectedLC == null) {
|
JOptionPane.showMessageDialog(getThis(), "请选择生命周期", "请选择生命周期", JOptionPane.WARNING_MESSAGE);
|
return;
|
}
|
selectedLC.tag = textFieldTag.getText();
|
selectedLC.description = textFieldDescription.getText();
|
selectedLC.startState = lc_startState.getSelectedItem().toString();
|
bounds = new ArrayList<Bound>();
|
routes = new ArrayList<TransitionVO>();
|
|
for (int i = 0; i < o.length; ++i) {
|
if (o[i] instanceof DefaultEdge) {
|
DefaultEdge w = (DefaultEdge) o[i];
|
DefaultPort s = (DefaultPort) w.getSource();
|
DefaultGraphCell ps = (DefaultGraphCell) s.getParent();
|
DefaultPort t = (DefaultPort) w.getTarget();
|
DefaultGraphCell pt = (DefaultGraphCell) t.getParent();
|
String startName = ps.toString();
|
String endName = pt.toString();
|
String routeName = w.getUserObject().toString();
|
TransitionVO route = new TransitionVO();
|
|
route.source = startName;
|
route.connect = routeName;
|
route.destination = endName;
|
|
List<TransitionVOEvent> tVOEvents = null;
|
// if (transitionevents_maps != null && transitionevents_maps.size() > 0) {
|
// for (int m = 0; m < transitionevents_maps.size(); m++) {
|
// Map<String, List<TransitionVOEvent>> map = transitionevents_maps.get(m);
|
// String key = getKey(map);
|
// if (key == null) {
|
// continue;
|
// }
|
// if (key.equals(routeName)) {
|
// transitionVOEvents = map.get(key);
|
// break;
|
// }
|
// }
|
if (mapTransitionEvents.containsKey(routeName)) {
|
tVOEvents = mapTransitionEvents.get(routeName);
|
}
|
|
if (tVOEvents != null && tVOEvents.size() > 0) {
|
TransitionVOEvent[] tVoEvents = tVOEvents.toArray(new TransitionVOEvent[0]);
|
route.transitionVOEvents = tVoEvents;
|
} else {
|
route.transitionVOEvents = new TransitionVOEvent[0];
|
}
|
|
routes.add(route);
|
} else if (o[i] instanceof DefaultGraphCell && !(o[i] instanceof DefaultPort)) {
|
DefaultGraphCell ci = (DefaultGraphCell) o[i];
|
double dx = GraphConstants.getBounds(ci.getAttributes()).getX();
|
|
double dy = GraphConstants.getBounds(ci.getAttributes()).getY();
|
|
double dw = GraphConstants.getBounds(ci.getAttributes()).getWidth();
|
|
double dh = GraphConstants.getBounds(ci.getAttributes()).getHeight();
|
|
String icon = "";
|
|
Icon icn = GraphConstants.getIcon(ci.getAttributes());
|
if (icn != null) {
|
icn.toString().replace("\\", "/");
|
icon = icon.substring(icon.lastIndexOf("/") + 1);
|
}
|
|
Bound b = new Bound();
|
b.name = ci.toString();
|
b.cellx = dx + "";
|
b.celly = dy + "";
|
b.cellw = dw + "";
|
b.cellh = dh + "";
|
b.cellicon = icon;
|
bounds.add(b);
|
} else {
|
System.out.println("此数据类型暂不支持");
|
}
|
}
|
|
selectedLC.bounds = ((Bound[]) bounds.toArray(new Bound[0]));
|
selectedLC.routes = ((TransitionVO[]) routes.toArray(new TransitionVO[0]));
|
selectedLC.modifier = InvocationUtility.getInvocation().userName;
|
LifeCycleStart.getService().modifyLifeCycle(selectedLC);
|
|
// lcGraph.getModel().remove(lcGraph.getRoots());
|
// lcGraph.updateUI();
|
// lcGraph.refresh();
|
// lcGraph.setOo(null);
|
|
setModifyState(false);
|
|
// addButton.setEnabled(true);
|
// modifyButton.setEnabled(true);
|
// deleteButton.setEnabled(true);
|
// checkButton.setEnabled(true);
|
// saveButton.setEnabled(false);
|
// cancelButton.setEnabled(false);
|
// // selectedLcStartState.setEnabled(false);
|
// deleteTansitionEventButton.setEnabled(false);
|
// addTansitionEventButton.setEnabled(false);
|
// // System.out.println("1109");
|
// saveTansitionEventButton.setEnabled(false);
|
|
//door = false;
|
// clearLifeCycleInfo();
|
// textFieldName.setText("");
|
// textFieldTag.setText("");
|
// textFieldFromStatus.setText("");
|
// textFieldToStatus.setText("");
|
// textFieldEdgeName.setText("");
|
// textFieldEdgeType.setText("");
|
// textFieldDescription.setText("");
|
// textFieldName.setEditable(false);
|
// textFieldTag.setEditable(false);
|
// textFieldDescription.setEditable(false);
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
// lc_startState.setEditable(false);
|
|
/**
|
* createTree(); westJPanel.add(scrollPane,BorderLayout.CENTER);
|
* westJPanel.updateUI();
|
*/
|
treeLifeCycle.updateUI();
|
|
// createLifeCycleTree();
|
// scrollPane.setViewportView(treeLifeCycle);
|
// // add by caill start 2016.3.31 将刷新后的生命周期panel放入splitPane的上部(修改)
|
// scrollPane.updateUI();
|
// splitPane.setTopComponent(scrollPane);
|
// splitPane.updateUI();
|
// // add by caill end
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
});
|
}
|
|
/***
|
*
|
* @param map
|
* @return
|
*/
|
public String getKey(Map<String, List<TransitionVOEvent>> map) {
|
String key = null;
|
Iterator iterator = map.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry entry = (Map.Entry) iterator.next();
|
key = (String) entry.getKey();
|
}
|
return key;
|
}
|
|
// 为add按钮添加监听器
|
public void addListeneradd() {
|
addButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
//door = false;
|
editingFlag = 1;
|
clearLifeCycleInfo();
|
// textFieldName.setText("");
|
// textFieldTag.setText("");
|
// textFieldDescription.setText("");
|
// textFieldFromStatus.setText("");
|
// textFieldToStatus.setText("");
|
// textFieldEdgeName.setText("");
|
// textFieldEdgeType.setText("");
|
// textFieldName.setEditable(true);
|
// textFieldTag.setEditable(true);
|
// textFieldDescription.setEditable(true);
|
// lc_startState.setEditable(false);
|
//
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
|
// eastJPanel1.removeAll();
|
// eastJPanel1.updateUI();
|
// eastJPanel1.add(createBaseInfoPanel(), BorderLayout.CENTER);
|
// removeALLData();
|
//
|
// lcGraph.getModel().remove(lcGraph.getRoots());
|
// lcGraph.updateUI();
|
// lcGraph.refresh();
|
// lcGraph.setOo(null);
|
//
|
// lcGraph.setMoveable(true);
|
// lcGraph.setEdgeLabelsMovable(true);
|
// lcGraph.setEditable(true);
|
// lcGraph.setCloneable(true);
|
// lcGraph.setInvokesStopCellEditing(true);
|
// lcGraph.setJumpToDefaultPort(true);
|
//
|
// if (eventTableModel.getRowCount() > 0) {
|
// eventTableModel.removeRows(0, eventTableModel.getRowCount());
|
// tableEvent.updateUI();
|
// }
|
|
setModifyState(true);
|
// addButton.setEnabled(false);
|
// modifyButton.setEnabled(false);
|
// deleteButton.setEnabled(false);
|
// checkButton.setEnabled(false);
|
// saveButton.setEnabled(true);
|
// cancelButton.setEnabled(true);
|
// deleteTansitionEventButton.setEnabled(true);
|
// addTansitionEventButton.setEnabled(true);
|
// saveTansitionEventButton.setEnabled(true);
|
// selectedLcStartState.setEnabled(true);
|
|
initlc_startState();
|
}
|
});
|
}
|
|
// 点击添加页面的时候执行的方法,用于显示要添加属性的页面
|
public JPanel createBaseInfoPanel() {
|
JPanel panelBase = new JPanel();
|
panelBase.setBorder(BorderFactory.createEtchedBorder());
|
panelBase.setLayout(new GridBagLayout());
|
GridBagConstraints g = new GridBagConstraints();
|
g.anchor = GridBagConstraints.WEST;
|
g.insets = new Insets(10, 5, 0, 5);
|
g.gridx = 0;
|
g.gridy = 0;
|
JLabel labelName = new JLabel("名称");
|
panelBase.add(labelName, g);
|
|
GridBagConstraints g1 = new GridBagConstraints();
|
g1.insets = new Insets(10, 5, 0, 5);
|
g.gridx = 1;
|
g.gridy = 0;
|
g1.gridwidth = GridBagConstraints.REMAINDER;
|
panelBase.add(textFieldName, g);
|
// 限定文本框的有效输入长度为50
|
textFieldName.setDocument(new PlainDocument() {
|
public void insertString(int offs, String str, javax.swing.text.AttributeSet a)
|
throws BadLocationException {
|
String text = textFieldName.getText();
|
if (text.length() + str.length() > 50) {
|
Toolkit.getDefaultToolkit().beep();
|
JOptionPane.showMessageDialog(null, "名称不能超过50个字符");
|
return;
|
}
|
super.insertString(offs, str, a);
|
}
|
});
|
|
g.gridx = 0;
|
g.gridy = 1;
|
JLabel jl2 = new JLabel("标签");
|
panelBase.add(jl2, g);
|
g.gridx = 1;
|
g.gridy = 1;
|
panelBase.add(textFieldTag, g);
|
|
g.gridx = 0;
|
g.gridy = 2;
|
JLabel startStateLabel = new JLabel("起始状态");
|
panelBase.add(startStateLabel, g);
|
g.gridx = 1;
|
g.gridy = 2;
|
lc_startState.setPreferredSize(textFieldTag.getPreferredSize());
|
panelBase.add(lc_startState, g);
|
// g.gridx = 2;
|
// g.gridy = 2;
|
// selectedLcStartState = new JButton("选择");
|
// panelBase.add(selectedLcStartState, g);
|
|
// selectedLcStartState.addActionListener(new ActionListener() {
|
// public void actionPerformed(ActionEvent e) {
|
// ImageSelectDialog dialog = null;
|
// dialog = ImageSelectDialog.getInstance();
|
// dialog.setVisible(true);
|
// imageURL = dialog.getImageName();
|
// List<Bound> bounds = dialog.getbounds();
|
// for (Bound bound : bounds) {
|
// if (bound != null) {
|
// String str1 = bound.cellicon.trim();
|
// String str2 = imageURL.trim();
|
// if (str1.equals(str2)) {
|
// imageName = bound.name;
|
// imageURL = bound.cellicon;
|
// //add by guo选择按钮的图片进行修改
|
// ImageIcon icon= new BundleImage().createImageIcon(imageURL);
|
// selectedLcStartState.setIcon(icon);
|
// }
|
// }
|
// }
|
// updateImageUILocal();
|
// }
|
// });
|
g.gridx = 0;
|
g.gridy = 3;
|
JLabel jl3 = new JLabel("描述");
|
panelBase.add(jl3, g);
|
g.gridx = 1;
|
g.gridy = 3;
|
|
textFieldDescription.setDocument(new PlainDocument() {
|
public void insertString(int offs, String str, javax.swing.text.AttributeSet a)
|
throws BadLocationException {
|
String text = textFieldDescription.getText();
|
if (text.length() + str.length() > 255) {
|
Toolkit.getDefaultToolkit().beep();
|
JOptionPane.showMessageDialog(null, "名称不能超过255个字符");
|
return;
|
}
|
super.insertString(offs, str, a);
|
}
|
});
|
panelBase.add(new JScrollPane(textFieldDescription), g);
|
return panelBase;
|
}
|
|
// public void updateImageUILocal() {
|
// lc_startState.setSelectedItem(imageName);
|
// }
|
|
// 树节点被选中时调用的方法,用于解析XML文件
|
public LifeCycle lifeCycleTreeSelection() {
|
try {
|
// this.mapTransitionEvents.clear();
|
// deleteTansitionEventButton.setEnabled(false);
|
// addTansitionEventButton.setEnabled(false);
|
// // System.out.println("1557");
|
// saveTansitionEventButton.setEnabled(false);
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeLifeCycle.getLastSelectedPathComponent();
|
if (node != null) {
|
Object userObject = node.getUserObject();
|
if (userObject instanceof LifeCycleWrapper) {
|
return ((LifeCycleWrapper) userObject).getLC();
|
}
|
}
|
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
return null;
|
|
}
|
|
// 新建一棵树用于显示所有的状态名称
|
public void createLifeCycleTree() {
|
// Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("生命周期模板列表");
|
try {
|
LifeCycle[] lcs = LifeCycleStart.getService().getLifeCycles();
|
for (LifeCycle lc : lcs) {
|
node1.add(new DefaultMutableTreeNode(new LifeCycleWrapper(lc)));
|
}
|
} catch (VCIError e1) {
|
// TODO Auto-generated catch block
|
e1.printStackTrace();
|
}
|
treeLifeCycle = new JTree(node1);
|
treeLifeCycle.setCellRenderer(new LifeCycleTreeCellRenderer());
|
//scrollPane.setViewportView(treeLifeCycle);
|
|
treeLifeCycle.addMouseListener(new MouseAdapter() {
|
public void mouseClicked(MouseEvent mouseevent) {
|
LifeCycle lc = lifeCycleTreeSelection();
|
clearLifeCycleInfo();
|
// removeALLData();
|
|
editingFlag = 0;
|
setModifyState(false);
|
|
// try {
|
// eastJPanel1.removeAll();
|
// eastJPanel1.updateUI();
|
// eastJPanel1.add(createBaseInfoPanel(), BorderLayout.CENTER);
|
// eastJPanel2.add(lcGraph.eastJPanelUI());
|
|
// textFieldName.setEditable(false);
|
// textFieldTag.setEditable(false);
|
// textFieldDescription.setEditable(false);
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
// lc_startState.setEnabled(false);
|
|
if (lc != null) {
|
initLifeCycleInfo(lc);
|
// textFieldName.setText(lc.name);
|
// textFieldTag.setText(lc.tag);
|
// textFieldDescription.setText(lc.description);
|
//
|
// lcGraph.refreshGraph(lc);
|
//
|
// initTransitionEventMap(lc);
|
}
|
// addButton.setEnabled(true);
|
// modifyButton.setEnabled(true);
|
// deleteButton.setEnabled(true);
|
// checkButton.setEnabled(true);
|
// saveButton.setEnabled(false);
|
// cancelButton.setEnabled(false);
|
// deleteTansitionEventButton.setEnabled(false);
|
// addTansitionEventButton.setEnabled(false);
|
// // System.out.println("1472");
|
// saveTansitionEventButton.setEnabled(false);
|
|
|
// } catch (DocumentException e) {
|
// e.printStackTrace();
|
// }
|
}
|
|
});
|
|
}
|
|
private void initTransitionEventMap(LifeCycle lc) {
|
// TODO Auto-generated method stub
|
mapTransitionEvents.clear();
|
|
for(TransitionVO tvo : lc.routes) {
|
//tvo.connect
|
if (tvo.transitionVOEvents != null && tvo.transitionVOEvents.length > 0) {
|
List<TransitionVOEvent> lstTVE = new ArrayList<TransitionVOEvent>();
|
for (TransitionVOEvent tvoE : tvo.transitionVOEvents) {
|
lstTVE.add(tvoE);
|
}
|
mapTransitionEvents.put(tvo.connect, lstTVE);
|
}
|
}
|
}
|
|
// 定义jgraph页面的相关属性
|
class LifeCycleGraph extends JGraph {
|
/**
|
*
|
*/
|
|
private static final long serialVersionUID = 1L;
|
private ArrayList<DefaultGraphCell> cells;
|
//private DefaultPort port00, port01;
|
private DefaultGraphCell cell1;
|
//private DefaultGraphCell cell2;
|
//private DefaultEdge edges;
|
private JGraph graph = this;
|
//private int q = 0;
|
private int edgeCount = 0;
|
// 设置一个静态的数组用于存放当前jgraph页面得到的组件
|
private Object[] oo;
|
|
public LifeCycleGraph() {
|
this.setModel(new DefaultGraphModel());
|
// GraphLayoutCache graphLayoutCache = new GraphLayoutCache(this.getModel(), new LifeCycelCellViewFactory());
|
// this.setGraphLayoutCache(graphLayoutCache);
|
initLifeCycleGraph();
|
}
|
|
private JGraph initLifeCycleGraph() {
|
this.getModel().remove(this.getRoots());
|
this.getModel().remove(this.getRoots());
|
|
this.updateUI();
|
{
|
this.setGridEnabled(true);
|
this.setGridVisible(true);
|
}
|
this.setDropEnabled(true);
|
|
graph.addMouseListener(new MyMouse());
|
graph.getModel().addGraphModelListener(new GraphModelListener() {
|
|
@Override
|
public void graphChanged(GraphModelEvent arg0) {
|
// TODO Auto-generated method stub
|
setOo(graph.getRoots());
|
lcGraph.getCells();
|
Object[] ll = arg0.getChange().getInserted();
|
if (arg0.getChange().getInserted() != null) {
|
if (ll.length == 1) {
|
DefaultGraphCell defau = (DefaultGraphCell) ll[0];
|
List<DefaultGraphCell> cells1 = cells;
|
k: for (int i = 0; i < cells1.size(); i++) {
|
if (defau.equals(cells1.get(i))) {
|
cells1.remove(i);
|
break k;
|
}
|
}
|
for (int k1 = 0; k1 < cells1.size(); k1++) {
|
DefaultGraphCell dfdf = cells1.get(k1);
|
if (defau.getUserObject().toString().equals(dfdf.getUserObject().toString())) {
|
JOptionPane.showMessageDialog(null, "不能选择重复的状态!");
|
Object[] objcet = new Object[1];
|
objcet[0] = defau;
|
graph.getModel().remove(objcet);
|
}
|
}
|
|
}
|
}
|
lcGraph.getCells();
|
}
|
});
|
graph.addMouseMotionListener(new MyMouseListener());
|
|
// 添加键盘事件,当点击键盘的delete键的时候删除指定的组件
|
graph.addKeyListener(new KeyAdapter() {
|
public void keyPressed(KeyEvent e1) {
|
|
if (e1.getKeyCode() == 127 && graph.getSelectionCell() instanceof DefaultEdge) {
|
graph.getModel().remove(graph.getSelectionCells());
|
} else if (e1.getKeyCode() == 127 && graph.getSelectionCell() instanceof DefaultGraphCell) {
|
|
if (graph.getSelectionCell() instanceof DefaultGraphCell) {
|
DefaultGraphCell dgc = (DefaultGraphCell) graph.getSelectionCell();
|
Object[] os = graph.getRoots();
|
List list = new ArrayList();
|
for (int i = 0; i < os.length; i++) {
|
if (!(os[i] instanceof DefaultPort)) {
|
if (os[i] instanceof DefaultEdge) {
|
list.add(os[i]);
|
}
|
}
|
}
|
for (int j1 = 0; j1 < list.size(); j1++) {
|
DefaultEdge dfe = (DefaultEdge) list.get(j1);
|
Object[] dd = new Object[1];
|
dd[0] = dfe;
|
if (dgc.getChildren().contains(dfe.getSource())) {
|
graph.getModel().remove(dd);
|
graph.refresh();
|
graph.updateUI();
|
} else if (dgc.getChildren().contains(dfe.getTarget())) {
|
graph.getModel().remove(dd);
|
graph.refresh();
|
graph.updateUI();
|
}
|
}
|
|
graph.getModel().remove(graph.getSelectionCells());
|
}
|
}
|
}
|
});
|
|
graph.refresh();
|
graph.setMoveBelowZero(false);
|
return graph;
|
}
|
|
public Object[] getOo() {
|
return oo;
|
}
|
|
public void setOo(Object[] oo) {
|
lcGraph.oo = oo;
|
}
|
|
public Map<String, DefaultGraphCell> getCells(LifeCycle lc, List<DefaultGraphCell> lstCell) {
|
try {
|
// cellsBounds = new DefaultGraphCell[lc.bounds.length];
|
double x, y, w, h;
|
String cellicon = null, name = null;
|
// Map<String, DefaultGraphCell> map = null;
|
// List<Map<String, DefaultGraphCell>> list = null;
|
Map<String, DefaultGraphCell> map = new HashMap<String, DefaultGraphCell>();
|
|
// list = new ArrayList<Map<String, DefaultGraphCell>>();
|
for (int i = 0; i < lc.bounds.length; i++) {
|
DefaultGraphCell cell = new DefaultGraphCell(lc.bounds[i].name);
|
x = Double.parseDouble(lc.bounds[i].cellx);
|
y = Double.parseDouble(lc.bounds[i].celly);
|
w = Double.parseDouble(lc.bounds[i].cellw);
|
h = Double.parseDouble(lc.bounds[i].cellh);
|
cellicon = lc.bounds[i].cellicon;
|
name = lc.bounds[i].name;
|
|
GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(x, y, w, h));
|
GraphConstants.setBorderColor(cell.getAttributes(), Color.black);
|
GraphConstants.setLineWidth(cell.getAttributes(), 2.0f);
|
GraphConstants.setOpaque(cell.getAttributes(), true);
|
GraphConstants.setEditable(cell.getAttributes(), false);
|
|
ImageIcon imageIcon = null;
|
if (!cellicon.startsWith("http://")) {
|
imageIcon = new BundleImage().createImageIcon(cellicon);
|
}
|
|
else {
|
URL url = null;
|
try {
|
url = new URL(cellicon);
|
} catch (MalformedURLException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
if (url == null) {
|
continue;
|
}
|
imageIcon = new ImageIcon(url);
|
}
|
|
// selectedLcStartState.setIcon(imageIcon);
|
|
GraphConstants.setIcon(cell.getAttributes(), imageIcon);
|
DefaultPort fp = new DefaultPort();
|
cell.add(fp);
|
map.put(name, cell);
|
lstCell.add(cell);
|
// list.add(map);
|
}
|
return map;
|
} catch (NumberFormatException e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
public String getKey(Map<String, DefaultGraphCell> map) {
|
String key = null;
|
Iterator iterator = map.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry entry = (Map.Entry) iterator.next();
|
key = (String) entry.getKey();
|
}
|
return key;
|
}
|
|
// public DefaultGraphCell[] arraycat(DefaultGraphCell[] dgc1, DefaultGraphCell[] dgc2) {
|
// try {
|
// int len1 = 0;
|
// int len2 = 0;
|
// if (dgc1 != null)
|
// len1 = dgc1.length;
|
// if (dgc2 != null)
|
// len2 = dgc2.length;
|
// if (len1 + len2 > 0)
|
// cellsLifecyles = new DefaultGraphCell[len1 + len2];
|
// if (len1 > 0)
|
// System.arraycopy(dgc1, 0, cellsLifecyles, 0, len1);
|
// if (len2 > 0)
|
// System.arraycopy(dgc2, 0, cellsLifecyles, len1, len2);
|
// return cellsLifecyles;
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// return null;
|
// }
|
|
// 点击左边树的时候的显示页面
|
public void refreshGraph(LifeCycle lc) throws DocumentException {
|
try {
|
this.graph.getModel().remove(getRoots());
|
//door = true;
|
|
List<DefaultGraphCell> lstCell = new ArrayList<DefaultGraphCell>();
|
// selectedLcStartState.setEnabled(false);
|
Map<String, DefaultGraphCell> mapCell = getCells(lc, lstCell);// cellsBounds);
|
DefaultGraphCell cell = null;
|
TransitionVO[] routes = lc.routes;
|
|
edgeCount = 0;
|
if (routes != null && routes.length > 0) {
|
// cellsRoutes = new DefaultGraphCell[routes.length];
|
for (int i = 0; i < routes.length; i++) {
|
DefaultEdge edge = new DefaultEdge();
|
edge.setUserObject(routes[i].connect);
|
String source = routes[i].source;
|
String destination = routes[i].destination;
|
|
if (mapCell.containsKey(source)) {
|
cell = mapCell.get(source);
|
edge.setSource(cell.getChildAt(0));
|
}
|
|
if (mapCell.containsKey(destination)) {
|
cell = mapCell.get(destination);
|
edge.setTarget(cell.getChildAt(0));
|
}
|
// for (Map<String, DefaultGraphCell> map : list) {
|
// if (source.equals(getKey(map))) {
|
// cell = map.get(source);
|
// edge.setSource(cell.getChildAt(0));
|
//
|
// }
|
// if (destination.equals(getKey(map))) {
|
// cell = map.get(destination);
|
// edge.setTarget(cell.getChildAt(0));
|
// }
|
//
|
// }
|
// cellsRoutes[i] = edge;
|
lstCell.add(edge);
|
edgeCount++;
|
|
int arrow = GraphConstants.ARROW_CLASSIC;
|
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
|
GraphConstants.setEndFill(edge.getAttributes(), true);
|
GraphConstants.setLineWidth(edge.getAttributes(), 2.0f);
|
GraphConstants.setDisconnectable(edge.getAttributes(), false);
|
|
}
|
|
}
|
// add by caill start 2016.3.28 当状态之间没有
|
// routes时,要把cellsRoutes置空,否则cellsRoutes会保留之前节点的值,影响后面的程序
|
// if (routes == null || routes.length == 0) {
|
// cellsRoutes = null;
|
// }
|
// add by caill end
|
// DefaultGraphCell[] cellsLifecyles = arraycat(cellsBounds, cellsRoutes);
|
|
// if (cellsLifecyles != null && cellsLifecyles.length > 0 && cellsBounds.length
|
// > 0) { // add by caill
|
// 2016.3.28将此处的&&
|
// cellsRoutes.length
|
// >
|
// 0判断条件去掉,因为单个节点时允许cellsRoutes为空
|
|
GraphLayoutCache glc = this.graph.getGraphLayoutCache();
|
for (DefaultGraphCell cellLifecyle : lstCell) {
|
glc.insert(cellLifecyle);
|
}
|
// }
|
// 清内存
|
// clearDefaultGraphCells(cellsBounds);
|
// clearDefaultGraphCells(cellsRoutes);
|
// clearDefaultGraphCells(cellsLifecyles);
|
|
setOo(this.graph.getRoots());
|
this.graph.setMoveable(false);
|
lcGraph.setEdgeLabelsMovable(false);
|
lcGraph.setEditable(false);
|
// eastJpanel.removeAll();
|
// eastJpanel.updateUI();
|
// eastJpanel.add(eastJPanel1, BorderLayout.NORTH);
|
// eastJpanel.add(lcGraph.eastJPanelUI(), BorderLayout.SOUTH);
|
lc_startState.setSelectedItem(lc.startState);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
public void clearDefaultGraphCells(DefaultGraphCell[] defaultGraphCells) {
|
if (defaultGraphCells != null) {
|
for (int i = 0; i < defaultGraphCells.length; i++) {
|
// DefaultGraphCell defaultGraphCell = defaultGraphCells[i];
|
defaultGraphCells[i] = null;
|
}
|
|
defaultGraphCells = null;
|
}
|
}
|
|
// 得到当前页面的所有cell,当页面有所改变的时候将这些cell更新进去
|
public void getCells() {
|
cells = new ArrayList<DefaultGraphCell>();
|
Object[] o2 = graph.getRoots();
|
for (int i = 0; i < o2.length; i++) {
|
if (!(o2[i] instanceof DefaultPort)) {
|
if ((o2[i] instanceof DefaultGraphCell) && !(o2[i] instanceof DefaultEdge)) {
|
DefaultGraphCell dgf1 = (DefaultGraphCell) o2[i];
|
cells.add(dgf1);
|
}
|
}
|
}
|
initlc_startState();
|
}
|
|
// private int kuan = 0;
|
|
// 自定义鼠标事件,当鼠标移动到cell上面的时候改变光标形状并且可以操作
|
class MyMouseListener implements MouseMotionListener {
|
int x1 = 0, y1 = 0;
|
|
@Override
|
public void mouseDragged(MouseEvent e) {
|
}
|
|
@Override
|
public void mouseMoved(MouseEvent e) {
|
|
flushed(); // add by caill 2016.3.31在中间区域移动鼠标时刷新左侧导航栏内的数据
|
graph.refresh();
|
x1 = e.getX();
|
y1 = e.getY();
|
if (cells != null) {
|
k: for (int i = 0; i < cells.size(); i++) {
|
if (cells.get(i) == null) {
|
break;
|
}
|
DefaultGraphCell cell = cells.get(i);
|
if (cell instanceof DefaultGraphCell) {
|
Rectangle2D rec = GraphConstants.getBounds(cell.getAttributes());
|
Point point = new Point((int) rec.getCenterX(), (int) rec.getCenterY());
|
java.awt.Rectangle rect = new java.awt.Rectangle(point.x - 10, point.y - 10, 20, 20);
|
if (rect.contains(x1, y1)) {
|
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
graph.setMoveable(false);
|
break k;
|
} else {
|
graph.setMoveable(true);
|
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
}
|
}
|
}
|
graph.refresh();
|
}
|
}
|
|
}
|
|
// 自定义鼠标事件,为连线做好准备工作
|
class MyMouse implements MouseListener {
|
int x1 = 0, y1 = 0;
|
|
protected void updateField() {
|
graph.refresh();
|
graph.updateUI();
|
}
|
|
// 点击鼠标事件,鼠标点击的时候执行的动作
|
@Override
|
public void mouseClicked(MouseEvent e) {
|
|
flushed(); // add by caill 2016.3.31在中间区域点击鼠标时刷新左侧导航栏内的数据
|
lcGraph.setCloneable(true);
|
lcGraph.setInvokesStopCellEditing(true);
|
lcGraph.setJumpToDefaultPort(true);
|
// addTansitionEventButton.setEnabled(false);
|
// // System.out.println("1929");
|
// deleteTansitionEventButton.setEnabled(false);
|
// saveTansitionEventButton.setEnabled(false);
|
|
clearEventInfo();
|
|
Object cell = graph.getSelectionCell();
|
if (cell == null) {
|
setEventModify(false);
|
return;
|
}
|
// 判断选中组件是否为线,如果为线则在响应区域显示跃迁信息
|
// if (!(graph.getSelectionCell() instanceof DefaultPort)) {
|
if (cell instanceof DefaultEdge) {
|
|
// if (door == true) {
|
// addTansitionEventButton.setEnabled(false);
|
// // System.out.println("1940");
|
// deleteTansitionEventButton.setEnabled(false);
|
// saveTansitionEventButton.setEnabled(false);
|
// } else {
|
// // System.out.println("addTansitionEventButton.setEnabled(true);");
|
// addTansitionEventButton.setEnabled(true);
|
// deleteTansitionEventButton.setEnabled(true);
|
// saveTansitionEventButton.setEnabled(true);
|
// }
|
|
if (editingFlag != 0) {
|
setEventModify(true);
|
} else {
|
setEventModify(false);
|
}
|
LifeCycle selectedLC = null;
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeLifeCycle.getLastSelectedPathComponent();
|
if (node != null) {
|
Object userObject = node.getUserObject();
|
if (userObject instanceof LifeCycleWrapper) {
|
selectedLC = ((LifeCycleWrapper) userObject).getLC();
|
}
|
}
|
DefaultEdge selectedge = (DefaultEdge) graph.getSelectionCell();
|
// 得到界面内的所有组件
|
// DefaultPort dfps = (DefaultPort) selectedge.getSource();
|
// DefaultPort dfpt = (DefaultPort) selectedge.getTarget();
|
textFieldEdgeName.setText(selectedge.getUserObject().toString());
|
textFieldEdgeType.setText("DefaultEdge");
|
|
// 得到选中线的源点和目的点
|
DefaultPort p1 = (DefaultPort) selectedge.getSource();
|
DefaultPort p2 = (DefaultPort) selectedge.getTarget();
|
String dp1 = p1.getParent().toString();
|
String dp2 = p2.getParent().toString();
|
textFieldFromStatus.setText(dp1);
|
textFieldToStatus.setText(dp2);
|
|
|
Object obj = selectedge.getUserObject();
|
if (obj == null)
|
return;
|
|
String name = obj.toString();
|
if (mapTransitionEvents.containsKey(name)) {
|
List<TransitionVOEvent> lstEvent = mapTransitionEvents.get(name);
|
|
if (lstEvent != null) {
|
for (TransitionVOEvent tvoEvent : lstEvent) {
|
eventTableModel.addRow(tvoEvent.id);
|
}
|
tableEvent.updateUI();
|
}
|
}
|
|
// textFieldName.setEditable(false);
|
// textFieldTag.setEditable(true);
|
// textFieldDescription.setEditable(true);
|
// lc_startState.setEditable(false);
|
//
|
// textFieldFromStatus.setEditable(false);
|
// textFieldToStatus.setEditable(false);
|
// textFieldEdgeName.setEditable(false);
|
// textFieldEdgeType.setEditable(false);
|
// startStateComboBox.setEnabled(false);
|
// LifeCyle[] lifeCyles = null;
|
// TransitionVOEvent[] transitionVOEvents = null;
|
// TransitionVO[] transitionVOs = null;
|
// try {
|
// lifeCyles = LifeCycleStart.getService().getLifeCyles();
|
// } catch (VCIError e2) {
|
// // TODO Auto-generated catch block
|
// e2.printStackTrace();
|
// }
|
// List<TransitionVOEvent> tVoEvents = null;
|
// if (lifeCyles == null || lifeCyles.length == 0) {
|
//// if (transitionevents_maps != null && transitionevents_maps.size() > 0) {
|
//// for (int m = 0; m < transitionevents_maps.size(); m++) {
|
//// Map<String, List<TransitionVOEvent>> map = transitionevents_maps.get(m);
|
//// String key = getKey(map);
|
//// if (key == null) {
|
//// continue;
|
//// }
|
//// if (key.equals(selectedge.getUserObject().toString())) {
|
//// tVoEvents = map.get(key);
|
//// break;
|
//// }
|
//// }
|
//// }
|
//
|
// String key = selectedge.getUserObject().toString();
|
// if (mapTransitionEvents.containsKey(key)) {
|
// tVoEvents = mapTransitionEvents.get(key);
|
// }
|
//
|
// if (tVoEvents != null) {
|
// for (TransitionVOEvent tVoEvent : tVoEvents) {
|
// eventTableModel.addRow(tVoEvent.id);
|
// tableEvent.updateUI();
|
// }
|
// }
|
// } else {
|
// if (selectedLC != null) {
|
// transitionVOs = selectedLC.routes;
|
// for (TransitionVO tVo : transitionVOs) {
|
// if (tVo.source.equals(dp1) && tVo.destination.equals(dp2)) {
|
// transitionVOEvents = tVo.transitionVOEvents;
|
// for (TransitionVOEvent tVoEvent : transitionVOEvents) {
|
// eventTableModel.addRow(tVoEvent.id);
|
// tableEvent.updateUI();
|
// }
|
// }
|
// }
|
// }
|
// }
|
|
// }
|
|
}
|
}
|
|
|
/***
|
*
|
* @param map
|
* @return
|
*/
|
public String getKey(Map<String, List<TransitionVOEvent>> map) {
|
String key = null;
|
Iterator iterator = map.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry entry = (Map.Entry) iterator.next();
|
key = (String) entry.getKey();
|
// System.out.println(entry.getKey());
|
}
|
return key;
|
}
|
|
// 设置鼠标按下事件,当鼠标按下的时候开始画线
|
@Override
|
public void mousePressed(MouseEvent e) {
|
|
flushed(); // add by caill 2016.3.31在中间区域按下鼠标时刷新左侧导航栏内的数据
|
x1 = e.getX();
|
y1 = e.getY();
|
Point point1 = new Point(x1, y1);
|
if (cells == null)
|
return;
|
|
for (int i = 0; i < cells.size(); i++) {
|
if (cells.get(i) == null) {
|
continue;
|
}
|
// 在cell中规定一片区域,当鼠标移动到这片区域的时候变成手的形状
|
DefaultGraphCell cell = cells.get(i);
|
Rectangle2D rect = GraphConstants.getBounds(cell.getAttributes());
|
// Point point = new Point((int) rec.getCenterX(),
|
// (int) rec.getCenterY());
|
// double dx = GraphConstants.getBounds(
|
// cell.getAttributes()).getX();
|
//
|
// double dy = GraphConstants.getBounds(
|
// cell.getAttributes()).getY();
|
//
|
// double dw = GraphConstants.getBounds(
|
// cell.getAttributes()).getWidth();
|
//
|
// double dh = GraphConstants.getBounds(
|
// cell.getAttributes()).getHeight();
|
//
|
// Rectangle rect = new Rectangle();
|
// rect.setRect(dx, dy, dw, dh);
|
|
if (rect.contains(point1)) {
|
DefaultPort port00 = new DefaultPort();
|
Point2D point2d = new Point2D.Double((GraphConstants.PERMILLE / 2),
|
(GraphConstants.PERMILLE / 2));
|
GraphConstants.setOffset(port00.getAttributes(), point2d);
|
cell.add(port00);
|
cell1 = cell;
|
break;
|
}
|
}
|
}
|
|
// 鼠标释放的时候执行的动作
|
@Override
|
public void mouseReleased(MouseEvent e) {
|
|
flushed(); // add by caill 2016.3.31在中间区域释放鼠标时刷新左侧导航栏内的数据
|
x1 = e.getX();
|
y1 = e.getY();
|
if (cells == null || cell1 == null)
|
return;
|
|
// System.out.println(String.format("鼠标位置:x=%d, y=%d", x1, y1));
|
Rectangle2D rec1 = GraphConstants.getBounds(cell1.getAttributes());
|
Point point1 = new Point((int) rec1.getCenterX(), (int) rec1.getCenterY());
|
|
for (int i = 0; i < cells.size(); i++) {
|
DefaultGraphCell cell = cells.get(i);
|
if (cell == null || cell == cell1)
|
continue;
|
|
// System.out.println("Cell: " + cell.toString());
|
|
Rectangle2D rect = GraphConstants.getBounds(cell.getAttributes());
|
Point point = new Point((int) rect.getCenterX(), (int) rect.getCenterY());
|
|
// double dx = GraphConstants.getBounds(cell.getAttributes()).getX();
|
//
|
// double dy = GraphConstants.getBounds(cell.getAttributes()).getY();
|
//
|
// double dw = GraphConstants.getBounds(cell.getAttributes()).getWidth();
|
//
|
// double dh = GraphConstants.getBounds(cell.getAttributes()).getHeight();
|
//
|
// Rectangle rect = new Rectangle();
|
// rect.setRect(dx, dy, dh, dw);
|
|
// System.out.println("Cell Rectangle = " + rect);
|
|
if (!rect.contains(x1, y1))
|
continue;
|
|
if (cell instanceof DefaultGraphCell) {
|
// System.out.println("创建连线");
|
|
DefaultPort port00 = new DefaultPort(point1);
|
DefaultPort port01 = new DefaultPort(point);
|
|
DefaultEdge edge = new DefaultEdge();
|
GraphConstants.setLabelAlongEdge(edge.getAttributes(), true);
|
|
cell1.add(port00);
|
DefaultGraphCell cell2 = cell;
|
cell2.add(port01);
|
edge.setSource(port00);
|
GraphConstants.setOpaque(edge.getAttributes(), false);
|
int arrow = GraphConstants.ARROW_CLASSIC;
|
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
|
GraphConstants.setEndFill(edge.getAttributes(), true);
|
GraphConstants.setLineWidth(edge.getAttributes(), 2.0f);
|
edge.setTarget(port01);
|
|
if (edge.getUserObject() == null) {
|
edge.setUserObject("line" + edgeCount);
|
edgeCount++;
|
} else {
|
String lineName = edge.getUserObject().toString();
|
// if (lineName != null) {
|
// edges.setUserObject(lineName);
|
// } else {
|
if (lineName == null) {
|
edge.setUserObject("line" + edgeCount);
|
edgeCount++;
|
}
|
}
|
|
cell2 = null;
|
graph.getGraphLayoutCache().insert(edge);
|
setOo(graph.getRoots());
|
}
|
break;
|
}
|
}
|
|
// 鼠标进入的时候执行的动作
|
@Override
|
public void mouseEntered(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
// 鼠标退出的时候执行的动作
|
@Override
|
public void mouseExited(MouseEvent e) {
|
}
|
|
}
|
|
}
|
|
/**
|
* added by zhouhui
|
*/
|
private void addListenner() {
|
/**
|
* 查看使用范围
|
*/
|
checkButton.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
//door = false;
|
LifeCycle selectedLC = lifeCycleTreeSelection();
|
if (selectedLC == null) {
|
JOptionPane.showMessageDialog(null, "请选中要查看的生命周期", "无生命周期", JOptionPane.WARNING_MESSAGE);
|
return;
|
}
|
String name = selectedLC.name;
|
if (name == null || name.equals("") || name.equals("生命周期模板列表")) {
|
JOptionPane.showMessageDialog(null, "请选中要查看的生命周期", "无生命周期", JOptionPane.WARNING_MESSAGE);
|
return;
|
}
|
UsedToDialog usedToDialog = new UsedToDialog(name);
|
usedToDialog.setVisible(true);
|
}
|
});
|
}
|
|
/***
|
*
|
* @param map
|
* @return
|
*/
|
public String getListImageKey(Map<String, String> map) {
|
String key = null;
|
Iterator iterator = map.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry entry = (Map.Entry) iterator.next();
|
key = (String) entry.getKey();
|
}
|
return key;
|
}
|
|
/**
|
* 跃迁事件
|
*/
|
public void addTransationListener() {
|
addTansitionEventButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
addData();
|
}
|
});
|
}
|
|
public void deleteTransationListener() {
|
deleteTansitionEventButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
removeData();
|
}
|
});
|
}
|
|
public void saveTransationListener() {
|
saveTansitionEventButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
// isNoPressSaveTransitionEvents = true;
|
save_transitionevents();
|
JOptionPane.showMessageDialog(null, "保存成功");
|
// //保存完了,清除表格数据
|
//removeALLData();
|
|
}
|
});
|
}
|
|
private void addData() {
|
eventTableModel.addRow("");
|
tableEvent.updateUI();
|
}
|
|
private void removeData() {
|
Object[] options = { "Yes", "No" };
|
int option = JOptionPane.showOptionDialog(getInstance(), "确认是否删除跃迁事件", "跃迁事件删除", JOptionPane.YES_NO_OPTION,
|
JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
|
if (option != JOptionPane.YES_OPTION) {
|
return;
|
}
|
int row = tableEvent.getSelectedRow();
|
eventTableModel.removeRow(row);
|
tableEvent.updateUI();
|
}
|
|
// private void removeALLData() {
|
// eventTableModel.removeRows(0, eventTableModel.getRowCount());
|
// tableEvent.updateUI();
|
// }
|
|
// 将跃迁对象绑定跃迁事件,返回保存生命周期前的跃迁对象集合
|
public void save_transitionevents() {
|
try {
|
// Map<String, List<TransitionVOEvent>> map = new HashMap<String,
|
// List<TransitionVOEvent>>();
|
List<TransitionVOEvent> transitionevents = new ArrayList<TransitionVOEvent>();
|
int row = eventTableModel.getRowCount();
|
for (int i = 0; i < row; i++) {
|
TransitionVOEvent transitionevent = new TransitionVOEvent();
|
String key = (String) eventTableModel.getValueAt(i, 0);
|
String value = LifeCycleTransitionEvents.getlce_events_valuebykey(key);
|
transitionevent.id = key;
|
transitionevent.name = value;
|
transitionevents.add(transitionevent);
|
}
|
|
DefaultEdge selectedge = (DefaultEdge) lcGraph.getSelectionCell();
|
String transition_name = selectedge.getUserObject().toString();
|
mapTransitionEvents.put(transition_name, transitionevents);
|
|
// map.put(transition_name, transitionevents);
|
// transitionevents_maps = get_transitionevents_maps_instance();
|
// Iterator<Map<String, List<TransitionVOEvent>>> transitioneventes = transitionevents_maps.iterator();
|
// if (transitioneventes.hasNext()) {
|
// Map<String, List<TransitionVOEvent>> transitionevent = transitioneventes.next();
|
// if (transitionevent.containsKey(transition_name)) {
|
// transitioneventes.remove();
|
// }
|
// }
|
// transitionevents_maps.add(map);
|
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
|
public void initlc_startState() {
|
lc_startState.removeAllItems();
|
List<Bound> bounds = new ArrayList<Bound>();
|
Object[] o = lcGraph.getOo();
|
if (o == null) {
|
return;
|
}
|
for (int i = 0; i < o.length; i++) {
|
if (o[i] instanceof DefaultGraphCell) {
|
Bound bound = new Bound();
|
DefaultGraphCell ci = (DefaultGraphCell) o[i];
|
lc_startState.addItem(ci.toString());
|
}
|
}
|
}
|
|
public LifeCyclePanel getThis() {
|
return this;
|
}
|
|
public List<LifeCycle> getSelectedLCs() {
|
TreePath[] selectionPaths = treeLifeCycle.getSelectionPaths();
|
// 未选中, 返回
|
if (selectionPaths == null || selectionPaths.length == 0) {
|
return null;
|
}
|
// 选中根节点, 返回
|
if (selectionPaths.length == 1 && !(((DefaultMutableTreeNode) selectionPaths[0].getLastPathComponent())
|
.getUserObject() instanceof LifeCycleWrapper)) {
|
return null;
|
}
|
List<LifeCycle> list = new ArrayList<LifeCycle>();
|
for (TreePath path : selectionPaths) {
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
|
Object obj = node.getUserObject();
|
if (obj instanceof LifeCycleWrapper) {
|
list.add(((LifeCycleWrapper) obj).getLC());
|
}
|
}
|
return list;
|
}
|
|
// add by caill start 2016.3.31 刷新左侧导航栏内的“状态”的数据,但不改变JSplitpanel中间分隔线的位置
|
public void flushed() {
|
splitPane.remove(splitPane.getBottomComponent());
|
JScrollPane scrollPane2 = new JScrollPane(new WestJpanel());
|
//scrollPane.setPreferredSize(new Dimension(dimScreen.width / 6, scrollPane.getHeight()));// JSplitPanel分隔线位置是可以变化的,所以scrollPane的高度是动态变化的
|
scrollPane2.setPreferredSize(new Dimension(dimScreen.width / 6, scrollPane2.getHeight()));
|
splitPane.setBottomComponent(scrollPane2);
|
;// add by caill 2016.3.29将状态栏的scrollpanel2放到splitPane中
|
splitPane.updateUI();
|
}
|
// add by caill end
|
}
|