From d6e749546dc68b0f4b6139ec89ac3e73f2772d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Wed, 21 Feb 2024 11:08:52 +0100 Subject: [PATCH] LogView: Option to activate on Error only For the case that someone is not interested in A LogView popping up for info items. --- .../ui/internal/views/log/LogView.java | 73 ++++++++++++++----- .../ui/internal/views/log/Messages.java | 2 + .../ui/internal/views/log/messages.properties | 4 +- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogView.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogView.java index d112ab6751f..a94fcc1b3b6 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogView.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogView.java @@ -84,6 +84,8 @@ public class LogView extends ViewPart implements LogListener { protected static final String P_COLUMN_2 = "column3"; //$NON-NLS-1$ protected static final String P_COLUMN_3 = "column4"; //$NON-NLS-1$ public static final String P_ACTIVATE = "activate"; //$NON-NLS-1$ + public static final String P_ACTIVATE_WARN = "activateWarn"; //$NON-NLS-1$ + public static final String P_ACTIVATE_ERRROR = "activateError"; //$NON-NLS-1$ public static final String P_SHOW_FILTER_TEXT = "show_filter_text"; //$NON-NLS-1$ public static final String P_ORDER_TYPE = "orderType"; //$NON-NLS-1$ public static final String P_ORDER_VALUE = "orderValue"; //$NON-NLS-1$ @@ -147,6 +149,8 @@ public class LogView extends ViewPart implements LogListener { private Action fReadLogAction; private Action fCopyAction; private Action fActivateViewAction; + private Action fActivateViewWarnAction; + private Action fActivateViewErrorAction; private Action fOpenLogAction; private Action fExportLogAction; private Action fExportLogEntryAction; @@ -311,8 +315,14 @@ private void createActions() { mgr.add(createFilterAction()); mgr.add(new Separator()); - fActivateViewAction = createActivateViewAction(); + fActivateViewAction = createActivateViewAction(Messages.LogView_activate, P_ACTIVATE); mgr.add(fActivateViewAction); + fActivateViewWarnAction = createActivateViewAction(Messages.LogView_activateWarn, P_ACTIVATE_WARN); + mgr.add(fActivateViewWarnAction); + fActivateViewErrorAction = createActivateViewAction(Messages.LogView_activateError, P_ACTIVATE_ERRROR); + mgr.add(fActivateViewErrorAction); + mgr.add(new Separator()); + if (fFilteredTree.getFilterControl() != null) mgr.add(createShowTextFilter()); @@ -349,14 +359,29 @@ private void createActions() { fTree.setMenu(menu); } - private Action createActivateViewAction() { - Action action = new Action(Messages.LogView_activate) { // + private Action createActivateViewAction(String msg, String key) { + Action action = new Action(msg) { @Override public void run() { - fMemento.putString(P_ACTIVATE, isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ + if (isChecked()) { + // on disabling one disable the others: + if (P_ACTIVATE.equals(key)) { + fActivateViewWarnAction.setChecked(false); + fActivateViewErrorAction.setChecked(false); + } else if (P_ACTIVATE_WARN.equals(key)) { + fActivateViewAction.setChecked(false); + fActivateViewErrorAction.setChecked(false); + } else if (P_ACTIVATE_ERRROR.equals(key)) { + fActivateViewAction.setChecked(false); + fActivateViewWarnAction.setChecked(false); + } + } + fMemento.putString(P_ACTIVATE, Boolean.toString(fActivateViewAction.isChecked())); + fMemento.putString(P_ACTIVATE_WARN, Boolean.toString(fActivateViewWarnAction.isChecked())); + fMemento.putString(P_ACTIVATE_ERRROR, Boolean.toString(fActivateViewErrorAction.isChecked())); } }; - action.setChecked(fMemento.getString(P_ACTIVATE).equals("true")); //$NON-NLS-1$ + action.setChecked(Boolean.parseBoolean(fMemento.getString(key))); return action; } @@ -746,7 +771,7 @@ protected void setLogFile(File path) { } finally { fReadLogAction.setText(Messages.LogView_readLog_reload); fReadLogAction.setToolTipText(Messages.LogView_readLog_reload); - asyncRefresh(false); + asyncRefresh(); resetDialogButtons(); } } @@ -842,7 +867,7 @@ public void handleClear() { currentSession.removeAllChildren(); } } - asyncRefresh(false); + asyncRefresh(); resetDialogButtons(); }); } @@ -862,7 +887,7 @@ protected void reloadLog() { } finally { fReadLogAction.setText(Messages.LogView_readLog_restore); fReadLogAction.setToolTipText(Messages.LogView_readLog_restore); - asyncRefresh(false); + asyncRefresh(); resetDialogButtons(); } } @@ -891,6 +916,7 @@ private CompletableFuture> fetchLogEntries() { } private void updateLogViewer(List entries) { + OptionalInt maxSeverity = entries.stream().mapToInt(LogEntry::getSeverity).max(); synchronized (elements) { elements.clear(); groups.clear(); @@ -898,8 +924,7 @@ private void updateLogViewer(List entries) { limitEntriesCount(); } setContentDescription(getTitleSummary()); - - asyncRefresh(false); + maxSeverity.ifPresent(this::asyncRefreshAndActivate); } private Display getDisplay() { @@ -1102,7 +1127,6 @@ public void logged(org.osgi.service.log.LogEntry input) { if (shouldReadLog) { readLogFile(); - asyncRefresh(true); } else { LogEntry entry = betterInput != null ? createLogEntry(betterInput) : createLogEntry(input); @@ -1117,7 +1141,6 @@ public void logged(org.osgi.service.log.LogEntry input) { } if (!useBatchedEntries) { pushEntry(entry); - asyncRefresh(true); } } } @@ -1139,7 +1162,6 @@ protected IStatus run(IProgressMonitor monitor) { } } } - asyncRefresh(true); return Status.OK_STATUS; } }; @@ -1187,7 +1209,7 @@ private void pushEntry(LogEntry entry) { limitEntriesCount(); } } - asyncRefresh(true); + asyncRefreshAndActivate(entry.getSeverity()); } private Throttler createMutualRefresh(Display display) { @@ -1226,15 +1248,18 @@ private Throttler createMutualActivate(Display display) { }); } - private void asyncRefresh(final boolean activate) { - if (fTree.isDisposed()) - return; - mutualRefresh.throttledExec(); - if (activate && fActivateViewAction.isChecked()) { + private void asyncRefreshAndActivate(int severity) { + asyncRefresh(); + if ((fActivateViewAction.isChecked()) || (severity >= IStatus.WARNING && fActivateViewWarnAction.isChecked()) + || (severity >= IStatus.ERROR && fActivateViewErrorAction.isChecked())) { mutualActivate.throttledExec(); } } + private void asyncRefresh() { + mutualRefresh.throttledExec(); + } + @Override public void setFocus() { if (isDisposed()) { @@ -1384,7 +1409,9 @@ public void saveState(IMemento memento) { this.fMemento.putInteger(P_COLUMN_1, getColumnWidth(fColumn1, 300)); this.fMemento.putInteger(P_COLUMN_2, getColumnWidth(fColumn2, 150)); this.fMemento.putInteger(P_COLUMN_3, getColumnWidth(fColumn3, 150)); - this.fMemento.putString(P_ACTIVATE, fActivateViewAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ + this.fMemento.putString(P_ACTIVATE, Boolean.toString(fActivateViewAction.isChecked())); + this.fMemento.putString(P_ACTIVATE_WARN, Boolean.toString(fActivateViewWarnAction.isChecked())); + this.fMemento.putString(P_ACTIVATE_ERRROR, Boolean.toString(fActivateViewErrorAction.isChecked())); memento.putMemento(this.fMemento); writeSettings(); } @@ -1736,6 +1763,10 @@ private void readSettings() { fMemento.putInteger(P_COLUMN_2, getColumnWidthPreference(instancePrefs, defaultPrefs, P_COLUMN_2, 150)); fMemento.putInteger(P_COLUMN_3, getColumnWidthPreference(instancePrefs, defaultPrefs, P_COLUMN_3, 150)); fMemento.putBoolean(P_ACTIVATE, instancePrefs.getBoolean(P_ACTIVATE, defaultPrefs.getBoolean(P_ACTIVATE, true))); + fMemento.putBoolean(P_ACTIVATE_WARN, + instancePrefs.getBoolean(P_ACTIVATE_WARN, defaultPrefs.getBoolean(P_ACTIVATE_WARN, true))); + fMemento.putBoolean(P_ACTIVATE_ERRROR, + instancePrefs.getBoolean(P_ACTIVATE_ERRROR, defaultPrefs.getBoolean(P_ACTIVATE_ERRROR, true))); fMemento.putInteger(P_ORDER_VALUE, instancePrefs.getInt(P_ORDER_VALUE, defaultPrefs.getInt(P_ORDER_VALUE, DESCENDING))); fMemento.putInteger(P_ORDER_TYPE, instancePrefs.getInt(P_ORDER_TYPE, defaultPrefs.getInt(P_ORDER_TYPE, LogView.DATE))); fMemento.putBoolean(P_SHOW_FILTER_TEXT, instancePrefs.getBoolean(P_SHOW_FILTER_TEXT, defaultPrefs.getBoolean(P_SHOW_FILTER_TEXT, true))); @@ -1797,6 +1828,8 @@ private void writeViewSettings() { instancePrefs.putInt(P_COLUMN_2, fMemento.getInteger(P_COLUMN_2).intValue()); instancePrefs.putInt(P_COLUMN_3, fMemento.getInteger(P_COLUMN_3).intValue()); instancePrefs.putBoolean(P_ACTIVATE, fMemento.getBoolean(P_ACTIVATE).booleanValue()); + instancePrefs.putBoolean(P_ACTIVATE_WARN, fMemento.getBoolean(P_ACTIVATE_WARN).booleanValue()); + instancePrefs.putBoolean(P_ACTIVATE_ERRROR, fMemento.getBoolean(P_ACTIVATE_ERRROR).booleanValue()); instancePrefs.putInt(P_ORDER_VALUE, fMemento.getInteger(P_ORDER_VALUE).intValue()); instancePrefs.putInt(P_ORDER_TYPE, fMemento.getInteger(P_ORDER_TYPE).intValue()); instancePrefs.putBoolean(P_SHOW_FILTER_TEXT, fMemento.getBoolean(P_SHOW_FILTER_TEXT).booleanValue()); diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Messages.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Messages.java index 12a6aede512..f1cf5683d4f 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Messages.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Messages.java @@ -57,6 +57,8 @@ public class Messages extends NLS { public static String LogView_operation_importing; public static String LogView_operation_reloading; public static String LogView_activate; + public static String LogView_activateWarn; + public static String LogView_activateError; public static String LogView_AddingBatchedEvents; public static String LogView_view_currentLog; public static String LogView_view_currentLog_tooltip; diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/messages.properties b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/messages.properties index f5f8dac44fd..b465987ebf5 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/messages.properties +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/messages.properties @@ -47,7 +47,9 @@ LogView_confirmOverwrite_message = File " {0}" exists. Would you like to overwri LogView_confirmDelete_deleteButton = &Delete All Events LogView_operation_importing = Importing log... LogView_operation_reloading = Reloading... -LogView_activate = &Activate on new events +LogView_activate = &Activate on any new event +LogView_activateWarn = Activate on new warning or error +LogView_activateError = Activate on new error LogView_AddingBatchedEvents=Adding batched log events... LogView_view_currentLog = &Open Log LogView_view_currentLog_tooltip = Open Log