diff --git a/protege-editor-core/src/main/resources/plugin.xml b/protege-editor-core/src/main/resources/plugin.xml
index 62b51a3dd..d194a9de4 100644
--- a/protege-editor-core/src/main/resources/plugin.xml
+++ b/protege-editor-core/src/main/resources/plugin.xml
@@ -214,6 +214,22 @@
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
section, OWLOntology ontology,
R rootObject, A axiom) {
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/AnnotatedSWRLRuleFrameSectionRow.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/AnnotatedSWRLRuleFrameSectionRow.java
new file mode 100644
index 000000000..6c12dba27
--- /dev/null
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/AnnotatedSWRLRuleFrameSectionRow.java
@@ -0,0 +1,60 @@
+package org.protege.editor.owl.ui.frame;
+
+import java.util.Iterator;
+
+import org.protege.editor.owl.OWLEditorKit;
+import org.protege.editor.owl.model.swrl.SWRLRulePreferences;
+import org.semanticweb.owlapi.model.OWLAnnotation;
+import org.semanticweb.owlapi.model.OWLObject;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.SWRLRule;
+
+/*
+ *
+ *
+ * @author wvw
+ *
+ */
+
+public class AnnotatedSWRLRuleFrameSectionRow extends SWRLRuleFrameSectionRow {
+
+ public AnnotatedSWRLRuleFrameSectionRow(OWLEditorKit owlEditorKit,
+ OWLFrameSection section, OWLOntology ontology, OWLOntology rootObject,
+ SWRLRule axiom) {
+
+ super(owlEditorKit, section, ontology, rootObject, axiom);
+ }
+
+ @Override
+ public String getRendering() {
+ SWRLRulePreferences prefs = SWRLRulePreferences.getInstance();
+ if (!prefs.getShowAnnPrpWithRule())
+ return super.getRendering();
+
+ StringBuilder sb = new StringBuilder();
+
+ OWLAnnotation ann = SWRLRuleUtils.findAnnotation(axiom.getAnnotations());
+ if (ann != null) {
+ String value = ann.getValue().asLiteral().get().getLiteral();
+
+ sb.append("").append(value).append(" = ");
+ }
+
+ for (Iterator extends OWLObject> it = getManipulatableObjects().iterator(); it.hasNext();) {
+ OWLObject obj = it.next();
+ sb.append(getObjectRendering(obj));
+ if (it.hasNext()) {
+ sb.append(getDelimeter());
+ }
+ }
+ sb.append(getSuffix());
+
+ return sb.toString();
+ }
+
+ // TODO
+ @Override
+ public String getTooltip() {
+ return null;
+ }
+}
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRuleUtils.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRuleUtils.java
new file mode 100644
index 000000000..4bbd34789
--- /dev/null
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRuleUtils.java
@@ -0,0 +1,14 @@
+package org.protege.editor.owl.ui.frame;
+
+import java.util.Set;
+
+import org.semanticweb.owlapi.model.OWLAnnotation;
+
+public class SWRLRuleUtils {
+
+ public static OWLAnnotation findAnnotation(Set annotations) {
+ return annotations.stream()
+ .filter(a -> a.getProperty().getIRI().toString().equals("http://www.w3.org/2000/01/rdf-schema#comment"))
+ .findAny().orElse(null);
+ }
+}
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRulesFrame.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRulesFrame.java
index 09db4f861..173cfb9a5 100644
--- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRulesFrame.java
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRulesFrame.java
@@ -7,19 +7,23 @@
*
*
*/
-
+import org.semanticweb.owlapi.model.OWLOntologyManager;
/**
* Author: Matthew Horridge
* The University Of Manchester
* Bio-Health Informatics Group
- * Date: 06-Jul-2007
+ * Date: 06-Jul-2007
+ *
*/
public class SWRLRulesFrame extends AbstractOWLFrame {
+ public SWRLRulesFrame(OWLEditorKit editorKit) {
+ super(editorKit.getModelManager().getOWLOntologyManager());
+ addSection(new SWRLRulesFrameSection(editorKit, this));
+ }
- public SWRLRulesFrame(OWLEditorKit editorKit) {
- super(editorKit.getModelManager().getOWLOntologyManager());
- addSection(new SWRLRulesFrameSection(editorKit, this));
- }
+ public SWRLRulesFrame(OWLOntologyManager owlOntologyManager) {
+ super(owlOntologyManager);
+ }
}
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRulesFrameSection.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRulesFrameSection.java
index 01b0a7ca2..1bd20a94c 100644
--- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRulesFrameSection.java
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SWRLRulesFrameSection.java
@@ -1,5 +1,7 @@
package org.protege.editor.owl.ui.frame;
+import java.util.Comparator;
+
import org.protege.editor.owl.OWLEditorKit;
import org.protege.editor.owl.ui.editor.OWLObjectEditor;
import org.protege.editor.owl.ui.editor.SWRLRuleEditor;
@@ -8,66 +10,61 @@
import org.semanticweb.owlapi.model.OWLOntologyChange;
import org.semanticweb.owlapi.model.SWRLRule;
-import java.util.Comparator;
-
-
/*
* Copyright (C) 2007, University of Manchester
*
*
*/
-
/**
* Author: Matthew Horridge
* The University Of Manchester
* Bio-Health Informatics Group
- * Date: 06-Jul-2007
+ * Date: 06-Jul-2007
+ *
*/
public class SWRLRulesFrameSection extends AbstractOWLFrameSection {
+ public SWRLRulesFrameSection(OWLEditorKit editorKit, OWLFrame extends OWLOntology> owlFrame) {
+ super(editorKit, "Rules", "Rule", owlFrame);
+ }
- public SWRLRulesFrameSection(OWLEditorKit editorKit, OWLFrame extends OWLOntology> owlFrame) {
- super(editorKit, "Rules", "Rule", owlFrame);
- }
-
-
- protected SWRLRule createAxiom(SWRLRule object) {
- return object;
- }
-
-
- public OWLObjectEditor getObjectEditor() {
- return new SWRLRuleEditor(getOWLEditorKit());
- }
-
+ protected SWRLRulesFrameSection(OWLEditorKit editorKit, String label, String rowLabel,
+ OWLFrame extends OWLOntology> frame) {
- public boolean canAdd() {
- return true;
- }
+ super(editorKit, label, rowLabel, frame);
+ }
+ protected SWRLRule createAxiom(SWRLRule object) {
+ return object;
+ }
- protected void refill(OWLOntology ontology) {
- for (SWRLRule rule : ontology.getAxioms(AxiomType.SWRL_RULE)) {
- addRow(new SWRLRuleFrameSectionRow(getOWLEditorKit(), this, ontology, ontology, rule));
- }
- }
+ public OWLObjectEditor getObjectEditor() {
+ return new SWRLRuleEditor(getOWLEditorKit());
+ }
+ public boolean canAdd() {
+ return true;
+ }
- protected void clear() {
- }
+ protected void refill(OWLOntology ontology) {
+ for (SWRLRule rule : ontology.getAxioms(AxiomType.SWRL_RULE))
+ addRow(new AnnotatedSWRLRuleFrameSectionRow(getOWLEditorKit(), this, ontology, ontology, rule));
+ }
+ protected void clear() {
+ }
- public Comparator> getRowComparator() {
- return null;
- }
+ public Comparator> getRowComparator() {
+ return null;
+ }
- @Override
- protected boolean isResettingChange(OWLOntologyChange change) {
- if (!change.isAxiomChange()) {
- return false;
- }
- return change.getAxiom() instanceof SWRLRule;
- }
+ @Override
+ protected boolean isResettingChange(OWLOntologyChange change) {
+ if (!change.isAxiomChange()) {
+ return false;
+ }
+ return change.getAxiom() instanceof SWRLRule;
+ }
}
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SortedSWRLRulesFrame.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SortedSWRLRulesFrame.java
new file mode 100644
index 000000000..bc13992ca
--- /dev/null
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SortedSWRLRulesFrame.java
@@ -0,0 +1,20 @@
+package org.protege.editor.owl.ui.frame;
+
+import org.protege.editor.owl.OWLEditorKit;
+
+/**
+ *
+ *
+ * @author wvw
+ *
+ */
+
+public class SortedSWRLRulesFrame extends SWRLRulesFrame {
+
+ // when passing editorKit as a whole to super constructor,
+ // sorting doesn't work
+ public SortedSWRLRulesFrame(OWLEditorKit editorKit) {
+ super(editorKit.getModelManager().getOWLOntologyManager());
+ addSection(new SortedSWRLRulesFrameSection(editorKit, this));
+ }
+}
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SortedSWRLRulesFrameSection.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SortedSWRLRulesFrameSection.java
new file mode 100644
index 000000000..4f40d1148
--- /dev/null
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/SortedSWRLRulesFrameSection.java
@@ -0,0 +1,76 @@
+package org.protege.editor.owl.ui.frame;
+
+import java.util.Comparator;
+
+import org.protege.editor.owl.OWLEditorKit;
+import org.protege.editor.owl.model.swrl.SWRLRulePreferences;
+import org.semanticweb.owlapi.model.OWLAnnotation;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.SWRLRule;
+
+/**
+ *
+ *
+ * @author wvw
+ *
+ */
+
+public class SortedSWRLRulesFrameSection extends SWRLRulesFrameSection {
+
+ public SortedSWRLRulesFrameSection(OWLEditorKit editorKit, OWLFrame extends OWLOntology> owlFrame) {
+ super(editorKit, owlFrame);
+ }
+
+ protected SortedSWRLRulesFrameSection(OWLEditorKit editorKit, String label, String rowLabel,
+ OWLFrame extends OWLOntology> frame) {
+
+ super(editorKit, label, rowLabel, frame);
+ }
+
+ @Override
+ public Comparator> getRowComparator() {
+ SWRLRulePreferences prefs = SWRLRulePreferences.getInstance();
+
+ if (!prefs.getSortRulesOnAnnPrp())
+ return null;
+
+ return new Comparator>() {
+
+ @Override
+ public int compare(OWLFrameSectionRow o1,
+ OWLFrameSectionRow o2) {
+
+ return cmp(o1.getAxiom(), o2.getAxiom());
+ }
+ };
+ }
+
+ private int cmp(SWRLRule rule1, SWRLRule rule2) {
+ OWLAnnotation ann1 = SWRLRuleUtils.findAnnotation(rule1.getAnnotations());
+ OWLAnnotation ann2 = SWRLRuleUtils.findAnnotation(rule2.getAnnotations());
+
+ // if both comments are null, rule1 == rule2
+ // if comment1 is null, rule1 > rule2 (i.e., put rule1 at the back)
+ // if comment2 is null, rule2 > rule1 (i.e., put rule2 at the back)
+ if (ann1 == null) {
+ if (ann2 == null)
+ return 0;
+ else
+ return 1;
+
+ } else {
+ if (ann2 == null)
+ return -1;
+ }
+
+ String value1 = ann1.getValue().asLiteral().get().getLiteral();
+ String value2 = ann2.getValue().asLiteral().get().getLiteral();
+
+ return doCmp(value1, value2);
+ }
+
+ // hook for subclasses
+ protected int doCmp(String value1, String value2) {
+ return value1.compareTo(value2);
+ }
+}
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/framelist/OWLFrameList.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/framelist/OWLFrameList.java
index 74ef239ad..6ef3616bc 100644
--- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/framelist/OWLFrameList.java
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/framelist/OWLFrameList.java
@@ -105,6 +105,10 @@ public class OWLFrameList extends MList implements LinkedObjectComponent, Dro
public OWLFrameList(OWLEditorKit editorKit, OWLFrame frame) {
+ this(editorKit, frame, true, true);
+ }
+
+ public OWLFrameList(OWLEditorKit editorKit, OWLFrame frame, boolean showExplainBtn, boolean showAnnotBtn) {
this.editorKit = editorKit;
this.frame = frame;
@@ -134,9 +138,11 @@ public void mouseDragged(MouseEvent e) {
createPopupMenu();
inferredRowButtons = new ArrayList<>();
- inferredRowButtons.add(new ExplainButton(e -> invokeExplanationHandler()));
+ if (showExplainBtn)
+ inferredRowButtons.add(new ExplainButton(e -> invokeExplanationHandler()));
- axiomAnnotationButton = new AxiomAnnotationButton(event -> invokeAxiomAnnotationHandler());
+ if (showAnnotBtn)
+ axiomAnnotationButton = new AxiomAnnotationButton(event -> invokeAxiomAnnotationHandler());
changeListenerMediator = new ChangeListenerMediator();
addListSelectionListener(selListener);
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/preferences/SWRLRulePreferencesPanel.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/preferences/SWRLRulePreferencesPanel.java
new file mode 100644
index 000000000..008cb5fdd
--- /dev/null
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/preferences/SWRLRulePreferencesPanel.java
@@ -0,0 +1,57 @@
+package org.protege.editor.owl.ui.preferences;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JCheckBox;
+
+import org.protege.editor.core.ui.preferences.PreferencesLayoutPanel;
+import org.protege.editor.owl.model.swrl.SWRLRulePreferences;
+import org.protege.editor.owl.ui.view.SWRLRulesViewComponent;
+
+/**
+ *
+ *
+ * @author wvw
+ *
+ */
+
+public class SWRLRulePreferencesPanel extends OWLPreferencesPanel {
+
+ private static final long serialVersionUID = 1L;
+
+ private JCheckBox sortRulesOnAnnPrpCheckBox;
+ private JCheckBox showAnnPrpWithRuleCheckBox;
+
+ @Override
+ public void initialise() throws Exception {
+ setLayout(new BorderLayout());
+
+ PreferencesLayoutPanel panel = new PreferencesLayoutPanel();
+ add(panel, BorderLayout.NORTH);
+ panel.addGroup("Display");
+
+ SWRLRulePreferences prefs = SWRLRulePreferences.getInstance();
+
+ sortRulesOnAnnPrpCheckBox = new JCheckBox("Sort rules based on rdfs:comment", prefs.getSortRulesOnAnnPrp());
+ panel.addGroupComponent(sortRulesOnAnnPrpCheckBox);
+
+ showAnnPrpWithRuleCheckBox = new JCheckBox("Show rdfs:comment with rule", prefs.getShowAnnPrpWithRule());
+ panel.addGroupComponent(showAnnPrpWithRuleCheckBox);
+ }
+
+ @Override
+ public void dispose() throws Exception {
+ }
+
+ @Override
+ public void applyChanges() {
+ SWRLRulePreferences prefs = SWRLRulePreferences.getInstance();
+
+ prefs.setSortRulesOnAnnPrp(sortRulesOnAnnPrpCheckBox.isSelected());
+ prefs.setShowAnnPrpWithRule(showAnnPrpWithRuleCheckBox.isSelected());
+
+ // TODO has no effect on sorting of already shown rule list
+ // getOWLEditorKit().getOWLWorkspace().refreshComponents();
+ SWRLRulesViewComponent.preferencesUpdated();
+ }
+}
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/renderer/OWLCellRenderer.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/renderer/OWLCellRenderer.java
index c46043f0c..d69e59392 100644
--- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/renderer/OWLCellRenderer.java
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/renderer/OWLCellRenderer.java
@@ -743,6 +743,10 @@ private void prepareTextPane(Object value, boolean selected) {
theVal = theVal.replace('\n', ' ');
theVal = theVal.replaceAll(" [ ]+", " ");
}
+
+ TheValueStyler theStyler = new TheValueStyler();
+ theVal = theStyler.processTheValue(theVal);
+
textPane.setText(theVal);
if (commentedOut) {
textPane.setText(textPane.getText());
@@ -811,6 +815,8 @@ private void prepareTextPane(Object value, boolean selected) {
doc.setCharacterAttributes(0, doc.getLength(), selectionForeground, false);
}
}
+
+ theStyler.applyTheValueStyles(doc);
}
@@ -1327,4 +1333,47 @@ protected void paintComponent(Graphics g) {
}
}
}
+
+ private class TheValueStyler {
+
+ private String[] tagNames = { "demph" };
+ private Style[] styles = { feintStyle };
+
+ private List startIdxs = new ArrayList<>();
+ private List endIdxs = new ArrayList<>();
+ private List