📄 searchclusterresultwizardpage.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.search;
import java.util.List;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
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.custom.CLabel;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
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.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.IQQNode;
import edu.tsinghua.lumaqq.qq.beans.ClusterInfo;
import edu.tsinghua.lumaqq.ui.tool.UITool;
/**
* 群搜索结果页
*
* @author luma
*/
public class SearchClusterResultWizardPage extends WizardPage {
private SearchResult result;
private TableViewer viewer;
private SearchResultContentProvider provider;
private SearchWizard wizard;
private CLabel lnkInfo;
/**
* @param pageName
*/
protected SearchClusterResultWizardPage(String pageName, SearchResult r) {
super(pageName);
result = r;
setTitle(LumaQQ.getString("search.cluster.result.title"));
setMessage(LumaQQ.getString("search.cluster.result.message"));
provider = new SearchResultContentProvider(result);
}
/* (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_HORIZONTAL));
GridLayout layout = new GridLayout();
control.setLayout(layout);
UITool.setDefaultBackground(control.getBackground());
// table viewer
viewer = new TableViewer(control, SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.BORDER);
viewer.setContentProvider(provider);
viewer.setLabelProvider(new SearchResultLabelProvider());
viewer.setSorter(new SearchClusterResultSorter());
viewer.setInput(this);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
wizard.setSelectedModel(getSelected());
setPageComplete(validatePage());
}
});
Table table = viewer.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
TableColumn tc = new TableColumn(table, SWT.LEFT);
tc.setText(LumaQQ.getString("search.cluster.result.id"));
tc.setWidth(80);
tc.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
sortOn(SearchClusterResultSorter.ID);
}
});
tc = new TableColumn(table, SWT.LEFT);
tc.setText(LumaQQ.getString("search.cluster.result.name"));
tc.setWidth(250);
tc.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
sortOn(SearchClusterResultSorter.NAME);
}
});
tc = new TableColumn(table, SWT.CENTER);
tc.setText(LumaQQ.getString("search.cluster.result.creator"));
tc.setWidth(100);
tc.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
sortOn(SearchClusterResultSorter.CREATOR);
}
});
table.setHeaderVisible(true);
table.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
viewInfo();
}
});
layout = new GridLayout();
Composite c = UITool.createContainer(control, new GridData(GridData.HORIZONTAL_ALIGN_END), layout);
// 查看资料
lnkInfo = UITool.createLink(c, LumaQQ.getString("search.cluster.result.info"), null);
lnkInfo.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
viewInfo();
}
});
setControl(control);
}
/**
* 设置在什么字段上排序
*
* @param sortOn
* 排序字段ID
*/
protected void sortOn(int sortOn) {
SearchClusterResultSorter sorter = (SearchClusterResultSorter)viewer.getSorter();
if(sorter.getSortOn() == sortOn)
sorter.reverse();
else
sorter.setSortOn(sortOn);
viewer.refresh();
}
/**
* @return
* 当前选择的对象
*/
private Object getSelected() {
IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
return selection.getFirstElement();
}
/**
* 查看群组资料
*/
private void viewInfo() {
Object obj = getSelected();
if(obj == null)
MessageDialog.openInformation(getShell(), LumaQQ.getString("message.box.common.warning.title"), LumaQQ.getString("message.box.please.select.cluster"));
else if(obj instanceof ClusterInfo) {
ClusterInfo info = (ClusterInfo)obj;
ClusterModel c = new ClusterModel(info.clusterId, info.name);
c.addProperty(IQQNode.IMAGE, IconHolder.getInstance().getClusterHead(4));
c.addProperty(IQQNode.INFO, info);
wizard.getMainShell().getShellLauncher().openClusterInfoWindow(c);
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
*/
public boolean isPageComplete() {
return validatePage();
}
/**
* @return
*/
private boolean validatePage() {
return !viewer.getSelection().isEmpty();
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.WizardPage#setWizard(org.eclipse.jface.wizard.IWizard)
*/
public void setWizard(IWizard newWizard) {
super.setWizard(newWizard);
wizard = (SearchWizard)newWizard;
}
/**
* 情况result,刷新table
*/
public void reset() {
result.clear();
provider.first();
viewer.refresh();
}
/**
* 添加一页,并显示这一页
*
* @param page
*/
public void addPage(List page) {
result.addPage(page);
provider.last();
viewer.refresh();
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
if(visible && wizard.isEnterResultPage()) {
reset();
wizard.setEnd(false);
wizard.doSearch(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -