鍚戝凡鏈夌殑TreeViewer鍜孴ableViewer涓婃坊鍔犵紪杈戝姛鑳斤紝鍙互浣跨敤CellEditor鍜孋ellModifier銆?/p>
CellEditor瀹氫箟浜嗘煇涓垪琚紪杈戞椂鏄劇ず鐨勫瑙傦紝瀹冨彲浠ユ槸鏂囨湰妗嗐佷笅鎷夊垪琛ㄦ鎴栧崟閫夋錛屼篃鍙互鑷繁瀹氫箟銆?/p>
閫氬父浣跨敤鐨凜ellEditor鐨勫瓙綾誨氨鏄細CheckboxCellEditor銆丆omboBoxCellEditor鍜孴extCellEditor銆?br />CellEditor涓鑸敤鏁扮粍鏉ヤ繚瀛橈紝濡傛灉鏌愪釜鍒椾笉闇瑕佺紪杈戯紝鍒欏彲灝嗚鍒楃殑CellEditor璁句負null銆?br />褰揅ellEditor鐨勬暟緇勫畾涔夊畬鍚庯紝鍗沖彲鍒╃敤setCellEditors(CellEditor[] editors)鏂規硶灝嗚鏁扮粍璁劇疆鍒板搴旂殑TreeViewer鎴朤ableViewer涓幓銆備緥濡傦細
聽聽聽聽CellEditor[]聽cellEditors聽
=
聽
new
聽CellEditor[
5
];
聽聽聽聽cellEditors[
0
]聽
=
聽
new
聽TextCellEditor(tableViewer.getTable());
聽聽聽聽cellEditors[
1
]聽
=
聽
null
;
聽聽聽聽cellEditors[
2
]聽
=
聽
new
聽ComboBoxCellEditor(tableViewer.getTable(),聽
new
聽String[]{
"
first
"
,聽
"
second
"
,聽
"
third
"
,聽
"
forth
"
});
聽聽聽聽cellEditors[
3
]聽
=
聽
new
聽CheckboxCellEditor(tableViewer.getTable());
聽聽聽聽cellEditors[
4
]聽
=
聽
new
聽CustomizedTextCellEditor(tableViewer.getTable());
聽聽聽聽tableViewer.setCellEditors(cellEditors);
鍏朵腑CustomizedTextCellEditor鏄嚜瀹氫箟鐨凜ellEditor錛岄伩鍏嶄簡璁劇疆value鏃墮犳垚鐨勭┖鎸囬拡寮傚父銆?br />

protected聽class聽CustomizedTextCellEditor聽extends聽TextCellEditor
{

聽聽聽聽public聽CustomizedTextCellEditor(Composite聽parent)
{
聽聽聽聽聽聽聽聽super(parent);
聽聽聽聽}

聽聽聽聽protected聽void聽doSetValue(Object聽value)聽
{
聽聽聽聽聽聽聽聽if(value聽==聽null)
聽聽聽聽聽聽聽聽聽聽聽聽return;
聽聽聽聽聽聽聽聽super.doSetValue(value);
聽聽聽聽}聽聽聽聽聽聽聽聽
}
CellEditor璐熻矗澶栬錛屽畠瀵硅緙栬緫鐨勬ā鍨嬩俊鎭竴鏃犳墍鐭ャ傛墍浠face涓紩鍏ヤ簡ICellModifier鎺ュ彛錛屽皢model涓嶤ellEditor鑱旂郴鍦ㄤ竴璧楓備負浜嗙‘瀹氬湪CellModifier涓殑鍒楋紝闇瑕佸畾涔塩olumnProperties鐨凷tring[]鏁扮粍錛岀敤浠ュ尯鍒嗕笉鍚屽垪瀵瑰簲鐨勪笉鍚屽睘鎬с備嬌鐢╯etColumnProperties(String[] columnProperties)璁劇疆璇ュ睘鎬ч泦銆?/p>
ICellModifier瀹氫箟浜嗕笁涓帴鍙f柟娉曪細
public boolean canModify(Object element, String property);
璇ユ柟娉曞垽鏂綍鏃惰鍒楀彲浠ヨ緙栬緫銆傚叾涓璭lement鏄搴旂殑model銆傝繑鍥瀟rue琛ㄧず姝ゆ椂璇ュ垪鍙互琚紪杈戙?/p>
public Object getValue(Object element, String property);
璇ユ柟娉曚竴鑸湪activateCellEditor()鏃惰皟鐢紝鐢ㄤ簬璁懼畾CellEditor鐨勫垵濮嬪箋傚叾涓璭lement鏄搴旂殑model銆?/p>
姝ゅ铏界劧鍙互榪斿洖Object綾誨瀷鐨勫紩鐢紝浣嗘槸浣跨敤鏃墮渶灝忓績錛岀壒瀹氱殑CellEditor浠呮帴鍙楃壒瀹氱被鍨嬬殑Value銆傛瘮濡傦細
TextCellEditor瀵瑰簲String綾誨瀷鐨刅alue錛?br />ComboBoxCellEditor瀵瑰簲Integer綾誨瀷鐨刅alue錛?br />CheckBoxCellEditor瀵瑰簲Boolean綾誨瀷鐨刅alue錛?br />鑻ヨ繑鍥炰簡涓嶉傚悎鐨刅alue瀵硅薄錛屽垯浼氭姏鍑篈ssertionFailedException銆?/p>
public void modify(Object element, String property, Object value);
璇ユ柟娉曟墽琛屼繚瀛樹慨鏀廣備竴鑸湪saveEditorValue涔嬬被鐨勬柟娉曚腑璋冪敤銆傛澶勭殑element涓嶅啀鏄痬odel錛岃屾槸Item綾誨瀷鐨勫紩鐢ㄣ傚彇鐢ㄥ搴旂殑妯″瀷錛岄渶瑕佷嬌鐢?(Item) element).getData()鏂規硶銆備竴鑸澶勭殑value鍊鹼紝涔熷氨鏄綋鍓岰ellEditor鐨刅alue鍊鹼紝浣跨敤CellEditor.getValue()寰楀埌銆傚彟澶栵紝鍦ㄦ墽琛屽畬鏇存敼鍚庯紝闇瑕佸埛鏂板搴旂殑TableViewer鎴朤reeViewer錛屼嬌鍋氬嚭鐨勬洿鏂板彲瑙併?br />
org.eclipse.debug.internal.ui.elements.adapters.DefaultVariableCellModifier鏄疘CellModifier鐨勪竴涓畬鏁村疄鐜幫細
import聽org.eclipse.debug.core.DebugException;
import聽org.eclipse.debug.core.model.IVariable;
import聽org.eclipse.debug.internal.ui.DebugUIPlugin;
import聽org.eclipse.debug.internal.ui.DefaultLabelProvider;
import聽org.eclipse.debug.internal.ui.VariableValueEditorManager;
import聽org.eclipse.debug.ui.actions.IVariableValueEditor;
import聽org.eclipse.jface.viewers.ICellModifier;


