From 0df464914ae2f0d8418149b15738bcd0fa3a7f39 Mon Sep 17 00:00:00 2001 From: Matthew Horridge Date: Wed, 18 May 2016 08:34:14 -0700 Subject: [PATCH] Fixed some issues with imports loading - Save the catalog when the save action is performed --- .../editor/owl/model/OWLModelManagerImpl.java | 15 +++++++++++++++ .../editor/owl/model/io/OntologySaver.java | 1 + .../ui/ontology/imports/AddImportsStrategy.java | 12 ++++-------- .../wizard/page/ImportConfirmationPage.java | 1 + 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/model/OWLModelManagerImpl.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/model/OWLModelManagerImpl.java index 800f164ec..f5e655ddf 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/model/OWLModelManagerImpl.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/model/OWLModelManagerImpl.java @@ -492,6 +492,7 @@ public void save(OWLOntology ont) throws OWLOntologyStorageException { .addOntology(ont, format, documentIRI) .build(); saver.saveOntologies(); + ensureCatalogFileExists(); manager.setOntologyDocumentIRI(ont, documentIRI); logger.info("Saved ontology {} to {} in {} format", ont.getOntologyID(), documentIRI, format); @@ -516,6 +517,20 @@ public void save(OWLOntology ont) throws OWLOntologyStorageException { } } + private void ensureCatalogFileExists() { + try { + OWLOntology activeOntology = getActiveOntology(); + IRI ontologyDocumentIRI = manager.getOntologyDocumentIRI(activeOntology); + if("file".equals(ontologyDocumentIRI.getScheme())) { + File file = new File(ontologyDocumentIRI.toURI()); + File parentDirectory = file.getParentFile(); + getOntologyCatalogManager().ensureCatalogExists(parentDirectory); + } + } catch (IllegalArgumentException e) { + logger.error("A problem occurred when trying to save the catalog file: {}", e.getMessage()); + } + } + /** * @throws OWLOntologyStorageException if a problem occurs during the save * @deprecated - this method would require user interaction - use OWLEditorKit.saveAs() instead diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/model/io/OntologySaver.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/model/io/OntologySaver.java index 582e61528..6090e06f4 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/model/io/OntologySaver.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/model/io/OntologySaver.java @@ -89,6 +89,7 @@ private Void saveOntologyInternal() throws OWLOntologyStorageException { IRI documentIRI = descriptor.getDocumentIRI(); dlg.setSubMessage(String.format("Location: %s", formatIRI(documentIRI))); ontology.saveOntology(descriptor.getDocumentFormat(), documentIRI); + } return null; } diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/ontology/imports/AddImportsStrategy.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/ontology/imports/AddImportsStrategy.java index b42ba87f8..db252b845 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/ontology/imports/AddImportsStrategy.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/ontology/imports/AddImportsStrategy.java @@ -62,7 +62,7 @@ public void addImports() { } private void addImportsInOtherThread() { - ListenableFuture> future = service.submit(() -> loadImportsInternal()); + ListenableFuture> future = service.submit(this::loadImportsInternal); Futures.addCallback(future, new FutureCallback>() { @Override public void onSuccess(List result) { @@ -105,16 +105,12 @@ private List loadImportsInternal() { if (!man.contains(importParameters.getOntologyID())) { try { OWLOntologyManager loadingManager = OWLManager.createConcurrentOWLOntologyManager(); - PriorityCollection iriMappers = loadingManager.getIRIMappers(); - iriMappers.clear(); - iriMappers.add(new UserResolvedIRIMapper(new MissingImportHandlerUI(editorKit))); - iriMappers.add(new WebConnectionIRIMapper()); - iriMappers.add(new AutoMappedRepositoryIRIMapper(editorKit.getOWLModelManager().getOntologyCatalogManager())); - + loadingManager.getIRIMappers() + .add(man.getIRIMappers()); ProgressDialogOntologyLoaderListener listener = new ProgressDialogOntologyLoaderListener(dlg, logger); loadingManager.addOntologyLoaderListener(listener); loadingManager.loadOntologyFromOntologyDocument( - new IRIDocumentSource(importedOntologyDocumentIRI), + new IRIDocumentSource(IRI.create(physicalLocation)), new OWLOntologyLoaderConfiguration().setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT)); loadingManager.removeOntologyLoaderListener(listener); // editorKit.getModelManager().fireEvent(EventType.ONTOLOGY_LOADED); diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/ontology/imports/wizard/page/ImportConfirmationPage.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/ontology/imports/wizard/page/ImportConfirmationPage.java index ecff2b379..809847434 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/ontology/imports/wizard/page/ImportConfirmationPage.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/ontology/imports/wizard/page/ImportConfirmationPage.java @@ -28,6 +28,7 @@ public class ImportConfirmationPage extends AbstractOWLWizardPanel { public static final String ID = "ImportConfirmationPage"; private JComponent importedOntologiesComponent; + private TitledBorder titledBorder; private Object backPanelDescriptor;