📄 clusterwizard.java
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq.ui.wizard.cluster;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.events.IQQListener;
import edu.tsinghua.lumaqq.qq.events.QQEvent;
import edu.tsinghua.lumaqq.qq.packets.in.ClusterCommandReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.out.ClusterCommandPacket;
import edu.tsinghua.lumaqq.ui.MainShell;
/**
* 创建群的wizard
*
* @author luma
*/
public class ClusterWizard extends Wizard implements INewWizard, IQQListener {
// 页名称
private static final String CREATE_WHAT = "1";
private static final String PERMANENT_CLUSTER_INFO = "2";
private static final String TEMP_CLUSTER_INFO = "3";
private static final String MEMBER_SELECT = "4";
private static final String CREATE = "5";
private MainShell main;
private boolean operating;
private String errorMessage;
private int clusterId;
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#addPages()
*/
public void addPages() {
addPage(new CreateWhatWizardPage(CREATE_WHAT));
addPage(new PermanentClusterInfoWizardPage(PERMANENT_CLUSTER_INFO));
addPage(new TempClusterInfoWizardPage(TEMP_CLUSTER_INFO));
addPage(new MemberSelectWizardPage(MEMBER_SELECT));
addPage(new CreateWizardPage(CREATE));
getShell().setImage(IconHolder.getInstance().getImage(IconHolder.icoCluster));
hookListener();
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
public boolean performFinish() {
unhookListener();
main.getShellRegistry().deregisterClusterWizard();
return true;
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#performCancel()
*/
public boolean performCancel() {
unhookListener();
main.getShellRegistry().deregisterClusterWizard();
return true;
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
*/
public IWizardPage getNextPage(IWizardPage p) {
String name = p.getName();
if(CREATE_WHAT.equals(name)) {
switch(getClusterType()) {
case CreateWhatWizardPage.PERMANENT_CLUSTER:
return getPage(PERMANENT_CLUSTER_INFO);
case CreateWhatWizardPage.MULTI_TALK:
case CreateWhatWizardPage.DISCUSSION_GROUP:
TempClusterInfoWizardPage page = (TempClusterInfoWizardPage)getPage(TEMP_CLUSTER_INFO);
page.setTempType(getClusterType());
return page;
default:
return null;
}
} else if(PERMANENT_CLUSTER_INFO.equals(name) || TEMP_CLUSTER_INFO.equals(name)) {
MemberSelectWizardPage page = (MemberSelectWizardPage)getPage(MEMBER_SELECT);
page.setParentClusterModel(getParentClusterModel());
return page;
} else if(MEMBER_SELECT.equals(name)) {
return getPage(CREATE);
} else
return null;
}
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
*/
public void init(IWorkbench arg0, IStructuredSelection arg1) {
}
/**
* @return
* MainShell
*/
public MainShell getMainShell() {
return main;
}
/**
* 初始化,传递MainShell引用
*
* @param main
*/
public void init(MainShell main) {
this.main = main;
setWindowTitle(LumaQQ.getString("cluster.title"));
setDefaultPageImageDescriptor(IconHolder.getInstance().getImageDescriptor(IconHolder.icoClusterWizard));
}
/**
* 把自己加为QQ listener
*/
private void hookListener() {
main.getClient().addQQListener(this);
}
/**
* 删除自己做为qq listener
*/
private void unhookListener() {
main.getClient().removeQQListener(this);
}
private ClusterModel getParentClusterModel() {
TempClusterInfoWizardPage page = (TempClusterInfoWizardPage)getPage(TEMP_CLUSTER_INFO);
return page.getParentClusterModel();
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#canFinish()
*/
public boolean canFinish() {
return ((CreateWizardPage)getPage(CREATE)).isPageComplete();
}
public int getClusterType() {
return ((CreateWhatWizardPage)getPage(CREATE_WHAT)).getType();
}
public List getMembers() {
return ((MemberSelectWizardPage)getPage(MEMBER_SELECT)).getMembers();
}
public int[] getMemberQQArray() {
return ((MemberSelectWizardPage)getPage(MEMBER_SELECT)).getMemberQQArray();
}
/**
* 创建群
*/
public void doCreate() {
if(isOperating())
return;
setOperating(true);
switch(getClusterType()) {
case CreateWhatWizardPage.PERMANENT_CLUSTER:
((PermanentClusterInfoWizardPage)getPage(PERMANENT_CLUSTER_INFO)).doCreate();
break;
default:
((TempClusterInfoWizardPage)getPage(TEMP_CLUSTER_INFO)).doCreate();
break;
}
setCreatePageStatus(CreateWizardPage.CREATING);
}
/**
* 设置创建页面的状态
*
* @param status
*/
public void setCreatePageStatus(int status) {
((CreateWizardPage)getPage(CREATE)).setStatus(status);
}
/**
* @return Returns the operating.
*/
public boolean isOperating() {
return operating;
}
/**
* @param operating The operating to set.
*/
public void setOperating(boolean operating) {
this.operating = operating;
}
/**
* @return Returns the clusterId.
*/
public int getClusterId() {
return clusterId;
}
/**
* @return Returns the errorMessage.
*/
public String getErrorMessage() {
return errorMessage;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.events.IQQListener#qqEvent(edu.tsinghua.lumaqq.qq.events.QQEvent)
*/
public void qqEvent(QQEvent e) {
switch(e.type) {
case QQEvent.QQ_CREATE_CLUSTER_SUCCESS:
case QQEvent.QQ_CREATE_TEMP_CLUSTER_SUCCESS:
processClusterCreateSuccess(e);
break;
case QQEvent.QQ_CREATE_CLUSTER_FAIL:
case QQEvent.QQ_CREATE_TEMP_CLUSTER_FAIL:
processClusterCreateFail(e);
break;
case QQEvent.QQ_OPERATION_TIMEOUT:
if(e.operation == QQ.QQ_CMD_CLUSTER_CMD)
processClusterCommandTimeout(e);
break;
}
}
/**
* 处理群操作超时事件
*
* @param e
*/
private void processClusterCommandTimeout(QQEvent e) {
ClusterCommandPacket packet = (ClusterCommandPacket)e.getSource();
if(packet.getSubCommand() == QQ.QQ_CLUSTER_CMD_CREATE_CLUSTER) {
main.getDisplay().syncExec(
new Runnable() {
public void run() {
setCreatePageStatus(CreateWizardPage.TIMEOUT);
setOperating(false);
}
}
);
}
}
/**
* 处理创建群失败事件
*
* @param e
*/
private void processClusterCreateFail(QQEvent e) {
final ClusterCommandReplyPacket packet = (ClusterCommandReplyPacket)e.getSource();
main.getDisplay().syncExec(
new Runnable() {
public void run() {
errorMessage = packet.errorMessage;
setCreatePageStatus(CreateWizardPage.FAILED);
setOperating(false);
}
}
);
}
/**
* 处理创建群成功事件
*
* @param e
*/
private void processClusterCreateSuccess(QQEvent e) {
final ClusterCommandReplyPacket packet = (ClusterCommandReplyPacket)e.getSource();
main.getDisplay().syncExec(
new Runnable() {
public void run() {
clusterId = packet.clusterId;
setCreatePageStatus(CreateWizardPage.CREATED);
setOperating(false);
}
}
);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -