changedUpdate exception
[fedora-idea.git] / platform / platform-impl / src / com / intellij / ui / SystemNotificationsImpl.java
blob16ed34cfde63e52dad77577b3e86002e183ed36b
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.ui;
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.components.PersistentStateComponent;
20 import com.intellij.openapi.components.State;
21 import com.intellij.openapi.components.Storage;
22 import com.intellij.openapi.util.SystemInfo;
23 import org.jetbrains.annotations.NotNull;
25 import java.util.HashSet;
26 import java.util.Set;
28 /**
29 * @author mike
31 @State(
32 name = "SystemNotifications",
33 storages = {
34 @Storage(
35 id="SystemNotifications",
36 file="$APP_CONFIG$/other.xml"
39 public class SystemNotificationsImpl implements SystemNotifications, PersistentStateComponent<SystemNotificationsImpl.State> {
40 private State myState = new State();
41 private boolean myGrowlDisabled = false;
43 public void notify(@NotNull String notificationName, @NotNull String title, @NotNull String text) {
44 if (!isGrowlEnabled() || ApplicationManager.getApplication().isActive()) return;
46 final GrowlNotifications nofications;
47 try {
48 nofications = GrowlNotifications.getNotifications();
50 catch (Throwable e) {
51 myGrowlDisabled = true;
52 return;
55 myState.NOTIFICATIONS.add(notificationName);
56 nofications.notify(myState.NOTIFICATIONS, notificationName, title, text);
59 private boolean isGrowlEnabled() {
60 if (myGrowlDisabled || !SystemInfo.isMac) return false;
62 if ("true".equalsIgnoreCase(System.getProperty("growl.disable"))) {
63 myGrowlDisabled = true;
66 return !myGrowlDisabled;
69 public State getState() {
70 return myState;
73 public void loadState(final State state) {
74 myState = state;
78 public static class State {
79 public Set<String> NOTIFICATIONS = new HashSet<String>();