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

📄 checkcurrentpgwin.java

📁 CoolFace是基于jxta的P2P系统
💻 JAVA
字号:
package com.cn.darkblue.window;

import java.util.ArrayList;
import java.util.HashMap;

import net.jxta.document.MimeMediaType;
import net.jxta.peergroup.PeerGroup;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

import com.cn.darkblue.entity.ICFView;
import com.cn.darkblue.helper.GroupHelper;
import com.cn.darkblue.helper.IPGResource;
import com.cn.darkblue.helper.PGResource;
import com.cn.darkblue.job.DiscoverPGJob;
import com.cn.darkblue.job.DiscoverPeerJob;
import com.cn.darkblue.prov.CFAsynContentProvider;
import com.cn.darkblue.prov.CFSynContentProvider;
import com.cn.darkblue.prov.CFViewLabelProvider;
import com.cn.darkblue.util.CFResource;
import com.cn.darkblue.util.CFUtil;
import com.cn.darkblue.util.SysUtil;

public class CheckCurrentPGWin extends CFShell{
	private static final Log log = LogFactory.getLog(CheckCurrentPGWin.class);
	
	private CheckboxTableViewer checkboxTableViewer_1;
	private CheckboxTableViewer checkboxTableViewer;
	private Table table_1;
	private Table table;
	public CheckCurrentPGWin(Shell shell,int style){
		this(shell.getDisplay(),style);
		
	}
	public CheckCurrentPGWin(Display display, int style) {
		super(display, style);
		 creatPanel();
	}
	
	private void creatPanel(){
		final Composite composite = new Composite(this, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		final GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 3;
		composite.setLayout(gridLayout);

		checkboxTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.FULL_SELECTION | SWT.BORDER);
		checkboxTableViewer.setContentProvider(new CFAsynContentProvider());
		checkboxTableViewer.setLabelProvider(new CFViewLabelProvider());
		table = checkboxTableViewer.getTable();
		table.setHeaderVisible(true);
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		final TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);
		newColumnTableColumn.setWidth(100);
		newColumnTableColumn.setText(" 当前操作组 ");

