Skip to main content



      Home
Home » Archived » Sapphire » Heterogeneous list with no common property
Heterogeneous list with no common property [message #1060618] Mon, 27 May 2013 06:59 Go to next message
Eclipse UserFriend
Hey,

I'm trying to implement a list storing different types. The gallery examples presents a running implementation. I copied the example and adjusted it for my requirements that slightly differ. My sub types do not have any attributes in common. So my base type does not contain any property, as it is for IChildElement interface. IChildElement contains the StringValue property that is inherited to all subtypes and used to shown in the UI (table).

@GenerateImpl
public interface Base extends IModelElement {
    ModelElementType TYPE = new ModelElementType(Empty.class);
}


Text, Image and Pdf extend Base.

@Type(base = Base.class, possible = { Text.class, Image.class, Pdf.class })
@XmlListBinding
(
   path = "description", 
   mappings = 
   {
       @XmlListBinding.Mapping(element = "text", type = Text.class),
       @XmlListBinding.Mapping(element = "image", type = Image.class), 
       @XmlListBinding.Mapping(element = "pdf", type = Pdf.class)
   }
)
    
ListProperty PROP_DESCRIPTION = new ListProperty(TYPE, "Description");
    
ModelElementList<Empty> getDescription();


The table that shows the types in the UI just executes the toString() method from java.lang.Object and prints the memory address from org.eclipse.sapphire.ui.renderers.swt.DefaultListPropertyEditorRenderer$TableRow. Is there a straightforward way I could provide a label/content provider? I provided editing support in the detail area, but it would be nice if the user could directly change one property of a certain subtype in the table (that I would had to define per type e.g. for Image the URI and for Text the content). Is that possible?

Thank you!

Kon
Re: Heterogeneous list with no common property [message #1060842 is a reply to message #1060618] Tue, 28 May 2013 11:36 Go to previous messageGo to next message
Eclipse UserFriend
Has anyone an clue how to solve this issue? I would like to keep just a simple list on the page without adding additional notes in the tree. I made a screen shot:

http://img716.imageshack.us/img716/2849/screenshotzwo.png

Thank you!
Re: Heterogeneous list with no common property [message #1060846 is a reply to message #1060842] Tue, 28 May 2013 11:54 Go to previous messageGo to next message
Eclipse UserFriend
The table editor for list properties requires at least one property in the base type, but the property does not need to be defined the same across all sub-types. You can vary, XML binding, validation, etc. For instance, you can definite property Content in base type, then bind it to "URI" element for one sub-type, to "Text" element for another sub-type, etc.

For an example, see how ContactAddress type overrides properties in its parent type Address to add XML binding specification.

- Konstantin
Re: Heterogeneous list with no common property [message #1060853 is a reply to message #1060846] Tue, 28 May 2013 12:35 Go to previous messageGo to next message
Eclipse UserFriend
I probably should pay more attention on the examples, even if I already spent some time with them Smile Just in case someone else would like to use my example, here are my adjustments:

@GenerateImpl
public interface Base extends IModelElement {
    ModelElementType TYPE = new ModelElementType(Base.class);
    
    // *** Content ***
    ValueProperty PROP_CONTENT = new ValueProperty(TYPE, "Content");
    Value<String> getContent();
    void setContent(String value);
}


And one sub-type that overrides the Content property.

@GenerateImpl
public interface Image extends Base {
    ModelElementType TYPE = new ModelElementType(Image.class);

    // *** Title ***

    @XmlBinding(path = "title")
    @Label(standard = "Title")
    @Required
    ValueProperty PROP_CONTENT = new ValueProperty(TYPE, Base.PROP_CONTENT);
}


Thank you Konstantin Smile

EDIT: I removed the getter/setter as mentioned by Konstantin. I the first place, I kept the property name as it was (PROP_TITLE). Then the new xml binding didn't work and I had to change the property name to PROP_CONTENT. Obviously the most convenient way is to omit the gettet/setter. Less code, less errors Wink Thank you!

[Updated on: Wed, 29 May 2013 03:15] by Moderator

Re: Heterogeneous list with no common property [message #1060855 is a reply to message #1060853] Tue, 28 May 2013 12:45 Go to previous message
Eclipse UserFriend
You are welcome. Note that you don't have repeat getter and setter methods when overriding a property. Just the property declaration any any overriding/augmenting annotations.

- Konstantin
Previous Topic:Advise for the use of Sapphire with present schema file
Next Topic: Element ordering not according to XSD (with several files)
Goto Forum:
  


Current Time: Fri May 16 20:58:03 EDT 2025

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

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

Back to the top