Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Extending Sapphire Wizard

Revision as of 11:11, 3 September 2011 by Kamesh.sampath.hotmail.com (Talk | contribs) (New page: Sapphire does a great deal of automated work behind the scenes for us in creating Wizards, Editors and Dialog boxes. Sometimes there might be some requirement for us in extending Sapphire ...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Sapphire does a great deal of automated work behind the scenes for us in creating Wizards, Editors and Dialog boxes. Sometimes there might be some requirement for us in extending Sapphire and providing the registrations via plugin.xml.

The Sapphire source distribution has lots of good examples which help us in creating the Wizards, editors and dialogs. the examples show us how to invoke them from command handlers (org.eclipse.ui.handlers) extensions, in this article I show how we can extends the Sapphire Wizard and register it via plugin.xml, thereby allowing us to Categorize our Wizards and invoke them using the Workbench New Wizard dialog.

I take a factitious example that we are creating a Wizard that will create a new Sapphire model interface that extends IModelElement


Lets start with our model elements definition

Model

ISapphireModelDef .java

@GenerateImpl
@XmlRootBinding(elementName = "sapphire-model")
public interface ISapphireModelDef extends IExecutableModelElement {
 
    ModelElementType TYPE = new ModelElementType(ISapphireModelDef.class);
 
    // *** Package ***
 
    @Label(standard = "Model Package")
    @XmlBinding(path = "model-package")
    ValueProperty PROP_MODEL_PACKAGE = new ValueProperty(TYPE, "ModelPackage");
 
    Value<String> getModelPackage();
 
    void setModelPackage(String value);
 
    // *** ModelName ***
 
    @Label(standard = "Model Name")
    @XmlBinding(path = "model-name")
    ValueProperty PROP_MODEL_NAME = new ValueProperty(TYPE, "ModelName");
 
    void setModelName(String value);
 
    void setModelName(JavaTypeName value);
 
    // *** ValueProperties ***
 
    @Type(base = ISModelValueProperty.class)
    @Label(standard = "Value Properties")
    @XmlListBinding(mappings = { @XmlListBinding.Mapping(element = "", type = ISModelTypedValueProperty.class) })
    ListProperty PROP_VALUE_PROPERTIES = new ListProperty(TYPE,
            "ValueProperties");
 
    ModelElementList<ISModelValueProperty> getValueProperties();
 
    // *** Method: execute ***
 
    @DelegateImplementation(ISapphireModelDefOpMethods.class)
    Status execute(ProgressMonitor monitor);
 
}

ISModelPropertyBase.java

@GenerateImpl
public interface ISModelPropertyBase extends IModelElement {
 
    ModelElementType TYPE = new ModelElementType(ISModelPropertyBase.class);
 
    // *** Name ***
 
    @Label(standard = "Name")
    @XmlBinding(path = "name")
    ValueProperty PROP_Name = new ValueProperty(TYPE, "Name");
 
    Value<String> getName();
 
    void setName(String value);
 
    // *** Label ***
 
    @Label(standard = "Label")
    @XmlBinding(path = "label")
    ValueProperty PROP_LABEL = new ValueProperty(TYPE, "Label");
 
    Value<String> getLabel();
 
    void setLabel(String value);
 
    // *** XmlBinding ***
 
    @Label(standard = "Xml Binding")
    @XmlBinding(path = "xml-binding")
    ValueProperty PROP_XML_BINDING = new ValueProperty(TYPE, "XmlBinding");
 
    Value<String> getXmlBinding();
 
    void setXmlBinding(String value);
 
}

ISModelPropertyBase.java

@GenerateImpl
public interface ISModelTypedValueProperty extends ISModelPropertyBase {
    ModelElementType TYPE = new ModelElementType(
            ISModelTypedValueProperty.class);
 
}

ISModelValueProperty.java

@GenerateImpl
public interface ISModelValueProperty extends ISModelPropertyBase {
 
    ModelElementType TYPE = new ModelElementType(ISModelValueProperty.class);
 
 
}

ISapphireModelDefOpMethods.java

public final class ISapphireModelDefOpMethods
{
    public static final Status execute( final ISapphireModelDef context,
                                        final ProgressMonitor monitor )
    {
        // Do something here.
 
        return Status.createOkStatus();
    }
}

Sapphire UI Definition

<?xml version="1.0" encoding="UTF-8"?>
<definition>
    <import>
        <package>org.eclipse.sapphire.model</package>
    </import>
    <wizard>
        <id>new.sapphire.model.creation.wizard</id>
        <label>New Sapphire Model</label>
        <description>This wizard will allow the creation of New Sapphire Models</description>
        <image>icons/sapphire-32.png</image>
        <page>
            <id>basic.properties</id>
            <label>Model Basic Properties</label>
            <description>Define the basic properties of the model like name, package etc.,</description>
            <content>
                <property-editor>ModelPackage</property-editor>
                <property-editor>ModelName</property-editor>
            </content>
        </page>
        <page>
            <id>new-sapphire-model.valueproperties.page</id>
            <label>Value Properties</label>
            <description>Define all value properties for the model</description>
            <content>
                <property-editor>ValueProperties</property-editor>
            </content>
        </page>
    </wizard>
</definition>

Back to the top