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

📄 servicenode.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/*
Copyright 2005 Matthew J. Battey

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software distributed
	under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
	CONDITIONS OF ANY KIND, either express or implied. See the License for the
	specific language governing permissions and limitations under the License.

This software implements a Java application to manage a SAFMQ server.
		
Created on May 13, 2005
*/
package flow.graph.gui.tree;

import java.net.URI;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;

import flow.graph.app.FlowManager;
import flow.graph.db.SQLiteConnection;
import flow.graph.db.bean.DataBaseNode;
import flow.graph.db.bean.NodeBean;
import flow.graph.db.bean.ServiceBean;

/**
* @author matt
*
*/
public	class ServiceNode extends AbstractManagerList implements IconItem, Deleteable{
	private ServiceBean serviceBean;
	private int page = 0;
	static ImageIcon hasnode = null;
	static Icon	nonode;
	
	static {
		try { hasnode = new ImageIcon(ServiceNode.class.getResource("images/new_ser.gif")); } catch (Exception e) { e.printStackTrace(); }
		nonode = UIManager.getIcon("Tree.closedIcon");
	}
	
	public ServiceNode(ServiceBean bean) {
		serviceBean = bean;
	}
	
	public ServiceBean getServiceBean(){
		return serviceBean;
	}
	
	public boolean equals(Object o) {
		if (o instanceof ServiceNode){
			ServiceNode bn = (ServiceNode)o;
			if(bn.getServiceBean().getT_id() == serviceBean.getT_id())
				return true;
			else
				return false;
		}
		else
			return false;
	}
	
	public String toString() {
		return serviceBean.getT_name();
	}
	
	public int getPage(){return page;}
	public void setPage(int p){page = p;}

	/**
	 * Provides the name of the SAFMQ server
	 * @return the name of the SAFMQ server
	 */
	public String getName() {
		return serviceBean.getT_name();
	}

	public void handleNetworkError() {
		//con = null;	
	}
	
	/**
	 * Provides the server icon for the user interface.
	 * 
	 * @see com.safmq.manager.IconItem#getIcon()
	 */
	public Icon getIcon() {
		return nonode;
	}

	/**
	 * Causes a new node to be added to the tree
	 * @see com.safmq.manager.AbstractManagerList#onAddNode(javax.swing.tree.DefaultMutableTreeNode)
	 */
	public void onAddNode(DefaultMutableTreeNode n) {
		/*
		System.out.println("ServiceNode...onAddNode......");
		if(n.getUserObject() instanceof BusinessNode){
			//n.add(new DefaultMutableTreeNode("No Child Node"));
		}
		else{
			n.add(new DefaultMutableTreeNode("No Child Node"));
		}
		*/
	}

	/**
	 * @see com.safmq.manager.AbstractManagerList#reload()
	 */
	public boolean reload() {
		Connection con = SQLiteConnection.getConnection();
		if(con == null){
			int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
					"Connect data base \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
					"System Infomation",
					JOptionPane.CLOSED_OPTION);	
			return false;
		}
		else{
			try {
				getList().removeAllElements();
				List list = DataBaseNode.selectNodes(con, serviceBean.getT_id());
				if(list == null){				
				}
				else{
					for(int i=0;i<list.size();i++){
						loadNode((NodeBean)list.get(i));
					}
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
						"DataBase error: \""+e.getMessage()+"!",
						"DataBase Error",
						JOptionPane.CLOSED_OPTION);	
				return false;
			}
		}
		return true;
	}
	
	/**
	 * @see com.safmq.manager.ServerTreeViewSelectionListener#doSelection(javax.swing.JTree, javax.swing.tree.DefaultMutableTreeNode)
	 */
	public void doSelection(JTree tree, DefaultMutableTreeNode node) {
		//System.out.println("1--------");
		if (reload()) {
			setNodeChildren(tree, node);
			FlowManager.getInstance().setControlView(new IconListView(this,UIManager.getIcon("Tree.closedIcon")));	
		}	
	}

	public void loadNode(NodeBean bean) {
		getList().add(new BusinessNode(bean, this));
		//store();
	}

	public boolean addNode(int parentid, String name){
		Connection con = SQLiteConnection.getConnection();
		if(con == null){
			int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
					"数据库错误 \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
					"系统信息",
					JOptionPane.CLOSED_OPTION);	
			return false;
		}
		else{
			try {
				NodeBean nb = new NodeBean();
				nb.setT_parentid(parentid);
				nb.setT_name("");
				nb.setT_desc(name);
				nb.setT_graph("");
				nb.setT_program("");
				NodeBean node = DataBaseNode.insertNode(con, nb);
				if(node == null){				
				}
				else{
					loadNode(node);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
						"数据库错误: \""+e.getMessage()+"!",
						"系统信息",
						JOptionPane.CLOSED_OPTION);	
				return false;
			}
		}
		return true;
	}

	public boolean modifyNode(BusinessNode node, String name){
		Connection con = SQLiteConnection.getConnection();
		if(con == null){
			int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
					"数据库错误 \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
					"系统信息",
					JOptionPane.CLOSED_OPTION);	
			return false;
		}
		else{
			try {
				getList().remove(node);
				NodeBean nb = new NodeBean();
				nb.setT_id(node.getNodeBean().getT_id());
				nb.setT_desc(name);				
				if(DataBaseNode.updateNodeName(con, nb) > 0){				
					NodeBean nbean = node.getNodeBean();
					nbean.setT_desc(name);
					loadNode(nbean);
				}
				else{
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
						"数据库错误: \""+e.getMessage()+"!",
						"系统信息",
						JOptionPane.CLOSED_OPTION);	
				return false;
			}
		}
		return true;
	}

	public void deleteBusinessNode(BusinessNode s) {
		System.out.println("正在删除节点2:"+s);
		Connection con = SQLiteConnection.getConnection();
		if(con == null){
			int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
					"数据库错误 \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
					"系统提示",
					JOptionPane.CLOSED_OPTION);	
		}
		else{
			try {
				/*
				for(int i=0;i<getList().size();i++){
					System.out.println("(---1)"+getList().get(i));
				}*/
				if(getList().size() == 1){
					getList().removeAllElements();
				}
				else{
					for(int i=0;i<getList().size();i++){
						if(s.equals(getList().get(i))){
							getList().remove(i);
							//System.out.println("i="+i);
							break;
						}
					}
				}
				//System.out.println("flag2="+getList().remove(s));
				
				System.out.println("size="+getList().size()+", node2="+s);
				
				for(int i=0;i<getList().size();i++)
					System.out.println("(---2)"+getList().get(i));
				
				if(DataBaseNode.deleteNode(con, s.getNodeBean().getT_id()) > 0){	
				}
				else{
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
						"数据库错误: \""+e.getMessage()+"!",
						"系统提示",
						JOptionPane.CLOSED_OPTION);	
			}
		}
	}
	/* (non-Javadoc)
	 * @see com.safmq.manager.Deleteable#delete()
	 */
	public boolean delete() {
		int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
							"确定要删除业务 \""+toString()+"\"?\n",
							"系统删除操作提示",
							JOptionPane.YES_NO_OPTION);
		if (res == JOptionPane.YES_OPTION) {
			FlowManager.getInstance().deleteServiceNode(this);
		}
		return true;
	}

	/* (non-Javadoc)
	 * @see com.safmq.manager.Deleteable#getDescription()
	 */
	public String getDescription() {
		return "业务 "+getName();
	}

}

⌨️ 快捷键说明

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