Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » WorkbenchWindowControlContribution resize problem in trim area
WorkbenchWindowControlContribution resize problem in trim area [message #506896] Mon, 11 January 2010 04:44 Go to next message
Jan is currently offline Jan
Messages: 12
Registered: July 2009
Junior Member
Hi group,

I added my own WorkbenchWindowControlContribution to the trim area of
the status bar:

<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="toolbar:org.eclipse.ui.trim.status">
<toolbar id="myToolbar">
<control id="myControl" class="MyContribution" />
</toolbar>
</menuContribution>
</extension>

"myControl" contains a Composite with Labels and Images. If the text of
a Label changes, I call pack() on the Composite and the Composite
resizes correctly. However the parent does not. If the text grows, the
composite will be truncated. I have to drag my contribution to a
different position (top, left or right) and back to make it resize
correctly.

I tried nearly anything to make it realise the resize. The following has
no effect from within the composite:

this.layout();
getParent().layout();
getParent().pack();
myContribution.update();
myContribution.getParent().markDirty();
myContribution.getParent().update(true);

So the question is: Is there any way to convince the
toolbar/ControlContribution/trimArea to recognize the change in the size
and layout itself?

Thanks
Jan
Re: WorkbenchWindowControlContribution resize problem in trim area [message #507502 is a reply to message #506896] Wed, 13 January 2010 12:08 Go to previous messageGo to next message
Jan is currently offline Jan
Messages: 12
Registered: July 2009
Junior Member
myToolbar is only resizing/redraw correctly on mouse drag. There must be
a way to this programmatically.

Anyone?
Re: WorkbenchWindowControlContribution resize problem in trim area [message #507514 is a reply to message #507502] Wed, 13 January 2010 08:12 Go to previous messageGo to next message
Eclipse User
Originally posted by: jccanova.gmail.com

Have you tried composite.getParent().layout(true, true). ?
this means that the parent will check if the control (parent) need a resize
and cascade the method call to its children.

In matter of fact... layout ()... call the method bellow passing the second
parameter as false. while the layout (true,true) call the same method
passing the second argument as true... also if you understand what this
method bellow does... let me know :).


void updateLayout (boolean resize, boolean all) {
Composite parent = findDeferredControl ();
if (parent != null) {
parent.state |= LAYOUT_CHILD;
return;
}
if ((state & LAYOUT_NEEDED) != 0) {
boolean changed = (state & LAYOUT_CHANGED) != 0;
state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
if (resize) setResizeChildren (false);
layout.layout (this, changed);
if (resize) setResizeChildren (true);
}
if (all) {
state &= ~LAYOUT_CHILD;
Control [] children = _getChildren ();
for (int i=0; i<children.length; i++) {
children [i].updateLayout (resize, all);
}
}
}


Just a question is you composite inside the toolbar or you have a button
that when pressed shows your composite passing as argument the parent ?

regards.

"Jan" <jan.kuenstler@bader-jene.de> wrote in message
news:hikuld$uig$1@build.eclipse.org...
> myToolbar is only resizing/redraw correctly on mouse drag. There must be a
> way to this programmatically.
>
> Anyone?
Re: WorkbenchWindowControlContribution resize problem in trim area [message #507516 is a reply to message #507514] Wed, 13 January 2010 13:17 Go to previous messageGo to next message
Eclipse User
Originally posted by: jccanova.gmail.com

Assume the "receiver" means "this" (Carolyn - Answer 2 days ago - in swt
forum).
The part changed argument (first boolean) means that "no flushCache()"
method call will be called if you passed as "false"... i guess the cache in
question means that some property of the layout
is cached in some Layout classes.

I still need to know which layout has a cache and which does not. I guess
your question if good for the eclipse SWT .. i guess.
Carolyn from IBM is a subject matter expert in SWT in the swt forum.

The Javadoc stands the following. in the layout(bool,bool).
/**
* If the receiver has a layout, asks the layout to <em>lay out</em>
* (that is, set the size and location of) the receiver's children.
* If the changed argument is <code>true</code> the layout must not rely
* on any information it has cached about its children. If it
* is <code>false</code> the layout may (potentially) optimize the
* work it is doing by assuming that none of the receiver's
* children has changed state since the last layout.
* If the all argument is <code>true</code> the layout will cascade down
* through all child widgets in the receiver's widget tree, regardless of
* whether the child has changed size. The changed argument is applied to
* all layouts. If the all argument is <code>false</code>, the layout will
* <em>not</em> cascade down through all child widgets in the receiver's
widget
* tree. However, if a child is resized as a result of a call to layout,
the
* resize event will invoke the layout of the child. Note that
* a layout due to a resize will not flush any cached information
* (same as <code>layout(false)</code>).
* </p>
* <p>
* Note: Layout is different from painting. If a child is
* moved or resized such that an area in the parent is
* exposed, then the parent will paint. If no child is
* affected, the parent will not paint.
* </p>

"Jose Carlos Canova" <jccanova@gmail.com> wrote in message
news:hil22c$qg0$1@build.eclipse.org...
> Have you tried composite.getParent().layout(true, true). ?
> this means that the parent will check if the control (parent) need a
> resize and cascade the method call to its children.
>
> In matter of fact... layout ()... call the method bellow passing the
> second parameter as false. while the layout (true,true) call the same
> method passing the second argument as true... also if you understand what
> this method bellow does... let me know :).
>
>
> void updateLayout (boolean resize, boolean all) {
> Composite parent = findDeferredControl ();
> if (parent != null) {
> parent.state |= LAYOUT_CHILD;
> return;
> }
> if ((state & LAYOUT_NEEDED) != 0) {
> boolean changed = (state & LAYOUT_CHANGED) != 0;
> state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
> if (resize) setResizeChildren (false);
> layout.layout (this, changed);
> if (resize) setResizeChildren (true);
> }
> if (all) {
> state &= ~LAYOUT_CHILD;
> Control [] children = _getChildren ();
> for (int i=0; i<children.length; i++) {
> children [i].updateLayout (resize, all);
> }
> }
> }
>
>
> Just a question is you composite inside the toolbar or you have a button
> that when pressed shows your composite passing as argument the parent ?
>
> regards.
>
> "Jan" <jan.kuenstler@bader-jene.de> wrote in message
> news:hikuld$uig$1@build.eclipse.org...
>> myToolbar is only resizing/redraw correctly on mouse drag. There must be
>> a way to this programmatically.
>>
>> Anyone?
>
Re: WorkbenchWindowControlContribution resize problem in trim area [message #507539 is a reply to message #507502] Wed, 13 January 2010 14:25 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6850
Registered: July 2009
Location: Ottawa
Senior Member

Jan wrote:
> myToolbar is only resizing/redraw correctly on mouse drag. There must be
> a way to this programmatically.

If none of Jose's suggestions work, you could always try
shell.layout(new Control[] { myControl}); when you know your text
requires a layout.

There might be a non-trivial cost for this, so you'll have to observe
and/or profile it.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: WorkbenchWindowControlContribution resize problem in trim area [message #507665 is a reply to message #507539] Thu, 14 January 2010 00:02 Go to previous messageGo to next message
Jan is currently offline Jan
Messages: 12
Registered: July 2009
Junior Member
> Have you tried composite.getParent().layout(true, true). ?

Has no effect, but thanks, didn't know about that one.

> shell.layout(new Control[] { myControl});

I tried that, but to no avail.

It seems this is the same issue as described in bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=186800

Have a look at the second to last comment: "Screenshot of expanding
contribution that doesn't push others down to next row"

By the way: I'm using Eclipse RCP 3.4.1, so I have this bugfix, right?

Thanks in advance
Re: WorkbenchWindowControlContribution resize problem in trim area [message #665663 is a reply to message #506896] Fri, 15 April 2011 08:28 Go to previous messageGo to next message
Jean Barata is currently offline Jean Barata
Messages: 1
Registered: July 2009
Junior Member
Have you tried to override the method "computeWidth()" in your class "MyContribution"

in my case it worked...
Re: WorkbenchWindowControlContribution resize problem in trim area [message #758287 is a reply to message #507665] Tue, 22 November 2011 09:57 Go to previous messageGo to next message
Zhang Mingquan is currently offline Zhang Mingquan
Messages: 1
Registered: November 2011
Junior Member
To anyone who is still trying to find a workaround, please check the bug, it had been fixed.

All you have to do is override isDynamic method and call getParent().update(true) when the control's content changes.

It works like a charm!
Re: WorkbenchWindowControlContribution resize problem in trim area [message #1079877 is a reply to message #758287] Mon, 05 August 2013 03:31 Go to previous message
Brian Lei is currently offline Brian Lei
Messages: 1
Registered: August 2013
Junior Member
Hi , i had this problem with it. And try to fixed it according to your solution. But the application always error below when a inner Class Observer call getParent().update(true) this line : java.lang.IllegalArgumentException: Argument not valid. So how to fix it?

	@Override
	protected Control createControl(Composite parent) {
		if (!init) {
			composite = new Composite(parent, SWT.NONE);
			composite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true));
			composite.setLayout(new GridLayout());
			
			labelStatus = new Label(composite, SWT.NONE);
			labelStatus.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true));
			CurrentLabelManager.getLabelObserver().addObserver(selectionObserver);
			init = true;
		}

		if (!labelStatus.isDisposed())
			labelStatus.setText(status);
		return composite;
	}
	
	Observer selectionObserver = new Observer(){

		@Override
		public void update(Observable o, Object arg) {
			List<MultiItem> selectionList = (List<MultiItem> )arg;
			if (selectionList != null && selectionList.size()!= 1) {
				labelStatus.setText(selectionList.size() + " rows selected");
			} else {
				PhoneLabel label = CurrentLabelManager.getCurrentLabel();
				if (label != null ) {
					StringBuffer sb = new StringBuffer();
					sb.append("Product:" + label.getProductName());
					sb.append("	");
					sb.append("Module:"+label.getModuleName());
					sb.append("	");
					sb.append("Label:"+label.getName());
					sb.append("	");
					sb.append("Master text:"+label.getMasterText().getColumnText(ColumnCodes.MASTER_TXT));
//				if (!labelStatus.isDisposed())
//					labelStatus.setText(sb.toString().trim());
					status = sb.toString();
					SelectedLabelInfoControl.this.updateStatus();
				}
			}
		}
		
	};
	
	private void updateStatus(){
		getParent().update(true);
	}
	
	/**
	 * for void happen widge is disposed error.
	 */
	@Override
	public boolean isDynamic(){
		return true;
	}
Previous Topic:Showing Multiple Windows
Next Topic:Widget disposed too early exception
Goto Forum:
  


Current Time: Sat Apr 19 11:51:34 EDT 2014

Powered by FUDForum. Page generated in 0.02322 seconds