Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sapphire » Sapphire for a "viewer" application: two questions
Sapphire for a "viewer" application: two questions [message #1041239] Sun, 14 April 2013 21:11 Go to next message
Ellen Badgley is currently offline Ellen Badgley
Messages: 35
Registered: October 2012
Member
I'm looking at implementing a viewer for an XML output file (containing model results), and I have a couple of questions about how Sapphire might be used for this.

1) The output XML contains a "snapshot" of the input XML configuration file (for which I have a separate Sapphire model and editor). I want this original data to be viewable but not updateable. Can this be accomplished at the UI level, or is @ReadOnly the only way to set an element as, well, read-only?

2) I'd like to include a custom SWT component that is hover-sensitive and will control displays within another linked viewer. To include this component on a FormEditorPage, should it extend SapphirePart (such that it can be used in a <custom/> element)? I'm having difficulty finding examples of this.
Re: Sapphire for a "viewer" application: two questions [message #1041457 is a reply to message #1041239] Mon, 15 April 2013 06:01 Go to previous messageGo to next message
Greg Amerson is currently offline Greg Amerson
Messages: 116
Registered: March 2010
Senior Member
With regards to 1), you can do this by using property inheritance. Simply create another modelElement that inherits from existing one. For the particular property you want to treat as read only, redefine the property but instead of putting a String for the propertyname, put a reference to the super-class'es property field. Then on this sub-class property mark it with @ReadOnly annotation.

Then in this new viewer, create a "snapshot" model using this new subclass model element that has the new @ReadOnly property instead of the normal element where this property is editable. The sapphire UI in this new viewer will show the field as readonly.

Example superclass element:
@GenerateImpl
public interface Node extends IModelElement 
{
	ModelElementType TYPE = new ModelElementType( Node.class );

	// *** Name ***

	@XmlBinding( path = "name" )
	@Label( standard = "&name" )
	@Required
	ValueProperty PROP_NAME = new ValueProperty( TYPE, "Name" );

	Value<String> getName();
	void setName( String value );

}


Subclass element where you want to "override" the property editor behavior:

@GenerateImpl
public interface ReadOnlyNode extends Node
{
    ModelElementType TYPE = new ModelElementType( ReadOnlyNode.class );

    @ReadOnly
    ValueProperty PROP_NAME = new ValueProperty( TYPE, Node.PROP_NAME );

}

[Updated on: Mon, 15 April 2013 06:03]

Report message to a moderator

Re: Sapphire for a "viewer" application: two questions [message #1041843 is a reply to message #1041457] Mon, 15 April 2013 16:54 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin Komissarchik
Messages: 940
Registered: July 2009
Senior Member
Quote:
1) The output XML contains a "snapshot" of the input XML configuration file (for which I have a separate Sapphire model and editor). I want this original data to be viewable but not updateable. Can this be accomplished at the UI level, or is @ReadOnly the only way to set an element as, well, read-only?


In addition to the override pattern that Greg has described, you can also make a writable property read-only in UI by using "read.only" hint in sdef for the property editor. I haven't tried this exact scenario, but you should be able to make the value of the "read.only" hint a template variable in sdef that you can set in sdef's part include constructs.

Quote:
2) I'd like to include a custom SWT component that is hover-sensitive and will control displays within another linked viewer. To include this component on a FormEditorPage, should it extend SapphirePart (such that it can be used in a <custom/> element)? I'm having difficulty finding examples of this.


To use <custom/> element in sdef, you would indeed need to implement SapphirePart. There isn't an example of this in samples, but existing implementation in sapphire.ui should be informative. Maybe start with a simple one like LabelPart.

PS: For ease of reading and responding, it is best to restrict one thread to one topic.
Re: Sapphire for a "viewer" application: two questions [message #1042555 is a reply to message #1041843] Tue, 16 April 2013 15:11 Go to previous message
Ellen Badgley is currently offline Ellen Badgley
Messages: 35
Registered: October 2012
Member
(Sorry about the dual topics; I will split them up in the future.)

Re: 1) Thanks to both of you for suggestions. Greg, I was not aware of that override pattern but that will be very helpful in the future. Konstantin, adding the "read.only" hint with a value of "true" did the trick as far as my output "editor" is concerned. The custom SapphirePart I need will be used for another purpose, not viewing the "snapshotted" original scenario element, so hints like this are certainly sufficient for the time being.

Re: 2): thanks for the feedback, and I'll start with LabelPart as a simple example.
Previous Topic:Survey : How did you first hear about Sapphire?
Next Topic:Instructions on exporting sapphire plugin
Goto Forum:
  


Current Time: Mon Sep 22 16:17:21 GMT 2014

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

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