怎样自动跳到下一列而且处于编辑壮态? 我是用Table 和 CellEditor写的
俱体代码如下,能不能指点一下?
package com.hnjchina.example.editors;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.part.EditorPart;
import com.hnjchina.securityManager.SecurityObject;
import com.hnjchina.securityManager.SecurityObjectCellModifier;
import com.hnjchina.securityManager.SecurityObjectContentProvider;
import com.hnjchina.securityManager.SecurityObjectEditor;
import com.hnjchina.securityManager.SecurityObjectLabelProvider;
public class SecurityObjectsEditors extends EditorPart{
private TableViewer tv;
private Table table;
public SecurityObjectEditor security=new SecurityObjectEditor();
private Action addItemAction,deleteItemAction;
public void createPartControl(Composite parent) {
GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_BOTH);
parent.setLayoutData (gridData);
GridLayout layout = new GridLayout(3, false);
layout.marginWidth = 7;
parent.setLayout (layout);
createTable(parent);
createTableViewer();
}
private void createTable(Composite parent) {
int style = SWT.SINGLE|SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION|SWT.HIDE_SELECTION;
table = new Table(parent, style);
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.grabExcessVerticalSpace = true;
gridData.horizontalSpan = 3;
table.setLayoutData(gridData);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn column = new TableColumn(table, SWT.LEFT,0);
column.setText("Application");
column.setWidth(80);
column=new TableColumn(table, SWT.LEFT,1);
column.setText("ObjectName");
column.setWidth(180);
column=new TableColumn(table, SWT.LEFT,2);
column.setText("Description");
column.setWidth(200);
column=new TableColumn(table, SWT.LEFT,3);
column.setText("ObjectType");
column.setWidth(80);
}
private void createTableViewer(){
tv = new TableViewer(table);
tv.setContentProvider(new SecurityObjectContentProvider());
tv.setLabelProvider(new SecurityObjectLabelProvider());
CellEditor[] editors = new CellEditor[4];
editors[0] = new ComboBoxCellEditor(table,security.getApplictArray(), SWT.READ_ONLY);
editors[1] = new TextCellEditor(table);
editors[2] = new TextCellEditor(table);
editors[3] = new TextCellEditor(table);
tv.setColumnProperties(SecurityObjectEditor.PROPS);
tv.setCellModifier(new SecurityObjectCellModifier(tv));
tv.setCellEditors(editors);
tv.setInput(security.getObject());
addItem();
addItem();
addItem();
}
private void addItem(){
SecurityObject p = new SecurityObject();
p.setApplicat("Application");
p.setObjectName("ObjectName");
p.setDescription("Description");
p.setObjectType("ObjectType");
security.getObject().add(p);
tv.refresh();
}
public String[] getChoices(String property) {
if ("Application".equals(property))
return security.getApplictArray();
else
return new String[]{};
}
public void setFocus() {}
public void doSave(IProgressMonitor monitor) {}
public void doSaveAs() { }
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
}
public boolean isDirty() {return false;}
public boolean isSaveAsAllowed() {return false;}
}
package com.hnjchina.securityManager;
public class SecurityObject{
private String applicat;
private String objectName;
private String description;
private String objectType;
public String getApplicat(){return applicat;}
public void setApplicat(String applicat){this.applicat=applicat;}
public String getObjectName(){return objectName;}
public void setObjectName(String objectName){this.objectName=objectName;}
public String getDescription(){return description;}
public void setDescription(String description){this.description=description;}
public String getObjectType(){return objectType;}
public void setObjectType(String objectType){this.objectType=objectType;}
}
package com.hnjchina.securityManager;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.widgets.Item;
import com.hnjchina.example.editors.SecurityObjectsEditors;
public class SecurityObjectCellModifier implements ICellModifier {
private Viewer viewer;
private SecurityObjectsEditors editors=new SecurityObjectsEditors();
public SecurityObjectCellModifier(Viewer viewer){this.viewer=viewer;}
public boolean canModify(Object element, String property) {
return true;
}
public Object getValue(Object element, String property) {
Object result = null;
SecurityObject p = (SecurityObject) element;
if (SecurityObjectEditor.APPLICATION.equals(property)){
String stringValue = p.getApplicat();
String[] choices = editors.getChoices(property);
int i = choices.length - 1;
while (!stringValue.equals(choices[i]) && i > 0)
--i;
result = new Integer(i);
}
else if (SecurityObjectEditor.OBJECTNAME.equals(property))
result=p.getObjectName();
else if (SecurityObjectEditor.DESCRIPTION.equals(property))
result=p.getDescription();
else if (SecurityObjectEditor.OBJECTTYPE.equals(property))
result=p.getObjectType();
return result;
}
public void modify(Object element, String property, Object value) {
String valueString;
if (element instanceof Item) element = ((Item)element).getData();
SecurityObject p=(SecurityObject)element;
if (SecurityObjectEditor.APPLICATION.equals(property)){
valueString = editors.getChoices(property)[((Integer) value).intValue()].trim();
if (!p.getApplicat().equals(valueString)) {
p.setApplicat(valueString);
}
}
else if (SecurityObjectEditor.OBJECTNAME.equals(property))
p.setObjectName((String)value);
else if (SecurityObjectEditor.DESCRIPTION.equals(property))
p.setDescription((String)value);
else if (SecurityObjectEditor.OBJECTTYPE.equals(property));
p.setObjectType((String)value);
viewer.refresh();
}
}
package com.hnjchina.securityManager;
import java.util.List;
import org.eclipse.jface.viewers.*;
public class SecurityObjectContentProvider implements IStructuredContentProvider{
public Object[] getElements(Object inputElement) {
return ((List) inputElement).toArray();
}
public void dispose() {}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
}
package com.hnjchina.securityManager;
import java.util.*;
public class SecurityObjectEditor{
public static final String APPLICATION="Application";
public static final String OBJECTNAME="ObjectName";
public static final String DESCRIPTION="Description";
public static final String OBJECTTYPE="ObjectType";
public static final String[] PROPS= { APPLICATION,OBJECTNAME,DESCRIPTION,OBJECTTYPE};
static final String[] APPLICAT_ARRAY = { "Applicat", "Master", "hnpfc", "hkpfc" };
public List object;
public SecurityObjectEditor() {
object = new ArrayList();
}
public List getObject(){
return object;
}
public String[] getProps(){
return PROPS;
}
public String[] getApplictArray(){
return APPLICAT_ARRAY;
}
}
package com.hnjchina.securityManager;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.graphics.Image;
public class SecurityObjectLabelProvider implements ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) {return null;}
public String getColumnText(Object element, int columnIndex) {
SecurityObject securityobject = (SecurityObject) element;
switch (columnIndex) {
case 0:
return securityobject.getApplicat();
case 1:
return securityobject.getObjectName();
case 2:
return securityobject.getDescription();
case 3:
return securityobject.getObjectType();
}
return null;
}
public void addListener(ILabelProviderListener listener) {}
public void dispose() {}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {}
}