From 0ba82105947cabbe3ca9a897f8b9026048c50dde Mon Sep 17 00:00:00 2001 From: Stefan Borgwardt Date: Tue, 31 May 2022 14:20:12 +0200 Subject: [PATCH 1/7] 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/7] 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/7] 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/7] 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); From 966a66ec5a3a18bd75c2cd2c1d511989f852f704 Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Tue, 28 May 2024 23:01:48 +0100 Subject: [PATCH 5/7] Do not create a new ExplanationPreferences object to apply changes. When applying changes in a ExplanationPreferencesGeneralPanel dialog, save the changes to an instance-level ExplanationPreferences object (that has itself been loaded upon initialisation of the dialog), rather than to a new object created on the fly. This ensure that any previously set "last explanation service" setting is preserved. --- .../explanation/ExplanationPreferencesGeneralPanel.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 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 d167d6253..ea3832b86 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 @@ -17,6 +17,7 @@ public class ExplanationPreferencesGeneralPanel extends OWLPreferencesPanel { private JCheckBox checkRecentlyUsed; private SortedPluginsTableModel tableModel; + private ExplanationPreferences preferences; @Override public void initialise() throws Exception { @@ -25,7 +26,8 @@ public void initialise() throws Exception { add(panel, BorderLayout.NORTH); addInstalledExplanationServicesComponent(panel); addDefaultExplanationServiceComponent(panel); - loadFrom(ExplanationPreferences.create().load()); + preferences = ExplanationPreferences.create().load(); + loadFrom(preferences); } @Override @@ -35,9 +37,8 @@ public void dispose() throws Exception { @Override public void applyChanges() { - ExplanationPreferences prefs = ExplanationPreferences.create(); - saveTo(prefs); - prefs.save(); + saveTo(preferences); + preferences.save(); } private void loadFrom(ExplanationPreferences prefs) { From 23e9b0124011fc3dc45d6892a4230f74eee89026 Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Tue, 28 May 2024 23:05:46 +0100 Subject: [PATCH 6/7] Disable up/down buttons upon dialog initialisation. When initialising the ExplanationPreferencesGeneralPanel dialog, make sure the "up" and "down" buttons are disabled if no row is selected in the list of available explanation services (which is normally the case when the dialog is created). --- .../owl/ui/explanation/ExplanationPreferencesGeneralPanel.java | 2 ++ 1 file changed, 2 insertions(+) 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 ea3832b86..b6a27b6df 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 @@ -94,6 +94,7 @@ private void addUpDownButtons(PreferencesLayoutPanel panel, JTable pluginTable) } pluginTable.setRowSelectionInterval(rowIndex - 1, rowIndex - 1); }); + buttonUp.setEnabled(pluginTable.getSelectedRow() != -1); JButton buttonDown = new JButton("↓ Move down︎"); buttonDown.setToolTipText("Move the selected explanation service towards the bottom of the list"); @@ -104,6 +105,7 @@ private void addUpDownButtons(PreferencesLayoutPanel panel, JTable pluginTable) } pluginTable.setRowSelectionInterval(rowIndex + 1, rowIndex + 1); }); + buttonDown.setEnabled(pluginTable.getSelectedRow() != -1); JPanel buttonsUpDown = new JPanel(); buttonsUpDown.add(buttonUp); From 36e18850254ff98e1d87ec4608f024a9a1abca09 Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Wed, 29 May 2024 12:06:59 +0100 Subject: [PATCH 7/7] Add "change priority" label. Add a label next to the "move up" / "move down" buttons in the ExplanationPreferencesGeneralPanel dialog, to hopefully make it clearer that the order of the listed explanation services matters. --- .../owl/ui/explanation/ExplanationPreferencesGeneralPanel.java | 1 + 1 file changed, 1 insertion(+) 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 b6a27b6df..d78d1f844 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 @@ -108,6 +108,7 @@ private void addUpDownButtons(PreferencesLayoutPanel panel, JTable pluginTable) buttonDown.setEnabled(pluginTable.getSelectedRow() != -1); JPanel buttonsUpDown = new JPanel(); + buttonsUpDown.add(new JLabel("Change priority")); buttonsUpDown.add(buttonUp); buttonsUpDown.add(buttonDown); panel.addGroupComponent(buttonsUpDown);