Following the current implementation of the "dependencies" collection on the 
ToDoItem class, the following code template would be of interest for "ordered 
collections".

I've defined it with name "iscss" and description "Collection (set-sorted)", 
just as an example.


// {{ ${CollectionName} (Collection)
${:import(java.util.SortedSet,java.util.TreeSet,org.apache.isis.applib.annotation.MemberOrder)}private
 SortedSet<${ElementType}> ${collectionName} = new TreeSet<${ElementType}>();
@MemberOrder(sequence="1")
public SortedSet<${ElementType}> get${CollectionName}() {
        return ${collectionName};
}
public void set${CollectionName}(final SortedSet<${ElementType}> 
${collectionName}) {
        this.${collectionName} = ${collectionName};
}
// }}


Also, is there any annotation that could allow the "addTo[CollectionName]" and 
"removeFrom[CollectionName]" to be available on the user interface?

In most collections, those names are "just valid" for the Ubiquitous Language.

If not available, or if is not recommended breaking the rule of not publishing 
to the UI the programming model methods , I could add a new template based on 
the "iscmod" like this one. which I've called "iscmoda" - "Collection modify 
(with actions)":

${:import(org.apache.isis.applib.annotation.MemberOrder)}// Action.
@MemberOrder(name="${collectionName}", sequence="1")
public ${enclosing_type} insertInto${CollectionName}(final ${ElementType} 
${elementName}) {
        addTo${CollectionName}(${elementName});
        return this;
}

// Programming model.
public void addTo${CollectionName}(final ${ElementType} ${elementName}) {
        // check for no-op
        if (${elementName} == null || 
                get${CollectionName}().contains(${elementName})) {
                return;
        }
        // associate new
        get${CollectionName}().add(${elementName});
    // additional business logic
    onAddTo${CollectionName}(${elementName});
}

// Action.
@MemberOrder(name="${collectionName}", sequence="2")
public ${enclosing_type} deleteFrom${CollectionName}(final ${ElementType} 
${elementName}) {
        removeFrom${CollectionName}(${elementName});
        return this;
}

// Programming model.
public void removeFrom${CollectionName}(final ${ElementType} ${elementName}) {
        // check for no-op
        if (${elementName} == null || 
                !get${CollectionName}().contains(${elementName})) {
                return;
        }
        // dissociate existing
        get${CollectionName}().remove(${elementName});
    // additional business logic
    onRemoveFrom${CollectionName}(${elementName});
}
protected void onAddTo${CollectionName}(final ${ElementType} ${elementName}) {
}
protected void onRemoveFrom${CollectionName}(final ${ElementType} 
${elementName}) {
}



Just for all those reasons, I've defined a new template, "iscssa" - "Collection 
(set-sorted-with actions)" that riquires 4 inputs for a collection with 
"add/insert" and "delete/remove" actions:

// {{ ${CollectionName} (Collection)
${:import(java.util.SortedSet,java.util.TreeSet,org.apache.isis.applib.annotation.MemberOrder)}private
 SortedSet<${ElementType}> ${collectionName} = new TreeSet<${ElementType}>();
@MemberOrder(sequence="1")
public SortedSet<${ElementType}> get${CollectionName}() {
        return ${collectionName};
}
public void set${CollectionName}(final SortedSet<${ElementType}> 
${collectionName}) {
        this.${collectionName} = ${collectionName};
}

@MemberOrder(name="${collectionName}", sequence="1")
public ${enclosing_type} insertInto${CollectionName}(final ${ElementType} 
${elementName}) {
        addTo${CollectionName}(${elementName});
        return this;
}

// Programming model.
public void addTo${CollectionName}(final ${ElementType} ${elementName}) {
        // check for no-op
        if (${elementName} == null || 
                get${CollectionName}().contains(${elementName})) {
                return;
        }
        // associate new
        get${CollectionName}().add(${elementName});
    // additional business logic
    onAddTo${CollectionName}(${elementName});
}

// Action.
@MemberOrder(name="${collectionName}", sequence="2")
public ${enclosing_type} deleteFrom${CollectionName}(final ${ElementType} 
${elementName}) {
        removeFrom${CollectionName}(${elementName});
        return this;
}

// Programming model.
public void removeFrom${CollectionName}(final ${ElementType} ${elementName}) {
        // check for no-op
        if (${elementName} == null || 
                !get${CollectionName}().contains(${elementName})) {
                return;
        }
        // dissociate existing
        get${CollectionName}().remove(${elementName});
    // additional business logic
    onRemoveFrom${CollectionName}(${elementName});
}
protected void onAddTo${CollectionName}(final ${ElementType} ${elementName}) {
}
protected void onRemoveFrom${CollectionName}(final ${ElementType} 
${elementName}) {
}
// }}



Reply via email to