-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting and disabling functionality for ExplanationServices #1059
Merged
gouttegd
merged 5 commits into
protegeproject:master
from
stefborg:sort-explanation-services
May 30, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0ba8210
sorting and disabling functionality for ExplanationServices
stefborg f66e756
Merge branch 'master' into sort-explanation-services
stefborg feca297
reload ExplanationManager whenever a new explanation or the preferenc…
stefborg 76c63ad
reload ExplanationManager whenever the preference dialog is closed
stefborg 9f66185
reordering the explanation preferences
stefborg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ditor-owl/src/main/java/org/protege/editor/owl/ui/explanation/ExplanationPreferences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> DEFAULT_EXPLANATION_SERVICES_LIST_ = Collections.emptyList(); | ||
private final static List<String> DEFAULT_DISABLED_EXPLANATION_SERVICES_ = Collections.emptyList(); | ||
|
||
public String defaultExplanationService; | ||
public boolean useLastExplanationService; | ||
public List<String> explanationServicesList; | ||
public List<String> 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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
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.JScrollPane; | ||
import javax.swing.*; | ||
|
||
import org.protege.editor.core.ui.preferences.PreferencesLayoutPanel; | ||
import org.protege.editor.owl.ui.preferences.OWLPreferencesPanel; | ||
|
@@ -15,30 +15,110 @@ public class ExplanationPreferencesGeneralPanel extends OWLPreferencesPanel { | |
|
||
private static final long serialVersionUID = -3354987384223578780L; | ||
|
||
private JCheckBox checkRecentlyUsed; | ||
private SortedPluginsTableModel tableModel; | ||
|
||
@Override | ||
public void initialise() throws Exception { | ||
setLayout(new BorderLayout()); | ||
PreferencesLayoutPanel panel = new PreferencesLayoutPanel(); | ||
add(panel, BorderLayout.NORTH); | ||
addInstalledExplanationServicesComponent(panel); | ||
addDefaultExplanationServiceComponent(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<String> pluginModel = new DefaultListModel<>(); | ||
ExplanationManager manager = new ExplanationManager(getOWLEditorKit()); | ||
Collection<ExplanationService> services = manager.getExplainers(); | ||
for (ExplanationService service : services) | ||
pluginModel.addElement(service.getName()); | ||
JList<String> 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 { | ||
getOWLEditorKit().getModelManager().getExplanationManager().reload(); | ||
} | ||
|
||
@Override | ||
public void applyChanges() { | ||
ExplanationPreferences prefs = ExplanationPreferences.create(); | ||
saveTo(prefs); | ||
prefs.save(); | ||
} | ||
|
||
private void loadFrom(ExplanationPreferences prefs) { | ||
checkRecentlyUsed.setSelected(prefs.useLastExplanationService); | ||
tableModel.setPluginIds(prefs.explanationServicesList); | ||
tableModel.setDisabledIds(prefs.disabledExplanationServices); | ||
} | ||
|
||
private void saveTo(ExplanationPreferences prefs) { | ||
prefs.useLastExplanationService = checkRecentlyUsed.isSelected(); | ||
prefs.explanationServicesList = tableModel.getPluginIds(); | ||
prefs.disabledExplanationServices = tableModel.getDisabledIds(); | ||
} | ||
|
||
private void addDefaultExplanationServiceComponent(PreferencesLayoutPanel panel) { | ||
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) { | ||
panel.addGroup("Installed explanation services"); | ||
Collection<ExplanationService> services = getOWLEditorKit().getOWLModelManager().getExplanationManager() | ||
.getExplainers(); | ||
Map<String, String> 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. 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); | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the panel is created, no row in the table is selected. So either select, e.g., the first row (if there is) or make the buttons not active. |
||
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); | ||
} | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create()
will erasedefaultExplanationService
, which is not stored in this preferences. One should probably use preferences that have been loaded duringinitialize()