📄 creatpgwin.java
字号:
package com.cn.darkblue.window;
import net.jxta.discovery.DiscoveryService;
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.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.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.cn.darkblue.helper.GroupHelper;
import com.cn.darkblue.helper.IPGResource;
import com.cn.darkblue.helper.PGResource;
import com.cn.darkblue.util.CFDefData;
import com.cn.darkblue.util.CFResource;
import com.cn.darkblue.util.CFUtil;
import com.cn.darkblue.util.SysUtil;
public class CreatPGWin extends CFShell{
private Text tID;
private static final Log log = LogFactory.getLog(CreatPGWin.class);
private Text tPsw;
private Text tUser;
private Combo combo;
private Text tDes;
private Text tName;
public CreatPGWin(Shell shell,int style){
this(shell.getDisplay(),style);
}
public CreatPGWin(Display display, int style) {
super(display, style);
setSize(300, 210);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
setLayout(gridLayout);
creatPanel();
}
private void creatPanel(){
final Label label = new Label(this, SWT.NONE);
label.setText(" 组名称: ");
tName = new Text(this, SWT.BORDER);
final GridData gd_tName = new GridData(SWT.FILL, SWT.CENTER, true, false);
tName.setLayoutData(gd_tName);
final Label label_5 = new Label(this, SWT.NONE);
label_5.setText(" 组 ID:");
tID = new Text(this, SWT.BORDER);
final GridData gd_tID = new GridData(SWT.FILL, SWT.CENTER, true, false);
tID.setLayoutData(gd_tID);
final Label label_1 = new Label(this, SWT.NONE);
label_1.setText(" 组描述: ");
tDes = new Text(this, SWT.BORDER);
final GridData gd_tDes = new GridData(SWT.FILL, SWT.CENTER, true, false);
tDes.setLayoutData(gd_tDes);
final Label label_2 = new Label(this, SWT.NONE);
label_2.setText(" 父 组*: ");
combo = new Combo(this, SWT.NONE);
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
combo.setItems(CFUtil.getPGNameIDs());
final Label label_3 = new Label(this, SWT.NONE);
label_3.setText(" 创建者: ");
tUser = new Text(this, SWT.BORDER);
final GridData gd_tUser = new GridData(SWT.FILL, SWT.CENTER, true, false);
tUser.setLayoutData(gd_tUser);
final Label label_4 = new Label(this, SWT.NONE);
label_4.setText(" 授权码: ");
tPsw = new Text(this, SWT.BORDER | SWT.PASSWORD);
final GridData gd_tPsw = new GridData(SWT.FILL, SWT.CENTER, true, false);
tPsw.setLayoutData(gd_tPsw);
final Composite composite = new Composite(this, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
final GridLayout gridLayout_1 = new GridLayout();
gridLayout_1.numColumns = 4;
composite.setLayout(gridLayout_1);
final Button button = new Button(composite, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
doCreat();
}
});
button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 3, 1));
button.setText(" 确定 ");
final Button button_1 = new Button(composite, SWT.NONE);
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
exit();
}
});
button_1.setText(" 退出 ");
new Label(this, SWT.NONE);
}
private void doCreat(){
String id = tID.getText();
String name = tName.getText();
String pId = combo.getText();
String user = tUser.getText();
String psw = tPsw.getText();
String description = tDes.getText();
if(pId==null || "".equals(pId)){
MessageDialog.openInformation(SysUtil.getSysShell()," 温馨提示 "," 请选择创建组所基于的父组 ");
combo.setFocus();
return ;
}
pId = SysUtil.getComboDescription(pId);
log.info(" 父组ID is : "+pId);
PeerGroup pg = CFResource.getInstance().getCachePeerGroup(pId);
if(pg!=null){
PeerGroup newPg = null;
try{
if(id==null || "".equals(id)){
newPg = new GroupHelper().createPeerGroup(pg, name, user, psw,description);
}else{
newPg = new GroupHelper().createPeerGroup(pg,id, name, user, psw,description);
}
System.out.println(newPg.getPeerGroupAdvertisement().getDocument(MimeMediaType.XMLUTF8).toString());
System.out.println(newPg.getAllPurposePeerGroupImplAdvertisement().getDocument(MimeMediaType.XMLUTF8).toString());
}catch(Exception eeee){
log.error(" 无法创建组: " + eeee.toString());
MessageDialog.openInformation(SysUtil.getSysShell()," 温馨提示 "," 组无法创建,请查看日志 ");
eeee.printStackTrace();
return;
}
if(newPg!=null){
/*
log.info("父组Peer名称:"+pg.getPeerName());
log.info("父组名称:"+pg.getPeerGroupName());
log.info("父组Peer ID:"+pg.getPeerID());
log.info("父组ID:"+pg.getPeerGroupID());
log.info("_________________________________");
log.info("组Peer名称:"+newPg.getPeerName());
log.info("组名称:"+newPg.getPeerGroupName());
log.info("组Peer ID:"+newPg.getPeerID());
log.info("组ID:"+newPg.getPeerGroupID());
*/
DiscoveryService discoSvc = pg.getDiscoveryService();
CFUtil.publishObject(discoSvc, newPg);
CFResource.getInstance().getGroupCache().add(newPg);
CFResource.getInstance().getMUIControl().addEntity(newPg);
CFResource.getInstance().getMUIControl().uiRefresh();
GroupHelper helper = new GroupHelper();
helper.joinPeerGroup(newPg, "sa","as");
IPGResource pgres = (IPGResource)CFResource.getInstance().getJoinPGMap().get(newPg);
if(pgres==null){
pgres = new PGResource();
CFResource.getInstance().getJoinPGMap().put(newPg, pgres);
}
//MessageDialog.openInformation(SysUtil.getSysShell(),"温馨提示��ܰ��ʾ","组已成功创建");
}
}else{
MessageDialog.openInformation(SysUtil.getSysShell()," 温馨提示 "," 无法找到指定的父组 ");
this.setActive();
return;
}
exit();
}
public void exit(){
close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -