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

📄 adaptoramin.java.svn-base

📁 数据库通用适配器:实现行粒度的数据库的转换
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
package hdaty.prtds.rdgadaptor.gui;
import hdaty.prtds.rdgadaptor.protocol.DataSour;
import hdaty.prtds.rdgadaptor.protocol.Message;
import hdaty.prtds.rdgadaptor.protocol.Source;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;


import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.events.ShellEvent;


public class Adaptoramin {

	private Table table;
	protected Shell shell;
	protected Shell dialogshell;
	
	static DataSour S;
	static Vector Message=new Vector();
	Vector Mes=new Vector();
	//MessageInfro Infro=new MessageInfro();
	Vector dataSources;
	Vector comb1,comb2;//comb1是数据源的下拉框,comb2是目的数据库的下拉框
	Vector comb3,comb4,comb5,Text1;//comb3是数据源表的下拉框,comb4是目的数据库表的下拉框
	
	
	

	
	
	//public CCombo comb[][];
	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Adaptoramin Adaptor= new Adaptoramin();			
			Adaptor.open();
			 try {
		    	 File f = new File("./src/config/DATASOURCE.txt"); 
		    	 if(f.exists()){ 
		    	 System.out.print("文件存在"); 
		    	 f.delete();
		    	 if(S.getS().size()!=0){f.createNewFile();//不存在则创建 
		    	 ObjectOutputStream out =new ObjectOutputStream(new FileOutputStream(f));
					out.writeObject(S);
					}
		    	 }else{ 
		    	 System.out.print("文件不存在"); 
		    	 if(S.getS().size()!=0){f.createNewFile();//不存在则创建 
		    	 ObjectOutputStream out =new ObjectOutputStream(new FileOutputStream(f));
					out.writeObject(S);
					}
		    	 }
		    	 
					
				File fr = new File("./src/config/task.txt"); 
		    	 if(fr.exists()){ 
		    	 System.out.print("文件存在"); 		    	 
		    	fr.delete();
		    	fr.createNewFile();//不存在则创建
	    		 ObjectOutputStream outr =new ObjectOutputStream(new FileOutputStream(fr));
				outr.writeObject(Message);
		    	 }else{ 
		    	 System.out.print("文件不存在"); 
		    	 if(Message.size()!=0){
		    		 fr.createNewFile();//不存在则创建
		    		 ObjectOutputStream outr =new ObjectOutputStream(new FileOutputStream(fr));
					outr.writeObject(Message);
		    	 }
		    	 }		    		    	 
		    	
				
				
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @throws ClassNotFoundException 
	 */
	public void open() throws FileNotFoundException, IOException, ClassNotFoundException {
		
		File f = new File("./src/config/DATASOURCE.txt"); 
   	    if(f.exists()){ 
   	      System.out.print("文件存在"); 
   	      ObjectInputStream in=new ObjectInputStream(new FileInputStream(f));   	      
   	      S=(DataSour)in.readObject();
   	    }else{ 
   	     System.out.print("文件不存在"); 
   	     dataSources=new Vector();
	     S=new DataSour(dataSources);
   	   	 }	
   	    
   	    File F = new File("./src/config/task.txt"); 
	    if(F.exists()){ 
	      System.out.print("文件存在"); 
	      ObjectInputStream Inr=new ObjectInputStream(new FileInputStream(F));   	      
	      Message=(Vector)Inr.readObject();
	    }else{ 
	     System.out.print("文件不存在"); 
	    
	   	 }	
   	    
		createContents();
		
	}
	int  count=0;
	/**
	 * Create contents of the window
	 */
	protected void createContents() {
		
		Display display = Display.getDefault();
		comb1=new Vector();
		comb2=new Vector();
		comb3=new Vector();
		comb4=new Vector();
		comb5=new Vector();
		Text1=new Vector();
		shell = new Shell(SWT.TITLE);
		
	final Toolkit kit = Toolkit.getDefaultToolkit();
		shell.setLayout(new FormLayout());		
		shell.setSize(800, 500);
		
		final int  point_x=(kit.getScreenSize().width - 800) / 2;
		final int  point_y=(kit.getScreenSize().height - 500) / 2;
		shell.setLocation(point_x,point_y);	
		
		shell.setText("关系型数据库通用数据采集适配器V1.0");
		final Tray tray=display.getSystemTray();
		if(tray==null){
			System.out.println("该系统不支持系统托盘");
			return;
		}
		final TrayItem item=new TrayItem(tray,SWT.None);
		Image image=new Image(display,"./src/config/icon.gif");
		item.setImage(image);
		item.setToolTipText("数据转移软件");

		
		item.addListener(SWT.Show, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("show");
            }
        });
        item.addListener(SWT.Hide, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("hide");
            }
        });
        item.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("selection");
                
            }
        });
        item.addListener(SWT.DefaultSelection, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("default selection");
                shell.setVisible(!shell.isVisible());
                tray.getItem(0).setVisible(!shell.isVisible());
            }
        });

		
		shell.addShellListener(new ShellListener() {

            public void shellActivated(ShellEvent e) {
                // TODO Auto-generated method stub
                
            }

            public void shellClosed(ShellEvent e) {
                // TODO Auto-generated method stub
            	
            }

            public void shellDeactivated(ShellEvent e) {
                // TODO Auto-generated method stub
                
            }

            public void shellDeiconified(ShellEvent e) {
                // TODO Auto-generated method stub
                
            }

            public void shellIconified(ShellEvent e) {
            	shell.setVisible(!shell.isVisible());
                tray.getItem(0).setVisible(!shell.isVisible());
            }
            
        });

		

		Menu menu = new Menu(shell, SWT.BAR);
		shell.setMenuBar(menu);
		
		final MenuItem newSubmenuMenuItem_2 = new MenuItem(menu, SWT.CASCADE);
		newSubmenuMenuItem_2.setText("文件");

		final Menu menu_4 = new Menu(newSubmenuMenuItem_2);
		newSubmenuMenuItem_2.setMenu(menu_4);
	
		final MenuItem newSubmenuMenuItem_3 = new MenuItem(menu_4, SWT.CASCADE);
		newSubmenuMenuItem_3.setText("打开");

		final Menu menu_5 = new Menu(newSubmenuMenuItem_3);
		newSubmenuMenuItem_3.setMenu(menu_5);

		final MenuItem newItemMenuItem_14 = new MenuItem(menu_5, SWT.NONE);
		newItemMenuItem_14.setText("日志文件");
		
		newItemMenuItem_14.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				//"日志文件"
				Shell logshell = new Shell();
				logshell.setSize(586, 422);
				final int  point_x=(kit.getScreenSize().width - 586) / 2;
				final int  point_y=(kit.getScreenSize().height - 422) / 2;
				logshell.setLocation(point_x, point_y);
				logshell.setText("日志文件");
				Text logText = new Text(logshell, SWT.BORDER|SWT.V_SCROLL|SWT.READ_ONLY|SWT.WRAP);
				logText.setBounds(0, 0, 578, 388);
				String FileName="./src/config/log.txt";
		        File myFile=new File(FileName);
		        if(!myFile.exists())
		        { 
		            System.err.println("Can't Find " + FileName);
		        }
		        String result = null;
		        try 
		        {
		            BufferedReader in = new BufferedReader(new FileReader(myFile));
		            String str;
		            while ((str = in.readLine()) != null) 
		            {
		                  System.out.println(str);
		                  result=result+str+"\n";
		                  
		            }
		            in.close();
		        } 
		        catch (IOException e1) 
		       {
		            e1.getStackTrace();
		        }

		        logText.setText(result);
		        logshell.open();
			}
		});

		new MenuItem(menu_4, SWT.SEPARATOR);

		final MenuItem newItemMenuItem_4 = new MenuItem(menu_4, SWT.NONE);

⌨️ 快捷键说明

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