Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TableViewer with OwnerDrawLabel only draws the first row
TableViewer with OwnerDrawLabel only draws the first row [message #1318306] Sun, 27 April 2014 15:36 Go to next message
Sharon Dagan is currently offline Sharon DaganFriend
Messages: 12
Registered: November 2013
Junior Member
This trivial test case running against Eclipse 4.3.2 puzzles me -- why is it that only the first row is drawn?

Thanks,
-S

---Begin---

package testcase;

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

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.OwnerDrawLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;

public class TableViewer_OwnerDrawLabel_Testcase {
	
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display, SWT.SHELL_TRIM);
		
		shell.setLayout(new FillLayout());
		shell.setMinimumSize(600, 400);

		final TableViewer tv = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
		tv.setContentProvider(new IStructuredContentProvider() {
			
			@Override
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
			}
			
			@Override
			public void dispose() {
			}
			
			@Override
			public Object[] getElements(Object inputElement) {
				return ((List)inputElement).toArray();
			}
		});
		
		tv.setLabelProvider(new OwnerDrawLabelProvider() {

			@Override
			protected void paint(Event event, Object element) {
				GC gc = event.gc;
				gc.drawText((String)element, 0, 0, true);
			}
			
			@Override
			protected void measure(Event event, Object element) {
			}
		});
		
		ArrayList<String> items = new ArrayList<String>();
		items.add("one");
		items.add("two");
		items.add("three");
		
		tv.setInput(items);
		
		shell.pack();
		shell.open();

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

---End---

[Updated on: Sun, 27 April 2014 15:37]

Report message to a moderator

Re: TableViewer with OwnerDrawLabel only draws the first row [message #1318514 is a reply to message #1318306] Sun, 27 April 2014 18:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6410
Registered: July 2009
Senior Member
Shouldn't you draw on event.x, event.y instead of 0,0? See
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet010OwnerDraw.java

Tom

On 27.04.14 17:36, Sharon Dagan wrote:
> This trivial test case running against Eclipse 4.3.2 puzzles me -- why
> is it that only the first row is drawn?
>
> Thanks,
> -S
>
> ---Begin---
>
> package testcase;
>
> import java.util.ArrayList;
> import java.util.List;
>
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.OwnerDrawLabelProvider;
> import org.eclipse.jface.viewers.TableViewer;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.GC;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Event;
> import org.eclipse.swt.widgets.Shell;
>
> public class TableViewer_OwnerDrawLabel_Testcase {
>
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display, SWT.SHELL_TRIM);
>
> shell.setLayout(new FillLayout());
> shell.setMinimumSize(600, 400);
>
> final TableViewer tv = new TableViewer(shell, SWT.BORDER |
> SWT.FULL_SELECTION);
> tv.setContentProvider(new IStructuredContentProvider() {
>
> @Override
> public void inputChanged(Viewer viewer, Object oldInput,
> Object newInput) {
> }
>
> @Override
> public void dispose() {
> }
>
> @Override
> public Object[] getElements(Object inputElement) {
> return ((List)inputElement).toArray();
> }
> });
>
> tv.setLabelProvider(new OwnerDrawLabelProvider() {
>
> @Override
> protected void paint(Event event, Object element) {
> GC gc = event.gc;
> gc.drawText((String)element, 0, 0, true);
> }
>
> @Override
> protected void measure(Event event, Object element) {
> }
> });
>
> ArrayList<String> items = new ArrayList<String>();
> items.add("one");
> items.add("two");
> items.add("three");
>
> tv.setInput(items);
>
> shell.pack();
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> }
> }
>
> ---End---
Re: TableViewer with OwnerDrawLabel only draws the first row [message #1318534 is a reply to message #1318514] Sun, 27 April 2014 18:43 Go to previous message
Sharon Dagan is currently offline Sharon DaganFriend
Messages: 12
Registered: November 2013
Junior Member
Thanks! that was it.
Previous Topic:[DATABINDING] How-to: binding the (current single) selection of treeViewers to something
Next Topic:TreeViewer::setInput() -> UI timeout
Goto Forum:
  


Current Time: Fri Sep 21 10:19:00 GMT 2018

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

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

Back to the top