Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Is it advisable to subclass ComboBoxCellEditor?
Is it advisable to subclass ComboBoxCellEditor? [message #315366] Wed, 09 May 2007 07:10 Go to next message
Eclipse UserFriend
Originally posted by: inliner683.gmx.de

Hello,

I am wondering if it is good advice to subclass ComboBoxCellEditor?
I read about the issues when subclassing widgets, so what would happen
to my subclass, if in next release the ComboBoxCellEditor fundamentally
changes?
In particular I want to make ComboBoxCelleditor deal with other values
than Integers.

The other way would be to write an own "SpecialComboBoxCellEditor"
dealing with my data objects.

What would you suggest? Thanks in advance.
Re: Is it advisable to subclass ComboBoxCellEditor? [message #315368 is a reply to message #315366] Wed, 09 May 2007 07:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Why don't you write a Viewer around your ComboBox? This would be the
cleanest solution and we will eventually provide such a thing in 3.4
hopefully.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=104225

Tom

inliner683 schrieb:
> Hello,
>
> I am wondering if it is good advice to subclass ComboBoxCellEditor?
> I read about the issues when subclassing widgets, so what would happen
> to my subclass, if in next release the ComboBoxCellEditor fundamentally
> changes?
> In particular I want to make ComboBoxCelleditor deal with other values
> than Integers.
>
> The other way would be to write an own "SpecialComboBoxCellEditor"
> dealing with my data objects.
>
> What would you suggest? Thanks in advance.


--
B e s t S o l u t i o n . a t EDV Systemhaus GmbH
----------------------------------------------------
tom schindl Eclipse JFace Committer
Re: Is it advisable to subclass ComboBoxCellEditor? [message #315376 is a reply to message #315368] Wed, 09 May 2007 08:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: inliner683.gmx.de

OK I looked at the ComboBoxViewerCellEditor.
Althoug i set a LabelProvider(), the box is empty (only the labels).
The returned value is correct, e.g. it returns my object which is
provided by a call to setInput() on the viewer. I don't know why the
labels are empty even if i provide a static string as label in the
labelprovider.

Nevertheless, this does do nothing other, as provide handling of custom
objects in the box via the label and content interfaces, which I wanted
to achieve by using e.g. a HashMap and implement the CellEditor
analogous to ComboBoxCellEditor, am I right?

Tom Schindl schrieb:
> Hi,
>
> Why don't you write a Viewer around your ComboBox? This would be the
> cleanest solution and we will eventually provide such a thing in 3.4
> hopefully.
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=104225
>
> Tom
>
> inliner683 schrieb:
>> Hello,
>>
>> I am wondering if it is good advice to subclass ComboBoxCellEditor?
>> I read about the issues when subclassing widgets, so what would happen
>> to my subclass, if in next release the ComboBoxCellEditor fundamentally
>> changes?
>> In particular I want to make ComboBoxCelleditor deal with other values
>> than Integers.
>>
>> The other way would be to write an own "SpecialComboBoxCellEditor"
>> dealing with my data objects.
>>
>> What would you suggest? Thanks in advance.
>
>
Re: Is it advisable to subclass ComboBoxCellEditor? [message #315382 is a reply to message #315376] Wed, 09 May 2007 09:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: inliner683.gmx.de

After investigating more in ComboBoxViewerCellEditor, i still can't
display any Labels! I set the LabelProvider and tried different
implementations and the LabelProvider which defaults to the
toString()-method.
In debug mode i can see the the method setItems is called on the
underlying Combo wiht the correct array of labels, but in the view I see
nothing. If it would work, it would fit well in my context, so
thanks for the hint so far.

But what am I missing to let it work properly?

inliner683 schrieb:
> OK I looked at the ComboBoxViewerCellEditor.
> Althoug i set a LabelProvider(), the box is empty (only the labels).
> The returned value is correct, e.g. it returns my object which is
> provided by a call to setInput() on the viewer. I don't know why the
> labels are empty even if i provide a static string as label in the
> labelprovider.
>
> Nevertheless, this does do nothing other, as provide handling of custom
> objects in the box via the label and content interfaces, which I wanted
> to achieve by using e.g. a HashMap and implement the CellEditor
> analogous to ComboBoxCellEditor, am I right?
>
> Tom Schindl schrieb:
>> Hi,
>>
>> Why don't you write a Viewer around your ComboBox? This would be the
>> cleanest solution and we will eventually provide such a thing in 3.4
>> hopefully.
>>
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=104225
>>
>> Tom
>>
>> inliner683 schrieb:
>>> Hello,
>>>
>>> I am wondering if it is good advice to subclass ComboBoxCellEditor?
>>> I read about the issues when subclassing widgets, so what would happen
>>> to my subclass, if in next release the ComboBoxCellEditor fundamentally
>>> changes?
>>> In particular I want to make ComboBoxCelleditor deal with other values
>>> than Integers.
>>>
>>> The other way would be to write an own "SpecialComboBoxCellEditor"
>>> dealing with my data objects.
>>>
>>> What would you suggest? Thanks in advance.
>>
>>
Re: Is it advisable to subclass ComboBoxCellEditor? [message #315388 is a reply to message #315382] Wed, 09 May 2007 10:05 Go to previous messageGo to next message
Eclipse UserFriend
Can you provide me a standalone easy snippet to track this down?

Tom

inliner683 schrieb:
> After investigating more in ComboBoxViewerCellEditor, i still can't
> display any Labels! I set the LabelProvider and tried different
> implementations and the LabelProvider which defaults to the
> toString()-method.
> In debug mode i can see the the method setItems is called on the
> underlying Combo wiht the correct array of labels, but in the view I see
> nothing. If it would work, it would fit well in my context, so
> thanks for the hint so far.
>
> But what am I missing to let it work properly?
>
> inliner683 schrieb:
>> OK I looked at the ComboBoxViewerCellEditor.
>> Althoug i set a LabelProvider(), the box is empty (only the labels).
>> The returned value is correct, e.g. it returns my object which is
>> provided by a call to setInput() on the viewer. I don't know why the
>> labels are empty even if i provide a static string as label in the
>> labelprovider.
>>
>> Nevertheless, this does do nothing other, as provide handling of
>> custom objects in the box via the label and content interfaces, which
>> I wanted to achieve by using e.g. a HashMap and implement the
>> CellEditor analogous to ComboBoxCellEditor, am I right?
>>
>> Tom Schindl schrieb:
>>> Hi,
>>>
>>> Why don't you write a Viewer around your ComboBox? This would be the
>>> cleanest solution and we will eventually provide such a thing in 3.4
>>> hopefully.
>>>
>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=104225
>>>
>>> Tom
>>>
>>> inliner683 schrieb:
>>>> Hello,
>>>>
>>>> I am wondering if it is good advice to subclass ComboBoxCellEditor?
>>>> I read about the issues when subclassing widgets, so what would happen
>>>> to my subclass, if in next release the ComboBoxCellEditor fundamentally
>>>> changes?
>>>> In particular I want to make ComboBoxCelleditor deal with other values
>>>> than Integers.
>>>>
>>>> The other way would be to write an own "SpecialComboBoxCellEditor"
>>>> dealing with my data objects.
>>>>
>>>> What would you suggest? Thanks in advance.
>>>
>>>
Re: Is it advisable to subclass ComboBoxCellEditor? [message #315397 is a reply to message #315388] Wed, 09 May 2007 10:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: inliner683.gmx.de

This is a multi-part message in MIME format.
--------------090602080804090700080402
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Yes I can, see the attached files.

Tom Schindl schrieb:
> Can you provide me a standalone easy snippet to track this down?
>
> Tom
>
> inliner683 schrieb:
>> After investigating more in ComboBoxViewerCellEditor, i still can't
>> display any Labels! I set the LabelProvider and tried different
>> implementations and the LabelProvider which defaults to the
>> toString()-method.
>> In debug mode i can see the the method setItems is called on the
>> underlying Combo wiht the correct array of labels, but in the view I
>> see nothing. If it would work, it would fit well in my context, so
>> thanks for the hint so far.
>>
>> But what am I missing to let it work properly?
>>
>> inliner683 schrieb:
>>> OK I looked at the ComboBoxViewerCellEditor.
>>> Althoug i set a LabelProvider(), the box is empty (only the labels).
>>> The returned value is correct, e.g. it returns my object which is
>>> provided by a call to setInput() on the viewer. I don't know why the
>>> labels are empty even if i provide a static string as label in the
>>> labelprovider.
>>>
>>> Nevertheless, this does do nothing other, as provide handling of
>>> custom objects in the box via the label and content interfaces, which
>>> I wanted to achieve by using e.g. a HashMap and implement the
>>> CellEditor analogous to ComboBoxCellEditor, am I right?
>>>
>>> Tom Schindl schrieb:
>>>> Hi,
>>>>
>>>> Why don't you write a Viewer around your ComboBox? This would be the
>>>> cleanest solution and we will eventually provide such a thing in 3.4
>>>> hopefully.
>>>>
>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=104225
>>>>
>>>> Tom
>>>>
>>>> inliner683 schrieb:
>>>>> Hello,
>>>>>
>>>>> I am wondering if it is good advice to subclass ComboBoxCellEditor?
>>>>> I read about the issues when subclassing widgets, so what would happen
>>>>> to my subclass, if in next release the ComboBoxCellEditor
>>>>> fundamentally
>>>>> changes?
>>>>> In particular I want to make ComboBoxCelleditor deal with other values
>>>>> than Integers.
>>>>>
>>>>> The other way would be to write an own "SpecialComboBoxCellEditor"
>>>>> dealing with my data objects.
>>>>>
>>>>> What would you suggest? Thanks in advance.
>>>>
>>>>


--------------090602080804090700080402
Content-Type: text/plain;
name="ComboBoxViewerCellEditor.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ComboBoxViewerCellEditor.java"



import java.text.MessageFormat;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
* A cell editor that presents a list of items in a combo box. In contrast to
* {@link ComboBoxCellEditor} it wraps the underlying {@link CCombo} using a
* {@link ComboViewer}
*/
public class ComboBoxViewerCellEditor extends CellEditor {

/**
* The custom combo box control.
*/
ComboViewer viewer;

Object selectedValue;

/**
* Default ComboBoxCellEditor style
*/
private static final int defaultStyle = SWT.NONE;

/**
* Creates a new cell editor with a combo viewer and a default style
*
* @param parent
* the parent control
*/
public ComboBoxViewerCellEditor(Composite parent) {
this(parent, defaultStyle);
}

/**
* Creates a new cell editor with a combo viewer and the given style
*
* @param parent
* the parent control
* @param style
* the style bits
*/
public ComboBoxViewerCellEditor(Composite parent, int style) {
super(parent, style);
setValueValid(true);
}

/*
* (non-Javadoc) Method declared on CellEditor.
*/
protected Control createControl(Composite parent) {

CCombo comboBox = new CCombo(parent, getStyle());
comboBox.setFont(parent.getFont());
viewer = new ComboViewer(comboBox);

comboBox.addKeyListener(new KeyAdapter() {
// hook key pressed - see PR 14201
public void keyPressed(KeyEvent e) {
keyReleaseOccured(e);
}
});

comboBox.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent event) {
applyEditorValueAndDeactivate();
}

public void widgetSelected(SelectionEvent event) {
ISelection selection = viewer.getSelection();
if (selection.isEmpty()) {
selectedValue = null;
} else {
selectedValue = ((IStructuredSelection) selection)
.getFirstElement();
}
}
});

comboBox.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_ESCAPE
|| e.detail == SWT.TRAVERSE_RETURN) {
e.doit = false;
}
}
});

comboBox.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
ComboBoxViewerCellEditor.this.focusLost();
}
});
return comboBox;
}

/**
* The <code>ComboBoxCellEditor</code> implementation of this
* <code>CellEditor</code> framework method returns the zero-based index
* of the current selection.
*
* @return the zero-based index of the current selection wrapped as an
* <code>Integer</code>
*/
protected Object doGetValue() {
return selectedValue;
}

/*
* (non-Javadoc) Method declared on CellEditor.
*/
protected void doSetFocus() {
viewer.getControl().setFocus();
}

/**
* The <code>ComboBoxCellEditor</code> implementation of this
* <code>CellEditor</code> framework method sets the minimum width of the
* cell. The minimum width is 10 characters if <code>comboBox</code> is
* not <code>null</code> or <code>disposed</code> eles it is 60 pixels
* to make sure the arrow button and some text is visible. The list of
* CCombo will be wide enough to show its longest item.
*/
public LayoutData getLayoutData() {
LayoutData layoutData = super.getLayoutData();
if ((viewer.getControl() == null) || viewer.getControl().isDisposed()) {
layoutData.minimumWidth = 60;
} else {
// make the comboBox 10 characters wide
GC gc = new GC(viewer.getControl());
layoutData.minimumWidth = (gc.getFontMetrics()
.getAverageCharWidth() * 10) + 10;
gc.dispose();
}
return layoutData;
}

