mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
notification logging settings
This commit is contained in:
@@ -19,6 +19,8 @@ package com.intellij.notification;
|
||||
import com.intellij.execution.filters.HyperlinkInfo;
|
||||
import com.intellij.execution.impl.ConsoleViewImpl;
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.notification.impl.NotificationSettings;
|
||||
import com.intellij.notification.impl.NotificationsConfiguration;
|
||||
import com.intellij.notification.impl.NotificationsManagerImpl;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.AbstractProjectComponent;
|
||||
@@ -67,7 +69,12 @@ public class EventLog implements Notifications {
|
||||
}
|
||||
}
|
||||
|
||||
public static void logNotification(@Nullable final Project project, final Notification notification) {
|
||||
private static void logNotification(@Nullable final Project project, final Notification notification) {
|
||||
final NotificationSettings settings = NotificationsConfiguration.getSettings(notification.getGroupId());
|
||||
if (!settings.isShouldLog()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (project == null) {
|
||||
final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
|
||||
if (openProjects.length == 0) {
|
||||
|
||||
+27
-8
@@ -24,13 +24,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author spleaner
|
||||
*/
|
||||
public class NotificationSettings {
|
||||
|
||||
private NotificationDisplayType myDisplayType;
|
||||
private final String myGroupId;
|
||||
private NotificationDisplayType myDisplayType;
|
||||
private boolean myShouldLog;
|
||||
|
||||
public NotificationSettings(final String groupId, final NotificationDisplayType displayType) {
|
||||
public NotificationSettings(String groupId, NotificationDisplayType displayType, boolean shouldLog) {
|
||||
myGroupId = groupId;
|
||||
myDisplayType = displayType;
|
||||
myShouldLog = shouldLog;
|
||||
}
|
||||
|
||||
public NotificationSettings(final String groupId, final NotificationDisplayType displayType) {
|
||||
this(groupId, displayType, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -43,21 +48,29 @@ public class NotificationSettings {
|
||||
return myDisplayType;
|
||||
}
|
||||
|
||||
public boolean isShouldLog() {
|
||||
return myShouldLog;
|
||||
}
|
||||
|
||||
public void setShouldLog(boolean shouldLog) {
|
||||
myShouldLog = shouldLog;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NotificationSettings load(@NotNull final Element element) {
|
||||
final String displayTypeString = element.getAttributeValue("displayType");
|
||||
NotificationDisplayType displayType = NotificationDisplayType.BALLOON;
|
||||
NotificationDisplayType displayType = NotificationDisplayType.STICKY_BALLOON;
|
||||
if (displayTypeString != null) {
|
||||
try {
|
||||
displayType = NotificationDisplayType.valueOf(displayTypeString.toUpperCase());
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
displayType = NotificationDisplayType.BALLOON;
|
||||
catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
final boolean shouldLog = !"false".equals(element.getAttributeValue("shouldLog")) && displayType != NotificationDisplayType.BALLOON_ONLY;
|
||||
final String groupId = element.getAttributeValue("groupId");
|
||||
return groupId != null ? new NotificationSettings(groupId, displayType) : null;
|
||||
return groupId != null ? new NotificationSettings(groupId, displayType, shouldLog) : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -65,7 +78,13 @@ public class NotificationSettings {
|
||||
final Element result = new Element("notification");
|
||||
|
||||
result.setAttribute("groupId", getGroupId());
|
||||
result.setAttribute("displayType", getDisplayType().toString());
|
||||
final NotificationDisplayType displayType = getDisplayType();
|
||||
if (displayType != NotificationDisplayType.STICKY_BALLOON) {
|
||||
result.setAttribute("displayType", displayType.toString());
|
||||
}
|
||||
if (!myShouldLog) {
|
||||
result.setAttribute("shouldLog", "false");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+33
-24
@@ -24,6 +24,8 @@ import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.hash.LinkedHashMap;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import org.jdom.Element;
|
||||
@@ -56,25 +58,27 @@ public class NotificationsConfiguration implements ApplicationComponent, Notific
|
||||
return getNotificationsConfiguration()._getAllSettings();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void remove(NotificationSettings[] toRemove) {
|
||||
getNotificationsConfiguration()._remove(ContainerUtil.map2Array(toRemove, String.class, new Function<NotificationSettings, String>() {
|
||||
@Override
|
||||
public String fun(NotificationSettings notificationSettings) {
|
||||
return notificationSettings.getGroupId();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static void remove(String... toRemove) {
|
||||
getNotificationsConfiguration()._remove(toRemove);
|
||||
}
|
||||
|
||||
public static void removeAll() {
|
||||
getNotificationsConfiguration()._removeAll();
|
||||
}
|
||||
|
||||
private void _removeAll() {
|
||||
myIdToSettingsMap.clear();
|
||||
}
|
||||
|
||||
private void _remove(NotificationSettings[] toRemove) {
|
||||
for (final NotificationSettings settings : toRemove) {
|
||||
myIdToSettingsMap.remove(settings.getGroupId());
|
||||
private synchronized void _remove(String... toRemove) {
|
||||
for (final String id : toRemove) {
|
||||
myIdToSettingsMap.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
private NotificationSettings[] _getAllSettings() {
|
||||
private synchronized NotificationSettings[] _getAllSettings() {
|
||||
final List<NotificationSettings> result = new ArrayList<NotificationSettings>();
|
||||
for (String s : myIdToSettingsMap.keySet()) {
|
||||
if (!Notifications.LOG_ONLY_GROUP_ID.equals(s)) {
|
||||
@@ -92,9 +96,14 @@ public class NotificationsConfiguration implements ApplicationComponent, Notific
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private synchronized NotificationSettings _getSettings(@NotNull final String groupId) {
|
||||
return myIdToSettingsMap.get(groupId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static NotificationSettings getSettings(@NotNull final String groupId) {
|
||||
final NotificationsConfiguration configuration = getNotificationsConfiguration();
|
||||
return configuration.myIdToSettingsMap.get(groupId);
|
||||
final NotificationSettings settings = getNotificationsConfiguration()._getSettings(groupId);
|
||||
return settings == null ? new NotificationSettings(groupId, NotificationDisplayType.STICKY_BALLOON, true) : settings;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -106,28 +115,28 @@ public class NotificationsConfiguration implements ApplicationComponent, Notific
|
||||
myMessageBus.connect().subscribe(TOPIC, this);
|
||||
}
|
||||
|
||||
public void disposeComponent() {
|
||||
public synchronized void disposeComponent() {
|
||||
myIdToSettingsMap.clear();
|
||||
}
|
||||
|
||||
public void register(@NotNull final String groupDisplayType, @NotNull final NotificationDisplayType displayType) {
|
||||
if (!myIdToSettingsMap.containsKey(groupDisplayType)) {
|
||||
myIdToSettingsMap.put(groupDisplayType, new NotificationSettings(groupDisplayType, displayType));
|
||||
registerDefaultSettings(new NotificationSettings(groupDisplayType, displayType));
|
||||
}
|
||||
|
||||
public synchronized void registerDefaultSettings(NotificationSettings settings) {
|
||||
if (!isRegistered(settings.getGroupId())) {
|
||||
myIdToSettingsMap.put(settings.getGroupId(), settings);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRegistered(@NotNull final String id) {
|
||||
public synchronized boolean isRegistered(@NotNull final String id) {
|
||||
return myIdToSettingsMap.containsKey(id);
|
||||
}
|
||||
|
||||
public void notify(@NotNull Notification notification) {
|
||||
}
|
||||
|
||||
public void notify(@NotNull Notification notification,
|
||||
@NotNull NotificationDisplayType defaultDisplayType) {
|
||||
}
|
||||
|
||||
public Element getState() {
|
||||
public synchronized Element getState() {
|
||||
@NonNls Element element = new Element("NotificationsConfiguration");
|
||||
for (NotificationSettings settings : myIdToSettingsMap.values()) {
|
||||
element.addContent(settings.save());
|
||||
@@ -136,7 +145,7 @@ public class NotificationsConfiguration implements ApplicationComponent, Notific
|
||||
return element;
|
||||
}
|
||||
|
||||
public void loadState(final Element state) {
|
||||
public synchronized void loadState(final Element state) {
|
||||
for (@NonNls Element child : (Iterable<? extends Element>)state.getChildren("notification")) {
|
||||
final NotificationSettings settings = NotificationSettings.load(child);
|
||||
if (settings != null) {
|
||||
|
||||
+5
-3
@@ -126,11 +126,13 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
public void doNotify(@NotNull final Notification notification, @Nullable NotificationDisplayType displayType, @Nullable final Project project) {
|
||||
final NotificationsConfiguration configuration = NotificationsConfiguration.getNotificationsConfiguration();
|
||||
if (!configuration.isRegistered(notification.getGroupId())) {
|
||||
configuration.register(notification.getGroupId(), displayType == null ? NotificationDisplayType.STICKY_BALLOON : displayType);
|
||||
configuration.registerDefaultSettings(new NotificationSettings(notification.getGroupId(),
|
||||
displayType == null ? NotificationDisplayType.STICKY_BALLOON : displayType,
|
||||
displayType != NotificationDisplayType.BALLOON_ONLY));
|
||||
}
|
||||
|
||||
if (NotificationsConfiguration.getSettings(notification.getGroupId()).getDisplayType() != NotificationDisplayType.BALLOON_ONLY &&
|
||||
!LOG_ONLY_GROUP_ID.equals(notification.getGroupId())) {
|
||||
final NotificationSettings settings = NotificationsConfiguration.getSettings(notification.getGroupId());
|
||||
if (settings.getDisplayType() != NotificationDisplayType.BALLOON_ONLY && settings.isShouldLog()) {
|
||||
myModel.add(notification, project);
|
||||
}
|
||||
|
||||
|
||||
+21
-6
@@ -95,6 +95,7 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
|
||||
private static class NotificationsTable extends StripeTable {
|
||||
private static final int ID_COLUMN = 0;
|
||||
private static final int DISPLAY_TYPE_COLUMN = 1;
|
||||
private static final int LOG_COLUMN = 2;
|
||||
|
||||
public NotificationsTable() {
|
||||
super(new NotificationsTableModel());
|
||||
@@ -128,6 +129,9 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
|
||||
}
|
||||
});
|
||||
|
||||
final TableColumn logColumn = getColumnModel().getColumn(LOG_COLUMN);
|
||||
logColumn.setMaxWidth(new JComboBox().getPreferredSize().width);
|
||||
|
||||
getEmptyText().setText("No notifications configured");
|
||||
}
|
||||
|
||||
@@ -187,12 +191,12 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
|
||||
private boolean myRemoved = false;
|
||||
|
||||
private SettingsWrapper(@NotNull final NotificationSettings original) {
|
||||
super(original.getGroupId(), original.getDisplayType());
|
||||
super(original.getGroupId(), original.getDisplayType(), original.isShouldLog());
|
||||
myOriginal = original;
|
||||
}
|
||||
|
||||
public boolean hasChanged() {
|
||||
return !getDisplayType().equals(myOriginal.getDisplayType()) || myRemoved;
|
||||
return !getDisplayType().equals(myOriginal.getDisplayType()) || isShouldLog() != myOriginal.isShouldLog() || myRemoved;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
@@ -205,11 +209,12 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
|
||||
|
||||
public void apply() {
|
||||
if (myRemoved) {
|
||||
NotificationsConfiguration.remove(new NotificationSettings[]{myOriginal});
|
||||
NotificationsConfiguration.remove(myOriginal.getGroupId());
|
||||
}
|
||||
else {
|
||||
if (hasChanged()) {
|
||||
myOriginal.setDisplayType(getDisplayType());
|
||||
myOriginal.setShouldLog(isShouldLog());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,6 +252,9 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
|
||||
case NotificationsTable.DISPLAY_TYPE_COLUMN:
|
||||
settings.setDisplayType((NotificationDisplayType)value);
|
||||
break;
|
||||
case NotificationsTable.LOG_COLUMN:
|
||||
settings.setShouldLog((Boolean)value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +267,7 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,6 +275,9 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
|
||||
if (NotificationsTable.DISPLAY_TYPE_COLUMN == columnIndex) {
|
||||
return NotificationDisplayType.class;
|
||||
}
|
||||
if (NotificationsTable.LOG_COLUMN == columnIndex) {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
return String.class;
|
||||
}
|
||||
@@ -276,20 +287,24 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
|
||||
switch (column) {
|
||||
case NotificationsTable.ID_COLUMN:
|
||||
return "Group";
|
||||
case NotificationsTable.LOG_COLUMN:
|
||||
return "Log";
|
||||
default:
|
||||
return "Display";
|
||||
return "Popup";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(final int rowIndex, final int columnIndex) {
|
||||
return columnIndex == NotificationsTable.DISPLAY_TYPE_COLUMN;
|
||||
return columnIndex > 0;
|
||||
}
|
||||
|
||||
public Object getValueAt(final int rowIndex, final int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case NotificationsTable.ID_COLUMN:
|
||||
return getSettings().get(rowIndex).getGroupId();
|
||||
case NotificationsTable.LOG_COLUMN:
|
||||
return getSettings().get(rowIndex).isShouldLog();
|
||||
case NotificationsTable.DISPLAY_TYPE_COLUMN:
|
||||
default:
|
||||
return getSettings().get(rowIndex).getDisplayType();
|
||||
|
||||
@@ -229,17 +229,12 @@ public class SvnVcs extends AbstractVcs<CommittedChangeList> {
|
||||
}
|
||||
|
||||
private void correctNotificationIds() {
|
||||
boolean notEmpty = NotificationsConfiguration.getSettings("SVN_NO_JNA") != null ||
|
||||
NotificationsConfiguration.getSettings("SVN_NO_CRYPT32") != null ||
|
||||
NotificationsConfiguration.getSettings("SubversionId") != null;
|
||||
boolean notEmpty = NotificationsConfiguration.getNotificationsConfiguration().isRegistered("SVN_NO_JNA") ||
|
||||
NotificationsConfiguration.getNotificationsConfiguration().isRegistered("SVN_NO_CRYPT32") ||
|
||||
NotificationsConfiguration.getNotificationsConfiguration().isRegistered("SubversionId");
|
||||
if (notEmpty) {
|
||||
NotificationsConfiguration.remove(new NotificationSettings[] {new NotificationSettings("SVN_NO_JNA", null),
|
||||
new NotificationSettings("SVN_NO_CRYPT32", null), new NotificationSettings("SubversionId", null)});
|
||||
// if group ids is being changed, set highest level first
|
||||
final NotificationSettings settings = NotificationsConfiguration.getSettings(getDisplayName());
|
||||
if (settings != null) {
|
||||
settings.setDisplayType(NotificationDisplayType.STICKY_BALLOON);
|
||||
}
|
||||
NotificationsConfiguration.remove("SVN_NO_JNA", "SVN_NO_CRYPT32", "SubversionId");
|
||||
NotificationsConfiguration.getNotificationsConfiguration().registerDefaultSettings(new NotificationSettings(getDisplayName(), NotificationDisplayType.BALLOON, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user