Skip to content

Commit

Permalink
Closes #525
Browse files Browse the repository at this point in the history
- Closes this issue for the Entities Tab.  Some other more general
mechanism is needed really.
- Also displays OBO style Ids for IRIs that seem to be OBO style Ids.
  • Loading branch information
matthewhorridge committed Sep 8, 2016
1 parent 0362e6b commit 4b013ba
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.protege.editor.owl.ui.view;

import org.protege.editor.owl.OWLEditorKit;
import org.semanticweb.owlapi.model.OWLEntity;

import javax.annotation.Nonnull;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 7 Sep 16
*/
public interface EntityBannerFormatter {

/**
* Formats a banner for the specified entity under the context of the specified editor kit.
* @param entity The entity.
* @param editorKit The editor kit.
* @return A string representing the banner. May be empty.
*/
@Nonnull
String formatBanner(@Nonnull OWLEntity entity, @Nonnull OWLEditorKit editorKit);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.protege.editor.owl.ui.view;

import org.protege.editor.owl.OWLEditorKit;
import org.semanticweb.owlapi.model.OWLEntity;

import javax.annotation.Nonnull;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 7 Sep 16
*/
public class EntityBannerFormatterImpl implements EntityBannerFormatter {

private static final Pattern OBO_STYLE_ID_PATTERN = Pattern.compile("/(\\w+)_(\\d+)$");

@Nonnull
@Override
public String formatBanner(@Nonnull OWLEntity entity, @Nonnull OWLEditorKit editorKit) {
String rendering = editorKit.getOWLModelManager().getRendering(entity);
String iri = entity.getIRI().toString();
String oboStyleId = "";
Matcher oboIdMatcher = OBO_STYLE_ID_PATTERN.matcher(iri);
if(oboIdMatcher.find()) {
oboStyleId = " \u2014 " + oboIdMatcher.group(1) + ":" + oboIdMatcher.group(2);
}
return String.format(
"<html><body><nobr>%s <span style='color: #808080;'>%s \u2014 %s</span><nobr></body></html>",
rendering,
oboStyleId,
iri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.protege.editor.core.util.HandlerRegistration;
import org.protege.editor.owl.model.selection.SelectionDriver;
import org.protege.editor.owl.model.selection.SelectionPlane;
import org.protege.editor.owl.ui.renderer.OWLSystemColors;
import org.protege.editor.owl.ui.util.NothingSelectedPanel;
import org.semanticweb.owlapi.model.*;
import org.slf4j.Logger;
Expand All @@ -17,6 +18,8 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
Expand Down Expand Up @@ -52,9 +55,16 @@ public class SelectedEntityCardView extends AbstractOWLViewComponent implements

private static final Logger logger = LoggerFactory.getLogger(SelectedEntityCardView.class);

private JLabel entityIRILabel;

private EntityBannerFormatter entityBannerFormatter;

protected void initialiseOWLView() throws Exception {
setLayout(new BorderLayout());
entityBannerFormatter = new EntityBannerFormatterImpl();
entityIRILabel = new JLabel();
entityIRILabel.setBorder(BorderFactory.createEmptyBorder(1, 4, 3, 0));
add(entityIRILabel, BorderLayout.NORTH);
add(cardPanel);
cardPanel.setLayout(cardLayout);
cardPanel.add(new NothingSelectedPanel(), BLANK_PANEL);
Expand Down Expand Up @@ -118,6 +128,7 @@ public void reset() {
}

viewsPanes.clear();
entityIRILabel.setText("");
createViewPanes(true);
validate();

Expand All @@ -130,42 +141,49 @@ public void reset() {
private void processSelection() {
OWLObject selectedObject = getOWLWorkspace().getOWLSelectionModel().getSelectedObject();
if(selectedObject == null) {
entityIRILabel.setIcon(null);
entityIRILabel.setText("");
entityIRILabel.setBackground(null);
selectPanel(BLANK_PANEL);
return;
}
if(!(selectedObject instanceof OWLEntity)) {
return;
}
((OWLEntity) selectedObject).accept(new OWLEntityVisitor() {
public void visit(@Nonnull OWLClass cls) {
selectPanel(CLASSES_PANEL);
}
OWLEntity selEntity = (OWLEntity) selectedObject;
String banner = entityBannerFormatter.formatBanner(selEntity, getOWLEditorKit());
entityIRILabel.setIcon(getOWLWorkspace().getOWLIconProvider().getIcon(selEntity));
entityIRILabel.setText(banner);
selEntity.accept(new OWLEntityVisitor() {
public void visit(@Nonnull OWLClass cls) {
selectPanel(CLASSES_PANEL);
}


public void visit(@Nonnull OWLObjectProperty property) {
selectPanel(OBJECT_PROPERTIES_PANEL);
}
public void visit(@Nonnull OWLObjectProperty property) {
selectPanel(OBJECT_PROPERTIES_PANEL);
}


public void visit(@Nonnull OWLDataProperty property) {
selectPanel(DATA_PROPERTIES_PANEL);
}
public void visit(@Nonnull OWLDataProperty property) {
selectPanel(DATA_PROPERTIES_PANEL);
}


public void visit(@Nonnull OWLAnnotationProperty property) {
selectPanel(ANNOTATION_PROPERTIES_PANEL);
}
public void visit(@Nonnull OWLAnnotationProperty property) {
selectPanel(ANNOTATION_PROPERTIES_PANEL);
}


public void visit(@Nonnull OWLNamedIndividual individual) {
selectPanel(INDIVIDUALS_PANEL);
}
public void visit(@Nonnull OWLNamedIndividual individual) {
selectPanel(INDIVIDUALS_PANEL);
}


public void visit(@Nonnull OWLDatatype dataType) {
selectPanel(DATATYPES_PANEL);
}
});
public void visit(@Nonnull OWLDatatype dataType) {
selectPanel(DATATYPES_PANEL);
}
});

}

Expand Down

0 comments on commit 4b013ba

Please sign in to comment.