package jetbrains.mps.ide.make.actions;
/*Generated by MPS */
import com.intellij.openapi.Disposable;
import jetbrains.mps.make.IMakeNotificationListener;
import com.intellij.openapi.project.Project;
import jetbrains.mps.make.IMakeService;
import com.intellij.notification.impl.NotificationsConfigurationImpl;
import com.intellij.notification.NotificationsConfiguration;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.ui.popup.BalloonBuilder;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.ui.LightColors;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.util.Disposer;
import java.awt.Component;
import com.intellij.openapi.wm.WindowManager;
import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
import java.awt.Container;
import java.awt.Rectangle;
import java.awt.Point;
import com.intellij.util.ui.UIUtil;
import java.awt.Dimension;
import com.intellij.ui.awt.RelativePoint;
import jetbrains.mps.generator.GenerationSettingsProvider;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.notification.impl.NotificationSettings;
import jetbrains.mps.make.MakeNotification;
import javax.swing.JComponent;
import com.intellij.openapi.wm.StatusBar;
public class TransientModelBallonDisplayer implements Disposable {
private static final String ID = "Saving Transient Models Is On";
private final IMakeNotificationListener myMakeNotificationListener = new TransientModelBallonDisplayer.MyMakeNotificationListener();
private final Project myProject;
private final TransientModelsWidget myWidget;
public TransientModelBallonDisplayer(Project project, TransientModelsWidget widget) {
myProject = project;
myWidget = widget;
}
public void init() {
IMakeService.INSTANCE.get().addListener(myMakeNotificationListener);
ensureRegistered();
}
@Override
public void dispose() {
if (IMakeService.INSTANCE.hasMakeService()) {
IMakeService.INSTANCE.get().removeListener(myMakeNotificationListener);
}
}
private void ensureRegistered() {
if (!(NotificationsConfigurationImpl.getInstanceImpl().isRegistered(ID))) {
NotificationsConfiguration.getNotificationsConfiguration().register(ID, NotificationDisplayType.BALLOON, false);
}
}
private void showBaloonInternal() {
Notification notification = new Notification(ID, "Saving transient models", "Saving transient models is on", NotificationType.WARNING);
boolean sticky = NotificationsConfigurationImpl.getSettings(ID).getDisplayType() == NotificationDisplayType.STICKY_BALLOON;
BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("Saving transient models is on", null, LightColors.YELLOW, null).setHideOnAction(!(sticky)).setHideOnClickOutside(!(sticky)).setHideOnKeyOutside(!(sticky));
if (!(sticky)) {
builder.setFadeoutTime(3000);
}
final Balloon balloon = builder.createBalloon();
notification.setBalloon(balloon);
Disposer.register(this, balloon);
Component component = check_45eojt_a0j0n(myWidget);
if (component != null && component.isShowing()) {
showForComponent(component, balloon);
} else {
component = check_45eojt_a0a0a01a31(WindowManager.getInstance().getStatusBar(myProject));
if (component != null && component.isShowing()) {
showForComponent(component, balloon);
} else {
final JRootPane rootPane = SwingUtilities.getRootPane(component);
if (rootPane != null && rootPane.isShowing()) {
final Container contentPane = rootPane.getContentPane();
final Rectangle bounds = contentPane.getBounds();
final Point target = UIUtil.getCenterPoint(bounds, new Dimension(1, 1));
target.y = bounds.height - 3;
balloon.show(new RelativePoint(contentPane, target), Balloon.Position.above);
}
}
}
}
private void showBallon() {
if (!(GenerationSettingsProvider.getInstance().getGenerationSettings().isSaveTransientModels()) || !(isPopupShown())) {
return;
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
showBaloonInternal();
}
});
}
private void showForComponent(Component component, Balloon ballon) {
int offset = component.getHeight() / 2;
Point point = new Point(component.getWidth() - offset, component.getHeight() - offset);
ballon.show(new RelativePoint(component, point), Balloon.Position.above);
}
public static boolean isPopupShown() {
if (!(NotificationsConfigurationImpl.getInstanceImpl().SHOW_BALLOONS)) {
return false;
}
NotificationDisplayType displayType = NotificationsConfigurationImpl.getSettings(ID).getDisplayType();
return displayType == NotificationDisplayType.BALLOON || displayType == NotificationDisplayType.STICKY_BALLOON;
}
public static void setShowPopup(boolean show) {
NotificationSettings settings = NotificationsConfigurationImpl.getSettings(ID);
settings.withDisplayType((show ? NotificationDisplayType.BALLOON : NotificationDisplayType.NONE));
}
private class MyMakeNotificationListener implements IMakeNotificationListener {
private volatile boolean mySessionJustOpened;
public MyMakeNotificationListener() {
}
@Override
public void handleNotification(MakeNotification notification) {
if (notification.getKind() == MakeNotification.Kind.SESSION_OPENED) {
mySessionJustOpened = true;
} else if (notification.getKind() == MakeNotification.Kind.SCRIPT_ABOUT_TO_START) {
if (mySessionJustOpened) {
showBallon();
mySessionJustOpened = false;
}
} else if (notification.getKind() == MakeNotification.Kind.SESSION_CLOSED) {
mySessionJustOpened = false;
}
}
@Override
public void scriptAboutToStart(MakeNotification notification) {
}
@Override
public void scriptFinished(MakeNotification notification) {
}
@Override
public void sessionOpened(MakeNotification notification) {
}
@Override
public void sessionClosed(MakeNotification notification) {
}
}
private static JComponent check_45eojt_a0j0n(TransientModelsWidget checkedDotOperand) {
if (null != checkedDotOperand) {
return checkedDotOperand.getComponent();
}
return null;
}
private static JComponent check_45eojt_a0a0a01a31(StatusBar checkedDotOperand) {
if (null != checkedDotOperand) {
return checkedDotOperand.getComponent();
}
return null;
}
}