Autocomplete 要在SWT的树编辑器中的Ccombo框中选择多个项目吗
在树查看器中,我有五列,除了第一列之外,我在树编辑器的帮助下使用cmbo框。现在在cmbo框中,我需要选择所有项目。怎么可能呢?请在我的视图中找到以下CCOMBOX的代码实现:Autocomplete 要在SWT的树编辑器中的Ccombo框中选择多个项目吗,autocomplete,eclipse-plugin,swt,eclipse-rcp,ccombo,Autocomplete,Eclipse Plugin,Swt,Eclipse Rcp,Ccombo,在树查看器中,我有五列,除了第一列之外,我在树编辑器的帮助下使用cmbo框。现在在cmbo框中,我需要选择所有项目。怎么可能呢?请在我的视图中找到以下CCOMBOX的代码实现: final CCombo comboForRunOn = new CCombo(remoteTable, SWT.READ_ONLY); comboForRunOn.setItems(remoteComputerIPs); /*Exe Type - WINDOWS, ANDROID*/ final CCombo com
final CCombo comboForRunOn = new CCombo(remoteTable, SWT.READ_ONLY);
comboForRunOn.setItems(remoteComputerIPs);
/*Exe Type - WINDOWS, ANDROID*/
final CCombo comboForExeType = new CCombo(remoteTable, SWT.READ_ONLY);
comboForExeType.setItems(exeTypes.toArray(new String[exeTypes.size()]));
comboForExeType.select(exeTypes.indexOf(tsTCGson.tcParams.get(1).tcparamValue));
/*Exe Type - Firefox, IE, Chrome*/
final CCombo comboForExePlatform = new CCombo(remoteTable, SWT.READ_ONLY);
comboForExePlatform.setItems(exePlatform.toArray(new String[exePlatform.size()]));
comboForExePlatform.select(exePlatform.indexOf(tsTCGson.tcParams.get(0).tcparamValue));
TreeEditor editorForRunOn = new TreeEditor(remoteTable);
TreeEditor editorForExeType = new TreeEditor(remoteTable);
TreeEditor editorForExePlatform = new TreeEditor(remoteTable);
editorForRunOn.setEditor(comboForRunOn, trtmTestcases, 3);
editorForExeType.setEditor(comboForExeType, trtmTestcases, 2);
editorForExePlatform.setEditor(comboForExePlatform, trtmTestcases, 1);
editorForRunOn.horizontalAlignment = SWT.LEFT;
editorForRunOn.grabHorizontal = true;
editorForExeType.horizontalAlignment = SWT.LEFT;
editorForExeType.grabHorizontal = true;
editorForExePlatform.horizontalAlignment = SWT.LEFT;
editorForExePlatform.grabHorizontal = true;
为了克服这个问题,我创建了MultiSectionCombo.java类,找到下面的代码
import java.util.Arrays;
import org.eclipse.swt.SWT;
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.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
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.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.wb.swt.SWTResourceManager;
public class MultiSelectionCombo extends Composite {
Shell shell = null;
List list = null;
Text txtCurrentSelection = null;
String[] textItems = null;
int[] currentSelection = null;
TreeItem treeItem = null;
public MultiSelectionCombo(Composite parent,TreeItem tItem, String[] items, int[] selection, int style) {
super(parent, style);
currentSelection = selection;
textItems = items;
treeItem = tItem;
init();
}
private void init() {
GridLayout layout = new GridLayout();
layout.marginBottom = 0;
layout.marginTop = 0;
layout.marginLeft = 0;
layout.marginRight = 0;
layout.marginWidth = 0;
layout.marginHeight = 0;
GridLayout gridLayout = new GridLayout();
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
setLayout(gridLayout);
txtCurrentSelection = new Text(this, SWT.READ_ONLY);
txtCurrentSelection.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
txtCurrentSelection.setLayoutData(new GridData(GridData.FILL_BOTH));
displayText();
txtCurrentSelection.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
super.mouseDown(event);
initFloatShell();
}
});
}
private void initFloatShell() {
Point p = txtCurrentSelection.getParent().toDisplay(txtCurrentSelection.getLocation());
Point size = txtCurrentSelection.getSize();
Rectangle shellRect = new Rectangle(p.x, p.y + size.y, size.x, 0);
shell = new Shell(MultiSelectionCombo.this.getShell(), SWT.NO_TRIM);
GridLayout gl = new GridLayout();
gl.marginBottom = 0;
gl.marginTop = 0;
gl.marginRight = 0;
gl.marginLeft = 0;
gl.marginWidth = 0;
gl.marginHeight = 0;
shell.setLayout(gl);
list = new List(shell, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
for (String value: textItems) {
list.add(value);
}
list.setSelection(currentSelection);
GridData gd = new GridData(GridData.FILL_BOTH);
list.setLayoutData(gd);
shell.setSize(shellRect.width, 100);
shell.setLocation(shellRect.x, shellRect.y);
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent event) {
super.mouseUp(event);
currentSelection = list.getSelectionIndices();
if ((event.stateMask & SWT.CTRL) == 0) {
shell.dispose();
displayText();
}
}
});
shell.addShellListener(new ShellAdapter() {
public void shellDeactivated(ShellEvent arg0) {
if (shell != null && !shell.isDisposed()) {
currentSelection = list.getSelectionIndices();
displayText();
shell.dispose();
}
}
});
shell.open();
}
private void displayText() {
if (currentSelection != null && currentSelection.length > 0) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < currentSelection.length; i++) {
if (i > 0)
sb.append(", ");
sb.append(textItems[currentSelection[i]]);
}
txtCurrentSelection.setText(sb.toString());
treeItem.setText(1, sb.toString());
}
else {
txtCurrentSelection.setText("");
treeItem.setText(1,"");
}
}
public int[] getSelections() {
return this.currentSelection;
}
}
导入java.util.array;
导入org.eclipse.swt.swt;
导入org.eclipse.swt.events.MouseAdapter;
导入org.eclipse.swt.events.MouseEvent;
导入org.eclipse.swt.events.SelectionAdapter;
导入org.eclipse.swt.events.SelectionEvent;
导入org.eclipse.swt.events.ShellAdapter;
导入org.eclipse.swt.events.ShellEvent;
导入org.eclipse.swt.graphics.Point;
导入org.eclipse.swt.graphics.Rectangle;
导入org.eclipse.swt.layout.GridData;
导入org.eclipse.swt.layout.GridLayout;
导入org.eclipse.swt.widgets.Button;
导入org.eclipse.swt.widgets.Composite;
导入org.eclipse.swt.widgets.Display;
导入org.eclipse.swt.widgets.List;
导入org.eclipse.swt.widgets.Shell;
导入org.eclipse.swt.widgets.Text;
导入org.eclipse.swt.widgets.TreeItem;
导入org.eclipse.wb.swt.SWTResourceManager;
公共类MultiSelectionCombo扩展了复合{
Shell=null;
List=null;
Text txtCurrentSelection=null;
字符串[]textItems=null;
int[]currentSelection=null;
TreeItem TreeItem=null;
公共MultiSelectionCombo(复合父项、树项、字符串[]项、int[]选择、int样式){
超级(父母,风格);
当前选择=选择;
text项目=项目;
treeItem=滴度;
init();
}
私有void init(){
GridLayout=新的GridLayout();
layout.marginBottom=0;
layout.marginTop=0;
layout.marginLeft=0;
layout.marginRight=0;
layout.marginWidth=0;
layout.marginHeight=0;
GridLayout=新的GridLayout();
gridLayout.marginWidth=0;
gridLayout.marginHeight=0;
setLayout(gridLayout);
txtCurrentSelection=新文本(此为SWT.READ_只读);
txtCurrentSelection.setBackground(SWTResourceManager.getColor(SWT.COLOR_-WHITE));
txtCurrentSelection.setLayoutData(新的GridData(GridData.FILL_两者));
displayText();
txtCurrentSelection.addMouseListener(新的MouseAdapter(){
@凌驾
公共void mouseDown(MouseEvent事件){
超级鼠标镇(事件);
initFloatShell();
}
});
}
私有void initFloatShell(){
点p=txtCurrentSelection.getParent().toDisplay(txtCurrentSelection.getLocation());
点大小=txtCurrentSelection.getSize();
矩形shellRect=新矩形(p.x,p.y+size.y,size.x,0);
shell=newshell(MultiSelectionCombo.this.getShell(),SWT.NO_TRIM);
GridLayout gl=新的GridLayout();
gl.marginBottom=0;
gl.marginTop=0;
gl.marginRight=0;
gl.marginLeft=0;
gl.marginWidth=0;
gl.marginHeight=0;
shell.setLayout(gl);
列表=新列表(shell,SWT.BORDER | SWT.MULTI | SWT.H|u SCROLL | SWT.V|u SCROLL);
for(字符串值:textItems){
列表。添加(值);
}
列表。设置选择(当前选择);
GridData gd=新的GridData(GridData.FILL\u二者);
列表。setLayoutData(gd);
shell.setSize(shellRect.width,100);
shell.setLocation(shellRect.x,shellRect.y);
list.addMouseListener(新的MouseAdapter(){
@凌驾
公共无效mouseUp(MouseEvent事件){
超级鼠标(事件);
currentSelection=list.GetSelectionDices();
if((event.stateMask&SWT.CTRL)==0){
shell.dispose();
displayText();
}
}
});
addShellListener(新的ShellAdapter(){
公共无效外壳已停用(外壳事件arg0){
if(shell!=null&&!shell.isDisposed()){
currentSelection=list.GetSelectionDices();
displayText();
shell.dispose();
}
}
});
shell.open();
}
私有void displayText(){
if(currentSelection!=null&¤tSelection.length>0){
StringBuffer sb=新的StringBuffer();
对于(int i=0;i0)
某人加上(“,”);
sb.追加(文本项[currentSelection[i]]);
}
txtCurrentSelection.setText(sb.toString());
treeItem.setText(1,sb.toString());
}
否则{
txtCurrentSelection.setText(“”);
treeItem.setText(1,“”);
}
}
public int[]getSelections(){
返回此.currentSelection;
}
}
而且它在代码中运行良好 CCombo不支持多选。我建议通过询问以下问题获得swt/jface支持的简单输入: