Aligment in a TableViewer [message #885116] |
Tue, 12 June 2012 09:46  |
Eclipse User |
|
|
|
Hi all,
I have the following problem with a TableViewer. I have a TableViwer that is displaying a set of properties with their values. Some of these properties has values that are just text and some are better displayed as images. The problem is that the viewer reserve space for the images in all the rows, doesn't matter if there image or not.
-----------------------------------------
| prop1 | val1 |
-----------------------------------------
| prop1 | val2 |
-----------------------------------------
| prop3 | < image > |
-----------------------------------------
but I will like to have:
-----------------------------------------
| prop1 | val1 |
-----------------------------------------
| prop1 | val2 |
-----------------------------------------
| prop3 | < image > |
-----------------------------------------
Any ideas how can I get that alignment?
Thank you very much.
Joaquin Morcate
|
|
|
|
|
|
|
|
|
Re: Aligment in a TableViewer [message #890011 is a reply to message #889797] |
Wed, 20 June 2012 10:51   |
Eclipse User |
|
|
|
Hi,
Still I am not able to find a good solution to my problem. If I use a OwnerDrawLabelProvider as Grant suggested yesterday, I get a good rendering of my values (i.e. the text entries are aligned to the left without space for the images). This is the code:
valueColumn.setLabelProvider(new OwnerDrawLabelProvider() {
@Override
public void update(ViewerCell cell) {
ReadoutEntry entry = (ReadoutEntry) cell.getElement();
cell.setText(entry.getStringValue());
cell.setImage(entry.getImageValue(Display.getDefault()));
}
@Override
protected void paint(Event event, Object element) {
ReadoutEntry entry = (ReadoutEntry) element;
GC gc = event.gc;
Table table = (Table) event.widget;
int width = table.getColumn(0).getWidth();
if (entry.getImageValue(table) != null) {
gc.drawImage(entry.getImageValue(Display.getDefault()),
width + 2, event.y + 2);
} else {
gc.drawText(entry.getStringValue(), width + 2, event.y + 2,
true);
}
}
@Override
protected void erase(Event event, Object element) {
event.detail &= ~SWT.FOREGROUND;
}
@Override
protected void measure(Event event, Object element) {
}
});
But if I enable the editors they are placed in the space defined by textBounds. This is a snapshot:

The problem, I guess, is that I am not able to modify the image and text bounds in the TableItem's. But I'm really confused now. May be there is a simpler solution or I'm doing something wrong.
Any help?
Joaquin
|
|
|
|
Powered by
FUDForum. Page generated in 0.05251 seconds