Skip to content

Commit

Permalink
Fix for #82 and #79
Browse files Browse the repository at this point in the history
Fix for #82 and #79
  • Loading branch information
tviegut committed Feb 22, 2024
1 parent bb1e965 commit 0040764
Show file tree
Hide file tree
Showing 8 changed files with 535 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ protected Template define() {
Group(
TreeViewer("left", true),
TreeViewer("right", true)),
Group(
Row(
Span(ViewCheckBox("concrete", "Set selected classes to concrete when added to the profile")),
Span(ViewCheckBox("required", "Set selected attributes to required when added to the profile"))
)),
Group(
Right(
Row(
Expand Down Expand Up @@ -168,27 +173,32 @@ public void selectionChanged(SelectionChangedEvent event) {

private Picker allLeft = new Picker() {
protected void handle(Node node) {
boolean arePropertiesRequired = getButton("required").getSelection();
boolean isConcrete = getButton("concrete").getSelection();
SortedNode target = getProfileNode();
Collection args = target.profileExpandArgs(node);
if(args.size() < 50 || confirm(node.toString(), args.size())) {
target.profileAddAllDeep(args);
target.profileAddAllDeep(args, isConcrete, arePropertiesRequired);
}
}
};

private Picker anonLeft = new Picker() {
protected void handle(Node node) {
boolean arePropertiesRequired = getButton("required").getSelection();
SortedNode target = getProfileNode();
target.profileAddAnon(node);
target.profileAddAnon(node, false, arePropertiesRequired);
}
};

private Picker toLeft = new Picker() {
protected void handle(Node node) {
boolean arePropertiesRequired = getButton("required").getSelection();
boolean isConcrete = getButton("concrete").getSelection();
SortedNode target = getProfileNode();
Collection args = target.profileExpandArgs(node);
if(args.size() < 50 || confirm(node.toString(), args.size())) {
target.profileAddAll(args);
target.profileAddAll(args, isConcrete, arePropertiesRequired);
}
}
};
Expand Down
82 changes: 78 additions & 4 deletions CIMToolPlugin/src/au/com/langdale/jena/OntModelAdapters.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.hp.hpl.jena.graph.FrontsNode;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;

import au.com.langdale.kena.OntModel;
import au.com.langdale.kena.OntResource;
import au.com.langdale.kena.ResIterator;
import au.com.langdale.kena.ResourceFactory;
import au.com.langdale.ui.binding.BooleanModel;
import au.com.langdale.xmi.UML;
/**
* A set of BooleanModel's that reflect the contents of an ontology model.
*/
Expand Down Expand Up @@ -66,6 +69,41 @@ private static class Annotation extends AdapterBase {
private FrontsNode ident;
private FrontsNode prop;

private static final List<String> NON_EDITABLE_IDENT = new ArrayList<String>();
private static final List<String> EDITABLE_CLASS_IDENT = new ArrayList<String>();
private static final List<String> EDITABLE_ASSOCIATION_IDENT = new ArrayList<String>();

static {
/**
* Class-level stereotypes - imported via XMI/EAP. None
* of these should be editable by the end user as they
* are core stereotypes native to CIM and used within
* The UML. They would automatically be set on a Class,
* attribute, enumeration, etc. during import processing
* of an XMI or EAP file.
*/
NON_EDITABLE_IDENT.add(UML.primitive.getURI());
NON_EDITABLE_IDENT.add(UML.datatype.getURI());
NON_EDITABLE_IDENT.add(UML.cimdatatype.getURI());
NON_EDITABLE_IDENT.add(UML.enumeration.getURI());
NON_EDITABLE_IDENT.add(UML.compound.getURI());
/** attribute-level stereotypes - imported via XMI/EAP */
NON_EDITABLE_IDENT.add(UML.attribute.getURI());
NON_EDITABLE_IDENT.add(UML.enumliteral.getURI());
/** association related stereotypes - imported via XMI/EAP */
NON_EDITABLE_IDENT.add(UML.compositeOf.getURI());
NON_EDITABLE_IDENT.add(UML.ofComposite.getURI());
NON_EDITABLE_IDENT.add(UML.aggregateOf.getURI());
NON_EDITABLE_IDENT.add(UML.ofAggregate.getURI());

/** Stereotypes editable only for top-level Classes in the tree. This doesn't include enumerations. */
EDITABLE_CLASS_IDENT.add(UML.concrete.getURI());
EDITABLE_CLASS_IDENT.add(UML.description.getURI());

/** Stereotypes editable only for associations in the tree. */
EDITABLE_ASSOCIATION_IDENT.add(UML.byreference.getURI());
}

public Annotation(FrontsNode ident, FrontsNode prop, String comment, OntModelProvider context) {
super(comment, context);
this.ident = ident;
Expand All @@ -78,12 +116,48 @@ public boolean isTrue() {
}

public void setTrue(boolean flag) {
OntResource subject = context.getSubject();
if( subject != null )
if(flag)
if(isEditable()){
OntResource subject = context.getSubject();
if(flag) {
subject.addProperty(prop, ident);
else
} else {
subject.removeProperty(prop, ident);
}
}
}

/**
* Method to determine if this Annotation is editable for the currently selected subject.
* The method uses the static List(s) of stereotypes to "test" if a stereotype should be
* allowed to be edited.
*/
public boolean isEditable() {
OntResource subject = context.getSubject();
if((subject == null) || NON_EDITABLE_IDENT.contains(ident.asNode().getURI()) || //
((subject != null) && //
// Indicates it is the profile envelope that is selected...nothing is editable
(!subject.isClass() && !subject.isDatatype()) ||
// A subject that is a datatype indicates that a attribute of type primitive is currently selected...
(subject.isDatatype() && (EDITABLE_CLASS_IDENT.contains(ident.asNode().getURI()) || EDITABLE_ASSOCIATION_IDENT.contains(ident.asNode().getURI()))) || //
// This is relevant for a top-level class that is selected...
(subject.isClass() && !subject.hasProperty(UML.hasStereotype, UML.attribute) && !subject.hasProperty(OWL.unionOf) && !subject.hasProperty(UML.hasStereotype, UML.enumeration) && EDITABLE_ASSOCIATION_IDENT.contains(ident.asNode().getURI())) || //
// This is relevant for a top-level enumeration that is selected...
(subject.isClass() && !subject.hasProperty(UML.hasStereotype, UML.attribute) && !subject.hasProperty(OWL.unionOf) && subject.hasProperty(UML.hasStereotype, UML.enumeration) && (EDITABLE_CLASS_IDENT.contains(ident.asNode().getURI()) || EDITABLE_ASSOCIATION_IDENT.contains(ident.asNode().getURI()))) || //
// This is relevant for an association that is selected...
(subject.isClass() && !subject.hasProperty(UML.hasStereotype, UML.attribute) && subject.hasProperty(OWL.unionOf) && !subject.hasProperty(UML.hasStereotype, UML.enumeration) && (EDITABLE_CLASS_IDENT.contains(ident.asNode().getURI()))) || //
// Remaining checks are for a non-primitive attribute...
(subject.isClass() && subject.hasProperty(UML.hasStereotype, UML.attribute) && //
(EDITABLE_CLASS_IDENT.contains(ident.asNode().getURI()) ||
// The presence of an 'enumeration' stereotype on an attribute indicates that an attribute of that enumeration type is currently selected...
(subject.hasProperty(UML.hasStereotype, UML.enumeration) && EDITABLE_ASSOCIATION_IDENT.contains(ident.asNode().getURI())))))) {
return false;
}
return true;
}

@Override
public String toString() {
return comment + (!isEditable() ? " [" + "Not Modifiable" + "]" : "");
}
}

Expand Down
13 changes: 13 additions & 0 deletions CIMUtil/src/au/com/langdale/jena/JenaTreeModelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public JenaTreeModelBase getModel() {
public String getPackageName() {
return extractPackageName(getBase());
}

/**
* Provide a name for the package or document that contains this
* definition.
*/
public OntResource getPackage() {
return extractPackage(getBase());
}

}

Expand All @@ -59,6 +67,11 @@ else if( source != null ){
return "";
}
}

private OntResource extractPackage(OntResource subject) {
OntResource defin = subject.getResource(RDFS.isDefinedBy);
return defin;
}

/**
* Construct an initially empty tree.
Expand Down
40 changes: 40 additions & 0 deletions CIMUtil/src/au/com/langdale/profiles/ProfileClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ProfileClass {
private OneToManyMap props;
private OntResource baseClass;
private Set classes;
private boolean compoundBase;
private boolean enumeratedBase;
private final OntResource defaultBase;

Expand Down Expand Up @@ -92,7 +93,33 @@ private void analyseBaseClass() {
// System.out.println("Profile with no schema class:");
// System.out.println( clss.describe());
// }
compoundBase = baseClass.hasProperty(UML.hasStereotype, UML.compound);
enumeratedBase = baseClass.hasProperty(UML.hasStereotype, UML.enumeration);
if (baseClass != null) {
if (enumeratedBase) {
if (baseClass.hasProperty(UML.hasStereotype)) {
ResIterator stereotypes = baseClass.listProperties(UML.hasStereotype);
while (stereotypes.hasNext()) {
OntResource stereo = stereotypes.nextResource();
if (!clss.hasProperty(UML.hasStereotype, stereo))
clss.addProperty(UML.hasStereotype, stereo);
}
}
} else {
ResIterator clazzes = baseClass.listSuperClasses(true);
while (clazzes.hasNext()) {
OntResource clazz = clazzes.nextResource();
if (clazz.hasProperty(UML.hasStereotype)) {
ResIterator stereotypes = clazz.listProperties(UML.hasStereotype);
while (stereotypes.hasNext()) {
OntResource stereo = stereotypes.nextResource();
if (!clss.hasProperty(UML.hasStereotype, stereo))
clss.addProperty(UML.hasStereotype, stereo);
}
}
}
}
}
}

/**
Expand Down Expand Up @@ -264,6 +291,15 @@ public OntResource createAllValuesFrom(OntResource prop, boolean required) {
label = prop.getLocalName();
child.addLabel(label, null);

if (prop.hasProperty(UML.hasStereotype)) {
ResIterator stereotypes = prop.listProperties(UML.hasStereotype);
while (stereotypes.hasNext()) {
OntResource stereo = stereotypes.nextResource();
if (!child.hasProperty(UML.hasStereotype, stereo))
child.addProperty(UML.hasStereotype, stereo);
}
}

OntResource res = model.createAllValuesFromRestriction(null, prop, child);
clss.addSuperClass(res);
props.put(prop, res);
Expand Down Expand Up @@ -395,6 +431,10 @@ public boolean isEnumerated() {
return enumeratedBase;
}

public boolean isCompound() {
return compoundBase;
}

public boolean isReference() {
return hasStereotype(UML.byreference) || clss.hasSuperClass(MESSAGE.Reference, false);
}
Expand Down
Loading

0 comments on commit 0040764

Please sign in to comment.