📄 servicelist.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.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
/**
* @author matt
*
*/
public class ServiceList extends AbstractTreeNode implements IconItem, Deleteable{
static ImageIcon icon = null;
static {
try {
icon = new ImageIcon(Node.class.getResource("images/folder.gif"));
} catch (Exception e) {
}
}
private ServiceBean bean;
AbstractTreeNode absNode;
public ServiceList(ServiceBean sb, AbstractTreeNode abs){
bean = sb;
absNode = abs;
}
public String toString() {
return bean.getT_name();
}
public ServiceBean getBean(){
return bean;
}
public AbstractTreeNode getAbs(){
return absNode;
}
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("--------ServiceList-------reload()......");
//加载业务列表
//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 {
getList().removeAllElements();
System.out.println("ServiceList...reload......");
List list = DataBaseNode.selectNodes(con, bean.getT_id());
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;
}
}
return true;
}
public void onAddNode(DefaultMutableTreeNode n) {
//n.add(new DefaultMutableTreeNode("No Service Node1"));
}
public void deleteNode(NodeBean s) {
getList().remove(s);
store();
}
public void addNode(NodeBean sb) {
getList().add(new Node(sb, bean, this));
}
public void handleNetworkError(Node 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 Icon getIcon() {
// TODO Auto-generated method stub
return null;
}
public boolean delete() {
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 {
DataBaseService.deleteService(con, bean.getT_id());
con = SQLiteConnection.getConnection();
if(DataBaseNode.deleteNode(con, bean.getT_id()) > 0){
reload();
}
else{
}
} 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 String getDescription() {
// TODO Auto-generated method stub
return null;
}
public void handleNetworkError() {
//con = null;
}
public boolean insertNode(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 {
NodeBean nb = new NodeBean();
nb.setT_parentid(bean.getT_id());
nb.setT_name("");
nb.setT_desc(name);
nb.setT_graph("");
nb.setT_program("");
NodeBean node = DataBaseNode.insertNode(con, nb);
if(node == 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 modifyNode(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 {
NodeBean node = new NodeBean();
node.setT_id(id);
node.setT_desc(name);
if(DataBaseNode.updateNodeName(con, node) <= 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 + -