⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invokeform.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/**
 * 
 */
package flow.graph.gui.graph.cell.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
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.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Hashtable;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCell;

import flow.graph.app.FlowManager;
import flow.graph.gui.graph.FlowGraphConstants;
import flow.graph.gui.graph.GraphExtends;
import flow.graph.gui.graph.cell.BPELFlag;
import flow.graph.gui.graph.cell.FlowGraphCell;
import flow.graph.gui.graph.cell.bpel.Function;
import flow.graph.gui.graph.cell.bpel.FunctionTips;
import flow.graph.gui.graph.cell.bpel.Functions;
import flow.graph.gui.graph.cell.bpel.Invoke;
import flow.graph.gui.graph.cell.bpel.Message;
import flow.graph.gui.graph.cell.bpel.Messages;
import flow.graph.gui.graph.cell.bpel.While;

/**
 * @author Administrator
 *
 */
public class InvokeForm {
	private DefaultGraphCell cell;
	private JGraph graph;
	private JDialog dialog;

	private JComboBox functionBox;
	private JComboBox inputBox;
	private JComboBox outputBox;
	private JButton exitButton;
	private Hashtable functionTipsTable;
	private JTextArea functionTipsArea;
	
	public InvokeForm(DefaultGraphCell cell, JGraph graph){
		this.cell = cell;
		this.graph = graph;
		functionTipsTable = new Hashtable();
		
		if(FlowGraphConstants.getBpelInvoke(cell.getAttributes()) == null){
			FlowGraphConstants.setBpelInvoke(cell.getAttributes(), new Invoke());
		}
		
		dialog = new JDialog(FlowManager.getInstance(), "函数调用数据编辑窗口", true);
		
		functionBox = new JComboBox();
		functionBox.setEditable(true);
		inputBox = new JComboBox();
		inputBox.insertItemAt("", 0);
		outputBox = new JComboBox();
		outputBox.insertItemAt("", 0);
		functionTipsArea = new JTextArea(30, 40);

		//初始化输入参数、输出参数
		if(((GraphExtends)graph).getBPELMessages() != null){
			Messages messages = ((GraphExtends)graph).getBPELMessages();
			for(int i=0;i<messages.getMessages().size();i++){
				Message message = (Message)messages.getMessages().get(i);
				if(message.getType().equals(Message.RESPONSE_TYPE)){
					//返回类型
					outputBox.insertItemAt(message.getName(), outputBox.getItemCount());
				}
				else{
					//请求类型
					inputBox.insertItemAt(message.getName(), inputBox.getItemCount());
				}
			}
		}
		
		//初始化函数列表
		//...
		Object[] cells = graph.getRoots();
		for(int i=0;i<cells.length;i++){
			if(cells[i] instanceof FlowGraphCell){
				if(FlowGraphConstants.getBpelType(((DefaultGraphCell)cells[i]).getAttributes()).toString().equals(BPELFlag.BPEL_MODEL)){
					if(FlowGraphConstants.getBpelFunctions(((DefaultGraphCell)cells[i]).getAttributes()) != null){
						Functions functions = (Functions)FlowGraphConstants.getBpelFunctions(((DefaultGraphCell)cells[i]).getAttributes());
						if(functions.getFunctions() != null){
							for(int j=0;j<functions.getFunctions().size();j++){
								Function function = (Function)functions.getFunctions().get(j);
								functionBox.insertItemAt(function.getName(), functionBox.getItemCount());
								functionTipsTable.put(function.getName(), function.getDiscription());
							}
						}
						if(functions.getFunctionTips() != null){
							for(int j=0;j<functions.getFunctionTips().size();j++){
								FunctionTips functionTips = (FunctionTips)functions.getFunctionTips().get(j);
								functionBox.insertItemAt(functionTips.getName(), functionBox.getItemCount());
								functionTipsTable.put(functionTips.getName(), functionTips.getDiscription());
							}
						}
					}
				}
			}
		}
		
		functionBox.addItemListener(new ItemListener(){

			public void itemStateChanged(ItemEvent e) {
				// TODO Auto-generated method stub
				JComboBox tempBox = (JComboBox)e.getSource();
				String name = tempBox.getSelectedItem().toString();
				if(functionTipsTable.get(name) != null){
					functionTipsArea.setText(functionTipsTable.get(name).toString());
				}
				else{
					functionTipsArea.setText("函数"+name+"没有添加说明");
				}
			}
			
		});
		
		if(FlowGraphConstants.getBpelInvoke(cell.getAttributes()) != null){
			functionBox.setSelectedItem(((Invoke)FlowGraphConstants.getBpelInvoke(cell.getAttributes())).getOperation());
			inputBox.setSelectedItem(((Invoke)FlowGraphConstants.getBpelInvoke(cell.getAttributes())).getInputVariable());
			outputBox.setSelectedItem(((Invoke)FlowGraphConstants.getBpelInvoke(cell.getAttributes())).getOutputVariable());
		}
		
		exitButton = new JButton("关  闭");
		exitButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				saveData();
			}			
		});
		
		dialog.getContentPane().setLayout(new BorderLayout());
		JPanel panel = new JPanel(new BorderLayout());
		panel.setBorder(new TitledBorder(""));
		
		Box box = Box.createHorizontalBox();
		box.add(new JLabel("函数名:"));
		box.add(functionBox);
		box.add(Box.createHorizontalStrut(3));
		box.add(new JLabel("输入:"));
		box.add(inputBox);
		box.add(Box.createHorizontalStrut(3));
		box.add(new JLabel("输出:"));
		box.add(outputBox);
		
		JPanel tipsPanel = new JPanel(new BorderLayout());
		functionTipsArea.setEditable(false);
		tipsPanel.setBorder(new TitledBorder("函数说明"));
		tipsPanel.add(functionTipsArea);
		
		Box layoutBox = Box.createVerticalBox();
		JPanel controlPanel = new JPanel(new FlowLayout());
		controlPanel.add(exitButton);
		
		layoutBox.add(box);
		layoutBox.add(Box.createVerticalStrut(5));
		layoutBox.add(tipsPanel);
		layoutBox.add(Box.createVerticalStrut(5));
		layoutBox.add(controlPanel);
		
		panel.add(layoutBox, BorderLayout.CENTER);
		
		dialog.addWindowListener(new WindowListener(){
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				if(saveData() == false)
					return;
			}

			public void windowClosed(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void windowActivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		dialog.getContentPane().add(panel, BorderLayout.CENTER);
		dialog.setSize(450, 400);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		dialog.setLocation((screenSize.width-450)/2, (screenSize.height-400)/2);
		dialog.setResizable(true);
		dialog.show();		
	}
	
	private boolean saveData(){
		if(functionBox.getSelectedItem().toString().length() <= 0){
			JOptionPane.showConfirmDialog(FlowManager.getInstance(),
					"函数名不能为空!",
					"工作流操作提示",
					JOptionPane.CLOSED_OPTION);
			return false;
		}
		((Invoke)FlowGraphConstants.getBpelInvoke(cell.getAttributes())).setOperation(functionBox.getSelectedItem().toString());
		((Invoke)FlowGraphConstants.getBpelInvoke(cell.getAttributes())).setInputVariable(inputBox.getSelectedItem().toString());
		((Invoke)FlowGraphConstants.getBpelInvoke(cell.getAttributes())).setOutputVariable(outputBox.getSelectedItem().toString());
		dialog.dispose();
		return true;
	}
	
	public static void main(String[] args){
		AssignForm.configureUI();
		new WhileForm(new DefaultGraphCell(), new JGraph());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -