📄 memberselectwizardpage.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.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.events.FriendSelectionEvent;
import edu.tsinghua.lumaqq.events.IFriendSelectionListener;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.ui.FriendSelectShell;
import edu.tsinghua.lumaqq.ui.tool.ListContentProvider;
import edu.tsinghua.lumaqq.ui.tool.FriendQQSorter;
/**
* 成员选择类型
*
* @author luma
*/
public class MemberSelectWizardPage extends WizardPage implements IFriendSelectionListener {
private TableViewer viewer;
private FriendSelectShell fss;
private List members;
private ClusterWizard wizard;
private ClusterModel parentClusterModel;
/**
* @param pageName
*/
protected MemberSelectWizardPage(String pageName) {
super(pageName);
setTitle(LumaQQ.getString("member.select.title"));
setMessage(LumaQQ.getString("member.select.message"));
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
Composite control = new Composite(parent, SWT.NONE);
control.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = 15;
layout.verticalSpacing = 8;
control.setLayout(layout);
members = new ArrayList();
members.add(wizard.getMainShell().getMyModel());
viewer = new TableViewer(control, SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL);
viewer.setContentProvider(new ListContentProvider(members));
viewer.setLabelProvider(new FriendModelLabelProvider());
viewer.setSorter(new FriendQQSorter());
Table t = viewer.getTable();
TableColumn tc = new TableColumn(t, SWT.LEFT);
tc.setText(LumaQQ.getString("member.select.qq"));
tc.setWidth(90);
tc = new TableColumn(t, SWT.CENTER);
tc.setText(LumaQQ.getString("member.select.nick"));
tc.setWidth(150);
tc = new TableColumn(t, SWT.CENTER);
tc.setText(LumaQQ.getString("member.select.from"));
tc.setWidth(100);
t.setHeaderVisible(true);
t.setLinesVisible(false);
t.setLayoutData(new GridData(GridData.FILL_BOTH));
viewer.setInput(this);
setControl(control);
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.WizardPage#setWizard(org.eclipse.jface.wizard.IWizard)
*/
public void setWizard(IWizard newWizard) {
super.setWizard(newWizard);
this.wizard = (ClusterWizard)newWizard;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
*/
public void setVisible(boolean visible) {
if(visible) {
fss = new FriendSelectShell(getShell(), false);
fss.addFriendSelectionListener(this);
members.clear();
members.add(wizard.getMainShell().getMyModel());
viewer.refresh();
switch(wizard.getClusterType()) {
case CreateWhatWizardPage.DISCUSSION_GROUP:
fss.setClusterModel(parentClusterModel);
break;
default:
fss.setModel(wizard.getMainShell().getModel());
break;
}
}
fss.setVisible(visible);
super.setVisible(visible);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.events.FriendSelectionListener#friendSelected(edu.tsinghua.lumaqq.events.FriendSelectionEvent)
*/
public void friendSelected(FriendSelectionEvent e) {
int myQQ = wizard.getMainShell().getMyModel().getQQ();
List selected = (List)e.getSource();
int size = selected.size();
for(int i = 0; i < size; i++) {
FriendModel f = (FriendModel)selected.get(i);
if(f.getQQ() != myQQ) {
members.add(f);
}
}
viewer.refresh();
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.events.FriendSelectionListener#friendDeselected(edu.tsinghua.lumaqq.events.FriendSelectionEvent)
*/
public void friendDeselected(FriendSelectionEvent e) {
int myQQ = wizard.getMainShell().getMyModel().getQQ();
List selected = (List)e.getSource();
int size = selected.size();
for(int i = 0; i < size; i++) {
FriendModel f = (FriendModel)selected.get(i);
if(f.getQQ() != myQQ) {
members.remove(f);
}
}
viewer.refresh();
}
/**
* @return Returns the parentClusterModel.
*/
public ClusterModel getParentClusterModel() {
return parentClusterModel;
}
/**
* @param parentClusterModel The parentClusterModel to set.
*/
public void setParentClusterModel(ClusterModel parentClusterModel) {
this.parentClusterModel = parentClusterModel;
}
public List getMembers() {
return members;
}
public int[] getMemberQQArray() {
int[] ret = new int[members.size()];
for(int i = 0; i < ret.length; i++)
ret[i] = ((FriendModel)members.get(i)).getQQ();
return ret;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -