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

📄 startlist.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.beans.XMLDecoder;
import java.beans.XMLEncoder;

import flow.graph.app.WorkFlow;
import flow.graph.db.SQLiteConnection;
import flow.graph.db.bean.DataBaseNode;
import flow.graph.db.bean.DataBaseService;
import flow.graph.db.bean.NodeBean;
import flow.graph.db.bean.ServiceBean;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;

/**
* @author matt
*
*/
public class StartList extends AbstractTreeNode {	
	ServiceBean bean;
	
	public StartList(){
		bean = new ServiceBean();
		bean.setT_id(0);
		bean.setT_enterid(0);
		bean.setT_name("业务列表");		
	}
	
	public ServiceBean getBean(){
		return bean;
	}

	public String toString() {
		return "业务列表";
	}
	
	public void load() {
		/*
		//addServer("192.168.1.141","admin","",true);
		//addServer("localhost","admin","",true);
		try {
			XMLDecoder d = new XMLDecoder(new BufferedInputStream(new FileInputStream(FILE_NAME)));
			Vector storeList = (Vector)d.readObject();
			for(int x=0;x<storeList.size();x++) {
				ServerSpec s = (ServerSpec)storeList.get(x);
				//System.out.println("name="+s.name);
				addServer(s.name,s.user,s.password,s.storePassword);	
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
	}

	public void store() {
		/*
		Vector 	list = getList();
		Vector	storeList = new Vector();
		Server s;
		for(int x=0; x<list.size(); x++) {
			s = (Server)list.get(x);
			
			storeList.add(new ServerSpec(s.getName(),s.getUsername(),s.getPassword(),s.getStorePassword()));
		}
		
		try {
			XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(FILE_NAME)));
			e.writeObject(storeList);
			e.close();
		} catch (Exception e) {
			// TOOD: Report the error
			e.printStackTrace();	
		}	
		*/
	}
	
	/**
	 * Called to reload the list.  The list isn't ever reloaded from
	 * a server so this method simply returns true, that the data has
	 * been successfully loaded.
	 */
	public boolean reload() {
		System.out.println("--------StartList-------reload()......");
		getList().removeAllElements();
		Connection con0 = SQLiteConnection.getConnection();
		if(con0 == null){
			int res = JOptionPane.showConfirmDialog(WorkFlow.getInstance(),
					"Connect data base \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
					"System Infomation",
					JOptionPane.CLOSED_OPTION);	
			return false;
		}
		else{
			
			try {
				//getList().removeAllElements();
				System.out.println("ServiceList...reload......");
				List list = DataBaseNode.selectNodes(con0, 0);
				if(list == null){				
				}
				else{
					for(int i=0;i<list.size();i++){
						addNode((NodeBean)list.get(i));
					}
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println("2.5............");
				int res = JOptionPane.showConfirmDialog(WorkFlow.getInstance(),
						"DataBase error: \""+e.getMessage()+"!",
						"DataBase Error",
						JOptionPane.CLOSED_OPTION);	
				return false;
			}
		}

		//加载业务列表
		//System.out.println("ServiceList load...");
		Connection con = SQLiteConnection.getConnection();
		if(con == null){
			int res = JOptionPane.showConfirmDialog(WorkFlow.getInstance(),
					"Connect data base \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
					"System Infomation",
					JOptionPane.CLOSED_OPTION);	
			return false;
		}
		else{
			
			try {
				List list = DataBaseService.selectService(con);
				if(list == null){				
				}
				else{
					for(int i=0;i<list.size();i++){
						addService((ServiceBean)list.get(i));
					}
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println("2.5............");
				int res = JOptionPane.showConfirmDialog(WorkFlow.getInstance(),
						"DataBase error: \""+e.getMessage()+"!",
						"DataBase Error",
						JOptionPane.CLOSED_OPTION);	
				return false;
			}
		}
		return true;
	}
	
	public void onAddNode(DefaultMutableTreeNode n) {
		if(n.getUserObject() instanceof Node){
			;
		}
		else
			n.add(new DefaultMutableTreeNode("No Service Node"));
	}
	
	public void deleteService(ServiceList s) {
		getList().remove(s);
		store();	
	}

	public void deleteNode(NodeBean s) {
		getList().remove(s);
		store();	
	}
	
	public void addNode(NodeBean sb) {
		getList().add(new Node(sb, bean, this));
	}

	public void addService(ServiceBean sb) {
		getList().add(new ServiceList(sb, this));
	}

	public void handleNetworkError(ServiceList svr) {
		svr.handleNetworkError();
	}
	
	public static void main(String[] args){
		/*
		Vector	storeList = new Vector();
		storeList.add(new ServerSpec("192.168.1.141","admin","",true));
		try {
			XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(FILE_NAME)));
			e.writeObject(storeList);
			e.close();
		} catch (Exception e) {
			// TOOD: Report the error
			e.printStackTrace();	
		}	
		*/
	}

	public boolean insertService(String name){
		Connection con = SQLiteConnection.getConnection();
		if(con == null){
			int res = JOptionPane.showConfirmDialog(WorkFlow.getInstance(),
					"Connect data base \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
					"System Infomation",
					JOptionPane.CLOSED_OPTION);	
			return false;
		}
		else{
			try {
				ServiceBean sb = DataBaseService.insertService(con, name);
				if(sb == null){				
				}
				else{
					reload();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println("2.5............");
				int res = JOptionPane.showConfirmDialog(WorkFlow.getInstance(),
						"DataBase error: \""+e.getMessage()+"!",
						"DataBase Error",
						JOptionPane.CLOSED_OPTION);	
				return false;
			}
		}
		return true;
	}

	public boolean modifyService(int id, String name){
		Connection con = SQLiteConnection.getConnection();
		if(con == null){
			int res = JOptionPane.showConfirmDialog(WorkFlow.getInstance(),
					"Connect data base \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
					"System Infomation",
					JOptionPane.CLOSED_OPTION);	
			return false;
		}
		else{
			try {
				ServiceBean ser = new ServiceBean();
				ser.setT_id(id);
				ser.setT_name(name);
				if(DataBaseService.updateService(con, ser) <= 0){
					System.out.println("modify...1");
				}
				else{
					System.out.println("modify...2");
					reload();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println("2.5............");
				int res = JOptionPane.showConfirmDialog(WorkFlow.getInstance(),
						"DataBase error: \""+e.getMessage()+"!",
						"DataBase Error",
						JOptionPane.CLOSED_OPTION);	
				return false;
			}
		}
		return true;
	}
}

⌨️ 快捷键说明

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