Topic: 求教:如何按回车自动Edit 下一列?

  Print this page

1.求教:如何按回车自动Edit 下一列? Copy to clipboard
Posted by: limeiyong
Posted on: 2005-02-02 08:48

求教:如何按回车自动Edit 下一列?

2.Re:求教:如何按回车自动Edit 下一列? [Re: limeiyong] Copy to clipboard
Posted by: kavinwang
Posted on: 2005-02-02 14:05


public class EnterPressAction extends KeyAdapter {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER){
... ...
}
}

JTextField.addkeyListener(new EnterPressAction ());

3.Re:求教:如何按回车自动Edit 下一列? [Re: limeiyong] Copy to clipboard
Posted by: kavinwang
Posted on: 2005-02-02 14:09

你也可以使用更好的方法,比如更改swing的tab键的功能。

4.Re:求教:如何按回车自动Edit 下一列? [Re: limeiyong] Copy to clipboard
Posted by: limeiyong
Posted on: 2005-02-03 08:53

怎样自动跳到下一列而且处于编辑壮态? 我是用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) {}
}

5.Re:求教:如何按回车自动Edit 下一列? [Re: limeiyong] Copy to clipboard
Posted by: kavinwang
Posted on: 2005-02-03 09:47

你问的是swt和table,我搞错了!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923