提交 5fa01537 编写于 作者: S serge-rider

#3278 Notifications preferences + commit/rollback notifications

上级 1a0ba85f
......@@ -26,9 +26,6 @@ public final class DBeaverPreferences
public static final String AGENT_LONG_OPERATION_NOTIFY = "agent.long.operation.notify"; //$NON-NLS-1$
public static final String AGENT_LONG_OPERATION_TIMEOUT = "agent.long.operation.timeout"; //$NON-NLS-1$
public static final String NOTIFICATIONS_ENABLED = "notifications.enabled"; //$NON-NLS-1$
public static final String NOTIFICATIONS_CLOSE_DELAY_TIMEOUT = "notifications.closeDelay"; //$NON-NLS-1$
public static final String PLATFORM_LANGUAGE = "platform.language"; //$NON-NLS-1$
public static final String NAVIGATOR_EXPAND_ON_CONNECT = "navigator.expand.on.connect"; //$NON-NLS-1$
......
......@@ -19,6 +19,7 @@ package org.jkiss.dbeaver.core;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore;
......@@ -63,10 +64,6 @@ public class DBeaverPreferencesInitializer extends AbstractPreferenceInitializer
PrefUtils.setDefaultPreferenceValue(store, DBeaverPreferences.AGENT_LONG_OPERATION_NOTIFY, isWindows);
PrefUtils.setDefaultPreferenceValue(store, DBeaverPreferences.AGENT_LONG_OPERATION_TIMEOUT, 30);
// Notifications
PrefUtils.setDefaultPreferenceValue(store, DBeaverPreferences.NOTIFICATIONS_ENABLED, true);
PrefUtils.setDefaultPreferenceValue(store, DBeaverPreferences.NOTIFICATIONS_CLOSE_DELAY_TIMEOUT, 5000L);
// Navigator
PrefUtils.setDefaultPreferenceValue(store, DBeaverPreferences.NAVIGATOR_EXPAND_ON_CONNECT, false);
PrefUtils.setDefaultPreferenceValue(store, DBeaverPreferences.NAVIGATOR_SORT_ALPHABETICALLY, false);
......
......@@ -22,25 +22,26 @@ import org.eclipse.swt.widgets.Display;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPMessageType;
import org.jkiss.dbeaver.ui.notifications.NotificationPopupMessage;
import org.jkiss.dbeaver.ui.notifications.NotificationUtils;
/**
* DBeaverIcons
*/
public class DBeaverNotifications
{
public static void showInformation(DBPDataSource dataSource, String text) {
/*
Display.getDefault().syncExec(() -> {
int delayClose = DBeaverCore.getGlobalPreferenceStore().getLong(DBeaverPreferences.AGENT_LONG_OPERATION_NOTIFY)
NotificationPopupMessage popup = new NotificationPopupMessage(dataSource, text, SWT.ICON_INFORMATION);
if (delayClose > 0) {
popup.setDelayClose(delayClose);
}
popup.open();
});
*/
public static void showNotification(DBPDataSource dataSource, String id, String text) {
NotificationUtils.sendNotification(dataSource, id, text, null, null);
}
public static void showNotification(DBPDataSource dataSource, String id, String text, DBPMessageType messageType) {
NotificationUtils.sendNotification(dataSource, id, text, messageType, null);
}
public static void showInformation(DBPDataSource dataSource, String id, String text, DBPMessageType messageType, Runnable feedback) {
NotificationUtils.sendNotification(dataSource, id, text, messageType, feedback);
}
}
......@@ -24,8 +24,8 @@ import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.qm.QMTransactionState;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.runtime.TasksJob;
import org.jkiss.dbeaver.ui.DBeaverNotifications;
import org.jkiss.dbeaver.ui.actions.AbstractDataSourceHandler;
import org.jkiss.dbeaver.ui.notifications.NotificationUtils;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import java.lang.reflect.InvocationTargetException;
......@@ -53,21 +53,12 @@ public class DataSourceCommitHandler extends AbstractDataSourceHandler
throw new InvocationTargetException(e);
}
NotificationUtils.sendNotification(
DBeaverNotifications.showNotification(
context.getDataSource(),
"commit",
"Transaction has been committed\n\n" +
"Query count: " + txnInfo.getUpdateCount() + "\n" +
"Duration: " + RuntimeUtils.formatExecutionTime(System.currentTimeMillis() - txnInfo.getTransactionStartTime()) + "\n");
/*
NotificationPopupMessage.showMessage(
context.getDataSource(),
"Transaction has been committed\n\n" +
"Query count: " + txnInfo.getUpdateCount() + "\n" +
"Duration: " + RuntimeUtils.formatExecutionTime(System.currentTimeMillis() - txnInfo.getTransactionStartTime()) + "\n",
3000, SWT.ICON_INFORMATION
);
*/
}
});
}
......
......@@ -18,12 +18,17 @@ package org.jkiss.dbeaver.ui.actions.datasource;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.jkiss.dbeaver.model.DBPMessageType;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.qm.QMTransactionState;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.runtime.TasksJob;
import org.jkiss.dbeaver.ui.DBeaverNotifications;
import org.jkiss.dbeaver.ui.actions.AbstractDataSourceHandler;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import java.lang.reflect.InvocationTargetException;
......@@ -46,11 +51,20 @@ public class DataSourceRollbackHandler extends AbstractDataSourceHandler
throws InvocationTargetException, InterruptedException {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
QMTransactionState txnInfo = QMUtils.getTransactionState(context);
try (DBCSession session = context.openSession(monitor, DBCExecutionPurpose.UTIL, "Rollback transaction")) {
txnManager.rollback(session, null);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
DBeaverNotifications.showNotification(
context.getDataSource(),
"rollback",
"Transaction has been rolled back\n\n" +
"Query count: " + txnInfo.getUpdateCount() + "\n" +
"Duration: " + RuntimeUtils.formatExecutionTime(System.currentTimeMillis() - txnInfo.getTransactionStartTime()) + "\n",
DBPMessageType.ERROR);
}
}
});
......
......@@ -31,6 +31,7 @@ import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.core.DBeaverUI;
......@@ -165,8 +166,8 @@ public class PrefPageDatabaseGeneral extends AbstractPrefPage implements IWorkbe
automaticUpdateCheck.setSelection(store.getBoolean(DBeaverPreferences.UI_AUTO_UPDATE_CHECK));
notificationsEnabled.setSelection(store.getBoolean(DBeaverPreferences.NOTIFICATIONS_ENABLED));
notificationsCloseDelay.setSelection(store.getInt(DBeaverPreferences.NOTIFICATIONS_CLOSE_DELAY_TIMEOUT));
notificationsEnabled.setSelection(store.getBoolean(ModelPreferences.NOTIFICATIONS_ENABLED));
notificationsCloseDelay.setSelection(store.getInt(ModelPreferences.NOTIFICATIONS_CLOSE_DELAY_TIMEOUT));
longOperationsCheck.setSelection(store.getBoolean(DBeaverPreferences.AGENT_LONG_OPERATION_NOTIFY));
longOperationsTimeout.setSelection(store.getInt(DBeaverPreferences.AGENT_LONG_OPERATION_TIMEOUT));
......@@ -179,8 +180,8 @@ public class PrefPageDatabaseGeneral extends AbstractPrefPage implements IWorkbe
store.setValue(DBeaverPreferences.UI_AUTO_UPDATE_CHECK, automaticUpdateCheck.getSelection());
store.setValue(DBeaverPreferences.NOTIFICATIONS_ENABLED, notificationsEnabled.getSelection());
store.setValue(DBeaverPreferences.NOTIFICATIONS_CLOSE_DELAY_TIMEOUT, notificationsCloseDelay.getSelection());
store.setValue(ModelPreferences.NOTIFICATIONS_ENABLED, notificationsEnabled.getSelection());
store.setValue(ModelPreferences.NOTIFICATIONS_CLOSE_DELAY_TIMEOUT, notificationsCloseDelay.getSelection());
store.setValue(DBeaverPreferences.AGENT_LONG_OPERATION_NOTIFY, longOperationsCheck.getSelection());
store.setValue(DBeaverPreferences.AGENT_LONG_OPERATION_TIMEOUT, longOperationsTimeout.getSelection());
......
......@@ -38,6 +38,9 @@ import java.util.Arrays;
*/
public final class ModelPreferences
{
public static final String NOTIFICATIONS_ENABLED = "notifications.enabled"; //$NON-NLS-1$
public static final String NOTIFICATIONS_CLOSE_DELAY_TIMEOUT = "notifications.closeDelay"; //$NON-NLS-1$
public static final String QUERY_ROLLBACK_ON_ERROR = "query.rollback-on-error"; //$NON-NLS-1$
public static final String EXECUTE_RECOVER_ENABLED = "execute.recover.enabled"; //$NON-NLS-1$
......@@ -112,6 +115,10 @@ public final class ModelPreferences
}
private static void initializeDefaultPreferences(DBPPreferenceStore store) {
// Notifications
PrefUtils.setDefaultPreferenceValue(store, ModelPreferences.NOTIFICATIONS_ENABLED, true);
PrefUtils.setDefaultPreferenceValue(store, ModelPreferences.NOTIFICATIONS_CLOSE_DELAY_TIMEOUT, 3000L);
// Common
PrefUtils.setDefaultPreferenceValue(store, QUERY_ROLLBACK_ON_ERROR, false);
PrefUtils.setDefaultPreferenceValue(store, EXECUTE_RECOVER_ENABLED, true);
......
......@@ -17,6 +17,7 @@
package org.jkiss.dbeaver.model.qm;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.app.DBPPlatform;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
......@@ -113,6 +114,7 @@ public class QMUtils {
return null;
}
@NotNull
public static QMTransactionState getTransactionState(DBCExecutionContext executionContext) {
int execCount = 0, updateCount = 0;
final boolean txnMode;
......
......@@ -13,6 +13,7 @@ import org.eclipse.mylyn.commons.notifications.core.NotificationSinkEvent;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.jkiss.dbeaver.ModelPreferences;
import java.util.*;
......@@ -121,6 +122,9 @@ public class DatabaseNotificationSink extends NotificationSink {
Shell shell = new Shell(PlatformUI.getWorkbench().getDisplay());
popup = new DatabaseNotificationPopup(shell);
popup.setFadingEnabled(isAnimationsEnabled());
popup.setDelayClose(ModelPreferences.getPreferences().getInt(ModelPreferences.NOTIFICATIONS_CLOSE_DELAY_TIMEOUT));
List<AbstractNotification> toDisplay = new ArrayList<>(currentlyNotifying);
Collections.sort(toDisplay);
popup.setContents(toDisplay);
......
......@@ -2,6 +2,7 @@ package org.jkiss.dbeaver.ui.notifications;
import org.eclipse.mylyn.commons.notifications.core.AbstractNotification;
import org.eclipse.mylyn.commons.notifications.ui.NotificationsUi;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPMessageType;
......@@ -14,6 +15,9 @@ public abstract class NotificationUtils {
}
public static void sendNotification(DBPDataSource dataSource, String id, String text, DBPMessageType messageType, Runnable feedback) {
if (!ModelPreferences.getPreferences().getBoolean(ModelPreferences.NOTIFICATIONS_ENABLED)) {
return;
}
AbstractNotification notification = new DatabaseNotification(
dataSource,
id,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册