提交 1b96f70d 编写于 作者: S serge-rider

#3278 Switch to Mylyn notifications

上级 82e99467
......@@ -136,6 +136,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.e4.ui.workbench.renderers.swt,
org.eclipse.e4.ui.css.core,
org.eclipse.e4.ui.css.swt,
org.eclipse.mylyn.commons.notifications.core,
org.eclipse.mylyn.commons.notifications.ui,
org.jkiss.dbeaver.runtime.ide.core,
org.jkiss.dbeaver.runtime.ide.ui
Bundle-Localization: OSGI-INF/l10n/bundle
......@@ -3758,6 +3758,24 @@
</perspective>
</extension>
<!-- Notifications -->
<extension point="org.eclipse.mylyn.commons.notifications.ui.notifications">
<category id="org.jkiss.dbeaver.notifications.database.category" label="Database"/>
<event categoryId="org.jkiss.dbeaver.notifications.database.category" id="org.jkiss.dbeaver.notifications.event.commit" label="Commit">
<defaultHandler sinkId="org.eclipse.mylyn.commons.notifications.sink.Popup"/>
<description>
This event is triggered when transaction was committed.
</description>
</event>
<event categoryId="org.jkiss.dbeaver.notifications.database.category" id="org.jkiss.dbeaver.notifications.event.rollback" label="Rollback">
<defaultHandler sinkId="org.eclipse.mylyn.commons.notifications.sink.Popup"/>
<description>
This event is triggered when transaction was rolled back.
</description>
</event>
</extension>
<!-- FIXME: Disabled because it breaks dark theme. -->
<!--
<extension point="org.eclipse.e4.ui.css.core.propertyHandler">
......
......@@ -18,18 +18,21 @@ package org.jkiss.dbeaver.ui.actions.datasource;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.mylyn.commons.notifications.core.AbstractNotification;
import org.eclipse.mylyn.commons.notifications.ui.NotificationsUi;
import org.jkiss.code.NotNull;
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.runtime.TasksJob;
import org.jkiss.dbeaver.ui.actions.AbstractDataSourceHandler;
import org.jkiss.dbeaver.ui.notifications.NotificationPopupMessage;
import org.jkiss.dbeaver.ui.notifications.DatabaseNotification;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
public class DataSourceCommitHandler extends AbstractDataSourceHandler
{
......@@ -53,6 +56,18 @@ public class DataSourceCommitHandler extends AbstractDataSourceHandler
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
AbstractNotification notification = new DatabaseNotification(
context.getDataSource(),
"commit",
"Transaction has been committed\n\n" +
"Query count: " + txnInfo.getUpdateCount() + "\n" +
"Duration: " + RuntimeUtils.formatExecutionTime(System.currentTimeMillis() - txnInfo.getTransactionStartTime()) + "\n",
DBPMessageType.WARNING, null);
NotificationsUi.getService().notify(
Collections.singletonList(notification));
/*
NotificationPopupMessage.showMessage(
context.getDataSource(),
"Transaction has been committed\n\n" +
......@@ -60,6 +75,7 @@ public class DataSourceCommitHandler extends AbstractDataSourceHandler
"Duration: " + RuntimeUtils.formatExecutionTime(System.currentTimeMillis() - txnInfo.getTransactionStartTime()) + "\n",
3000, SWT.ICON_INFORMATION
);
*/
}
});
}
......
......@@ -16,6 +16,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.views,
org.eclipse.ui.workbench.texteditor,
org.eclipse.mylyn.commons.ui,
org.eclipse.mylyn.commons.notifications.ui,
org.jkiss.dbeaver.model
Export-Package: org.jkiss.dbeaver.ui,
org.jkiss.dbeaver.ui.notifications
package org.jkiss.dbeaver.ui.notifications;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.mylyn.commons.notifications.ui.AbstractUiNotification;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPMessageType;
import java.util.Date;
public class DatabaseNotification extends AbstractUiNotification {
private final String label;
private final String description;
private final DBPMessageType messageType;
private final Runnable feedback;
private final Date date;
public DatabaseNotification(
@Nullable DBPDataSource dataSource,
@NotNull String id,
@NotNull String description,
@Nullable DBPMessageType messageType,
@Nullable Runnable feedback)
{
super("org.jkiss.dbeaver.notifications.event." + id);
this.label = dataSource.getContainer().getName();
this.description = description;
this.messageType = messageType;
this.feedback = feedback;
this.date = new Date();
}
@Override
public String getLabel() {
return label;
}
@Override
public String getDescription() {
return description;
}
@Override
public Date getDate() {
return date;
}
@Override
public <T> T getAdapter(Class<T> adapter) {
return null;
}
@Override
public Image getNotificationImage() {
return null;
}
@Override
public Image getNotificationKindImage() {
if (messageType == null) {
return null;
}
int iconType;
switch (messageType) {
case ERROR: iconType = SWT.ICON_ERROR; break;
case WARNING: iconType = SWT.ICON_WARNING; break;
default: iconType = SWT.ICON_INFORMATION; break;
}
return Display.getDefault().getSystemImage(iconType);
}
@Override
public void open() {
if (feedback != null) {
feedback.run();
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册