		final TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);
		newColumnTableColumn_1.setWidth(100);
		newColumnTableColumn_1.setText(" 组ID ");

		final TableColumn newColumnTableColumn_2 = new TableColumn(table, SWT.NONE);
		newColumnTableColumn_2.setWidth(100);
		newColumnTableColumn_2.setText(" 组描述 ");

		final TableColumn newColumnTableColumn_3 = new TableColumn(table, SWT.NONE);
		newColumnTableColumn_3.setWidth(100);
		newColumnTableColumn_3.setText(" 父组 ");

		final Group group = new Group(composite, SWT.NONE);
		group.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true));
		group.setLayout(new GridLayout());

		final Button btAdd = new Button(group, SWT.NONE);
		btAdd.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				
				ArrayList list = (ArrayList)checkboxTableViewer_1.getInput();
				int index = table_1.getSelectionIndex();
				if(index==-1) return;
				
				ICFView ve = (ICFView)list.get(index);
				PeerGroup findPg = (PeerGroup)ve.getTarget();

				IPGResource pgres = (IPGResource)CFResource.getInstance().getJoinPGMap().get(findPg);
				if(pgres==null){
					pgres = new PGResource();
					CFResource.getInstance().getJoinPGMap().put(findPg, pgres);
				}
				
				
				if(!CFResource.getInstance().getMUIControl().getViewData().contains(findPg)){
					GroupHelper helper = new GroupHelper();
					helper.joinPeerGroup(findPg, "sa","as");
					
					CFResource.getInstance().getMUIControl().addEntity(findPg);
					checkboxTableViewer.setInput(CFResource.getInstance().getMUIControl().getViewData());
					CFResource.getInstance().getMUIControl().uiRefresh();
					log.info(" 已经成功加入组:ID="+findPg.getPeerGroupID()+" Name="+findPg.getPeerName());
				}else{
					log.info(" 组:ID= "+findPg.getPeerGroupID()+" Name="+findPg.getPeerName()+" 已在当前操作列表中 ");
					MessageDialog.openInformation(SysUtil.getSysShell()," 温馨提示 "," 组:ID= "+findPg.getPeerGroupID()+" Name="+findPg.getPeerName()+" 已在当前操作列表中");
				}
				HashMap map = new HashMap();
				CFUtil.seatchPeer(findPg, map);
			}
		});
		final GridData gd_btAdd = new GridData(25, SWT.DEFAULT);
		btAdd.setLayoutData(gd_btAdd);
		btAdd.setText("<");

		final Button btRmv = new Button(group, SWT.NONE);
		btRmv.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				ArrayList list = (ArrayList)checkboxTableViewer.getInput();
				int index = table.getSelectionIndex();
				if(index==-1) return;
				PeerGroup findPg = (PeerGroup)list.get(index);
				CFResource.getInstance().getMUIControl().removeEntity(findPg);
				checkboxTableViewer.setInput(CFResource.getInstance().getMUIControl().getViewData());
			}
		});
		final GridData gd_btRmv = new GridData(25, SWT.DEFAULT);
		btRmv.setLayoutData(gd_btRmv);
		btRmv.setText(">");

		checkboxTableViewer_1 = CheckboxTableViewer.newCheckList(composite, SWT.FULL_SELECTION | SWT.BORDER);
		checkboxTableViewer_1.setContentProvider(new CFAsynContentProvider());
		checkboxTableViewer_1.setLabelProvider(new CFViewLabelProvider());
		table_1 = checkboxTableViewer_1.getTable();
		table_1.setHeaderVisible(true);
		table_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		final TableColumn newColumnTableColumn_4 = new TableColumn(table_1, SWT.NONE);
		newColumnTableColumn_4.setWidth(100);
		newColumnTableColumn_4.setText(" 当前查询组 ");

		final TableColumn newColumnTableColumn_7 = new TableColumn(table_1, SWT.NONE);
		newColumnTableColumn_7.setWidth(100);
		newColumnTableColumn_7.setText(" 组ID ");

		final TableColumn newColumnTableColumn_6 = new TableColumn(table_1, SWT.NONE);
		newColumnTableColumn_6.setWidth(100);
		newColumnTableColumn_6.setText(" 组描述 ");

		final TableColumn newColumnTableColumn_5 = new TableColumn(table_1, SWT.NONE);
		newColumnTableColumn_5.setWidth(100);
		newColumnTableColumn_5.setText(" 父组 ");

		final Composite composite_1 = new Composite(this, SWT.NONE);
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		final GridLayout gridLayout_1 = new GridLayout();
		gridLayout_1.numColumns = 7;
		composite_1.setLayout(gridLayout_1);

		final Button button = new Button(composite_1, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Object[] objs = checkboxTableViewer_1.getCheckedElements();
				
				if(objs.length>0){
					ICFView entity;
					PeerGroup pg;

					for(int i=0;i<objs.length;i++){
						entity = (ICFView)objs[i];
						pg = (PeerGroup)entity.getTarget();
						CFUtil.publishObject(pg.getParentGroup().getDiscoveryService(), pg.getPeerGroupAdvertisement());
						System.out.println(pg.getPeerGroupAdvertisement().getDocument(MimeMediaType.XMLUTF8));
					}
					
				}
			}
		});
		button.setText("发布组广告");

		final Button btExit = new Button(composite_1, SWT.NONE);
		btExit.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				exit();
			}
		});
		final GridData gd_btExit = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
		btExit.setLayoutData(gd_btExit);
		btExit.setText(" 退出 ");
		setText("私聊");
		setSize(600, 250);
		
		bindValue();
	}
	
	private void bindValue(){
		checkboxTableViewer.setInput(CFResource.getInstance().getMUIControl().getViewData());
		checkboxTableViewer_1.setInput(CFUtil.getPGViews(CFResource.getInstance().getGroupCache()));
	}
	
	public void exit(){
		close();
	}

}

⌨️ 快捷键说明

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