Skip to content

Commit

Permalink
Improve editing of imports for use cases 1 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
bdionne committed Apr 24, 2020
1 parent 4967789 commit a16a9ef
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>gov.nih.nci</groupId>
<artifactId>nci-edit-tab</artifactId>
<version>1.0.9-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<name>Edit Tab</name>
<description>An editing tab for NCI's complex editing operations</description>
<packaging>bundle</packaging>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/gov/nih/nci/ui/EditPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAnnotationSubject;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyChange;

import gov.nih.nci.ui.dialog.ComplexPropChooser;
Expand Down Expand Up @@ -264,6 +265,15 @@ public void setSelectedClass(OWLClass cls) {
}

Optional<String> cps = NCIEditTab.currentTab().getCode(cls);
if (!cps.isPresent()) {
for (OWLOntology ont : getEditorKit().getOWLModelManager().getActiveOntologies()) {
Optional<String> temp_cps = NCIEditTab.currentTab().getCode(cls, ont);
if (temp_cps.isPresent()) {
cps = temp_cps;
}
}

}

if (cps.isPresent()) {
codeText.setText(cps.get());
Expand All @@ -284,8 +294,12 @@ public void setSelectedClass(OWLClass cls) {
}
complexPropertyPanel.repaint();

list.setReadOnly(NCIEditTab.currentTab().isImported(cls));

list.setRootObject(cls);

if (cls != null) {
gen_props.setReadOnly(NCIEditTab.currentTab().isImported(cls));
gen_props.setRootObject(cls.getIRI());
}

Expand Down
66 changes: 45 additions & 21 deletions src/main/java/gov/nih/nci/ui/NCIAnnotationFrameSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,51 @@ protected void clear() {


protected void refill(OWLOntology ontology) {
boolean hidden = false;
final OWLAnnotationSubject annotationSubject = getRootObject();
for (OWLAnnotationAssertionAxiom ax : ontology.getAnnotationAssertionAxioms(annotationSubject)) {
if (!getOWLEditorKit().getWorkspace().isHiddenAnnotationURI(ax.getAnnotation().getProperty().getIRI().toURI()) &&
!propsToExclude.contains(ax.getProperty())) {
if (!readOnlyProps.contains(ax.getProperty())) {
addRow(new NCIOWLAnnotationsFrameSectionRow(getOWLEditorKit(), this, ontology, annotationSubject, propsToExclude, ax));
} else {
addRow(new NCIOWLAnnotationsFrameSectionRow(getOWLEditorKit(), this, ontology, annotationSubject, propsToExclude, ax, false));

}
} else {
hidden = true;
}
}
if (hidden) {
setLabel(LABEL + " (some annotations are hidden)");
} else {
setLabel(LABEL);
}


boolean hidden = false;
final OWLAnnotationSubject annotationSubject = getRootObject();

if (NCIEditTab.currentTab().isCurrentOntology(ontology)) {
if (ontology.containsClassInSignature(annotationSubject.asIRI().get())) {
for (OWLAnnotationAssertionAxiom ax : ontology.getAnnotationAssertionAxioms(annotationSubject)) {
if (!getOWLEditorKit().getWorkspace()
.isHiddenAnnotationURI(ax.getAnnotation().getProperty().getIRI().toURI())
&& !propsToExclude.contains(ax.getProperty())) {
if (!readOnlyProps.contains(ax.getProperty())) {
addRow(new NCIOWLAnnotationsFrameSectionRow(getOWLEditorKit(), this, ontology,
annotationSubject, propsToExclude, ax));
} else {
addRow(new NCIOWLAnnotationsFrameSectionRow(getOWLEditorKit(), this, ontology,
annotationSubject, propsToExclude, ax, false));

}
} else {
hidden = true;
}
}
}
} else {
if (ontology.containsClassInSignature(annotationSubject.asIRI().get())) {

for (OWLAnnotationAssertionAxiom ax : ontology.getAnnotationAssertionAxioms(annotationSubject)) {
if (!getOWLEditorKit().getWorkspace()
.isHiddenAnnotationURI(ax.getAnnotation().getProperty().getIRI().toURI())) {
addRow(new NCIOWLAnnotationsFrameSectionRow(getOWLEditorKit(), this, ontology,
annotationSubject, new HashSet<OWLAnnotationProperty>(), ax, false));

} else {
hidden = true;
}
}
}

}
if (hidden) {
setLabel(LABEL + " (some annotations are hidden)");
} else {
setLabel(LABEL);
}

}


Expand Down
37 changes: 37 additions & 0 deletions src/main/java/gov/nih/nci/ui/NCIEditTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ public String getUserId() {

private OWLOntology ontology;

public boolean isCurrentOntology(OWLOntology ont) {
return ont.getOntologyID() == ontology.getOntologyID();
}

public boolean isImported(OWLClass c) {
return !(c.getIRI().getNamespace().equalsIgnoreCase(
ontology.getOntologyID().getOntologyIRI().get().getIRIString() + "#"));
}

private static ArrayList<EditTabChangeListener> event_listeners = new ArrayList<EditTabChangeListener>();

public static void addListener(EditTabChangeListener l) {
Expand Down Expand Up @@ -2198,6 +2207,34 @@ public Optional<String> getCode(OWLNamedObject oobj) {
}
}

public Optional<String> getCode(OWLNamedObject oobj, OWLOntology ont) {
// TODO: fall back to IRI if no label
if (oobj != null) {
Set<OWLAnnotationAssertionAxiom> axioms = ont.annotationAssertionAxioms(oobj.getIRI()).
collect(Collectors.toSet());
if (axioms.isEmpty()) {
return Optional.of("");
}
for (OWLAnnotation annotation : annotationObjects(ont.annotationAssertionAxioms(oobj.getIRI()), NCIEditTabConstants.CODE_PROP).
collect(Collectors.toSet())) {
OWLAnnotationValue av = annotation.getValue();
Optional<OWLLiteral> ol = av.asLiteral();
if (ol.isPresent()) {
return Optional.of(ol.get().getLiteral());
}
}

if (!topOrBot(oobj)) {

JOptionPane.showMessageDialog(this, oobj.getIRI().getShortForm() + " should have a code property, using IRI short form instead",
"Warning", JOptionPane.WARNING_MESSAGE);
}
return Optional.of(oobj.getIRI().getShortForm());
} else {
return Optional.empty();
}
}

public Optional<OWLAnnotationValue> getSemanticType(OWLClass cls) {

for (OWLAnnotation annotation : annotationObjects(ontology.annotationAssertionAxioms(cls.getIRI()), SEMANTIC_TYPE).
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/gov/nih/nci/ui/NCIOWLFrameList.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class NCIOWLFrameList<R> extends OWLFrameList {

private boolean read_only = false;

public void setReadOnly(boolean b) {
//super.setReadOnly(b);
read_only = b;
}

private OWLEditorKit editorKit;

private List<OWLAnnotationProperty> annotationProps;
Expand Down Expand Up @@ -68,6 +73,7 @@ public NCIOWLFrameList(OWLEditorKit editorKit, OWLFrame<R> frame) {
}

protected List<MListButton> getButtons(Object value) {
List<MListButton> buttons = new ArrayList<MListButton>();
if (read_only) {

} else if (isComplexProperty(value)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/update.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=nci-edit-tab
version=1.0.9
download=https://github.com/ncievs/nci-edit-tab/releases/download/nci-edit-tab-1.0.9/nci-edit-tab-1.0.9-SNAPSHOT.jar
version=1.1.0
download=https://github.com/ncievs/nci-edit-tab/releases/download/nci-edit-tab-1.1.0/nci-edit-tab-1.1.0-SNAPSHOT.jar
name=NCI Edit Tab
readme=https://raw.githubusercontent.com/ncievs/nci-edit-tab/master/src/main/resources/readme.html
license=https://raw.githubusercontent.com/ncievs/nci-edit-tab/master/LICENSE
Expand Down

0 comments on commit a16a9ef

Please sign in to comment.