IDEA-304705 Slow Operations: Editor ctor gets psi file on EDT
[idea/community.git] / platform / diff-impl / src / com / intellij / diff / tools / fragmented / UnifiedDiffPanel.java
1 /*
2  * Copyright 2000-2015 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.intellij.diff.tools.fragmented;
17
18 import com.intellij.CommonBundle;
19 import com.intellij.diff.DiffContext;
20 import com.intellij.diff.tools.util.base.DiffPanelBase;
21 import com.intellij.openapi.actionSystem.DataProvider;
22 import com.intellij.openapi.diff.DiffBundle;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.util.ui.AsyncProcessIcon;
25 import com.intellij.util.ui.JBUI;
26 import org.jetbrains.annotations.NonNls;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29
30 import javax.swing.*;
31
32 import static com.intellij.diff.util.DiffUtil.createMessagePanel;
33
34 public class UnifiedDiffPanel extends DiffPanelBase {
35   private static final @NonNls String GOOD_CONTENT = "GoodContent";
36   private static final @NonNls String LOADING_CONTENT = "LoadingContent";
37   private static final @NonNls String TOO_BIG_CONTENT = "TooBigContent";
38   private static final @NonNls String OPERATION_CANCELED_CONTENT = "OperationCanceledContent";
39   private static final @NonNls String ERROR_CONTENT = "ErrorContent";
40
41   @NotNull private final AsyncProcessIcon.Big myBusyIcon;
42
43   public UnifiedDiffPanel(@Nullable Project project,
44                           @NotNull JComponent content,
45                           @NotNull DataProvider provider,
46                           @NotNull DiffContext context) {
47     super(project, provider, context);
48     myBusyIcon = new AsyncProcessIcon.Big("UnifiedDiff");
49     JPanel centerPanel = JBUI.Panels.simplePanel(content).addToTop(myNotificationsPanel);
50     myContentPanel.add(centerPanel, GOOD_CONTENT);
51     myContentPanel.add(myBusyIcon, LOADING_CONTENT);
52     myContentPanel.add(createMessagePanel(DiffBundle.message("error.can.not.calculate.diff.file.too.big")), TOO_BIG_CONTENT);
53     myContentPanel.add(createMessagePanel(DiffBundle.message("error.can.not.calculate.diff.operation.canceled")), OPERATION_CANCELED_CONTENT);
54     myContentPanel.add(createMessagePanel(CommonBundle.message("title.error")), ERROR_CONTENT);
55
56     setCurrentCard(LOADING_CONTENT, false);
57   }
58
59   //
60   // Card layout
61   //
62
63   public void setLoadingContent() {
64     setCurrentCard(LOADING_CONTENT);
65   }
66
67   public void setGoodContent() {
68     setCurrentCard(GOOD_CONTENT);
69   }
70
71   public void setTooBigContent() {
72     setCurrentCard(TOO_BIG_CONTENT);
73   }
74
75   public void setOperationCanceledContent() {
76     setCurrentCard(OPERATION_CANCELED_CONTENT);
77   }
78
79   public void setErrorContent() {
80     setCurrentCard(ERROR_CONTENT);
81   }
82
83   @Override
84   protected void setCurrentCard(@NotNull String card) {
85     if (card == LOADING_CONTENT) {
86       myBusyIcon.resume();
87     }
88     else {
89       myBusyIcon.suspend();
90     }
91
92     super.setCurrentCard(card);
93   }
94
95   //
96   // Misc
97   //
98
99   public boolean isGoodContent() {
100     return myCurrentCard.equals(GOOD_CONTENT);
101   }
102 }