/**
* Set a new value
*
* @param value
* the new value
*/
protected void doSetValue(Object value) {
Assert.isTrue(viewer != null);
viewer.setSelection(new StructuredSelection(value));
}

/**
* @param labelProvider
* the label provider used
* @see StructuredViewer#setLabelProvider(IBaseLabelProvider)
*/
public void setLabelProvider(IBaseLabelProvider labelProvider) {
viewer.setLabelProvider(labelProvider);
}

/**
* @param provider
* the content provider used
* @see StructuredViewer#setContentProvider(IContentProvider)
*/
public void setContenProvider(IStructuredContentProvider provider) {
viewer.setContentProvider(provider);
}

/**
* @param input
* the input used
* @see StructuredViewer#setInput(Object)
*/
public void setInput(Object input) {
viewer.setInput(input);
}

/**
* @return get the viewer
*/
public ComboViewer getViewer() {
return viewer;
}

/**
* Applies the currently selected value and deactiavates the cell editor
*/
void applyEditorValueAndDeactivate() {
// must set the selection before getting value
ISelection selection = viewer.getSelection();
if (selection.isEmpty()) {
selectedValue = null;
} else {
selectedValue = ((IStructuredSelection) selection)
.getFirstElement();
}

Object newValue = doGetValue();
markDirty();
boolean isValid = isCorrect(newValue);
setValueValid(isValid);

if (!isValid) {
MessageFormat.format(getErrorMessage(),
new Object[] { selectedValue });
}

fireApplyEditorValue();
deactivate();
}

