Bug 130024 - custom TableItems and TreeItems cannot be shrunk by MeasureItem
Summary: custom TableItems and TreeItems cannot be shrunk by MeasureItem
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows 2000
: P3 normal with 5 votes (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 192770 (view as bug list)
Depends on:
Blocks: 195597
  Show dependency tree
 
Reported: 2006-03-01 15:31 EST by Grant Gayed CLA
Modified: 2020-02-29 07:10 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Grant Gayed CLA 2006-03-01 15:31:32 EST
- run the snippet below, which shows an item that starts by answering a width of 100 in its MeasureItem callback
- the -10 and +10 buttons at the bottom change this item's desired width
- press +10 and note that the example item's width grows, because the width value of subsequent MeasureItem callbacks has been increased by 10
- however, press -10 and note that the example's item's width does not shrink even though the width value of subsequent MeasuteItem callbacks has been reduced by 10

public class MeasureItemTest {
	static int currentWidth = 100;
	public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell(display);
		shell.setBounds(10,10,200,200);
		final Table table = new Table(shell, SWT.NONE);
		table.setBounds(10,10,150,100);
		new TableItem(table, SWT.NONE).setText("item");

		table.addListener(SWT.MeasureItem, new Listener() {
			public void handleEvent(Event event) {
				System.out.println("setting event width to: " + currentWidth);
				event.width = currentWidth;
			}
		});
		table.addListener(SWT.EraseItem, new Listener() {
			public void handleEvent(Event event) {
				System.out.println("-->Received EraseItem with width: " + event.width);
				event.gc.setForeground(display.getSystemColor(SWT.COLOR_GREEN));
				for (int x = event.x; x < event.x + event.width + 10; x += 10) {
					event.gc.drawLine (x, event.y, x - 15, event.y + event.height);
				}
			}
		});
		Button minus10 = new Button(shell, SWT.PUSH);
		minus10.setBounds(10,130,50,30);
		minus10.setText("-10");
		Button plus10 = new Button(shell, SWT.PUSH);
		plus10.setBounds(80,130,50,30);
		plus10.setText("+10");
		final Label label = new Label(shell, SWT.NONE);
		label.setBounds(140,130,50,30);
		label.setText(String.valueOf(currentWidth));
		minus10.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				if (currentWidth == 0) return;
				currentWidth += -10;
				label.setText(String.valueOf(currentWidth));
				table.redraw();
			}
		});
		plus10.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				currentWidth += 10;
				label.setText(String.valueOf(currentWidth));
				table.redraw();
			}
		});
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}
Comment 1 Rob Grzywinski CLA 2006-06-20 15:08:25 EDT
The same goes for height too (if the appropriate changes are made to Mr. Gayed's code).
Comment 2 Rob Grzywinski CLA 2006-06-20 15:22:50 EDT
Likewise for Tree.  Does a separate bug need to be opened for Tree?
Comment 3 Rob Grzywinski CLA 2006-06-20 15:33:38 EDT
It seems that the height problem is caused by code of the form:

   if (event.height > getItemHeight ()) setItemHeight (event.height);

If one subclasses Tree/Table and overrides getItemHeight() you *can* make the items increase and decrease in height.

The width case is a completely separate problem.
Comment 4 Grant Gayed CLA 2006-06-20 15:37:51 EDT
The height not shrinking is by design, and is enforced on all platforms.  I don't remember the history of this, but the root cause was likely a platform limitation.
Comment 5 Steve Northover CLA 2007-06-15 11:02:30 EDT
*** Bug 192770 has been marked as a duplicate of this bug. ***
Comment 6 Steve Northover CLA 2007-06-15 11:04:43 EDT
Currently, trees and tables don't support variable height items.  If the height was allowed to decrease, then items required more space would shrink and the tree/table would flash and redraw constantly.

There are ways around this.  One would be to expose the API Tree/Table.setItemHeight() that programmers could use to shrink the height.
Comment 7 Al Major CLA 2007-06-15 12:49:43 EDT
i see. so the intent of "event.height > getItemHeight" was to ensure that all rows have the same height (the max height over all SWT.MeasreItem event.height values).

in my use case, all rows_do_  have the same height, but that height is changed when the parent window client area height changes. so if the underlying platforms allow it, i think it should be enabled somehow. IMO exposing Tree/Table.setItemHeight() is actually the more appropriate solution here, since it makes it clear that all rows will have a single new height (rather than a per-item SWT.MeasureItem fix).

any chance of this happening soon? Table.setItemHeight currently has package visibility so i'm not sure i can access it without having a private fork of SWT (which i really don't want to do) or playing games with feature patches (which, if it even works, i'm reluctant to do, but won't rule out).

the good news is that it sounds like there's no underlying platform restrictions to the desired behavior (changing the table row height when the parent window height changes). is this correct?
Comment 8 Steve Northover CLA 2007-06-15 14:30:31 EDT
> any chance of this happening soon? 

Not for 3.3.  Since API can't normally be released in an x.x.x release, the earliest is 3.4.  Sorry about that.  However, there will be milestones way before that that might contain the API, assuming we go with it.
Comment 9 Al Major CLA 2007-06-15 16:07:41 EDT
cool. thanks for the quick turnaround. if there's any other way i can assist with this item, let me know.
Comment 10 Boris Bokowski CLA 2007-07-09 12:29:24 EDT
(In reply to comment #6)
> There are ways around this.  One would be to expose the API
> Tree/Table.setItemHeight() that programmers could use to shrink the height.

See bug 148039.
Comment 11 Rohit Shetty CLA 2008-10-31 03:22:42 EDT
Is there a plan to resolve this issue? 
Comment 12 Nobody - feel free to take it CLA 2010-07-07 00:56:09 EDT
What is the status on this bug? Do you have the API working to support this?
Comment 13 Grant Gayed CLA 2010-07-08 17:16:18 EDT
This is not currently being investigated.  This could happen during 3.7, and probably has a better chance than bug 148039, but is still resource-dependent.  The 3.7 plan which outlines where 3.7 efforts will be directed comes out in the fall.
Comment 14 Eclipse Genie CLA 2020-02-29 07:10:04 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.