private void selectEntity() { Optional<OWLEntity> selectedEntity = searchPanel.getSelectedEntity(); if (selectedEntity.isPresent()) { editorKit.getOWLWorkspace().getOWLSelectionModel().setSelectedEntity(selectedEntity.get()); editorKit.getOWLWorkspace().displayOWLEntity(selectedEntity.get()); } }
/** * This method makes sure is used to setup a new/fresh OBDA model. This is done by replacing the * instance this.obdacontroller (the OBDA model) with a new object. On creation listeners for the * datasources, mappings and queries are setup so that changes in these trigger and ontology * change. * * <p>Additionally, this method configures all available OBDAOWLReasonerFacotry objects to have a * reference to the newly created OBDA model and to the global preference object. This is * necessary so that the factories are able to pass the OBDA model to the reasoner instances when * they are created. */ private void setupNewOBDAModel() { OBDAModel activeOBDAModel = getActiveOBDAModel(); if (activeOBDAModel != null) { return; } activeOBDAModel = dfac.getOBDAModel(); activeOBDAModel.addSourcesListener(dlistener); activeOBDAModel.addMappingsListener(mlistener); queryController.addListener(qlistener); OWLModelManager mmgr = owlEditorKit.getOWLWorkspace().getOWLModelManager(); Set<OWLOntology> ontologies = mmgr.getOntologies(); for (OWLOntology ontology : ontologies) { // Setup the entity declarations for (OWLClass c : ontology.getClassesInSignature()) { OClass pred = ofac.createClass(c.getIRI().toString()); activeOBDAModel.declareClass(pred); } for (OWLObjectProperty r : ontology.getObjectPropertiesInSignature()) { ObjectPropertyExpression pred = ofac.createObjectProperty(r.getIRI().toString()); activeOBDAModel.declareObjectProperty(pred); } for (OWLDataProperty p : ontology.getDataPropertiesInSignature()) { DataPropertyExpression pred = ofac.createDataProperty(p.getIRI().toString()); activeOBDAModel.declareDataProperty(pred); } } // Setup the prefixes PrefixOWLOntologyFormat prefixManager = PrefixUtilities.getPrefixOWLOntologyFormat(mmgr.getActiveOntology()); // addOBDACommonPrefixes(prefixManager); PrefixManagerWrapper prefixwrapper = new PrefixManagerWrapper(prefixManager); activeOBDAModel.setPrefixManager(prefixwrapper); OWLOntology activeOntology = mmgr.getActiveOntology(); String defaultPrefix = prefixManager.getDefaultPrefix(); if (defaultPrefix == null) { OWLOntologyID ontologyID = activeOntology.getOntologyID(); defaultPrefix = ontologyID.getOntologyIRI().toURI().toString(); } activeOBDAModel.getPrefixManager().addPrefix(PrefixManager.DEFAULT_PREFIX, defaultPrefix); // Add the model URI modelUri = activeOntology.getOntologyID().getOntologyIRI().toURI(); obdamodels.put(modelUri, activeOBDAModel); }
@Override protected void initialiseOWLView() throws Exception { // Retrieve the editor kit. final OWLEditorKit editor = getOWLEditorKit(); controller = (OBDAModelManager) editor.get(OBDAModelImpl.class.getName()); controller.addListener(this); OBDAModel obdaModel = controller.getActiveOBDAModel(); TargetQueryVocabularyValidator validator = new TargetQueryValidator(obdaModel); // Init the Mapping Manager panel. mappingPanel = new MappingManagerPanel(obdaModel, validator); editor .getOWLWorkspace() .getOWLSelectionModel() .addListener( new OWLSelectionModelListener() { @Override public void selectionChanged() throws Exception { OWLEntity entity = editor.getOWLWorkspace().getOWLSelectionModel().getSelectedEntity(); if (entity == null) return; if (!entity.isTopEntity()) { String shortf = entity.getIRI().getFragment(); if (shortf == null) { String iri = entity.getIRI().toString(); shortf = iri.substring(iri.lastIndexOf("/")); } mappingPanel.setFilter("pred:" + shortf); } else { mappingPanel.setFilter(""); } } }); datasourceSelector = new DatasourceSelector(controller.getActiveOBDAModel()); datasourceSelector.addDatasourceListListener(mappingPanel); // Construt the layout of the panel. JPanel selectorPanel = new JPanel(); selectorPanel.setLayout(new GridBagLayout()); JLabel label = new JLabel("Select datasource: "); label.setFont(new Font("Dialog", Font.BOLD, 12)); label.setForeground(new Color(53, 113, 163)); // label.setBackground(new java.awt.Color(153, 153, 153)); // label.setFont(new java.awt.Font("Arial", 1, 11)); // label.setForeground(new java.awt.Color(153, 153, 153)); label.setPreferredSize(new Dimension(119, 14)); GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new Insets(5, 5, 5, 5); selectorPanel.add(label, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new Insets(5, 5, 5, 5); selectorPanel.add(datasourceSelector, gridBagConstraints); selectorPanel.setBorder(new TitledBorder("Datasource selection")); mappingPanel.setBorder(new TitledBorder("Mapping manager")); setLayout(new BorderLayout()); add(mappingPanel, BorderLayout.CENTER); add(selectorPanel, BorderLayout.NORTH); }
/** * Gets the icon for an entity. * * @param entity The entity. * @return The icon or null if the entity does not have an icon. */ private Icon getIcon(OWLObject entity) { return editorKit.getOWLWorkspace().getOWLIconProvider().getIcon(entity); }