Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Combining different cell editors in one editing support
Combining different cell editors in one editing support [message #1275805] Sun, 23 March 2014 17:21 Go to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello, hope I can get some help regarding the following issue.

I have a jface table viewer with two columns. I listen to some specific EMF model instances and sort out some of their features. Via further databinding, the first column shows the name and the second column the value of these features. The second column is editable. I have extended the EditingSupport class so that I can use the EMF edit commands to set the values of features.

public class MyEditingSupport extends EditingSupport {

    Map<String, CellEditor> celleditors = new HashMap<String, CellEditor>();
	private TableViewer viewer;
	private EditingDomain editingDomain;
	
	public TaggedValueEditingSupport(TableViewer tableViewer, EditingDomain editingDomain) {
		super(tableViewer);
	    this.viewer = tableViewer;
	    new TextCellEditor(viewer.getTable());
	    this.editingDomain = editingDomain;
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		return new TextCellEditor(viewer.getTable());
	}

	@Override
	protected boolean canEdit(Object element) {
		return true;
	}

	@Override
	protected Object getValue(Object element) {
                ...
	}

	@Override
	protected void setValue(Object element, Object value) {
		...
	        viewer.update(element, null);
	}
}



The second column gets editable with the following line:

secondTableColum.setEditingSupport(new MyEditingSupport(tableViewer, getEditingDomain()));


But for now I only use simple TextCellEditors in MyEditingSupport, which is OK for String or Integer features. Now I need to support further types of features such as Boolean or Enum with ComboBoxEditors, or multi-cardinal features with a DialogBoxEditor.

The thing is that at a given time, there can be different types of features shown in the table viewer. For example, while the first cell from the second column has a String object in it, the second cell under it can have a boolean. So this leads to while the first cell can be editable with a simple TextCellEditor, for the second cell I need a ComboBoxEditor. Actually exactly like how the Eclipse Properties View handles this.

This is where I lose the track. I have no idea how I can combine these different kind of editors for various cells at the same time. For a column in a table viewer there can only be on editing support. I probably need first of all a switch-case for the objects that are in different cells of the second column and implement accordingly different editors, right? Or is there another way to achieve this?

Thanks a lot, every help will be appreciated.

Emre
Re: Combining different cell editors in one editing support [message #1397105 is a reply to message #1275805] Wed, 09 July 2014 07:52 Go to previous message
Hussein MHANNA is currently offline Hussein MHANNAFriend
Messages: 45
Registered: February 2014
Location: LAVAL
Member
Hi Emre,

You can specify the CellEditor in the method protected CellEditor getCellEditor(Object element) of your EditingSupport.

This method will be called whenever you click to edit an element.

In the parameter of this method, there is the model element so you can do an if (element instanceof XXXX) return XXXCellEditor; else ..... to return the appropriate CellEditor.


Kind Regards,

Hussein


ALL4TEC
Previous Topic:How to display the percentage text in ProgressMonitorDialog
Next Topic:Keyboard accessibility on TableViewerColumn with a combo box
Goto Forum:
  


Current Time: Fri Apr 26 15:27:11 GMT 2024

Powered by FUDForum. Page generated in 0.03656 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top