Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to create a DirectEditManager using ComboBoxCellEditor in GEF (workaround)
How to create a DirectEditManager using ComboBoxCellEditor in GEF (workaround) [message #216255] Tue, 16 May 2006 15:24
Vyacheslav Zakovyrya is currently offline Vyacheslav ZakovyryaFriend
Messages: 2
Registered: July 2009
Junior Member
I need to use ComboBoxCellEditor in direct edit in order to provide user the
ability to choose single value for entity from limited set of option.
I read through news archive but didn't find appropriate solution for my
problem - may be I'm not so patient, so I decided to create my own
workaround.

First of all - I used example which shows how to create TextCellEditor, but
the problem is that DirectEditManager creates editor by calling its
constructor which accepts object of class Composite as parameter:
------------------------------------8<------------------------------------
protected CellEditor createCellEditorOn(Composite composite) {
try {
Constructor constructor = editorType.getConstructor(new
Class[]{Composite.class});
return (CellEditor)constructor.newInstance(new Object[]{composite});
} catch (Exception e) {
return null;
}
------------------------------------8<------------------------------------
ComboBoxCellEditor (from my JFace distribution, and I suppose from yours
too) doesn't have one. I decided to subclass DirectEditManager and address
this problem:

------------------------------------8<------------------------------------
public class ComboBoxDirectEditManager extends DirectEditManager {
String[] editorValues;

Object selectedPosition;

public ComboBoxDirectEditManager(GraphicalEditPart source,
CellEditorLocator locator, String[] editorValues,
Object selectedPosition) {
super(source, CellEditor.class, locator);
this.editorValues = editorValues;
this.selectedPosition = selectedPosition;
}

protected CellEditor createCellEditorOn(Composite parent) {
ComboBoxCellEditor cellEditor = new PatchedComboBoxCellEditor(parent,
editorValues);
return cellEditor;
}

protected void initCellEditor() {
getComboBoxCellEditor().setValue(selectedPosition);
}

private ComboBoxCellEditor getComboBoxCellEditor() {
return (ComboBoxCellEditor) getCellEditor();
}
}
------------------------------------8<------------------------------------

As you can see I did not use original ComboBoxCellEditor - it doesn't become
'dirty' :-) and you Command on entity changes isn't called:
https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&a mp;id=85936
Here is a naive approach to workaround this stuff:

------------------------------------8<------------------------------------
public class PatchedComboBoxCellEditor extends ComboBoxCellEditor {

public PatchedComboBoxCellEditor(Composite parent, String[] editorValues) {
super(parent, editorValues);
}

protected void doSetValue(Object value) {
super.doSetValue(value);
fireEditorValueChanged(true, true);
}
}

------------------------------------8<------------------------------------

I'd like to ask Randy Hudson if it possible - what problem CAN be in
subclassing like this?
Thank you
Previous Topic:attach a movable label to a connection link
Next Topic:setScrollBarVisibility(true) in UML Example
Goto Forum:
  


Current Time: Sat Apr 27 01:20:37 GMT 2024

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

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

Back to the top