Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules sorting #819

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions protege-editor-core/src/main/resources/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@
<editorKitId value="any"/>
</extension>

<extension id="menu.window.timestamp" point="org.protege.editor.core.application.EditorKitMenuAction">
<name value="Timestamp log / console"/>
<path value="org.protege.editor.core.application.menu.window/SlotE-A"/>
<toolTip value="Prints a timestamp and optional message into the logs or console"/>
<class value="org.protege.editor.core.ui.action.TimestampOutputAction"/>
<editorKitId value="any"/>
</extension>

<extension id="menu.window.showlog" point="org.protege.editor.core.application.EditorKitMenuAction">
<name value="Show log..."/>
<path value="org.protege.editor.core.application.menu.window/SlotE-B"/>
<toolTip value="Prints a timestamp and optional message into the logs or console"/>
<class value="org.protege.editor.core.log.ShowLogAction"/>
<editorKitId value="any"/>
</extension>

<!-- Help menu -->

<extension id="menu.HelpMenu" point="org.protege.editor.core.application.EditorKitMenuAction">
Expand Down Expand Up @@ -261,30 +277,6 @@
<class value="org.protege.editor.core.update.PluginPreferencesPanel"/>
</extension>

<!-- Log preferences -->

<extension id="ui.preferences.update"
point="org.protege.editor.core.application.preferencespanel">
<label value="Log"/>
<class value="org.protege.editor.core.log.LogPreferencesPanel"/>
</extension>

<extension id="menu.window.timestamp" point="org.protege.editor.core.application.EditorKitMenuAction">
<name value="Timestamp log / console"/>
<path value="org.protege.editor.core.application.menu.window/SlotE-A"/>
<toolTip value="Prints a timestamp and optional message into the logs or console"/>
<class value="org.protege.editor.core.ui.action.TimestampOutputAction"/>
<editorKitId value="any"/>
</extension>

<extension id="menu.window.showlog" point="org.protege.editor.core.application.EditorKitMenuAction">
<name value="Show log..."/>
<path value="org.protege.editor.core.application.menu.window/SlotE-B"/>
<toolTip value="Prints a timestamp and optional message into the logs or console"/>
<class value="org.protege.editor.core.log.ShowLogAction"/>
<editorKitId value="any"/>
</extension>

<!-- Other startup actions -->

<extension id ="AltCheckForPluginsAction"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.protege.editor.owl.model.swrl;

import org.protege.editor.core.prefs.Preferences;
import org.protege.editor.core.prefs.PreferencesManager;

public class SWRLRulePreferences {

private static SWRLRulePreferences instance;

private static final String SWRL_RULE_PREFS_KEY = "SWRL_RULE_PREFS";

private static final String SORT_ON_ANN_PRP_KEY = "SORT_ON_ANN_PRP";
private static final String SHOW_ANN_PRP_WITH_RULE_KEY = "SHOW_ANN_PRP_WITH_RULE";

public static SWRLRulePreferences getInstance() {
if (instance == null)
instance = new SWRLRulePreferences();

return instance;
}

private static Preferences getPreferences() {
return PreferencesManager.getInstance().getApplicationPreferences(SWRL_RULE_PREFS_KEY);
}

public boolean getSortRulesOnAnnPrp() {
return getPreferences().getBoolean(SORT_ON_ANN_PRP_KEY, false);
}

public void setSortRulesOnAnnPrp(boolean sort) {
getPreferences().putBoolean(SORT_ON_ANN_PRP_KEY, sort);
}

public boolean getShowAnnPrpWithRule() {
return getPreferences().getBoolean(SHOW_ANN_PRP_WITH_RULE_KEY, false);
}

public void setShowAnnPrpWithRule(boolean show) {
getPreferences().putBoolean(SHOW_ANN_PRP_WITH_RULE_KEY, show);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class AbstractOWLFrameSectionRow<R extends Object, A extends OWL

private Object userObject;

private OWLFrameSection section;
protected OWLFrameSection section;

protected AbstractOWLFrameSectionRow(OWLEditorKit owlEditorKit, OWLFrameSection<R,A,E> section, OWLOntology ontology,
R rootObject, A axiom) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OWLOntology, SWRLRule, SWRLRule> 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("<demph>").append(value).append("</demph> = ");
}

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;
}
}
Original file line number Diff line number Diff line change
@@ -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<OWLAnnotation> annotations) {
return annotations.stream()
.filter(a -> a.getProperty().getIRI().toString().equals("http://www.w3.org/2000/01/rdf-schema#comment"))
.findAny().orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
*
*
*/

import org.semanticweb.owlapi.model.OWLOntologyManager;

/**
* Author: Matthew Horridge<br>
* The University Of Manchester<br>
* Bio-Health Informatics Group<br>
* Date: 06-Jul-2007<br><br>
* Date: 06-Jul-2007<br>
* <br>
*/
public class SWRLRulesFrame extends AbstractOWLFrame<OWLOntology> {

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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<br>
* The University Of Manchester<br>
* Bio-Health Informatics Group<br>
* Date: 06-Jul-2007<br><br>
* Date: 06-Jul-2007<br>
* <br>
*/
public class SWRLRulesFrameSection extends AbstractOWLFrameSection<OWLOntology, SWRLRule, SWRLRule> {

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<SWRLRule> 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<SWRLRule> 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<OWLFrameSectionRow<OWLOntology, SWRLRule, SWRLRule>> getRowComparator() {
return null;
}
public Comparator<OWLFrameSectionRow<OWLOntology, SWRLRule, SWRLRule>> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Loading