Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Combo-(viewer) XWT-Databinding trouble
Combo-(viewer) XWT-Databinding trouble [message #901158] Fri, 10 August 2012 03:27 Go to next message
Jürgen Weinberger is currently offline Jürgen Weinberger
Messages: 35
Registered: August 2012
Member
Hi!

I got following problem with the comboviewer databinding in xwt.

I want to provide the user with a list of predefined items in the combolist but he should also be able to type some custom text into the viewer.
How can i realize this? (I don't care if i have to use comboviewer or just the combo-widget). When i use the selectionEvent i only get the selected text and null if he typed something custom.

I played around and achieved to get one thing running at a time but not both. I think this should work something like this:

<ComboViewer x:style="BORDER" input="{Binding Path=possibleRoles}">
<ComboViewer.combo text="{Binding Path=roleName}"/>
</ComboViewer>

But i always get a NullPointer exception.

Has anybody an idea how to achieve this?

regards weinma
Re: Combo-(viewer) XWT-Databinding trouble [message #901164 is a reply to message #901158] Fri, 10 August 2012 03:58 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 731
Registered: July 2009
Senior Member
Did you try the swt modify listener/event?
Re: Combo-(viewer) XWT-Databinding trouble [message #901178 is a reply to message #901164] Fri, 10 August 2012 04:33 Go to previous messageGo to next message
Jürgen Weinberger is currently offline Jürgen Weinberger
Messages: 35
Registered: August 2012
Member
Yes, but that seems to be my next problem. Event handling won't work.

Started following experiment and nothing (button nor combo) works.
Exceptions are always Eventhandler "onSelection" not found and Eventhander "onModifyCombo" not found.

package aasdaa;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;

public class HelloWorld extends Composite {

	public HelloWorld(Composite parent, int style) {
		super(parent, style);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param Object
	 * @param Event
	 */
	protected void onSelection(Object o, Event event) {
		System.out.println("Button pressed");
	}

	/**
	 * @param Object
	 * @param Event
	 */
	public void onModifyCombo(Object object, Event event) {
		System.out.println("Combo modified");
	}

}


I also tried this code without the object parameter in the method call and just the Event parameter, as suggested in some tutorials. Same result

<Composite xmlns="http://www.eclipse.org/xwt/presentation"
	 xmlns:x="http://www.eclipse.org/xwt"
	 xmlns:c="clr-namespace:aasdaa"
	 xmlns:j="clr-namespace:java.lang"
	 x:Class="aasdaa.HelloWorld">
	 <Composite.layout>
		 <GridLayout  numColumns="3" />
	 </Composite.layout>
<Button text="hello" x:style="SWT.PUSH" selectionEvent="onSelection">
</Button>
<Combo x:style="SWT.NONE" modifyEvent="onModifyCombo">
<Combo.items></Combo.items>
</Combo>
</Composite>


I think this should work but i don't have an idea why it doen't.

regards weinma

[Updated on: Fri, 10 August 2012 04:34]

Report message to a moderator

Re: Combo-(viewer) XWT-Databinding trouble [message #901215 is a reply to message #901178] Fri, 10 August 2012 07:33 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 731
Registered: July 2009
Senior Member
Yes, your event method should have a one parameter of type Event.
If it still cannot find the event handler class (x:class), then, there is a class loader issue.
How do you load the Composite?

You could try to provide the event class to the load method of XWT as an option to test whether this is a class loader issue...
Re: Combo-(viewer) XWT-Databinding trouble [message #901227 is a reply to message #901215] Fri, 10 August 2012 08:29 Go to previous messageGo to next message
Jürgen Weinberger is currently offline Jürgen Weinberger
Messages: 35
Registered: August 2012
Member
Hi! Thanks for the reply. I played around a little bit and it seems that you are right with the class loader issue. In my experiments i had to set the XWT.setLoadingContext right and than it worked.

But not with my product code. There I inherit from the TitleAreaDialog and in the createDialogArea() method i load the composite simply with.

XWT.load(parent,url,this)


There it doesn't seem so easy and i don't understand this issue completely. Is there any Documentation about this. How would i provide the EventHandler in the options?
Which classloader should i provide in the DefaultLoadingContext?

regards weinma
Re: Combo-(viewer) XWT-Databinding trouble [message #901236 is a reply to message #901227] Fri, 10 August 2012 09:03 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 731
Registered: July 2009
Senior Member
In the past I have been using something like this:

public abstract class AbstractXWTComposite extends Composite {
	private static Logger log = Logger.getLogger(AbstractXWTComposite.class);
	
	static {
	ILoadingContext lctx = new DefaultLoadingContext(loader) {
		@Override
		public Class<?> loadClass(String name) {
			try {
				Class<?> ret = super.loadClass(name);
				return ret;
			} catch (Exception e) {
				;
			}
			return FrameworkUtil.getBundle(AbstractXWTComposite.class).loadClass(name);
		}
	};
	XWT.setLoadingContext(lctx);	
	}

	public AbstractXWTComposite(Composite parent, int style) {
		super(parent, style);
		setLayout(new FillLayout());
		loadXWT();
	}

	private void loadXWT() {
		log.info("Rendering composite: "
				+ AbstractXWTComposite.this.getClass().getName());

		URL url = getXWTResourceURL();
		Map<String, Object> options = new HashMap<String, Object>();
		options.put(IXWTLoader.CONTAINER_PROPERTY, AbstractXWTComposite.this);
		options.put(IXWTLoader.CLASS_PROPERTY, AbstractXWTComposite.this);

		try {
			Object root = XWTForms.loadWithOptions(url, options);
			AbstractXWTComposite.this.layout();
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
	}

	protected URL getXWTResourceURL() {
		return this.getClass().getResource(
				this.getClass().getSimpleName() + ".xwt");
	}
}


Note the static initialization part which sets the default loading context of XWT to take advantage of the osgi class loading...
Your concrete UI class would just extend that AbstractXWTComposite and additionally define the event methods...
Re: Combo-(viewer) XWT-Databinding trouble [message #901567 is a reply to message #901236] Mon, 13 August 2012 09:08 Go to previous messageGo to next message
Jürgen Weinberger is currently offline Jürgen Weinberger
Messages: 35
Registered: August 2012
Member
Hey!

I tried it today and it was definitely the class loader.
It seems to work now. Thanks a lot for the support Smile
Re: Combo-(viewer) XWT-Databinding trouble [message #901638 is a reply to message #901567] Mon, 13 August 2012 14:09 Go to previous message
Erdal Karaca is currently offline Erdal Karaca
Messages: 731
Registered: July 2009
Senior Member
I think there should be an OSGi aware loading context that just delegates to the bundle's class loader that is active if running in OSGi...
You could file an enhancement request...

Jürgen Weinberger wrote on Mon, 13 August 2012 09:08
Hey!

I tried it today and it was definitely the class loader.
It seems to work now. Thanks a lot for the support Smile

Previous Topic:Use ExtendedObjectSupplier for pure @Inject annotations?
Next Topic:Autosave
Goto Forum:
  


Current Time: Wed Aug 20 20:36:11 EDT 2014

Powered by FUDForum. Page generated in 0.02687 seconds