/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.CellEditor#focusLost()
*/
protected void focusLost() {
if (isActivated()) {
applyEditorValueAndDeactivate();
}
}

/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.CellEditor#keyReleaseOccured(org.e clipse.swt.events.KeyEvent)
*/
protected void keyReleaseOccured(KeyEvent keyEvent) {
if (keyEvent.character == '\u001b') { // Escape character
fireCancelEditor();
} else if (keyEvent.character == '\t') { // tab key
applyEditorValueAndDeactivate();
}
}
}


--------------090602080804090700080402
Content-Type: text/plain;
name="ComboViewerCellEditorDemo.java"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="ComboViewerCellEditorDemo.java"

aW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7DQppbXBvcnQgamF2YS51dGls Lkxpc3Q7DQoN
CmltcG9ydCBvcmcuZWNsaXBzZS5qZmFjZS52aWV3ZXJzLkNlbGxFZGl0b3I7 DQppbXBvcnQg
b3JnLmVjbGlwc2UuamZhY2Uudmlld2Vycy5JQ2VsbE1vZGlmaWVyOw0KaW1w b3J0IG9yZy5l
Y2xpcHNlLmpmYWNlLnZpZXdlcnMuSUxhYmVsUHJvdmlkZXI7DQppbXBvcnQg b3JnLmVjbGlw
c2UuamZhY2Uudmlld2Vycy5JTGFiZWxQcm92aWRlckxpc3RlbmVyOw0KaW1w b3J0IG9yZy5l
Y2xpcHNlLmpmYWNlLnZpZXdlcnMuSVN0cnVjdHVyZWRDb250ZW50UHJvdmlk ZXI7DQppbXBv
cnQgb3JnLmVjbGlwc2UuamZhY2Uudmlld2Vycy5JVGFibGVMYWJlbFByb3Zp ZGVyOw0KaW1w
b3J0IG9yZy5lY2xpcHNlLmpmYWNlLnZpZXdlcnMuTGFiZWxQcm92aWRlcjsN CmltcG9ydCBv
cmcuZWNsaXBzZS5qZmFjZS52aWV3ZXJzLlRhYmxlVmlld2VyOw0KaW1wb3J0 IG9yZy5lY2xp
cHNlLmpmYWNlLnZpZXdlcnMuVGV4dENlbGxFZGl0b3I7DQppbXBvcnQgb3Jn LmVjbGlwc2Uu
amZhY2Uudmlld2Vycy5WaWV3ZXI7DQppbXBvcnQgb3JnLmVjbGlwc2Uuc3d0 LlNXVDsNCmlt
cG9ydCBvcmcuZWNsaXBzZS5zd3QuZ3JhcGhpY3MuSW1hZ2U7DQppbXBvcnQg b3JnLmVjbGlw
c2Uuc3d0LmxheW91dC5GaWxsTGF5b3V0Ow0KaW1wb3J0IG9yZy5lY2xpcHNl LnN3dC53aW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JldHVybiBlbGVtZW50LnRvU3RyaW5nKCk7DQoJCQl9DQoN CgkJCXB1Ymxp
YyBib29sZWFuIGNhbk1vZGlmeShPYmplY3QgZWxlbWVudCwgU3RyaW5nIHBy b3BlcnR5KSB7
DQoJCQkJLy8gVE9ETyBBdXRvLWdlbmVyYXRlZCBtZXRob2Qgc3R1Yg0KCQkJ CXJldHVybiB0
cnVlOw0KCQkJfQ0KDQoJCX0pOw0KDQoJCUxpc3QgaW5wdXQgPSBuZXcgQXJy YXlMaXN0KCk7
DQoJCWlucHV0LmFkZCgidmFsdWUxIik7DQoJCWlucHV0LmFkZCgidmFsdWUy Iik7DQoJCWlu
cHV0LmFkZCgidmFsdWUzIik7DQoJCWlucHV0LmFkZCgidmFsdWU0Iik7DQoJ CWlucHV0LmFk
ZCgidmFsdWU1Iik7DQoJCWlucHV0LmFkZCgidmFsdWU2Iik7DQoJCWlucHV0 LmFkZCgidmFs
dWU3Iik7DQoJCXR2LnNldElucHV0KGlucHV0KTsNCg0KCQlzaGVsbC5wYWNr KCk7DQoJCXNo
ZWxsLm9wZW4oKTsNCgkJd2hpbGUgKCFzaGVsbC5pc0Rpc3Bvc2VkKCkpIHsN CgkJCWlmICgh
ZGlzcGxheS5yZWFkQW5kRGlzcGF0Y2goKSkNCgkJCQlkaXNwbGF5LnNsZWVw KCk7DQoJCX0N
CgkJZGlzcGxheS5kaXNwb3NlKCk7DQoJfQ0KfQ==
--------------090602080804090700080402--
Re: Is it advisable to subclass ComboBoxCellEditor? [message #315407 is a reply to message #315397] Wed, 09 May 2007 11:43 Go to previous messageGo to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------050206040002080206060509
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

For me this works like a charme although I had to modify your snippet a
bit to select the correct values. What version of eclipse are you
running? To make this work you need 3.3-stream because before the
ComboViewer could not deal with CCombo and that might be your problem.

I attach you the modified fully working example. I'll also add it to the
bug so we can later create a snippet from this for our collection
( http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/)

Tom

--------------050206040002080206060509
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
name="ComboViewerCellEditorDemo.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ComboViewerCellEditorDemo.java"

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class ComboViewerCellEditorDemo {

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

Table table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);

TableColumn tc = new TableColumn(table, SWT.NONE);
tc.setText("first");
tc.pack();

TableColumn tc2 = new TableColumn(table, SWT.NONE);
tc2.setText("second");
tc2.pack();

final TableViewer tv = new TableViewer(table);
tv.setContentProvider(new IStructuredContentProvider() {

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

}

public void dispose() {

}

public Object[] getElements(Object inputElement) {
return ((List) inputElement).toArray();
}

});
tv.setLabelProvider(new ITableLabelProvider() {

public void removeListener(ILabelProviderListener listener) {

}

public boolean isLabelProperty(Object element, String aProperty) {
return false;
}

public void dispose() {

}

public void addListener(ILabelProviderListener listener) {

}

public String getColumnText(Object element, int aColumnIndex) {
if( aColumnIndex == 0 ) {
return "Item " + ((ModelObject)element).i;
} else {
return ((ModelObject)element).value.toString();
}

}

public Image getColumnImage(Object element, int aColumnIndex) {
return null;
}

});
tv.setColumnProperties(new String[] { "first", "second" });
CellEditor[] cellEditors = new CellEditor[2];
cellEditors[0] = new TextCellEditor(table);