/**聽*//**
聽*聽@since聽3.2
聽*
聽*/

public聽class聽DefaultVariableCellModifier聽implements聽ICellModifier聽
{
聽聽聽聽

聽聽聽聽/**//*聽(non-Javadoc)
聽聽聽聽聽*聽@see聽org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object,聽java.lang.String)
聽聽聽聽聽*/

聽聽聽聽public聽boolean聽canModify(Object聽element,聽String聽property)聽
{

聽聽聽聽聽聽聽聽if聽(VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property))聽
{

聽聽聽聽聽聽聽聽聽聽聽聽if聽(element聽instanceof聽IVariable)聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return聽((IVariable)聽element).supportsValueModification();
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽return聽false;
聽聽聽聽}


聽聽聽聽/**//*聽(non-Javadoc)
聽聽聽聽聽*聽@see聽org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object,聽java.lang.String)
聽聽聽聽聽*/

聽聽聽聽public聽Object聽getValue(Object聽element,聽String聽property)聽
{

聽聽聽聽聽聽聽聽if聽(VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property))聽
{

聽聽聽聽聽聽聽聽聽聽聽聽if聽(element聽instanceof聽IVariable)聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽IVariable聽variable聽=聽(IVariable)聽element;

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽try聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return聽DefaultLabelProvider.escapeSpecialChars(variable.getValue().getValueString());

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}聽catch聽(DebugException聽e)聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽DebugUIPlugin.log(e);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽return聽null;
聽聽聽聽}


聽聽聽聽/**//*聽(non-Javadoc)
聽聽聽聽聽*聽@see聽org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object,聽java.lang.String,聽java.lang.Object)
聽聽聽聽聽*/

聽聽聽聽public聽void聽modify(Object聽element,聽String聽property,聽Object聽value)聽
{
聽聽聽聽聽聽聽聽Object聽oldValue聽=聽getValue(element,聽property);

聽聽聽聽聽聽聽聽if聽(!value.equals(oldValue))聽
{

聽聽聽聽聽聽聽聽聽聽聽聽if聽(VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property))聽
{

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if聽(element聽instanceof聽IVariable)聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽IVariable聽variable聽=聽(IVariable)聽element;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽IVariableValueEditor聽editor聽=聽VariableValueEditorManager.getDefault().getVariableValueEditor(variable.getModelIdentifier());

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if聽(value聽instanceof聽String)聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽value聽=聽DefaultLabelProvider.encodeEsacpedChars((String)value);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if聽(editor聽!=聽null)聽
{

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if聽聽(editor.saveVariable(variable,聽(String)聽value,聽DebugUIPlugin.getShell()))聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽try聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽variable.setValue((String)聽value);

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}聽catch聽(DebugException聽e)聽
{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(),聽Messages.VariableColumnPresentation_4,聽Messages.VariableColumnPresentation_5,聽e.getStatus());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽}

}
]]>