UseOWLClassesPanel

From Protege Wiki
Jump to: navigation, search

How to use the OWL Classes Panel in your own application

The recommended way is to use the edu.stanford.smi.protegex.owl.ui.dialogs.SelectClassPanel class. It will provide you with the same view of the classes tree as the one showed in the OWL Classes Tab.

The code below shows how to use the classes panel in a JFrame:

    SelectClassPanel panel = new SelectClassPanel(owlModel, rootClses, false, true);

    JFrame f = new JFrame();
    f.setSize(300, 700);
    f.setContentPane(panel);
    f.setVisible(true);


The arguments of the SelectClassesPanel constructor are:

  • the OWLModel owlModel
  • Collection rootClses - e.g. can be a collection containing just owl:Thing
  • boolean multiple - allows multiple selection in the classes tree or not
  • boolean editable - allows or not the creation of subclasses and siblings (by showing the create icons)


Note: If you loaded the OWL ontology by using the Project methods (e.g. Project.load(String path, Collection errors)) then the system classes (e.g. owl:Class, rdf:Property, etc.) will be hidden by default.

If you load the OWL ontology by using the ProtegeOWL methods (e.g. ProtegeOWL.createJenaOWLModelFromURI(someURI)) then you will need to use the method from below to hide the system frames:

public static void makeSystemClassesHidden(OWLModel owlModel) {
    Collection systemFrames = new HashSet(owlModel.getSystemFrames().getFrames());
    systemFrames.addAll(owlModel.getOWLSystemResources());
		
    for (Iterator iterator = systemFrames.iterator(); iterator.hasNext();) {
        Frame frame = (Frame) iterator.next();
        frame.setVisible(false);
    }
    owlModel.getOWLThingClass().setVisible(true);
    owlModel.getProject().setDisplayHiddenClasses(false);
}

Call the makeSystemClassesHidden method before the call to the constructor for SelectClassPanel.

Example

You can download from here the binaries and source code for an example Tab plugin that shows two SelectClassesPanel side by side. The left one shows the pizza ontology and the right one the koala ontology.

To install the plugin, just unzip the archive in the Protege plugin folder. Then open Protege, create a new OWL/RDF file and enable the TwoClassesTressTab from Project menu -> Configure. Below is a screenshot of the plugin.

TwoClassesTreesTab.png