ComboBoxViewerCellEditor cv = new ComboBoxViewerCellEditor(table);
cv.setContenProvider(new IStructuredContentProvider() {

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO Auto-generated method stub

}

public void dispose() {
// TODO Auto-generated method stub

}

public Object[] getElements(Object inputElement) {
return ((List) inputElement).toArray();
}

});
cv.setLabelProvider(new LabelProvider() {

public String getText(Object element) {
return element.toString();
}

});
List comboInput = new ArrayList();
comboInput.add(new DDElement(1));
comboInput.add(new DDElement(2));
comboInput.add(new DDElement(3));
cv.setInput(comboInput);

cellEditors[1] = cv;

tv.setCellEditors(cellEditors);

tv.setCellModifier(new ICellModifier() {

public void modify(Object element, String property, Object value) {
ModelObject modelObject = (ModelObject) ((TableItem)element).getData();

if( property.equals("first") ) {
modelObject.i = Integer.parseInt(value.toString());
} else {
modelObject.value = (DDElement) value;
}

tv.update(modelObject, null);
}

public Object getValue(Object element, String property) {
if( property.equals("first") ) {
return ((ModelObject)element).i+"";
}
return ((ModelObject)element).value;
}

public boolean canModify(Object element, String property) {
return true;
}

});

List input = new ArrayList();
input.add(new ModelObject(1,(DDElement) comboInput.get(0)));
input.add(new ModelObject(2,(DDElement) comboInput.get(1)));
input.add(new ModelObject(3,(DDElement) comboInput.get(2)));
input.add(new ModelObject(4,(DDElement) comboInput.get(0)));
input.add(new ModelObject(5,(DDElement) comboInput.get(1)));
input.add(new ModelObject(6,(DDElement) comboInput.get(2)));
input.add(new ModelObject(7,(DDElement) comboInput.get(0)));
input.add(new ModelObject(8,(DDElement) comboInput.get(1)));
tv.setInput(input);

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

