diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/model/OWLWorkspace.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/model/OWLWorkspace.java index ffac67b75..5cc07ddd7 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/model/OWLWorkspace.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/model/OWLWorkspace.java @@ -23,7 +23,6 @@ import org.protege.editor.owl.ProtegeOWL; import org.protege.editor.owl.model.entity.OWLEntityCreationSet; import org.protege.editor.owl.model.event.EventType; -import org.protege.editor.owl.model.event.OWLModelManagerChangeEvent; import org.protege.editor.owl.model.event.OWLModelManagerListener; import org.protege.editor.owl.model.inference.*; import org.protege.editor.owl.model.selection.OWLSelectionHistoryManager; @@ -52,7 +51,6 @@ import javax.swing.text.JTextComponent; import java.awt.*; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.io.File; import java.net.MalformedURLException; @@ -67,7 +65,7 @@ * The University Of Manchester
* Medical Informatics Group
* Date: Mar 17, 2006

- + *

* matthew.horridge@cs.man.ac.uk
* www.cs.man.ac.uk/~horridgm

*/ @@ -116,7 +114,7 @@ public class OWLWorkspace extends TabbedWorkspace implements SendErrorReportHand private PrecomputeAction startReasonerAction = new PrecomputeAction(); private PrecomputeAction synchronizeReasonerAction = new PrecomputeAction(); - + private ProtegeOWLAction stopReasonerAction = new StopReasonerAction(); private ExplainInconsistentOntologyAction explainInconsistentOntologyAction = new ExplainInconsistentOntologyAction(); @@ -129,10 +127,11 @@ public class OWLWorkspace extends TabbedWorkspace implements SendErrorReportHand public static final String REASONER_INITIALIZE = "Start reasoner"; public static final String REASONER_RESYNC = "Synchronize reasoner"; - - public static final String REASONER_STOP = "Stop reasoner"; + + public static final String REASONER_STOP = "Stop reasoner"; public static final String REASONER_EXPLAIN = "Explain inconsistent ontology"; + private ErrorLogListener errorLogListener; public OWLEditorKit getOWLEditorKit() { @@ -170,11 +169,9 @@ public void errorLogCleared() { ProtegeApplication.getLogManager().addErrorLogListener(errorLogListener); - backgroundTaskLabel = new BackgroundTaskLabel(ProtegeApplication.getBackgroundTaskManager()); - createActiveOntologyPanel(); reselectionEventTypes.add(EventType.ACTIVE_ONTOLOGY_CHANGED); reselectionEventTypes.add(EventType.ONTOLOGY_RELOADED); @@ -193,8 +190,7 @@ public void errorLogCleared() { owlModelManagerListener = event -> { try { handleModelManagerEvent(event.getType()); - } - catch (Exception t) { + } catch (Exception t) { logger.warn("An error occurred whilst handling a Model Manager Event: {}", t); } }; @@ -256,8 +252,8 @@ private void updateDirtyFlag() { JFrame frame = workspaceManager.getFrame(this); Set dirtyOntologies = getOWLModelManager().getDirtyOntologies(); boolean dirty = false; - for(OWLOntology ont : getOWLModelManager().getOntologies()) { - if(dirtyOntologies.contains(ont)) { + for (OWLOntology ont : getOWLModelManager().getOntologies()) { + if (dirtyOntologies.contains(ont)) { dirty = true; break; } @@ -349,7 +345,7 @@ private void verifySelection(Set entities) { break; } } - if(unreferenced) { + if (unreferenced) { unreferencedEntities.add(entity); } } @@ -440,20 +436,22 @@ protected void initialiseExtraMenuItems(JMenuBar menuBar) { addReasonerListener(menuBar); updateTitleBar(); - JMenu windowMenu = getWindowMenu(menuBar); - if (windowMenu != null) { - windowMenu.addSeparator(); - windowMenu.add(new AbstractAction("Refresh user interface") { - - - public void actionPerformed(ActionEvent e) { - refreshComponents(); - } - }); + Optional menu = getWindowMenu(menuBar); + if (!menu.isPresent()) { + return; } + JMenu windowMenu = menu.get(); + windowMenu.addSeparator(); + windowMenu.add(new AbstractAction("Refresh user interface") { + public void actionPerformed(ActionEvent e) { + refreshComponents(); + } + }); + } private class ExtraReasonerMenuActionPlugin extends ProtegeActionPluginJPFImpl { + protected ExtraReasonerMenuActionPlugin(EditorKit editorKit, IExtension extension) { super(editorKit, extension); } @@ -507,8 +505,8 @@ private List initialiseExtraReasonerMenuActions() { action.putValue(Action.SHORT_DESCRIPTION, toolTipText); } String accelerator = extraReasonerMenuActionPlugin.getAccelerator(); - if(accelerator != null) { - action.putValue(Action.ACCELERATOR_KEY,accelerator); + if (accelerator != null) { + action.putValue(Action.ACCELERATOR_KEY, accelerator); } result.add(action); logger.debug("action = " + action); @@ -524,12 +522,14 @@ private List initialiseExtraReasonerMenuActions() { private void rebuildReasonerMenu(JMenuBar menuBar) { final OWLModelManager mngr = getOWLModelManager(); - JMenu reasonerMenu = getReasonerMenu(menuBar); + Optional menu = getReasonerMenu(menuBar); - if(reasonerMenu == null) { + if (!menu.isPresent()) { return; } + JMenu reasonerMenu = menu.get(); + reasonerMenu.removeAll(); startReasonerAction.setEditorKit(getOWLEditorKit()); @@ -539,7 +539,7 @@ private void rebuildReasonerMenu(JMenuBar menuBar) { synchronizeReasonerAction.setEditorKit(getOWLEditorKit()); synchronizeReasonerAction.putValue(Action.NAME, REASONER_RESYNC); reasonerMenu.add(synchronizeReasonerAction); - + stopReasonerAction.setEditorKit(getOWLEditorKit()); stopReasonerAction.putValue(Action.NAME, REASONER_STOP); reasonerMenu.add(stopReasonerAction); @@ -554,12 +554,12 @@ private void rebuildReasonerMenu(JMenuBar menuBar) { configureAction.putValue(Action.NAME, "Configure..."); reasonerMenu.add(configureAction); - if (extraReasonerMenuActions != null && extraReasonerMenuActions.size() > 0) { - reasonerMenu.addSeparator(); - for (ProtegeAction action : extraReasonerMenuActions) { - reasonerMenu.add(action); - } - } + if (extraReasonerMenuActions != null && extraReasonerMenuActions.size() > 0) { + reasonerMenu.addSeparator(); + for (ProtegeAction action : extraReasonerMenuActions) { + reasonerMenu.add(action); + } + } reasonerMenu.addSeparator(); @@ -608,36 +608,35 @@ public void removed(IExtensionPoint[] extensionPoints) { } - private JMenu getOntologiesMenu(JMenuBar menuBar) { + private Optional getOntologiesMenu(JMenuBar menuBar) { return getMenu(menuBar, "Ontologies"); } - private static JMenu getReasonerMenu(JMenuBar menuBar) { + private static Optional getReasonerMenu(JMenuBar menuBar) { return getMenu(menuBar, "Reasoner"); } - private static JMenu getWindowMenu(JMenuBar menuBar) { + private static Optional getWindowMenu(JMenuBar menuBar) { return getMenu(menuBar, "Window"); } - private static JMenu getMenu(JMenuBar menuBar, String name) { + private static Optional getMenu(JMenuBar menuBar, String name) { for (int i = 0; i < menuBar.getMenuCount(); i++) { JMenu menu = menuBar.getMenu(i); if (menu != null) { if (menu.getText() != null) { if (menu.getText().equals(name)) { - return menu; + return Optional.of(menu); } } } } - return null; + return Optional.absent(); } - private void createActiveOntologyPanel() { JPanel topBarPanel = new JPanel(new GridBagLayout()); @@ -712,7 +711,7 @@ public void actionPerformed(ActionEvent e) { new Insets(0, 0, 0, 0), 0, 0 ) - ); + ); add(topBarPanel, BorderLayout.NORTH); @@ -734,7 +733,7 @@ public void actionPerformed(ActionEvent e) { } public void showSearchDialog() { - if(searchDialog == null) { + if (searchDialog == null) { searchDialog = SearchDialogPanel.createDialog(this, getOWLEditorKit()); Point workspaceLocation = getLocation(); Dimension workspaceSize = getSize(); @@ -796,8 +795,7 @@ private void updateReasonerStatus(boolean changesInProgress) { ReasonerStatus newStatus; try { newStatus = reasonerManager.getReasonerStatus(); - } - catch (ReasonerDiedException reasonerDied) { + } catch (ReasonerDiedException reasonerDied) { newStatus = ReasonerStatus.REASONER_NOT_INITIALIZED; ReasonerUtilities.warnThatReasonerDied(null, reasonerDied); } @@ -809,15 +807,15 @@ private void updateReasonerStatus(boolean changesInProgress) { private void updateReasonerStatus(ReasonerStatus status) { reasonerStatus.setText(status.getDescription()); - + startReasonerAction.setEnabled(status.isEnableInitialization()); startReasonerAction.putValue(Action.SHORT_DESCRIPTION, status.getInitializationTooltip()); - + synchronizeReasonerAction.setEnabled(status.isEnableSynchronization()); synchronizeReasonerAction.putValue(Action.SHORT_DESCRIPTION, status.getSynchronizationTooltip()); - + stopReasonerAction.setEnabled(status.isEnableStop()); - + explainInconsistentOntologyAction.setEnabled(status == ReasonerStatus.INCONSISTENT); KeyStroke shortcut = KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); @@ -897,8 +895,7 @@ private void rebuildOntologyDropDown() { ts.addAll(getOWLModelManager().getOntologies()); ontologiesList.setModel(new DefaultComboBoxModel<>(ts.toArray(new OWLOntology[ts.size()]))); ontologiesList.setSelectedItem(getOWLModelManager().getActiveOntology()); - } - catch (Exception e) { + } catch (Exception e) { logger.error("An error occurred whilst building the ontology list: {}", e); } } @@ -1033,8 +1030,7 @@ public String getIndex() { public URL getDefaultViewConfigFile() { try { return new File(getId() + "-config.xml").toURI().toURL(); - } - catch (MalformedURLException uriex) { + } catch (MalformedURLException uriex) { logger.warn("The default view configuration file is malformed: " + uriex.getMessage()); } return null;