2 * Copyright 2000-2015 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.xdebugger.impl.breakpoints.ui;
18 import com.intellij.openapi.Disposable;
19 import com.intellij.openapi.components.ServiceManager;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.openapi.ui.popup.Balloon;
22 import com.intellij.openapi.util.Disposer;
23 import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil;
24 import org.jetbrains.annotations.Nullable;
26 public class BreakpointsDialogFactory {
28 private Project myProject;
29 private Balloon myBalloonToHide;
30 private Object myBreakpoint;
31 private BreakpointsDialog myDialogShowing;
34 public BreakpointsDialogFactory(Project project) {
38 public void setBalloonToHide(final Balloon balloonToHide, Object breakpoint) {
39 myBalloonToHide = balloonToHide;
40 myBreakpoint = breakpoint;
41 Disposer.register(myBalloonToHide, new Disposable() {
43 public void dispose() {
44 if (myBalloonToHide == balloonToHide) {
45 myBalloonToHide = null;
52 public static BreakpointsDialogFactory getInstance(Project project) {
53 return ServiceManager.getService(project, BreakpointsDialogFactory.class);
56 public boolean isBreakpointPopupShowing() {
57 return (myBalloonToHide != null && !myBalloonToHide.isDisposed()) || myDialogShowing != null;
60 public void showDialog(@Nullable Object initialBreakpoint) {
61 if (myDialogShowing != null) {
65 final BreakpointsDialog dialog = new BreakpointsDialog(myProject, initialBreakpoint != null ? initialBreakpoint : myBreakpoint, XBreakpointUtil.collectPanelProviders()) {
67 protected void dispose() {
69 for (BreakpointPanelProvider provider : XBreakpointUtil.collectPanelProviders()) {
70 provider.onDialogClosed(myProject);
72 myDialogShowing = null;
78 if (myBalloonToHide != null) {
79 if (!myBalloonToHide.isDisposed()) {
80 myBalloonToHide.hide();
82 myBalloonToHide = null;
84 myDialogShowing = dialog;