From 0ba82105947cabbe3ca9a897f8b9026048c50dde Mon Sep 17 00:00:00 2001 From: Stefan Borgwardt Date: Tue, 31 May 2022 14:20:12 +0200 Subject: [PATCH 1/4] sorting and disabling functionality for ExplanationServices --- .../owl/ui/explanation/ExplanationDialog.java | 45 ++---- .../ui/explanation/ExplanationManager.java | 55 ++++++- .../explanation/ExplanationPreferences.java | 69 ++++++++ .../ExplanationPreferencesGeneralPanel.java | 153 ++++++++++++++---- .../explanation/SortedPluginsTableModel.java | 103 ++++++++++++ 5 files changed, 359 insertions(+), 66 deletions(-) create mode 100644 protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferences.java create mode 100644 protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/SortedPluginsTableModel.java diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationDialog.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationDialog.java index 9dfaac875..0b5009d5e 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationDialog.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationDialog.java @@ -1,22 +1,13 @@ package org.protege.editor.owl.ui.explanation; -import org.protege.editor.core.prefs.Preferences; -import org.protege.editor.core.prefs.PreferencesManager; -import org.protege.editor.owl.model.inference.ReasonerPreferences; import org.semanticweb.owlapi.model.OWLAxiom; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.Collection; public class ExplanationDialog extends JPanel { - public static final String PREFERENCES_SET_KEY = "EXPLANATION_PREFS_SET"; - - public static final String DEFAULT_EXPLANATION_ID = "PREFERRED_PLUGIN_ID"; - private JPanel explanationContainer; private ExplanationResult explanation; @@ -46,22 +37,27 @@ public ExplanationDialog(ExplanationManager explanationManager, OWLAxiom axiom) private JComboBox createComboBox(Collection explanationServices) { ExplanationService[] teacherArray = explanationServices.toArray(new ExplanationService[explanationServices.size()]); final JComboBox selector = new JComboBox<>(teacherArray); + final ExplanationPreferences prefs = ExplanationPreferences.create().load(); if (teacherArray.length > 0) { ExplanationService selected = teacherArray[0]; - String id = getDefaultPluginId(); - if (id != null) { - for (ExplanationService t : explanationServices) { - if (id.equals(t.getPluginId())) { - selected = t; - } - } - } + if (prefs.useLastExplanationService) { + String id = prefs.defaultExplanationService; + if (id != null) { + for (ExplanationService t : explanationServices) { + if (id.equals(t.getPluginId())) { + selected = t; + } + } + } + } selector.setSelectedItem(selected); explanation = selected.explain(axiom); } selector.addActionListener(e -> { ExplanationService t = (ExplanationService) selector.getSelectedItem(); - setDefaultPluginId(t.getPluginId()); + prefs.load(); + prefs.defaultExplanationService = t.getPluginId(); + prefs.save(); explanationContainer.removeAll(); if (explanation != null) { explanation.dispose(); @@ -73,19 +69,6 @@ private JComboBox createComboBox(Collection explanationServices = new HashSet<>(); - + private final Collection explanationServices = new ArrayList<>(); + + private final Collection enabledServices = new ArrayList<>(); + private final Collection openedExplanations = new HashSet<>(); public ExplanationManager(OWLEditorKit editorKit) { @@ -37,16 +42,50 @@ public ExplanationManager(OWLEditorKit editorKit) { public void reload() { ExplanationPluginLoader loader = new ExplanationPluginLoader(editorKit); - explanationServices.clear(); + // use TreeMap for alphabetical ordering + Map sortedExplanationServices = new TreeMap<>(); for (ExplanationPlugin plugin : loader.getPlugins()) { ExplanationService teacher = null; try { teacher = plugin.newInstance(); teacher.initialise(); + sortedExplanationServices.put(teacher.getPluginId(), teacher); + } catch (Exception e) { + logger.error("An error occurred whilst initialising an explanation service {}.", plugin.getName(), e); + } + } + + // add ExplanationServices in the order defined in the preferences + final ExplanationPreferences prefs = ExplanationPreferences.create().load(); + explanationServices.clear(); + for (String id : prefs.explanationServicesList) { + ExplanationService teacher = sortedExplanationServices.get(id); + if (teacher != null) { explanationServices.add(teacher); + sortedExplanationServices.remove(id); } - catch (Exception e) { - logger.error("An error occurred whilst initialising an explanation service {}.", plugin.getName(), e); + } + + if (!sortedExplanationServices.isEmpty()) { + // add new ExplanationServices (which do not occur in the preferences yet) in + // alphabetical order at the end + for (ExplanationService teacher : sortedExplanationServices.values()) { + explanationServices.add(teacher); + } + } + + // update preferences according to current list (adding new and removing old + // ExplanationServices) + prefs.explanationServicesList = new ArrayList<>(); + for (ExplanationService teacher : explanationServices) { + prefs.explanationServicesList.add(teacher.getPluginId()); + } + prefs.save(); + + enabledServices.clear(); + for (ExplanationService teacher : explanationServices) { + if (!prefs.disabledExplanationServices.contains(teacher.getPluginId())) { + enabledServices.add(teacher); } } } @@ -64,8 +103,8 @@ public Collection getExplainers() { } public Collection getTeachers(OWLAxiom axiom) { - Set smartTeachers = new HashSet<>(); - for (ExplanationService teacher : explanationServices) { + Collection smartTeachers = new ArrayList<>(); + for (ExplanationService teacher : enabledServices) { if (teacher.hasExplanation(axiom)) { smartTeachers.add(teacher); } @@ -74,7 +113,7 @@ public Collection getTeachers(OWLAxiom axiom) { } public boolean hasExplanation(OWLAxiom axiom) { - for (ExplanationService explanationService : explanationServices) { + for (ExplanationService explanationService : enabledServices) { if (explanationService.hasExplanation(axiom)) { return true; } diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferences.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferences.java new file mode 100644 index 000000000..02be8da7f --- /dev/null +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferences.java @@ -0,0 +1,69 @@ +package org.protege.editor.owl.ui.explanation; + +import java.util.Collections; +import java.util.List; + +import org.protege.editor.core.prefs.Preferences; +import org.protege.editor.core.prefs.PreferencesManager; + +public class ExplanationPreferences { + + private static final String PREFERENCES_SET_KEY_ = "EXPLANATION_PREFS_SET", + DEFAULT_EXPLANATION_ID_ = "PREFERRED_PLUGIN_ID", + USE_LAST_EXPLANATION_SERVICE_KEY_ = "USE_LAST_EXPLANATION_SERVICE", + EXPLANATION_SERVICES_LIST_KEY_ = "EXPLANATION_SERVICES_LIST", + DISABLED_EXPLANATION_SERVICES_KEY_ = "DISABLED_EXPLANATION_SERVICES"; + + private final static String DEFAULT_DEFAULT_EXPLANATION_ID_ = null; + private final static boolean DEFAULT_USE_LAST_EXPLANATION_SERVICE_ = true; + private final static List DEFAULT_EXPLANATION_SERVICES_LIST_ = Collections.emptyList(); + private final static List DEFAULT_DISABLED_EXPLANATION_SERVICES_ = Collections.emptyList(); + + public String defaultExplanationService; + public boolean useLastExplanationService; + public List explanationServicesList; + public List disabledExplanationServices; + + private ExplanationPreferences() { + // use create() + } + + public static ExplanationPreferences create() { + return new ExplanationPreferences().reset(); + } + + private static Preferences getPrefs() { + PreferencesManager prefMan = PreferencesManager.getInstance(); + return prefMan.getPreferencesForSet(PREFERENCES_SET_KEY_, ExplanationPreferences.class); + } + + public ExplanationPreferences load() { + Preferences prefs = getPrefs(); + defaultExplanationService = prefs.getString(DEFAULT_EXPLANATION_ID_, DEFAULT_DEFAULT_EXPLANATION_ID_); + useLastExplanationService = prefs.getBoolean(USE_LAST_EXPLANATION_SERVICE_KEY_, + DEFAULT_USE_LAST_EXPLANATION_SERVICE_); + explanationServicesList = prefs.getStringList(EXPLANATION_SERVICES_LIST_KEY_, + DEFAULT_EXPLANATION_SERVICES_LIST_); + disabledExplanationServices = prefs.getStringList(DISABLED_EXPLANATION_SERVICES_KEY_, + DEFAULT_DISABLED_EXPLANATION_SERVICES_); + return this; + } + + public ExplanationPreferences save() { + Preferences prefs = getPrefs(); + prefs.putString(DEFAULT_EXPLANATION_ID_, defaultExplanationService); + prefs.putBoolean(USE_LAST_EXPLANATION_SERVICE_KEY_, useLastExplanationService); + prefs.putStringList(EXPLANATION_SERVICES_LIST_KEY_, explanationServicesList); + prefs.putStringList(DISABLED_EXPLANATION_SERVICES_KEY_, disabledExplanationServices); + return this; + } + + public ExplanationPreferences reset() { + defaultExplanationService = DEFAULT_DEFAULT_EXPLANATION_ID_; + useLastExplanationService = DEFAULT_USE_LAST_EXPLANATION_SERVICE_; + explanationServicesList = DEFAULT_EXPLANATION_SERVICES_LIST_; + disabledExplanationServices = DEFAULT_DISABLED_EXPLANATION_SERVICES_; + return this; + } + +} diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java index 5a60c2433..0e3f30b00 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java @@ -3,10 +3,16 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; -import javax.swing.DefaultListModel; -import javax.swing.JList; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JRadioButton; import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; import org.protege.editor.core.ui.preferences.PreferencesLayoutPanel; import org.protege.editor.owl.ui.preferences.OWLPreferencesPanel; @@ -15,30 +21,123 @@ public class ExplanationPreferencesGeneralPanel extends OWLPreferencesPanel { private static final long serialVersionUID = -3354987384223578780L; + private JRadioButton buttonLast, buttonFirst; + private SortedPluginsTableModel tableModel; + + @Override + public void initialise() throws Exception { + setLayout(new BorderLayout()); + PreferencesLayoutPanel panel = new PreferencesLayoutPanel(); + add(panel, BorderLayout.NORTH); + addDefaultExplanationServiceComponent(panel); + addInstalledExplanationServicesComponent(panel); + loadFrom(ExplanationPreferences.create().load()); + } + @Override - public void initialise() throws Exception { - setLayout(new BorderLayout()); - PreferencesLayoutPanel panel = new PreferencesLayoutPanel(); - add(panel, BorderLayout.NORTH); - - panel.addGroup("Installed explanation services"); - DefaultListModel pluginModel = new DefaultListModel<>(); - ExplanationManager manager = new ExplanationManager(getOWLEditorKit()); - Collection services = manager.getExplainers(); - for (ExplanationService service : services) - pluginModel.addElement(service.getName()); - JList pluginList = new JList<>(pluginModel); - pluginList.setToolTipText("Plugins that provide explanation facilities"); - JScrollPane pluginInfoScrollPane = new JScrollPane(pluginList); - pluginInfoScrollPane.setPreferredSize(new Dimension(300, 100)); - panel.addGroupComponent(pluginInfoScrollPane); - } - - @Override - public void dispose() throws Exception { - } - - @Override - public void applyChanges() { - } + public void dispose() throws Exception { + } + + @Override + public void applyChanges() { + ExplanationPreferences prefs = ExplanationPreferences.create(); + saveTo(prefs); + prefs.save(); + getOWLEditorKit().getModelManager().getExplanationManager().reload(); + } + + private void loadFrom(ExplanationPreferences prefs) { + if (prefs.useLastExplanationService) { + buttonLast.setSelected(true); + } else { + buttonFirst.setSelected(true); + } + tableModel.setPluginIds(prefs.explanationServicesList); + tableModel.setDisabledIds(prefs.disabledExplanationServices); + } + + private void saveTo(ExplanationPreferences prefs) { + prefs.useLastExplanationService = buttonLast.isSelected(); + prefs.explanationServicesList = tableModel.getPluginIds(); + prefs.disabledExplanationServices = tableModel.getDisabledIds(); + } + + private void addDefaultExplanationServiceComponent(PreferencesLayoutPanel panel) { + panel.addGroup("Default explanation service"); + buttonLast = new JRadioButton("Most recently used explanation service"); + buttonLast.setToolTipText( + "Always use the most recently used explanation service, if it can provide an explanation for the chosen axiom"); + buttonFirst = new JRadioButton("First available explanation service from the list below"); + buttonFirst.setToolTipText( + "Always use the first explanation service from the list below that can provide an explanation for the chosen axiom"); + ButtonGroup group = new ButtonGroup(); + group.add(buttonLast); + group.add(buttonFirst); + panel.addGroupComponent(buttonLast); + panel.addGroupComponent(buttonFirst); + } + + private void addInstalledExplanationServicesComponent(PreferencesLayoutPanel panel) { + panel.addGroup("Installed explanation services"); + Collection services = getOWLEditorKit().getOWLModelManager().getExplanationManager() + .getExplainers(); + Map nameMap = new HashMap<>(); + for (ExplanationService service : services) { + nameMap.put(service.getPluginId(), service.getName()); + } + tableModel = new SortedPluginsTableModel(nameMap); + JTable pluginTable = new JTable(tableModel); + pluginTable.setToolTipText( + "Plugins that provide explanation facilities. You can disable and enable plugins and change their order using the buttons below."); + pluginTable.setRowSelectionAllowed(true); + pluginTable.setColumnSelectionAllowed(false); + pluginTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + pluginTable.getColumnModel().getColumn(0).setMaxWidth(20); + pluginTable.getColumnModel().getColumn(1).setMaxWidth(50); + pluginTable.getColumnModel().getColumn(2).setMinWidth(300); + pluginTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + JScrollPane pluginTableScrollPane = new JScrollPane(pluginTable); + pluginTableScrollPane.setPreferredSize(new Dimension(400, 100)); + panel.addGroupComponent(pluginTableScrollPane); + addUpDownButtons(panel, pluginTable); + } + + private void addUpDownButtons(PreferencesLayoutPanel panel, JTable pluginTable) { + JButton buttonUp = new JButton("↑ Move up"); + buttonUp.setToolTipText("Move the selected explanation service towards the top of the list"); + buttonUp.addActionListener(e -> { + int rowIndex = pluginTable.getSelectedRow(); + if (rowIndex > 0) { + tableModel.swap(rowIndex - 1, rowIndex); + } + pluginTable.setRowSelectionInterval(rowIndex - 1, rowIndex - 1); + }); + + JButton buttonDown = new JButton("↓ Move down︎"); + buttonDown.setToolTipText("Move the selected explanation service towards the bottom of the list"); + buttonDown.addActionListener(e -> { + int rowIndex = pluginTable.getSelectedRow(); + if (rowIndex < pluginTable.getRowCount() - 1) { + tableModel.swap(rowIndex, rowIndex + 1); + } + pluginTable.setRowSelectionInterval(rowIndex + 1, rowIndex + 1); + }); + + JPanel buttonsUpDown = new JPanel(); + buttonsUpDown.add(buttonUp); + buttonsUpDown.add(buttonDown); + panel.addGroupComponent(buttonsUpDown); + + pluginTable.getSelectionModel().addListSelectionListener(e -> { + int rowIndex = pluginTable.getSelectedRow(); + if (rowIndex == -1) { + buttonUp.setEnabled(false); + buttonDown.setEnabled(false); + } else { + buttonUp.setEnabled(rowIndex > 0); + buttonDown.setEnabled(rowIndex < pluginTable.getRowCount() - 1); + } + }); + } + } diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/SortedPluginsTableModel.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/SortedPluginsTableModel.java new file mode 100644 index 000000000..36b5257e6 --- /dev/null +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/SortedPluginsTableModel.java @@ -0,0 +1,103 @@ +package org.protege.editor.owl.ui.explanation; + +import java.util.List; +import java.util.Map; + +import javax.swing.table.AbstractTableModel; + +public class SortedPluginsTableModel extends AbstractTableModel { + + private List pluginIds; + private List disabledIds; + private Map nameMap; + + private String[] columnNames = new String[] { "#", "Enabled", "Plugin" }; + private Class[] columnClasses = new Class[] { Integer.class, Boolean.class, String.class }; + + public SortedPluginsTableModel(Map nameMap) { + this.nameMap = nameMap; + } + + public List getPluginIds() { + return pluginIds; + } + + public List getDisabledIds() { + return disabledIds; + } + + public void setPluginIds(List pluginIds) { + this.pluginIds = pluginIds; + fireTableDataChanged(); + } + + public void setDisabledIds(List disabledIds) { + this.disabledIds = disabledIds; + fireTableDataChanged(); + } + + @Override + public int getRowCount() { + return pluginIds.size(); + } + + @Override + public int getColumnCount() { + return 3; + } + + @Override + public String getColumnName(int columnIndex) { + return columnNames[columnIndex]; + } + + @Override + public Class getColumnClass(int columnIndex) { + return columnClasses[columnIndex]; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return columnIndex == 1; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + String pluginId = pluginIds.get(rowIndex); + switch (columnIndex) { + case 0: + return rowIndex + 1; + case 1: + return !disabledIds.contains(pluginId); + case 2: + return nameMap.get(pluginId); + default: + throw new IllegalArgumentException("Invalid column index: " + columnIndex); + } + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + assert (columnIndex == 1); + boolean enabled = (Boolean) aValue; + String pluginId = pluginIds.get(rowIndex); + if (enabled) { + disabledIds.remove(pluginId); + } else { + if (!disabledIds.contains(pluginId)) { + disabledIds.add(pluginId); + } + } + fireTableCellUpdated(rowIndex, columnIndex); + } + + public void swap(int rowIndex1, int rowIndex2) { + String pluginId1 = pluginIds.get(rowIndex1); + String pluginId2 = pluginIds.get(rowIndex2); + pluginIds.set(rowIndex1, pluginId2); + pluginIds.set(rowIndex2, pluginId1); + fireTableRowsUpdated(rowIndex1, rowIndex1); + fireTableRowsUpdated(rowIndex2, rowIndex2); + } + +} \ No newline at end of file From feca29756e170a30ee3767bdb988c52ae0aca6b1 Mon Sep 17 00:00:00 2001 From: Stefan Borgwardt Date: Mon, 27 May 2024 11:09:20 +0200 Subject: [PATCH 2/4] reload ExplanationManager whenever a new explanation or the preferences are opened --- .../protege/editor/owl/ui/explanation/ExplanationManager.java | 2 +- .../owl/ui/explanation/ExplanationPreferencesGeneralPanel.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationManager.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationManager.java index 452069c9b..eaa508423 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationManager.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationManager.java @@ -9,7 +9,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.TreeMap; import javax.swing.JDialog; @@ -122,6 +121,7 @@ public boolean hasExplanation(OWLAxiom axiom) { } public void handleExplain(Frame owner, OWLAxiom axiom) { + reload(); final ExplanationDialog explanation = new ExplanationDialog(this, axiom); openedExplanations.add(explanation); JOptionPane op = new JOptionPane(explanation, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION); diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java index 0e3f30b00..51ace7b19 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java @@ -31,6 +31,7 @@ public void initialise() throws Exception { add(panel, BorderLayout.NORTH); addDefaultExplanationServiceComponent(panel); addInstalledExplanationServicesComponent(panel); + getOWLEditorKit().getModelManager().getExplanationManager().reload(); loadFrom(ExplanationPreferences.create().load()); } From 76c63ad6c55f2d6c18e5242bc97d386d8f2b7319 Mon Sep 17 00:00:00 2001 From: Stefan Borgwardt Date: Mon, 27 May 2024 11:30:58 +0200 Subject: [PATCH 3/4] reload ExplanationManager whenever the preference dialog is closed --- .../protege/editor/owl/ui/explanation/ExplanationManager.java | 1 - .../owl/ui/explanation/ExplanationPreferencesGeneralPanel.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationManager.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationManager.java index eaa508423..e5408fa9f 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationManager.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationManager.java @@ -121,7 +121,6 @@ public boolean hasExplanation(OWLAxiom axiom) { } public void handleExplain(Frame owner, OWLAxiom axiom) { - reload(); final ExplanationDialog explanation = new ExplanationDialog(this, axiom); openedExplanations.add(explanation); JOptionPane op = new JOptionPane(explanation, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION); diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java index 51ace7b19..59a134a55 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java @@ -31,12 +31,12 @@ public void initialise() throws Exception { add(panel, BorderLayout.NORTH); addDefaultExplanationServiceComponent(panel); addInstalledExplanationServicesComponent(panel); - getOWLEditorKit().getModelManager().getExplanationManager().reload(); loadFrom(ExplanationPreferences.create().load()); } @Override public void dispose() throws Exception { + getOWLEditorKit().getModelManager().getExplanationManager().reload(); } @Override @@ -44,7 +44,6 @@ public void applyChanges() { ExplanationPreferences prefs = ExplanationPreferences.create(); saveTo(prefs); prefs.save(); - getOWLEditorKit().getModelManager().getExplanationManager().reload(); } private void loadFrom(ExplanationPreferences prefs) { From 9f661852f10cee4c61925a833e0dc8591b1ab199 Mon Sep 17 00:00:00 2001 From: Stefan Borgwardt Date: Mon, 27 May 2024 15:28:01 +0200 Subject: [PATCH 4/4] reordering the explanation preferences --- .../ExplanationPreferencesGeneralPanel.java | 37 +++++-------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java index 59a134a55..d167d6253 100644 --- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java +++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferencesGeneralPanel.java @@ -6,13 +6,7 @@ import java.util.HashMap; import java.util.Map; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; +import javax.swing.*; import org.protege.editor.core.ui.preferences.PreferencesLayoutPanel; import org.protege.editor.owl.ui.preferences.OWLPreferencesPanel; @@ -21,7 +15,7 @@ public class ExplanationPreferencesGeneralPanel extends OWLPreferencesPanel { private static final long serialVersionUID = -3354987384223578780L; - private JRadioButton buttonLast, buttonFirst; + private JCheckBox checkRecentlyUsed; private SortedPluginsTableModel tableModel; @Override @@ -29,8 +23,8 @@ public void initialise() throws Exception { setLayout(new BorderLayout()); PreferencesLayoutPanel panel = new PreferencesLayoutPanel(); add(panel, BorderLayout.NORTH); - addDefaultExplanationServiceComponent(panel); addInstalledExplanationServicesComponent(panel); + addDefaultExplanationServiceComponent(panel); loadFrom(ExplanationPreferences.create().load()); } @@ -47,34 +41,21 @@ public void applyChanges() { } private void loadFrom(ExplanationPreferences prefs) { - if (prefs.useLastExplanationService) { - buttonLast.setSelected(true); - } else { - buttonFirst.setSelected(true); - } + checkRecentlyUsed.setSelected(prefs.useLastExplanationService); tableModel.setPluginIds(prefs.explanationServicesList); tableModel.setDisabledIds(prefs.disabledExplanationServices); } private void saveTo(ExplanationPreferences prefs) { - prefs.useLastExplanationService = buttonLast.isSelected(); + prefs.useLastExplanationService = checkRecentlyUsed.isSelected(); prefs.explanationServicesList = tableModel.getPluginIds(); prefs.disabledExplanationServices = tableModel.getDisabledIds(); } private void addDefaultExplanationServiceComponent(PreferencesLayoutPanel panel) { - panel.addGroup("Default explanation service"); - buttonLast = new JRadioButton("Most recently used explanation service"); - buttonLast.setToolTipText( - "Always use the most recently used explanation service, if it can provide an explanation for the chosen axiom"); - buttonFirst = new JRadioButton("First available explanation service from the list below"); - buttonFirst.setToolTipText( - "Always use the first explanation service from the list below that can provide an explanation for the chosen axiom"); - ButtonGroup group = new ButtonGroup(); - group.add(buttonLast); - group.add(buttonFirst); - panel.addGroupComponent(buttonLast); - panel.addGroupComponent(buttonFirst); + checkRecentlyUsed = new JCheckBox("Try using the most recently used explanation service first"); + checkRecentlyUsed.setToolTipText("Use the most recently used explanation service, if it can provide an explanation for the chosen axiom; otherwise, use the first available service from the list above"); + panel.addGroupComponent(checkRecentlyUsed); } private void addInstalledExplanationServicesComponent(PreferencesLayoutPanel panel) { @@ -88,7 +69,7 @@ private void addInstalledExplanationServicesComponent(PreferencesLayoutPanel pan tableModel = new SortedPluginsTableModel(nameMap); JTable pluginTable = new JTable(tableModel); pluginTable.setToolTipText( - "Plugins that provide explanation facilities. You can disable and enable plugins and change their order using the buttons below."); + "Plugins that provide explanation facilities. Protégé will use the first enabled service on the list that can provide an explanation for the chosen axiom."); pluginTable.setRowSelectionAllowed(true); pluginTable.setColumnSelectionAllowed(false); pluginTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);