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

📄 invokeform.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				// TODO Auto-generated method stub
				
			}

			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}});
		inputModifyButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(inputRowID != -1){
					if(inputName.getText().length() <= 0){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"变量名称不能为空!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						inputName.requestFocus();
						return;
					}
					if(inputType.getSelectedIndex() == 0){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"请选择数据类型!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						inputType.requestFocus();
						return;
					}
					if(inputFlag.isSelected() == true){
						if(inputSource.getSelectedIndex() <= 0){
							JOptionPane.showConfirmDialog(FlowManager.getInstance(),
									"请选择数据来源!",
									"工作流操作提示",
									JOptionPane.CLOSED_OPTION);
							inputSource.requestFocus();
							return;
						}
					}
					
					//////////////////////////
					//判断变量名是否已经存在
					for(int i=0;i<((InputParameterTableModel)inputTable.getModel()).getRowCount();i++){
						if(i == inputRowID)
							continue;
						if(((InputParameterTableModel)inputTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(inputName.getText())){
							JOptionPane.showConfirmDialog(FlowManager.getInstance(),
									"变量"+inputName.getText()+" 已经存在!",
									"工作流操作提示",
									JOptionPane.CLOSED_OPTION);
							inputName.requestFocus();
							return;
						}
					}
					String name = ((InputParameterTableModel)inputTable.getModel()).getValueAt(inputRowID, 0).toString();
					int index = ((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getExistsParameter(name);
					if(index >= 0){
						((InputParameter)((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setName(inputName.getText());
						((InputParameter)((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setType(inputType.getSelectedItem().toString());
						((InputParameter)((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setFlag(inputFlag.isSelected());
						((InputParameter)((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setSource(inputSource.getSelectedItem().toString());
						((InputParameter)((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setValue(inputValue.getText());
						((InputParameter)((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setDiscription(inputDiscription.getText());
					}
					
					((InputParameterTableModel)inputTable.getModel()).setValueAt(inputName.getText(), inputRowID, 0);
					((InputParameterTableModel)inputTable.getModel()).setValueAt(inputType.getSelectedItem().toString(), inputRowID, 1);
					((InputParameterTableModel)inputTable.getModel()).setValueAt(inputFlag.isSelected(), inputRowID, 2);
					((InputParameterTableModel)inputTable.getModel()).setValueAt(inputSource.getSelectedItem().toString(), inputRowID, 3);
					((InputParameterTableModel)inputTable.getModel()).setValueAt(inputValue.getText(), inputRowID, 4);
					((InputParameterTableModel)inputTable.getModel()).setValueAt(inputDiscription.getText(), inputRowID, 5);
					inputName.setText("");
					inputType.setSelectedIndex(0);
					inputFlag.setSelected(false);
					inputSource.setSelectedIndex(0);
					inputValue.setText("");
					inputDiscription.setText("");					
				}
				inputRowID = -1;
			}});
		inputDeleteButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(inputRowID != -1){
					((InputParameterTableModel)inputTable.getModel()).removeRow(inputRowID);
					int index = ((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getExistsParameter(inputName.getText());
					if(index >= 0){
						((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().remove(index);
					}
					inputName.setText("");
					inputType.setSelectedIndex(0);
					inputFlag.setSelected(false);
					inputSource.setSelectedIndex(0);
					inputValue.setText("");
					inputDiscription.setText("");					
				}
				inputRowID = -1;
			}});

		///////////////////////////////////////////////////////////
		outputAddButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(outputName.getText().length() <= 0){
					JOptionPane.showConfirmDialog(FlowManager.getInstance(),
							"变量名称不能为空!",
							"工作流操作提示",
							JOptionPane.CLOSED_OPTION);
					outputName.requestFocus();
					return;
				}
				if(outputType.getSelectedIndex() == 0){
					JOptionPane.showConfirmDialog(FlowManager.getInstance(),
							"请选择数据类型!",
							"工作流操作提示",
							JOptionPane.CLOSED_OPTION);
					outputType.requestFocus();
					return;
				}
				
				//////////////////////////
				//判断变量名是否已经存在
				/*
				if(FlowGraphConstants.getInputTemplate(cell.getAttributes()) != null){
					if(((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).exitsParameter(inputName.getText())){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"变量"+inputName.getText()+"已经存在!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						inputName.requestFocus();
						return;
					}
				}*/
				for(int i=0;i<((ParameterTableModel)outputTable.getModel()).getRowCount();i++){
					if(((ParameterTableModel)outputTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(outputName.getText())){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"变量"+outputName.getText()+" 已经存在!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						return;
					}
				}
				
				((ParameterTableModel)outputTable.getModel()).addRow(outputName.getText(), outputType.getSelectedItem().toString(), outputValue.getText(), outputDiscription.getText());
				Parameter p = new Parameter(outputName.getText(), outputType.getSelectedItem().toString(), outputValue.getText(), outputDiscription.getText());
				((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).addParameter(p);
				outputName.setText("");
				outputType.setSelectedIndex(0);
				outputValue.setText("");
				outputDiscription.setText("");
			}});
		
		outputTable.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				outputRowID = outputTable.rowAtPoint(e.getPoint());
				int columnID = outputTable.columnAtPoint(e.getPoint());
				outputName.setText(((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 0).toString());
				outputType.setSelectedItem(((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 1).toString());
				outputValue.setText(((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 2).toString());
				outputDiscription.setText(((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 3).toString());
			}

			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}});
		outputModifyButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(outputRowID != -1){
					if(outputName.getText().length() <= 0){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"变量名称不能为空!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						outputName.requestFocus();
						return;
					}
					if(outputType.getSelectedIndex() == 0){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"请选择数据类型!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						outputType.requestFocus();
						return;
					}
					
					//////////////////////////
					//判断变量名是否已经存在
					for(int i=0;i<((ParameterTableModel)outputTable.getModel()).getRowCount();i++){
						if(i == outputRowID)
							continue;
						if(((ParameterTableModel)outputTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(outputName.getText())){
							JOptionPane.showConfirmDialog(FlowManager.getInstance(),
									"变量"+outputName.getText()+" 已经存在!",
									"工作流操作提示",
									JOptionPane.CLOSED_OPTION);
							return;
						}
					}
					String name = ((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 0).toString();
					int index = ((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getExistsParameter(name);
					if(index >= 0){
						((Parameter)((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().get(index)).setName(outputName.getText());
						((Parameter)((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().get(index)).setType(outputType.getSelectedItem().toString());
						((Parameter)((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().get(index)).setValue(outputValue.getText());
						((Parameter)((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().get(index)).setDiscription(outputDiscription.getText());
					}
					
					((ParameterTableModel)outputTable.getModel()).setValueAt(outputName.getText(), outputRowID, 0);
					((ParameterTableModel)outputTable.getModel()).setValueAt(outputType.getSelectedItem().toString(), outputRowID, 1);
					((ParameterTableModel)outputTable.getModel()).setValueAt(outputValue.getText(), outputRowID, 2);
					((ParameterTableModel)outputTable.getModel()).setValueAt(outputDiscription.getText(), outputRowID, 3);
					outputName.setText("");
					outputType.setSelectedIndex(0);
					outputValue.setText("");
					outputDiscription.setText("");					
				}
				outputRowID = -1;
			}});
		outputDeleteButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(outputRowID != -1){
					((ParameterTableModel)outputTable.getModel()).removeRow(outputRowID);
					int index = ((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getExistsParameter(outputName.getText());
					if(index >= 0){
						((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().remove(index);
					}
					outputName.setText("");
					outputType.setSelectedIndex(0);
					outputValue.setText("");
					outputDiscription.setText("");					
				}
				outputRowID = -1;
			}});
		///////////////////////////////////////////////////////////
		dialog.getContentPane().setLayout(new BorderLayout());
		Box parameterBox = Box.createHorizontalBox();
		parameterBox.add(inputTitledPanel);
		parameterBox.add(outputTitledPanel);
		JPanel parameterPanel = new JPanel(new BorderLayout());
		parameterPanel.setBorder(new TitledBorder("参数"));
		parameterPanel.setPreferredSize(new Dimension(10, 1));
		parameterPanel.add(parameterBox, BorderLayout.CENTER);
		
		//Box actionBox1 = Box.createVerticalBox();
		//actionBox1.add(condictionBox);
		//actionBox1.add(actionPanel);
		
		Box actionBox = Box.createHorizontalBox();
		JPanel tipsPanel = new JPanel(new BorderLayout());
		tipsPanel.setBorder(new TitledBorder("函数参考"));
		tipsPanel.setPreferredSize(new Dimension(1, 100));
		tipsPanel.add(new FunctionTree(graph).getTree(), BorderLayout.CENTER);
		actionBox.add(actionPanel);
		actionBox.add(tipsPanel);
		JPanel codePanel = new JPanel(new BorderLayout());
		codePanel.setBorder(new TitledBorder("代码"));
		codePanel.add(actionBox, BorderLayout.CENTER);
		
		Box layoutBox = Box.createVerticalBox();
		layoutBox.add(parameterPanel);

		layoutBox.add(codePanel);
		
		dialog.getContentPane().add(layoutBox, BorderLayout.CENTER);
		dialog.getContentPane().add(exitPanel, BorderLayout.SOUTH);
		dialog.setSize(900, 650);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		dialog.setLocation((screenSize.width-900)/2, (screenSize.height-650)/2);
		dialog.setResizable(false);
		dialog.addWindowListener(new WindowListener(){

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

			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				saveData();
			}

			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.show();		
	}
	
	private void saveData(){
		if(FlowGraphConstants.getActionTemplate(cell.getAttributes()) != null){
			((ActionTemplate)FlowGraphConstants.getActionTemplate(cell.getAttributes())).setAction(actionArea.getText());
		}
		//Vector v = GraphTemplateCell.getParameters(cell);
		//System.out.println("-===================ddddddddddd=======================-");
		//for(int i=0;i<v.size();i++){
		//	System.out.println(v.get(i).toString());
		//}
		LuaInvokeParse parse = new LuaInvokeParse(cell);
		System.out.println(parse.getDiscriptionCode());
		System.out.println(parse.getDefineCode());
		System.out.println(parse.getExecuteCode());
		
		inputType.setPopupVisible(false);
		inputSource.setPopupVisible(false);
		outputType.setPopupVisible(false);
		
		dialog.dispose();
	}

	public static void main(String[] args){
		CaseForm.setLookAndFeel();
		DefaultGraphCell cell = new DefaultGraphCell();
		cell.addPort();
		new InvokeForm(cell, new JGraph());
	}
}

⌨️ 快捷键说明

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