📄 startnode.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 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;
import flow.graph.app.FlowManager;
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;
/**
* @author matt
*
*/
public class StartNode extends AbstractManagerList {
private ServiceBean serviceBean;
public StartNode(){
serviceBean = new ServiceBean();
serviceBean.setT_id(0);
serviceBean.setT_name("业务列表");
serviceBean.setT_enterid(0);
}
public String toString() {
return serviceBean.getT_name();
}
public ServiceBean getServiceBean(){
return serviceBean;
}
public void load() {
Connection con0 = SQLiteConnection.getConnection();
Connection con1 = SQLiteConnection.getConnection();
if(con0 == null || con1 == null){
int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"Connect data base \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
"System Infomation",
JOptionPane.CLOSED_OPTION);
}
else{
try {
List listnode = DataBaseNode.selectNodes(con0, 0);
if(listnode == null){
}
else{
for(int i=0;i<listnode.size();i++){
loadNode((NodeBean)listnode.get(i));
}
}
List listservice = DataBaseService.selectService(con1);
if(listservice == null){
}
else{
for(int i=0;i<listservice.size();i++){
loadService((ServiceBean)listservice.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);
}
}
}
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() {
//getList().removeAllElements();
//load();
return true;
}
public void onAddNode(DefaultMutableTreeNode n) {
//if(n.getUserObject() instanceof BusinessNode){
//}
//else{
// n.add(new DefaultMutableTreeNode("No Child Node"));
//}
}
public void deleteServiceNode(ServiceNode s) {
System.out.println("正在删除业务:"+s);
Connection con = SQLiteConnection.getConnection();
if(con == null){
int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"数据库错误 \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
"系统提示",
JOptionPane.CLOSED_OPTION);
}
else{
try {
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("size="+getList().size()+", node2="+s);
DataBaseService.deleteService(con, s.getServiceBean().getT_id());
con = SQLiteConnection.getConnection();
if(DataBaseNode.deleteNodeByParent(con, s.getServiceBean().getT_id()) > 0){
}
else{
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("2.5............");
int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"数据库错误: \""+e.getMessage()+"!",
"系统提示",
JOptionPane.CLOSED_OPTION);
}
}
}
public void deleteBusinessNode(BusinessNode s) {
System.out.println("正在删除节点1:"+s);
Connection con = SQLiteConnection.getConnection();
if(con == null){
int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"数据库错误 \""+SQLiteConnection.SQLite_DATABASE+"\" failed!",
"系统提示",
JOptionPane.CLOSED_OPTION);
}
else{
try {
if(getList().size() == 1){
getList().removeAllElements();
System.out.println("111111111111");
}
else{
System.out.println("222222222222");
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("size="+getList().size()+", node2="+s);
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);
}
}
}
public void loadNode(NodeBean bean) {
ServiceNode sn = new ServiceNode(serviceBean);
getList().add(new BusinessNode(bean, sn));
store();
}
public void loadService(ServiceBean bean) {
getList().add(new ServiceNode(bean));
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(NodeBean nb, 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(new BusinessNode(nb, new ServiceNode(serviceBean)));
nb.setT_desc(name);
if(DataBaseNode.updateNodeName(con, nb) <= 0){
}
else{
loadNode(nb);
}
} 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 addService(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 {
ServiceBean sb = DataBaseService.insertService(con, name);
if(sb == null){
}
else{
loadService(sb);
}
} catch (SQLException e) {
int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"数据库错误: \""+e.getMessage()+"!",
"系统信息",
JOptionPane.CLOSED_OPTION);
return false;
}
}
return true;
}
public boolean modifyService(ServiceNode service, 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 {
int size = 0;
for(int i=0;i<getList().size();i++){
if(getList().get(i).equals(service)){
size = i;
break;
}
}
getList().remove(service);
ServiceBean bean = service.getServiceBean();
bean.setT_name(name);
if(DataBaseService.updateService(con, bean) <= 0){
}
else{
//System.out.println("a===================size="+size);
//getList().insertElementAt(new ServiceNode(bean), size);
loadService(bean);
}
} catch (SQLException e) {
int res = JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"数据库错误: \""+e.getMessage()+"!",
"系统信息",
JOptionPane.CLOSED_OPTION);
return false;
}
}
return true;
}
public void handleNetworkError(ServiceNode svr) {
svr.handleNetworkError();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -