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

📄 filesynchronaldialog.java

📁 Java SWT代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com;
 
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
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.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
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.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;

import util.Dialog;

import com.swtdesigner.SWTResourceManager;

/**
 * 
 * @author NJ
 *
 */
public class FileSynchronalDialog {

	private Shell sShell = null;
	private Tree treePc;
	private Tree treeMobile;
	
	private Map<String,String> mapFileNameAndPathPc=new LinkedHashMap<String, String>();
	private Map<String,String> mapFileNameAndPathMobile=new LinkedHashMap<String, String>();
	
	private List<String> listRootFile=new ArrayList<String>();
	
	private Tree actionTree;
	private ToolItem tolSetFile;
	private ToolItem tolDel;
	private ToolItem tolSetDirectory;
	private ToolItem tolSetCorresponding;
	private Text textName;
	private Text textFileName;
	private Table tableProrertiesFile;
	private TabFolder tabFolder;
 

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Display display = Display.getDefault();
		FileSynchronalDialog thisClass = new FileSynchronalDialog();
		thisClass.createSShell();
		thisClass.sShell.open();

		while (!thisClass.sShell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

	/**
	 * This method initializes sShell
	 */
	private void createSShell() {
		sShell = new Shell();
		sShell.setText("文件同步");
		
		int x=Display.getDefault().getBounds().width ;
		int y=Display.getDefault().getBounds().height-40;
		
		sShell.setSize(new Point(x, y));
		sShell.setMaximized(true);
		sShell.setLayout(new FillLayout());
		 
		sShell.setImage(SWTResourceManager.getImage(FileSynchronalDialog.class,"/resource/Mac_file.png"));
		 
		tabFolder=new TabFolder(sShell,SWT.NONE);
		
		TabItem tabItem=new TabItem(tabFolder,SWT.NONE);
		tabItem.setText("选择配置文件");
		
		Composite composite=new Composite(tabFolder,SWT.NONE);
		tabItem.setControl(composite);
		composite.setLayout(new FillLayout());
		
		createTabItemInit(composite);
		
		TabItem tabItem1=new TabItem(tabFolder,SWT.NONE);
		tabItem1.setText("同步源->目标");
		
		Composite composite1=new Composite(tabFolder,SWT.NONE);
		tabItem1.setControl(composite1);
		composite1.setLayout(new FillLayout());
		
		createTabItemComp(composite1);
		
		tabFolder.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doTabFolderSeleced();
			}
		});
		
		initData();
		treePc.notifyListeners(SWT.FocusIn, new Event());
	}
	

	private void createTabItemComp(Composite composite1) {
		SashForm sashForm=new SashForm(composite1,SWT.VERTICAL);
		
		SashForm sashTree=new SashForm(sashForm,SWT.HORIZONTAL);
		
		Group compositePc=new Group(sashTree,SWT.NONE);
		compositePc.setText("同步源");
		compositePc.setLayout(new FillLayout());
		
		treePc=getTree(compositePc);
		
		treePc.addFocusListener(new FocusAdapter(){

			public void focusGained(FocusEvent e) {
				actionTree=treePc;
				/*tolSetFile.setText("设置PC同步文件");
				tolSetDirectory.setText("设置PC同步目录");
				tolSetCorresponding.setText("设置PC对应路径");*/
			} 
		});
		
		Group compositeMobile=new Group(sashTree,SWT.NONE);
		compositeMobile.setText("目标");
		compositeMobile.setLayout(new FillLayout()); 
		
		treeMobile=getTree(compositeMobile);
		
		treeMobile.addFocusListener(new FocusAdapter(){

			public void focusGained(FocusEvent e) {
				actionTree=treeMobile;
				/*tolSetFile.setText("设置Mobile同步文件");
				tolSetDirectory.setText("设置Mobile同步目录");
				tolSetCorresponding.setText("设置Mobile对应路径");*/
			} 
			
		});
		
		sashTree.setWeights(new int[]{1,1});
		
		Group groupButton=new Group(sashForm,SWT.NONE);
		groupButton.setLayout(new FillLayout());
		
		ToolBar tolBar=new ToolBar(groupButton,SWT.PUSH);
		
		ToolItem tolComp=new ToolItem(tolBar,SWT.RIGHT | SWT.BORDER);
		tolComp.setText("读取差异");
		tolComp.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnComp();
			}
		});
		
		ToolItem tolSynchronal=new ToolItem(tolBar,SWT.RIGHT | SWT.BORDER);
		tolSynchronal.setText("同步");
		tolSynchronal.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnSynchronal(false);
			}
		});
		
		ToolItem tolSynchronalAll=new ToolItem(tolBar,SWT.RIGHT | SWT.BORDER);
		tolSynchronalAll.setText("同步(包括隐藏文件)");
		tolSynchronalAll.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnSynchronal(true);
			}
		});

		
		tolComp=new ToolItem(tolBar,SWT.SEPARATOR | SWT.BORDER);
		tolComp=new ToolItem(tolBar,SWT.SEPARATOR | SWT.BORDER);
		
		tolSetFile=new ToolItem(tolBar,SWT.RIGHT | SWT.BORDER);
		tolSetFile.setText("设置同步源文件");
		tolSetFile.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnSetFile();
			}
		});
		
		tolSetDirectory=new ToolItem(tolBar,SWT.RIGHT | SWT.BORDER);
		tolSetDirectory.setText("设置同步源目录");
		tolSetDirectory.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnSetDirectory();
			}
		});
		
		tolSetCorresponding=new ToolItem(tolBar,SWT.RIGHT | SWT.BORDER);
		tolSetCorresponding.setText("设置同步目标路径");
		tolSetCorresponding.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnSetCorresponding();
			}
		});
		
		tolDel=new ToolItem(tolBar,SWT.RIGHT | SWT.BORDER);
		tolDel.setText("删除");
		tolDel.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnDel();
			}
		});
		
		sashForm.setWeights(new int[]{9,1});
	} 

	private void createTabItemInit(Composite composite) {
		SashForm sashForm=new SashForm(composite,SWT.VERTICAL);
		
		tableProrertiesFile=new Table(sashForm,SWT.FULL_SELECTION|SWT.MULTI|SWT.CHECK);
		tableProrertiesFile.setHeaderVisible(true);
		
		TableColumn tableColumn=new TableColumn(tableProrertiesFile,SWT.NONE);
		tableColumn.setText("序号");
		tableColumn.setWidth(60);
		
		tableColumn=new TableColumn(tableProrertiesFile,SWT.NONE);
		tableColumn.setText("名称");
		tableColumn.setWidth(100);
		
		tableColumn=new TableColumn(tableProrertiesFile,SWT.NONE);
		tableColumn.setText("文件名");
		tableColumn.setWidth(300);
		
		tableColumn=new TableColumn(tableProrertiesFile,SWT.NONE);
		tableColumn.setText("路径");
		tableColumn.setWidth(500);
		
		tableProrertiesFile.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doTableProrertiesFileSelectedAction();
			}
		});
		
		Group group=new Group(sashForm,SWT.NONE);
		
		group.setLayout(new GridLayout(7,false));
		
		Label lblName=new Label(group,SWT.NONE);
		lblName.setText("名称");
		
		textName=new Text(group,SWT.BORDER);
		textName.setLayoutData(new GridData(100,SWT.DEFAULT));
		
		textName.addModifyListener(new ModifyListener(){
			public void modifyText(ModifyEvent e) {
				textFileName.setText(textName.getText()+".properties");
			}
		});
		
		Label lblFileName=new Label(group,SWT.NONE);
		lblFileName.setText("文件名");
		
		textFileName=new Text(group,SWT.BORDER);
		textFileName.setEditable(false);
		textFileName.setLayoutData(new GridData(200,SWT.DEFAULT));
		
		Button btnSave=new Button(group,SWT.NONE);
		btnSave.setText("新增");
		
		btnSave.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnAddProrertiesFile();
			}
		});
		
		Button btnDel=new Button(group,SWT.NONE);
		btnDel.setText("删除");
		
		btnDel.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e) {
				doBtnDelProrertiesFile();
			}
		});
		
		Label lblInfo=new Label(group,SWT.NONE);
		lblInfo.setText("默认选中initPc2Mobile与initMobile2Pc。");
		
		sashForm.setWeights(new int[]{8,1});
		
		initPropertiesFile();
	}

	protected void doTableProrertiesFileSelectedAction() {
		if(tableProrertiesFile.getSelectionCount()>0){
			TableItem tableItemSelect=tableProrertiesFile.getSelection()[0];
			Boolean checked=tableItemSelect.getChecked();
			for (int i = 0; i < tableProrertiesFile.getItems().length; i++) {
				TableItem tableItem=tableProrertiesFile.getItems()[i];

				String strKeySelect=tableItemSelect.getText(1);
				
				strKeySelect=strKeySelect.replaceAll(InitProperties.KEY_MOBILE2PC, "");
				strKeySelect=strKeySelect.replaceAll(InitProperties.KEY_PC2MOBILE, "");
				
				String strKey=tableItem.getText(1);
				
				strKey=strKey.replaceAll(InitProperties.KEY_MOBILE2PC, "");
				strKey=strKey.replaceAll(InitProperties.KEY_PC2MOBILE, "");
				
				if(strKey.equals(strKeySelect)){
					tableItem.setChecked(checked);
					if(checked){
						if(tableItem.getText(2).indexOf(InitProperties.KEY_PC2MOBILE)>=0){
							InitProperties.TYPE_PC2MOBILE_ACTIVE=tableItem.getText(2);
						}else if(tableItem.getText(2).indexOf(InitProperties.KEY_MOBILE2PC)>=0){

⌨️ 快捷键说明

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