Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sapphire » How to programmatically add elements to a Sapphire list?
How to programmatically add elements to a Sapphire list? [message #1497003] Wed, 03 December 2014 13:10 Go to next message
Dmitri Pisarenko is currently offline Dmitri PisarenkoFriend
Messages: 24
Registered: September 2014
Junior Member
Hello!

I have following model:

public interface IMyModel extends Element {
	ElementType TYPE = new ElementType(IMyModel.class);

	@Type(base=ISomeElement.class)
	@Label( standard = "Some element" )
    ListProperty PROP_SOME_ELEMENTS = new ListProperty( TYPE, "SomeElements" );
    ElementList<ISomeElement> getSomeElements();
    void setSomeElements(final ElementList<ISomeElement> value);    
}

public interface ISomeElement extends Element {
	ElementType TYPE = new ElementType(ISomeElement.class);

	// Name

	@Label(standard = "Name")
	@Required
	ValueProperty PROP_NAME = new ValueProperty(TYPE, "Name");
	Value<String> getName();
	void setName(String name);
}


When I try to create an instance of IMyModel and then a ISomeElement instance to it, I get an error.

final IMyModel sample = IMyModel.TYPE.instantiate();

final ISomeElement someElement = ISomeElement.TYPE.instantiate();
someElement.setName("Some name");

sample.getSomeElements().add(someElement);

The error is caused by this piece of code in org.eclipse.sapphire.ElementList.add(T):

public boolean add( final T object )
{
    throw new UnsupportedOperationException();
}

How am I supposed to add elements to a list programmatically?

Note that I need this to be able to run tests on classes, which use IMyModel as input.

Thanks in advance

Dmitri Pisarenko
Re: How to programmatically add elements to a Sapphire list? [message #1497067 is a reply to message #1497003] Wed, 03 December 2014 14:13 Go to previous messageGo to next message
Greg Amerson is currently offline Greg AmersonFriend
Messages: 119
Registered: March 2010
Senior Member
final ISomeElement someElement = sample.getSomeElements().insert();
Re: How to programmatically add elements to a Sapphire list? [message #1497072 is a reply to message #1497067] Wed, 03 December 2014 14:18 Go to previous message
Dmitri Pisarenko is currently offline Dmitri PisarenkoFriend
Messages: 24
Registered: September 2014
Junior Member
Thanks!
Previous Topic:What class/interface do I need to extend/implement to create a custom Sapphire property editor?
Next Topic:What is the best way to add tree node for an optional xml child element?
Goto Forum:
  


Current Time: Wed Sep 19 22:47:06 GMT 2018

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

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

Back to the top