Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Simple question: Add and update Text field in Toolbar
Simple question: Add and update Text field in Toolbar [message #549658] Tue, 27 July 2010 13:35 Go to next message
Florian Philipp is currently offline Florian PhilippFriend
Messages: 43
Registered: February 2010
Member
Hello!

I want to add a text field to the coolbar in order to show a certain setting from the application preferences. This text shall then be updated when the preferences change.

So far, so good. As far as I know, the proper to way to add arbitrary GUI elements to the Toolbar is to extend the class org.eclipse.jface.action.ControlContribution.

But how do I later change the displayed text?

My current approach is this:

public class MainFileContribution extends ControlContribution{

	protected Control createControl(Composite parent) {
		
		final Text text = new Text(parent, SWT.BORDER|SWT.READ_ONLY);
		text.setText(getText());

		preferences.addPreferenceChangeListener(
				new IPreferenceChangeListener() {
			
			public void preferenceChange(PreferenceChangeEvent event) {
				text.setText(getText());
			}
		});
		
		return text;				
	}


Basically, I'm storing a reference to the Text widget and call the setText method when I want to change it.

This works but I get the following exception:
Quote:

org.eclipse.swt.SWTException: Widget is disposed



Changes are still applied, though.

So now my question is: What is the proper way to accomplish this?

Thanks in advance!
Florian Philipp
Re: Simple question: Add and update Text field in Toolbar [message #551033 is a reply to message #549658] Wed, 04 August 2010 22:22 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi Florian,

The disposed message does not come from your text widget. I bet it comes from
the preference widget.

--

Best Regards,
Wim Jongman

Eclipse Twitter
-- Liar.getLiar().isPantsOnFire()
Kim Horne


> Hello!
>
> I want to add a text field to the coolbar in order to show a certain
setting from the application preferences. This text shall then be updated
when the preferences change.
>
> So far, so good. As far as I know, the proper to way to add arbitrary GUI
elements to the Toolbar is to extend the class
org.eclipse.jface.action.ControlContribution.
>
> But how do I later change the displayed text?
>
> My current approach is this:
>
>
> public class MainFileContribution extends ControlContribution{
>
> protected Control createControl(Composite parent) {
>
> final Text text = new Text(parent, SWT.BORDER|SWT.READ_ONLY);
> text.setText(getText());
>
> preferences.addPreferenceChangeListener(
> new IPreferenceChangeListener() {
>
> public void preferenceChange(PreferenceChangeEvent event) {
> text.setText(getText());
> }
> });
>
> return text;
> }
>
>
> Basically, I'm storing a reference to the Text widget and call the setText
method when I want to change it.
>
> This works but I get the following exception:
> Quote:
>> org.eclipse.swt.SWTException: Widget is disposed
>
>
> Changes are still applied, though.
>
> So now my question is: What is the proper way to accomplish this?
>
> Thanks in advance!
> Florian Philipp
Re: Simple question: Add and update Text field in Toolbar [message #551059 is a reply to message #551033] Thu, 05 August 2010 05:18 Go to previous message
Florian Philipp is currently offline Florian PhilippFriend
Messages: 43
Registered: February 2010
Member
Wim Jongman wrote on Wed, 04 August 2010 18:22
Hi Florian,

The disposed message does not come from your text widget. I bet it comes from
the preference widget.





org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4083)
	at org.eclipse.swt.SWT.error(SWT.java:3998)
	at org.eclipse.swt.SWT.error(SWT.java:3969)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:466)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:403)
	at org.eclipse.swt.widgets.Text.setText(Text.java:2031)
	at de.[...].MainFileContribution$1.preferenceChange(MainFileContribution.java:36)
	at org.eclipse.core.internal.preferences.EclipsePreferences$2.run(EclipsePreferences.java:753)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.preferences.EclipsePreferences.firePreferenceEvent(EclipsePreferences.java:756)
	at org.eclipse.core.internal.preferences.EclipsePreferences.put(EclipsePreferences.java:769)
	at de.[...].MainFileAction.run(MainFileAction.java:37)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3552)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3171)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at de.[...].Application.start(Application.java:20)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1383)



Looks like it is thrown by SWT.Text ...
Previous Topic:How to control shortcut bar ?
Next Topic:Dynamic TreeViewer
Goto Forum:
  


Current Time: Fri Apr 26 14:53:26 GMT 2024

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

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

Back to the top