private static class DDElement {
private int value;

public DDElement(int value) {
this.value = value;
}

public String toString() {
return "Combo-"+value;
}
}

private static class ModelObject {
private int i = 0;
private DDElement value;

public ModelObject(int i, DDElement value) {
this.i = i;
this.value = value;
}
}
}
--------------050206040002080206060509--
Re: Is it advisable to subclass ComboBoxCellEditor? [message #315456 is a reply to message #315407] Thu, 10 May 2007 07:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: inliner683.gmx.de

Hi,

I am actually working on 3.2.2! I tested it on 3.3 and it works with no
modification! Didn't think of that.
As I need to be compliant to 3.2.2 I implemented a custom
ComboBoxCellEditor dealing with a simple key-value map, and it works fine.
If you use Combo instead CCombo in the Demo, the ComboViewer works as
well on 3.2.2 but doesn't look well in a table...

So thanks for your help!

Tom Schindl schrieb:
> Hi,
>
> For me this works like a charme although I had to modify your snippet a
> bit to select the correct values. What version of eclipse are you
> running? To make this work you need 3.3-stream because before the
> ComboViewer could not deal with CCombo and that might be your problem.
>
> I attach you the modified fully working example. I'll also add it to the
> bug so we can later create a snippet from this for our collection
> ( http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/)
>
>
> Tom
>
Re: Is it advisable to subclass ComboBoxCellEditor? [message #315458 is a reply to message #315456] Thu, 10 May 2007 07:07 Go to previous message
Eclipse UserFriend
Hi,

Your problem is that 3.2.2 ComboViewer can't deal with CCombo and the
bad thing is that it doesn't event produce an Compiletime-Exception
because the ComboViewer(Composite) is the constructor called in this case.

Any easy work-around would be to copy the ComboViewer from 3.3 into your
3.3 project because it doesn't contain any code not compatible with
eclipse 3.2 and then your are done.

Tom

inliner683 schrieb:
> Hi,
>
> I am actually working on 3.2.2! I tested it on 3.3 and it works with no
> modification! Didn't think of that.
> As I need to be compliant to 3.2.2 I implemented a custom
> ComboBoxCellEditor dealing with a simple key-value map, and it works fine.
> If you use Combo instead CCombo in the Demo, the ComboViewer works as
> well on 3.2.2 but doesn't look well in a table...
>
> So thanks for your help!
>
> Tom Schindl schrieb:
>> Hi,
>>
>> For me this works like a charme although I had to modify your snippet
>> a bit to select the correct values. What version of eclipse are you
>> running? To make this work you need 3.3-stream because before the
>> ComboViewer could not deal with CCombo and that might be your problem.
>>
>> I attach you the modified fully working example. I'll also add it to
>> the bug so we can later create a snippet from this for our collection
>> ( http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/)
>>
>>
>> Tom
>>
>
Previous Topic:Re: Localisations
Next Topic:Enabling/Disabling Commands and the new Menu-Extension-Point
Goto Forum:
  


Current Time: Sat May 10 17:12:17 EDT 2025

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

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

Back to the top